Advertisement
Guest User

Untitled

a guest
Sep 12th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.30 KB | None | 0 0
  1. #ifndef __ZLISTBOX_H_
  2. #define __ZLISTBOX_H_
  3.  
  4. #include <ZScrollPanel.h>
  5. #include <ZWrapLine.h>
  6. #include <ZSkinBase.h>
  7.  
  8. class ZListBox;
  9. class Q_EXPORT ZListItem
  10. {
  11. public:
  12. ZListItem( ZListBox* listbox, const QString itemType = NULL);
  13. virtual ~ZListItem();
  14. enum ListItemType {LISTBOXITEM, SETTINGITEM};
  15. QString getItemType() const;
  16. ZListBox* listBox() const { return lb; }
  17. void setActive();
  18. void check(bool b);
  19. bool isChecked() const;
  20. QString getMarkColumnType() const;
  21. void setReservedData(unsigned int rsvData);
  22. unsigned int getReservedData();
  23. void setEnabled(bool enabled);
  24. bool enabled() const ;
  25. bool selected() const { return current(); }
  26. bool current() const;
  27. void setSelectable( bool b = FALSE );
  28. bool isSelectable() const;
  29. ZListItem *next() const {return n;}
  30. ZListItem *prev() const {return p;}
  31. void setWrapPolicy(ZWrapLine::WrapPolicy policy);
  32. ZWrapLine::WrapPolicy getWrapPolicy(){return wrapPolicy;}
  33. void setZStyle(ZSkinService::WidgetClsID style);
  34. ZSkinService::WidgetClsID getZStyle() const;
  35. void setSeparator(const QString text, const QPixmap* icon = NULL);
  36. bool isSeparatorItem() const {return isSeparator;}
  37. virtual QString getSortText() const {return QString("");};
  38. virtual int width( const ZListBox * ) const {return 0;};
  39. virtual int height( const ZListBox * ) const {return 0;};
  40. void setPartialChecked(bool partial);
  41. bool partialChecked() const;
  42. protected:
  43. virtual void paint( QPainter * ) {};
  44. int separatorHeight(const ZListBox* listbox) const;
  45. void drawSeparator(QPainter *painter, int x, int y, int width, int height);
  46. private:
  47. virtual void startMarquee() {};
  48. virtual void stopMarquee() {};
  49. virtual ListItemType listitemType() const {return LISTBOXITEM;};
  50. protected:
  51. void update(bool all);
  52. void drawImage(QPainter* painter, int x, int y, int width, int height, const QPixmap& pm, int flag);
  53. QString truncate(QString& str, int len, uint width, QFont& font, QString ellpsis = NULL);
  54. ZSkinBase::SelectionState getSelectionState();
  55. protected:
  56. ZListBox* lb;
  57. QString itemType;
  58. ZListItem * p, * n;
  59. enum ToggleState { OFF, NOCHANGE, ON};
  60. short stat;
  61. QPixmap* mSepIcon;
  62. QString* mSepText;
  63. unsigned int reserved;
  64. ZWrapLine::WrapPolicy wrapPolicy;
  65. ZSkinService::WidgetClsID itemClsId;
  66. uint down:1;
  67. uint isEnabled:1;
  68. uint isSeparator:1;
  69. uint selectable:1;
  70. uint dirty:1;
  71. uint own_style:1;
  72. uint mPartialChecked : 1;
  73. friend class ZListBox;
  74. friend class ZListBoxClipper;
  75. };
  76.  
  77. class LBItemInfo;
  78. class LBSubItemInfo;
  79.  
  80. class Q_EXPORT ZListBoxItem : public ZListItem
  81. {
  82. public:
  83. ZListBoxItem( ZListBox* listbox, const QString itemType = NULL);
  84. virtual ~ZListBoxItem();
  85.  
  86. enum ShowPriority
  87. {
  88. FirstPriority ,
  89. SecondPriority,
  90. EquityPriority
  91. };
  92.  
  93. int appendSubItem(int index, const QString text, const QString text2, const QPixmap* icon = NULL,
  94. uint percent = 50, ShowPriority priority = EquityPriority);
  95. int appendSubItem(int index, const QString text, bool isWrapable = false, const QPixmap* icon = NULL);
  96. int appendSubItem(int index, QPixmap* iconList, uint count);
  97. QString getSubItemText(int index, int subIndex, bool text2 = false);
  98. QList<QPixmap> getSubItemIcon(int index, int subIndex);
  99. bool deleteSubItem(int index, int subIndex);
  100. bool setSubItem(int index, int subIndex, QString text, QString text2, const QPixmap* icon = NULL, uint percent = 50, ZListBoxItem::ShowPriority prior = EquityPriority);
  101. bool setSubItem(int index, int subIndex, QString text, bool isWrapable = false, const QPixmap* icon = NULL);
  102. bool setSubItem(int index, int subIndex, QPixmap* iconList, uint count);
  103. int getCurrentSubItem(int index);
  104. void setCurrentSubItem(int index, int subIndex);
  105. void setSubItemShowed(int index, int subIndex, bool showed);
  106. QPixmap getPixmap(int index);
  107. bool setPixmap(int index, const QPixmap& pixmap);
  108. void setShowIndicator(bool isShow){isShowIndicator = isShow;}
  109. void keyPressEvent( QKeyEvent *e );
  110. void showColumn(int index, bool show);
  111. bool setSortIndex(int index, int subIndex);
  112. int sortIndex() const { return sortIdx;}
  113. int sortSubIndex() const {return sortSubIdx;}
  114. virtual QString getSortText() const {return sortText?(*sortText):QString("");}
  115. virtual int width( const ZListBox * ) const;
  116. virtual int height( const ZListBox * ) const;
  117. protected:
  118. virtual void paint( QPainter * );
  119. private:
  120. virtual void startMarquee();
  121. virtual void stopMarquee();
  122. virtual ListItemType listitemType() const {return LISTBOXITEM;}
  123. void drawTextColumn(QPainter *painter, int xp,LBItemInfo* item, int validWidth );
  124. int textColumnSubItemHeight(const ZListBox* listbox, LBItemInfo* item, LBSubItemInfo* subItem, int width) const;
  125. int textColumnItemHeight(const ZListBox* listbox, LBItemInfo* item, int width) const ;
  126. int prevShowedSubItem(LBItemInfo* item);
  127. int nextShowedSubItem(LBItemInfo* item);
  128. bool isIndicatorShowed(LBItemInfo* item) const;
  129. bool isShowSubItemIcon() const;
  130. private:
  131. QList< LBItemInfo > list;
  132. short sortIdx;
  133. short sortSubIdx;
  134. QString *sortText;
  135. uint isShowIndicator:1;
  136. uint marquee:1;
  137. uint own_showSubItemIcon :1;
  138. uint showSubItemIcon : 1;
  139.  
  140. };
  141.  
  142. enum SettingItemRegion {SETTINGITEM_REGION_A, SETTINGITEM_REGION_B};
  143.  
  144. class SetSubItemInfo;
  145. class SetItemInfo;
  146.  
  147. class Q_EXPORT ZSettingItem : public ZListItem
  148. {
  149. public:
  150. ZSettingItem( ZListBox* container = 0, const QString itemType = NULL);
  151. virtual ~ZSettingItem();
  152. int appendSubItem(int index, QString text, bool isWrapable = false);
  153. int appendSubItem(int index, QString text, bool isWrapable, SettingItemRegion region);
  154. int getSubItemCount(int index);
  155. QString getSubItemText(int index, int subIndex);
  156. bool deleteSubItem(int index, int subIndex);
  157. bool setSubItem(int index, int subIndex, QString text, bool isWrapable = false, SettingItemRegion region = SETTINGITEM_REGION_B);
  158. QPixmap getPixmap(int index);
  159. bool setPixmap(int index, const QPixmap& pixmap);
  160. virtual int width( const ZListBox * ) const;
  161. virtual int height( const ZListBox * ) const;
  162. bool setSortIndex(int index, int subIndex);
  163. int sortIndex() const { return sortIdx;}
  164. int sortSubIndex() const {return sortSubIdx;}
  165. virtual QString getSortText() const {return sortText?(*sortText):QString("");}
  166. protected:
  167. virtual void paint( QPainter * );
  168. private:
  169. void drawTextColumn(QPainter *painter, int xp,SetItemInfo* item, int validWidth );
  170. int textColumnSubItemHeight(const ZListBox*, SetItemInfo* item, SetSubItemInfo* subItem, int width) const;
  171. int textColumnItemHeight(const ZListBox*, SetItemInfo* item, int width) const ;
  172. virtual void startMarquee();
  173. virtual void stopMarquee();
  174. virtual ListItemType listitemType() const {return SETTINGITEM;}
  175. private:
  176. QList< SetItemInfo > list;
  177. short sortIdx;
  178. short sortSubIdx;
  179. QString *sortText;
  180. uint marquee:1;
  181. uint own_style:1;
  182. };
  183.  
  184. class ZListBoxPrivate;
  185.  
  186. class Q_EXPORT ZListBox : public ZScrollPanel
  187. {
  188. friend class ZListItem;
  189. friend class ZListBoxItem;
  190. friend class ZSettingItem;
  191. friend class ZListBoxPrivate;
  192. Q_OBJECT
  193. public:
  194. ZListBox( QWidget* parent = 0, WFlags f = 0,
  195. ZSkinService::WidgetClsID clsId = ZSkinService::clsZListBox1 );
  196. ZListBox( QString type, QWidget* parent=0, WFlags f = 0,
  197. ZSkinService::WidgetClsID clsId = ZSkinService::clsZListBox1);
  198.  
  199. virtual ~ZListBox();
  200. void setListItemType(ZListItem::ListItemType type);
  201. int count() const;
  202. void insertItem( const ZListItem * item, int index=-1, bool autoHighlighted = TRUE );
  203. void insertItem( const ZListItem * item, const ZListItem *after, bool autoHighlighted = TRUE);
  204. void clear();
  205. void changeItem( const ZListItem * item, int index );
  206. void takeItem( const ZListItem * item);
  207. void removeItem( int index );
  208. int currentItem() const;
  209. virtual void setCurrentItem( int index );
  210. virtual void setCurrentItem( ZListItem * item);
  211. int topItem() const;
  212. virtual void setTopItem( int index );
  213. virtual void setBottomItem( int index );
  214. ZListBoxItem *item( int index ) const;
  215. int index( const ZListItem * item) const;
  216. bool itemVisible( int index );
  217. bool itemVisible( const ZListItem * item);
  218. QRect itemRect( ZListItem *item ) const;
  219. ZListItem *firstItem() const;
  220. void setSelected( int index, bool select);
  221. virtual void setSelected( ZListItem * item, bool select);
  222. bool isSelected( int index) const;
  223. bool isSelected( const ZListItem * item) const;
  224. void sort( bool ascending = TRUE );
  225. QSize sizeHint() const;
  226. QSize maxmumSizeHint() const;
  227. QSize minimumSizeHint() const;
  228. void triggerUpdate( bool doLayout );
  229. int itemHeight( int index = 0 ) const;
  230. virtual void resetFocusItem(bool);
  231. virtual QRect getCurrentFocusRect(bool) const;
  232. virtual bool hasNextPrevFocusItem(bool)const;
  233. int getListBoxSpace(ZListItem*) const;
  234. QString getItemType();
  235. void setItemType( QString type );
  236. void checkItem( int index, bool select);
  237. bool itemChecked(int index);
  238. void checkItem( ZListItem* item, bool select );
  239. bool itemChecked( ZListItem* item );
  240. QList<ZListItem>* itemsChecked();
  241. int radioItemChecked();
  242. void moveItem(int from, int to);
  243. void updateSkin(bool redraw);
  244. void setZBorder( WIDGET_BORDER_INFO_T borderItems[StateCount]);
  245. void enableEllpsis(bool enable);
  246. bool isEnableEllpsis();
  247. void setCurrentItem(int index, bool next);
  248. typedef void (*DeleteItemCallBack)(ZListItem*);
  249. void setDeleteItemCallBackFunction(DeleteItemCallBack func);
  250. DeleteItemCallBack getDeleteItemCallBackFunction() const ;
  251. void setDefaultItemHeight(int height);
  252. int defaultItemHeight() const;
  253.  
  254. ZSkinBase* getItemSkin(ZSkinService::WidgetClsID style, SelectionState state) const ;
  255. public:
  256. enum ITEMALIGN{ALIGN_MARK, ALIGN_IMAGE, ALIGN_REGION_A, ALIGN_REGION_B, ALIGN_REGION_C, ALIGN_ROWTYPETHREE};
  257. void setAlign(ITEMALIGN element, int align);
  258. int align(ITEMALIGN element) const;
  259. enum ListItemRegion
  260. {LISTITEM_REGION_A,
  261. LISTITEM_REGION_B,
  262. LISTITEM_REGION_C};
  263. void setEllpsis(QString ellpsis, ListItemRegion region = LISTITEM_REGION_C);
  264. QString getEllpsis(ListItemRegion region = LISTITEM_REGION_C);
  265. void setZItemStyle(ZSkinService::WidgetClsID style);
  266. ZSkinService::WidgetClsID getZItemStyle(bool isSeparator = FALSE) const;
  267. void setItemFont(ListItemRegion region, ZSkinBase::SelectionState state, QFont& font);
  268. QFont& itemFont(ListItemRegion region, SelectionState state) const;
  269. void enableMarquee(ListItemRegion region, bool enable);
  270. bool marqueeEnabled(ListItemRegion region) const;
  271. public:
  272. void setShowSubItemIcon(bool show);
  273. bool isShowSubItemIcon() const;
  274. void showAllSubItem(bool bShow = true);
  275. bool isShowAllSubItem() const;
  276. ZListItem * itemAt( QPoint pt) const;
  277. void setPalette( const QPalette & ){updateSkin(TRUE);}
  278. public:
  279. // Please don't use following functions.
  280. void setItemFont(ListItemRegion region, QFont& font, bool highlighted = FALSE);
  281. QFont& getItemFont(ListItemRegion region, bool highlighted = FALSE) const;
  282.  
  283. public slots:
  284. virtual void ensureCurrentVisible();
  285.  
  286. public:
  287. signals:
  288. void highlighted( int index );
  289. void highlighted( ZListItem * );
  290. void highlighted( ZListBoxItem * );
  291. void highlighted( ZSettingItem * );
  292. void selected( int index );
  293. void selected( ZListItem * );
  294. void selected( ZListBoxItem * );
  295. void selected( ZSettingItem * );
  296. void selectionChanged( ZListItem * );
  297. void selectionChanged( ZListBoxItem * );
  298. void selectionChanged( ZSettingItem * );
  299. void currentChanged( ZListItem * );
  300. void currentChanged( ZListBoxItem * );
  301. void currentChanged( ZSettingItem * );
  302. void returnPressed( int );
  303. void returnPressed( ZListItem * );
  304. void returnPressed( ZListBoxItem * );
  305. void returnPressed( ZSettingItem * );
  306. void clicked( ZListItem * );
  307. void clicked( ZListItem *, const QPoint & );
  308. void doubleClicked( ZListItem * );
  309. void showedSubItemChanged(int index, int subIndex);
  310. protected:
  311. void viewportPaintEvent( QPaintEvent * event);
  312. void viewportMousePressEvent( QMouseEvent * );
  313. void mousePressEvent ( QMouseEvent * );
  314. void viewportMouseDoubleClickEvent( QMouseEvent * );
  315. void mouseDoubleClickEvent( QMouseEvent * );
  316. void keyPressEvent( QKeyEvent *e );
  317. void focusInEvent( QFocusEvent *e );
  318. void focusOutEvent( QFocusEvent *e );
  319. void resizeEvent( QResizeEvent * );
  320. void showEvent( QShowEvent * );
  321. void updateItem( int index );
  322. void updateItem( ZListItem * );
  323. void toggleCurrentItem();
  324. void doLayout() const;
  325. private slots:
  326. void refreshSlot();
  327. void adjustItems();
  328. private:
  329. void init(QString type,QWidget * parent,WFlags f, const ZSkinService::WidgetClsID clsId );
  330. void selectBtns(ZListItem* it);
  331. void tryGeometry( int, int ) const;
  332. int numRows() const;
  333. int currentRow() const;
  334. int rowAt( int ) const;
  335. void setFontData(QFont& font, int size, int style) const;
  336. int getMaxItemWidth() const;
  337. QPixmap& indImage(SelectionState state)const;
  338. QPixmap& markImage(SelectionState state, bool single, bool partial) const;
  339. void setSeparatorFont(QFont& font);
  340. QFont& getSeparatorFont() const;
  341. QPixmap& getSeparatorImage(int index) const;
  342. ZSkinBase* getSeparatorSkin(ZSkinService::WidgetClsID) const;
  343. ZSkinBase* getImageContainerSkin(SelectionState state);
  344. int textAlign(ListItemRegion region, SelectionState state);
  345. QColor textColor(ListItemRegion region, SelectionState state);
  346. ZListBoxPrivate * d;
  347. };
  348.  
  349. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement