Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSetWidget Class Reference

A colormanaged widget for choosing a color from a colorset. More...

#include <KoColorSetWidget.h>

+ Inheritance diagram for KoColorSetWidget:

Signals

void colorChanged (const KoColor &color, bool final)
 
void widgetSizeChanged (const QSize &size)
 

Public Member Functions

void activateRecent (int i)
 
void addRecent (const KoColor &)
 
void addRemoveColors ()
 
KoColorSetSP colorSet ()
 
 KoColorSetWidget (QWidget *parent=0)
 
void setColorSet (KoColorSetSP colorSet)
 
void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer)
 setDisplayRenderer Set the display renderer of this object.
 
 ~KoColorSetWidget () override
 

Public Attributes

QToolButton * addRemoveButton
 
QHBoxLayout * bottomLayout
 
KisPaletteComboBoxcolorNameCmb
 
KoColorSetSP colorSet
 
QVBoxLayout * colorSetLayout
 
const KoColorDisplayRendererInterfacedisplayRenderer
 
QVBoxLayout * mainLayout
 
int numRecents
 
KisPaletteChooserpaletteChooser
 
KisPopupButtonpaletteChooserButton
 
KisPaletteViewpaletteView
 
KoColorPatchrecentPatches [6]
 
QHBoxLayout * recentsLayout
 
KoResourceServer< KoColorSet > * rServer
 
KoColorSetWidgetthePublic
 

Protected Member Functions

void resizeEvent (QResizeEvent *event) override
 reimplemented from QFrame
 

Private Slots

void slotColorSelectedByPalette (const KoColor &color)
 slotEntrySelected Triggered when a color is choose from the palette view
 
void slotNameListSelection (const KoColor &)
 
void slotPaletteChosen (KoColorSetSP)
 
void slotPatchTriggered (KoColorPatch *)
 slotPatchTriggered Triggered when a recent patch is triggered
 

Private Attributes

KoColorSetWidgetPrivate *const d
 

Detailed Description

A colormanaged widget for choosing a color from a colorset.

KoColorSetWidget is a widget for choosing a color (colormanaged via pigment). It shows a color set plus optionally a checkbox to filter away bad matching colors.

Definition at line 30 of file KoColorSetWidget.h.

Constructor & Destructor Documentation

◆ KoColorSetWidget()

KoColorSetWidget::KoColorSetWidget ( QWidget * parent = 0)
explicit

Constructor for the widget, where color is initially blackpoint of sRGB

Parameters
parentparent QWidget

Definition at line 67 of file KoColorSetWidget.cpp.

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}
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...
void slotPaletteChosen(KoColorSetSP)
void slotColorSelectedByPalette(const KoColor &color)
slotEntrySelected Triggered when a color is choose from the palette view
KoColorSetWidgetPrivate *const d
void slotNameListSelection(const KoColor &)
void setColorSet(KoColorSetSP colorSet)
QIcon loadIcon(const QString &name)
static KoColorSpaceRegistry * instance()
static KoResourceServerProvider * instance()
KoResourceServer< KoColorSet > * paletteServer

References connect(), d, KoColor::fromQColor(), KoColorSpaceRegistry::instance(), KoResourceServerProvider::instance(), KisIconUtils::loadIcon(), KoResourceServerProvider::paletteServer, setColorSet(), slotColorSelectedByPalette(), slotNameListSelection(), and slotPaletteChosen().

◆ ~KoColorSetWidget()

KoColorSetWidget::~KoColorSetWidget ( )
override

Destructor

Definition at line 122 of file KoColorSetWidget.cpp.

123{
124 delete d;
125}

References d.

Member Function Documentation

◆ activateRecent()

void KoColorSetWidget::activateRecent ( int i)

◆ addRecent()

void KoColorSetWidget::addRecent ( const KoColor & )

◆ addRemoveColors()

void KoColorSetWidget::addRemoveColors ( )

◆ colorChanged

void KoColorSetWidget::colorChanged ( const KoColor & color,
bool final )
signal

Emitted every time the color changes (by calling setColor() or by user interaction.

Parameters
colorthe new color
finalif the value is final (ie not produced by the pointer moving over around)

◆ colorSet()

KoColorSetSP KoColorSetWidget::colorSet ( )

Gets the current color set

Returns
current color set,, 0 if none set

◆ resizeEvent()

void KoColorSetWidget::resizeEvent ( QResizeEvent * event)
overrideprotected

reimplemented from QFrame

Definition at line 153 of file KoColorSetWidget.cpp.

154{
155 Q_EMIT widgetSizeChanged(event->size());
156 QFrame::resizeEvent(event);
157}
void widgetSizeChanged(const QSize &size)

References widgetSizeChanged().

◆ setColorSet()

void KoColorSetWidget::setColorSet ( KoColorSetSP colorSet)

Sets the color set that this widget shows.

Parameters
colorSetpointer to the color set

Definition at line 127 of file KoColorSetWidget.cpp.

128{
129 if (!colorSet) return;
130 if (colorSet == d->colorSet) return;
131
132 d->paletteView->paletteModel()->setColorSet(colorSet);
133 d->colorSet = colorSet;
134}

References colorSet, and d.

◆ setDisplayRenderer()

void KoColorSetWidget::setDisplayRenderer ( const KoColorDisplayRendererInterface * displayRenderer)

setDisplayRenderer Set the display renderer of this object.

Parameters
displayRenderer

Definition at line 141 of file KoColorSetWidget.cpp.

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}
const KoColorDisplayRendererInterface * displayRenderer

