color_palette.hpp
Go to the documentation of this file.
1 
22 #ifndef COLOR_WIDGETS_COLOR_PALETTE_HPP
23 #define COLOR_WIDGETS_COLOR_PALETTE_HPP
24 
25 #include <QColor>
26 #include <QString>
27 #include <QVector>
28 #include <QObject>
29 #include <QPair>
30 #include <QPixmap>
31 
32 namespace color_widgets {
33 
34 class ColorPalette : public QObject
35 {
36  Q_OBJECT
37 
45  Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
49  Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
53  Q_PROPERTY(int count READ count)
57  Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
61  Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
62 
63 public:
64  typedef QPair<QColor,QString> value_type;
65 
66  ColorPalette(const QVector<QColor>& colors, const QString& name = QString(), int columns = 0);
67  ColorPalette(const QVector<QPair<QColor,QString> >& colors, const QString& name = QString(), int columns = 0);
68  explicit ColorPalette(const QString& name = QString());
69  ColorPalette(const ColorPalette& other);
70  ColorPalette& operator=(const ColorPalette& other);
71  ~ColorPalette();
72  ColorPalette(ColorPalette&& other);
73  ColorPalette& operator=(ColorPalette&& other);
74 
78  Q_INVOKABLE QColor colorAt(int index) const;
79 
83  Q_INVOKABLE QString nameAt(int index) const;
84 
85  QVector<QPair<QColor,QString> > colors() const;
86  QVector<QColor> onlyColors() const;
87 
88  int count() const;
89  int columns();
90 
91  QString name() const;
92 
96  Q_INVOKABLE void loadColorTable(const QVector<QRgb>& color_table);
97 
101  Q_INVOKABLE QVector<QRgb> colorTable() const;
102 
106  static ColorPalette fromColorTable(const QVector<QRgb>& table);
107 
111  Q_INVOKABLE bool loadImage(const QImage& image);
112 
116  static ColorPalette fromImage(const QImage& image);
117 
123  Q_INVOKABLE bool load(const QString& name);
124 
128  static ColorPalette fromFile(const QString& name);
129 
130  QString fileName() const;
131 
132  bool dirty() const;
133 
137  QPixmap preview(const QSize& size, const QColor& background=Qt::transparent) const;
138 
139 public slots:
140  void setColumns(int columns);
141 
142  void setColors(const QVector<QColor>& colors);
143  void setColors(const QVector<QPair<QColor,QString> >& colors);
144 
148  void setColorAt(int index, const QColor& color);
152  void setColorAt(int index, const QColor& color, const QString& name);
156  void setNameAt(int index, const QString& name = QString());
160  void appendColor(const QColor& color, const QString& name = QString());
164  void insertColor(int index, const QColor& color, const QString& name = QString());
168  void eraseColor(int index);
169 
174  bool save(const QString& filename);
179  bool save();
180 
181  void setName(const QString& name);
182  void setFileName(const QString& name);
183  void setDirty(bool dirty);
184 
185 signals:
189  void colorsChanged(const QVector<QPair<QColor,QString> >&);
190  void columnsChanged(int);
191  void nameChanged(const QString&);
192  void fileNameChanged(const QString&);
193  void dirtyChanged(bool);
197  void colorChanged(int index);
201  void colorRemoved(int index);
205  void colorAdded(int index);
209  void colorsUpdated(const QVector<QPair<QColor,QString>>&);
210 
211 private:
215  QString unnamed(const QString& name = QString()) const;
216 
220  void emitUpdate();
221 
222  class Private;
223  Private *p;
224 };
225 
226 } // namespace color_widgets
227 
228 #endif // COLOR_WIDGETS_COLOR_PALETTE_HPP
void colorsChanged(const QVector< QPair< QColor, QString > > &)
Emitted when all the colors have changed.
void setName(const QString &name)
QVector< QColor > onlyColors() const
bool save()
save to file, the filename is fileName or determined automatically
Q_INVOKABLE void loadColorTable(const QVector< QRgb > &color_table)
Use a color table to set the colors.
void emitUpdate()
Emit all the necessary signals when the palette has been completely overwritten.
Q_INVOKABLE QVector< QRgb > colorTable() const
Convert to a color table.
void setColors(const QVector< QColor > &colors)
void setFileName(const QString &name)
QVector< QPair< QColor, QString > > colors() const
static ColorPalette fromImage(const QImage &image)
Creates a ColorPalette from a Gimp palette (gpl) file.
void colorAdded(int index)
Emitted when a single color has been added.
void setNameAt(int index, const QString &name=QString())
Change the name of a color.
QPixmap preview(const QSize &size, const QColor &background=Qt::transparent) const
Returns a preview image of the colors in the palette.
void setColorAt(int index, const QColor &color)
Change the color at the given index.
void eraseColor(int index)
Remove the color at the given index.
static ColorPalette fromFile(const QString &name)
Creates a ColorPalette from a Gimp palette (gpl) file.
void colorRemoved(int index)
Emitted when the color at the given index has been removed.
void nameChanged(const QString &)
Q_INVOKABLE bool loadImage(const QImage &image)
Use the pixels on an image to set the palette colors.
Q_INVOKABLE QColor colorAt(int index) const
Color at the given index.
void colorChanged(int index)
Emitted when the color or the name at the given index has been modified.
static ColorPalette fromColorTable(const QVector< QRgb > &table)
Creates a ColorPalette from a color table.
Q_INVOKABLE bool load(const QString &name)
Load contents from a Gimp palette (gpl) file.
void insertColor(int index, const QColor &color, const QString &name=QString())
Insert a color in an arbitrary location.
void fileNameChanged(const QString &)
Q_INVOKABLE QString nameAt(int index) const
Color name at the given index.
QPair< QColor, QString > value_type
void appendColor(const QColor &color, const QString &name=QString())
Append a color at the end.
QString fileName() const
void setColumns(int columns)
QString unnamed(const QString &name=QString()) const
Returns name if it isn&#39;t null, otherwise a default value.
void colorsUpdated(const QVector< QPair< QColor, QString >> &)
Emitted when the colors have been modified with a simple operation (set, append etc.)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:47:33