swatch.hpp
Go to the documentation of this file.
1 
22 #ifndef COLOR_WIDGETS_SWATCH_HPP
23 #define COLOR_WIDGETS_SWATCH_HPP
24 
25 #include <QWidget>
26 #include <QPen>
27 #include "color_palette.hpp"
28 
29 namespace color_widgets {
30 
34 class Swatch : public QWidget
35 {
36  Q_OBJECT
37 
41  Q_PROPERTY(const ColorPalette& palette READ palette WRITE setPalette NOTIFY paletteChanged)
45  Q_PROPERTY(int selected READ selected WRITE setSelected NOTIFY selectedChanged)
46 
50  Q_PROPERTY(QSize colorSize READ colorSize WRITE setColorSize NOTIFY colorSizeChanged)
51 
53 
57  Q_PROPERTY(QPen border READ border WRITE setBorder NOTIFY borderChanged)
58 
69  Q_PROPERTY(int forcedRows READ forcedRows WRITE setForcedRows NOTIFY forcedRowsChanged)
70 
82 
87  Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly NOTIFY readOnlyChanged)
88 
89 
90 public:
92  {
93  Hint,
96  };
97  Q_ENUMS(ColorSizePolicy)
98 
99  Swatch(QWidget* parent = 0);
100  ~Swatch();
101 
102  QSize sizeHint() const Q_DECL_OVERRIDE;
103  QSize minimumSizeHint() const Q_DECL_OVERRIDE;
104 
105  const ColorPalette& palette() const;
107  int selected() const;
111  QColor selectedColor() const;
112 
118  int indexAt(const QPoint& p);
119 
124  QColor colorAt(const QPoint& p);
125 
126  QSize colorSize() const;
128  QPen border() const;
129 
130  int forcedRows() const;
131  int forcedColumns() const;
132 
133  bool readOnly() const;
134 
135 public slots:
136  void setPalette(const ColorPalette& palette);
137  void setSelected(int selected);
138  void clearSelection();
139  void setColorSize(const QSize& colorSize);
141  void setBorder(const QPen& border);
142  void setForcedRows(int forcedRows);
144  void setReadOnly(bool readOnly);
148  void removeSelected();
149 
150 signals:
151  void paletteChanged(const ColorPalette& palette);
152  void selectedChanged(int selected);
153  void colorSelected(const QColor& color);
154  void colorSizeChanged(const QSize& colorSize);
155  void colorSizePolicyChanged(ColorSizePolicy colorSizePolicy);
156  void doubleClicked(int index);
157  void rightClicked(int index);
158  void forcedRowsChanged(int forcedRows);
159  void forcedColumnsChanged(int forcedColumns);
160  void readOnlyChanged(bool readOnly);
161  void borderChanged(const QPen& border);
162 
163 protected:
164  bool event(QEvent* event) Q_DECL_OVERRIDE;
165 
166  void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
167 
168  void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE;
169 
170  void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
171  void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
172  void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
173  void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
174  void wheelEvent(QWheelEvent* event) Q_DECL_OVERRIDE;
175 
176  void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
177  void dragMoveEvent(QDragMoveEvent* event) Q_DECL_OVERRIDE;
178  void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
179  void dropEvent(QDropEvent* event) Q_DECL_OVERRIDE;
180 
181 protected slots:
185  void paletteModified();
186 
187 private:
188  class Private;
189  Private* p;
190 };
191 
192 
193 } // namespace color_widgets
194 #endif // COLOR_WIDGETS_SWATCH_HPP
void forcedRowsChanged(int forcedRows)
void setPalette(const ColorPalette &palette)
Definition: swatch.cpp:299
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:573
void setColorSize(const QSize &colorSize)
Definition: swatch.cpp:670
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:544
A widget drawing a palette.
Definition: swatch.hpp:34
void colorSelected(const QColor &color)
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:562
void readOnlyChanged(bool readOnly)
void colorSizeChanged(const QSize &colorSize)
int indexAt(const QPoint &p)
Color index at the given position within the widget.
Definition: swatch.cpp:275
void selectedChanged(int selected)
void forcedColumnsChanged(int forcedColumns)
int forcedRows() const
bool event(QEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:740
void removeSelected()
Remove the currently seleceted color.
Definition: swatch.cpp:494
void setForcedColumns(int forcedColumns)
Definition: swatch.cpp:702
void paletteModified()
Connected to the internal palette object to keep eveything consistent.
Definition: swatch.cpp:652
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:520
void colorSizePolicyChanged(ColorSizePolicy colorSizePolicy)
int selected() const
QColor colorAt(const QPoint &p)
Color at the given position within the widget.
Definition: swatch.cpp:294
void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:598
void paletteChanged(const ColorPalette &palette)
QSize colorSize() const
void rightClicked(int index)
QPen border() const
QSize sizeHint() const Q_DECL_OVERRIDE
Definition: swatch.cpp:235
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:326
void setSelected(int selected)
Definition: swatch.cpp:307
void setReadOnly(bool readOnly)
Definition: swatch.cpp:731
void borderChanged(const QPen &border)
QColor selectedColor() const
Color at the currently selected index.
Definition: swatch.cpp:270
QSize minimumSizeHint() const Q_DECL_OVERRIDE
Definition: swatch.cpp:248
void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:603
void setColorSizePolicy(ColorSizePolicy colorSizePolicy)
Definition: swatch.cpp:681
int forcedColumns() const
void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:552
void setForcedRows(int forcedRows)
Definition: swatch.cpp:714
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:504
bool readOnly() const
void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:591
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE
Definition: swatch.cpp:399
The size is just a hint.
Definition: swatch.hpp:93
const ColorPalette & palette() const
void setBorder(const QPen &border)
Definition: swatch.cpp:774
Must be exactly as specified.
Definition: swatch.hpp:95
void doubleClicked(int index)
ColorSizePolicy colorSizePolicy() const
Can expand but not contract.
Definition: swatch.hpp:94


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48