Commit 8c291425 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

change kodualcolorbutton about to simply code.

This doesn't prevent a crash when closing all available documents, sadly.
parent eb1232be
......@@ -165,7 +165,21 @@ void KoDualColorButton::setDisplayRenderer(const KoColorDisplayRendererInterface
if (displayRenderer) {
d->displayRenderer = displayRenderer;
d->colorSelectorDialog->setDisplayRenderer(displayRenderer);
} else {
d->displayRenderer = KoDumbColorDisplayRenderer::instance();
}
}
QColor KoDualColorButton::getColorFromDisplayRenderer(KoColor c)
{
QColor col;
if (d->displayRenderer) {
c.convertTo(d->displayRenderer->getPaintingColorSpace());
col = d->displayRenderer->toQColor(c);
} else {
col = c.toQColor();
}
return col;
}
void KoDualColorButton::setPopDialog( bool popDialog )
......@@ -189,8 +203,8 @@ void KoDualColorButton::paintEvent(QPaintEvent *)
metrics( foregroundRect, backgroundRect );
QBrush defBrush = palette().brush( QPalette::Button );
QBrush foregroundBrush( d->displayRenderer->toQColor(d->foregroundColor), Qt::SolidPattern );
QBrush backgroundBrush( d->displayRenderer->toQColor(d->backgroundColor), Qt::SolidPattern );
QBrush foregroundBrush( getColorFromDisplayRenderer(d->foregroundColor), Qt::SolidPattern );
QBrush backgroundBrush( getColorFromDisplayRenderer(d->backgroundColor), Qt::SolidPattern );
qDrawShadeRect( &painter, backgroundRect, palette(), false, 1, 0,
isEnabled() ? &backgroundBrush : &defBrush );
......@@ -286,8 +300,8 @@ void KoDualColorButton::mouseMoveEvent( QMouseEvent *event )
if ( event->x() >= d->dragPosition.x() + delay || event->x() <= d->dragPosition.x() - delay ||
event->y() >= d->dragPosition.y() + delay || event->y() <= d->dragPosition.y() - delay ) {
KColorMimeData::createDrag( d->tmpSelection == Foreground ?
d->displayRenderer->toQColor(d->foregroundColor) :
d->displayRenderer->toQColor(d->backgroundColor),
getColorFromDisplayRenderer(d->foregroundColor) :
getColorFromDisplayRenderer(d->backgroundColor),
this )->start();
d->dragFlag = true;
}
......
......@@ -119,6 +119,15 @@ class KRITAWIDGETS_EXPORT KoDualColorButton : public QWidget
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
/**
* @brief getColorFromDisplayRenderer
* convenience function to get the right qcolor from the display renderer, including checking
* whether the display renderer actually exists.
* @param c the kocolor to convert.
* @return the qcolor to use for display.
*/
QColor getColorFromDisplayRenderer(KoColor c);
/**
* Sets if a dialog with a color chooser should be popped up when clicking
* If you set this to false then you could connect to the pleasePopDialog signal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment