Changeset View
Changeset View
Standalone View
Standalone View
plugins/tools/basictools/kis_tool_colorpicker.h
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (c) 1999 Matthias Elter <elter@kde.org> | 2 | * Copyright (c) 1999 Matthias Elter <elter@kde.org> | ||
3 | * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> | 3 | * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> | ||
4 | * Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com> | 4 | * Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com> | ||
5 | * Copyright (c) 2018 Emmet & Eoin O'Neill <emmetoneill.pdx@gmail.com> | ||||
5 | * | 6 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | 10 | * (at your option) any later version. | ||
10 | * | 11 | * | ||
11 | * This program is distributed in the hope that it will be useful, | 12 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
15 | * | 16 | * | ||
16 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | */ | 20 | */ | ||
20 | 21 | | |||
21 | #ifndef KIS_TOOL_COLOR_PICKER_H_ | 22 | #ifndef KIS_TOOL_COLOR_PICKER_H_ | ||
22 | #define KIS_TOOL_COLOR_PICKER_H_ | 23 | #define KIS_TOOL_COLOR_PICKER_H_ | ||
23 | 24 | | |||
24 | #include <QList> | | |||
25 | #include <QTimer> | 25 | #include <QTimer> | ||
26 | | ||||
27 | #include "KoToolFactoryBase.h" | 26 | #include "KoToolFactoryBase.h" | ||
28 | #include "ui_wdgcolorpicker.h" | 27 | #include "ui_wdgcolorpicker.h" | ||
29 | #include "kis_tool.h" | 28 | #include "kis_tool.h" | ||
30 | #include <flake/kis_node_shape.h> | | |||
31 | #include <KoIcon.h> | | |||
32 | #include <kis_icon.h> | 29 | #include <kis_icon.h> | ||
33 | #include <QKeySequence> | | |||
34 | 30 | | |||
35 | class KoResource; | 31 | class KoResource; | ||
36 | class KoColorSet; | 32 | class KoColorSet; | ||
37 | 33 | | |||
38 | namespace KisToolUtils { | 34 | namespace KisToolUtils { | ||
39 | struct ColorPickerConfig; | 35 | struct ColorPickerConfig; | ||
40 | } | 36 | } | ||
41 | 37 | | |||
42 | class ColorPickerOptionsWidget : public QWidget, public Ui::ColorPickerOptionsWidget | 38 | class ColorPickerOptionsWidget : public QWidget, public Ui::ColorPickerOptionsWidget | ||
43 | { | 39 | { | ||
44 | Q_OBJECT | 40 | Q_OBJECT | ||
45 | 41 | | |||
46 | public: | 42 | public: | ||
47 | ColorPickerOptionsWidget(QWidget *parent) : QWidget(parent) { | 43 | ColorPickerOptionsWidget(QWidget *parent) : QWidget(parent) { | ||
48 | setupUi(this); | 44 | setupUi(this); | ||
49 | } | 45 | } | ||
50 | }; | 46 | }; | ||
51 | 47 | | |||
52 | class KisToolColorPicker : public KisTool | 48 | class KisToolColorPicker : public KisTool | ||
53 | { | 49 | { | ||
54 | | ||||
55 | Q_OBJECT | 50 | Q_OBJECT | ||
56 | Q_PROPERTY(bool toForeground READ toForeground WRITE setToForeground NOTIFY toForegroundChanged) | 51 | Q_PROPERTY(bool toForeground READ toForeground WRITE setToForeground NOTIFY toForegroundChanged) | ||
57 | 52 | | |||
58 | public: | 53 | public: | ||
59 | KisToolColorPicker(KoCanvasBase* canvas); | 54 | KisToolColorPicker(KoCanvasBase *canvas); | ||
60 | ~KisToolColorPicker() override; | 55 | ~KisToolColorPicker() override; | ||
61 | 56 | | |||
62 | public: | 57 | public: | ||
63 | struct Configuration { | 58 | struct Configuration { | ||
64 | Configuration(); | 59 | Configuration(); | ||
65 | 60 | | |||
66 | bool toForegroundColor; | 61 | bool toForegroundColor; | ||
67 | bool updateColor; | 62 | bool updateColor; | ||
68 | bool addPalette; | 63 | bool addPalette; | ||
69 | bool normaliseValues; | 64 | bool normaliseValues; | ||
70 | bool sampleMerged; | 65 | bool sampleMerged; | ||
71 | int radius; | 66 | int radius; | ||
67 | int blend; | ||||
72 | 68 | | |||
73 | void save(ToolActivation activation) const; | 69 | void save(ToolActivation activation) const; | ||
74 | void load(ToolActivation activation); | 70 | void load(ToolActivation activation); | ||
75 | }; | 71 | }; | ||
76 | 72 | | |||
77 | public: | 73 | public: | ||
78 | QWidget* createOptionWidget() override; | 74 | QWidget* createOptionWidget() override; | ||
79 | 75 | | |||
80 | void beginPrimaryAction(KoPointerEvent *event) override; | 76 | void beginPrimaryAction(KoPointerEvent *event) override; | ||
81 | void continuePrimaryAction(KoPointerEvent *event) override; | 77 | void continuePrimaryAction(KoPointerEvent *event) override; | ||
82 | void endPrimaryAction(KoPointerEvent *event) override; | 78 | void endPrimaryAction(KoPointerEvent *event) override; | ||
83 | 79 | | |||
84 | void paint(QPainter& gc, const KoViewConverter &converter) override; | 80 | void paint(QPainter &gc, const KoViewConverter &converter) override; | ||
85 | 81 | | |||
86 | bool toForeground() const; | 82 | bool toForeground() const; | ||
87 | 83 | | |||
88 | Q_SIGNALS: | 84 | Q_SIGNALS: | ||
89 | void toForegroundChanged(); | 85 | void toForegroundChanged(); | ||
90 | 86 | | |||
91 | protected: | 87 | protected: | ||
92 | void activate(ToolActivation activation, const QSet<KoShape*> &) override; | 88 | void activate(ToolActivation activation, const QSet<KoShape*> &) override; | ||
93 | void deactivate() override; | 89 | void deactivate() override; | ||
94 | 90 | | |||
95 | public Q_SLOTS: | 91 | public Q_SLOTS: | ||
96 | void setToForeground(bool newValue); | 92 | void setToForeground(bool newValue); | ||
97 | void slotSetUpdateColor(bool); | 93 | void slotSetUpdateColor(bool); | ||
98 | void slotSetNormaliseValues(bool); | 94 | void slotSetNormaliseValues(bool); | ||
99 | void slotSetAddPalette(bool); | 95 | void slotSetAddPalette(bool); | ||
100 | void slotChangeRadius(int); | 96 | void slotChangeRadius(int); | ||
97 | void slotChangeBlend(int); | ||||
101 | void slotAddPalette(KoResource* resource); | 98 | void slotAddPalette(KoResource* resource); | ||
102 | void slotSetColorSource(int value); | 99 | void slotSetColorSource(int value); | ||
103 | 100 | | |||
104 | private: | 101 | private: | ||
105 | void displayPickedColor(); | 102 | void displayPickedColor(); | ||
106 | void pickColor(const QPointF& pos); | 103 | void pickColor(const QPointF& pos); | ||
107 | void updateOptionWidget(); | 104 | void updateOptionWidget(); | ||
108 | 105 | | |||
109 | //Configuration m_config; | 106 | // Configuration | ||
110 | QScopedPointer<KisToolUtils::ColorPickerConfig> m_config; | 107 | QScopedPointer<KisToolUtils::ColorPickerConfig> m_config; | ||
108 | | ||||
111 | ToolActivation m_toolActivationSource; | 109 | ToolActivation m_toolActivationSource; | ||
112 | bool m_isActivated; | 110 | bool m_isActivated; | ||
113 | 111 | | |||
114 | KoColor m_pickedColor; | 112 | KoColor m_pickedColor; | ||
115 | 113 | | |||
116 | // used to skip some of the tablet events and don't update the colour that often | 114 | // Used to skip some tablet events and update color less often | ||
117 | QTimer m_colorPickerDelayTimer; | 115 | QTimer m_colorPickerDelayTimer; | ||
118 | 116 | | |||
119 | ColorPickerOptionsWidget *m_optionsWidget; | 117 | ColorPickerOptionsWidget *m_optionsWidget; | ||
120 | 118 | | |||
121 | QList<KoColorSet*> m_palettes; | 119 | QList<KoColorSet*> m_palettes; | ||
122 | }; | 120 | }; | ||
123 | 121 | | |||
124 | class KisToolColorPickerFactory : public KoToolFactoryBase | 122 | class KisToolColorPickerFactory : public KoToolFactoryBase | ||
125 | { | 123 | { | ||
126 | | ||||
127 | public: | 124 | public: | ||
128 | KisToolColorPickerFactory() | 125 | KisToolColorPickerFactory() | ||
129 | : KoToolFactoryBase("KritaSelected/KisToolColorPicker") { | 126 | : KoToolFactoryBase("KritaSelected/KisToolColorPicker") { | ||
130 | setToolTip(i18n("Color Selector Tool")); | 127 | setToolTip(i18n("Color Selector Tool")); | ||
131 | setSection(TOOL_TYPE_FILL); | 128 | setSection(TOOL_TYPE_FILL); | ||
132 | setPriority(2); | 129 | setPriority(2); | ||
133 | setIconName(koIconNameCStr("krita_tool_color_picker")); | 130 | setIconName(koIconNameCStr("krita_tool_color_picker")); | ||
134 | setShortcut(QKeySequence(Qt::Key_P)); | 131 | setShortcut(QKeySequence(Qt::Key_P)); | ||
135 | setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); | 132 | setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); | ||
136 | } | 133 | } | ||
137 | 134 | | |||
138 | ~KisToolColorPickerFactory() override {} | 135 | ~KisToolColorPickerFactory() override {} | ||
139 | 136 | | |||
140 | KoToolBase * createTool(KoCanvasBase *canvas) override { | 137 | KoToolBase *createTool(KoCanvasBase *canvas) override { | ||
141 | return new KisToolColorPicker(canvas); | 138 | return new KisToolColorPicker(canvas); | ||
142 | } | 139 | } | ||
143 | }; | 140 | }; | ||
144 | 141 | | |||
145 | | ||||
146 | #endif // KIS_TOOL_COLOR_PICKER_H_ | 142 | #endif // KIS_TOOL_COLOR_PICKER_H_ | ||
147 | |