Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_color_selector_ng_docker_widget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Adam Celarek <kdedev at xibo dot at>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8#include "ui_wdg_color_selector_settings.h"
9
10#include <QVBoxLayout>
11#include <QHBoxLayout>
12#include <QToolButton>
13
14#include <kconfig.h>
15#include <kconfiggroup.h>
16#include <ksharedconfig.h>
17#include <kis_icon_utils.h>
18
19#include <QAction>
20#include <kactioncollection.h>
21
22#include "kis_canvas2.h"
23#include "KisViewManager.h"
24#include "kis_node_manager.h"
27#include "kis_config_notifier.h"
29#include "kis_node.h"
30#include "kis_paint_device.h"
31#include "KisMainWindow.h"
32
33#include "kis_color_history.h"
34#include "kis_common_colors.h"
37
38#include "kis_action_registry.h"
39
41 QWidget(parent),
42 m_colorHistoryAction(0),
43 m_commonColorsAction(0),
44 m_widgetLayout(0),
45 m_mainLayout(0),
46 m_horizontalPatchesContainer(0),
47 m_sidebarLayout(0),
48 m_verticalColorPatchesLayout(0),
49 m_horizontalColorPatchesLayout(0),
50 m_fallbackSettingsButton(new QToolButton(this)),
51 m_canvas(0)
52{
53 setAutoFillBackground(true);
54
58
59 //default settings
60 //remember to also change the default in the ui file
61
62 //shade selector
63
64 // fallback settings button when the color selector is disabled
66 m_fallbackSettingsButton->setIconSize(QSize(22,22));
67 m_fallbackSettingsButton->setAutoRaise(true);
69
70 //layout
71 m_widgetLayout = new QHBoxLayout(this);
72 m_widgetLayout->setSpacing(0);
73 m_widgetLayout->setContentsMargins(0, 0, 0, 0);
74
75 m_mainLayout = new QVBoxLayout();
76 m_mainLayout->setSpacing(0);
77 m_mainLayout->setContentsMargins(0, 0, 0, 0);
78
79 m_horizontalPatchesContainer = new QHBoxLayout();
80 m_horizontalPatchesContainer->setSpacing(0);
81 m_horizontalPatchesContainer->setContentsMargins(0, 0, 0, 0);
82
83 m_sidebarLayout = new QVBoxLayout();
84 m_sidebarLayout->setSpacing(0);
85 m_sidebarLayout->setContentsMargins(0, 0, 0, 0);
86
87 m_verticalColorPatchesLayout = new QHBoxLayout();
88 m_verticalColorPatchesLayout->setSpacing(0);
89 m_verticalColorPatchesLayout->setContentsMargins(0, 0, 0, 0);
90
91 m_horizontalColorPatchesLayout = new QVBoxLayout();
92 m_horizontalColorPatchesLayout->setSpacing(0);
93 m_horizontalColorPatchesLayout->setContentsMargins(0, 0, 0, 0);
94
96
99
101
102 m_widgetLayout->addLayout(m_mainLayout);
104
105 updateLayout();
106
108
109 //Q_EMIT settingsChanged() if the settings are changed in krita preferences
112 dynamic_cast<KisColorSelectorSettingsFactory*>(preferenceSetRegistry->get("KisColorSelectorSettingsFactory"));
113 Q_ASSERT(factory);
114 connect(&(factory->repeater), SIGNAL(settingsUpdated()), this, SIGNAL(settingsChanged()), Qt::UniqueConnection);
115 connect(this, SIGNAL(settingsChanged()), this, SLOT(updateLayout()), Qt::UniqueConnection);
116 connect(this, SIGNAL(settingsChanged()), m_commonColorsWidget, SLOT(updateSettings()), Qt::UniqueConnection);
117 connect(this, SIGNAL(settingsChanged()), m_colorHistoryWidget, SLOT(updateSettings()), Qt::UniqueConnection);
118 connect(this, SIGNAL(settingsChanged()), m_colorSelectorContainer, SIGNAL(settingsChanged()), Qt::UniqueConnection);
119 connect(this, SIGNAL(settingsChanged()), this, SLOT(update()), Qt::UniqueConnection);
120
121
122 Q_EMIT settingsChanged();
123
124 m_colorHistoryAction = KisActionRegistry::instance()->makeQAction("show_color_history", this);
125 connect(m_colorHistoryAction, SIGNAL(triggered()), m_colorHistoryWidget, SLOT(showPopup()), Qt::UniqueConnection);
126
127 m_commonColorsAction = KisActionRegistry::instance()->makeQAction("show_common_colors", this);
128 connect(m_commonColorsAction, SIGNAL(triggered()), m_commonColorsWidget, SLOT(showPopup()), Qt::UniqueConnection);
129
130 connect(m_fallbackSettingsButton, SIGNAL(clicked()), this, SLOT(openSettings()));
131}
132
140
142{
143 if (m_canvas) {
144 m_canvas->disconnect(this);
145 KisKActionCollection *ac = m_canvas->viewManager()->actionCollection();
146 ac->takeAction(ac->action("show_color_history"));
147 ac->takeAction(ac->action("show_common_colors"));
148 }
149
150 m_canvas = canvas;
151
155
156 if (m_canvas && m_canvas->viewManager()) {
157 KisKActionCollection* actionCollection = canvas->viewManager()->actionCollection();
158
159 actionCollection->addAction("show_color_history", m_colorHistoryAction);
160 actionCollection->addAction("show_common_colors", m_commonColorsAction);
161
162 connect(m_canvas->viewManager()->mainWindow(), SIGNAL(themeChanged()), m_colorSelectorContainer, SLOT(slotUpdateIcons()), Qt::UniqueConnection);
163 }
164
165}
166
168{
169 if (!m_canvas) return;
170
172 if(settings.exec()==QDialog::Accepted) {
173 Q_EMIT settingsChanged();
175 }
176}
177
178
180{
181 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
182
183 bool showColorSelector = (bool) cfg.readEntry("showColorSelector", true);
184
185 //color patches
186 bool m_lastColorsShow = cfg.readEntry("lastUsedColorsShow", true);
187 KisColorPatches::Direction m_lastColorsDirection;
188 if(cfg.readEntry("lastUsedColorsAlignment", false))
189 m_lastColorsDirection=KisColorPatches::Vertical;
190 else
191 m_lastColorsDirection=KisColorPatches::Horizontal;
192
193 bool m_commonColorsShow = cfg.readEntry("commonColorsShow", true);
194 KisColorPatches::Direction m_commonColorsDirection;
195 if(cfg.readEntry("commonColorsAlignment", false))
196 m_commonColorsDirection=KisColorPatches::Vertical;
197 else
198 m_commonColorsDirection=KisColorPatches::Horizontal;
199
204
207
208 if (m_lastColorsShow == false) {
209 m_colorHistoryWidget->hide();
210 } else {
211 m_colorHistoryWidget->show();
212 }
213
214 if(m_commonColorsShow==false) {
215 m_commonColorsWidget->hide();
216 }
217 else {
218 m_commonColorsWidget->show();
219 }
220
221
222 bool fallbackSettingsButtonVertical = true;
223
224 if(m_lastColorsShow && m_lastColorsDirection==KisColorPatches::Vertical) {
226 }
227
228 if(m_commonColorsShow && m_commonColorsDirection==KisColorPatches::Vertical) {
230 }
231
232 if(m_lastColorsShow && m_lastColorsDirection==KisColorPatches::Horizontal) {
234 fallbackSettingsButtonVertical = false;
235 }
236
237 if(m_commonColorsShow && m_commonColorsDirection==KisColorPatches::Horizontal) {
239 fallbackSettingsButtonVertical = false;
240 }
241
242 // prefer the vertical column, if patch components have different layout
243 if (m_commonColorsDirection != m_lastColorsDirection) {
244 fallbackSettingsButtonVertical = true;
245 }
246
247 if (!showColorSelector) {
248 if (fallbackSettingsButtonVertical) {
250 } else {
252 }
253
255 } else {
257 }
258
259 updateGeometry();
260}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QAction * makeQAction(const QString &name, QObject *parent=0)
static KisActionRegistry * instance()
KisViewManager * viewManager() const
void setCanvas(KisCanvas2 *canvas) override
void unsetCanvas() override
KisColorSelectorSettingsUpdateRepeater repeater
void unsetCanvas() override
void setCanvas(KisCanvas2 *canvas) override
static KisConfigNotifier * instance()
A container for a set of QAction objects.
QAction * takeAction(QAction *action)
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
QAction * action(int index) const
static KisPreferenceSetRegistry * instance()
virtual KisKActionCollection * actionCollection() const
T get(const QString &id) const
QIcon loadIcon(const QString &name)