Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSetWidget.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007, 2012 C. Boemann <cbo@boemann.dk>
3 SPDX-FileCopyrightText: 2007-2008 Fredy Yanardi <fyanardi@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#include "KoColorSetWidget.h"
9
10#include <QApplication>
11#include <QSize>
12#include <QHBoxLayout>
13#include <QCheckBox>
14#include <QFrame>
15#include <QLabel>
16#include <QMouseEvent>
17#include <QWidgetAction>
18#include <QDir>
19#include <QScrollArea>
20#include <QGroupBox>
21#include <QVBoxLayout>
22
23#include <klocalizedstring.h>
24#include <ksharedconfig.h>
25
27#include <KoColorPatch.h>
29#include <KoResourceServer.h>
31
32#include <kis_palette_view.h>
33#include <KisPaletteDelegate.h>
34#include <KisPaletteModel.h>
35#include <kis_icon_utils.h>
36
37void KoColorSetWidget::KoColorSetWidgetPrivate::addRecent(const KoColor &color)
38{
39 if(numRecents < 6) {
40 recentPatches[numRecents] = new KoColorPatch(thePublic);
41 recentPatches[numRecents]->setFrameShape(QFrame::StyledPanel);
42 recentPatches[numRecents]->setDisplayRenderer(displayRenderer);
43 recentsLayout->insertWidget(numRecents + 1, recentPatches[numRecents]);
44 connect(recentPatches[numRecents], SIGNAL(triggered(KoColorPatch*)), thePublic, SLOT(slotPatchTriggered(KoColorPatch*)));
45 numRecents++;
46 }
47 // shift colors to the right
48 for (int i = numRecents- 1; i >0; i--) {
49 recentPatches[i]->setColor(recentPatches[i-1]->color());
50 }
51
52 //Finally set the recent color
53 recentPatches[0]->setColor(color);
54}
55
56void KoColorSetWidget::KoColorSetWidgetPrivate::activateRecent(int i)
57{
58 KoColor color = recentPatches[i]->color();
59
60 while (i >0) {
61 recentPatches[i]->setColor(recentPatches[i-1]->color());
62 i--;
63 }
64 recentPatches[0]->setColor(color);
65}
66
68 : QFrame(parent)
69 , d(new KoColorSetWidgetPrivate())
70{
71 d->thePublic = this;
72
73 d->numRecents = 0;
74 d->recentsLayout = new QHBoxLayout;
75 d->recentsLayout->setContentsMargins(0, 0, 0, 0);
76 d->recentsLayout->addWidget(new QLabel(i18n("Recent:")));
77 d->recentsLayout->addStretch(1);
78
80 color.fromQColor(QColor(128,0,0));
81 d->addRecent(color);
82
83 d->paletteView = new KisPaletteView(this);
84 KisPaletteModel *paletteModel = new KisPaletteModel(d->paletteView);
85 d->paletteView->setPaletteModel(paletteModel);
86 d->paletteView->setDisplayRenderer(d->displayRenderer);
87
88 d->paletteChooser = new KisPaletteChooser(this);
89 d->paletteChooserButton = new KisPopupButton(this);
90 d->paletteChooserButton->setPopupWidget(d->paletteChooser);
91 d->paletteChooserButton->setIcon(KisIconUtils::loadIcon("palette-library"));
92 d->paletteChooserButton->setToolTip(i18n("Choose palette"));
93
94 d->colorNameCmb = new KisPaletteComboBox(this);
95 d->colorNameCmb->setCompanionView(d->paletteView);
96
97 d->bottomLayout = new QHBoxLayout;
98 d->bottomLayout->addWidget(d->paletteChooserButton);
99 d->bottomLayout->addWidget(d->colorNameCmb);
100 d->bottomLayout->setStretch(0, 0); // minimize chooser button
101 d->bottomLayout->setStretch(1, 1); // maximize color name cmb
102
103 d->mainLayout = new QVBoxLayout(this);
104 d->mainLayout->setContentsMargins(4, 4, 4, 4);
105 d->mainLayout->setSpacing(2);
106 d->mainLayout->addLayout(d->recentsLayout);
107 d->mainLayout->addWidget(d->paletteView);
108 d->mainLayout->addLayout(d->bottomLayout);
109
110 connect(d->paletteChooser, SIGNAL(sigPaletteSelected(KoColorSetSP)), SLOT(slotPaletteChosen(KoColorSetSP)));
111 connect(d->paletteView, SIGNAL(sigColorSelected(KoColor)), SLOT(slotColorSelectedByPalette(KoColor)));
112 connect(d->colorNameCmb, SIGNAL(sigColorSelected(KoColor)), SLOT(slotNameListSelection(KoColor)));
113
115 KoColorSetSP defaultColorSet = d->rServer->resource("", "", "Default");
116 if (!defaultColorSet && d->rServer->resourceCount() > 0) {
117 defaultColorSet = d->rServer->firstResource();
118 }
119 setColorSet(defaultColorSet);
120}
121
126
128{
129 if (!colorSet) return;
130 if (colorSet == d->colorSet) return;
131
132 d->paletteView->paletteModel()->setColorSet(colorSet);
133 d->colorSet = colorSet;
134}
135
137{
138 return d->colorSet;
139}
140
142{
143 if (displayRenderer) {
144 d->displayRenderer = displayRenderer;
145 for (int i=0; i<6; i++) {
146 if (d->recentPatches[i]) {
147 d->recentPatches[i]->setDisplayRenderer(displayRenderer);
148 }
149 }
150 }
151}
152
153void KoColorSetWidget::resizeEvent(QResizeEvent *event)
154{
155 Q_EMIT widgetSizeChanged(event->size());
156 QFrame::resizeEvent(event);
157}
158
160{
161 Q_EMIT colorChanged(color, true);
162 d->addRecent(color);
163}
164
166{
167 Q_EMIT colorChanged(patch->color(), true);
168
169 int i;
170
171 for (i = 0; i < d->numRecents; i++) {
172 if(patch == d->recentPatches[i]) {
173 d->activateRecent(i);
174 break;
175 }
176 }
177
178 if (i == d->numRecents) { // we didn't find it above
179 d->addRecent(patch->color());
180 }
181}
182
184{
185 d->colorSet = colorSet;
186 d->paletteView->paletteModel()->setColorSet(colorSet);
187}
188
190{
191 Q_EMIT colorChanged(color, true);
192}
193
194//have to include this because of Q_PRIVATE_SLOT
195#include "moc_KoColorSetWidget.cpp"
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisPaletteComboBox class A combobox used with KisPaletteView.
The KisPaletteModel class This, together with KisPaletteView and KisPaletteDelegate forms a mvc way t...
KoColor color() const
void slotPaletteChosen(KoColorSetSP)
void colorChanged(const KoColor &color, bool final)
void slotColorSelectedByPalette(const KoColor &color)
slotEntrySelected Triggered when a color is choose from the palette view
void slotPatchTriggered(KoColorPatch *)
slotPatchTriggered Triggered when a recent patch is triggered
KoColorSetWidgetPrivate *const d
void slotNameListSelection(const KoColor &)
void widgetSizeChanged(const QSize &size)
const KoColorDisplayRendererInterface * displayRenderer
void setColorSet(KoColorSetSP colorSet)
void resizeEvent(QResizeEvent *event) override
reimplemented from QFrame
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
setDisplayRenderer Set the display renderer of this object.
KoColorSetWidget(QWidget *parent=0)
void setColor(const quint8 *data, const KoColorSpace *colorSpace=0)
Definition KoColor.cpp:186
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
QIcon loadIcon(const QString &name)
static KoColorSpaceRegistry * instance()
static KoResourceServerProvider * instance()
KoResourceServer< KoColorSet > * paletteServer