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

#include <KoColorPopupAction.h>

+ Inheritance diagram for KoColorPopupAction:

Classes

class  KoColorPopupActionPrivate
 

Public Slots

QColor currentColor () const
 Returns the current color.
 
KoColor currentKoColor () const
 Returns the current color as a KoColor.
 
void setCurrentColor (const KoColor &color)
 Sets a new color to be displayed.
 
void setCurrentColor (const QColor &color)
 Sets a new color to be displayed.
 
void updateIcon ()
 update the icon - only needed if you resize the iconsize in the widget that shows the action
 

Signals

void colorChanged (const KoColor &color)
 

Public Member Functions

 KoColorPopupAction (QObject *parent=0)
 
 ~KoColorPopupAction () override
 

Private Slots

void colorWasEdited (const QColor &color)
 
void colorWasSelected (const KoColor &color, bool final)
 
void emitColorChanged ()
 
void opacityWasChanged (int opacity)
 

Private Attributes

KoColorPopupActionPrivate *const d
 

Detailed Description

KoColorPopupAction makes use of KoColorSetWidget to show a widget for choosing a color (colormanaged via pigment).

See also
KoColorPopupAction

Definition at line 22 of file KoColorPopupAction.h.

Constructor & Destructor Documentation

◆ KoColorPopupAction()

KoColorPopupAction::KoColorPopupAction ( QObject * parent = 0)
explicit

Constructs a KoColorPopupAction with the specified parent.

Parameters
parentThe parent for this action.

Definition at line 62 of file KoColorPopupAction.cpp.

63 : QAction(parent),
64 d(new KoColorPopupActionPrivate())
65{
66 d->menu = new QMenu();
67 QWidget *widget = new QWidget(d->menu);
68 QWidgetAction *wdgAction = new QWidgetAction(d->menu);
69 d->colorSetWidget = new KoColorSetWidget(widget);
71
72 KoColorSetSP defaultColorSet = rServer->resource("", "", "Default");
73 if (!defaultColorSet && rServer->resourceCount() > 0) {
74 defaultColorSet = rServer->firstResource();
75 }
76 d->colorSetWidget->setColorSet(defaultColorSet);
77
78 d->colorChooser = new KoTriangleColorSelector( widget );
79 // prevent mouse release on color selector from closing popup
80 d->colorChooser->setAttribute( Qt::WA_NoMousePropagation );
81 d->opacitySlider = new KoColorSlider( Qt::Vertical, widget );
82 d->opacitySlider->setFixedWidth(25);
83 d->opacitySlider->setRange(0, 255);
84 d->opacitySlider->setValue(255);
85 d->opacitySlider->setToolTip( i18n( "Opacity" ) );
86
87 QGridLayout * layout = new QGridLayout( widget );
88 layout->addWidget( d->colorSetWidget, 0, 0, 1, -1 );
89 layout->addWidget( d->colorChooser, 1, 0 );
90 layout->addWidget( d->opacitySlider, 1, 1 );
91 layout->setContentsMargins(4, 4, 4, 4);
92
93 wdgAction->setDefaultWidget(widget);
94 d->menu->addAction(wdgAction);
95 setMenu(d->menu);
96 new QHBoxLayout(d->menu);
97 d->menu->layout()->addWidget(widget);
98 d->menu->layout()->setContentsMargins(0, 0, 0, 0);
99
100 connect(this, SIGNAL(triggered()), this, SLOT(emitColorChanged()));
101
103 this, SLOT(colorWasSelected(KoColor,bool)));
104 connect(d->colorChooser, SIGNAL(colorChanged(QColor)),
105 this, SLOT(colorWasEdited(QColor)));
106 connect(d->opacitySlider, SIGNAL(valueChanged(int)),
107 this, SLOT(opacityWasChanged(int)));
108}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void colorWasSelected(const KoColor &color, bool final)
KoColorPopupActionPrivate *const d
void colorChanged(const KoColor &color)
void opacityWasChanged(int opacity)
void colorWasEdited(const QColor &color)
A colormanaged widget for choosing a color from a colorset.
void setColorSet(KoColorSetSP colorSet)
int resourceCount() const
QSharedPointer< T > resource(const QString &md5, const QString &fileName, const QString &name)
resource retrieves a resource. If the md5sum is not empty, the resource will only be retrieved if a r...
QSharedPointer< T > firstResource() const
Return the first resource available.
static KoResourceServerProvider * instance()
KoResourceServer< KoColorSet > * paletteServer

