1 /*
2  *  Copyright (c) 2010 Adam Celarek <kdedev at xibo dot at>
3  *
4  *  This library is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation; version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KIS_COLOR_PATCHES_H
20 #define KIS_COLOR_PATCHES_H
21 
22 #include "kis_color_selector_base.h"
23 
24 #include "KoColor.h"
25 
26 class KoColor;
27 
28 
29 class KisColorPatches : public KisColorSelectorBase
30 {
31 Q_OBJECT
32 public:
33     explicit KisColorPatches(QString configPrefix, QWidget *parent = 0);
34     enum Direction { Horizontal, Vertical };
35 
36 public Q_SLOTS:
37     void updateSettings() override;
38 
39 protected:
40     void setColors(QList<KoColor> colors);
colors()41     QList<KoColor> colors() const {return m_colors;}
42 
43     void paintEvent(QPaintEvent *) override;
44     void wheelEvent(QWheelEvent *) override;
45     void resizeEvent(QResizeEvent *) override;
46     void mouseReleaseEvent(QMouseEvent *) override;
47     void mousePressEvent(QMouseEvent *) override;
48     void mouseMoveEvent(QMouseEvent *) override;
49     int patchCount() const;
50     bool colorAt(const QPoint &, KoColor *result) const;
51 
52 public:
53     /// set buttons, that should be drawn additionally to the patches
54     /// this class takes ownership of them and will delete them
55     /// they will be resized to the patchsize
56     void setAdditionalButtons(QList<QWidget*> buttonList);
57 
58 private:
59     int m_patchWidth;
60     int m_patchHeight;
61     int m_patchCount;
62     QList<KoColor> m_colors;
63     bool m_allowColorListChangeGuard;
64     int m_scrollValue;
65 
66     Direction m_direction;
67     bool m_allowScrolling;
68     int m_numCols;
69     int m_numRows;
70     QList<QWidget*> m_buttonList;
71 
72     /// returns width of the patchfield, if there are only m_numRows allowed
73     int widthOfAllPatches();
74     /// returns height of the patchfield, if there are only m_numCols allowed
75     int heightOfAllPatches();
76 
77     /// returns height, that is needed to display all patches with the given width
78     int heightForWidth(int width) const override;
79     /// returns width, that is needed to display all patches with the given height
80     int widthForHeight(int height) const;
81 
82     /// returns count of colors and buttons
83     int fieldCount() const;
84 
85     QString m_configPrefix;
86 
87     QPoint m_dragStartPos;
88 };
89 
90 #endif
91