Scribus
Open source desktop publishing at your fingertips
colorlistbox.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #ifndef COLORLISTBOX_H
8 #define COLORLISTBOX_H
9 
10 #include <QListWidget>
11 #include <QColor>
12 #include <QPointer>
13 
14 #include "colorsetmanager.h"
15 #include "commonstrings.h"
16 #include "scribusapi.h"
17 #include "sclistboxpixmap.h"
18 #include "scguardedptr.h"
19 #include "sccolor.h"
20 
21 struct SCRIBUS_API ColorPixmapValue
22 {
23  ScColor m_color;
25  QString m_name;
26 
28  ColorPixmapValue( const ScColor& col, ScribusDoc* doc, const QString colName );
29  ColorPixmapValue(const ColorPixmapValue& other);
30  ColorPixmapValue& operator= (const ColorPixmapValue& other);
31 };
32 
33 
34 Q_DECLARE_METATYPE(ColorPixmapValue)
35 
36 class ColorPixmapItem : public QListWidgetItem
37 {
38  enum {
39  ColorPixmapUserType = UserType + 1
40  } usrtyp;
41 public:
42  ColorPixmapItem( const ScColor& col, ScribusDoc* doc, const QString colName) : QListWidgetItem(NULL, ColorPixmapUserType) {
43  setText(colName);
44  setData(Qt::UserRole, QVariant::fromValue(ColorPixmapValue(col, doc, colName)));
45  };
46  ColorPixmapItem( const ColorPixmapValue& col) : QListWidgetItem(NULL, ColorPixmapUserType) {
47  setText(col.m_name);
48  setData(Qt::UserRole, QVariant::fromValue(col));
49  };
50  ColorPixmapItem( ) : QListWidgetItem(NULL, ColorPixmapUserType) {
51  setText(CommonStrings::tr_NoneColor);
52  setData(Qt::UserRole, QVariant::fromValue(ColorPixmapValue(ScColor(0,0,0,0), NULL, CommonStrings::tr_NoneColor)));
53  };
54  QListWidgetItem * clone () const { return new ColorPixmapItem(*this); }
55  QString colorName() const { return data(Qt::UserRole).value<ColorPixmapValue>().m_name; }
56 };
57 
58 
59 
67 class SCRIBUS_API ColorListBox : public QListWidget
68 {
69  Q_OBJECT
70 
71  public:
72 
73  enum PixmapType
74  {
75  smallPixmap,
76  widePixmap,
77  fancyPixmap
78  };
79 
82  ColorListBox(QWidget * parent = 0);
83 
84  virtual void changeEvent(QEvent *e);
85 
86  QString currentColor() const;
87 
93  void updateBox(ColorList& list, ColorListBox::PixmapType type);
94 
99  void insertItems(ColorList& list, ColorListBox::PixmapType type);
100 
101  void addItem(ColorPixmapItem* item, ColorListBox::PixmapType type);
102  void addItem(ColorPixmapItem* item);
103  void addItem(QString text);
104 
107  void insertSmallPixmapItems(ColorList& list);
108 
111  void insertWidePixmapItems(ColorList& list);
112 
115  void insertFancyPixmapItems(ColorList& list);
116 
119  private slots:
120  void slotRightClick();
121  protected slots:
122  virtual void languageChange();
123  signals:
124  void showContextMenue();
125  protected:
126  bool viewportEvent(QEvent *event);
127  static int initialized;
128  static int sortRule;
129  ColorListBox::PixmapType m_type;
130 };
131 
132 #endif
Definition: colorlistbox.h:36
Definition: sccolor.h:51
Very nice list box with color names and samples. It's inherited from QListBox with all its methods an...
Definition: colorlistbox.h:67
ColorList * cList
Pointer to the color list displayed by this box.
Definition: colorlistbox.h:118
Definition: sccolor.h:155
the Document Class
Definition: scribusdoc.h:90
Definition: colorlistbox.h:21