References colorChanged(), KoColorPopupAction::KoColorPopupActionPrivate::colorChooser, KoColorPopupAction::KoColorPopupActionPrivate::colorSetWidget, colorWasEdited(), colorWasSelected(), connect(), d, emitColorChanged(), KoResourceServer< T >::firstResource(), KoResourceServerProvider::instance(), KoColorPopupAction::KoColorPopupActionPrivate::menu, KoColorPopupAction::KoColorPopupActionPrivate::opacitySlider, opacityWasChanged(), KoResourceServerProvider::paletteServer, KoResourceServer< T >::resource(), KoResourceServer< T >::resourceCount(), and KoColorSetWidget::setColorSet().

◆ ~KoColorPopupAction()

KoColorPopupAction::~KoColorPopupAction ( )
override

Destructor

Definition at line 110 of file KoColorPopupAction.cpp.

111{
112 delete d;
113}

References d.

Member Function Documentation

◆ colorChanged

void KoColorPopupAction::colorChanged ( const KoColor & color)
signal

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

Parameters
colorthe new color

◆ colorWasEdited

void KoColorPopupAction::colorWasEdited ( const QColor & color)
privateslot

Definition at line 210 of file KoColorPopupAction.cpp.

211{
213 quint8 opacity = d->opacitySlider->value();
214 d->currentColor.setOpacity( opacity );
215
216 KoColor minColor = d->currentColor;
218 KoColor maxColor = minColor;
219 maxColor.setOpacity( OPACITY_OPAQUE_U8 );
220
221 d->opacitySlider->setColors( minColor, maxColor );
222
224
225 updateIcon();
226}
const quint8 OPACITY_TRANSPARENT_U8
const quint8 OPACITY_OPAQUE_U8
void updateIcon()
update the icon - only needed if you resize the iconsize in the widget that shows the action
void setOpacity(quint8 alpha)
Definition KoColor.cpp:333
void setColors(const KoColor &minColor, const KoColor &maxColor)
static KoColorSpaceRegistry * instance()

References KoColorPopupAction::KoColorPopupActionPrivate::currentColor, d, emitColorChanged(), KoColorSpaceRegistry::instance(), OPACITY_OPAQUE_U8, OPACITY_TRANSPARENT_U8, KoColorPopupAction::KoColorPopupActionPrivate::opacitySlider, KoColorSlider::setColors(), KoColor::setOpacity(), and updateIcon().

◆ colorWasSelected

void KoColorPopupAction::colorWasSelected ( const KoColor & color,
bool final )
privateslot

Definition at line 200 of file KoColorPopupAction.cpp.

201{
202 d->currentColor = color;
203 if (final) {
204 menu()->hide();
206 }
207 updateIcon();
208}

References KoColorPopupAction::KoColorPopupActionPrivate::currentColor, d, emitColorChanged(), and updateIcon().

◆ currentColor

QColor KoColorPopupAction::currentColor ( ) const
slot

Returns the current color.

Definition at line 147 of file KoColorPopupAction.cpp.

148{
149 return d->currentColor.toQColor();
150}
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198

References KoColorPopupAction::KoColorPopupActionPrivate::currentColor, d, and KoColor::toQColor().

◆ currentKoColor

KoColor KoColorPopupAction::currentKoColor ( ) const
slot

Returns the current color as a KoColor.

Definition at line 152 of file KoColorPopupAction.cpp.

153{
154 return d->currentColor;
155}

References KoColorPopupAction::KoColorPopupActionPrivate::currentColor, and d.

◆ emitColorChanged

void KoColorPopupAction::emitColorChanged ( )
privateslot

◆ opacityWasChanged

void KoColorPopupAction::opacityWasChanged ( int opacity)
privateslot

◆ setCurrentColor [1/2]

void KoColorPopupAction::setCurrentColor ( const KoColor & color)
slot

