• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • krita API Reference
  • KDE Home
  • Contact Us
 

KritaWidgets

  • sources
  • kfour-appscomplete
  • krita
  • libs
  • widgets
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 <[email protected]>
3  SPDX-FileCopyrightText: 2007-2008 Fredy Yanardi <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 #include "KoColorSetWidget.h"
8 #include "KoColorSetWidget_p.h"
9 
10 #include <QApplication>
11 #include <QSize>
12 #include <QToolButton>
13 #include <QHBoxLayout>
14 #include <QCheckBox>
15 #include <QFrame>
16 #include <QLabel>
17 #include <QMouseEvent>
18 #include <QMenu>
19 #include <QWidgetAction>
20 #include <QDir>
21 #include <QScrollArea>
22 #include <QGroupBox>
23 #include <QVBoxLayout>
24 
25 #include <klocalizedstring.h>
26 #include <ksharedconfig.h>
27 
28 #include <resources/KoColorSet.h>
29 #include <KoColorPatch.h>
30 #include <KoColorSpaceRegistry.h>
31 #include <KoResourceServer.h>
32 #include <KoResourceServerProvider.h>
33 
34 #include <kis_palette_view.h>
35 #include <KisPaletteDelegate.h>
36 #include <KisPaletteModel.h>
37 #include <kis_icon_utils.h>
38 
39 void KoColorSetWidget::KoColorSetWidgetPrivate::addRecent(const KoColor &color)
40 {
41  if(numRecents < 6) {
42  recentPatches[numRecents] = new KoColorPatch(thePublic);
43  recentPatches[numRecents]->setFrameShape(QFrame::StyledPanel);
44  recentPatches[numRecents]->setDisplayRenderer(displayRenderer);
45  recentsLayout->insertWidget(numRecents + 1, recentPatches[numRecents]);
46  connect(recentPatches[numRecents], SIGNAL(triggered(KoColorPatch*)), thePublic, SLOT(slotPatchTriggered(KoColorPatch*)));
47  numRecents++;
48  }
49  // shift colors to the right
50  for (int i = numRecents- 1; i >0; i--) {
51  recentPatches[i]->setColor(recentPatches[i-1]->color());
52  }
53 
54  //Finally set the recent color
55  recentPatches[0]->setColor(color);
56 }
57 
58 void KoColorSetWidget::KoColorSetWidgetPrivate::activateRecent(int i)
59 {
60  KoColor color = recentPatches[i]->color();
61 
62  while (i >0) {
63  recentPatches[i]->setColor(recentPatches[i-1]->color());
64  i--;
65  }
66  recentPatches[0]->setColor(color);
67 }
68 
69 KoColorSetWidget::KoColorSetWidget(QWidget *parent)
70  : QFrame(parent)
71  , d(new KoColorSetWidgetPrivate())
72 {
73  d->thePublic = this;
74 
75  d->numRecents = 0;
76  d->recentsLayout = new QHBoxLayout;
77  d->recentsLayout->setMargin(0);
78  d->recentsLayout->addWidget(new QLabel(i18n("Recent:")));
79  d->recentsLayout->addStretch(1);
80 
81  KoColor color(KoColorSpaceRegistry::instance()->rgb8());
82  color.fromQColor(QColor(128,0,0));
83  d->addRecent(color);
84 
85  d->paletteView = new KisPaletteView(this);
86  KisPaletteModel *paletteModel = new KisPaletteModel(d->paletteView);
87  d->paletteView->setPaletteModel(paletteModel);
88  d->paletteView->setDisplayRenderer(d->displayRenderer);
89 
90  d->paletteChooser = new KisPaletteChooser(this);
91  d->paletteChooserButton = new KisPopupButton(this);
92  d->paletteChooserButton->setPopupWidget(d->paletteChooser);
93  d->paletteChooserButton->setIcon(KisIconUtils::loadIcon("hi16-palette_library"));
94  d->paletteChooserButton->setToolTip(i18n("Choose palette"));
95 
96  d->colorNameCmb = new KisPaletteComboBox(this);
97  d->colorNameCmb->setCompanionView(d->paletteView);
98 
99  d->bottomLayout = new QHBoxLayout;
100  d->bottomLayout->addWidget(d->paletteChooserButton);
101  d->bottomLayout->addWidget(d->colorNameCmb);
102  d->bottomLayout->setStretch(0, 0); // minimize chooser button
103  d->bottomLayout->setStretch(1, 1); // maximize color name cmb
104 
105  d->mainLayout = new QVBoxLayout(this);
106  d->mainLayout->setMargin(4);
107  d->mainLayout->setSpacing(2);
108  d->mainLayout->addLayout(d->recentsLayout);
109  d->mainLayout->addWidget(d->paletteView);
110  d->mainLayout->addLayout(d->bottomLayout);
111 
112  connect(d->paletteChooser, SIGNAL(sigPaletteSelected(KoColorSetSP)), SLOT(slotPaletteChoosen(KoColorSetSP)));
113  connect(d->paletteView, SIGNAL(sigColorSelected(KoColor)), SLOT(slotColorSelectedByPalette(KoColor)));
114  connect(d->colorNameCmb, SIGNAL(sigColorSelected(KoColor)), SLOT(slotNameListSelection(KoColor)));
115 
116  d->rServer = KoResourceServerProvider::instance()->paletteServer();
117  KoColorSetSP defaultColorSet = d->rServer->resourceByName("Default");
118  if (!defaultColorSet && d->rServer->resourceCount() > 0) {
119  defaultColorSet = d->rServer->firstResource();
120  }
121  setColorSet(defaultColorSet);
122 }
123 
124 KoColorSetWidget::~KoColorSetWidget()
125 {
126  delete d;
127 }
128 
129 void KoColorSetWidget::setColorSet(KoColorSetSP colorSet)
130 {
131  if (!colorSet) return;
132  if (colorSet == d->colorSet) return;
133 
134  d->paletteView->paletteModel()->setPalette(colorSet);
135  d->colorSet = colorSet;
136 }
137 
138 KoColorSetSP KoColorSetWidget::colorSet()
139 {
140  return d->colorSet;
141 }
142 
143 void KoColorSetWidget::setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
144 {
145  if (displayRenderer) {
146  d->displayRenderer = displayRenderer;
147  for (int i=0; i<6; i++) {
148  if (d->recentPatches[i]) {
149  d->recentPatches[i]->setDisplayRenderer(displayRenderer);
150  }
151  }
152  }
153 }
154 
155 void KoColorSetWidget::resizeEvent(QResizeEvent *event)
156 {
157  emit widgetSizeChanged(event->size());
158  QFrame::resizeEvent(event);
159 }
160 
161 void KoColorSetWidget::slotColorSelectedByPalette(const KoColor &color)
162 {
163  emit colorChanged(color, true);
164  d->addRecent(color);
165 }
166 
167 void KoColorSetWidget::slotPatchTriggered(KoColorPatch *patch)
168 {
169  emit colorChanged(patch->color(), true);
170 
171  int i;
172 
173  for (i = 0; i < d->numRecents; i++) {
174  if(patch == d->recentPatches[i]) {
175  d->activateRecent(i);
176  break;
177  }
178  }
179 
180  if (i == d->numRecents) { // we didn't find it above
181  d->addRecent(patch->color());
182  }
183 }
184 
185 void KoColorSetWidget::slotPaletteChoosen(KoColorSetSP colorSet)
186 {
187  d->colorSet = colorSet;
188  d->paletteView->paletteModel()->setPalette(colorSet);
189 }
190 
191 void KoColorSetWidget::slotNameListSelection(const KoColor &color)
192 {
193  emit colorChanged(color, true);
194 }
195 
196 //have to include this because of Q_PRIVATE_SLOT
197 #include "moc_KoColorSetWidget.cpp"
QColor
QVBoxLayout
QFrame
QFrame::event
virtual bool event(QEvent *e)
KisPaletteDelegate.h
KoColorSetWidget::KoColorSetWidget
KoColorSetWidget(QWidget *parent=0)
Constructor for the widget, where color is initially blackpoint of sRGB.
Definition: KoColorSetWidget.cpp:69
KoColorSetWidget::~KoColorSetWidget
~KoColorSetWidget() override
Destructor.
Definition: KoColorSetWidget.cpp:124
QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
QWidget
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KisPaletteModel.h
kis_palette_view.h
KisPaletteView
Definition: kis_palette_view.h:27
KoColorSetWidget::setColorSet
void setColorSet(KoColorSetSP colorSet)
Sets the color set that this widget shows.
Definition: KoColorSetWidget.cpp:129
QLabel
KoColorSetWidget.h
KoResourceServerProvider.h
KoColorSetWidget::colorChanged
void colorChanged(const KoColor &color, bool final)
Emitted every time the color changes (by calling setColor() or by user interaction.
KisPaletteModel
The KisPaletteModel class This, together with KisPaletteView and KisPaletteDelegate forms a mvc way t...
Definition: KisPaletteModel.h:28
KoColorSetWidget::displayRenderer
const KoColorDisplayRendererInterface * displayRenderer
Definition: KoColorSetWidget_p.h:59
KisPaletteComboBox
The KisPaletteComboBox class A combobox used with KisPaletteView.
Definition: KisPaletteComboBox.h:28
KisPaletteChooser
Definition: KisPaletteChooser.h:24
KoColorSetWidget::resizeEvent
void resizeEvent(QResizeEvent *event) override
reimplemented from QFrame
Definition: KoColorSetWidget.cpp:155
KoColorSetWidget_p.h
KoColorSetWidget::widgetSizeChanged
void widgetSizeChanged(const QSize &size)
Emitted every time the size of this widget changes because of new colorset with different number of c...
QResizeEvent
QHBoxLayout
KoColorPatch.h
KoColorSetWidget::colorSet
KoColorSetSP colorSet()
Gets the current color set.
KoColorSetWidgetPrivate
KoColorSetWidget::setDisplayRenderer
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
setDisplayRenderer Set the display renderer of this object.
Definition: KoColorSetWidget.cpp:143
KoColorPatch::color
KoColor color() const
Definition: KoColorPatch.cpp:60
KoColorPatch
SPDX-FileCopyrightText: 2006 C.
Definition: KoColorPatch.h:18
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 23:44:00 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KritaWidgets

Skip menu "KritaWidgets"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

krita API Reference

Skip menu "krita API Reference"
  • libs
  •   KritaBasicFlakes
  •   brush
  •   KritaUndo2
  •   KritaFlake
  •   image
  •   KritaPlugin
  •   Krita
  •   KritaPigment
  •   KritaResources
  •   KritaStore
  •   ui
  •   KritaWidgets
  •   KritaWidgetUtils
  • plugins
  •   Assitants
  •   Extensions
  •   Filters
  •   Generators
  •   Formats
  •           src
  •   PaintOps
  •     libpaintop

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal