JKQtExtras
a library of useful Qt widgets and tools
jkqtecolorsampler.h
1 #ifndef JKQTECOLORSAMPLER_H
2 #define JKQTECOLORSAMPLER_H
3 
4 #include <QWidget>
5 #include "jkqtextras_imexport.h"
6 
7 /*! \brief a widget which display a color (sample)
8  \ingroup JKQtExtrasWidgetsLabels
9 
10  Screenshots:
11  \image html JKQTEColorSampler.png
12 
13  Basic usage is simple:
14 
15  \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEColorSampler
16 
17 */
19 {
20  Q_OBJECT
21  Q_PROPERTY(SamplerMode samplerMode READ samplerMode WRITE setSamplerMode USER true)
22  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
23 public:
24  /** \brief available modes for the slider
25  *
26  * the appearance and the range of the slider depend on this */
27  enum SamplerMode {
28  CircleSampler=0, /**< color is shown as a filled circle \image html JKQTEColorSampler_CircleSampler.png */
29  RectangleSampler, /**< color is shown as a filled rectangle \image html JKQTEColorSampler_RectangleSampler.png */
30  };
31  Q_ENUM(SamplerMode)
32 
33  explicit JKQTEColorSampler(QWidget *parent = nullptr);
34 
35  /** \brief sets the color to display */
36  QColor color() const;
37  /** \brief sets the display mode of the color sampler */
38  SamplerMode samplerMode() const;
39 
40  virtual QSize minimumSizeHint() const override;
41  virtual QSize sizeHint() const override;
42 public slots:
43  /** \brief sets the color to display */
44  void setColor(QColor col);
45  /** \brief sets the display mode of the color sampler */
46  void setSamplerMode(SamplerMode m);
47 signals:
48 
49 protected:
50  QColor m_color;
51  SamplerMode m_samplerMode;
52 
53  /** \brief paints the sampler */
54  virtual void paintEvent(QPaintEvent *ev) override;
55 };
56 
57 #endif // JKQTECOLORSAMPLER_H
JKQTEColorSampler::RectangleSampler
@ RectangleSampler
Definition: jkqtecolorsampler.h:29
JKQTEColorSampler::SamplerMode
SamplerMode
available modes for the slider
Definition: jkqtecolorsampler.h:27
JKQTEXTRAS_LIB_EXPORT
#define JKQTEXTRAS_LIB_EXPORT
Definition: jkqtextras_imexport.h:95
JKQTEColorSampler
a widget which display a color (sample)
Definition: jkqtecolorsampler.h:19