References d, and displayRenderer.

◆ slotColorSelectedByPalette

void KoColorSetWidget::slotColorSelectedByPalette ( const KoColor & color)
privateslot

slotEntrySelected Triggered when a color is choose from the palette view

Definition at line 159 of file KoColorSetWidget.cpp.

160{
161 Q_EMIT colorChanged(color, true);
162 d->addRecent(color);
163}
void colorChanged(const KoColor &color, bool final)

References colorChanged(), and d.

◆ slotNameListSelection

void KoColorSetWidget::slotNameListSelection ( const KoColor & color)
privateslot

Definition at line 189 of file KoColorSetWidget.cpp.

190{
191 Q_EMIT colorChanged(color, true);
192}

References colorChanged().

◆ slotPaletteChosen

void KoColorSetWidget::slotPaletteChosen ( KoColorSetSP colorSet)
privateslot

Definition at line 183 of file KoColorSetWidget.cpp.

184{
185 d->colorSet = colorSet;
186 d->paletteView->paletteModel()->setColorSet(colorSet);
187}

References colorSet, and d.

◆ slotPatchTriggered

void KoColorSetWidget::slotPatchTriggered ( KoColorPatch * patch)
privateslot

slotPatchTriggered Triggered when a recent patch is triggered

Definition at line 165 of file KoColorSetWidget.cpp.

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}
KoColor color() const

References KoColorPatch::color(), colorChanged(), and d.

◆ widgetSizeChanged

void KoColorSetWidget::widgetSizeChanged ( const QSize & size)
signal

Emitted every time the size of this widget changes because of new colorset with different number of colors is loaded. This is useful for KoColorSetAction to update correct size of the menu showing this widget.

Parameters
sizethe new size

Member Data Documentation

◆ addRemoveButton

QToolButton* KoColorSetWidget::addRemoveButton

Definition at line 50 of file KoColorSetWidget_p.h.

◆ bottomLayout

QHBoxLayout* KoColorSetWidget::bottomLayout

Definition at line 47 of file KoColorSetWidget_p.h.

◆ colorNameCmb

KisPaletteComboBox* KoColorSetWidget::colorNameCmb

Definition at line 51 of file KoColorSetWidget_p.h.

◆ colorSet

KoColorSetSP KoColorSetWidget::colorSet

Definition at line 38 of file KoColorSetWidget_p.h.

◆ colorSetLayout

QVBoxLayout* KoColorSetWidget::colorSetLayout

Definition at line 45 of file KoColorSetWidget_p.h.

◆ d

KoColorSetWidgetPrivate* const KoColorSetWidget::d
private

Definition at line 105 of file KoColorSetWidget.h.

◆ displayRenderer

const KoColorDisplayRendererInterface* KoColorSetWidget::displayRenderer

Definition at line 54 of file KoColorSetWidget_p.h.

◆ mainLayout

QVBoxLayout* KoColorSetWidget::mainLayout

Definition at line 44 of file KoColorSetWidget_p.h.

◆ numRecents

int KoColorSetWidget::numRecents

Definition at line 52 of file KoColorSetWidget_p.h.

◆ paletteChooser

KisPaletteChooser* KoColorSetWidget::paletteChooser

Definition at line 41 of file KoColorSetWidget_p.h.

◆ paletteChooserButton

KisPopupButton* KoColorSetWidget::paletteChooserButton

Definition at line 42 of file KoColorSetWidget_p.h.

◆ paletteView

KisPaletteView* KoColorSetWidget::paletteView

Definition at line 40 of file KoColorSetWidget_p.h.

◆ recentPatches

KoColorPatch* KoColorSetWidget::recentPatches[6]

Definition at line 49 of file KoColorSetWidget_p.h.

◆ recentsLayout

QHBoxLayout* KoColorSetWidget::recentsLayout

Definition at line 46 of file KoColorSetWidget_p.h.

◆ rServer

KoResourceServer<KoColorSet>* KoColorSetWidget::rServer

Definition at line 55 of file KoColorSetWidget_p.h.

◆ thePublic

KoColorSetWidget* KoColorSetWidget::thePublic

Definition at line 37 of file KoColorSetWidget_p.h.


The documentation for this class was generated from the following files: