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
color_widgets::ColorPalette::fileName
QString fileName
Name of the file the palette has been read from.
Definition: color_palette.hpp:57
color_widgets::ColorPalette::fromFile
static ColorPalette fromFile(const QString &name)
Creates a ColorPalette from a Gimp palette (gpl) file.
Definition: color_palette.cpp:258
color
color
Definition: color.h:16
color_widgets::ColorPalette::colorsUpdated
void colorsUpdated(const QVector< QPair< QColor, QString >> &)
Emitted when the colors have been modified with a simple operation (set, append etc....
color_widgets::ColorPalette::fromImage
static ColorPalette fromImage(const QImage &image)
Creates a ColorPalette from a Gimp palette (gpl) file.
Definition: color_palette.cpp:179
color_widgets::ColorPalette::setColumns
void setColumns(int columns)
Definition: color_palette.cpp:316
color_widgets::ColorPalette::loadColorTable
Q_INVOKABLE void loadColorTable(const QVector< QRgb > &color_table)
Use a color table to set the colors.
Definition: color_palette.cpp:143
color_widgets::ColorPalette::columns
int columns
Number of colors to display in a row, if 0 unspecified.
Definition: color_palette.hpp:49
color_widgets::ColorPalette::name
QString name
Name of the palette.
Definition: color_palette.hpp:45
color_widgets::ColorPalette::unnamed
QString unnamed(const QString &name=QString()) const
Returns name if it isn't null, otherwise a default value.
Definition: color_palette.cpp:426
QVector
Definition: qwt_clipper.h:23
color_widgets::ColorPalette
Definition: color_palette.hpp:34
color_widgets::ColorPalette::insertColor
void insertColor(int index, const QColor &color, const QString &name=QString())
Insert a color in an arbitrary location.
Definition: color_palette.cpp:390
color_widgets::ColorPalette::colorChanged
void colorChanged(int index)
Emitted when the color or the name at the given index has been modified.
color_widgets::ColorPalette::preview
QPixmap preview(const QSize &size, const QColor &background=Qt::transparent) const
Returns a preview image of the colors in the palette.
Definition: color_palette.cpp:432
color_widgets::ColorPalette::setColors
void setColors(const QVector< QColor > &colors)
Definition: color_palette.cpp:328
color_widgets::ColorPalette::colorsChanged
void colorsChanged(const QVector< QPair< QColor, QString > > &)
Emitted when all the colors have changed.
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
color_widgets
Definition: color_dialog.hpp:33
color_widgets::ColorPalette::count
int count
Number of colors.
Definition: color_palette.hpp:53
color_widgets::ColorPalette::fileNameChanged
void fileNameChanged(const QString &)
color_widgets::ColorPalette::save
bool save()
save to file, the filename is fileName or determined automatically
Definition: color_palette.cpp:271
color_widgets::ColorPalette::colors
QVector< value_type > colors
The list of colors.
Definition: color_palette.hpp:41
color_widgets::ColorPalette::columnsChanged
void columnsChanged(int)
color_widgets::ColorPalette::p
Private * p
Definition: color_palette.hpp:222
color_widgets::ColorPalette::setFileName
void setFileName(const QString &name)
Definition: color_palette.cpp:420
color_widgets::ColorPalette::nameAt
Q_INVOKABLE QString nameAt(int index) const
Color name at the given index.
Definition: color_palette.cpp:118
color_widgets::ColorPalette::loadImage
Q_INVOKABLE bool loadImage(const QImage &image)
Use the pixels on an image to set the palette colors.
Definition: color_palette.cpp:157
color_widgets::ColorPalette::setName
void setName(const QString &name)
Definition: color_palette.cpp:414
color_widgets::ColorPalette::eraseColor
void eraseColor(int index)
Remove the color at the given index.
Definition: color_palette.cpp:402
color_widgets::ColorPalette::Private
Definition: color_palette.cpp:32
color_widgets::ColorPalette::colorAt
Q_INVOKABLE QColor colorAt(int index) const
Color at the given index.
Definition: color_palette.cpp:113
color_widgets::ColorPalette::nameChanged
void nameChanged(const QString &)
color_widgets::ColorPalette::setDirty
void setDirty(bool dirty)
Definition: color_palette.cpp:467
color_widgets::ColorPalette::dirty
bool dirty
Whether it has been modified and it might be advisable to save it.
Definition: color_palette.hpp:61
color_widgets::ColorPalette::emitUpdate
void emitUpdate()
Emit all the necessary signals when the palette has been completely overwritten.
Definition: color_palette.cpp:104
color_widgets::ColorPalette::dirtyChanged
void dirtyChanged(bool)
color_widgets::ColorPalette::onlyColors
QVector< QColor > onlyColors() const
Definition: color_palette.cpp:473
color_widgets::ColorPalette::load
Q_INVOKABLE bool load(const QString &name)
Load contents from a Gimp palette (gpl) file.
Definition: color_palette.cpp:186
color_widgets::ColorPalette::colorRemoved
void colorRemoved(int index)
Emitted when the color at the given index has been removed.
color_widgets::ColorPalette::fromColorTable
static ColorPalette fromColorTable(const QVector< QRgb > &table)
Creates a ColorPalette from a color table.
Definition: color_palette.cpp:491
color_widgets::ColorPalette::setNameAt
void setNameAt(int index, const QString &name=QString())
Change the name of a color.
Definition: color_palette.cpp:369
color_widgets::ColorPalette::appendColor
void appendColor(const QColor &color, const QString &name=QString())
Append a color at the end.
Definition: color_palette.cpp:382
color_widgets::ColorPalette::colorTable
Q_INVOKABLE QVector< QRgb > colorTable() const
Convert to a color table.
Definition: color_palette.cpp:482
color_widgets::ColorPalette::value_type
QPair< QColor, QString > value_type
Definition: color_palette.hpp:64
color_widgets::ColorPalette::setColorAt
void setColorAt(int index, const QColor &color)
Change the color at the given index.
Definition: color_palette.cpp:345
color_widgets::ColorPalette::colorAdded
void colorAdded(int index)
Emitted when a single color has been added.


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:22