Sets a new color to be displayed.

Definition at line 115 of file KoColorPopupAction.cpp.

116{
117 KoColor minColor( color );
118 d->currentColor = minColor;
119
120 d->colorChooser->blockSignals(true);
121 d->colorChooser->slotSetColor(color);
122 d->colorChooser->blockSignals(false);
123
124 KoColor maxColor( color );
125 minColor.setOpacity( OPACITY_TRANSPARENT_U8 );
126 maxColor.setOpacity( OPACITY_OPAQUE_U8 );
127
128 d->opacitySlider->blockSignals( true );
129 d->opacitySlider->setColors( minColor, maxColor );
130 d->opacitySlider->setValue( color.opacityU8() );
131 d->opacitySlider->blockSignals( false );
132
133 updateIcon();
134}
quint8 opacityU8() const
Definition KoColor.cpp:341
void slotSetColor(const KoColor &) override

References KoColorPopupAction::KoColorPopupActionPrivate::colorChooser, KoColorPopupAction::KoColorPopupActionPrivate::currentColor, d, OPACITY_OPAQUE_U8, OPACITY_TRANSPARENT_U8, KoColorPopupAction::KoColorPopupActionPrivate::opacitySlider, KoColor::opacityU8(), KoColorSlider::setColors(), KoColor::setOpacity(), KoTriangleColorSelector::slotSetColor(), and updateIcon().

◆ setCurrentColor [2/2]

void KoColorPopupAction::setCurrentColor ( const QColor & color)
slot

Sets a new color to be displayed.

Definition at line 136 of file KoColorPopupAction.cpp.

137{
138#ifndef NDEBUG
139 if (!_color.isValid()) {
140 warnWidgets << "Invalid color given, defaulting to black";
141 }
142#endif
143 const QColor color(_color.isValid() ? _color : QColor(0,0,0,255));
145}
#define warnWidgets
void setCurrentColor(const QColor &color)
Sets a new color to be displayed.

References KoColorSpaceRegistry::instance(), setCurrentColor(), and warnWidgets.

◆ updateIcon

void KoColorPopupAction::updateIcon ( )
slot

update the icon - only needed if you resize the iconsize in the widget that shows the action

Definition at line 157 of file KoColorPopupAction.cpp.

158{
159 QSize iconSize;
160 QToolButton *toolButton = dynamic_cast<QToolButton*>(parentWidget());
161 if (toolButton) {
162 iconSize = QSize(toolButton->iconSize());
163 } else {
164 iconSize = QSize(16, 16);
165 }
166
167 // This must be a QImage, as drawing to a QPixmap outside the
168 // UI thread will cause sporadic crashes.
169 QImage pm;
170
171 if (icon().isNull()) {
172 d->applyMode = false;
173 }
174
175 if(d->applyMode) {
176 pm = icon().pixmap(iconSize).toImage();
177 if (pm.isNull()) {
178 pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied);
179 pm.fill(Qt::transparent);
180 }
181 QPainter p(&pm);
182 p.fillRect(0, iconSize.height() - 4, iconSize.width(), 4, d->currentColor.toQColor());
183 p.end();
184 } else {
185 pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied);
186 pm.fill(Qt::transparent);
187 QPainter p(&pm);
188 d->checkerPainter.paint(p, QRect(QPoint(),iconSize));
189 p.fillRect(0, 0, iconSize.width(), iconSize.height(), d->currentColor.toQColor());
190 p.end();
191 }
192 setIcon(QIcon(QPixmap::fromImage(pm)));
193}
const Params2D p
int iconSize(qreal width, qreal height)
void paint(QPainter &painter, const QRectF &rect, const QPointF &patternOrigin) const

References KoColorPopupAction::KoColorPopupActionPrivate::applyMode, KoColorPopupAction::KoColorPopupActionPrivate::checkerPainter, KoColorPopupAction::KoColorPopupActionPrivate::currentColor, d, iconSize(), p, KoCheckerBoardPainter::paint(), and KoColor::toQColor().

Member Data Documentation

◆ d

KoColorPopupActionPrivate* const KoColorPopupAction::d
private

Definition at line 71 of file KoColorPopupAction.h.


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