color_palette.hpp
Go to the documentation of this file.
00001 
00022 #ifndef COLOR_WIDGETS_COLOR_PALETTE_HPP
00023 #define COLOR_WIDGETS_COLOR_PALETTE_HPP
00024 
00025 #include <QColor>
00026 #include <QString>
00027 #include <QVector>
00028 #include <QObject>
00029 #include <QPair>
00030 #include <QPixmap>
00031 
00032 namespace color_widgets {
00033 
00034 class  ColorPalette : public QObject
00035 {
00036     Q_OBJECT
00037 
00041     Q_PROPERTY(QVector<value_type> colors READ colors WRITE setColors NOTIFY colorsChanged)
00045     Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
00049     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
00053     Q_PROPERTY(int count READ count)
00057     Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
00061     Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
00062 
00063 public:
00064     typedef QPair<QColor,QString> value_type;
00065 
00066     ColorPalette(const QVector<QColor>& colors, const QString& name = QString(), int columns = 0);
00067     ColorPalette(const QVector<QPair<QColor,QString> >& colors, const QString& name = QString(), int columns = 0);
00068     explicit ColorPalette(const QString& name = QString());
00069     ColorPalette(const ColorPalette& other);
00070     ColorPalette& operator=(const ColorPalette& other);
00071     ~ColorPalette();
00072     ColorPalette(ColorPalette&& other);
00073     ColorPalette& operator=(ColorPalette&& other);
00074 
00078     Q_INVOKABLE QColor colorAt(int index) const;
00079 
00083     Q_INVOKABLE QString nameAt(int index) const;
00084 
00085     QVector<QPair<QColor,QString> > colors() const;
00086     QVector<QColor> onlyColors() const;
00087 
00088     int count() const;
00089     int columns();
00090 
00091     QString name() const;
00092 
00096     Q_INVOKABLE void loadColorTable(const QVector<QRgb>& color_table);
00097 
00101     Q_INVOKABLE QVector<QRgb> colorTable() const;
00102     
00106     static ColorPalette fromColorTable(const QVector<QRgb>& table);
00107 
00111     Q_INVOKABLE bool loadImage(const QImage& image);
00112 
00116     static ColorPalette fromImage(const QImage& image);
00117 
00123     Q_INVOKABLE bool load(const QString& name);
00124 
00128     static ColorPalette fromFile(const QString& name);
00129 
00130     QString fileName() const;
00131 
00132     bool dirty() const;
00133 
00137     QPixmap preview(const QSize& size, const QColor& background=Qt::transparent) const;
00138 
00139 public slots:
00140     void setColumns(int columns);
00141 
00142     void setColors(const QVector<QColor>& colors);
00143     void setColors(const QVector<QPair<QColor,QString> >& colors);
00144 
00148     void setColorAt(int index, const QColor& color);
00152     void setColorAt(int index, const QColor& color, const QString& name);
00156     void setNameAt(int index, const QString& name = QString());
00160     void appendColor(const QColor& color, const QString& name = QString());
00164     void insertColor(int index, const QColor& color, const QString& name = QString());
00168     void eraseColor(int index);
00169 
00174     bool save(const QString& filename);
00179     bool save();
00180 
00181     void setName(const QString& name);
00182     void setFileName(const QString& name);
00183     void setDirty(bool dirty);
00184 
00185 signals:
00189     void colorsChanged(const QVector<QPair<QColor,QString> >&);
00190     void columnsChanged(int);
00191     void nameChanged(const QString&);
00192     void fileNameChanged(const QString&);
00193     void dirtyChanged(bool);
00197     void colorChanged(int index);
00201     void colorRemoved(int index);
00205     void colorAdded(int index);
00209     void colorsUpdated(const QVector<QPair<QColor,QString>>&);
00210 
00211 private:
00215     QString unnamed(const QString& name = QString()) const;
00216 
00220     void emitUpdate();
00221 
00222     class Private;
00223     Private *p;
00224 };
00225 
00226 } // namespace color_widgets
00227 
00228 #endif // COLOR_WIDGETS_COLOR_PALETTE_HPP


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:55