SMIL  1.1
ColorPicker.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef COLORPICKER_H
30 #define COLORPICKER_H
31 
32 #include <QPushButton>
33 #include <QColor>
34 #include <QGridLayout>
35 #include <QEventLoop>
36 #include <QLabel>
37 #include <QEvent>
38 #include <QFocusEvent>
39 
40 class ColorButton : public QPushButton
41 {
42  Q_OBJECT
43 public:
44  ColorButton(QWidget* parent = 0);
45  ~ColorButton();
46 
47  QColor getColor()
48  {
49  return color;
50  }
51  int colorIndex;
52 public slots:
53  virtual void setColor(const QColor &col, const int index=-1);
54 
55 signals:
56  void colorChosen(ColorButton *button);
57 
58 protected:
59  int iconSize;
60  void paintEvent(QPaintEvent *e);
61 
62 private slots:
63  void buttonPressed(bool toggled);
64 
65 private:
66  QColor color;
67 };
68 
69 
70 
71 class ColorPannel : public QFrame
72 {
73  Q_OBJECT
74 
75 public:
76  ColorPannel(QWidget *parent=NULL);
77  ~ColorPannel();
78 
79  void setColors(const QVector<QRgb> &cols);
80 
81 signals:
82  void colorSelected(const QColor &, const int &index);
83  void onHide();
84 
85 protected slots:
86  void colorButtonSelected(ColorButton *button);
87 private:
88  QGridLayout *grid;
89 protected:
90  QVector<QRgb> colors;
91  void hideEvent(QHideEvent *e);
92  void clearGrid();
93  ColorButton *lastButtonSelected;
94 };
95 
96 
97 
98 class ColorPicker : public ColorButton
99 {
100  Q_OBJECT
101 
102 
103 public:
104  ColorPicker(QWidget *parent = 0);
105 
106  ~ColorPicker();
107 
108  void setColors(const QVector<QRgb> &cols);
109 
110  void popup();
111 
112 protected slots:
113  void colorSelected(const QColor &, const int &index);
114 
115  signals:
116  void colorChanged(const QColor &);
117 
118 protected:
119  ColorPannel *pannel;
120 
121 private slots:
122  void buttonPressed(bool toggled);
123  void pannelClosed();
124 
125 private:
126 };
127 
128 #endif
Definition: ColorPicker.h:41
Definition: ColorPicker.h:72
Definition: ColorPicker.h:99