Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_minimal_shade_selector.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
9#include <QColor>
10#include <QVBoxLayout>
11#include <QPainter>
12#include <QMouseEvent>
13#include <QApplication>
14
15#include <kconfig.h>
16#include <kconfiggroup.h>
17#include <ksharedconfig.h>
18
20
22
24
25
27 : KisColorSelectorBase(parent)
28 , m_canvas(0)
29 , m_proxy(new KisColorSelectorBaseProxyObject(this))
30{
31 setAcceptDrops(true);
32
33 QVBoxLayout* l = new QVBoxLayout(this);
34 l->setSpacing(0);
35 l->setContentsMargins(0, 0, 0, 0);
36
38
39 setMouseTracking(true);
40}
41
45
51
57
59{
60 m_lastRealColor = color;
61
62 for(int i=0; i<m_shadingLines.size(); i++) {
63 m_shadingLines.at(i)->setColor(color);
64 }
65}
66
68{
70 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
71
72 QString stri = cfg.readEntry("minimalShadeSelectorLineConfig", "0|0.2|0|0");
73 QStringList strili = stri.split(';', Qt::SkipEmptyParts);
74
75 int lineCount = strili.size();
76 while(lineCount-m_shadingLines.size() > 0) {
77 KisShadeSelectorLine *line = new KisShadeSelectorLine(m_proxy.data(), this);
78 m_shadingLines.append(line);
79 m_shadingLines.last()->setLineNumber(m_shadingLines.size()-1);
80 layout()->addWidget(m_shadingLines.last());
81 }
82 while(lineCount-m_shadingLines.size() < 0) {
83 layout()->removeWidget(m_shadingLines.last());
84 delete m_shadingLines.takeLast();
85 }
86
87 for(int i=0; i<strili.size(); i++) {
88 m_shadingLines.at(i)->fromString(strili.at(i));
89 }
90
91 int lineHeight = cfg.readEntry("minimalShadeSelectorLineHeight", 20);
92 setMinimumHeight(lineCount*lineHeight+2*lineCount);
93 setMaximumHeight(lineCount*lineHeight+2*lineCount);
94
95 for(int i=0; i<m_shadingLines.size(); i++)
96 m_shadingLines.at(i)->updateSettings();
97
98 setPopupBehaviour(false, false);
99}
100
102{
103 Q_FOREACH (KisShadeSelectorLine* line, m_shadingLines) {
104 QMouseEvent newEvent(e->type(),
105 line->mapFromGlobal(e->globalPos()),
106 e->button(),
107 e->buttons(),
108 e->modifiers());
109 if(line->rect().contains(newEvent.pos()))
110 line->mousePressEvent(&newEvent);
111 }
113}
114
116{
117 Q_FOREACH (KisShadeSelectorLine* line, m_shadingLines) {
118 QMouseEvent newEvent(e->type(),
119 line->mapFromGlobal(e->globalPos()),
120 e->button(),
121 e->buttons(),
122 e->modifiers());
123 if(line->rect().contains(newEvent.pos()))
124 line->mouseMoveEvent(&newEvent);
125 }
127}
128
130{
131 Q_FOREACH (KisShadeSelectorLine* line, m_shadingLines) {
132 QMouseEvent newEvent(e->type(),
133 line->mapFromGlobal(e->globalPos()),
134 e->button(),
135 e->buttons(),
136 e->modifiers());
137
138 if(line->rect().contains(newEvent.pos()))
139 line->mouseReleaseEvent(&newEvent);
140 }
142}
143
145{
146 if(m_colorUpdateAllowed==false)
147 return;
148
149 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
150
151 bool onForeground = cfg.readEntry("shadeSelectorUpdateOnForeground", false);
152 bool onBackground = cfg.readEntry("shadeSelectorUpdateOnBackground", true);
153
154 if ((key == KoCanvasResource::ForegroundColor && onForeground)
155 || (key == KoCanvasResource::BackgroundColor && onBackground)) {
156
157 setColor(v.value<KoColor>());
158 }
159}
160
162{
163 QPainter p(this);
164 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
165
166 if (cfg.readEntry("useCustomColorForBackground", false)) {
167 p.fillRect(0,0,width(), height(), cfg.readEntry("customSelectorBackgroundColor", QColor(Qt::gray)));
168 } else {
169 p.fillRect(0,0,width(), height(), qApp->palette().window().color());
170 }
171}
172
const Params2D p
qreal v
Base class for all color selectors, that should support color management and zooming.
virtual void setCanvas(KisCanvas2 *canvas)
void mouseReleaseEvent(QMouseEvent *) override
void mousePressEvent(QMouseEvent *) override
void mouseMoveEvent(QMouseEvent *event) override
void setPopupBehaviour(bool onMouseOver, bool onMouseClick)
void mousePressEvent(QMouseEvent *) override
KisColorSelectorBase * createPopup() const override
void mouseMoveEvent(QMouseEvent *) override
void mouseReleaseEvent(QMouseEvent *) override
QList< KisShadeSelectorLine * > m_shadingLines
void setCanvas(KisCanvas2 *canvas) override
void canvasResourceChanged(int key, const QVariant &v) override
QScopedPointer< KisColorSelectorBaseProxy > m_proxy
void paintEvent(QPaintEvent *) override
void setColor(const KoColor &color) override
void mouseReleaseEvent(QMouseEvent *) override
void mousePressEvent(QMouseEvent *) override
void mouseMoveEvent(QMouseEvent *) override
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.