Commit 6655f984 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add display color converters to the KoColorSetWidget/KoColorPatch

Ref T2438
parent b5a0d6c3
......@@ -86,9 +86,12 @@ KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor colo
}
}
connect(m_ui->paletteBox, SIGNAL(colorChanged(KoColor,bool)), this, SLOT(slotColorUpdated(KoColor)));
m_ui->paletteBox->setDisplayRenderer(displayRenderer);
m_ui->currentColor->setColor(m_d->currentColor);
m_ui->currentColor->setDisplayRenderer(displayRenderer);
m_ui->previousColor->setColor(m_d->currentColor);
m_ui->previousColor->setDisplayRenderer(displayRenderer);
connect(this, SIGNAL(accepted()), this, SLOT(setPreviousColor()));
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector()));
......@@ -130,6 +133,9 @@ void KisInternalColorSelector::setDisplayRenderer(const KoColorDisplayRendererIn
if (displayRenderer) {
m_d->displayRenderer = displayRenderer;
m_ui->visualSelector->setDisplayRenderer(displayRenderer);
m_ui->currentColor->setDisplayRenderer(displayRenderer);
m_ui->previousColor->setDisplayRenderer(displayRenderer);
m_ui->paletteBox->setDisplayRenderer(displayRenderer);
} else {
m_d->displayRenderer = KoDumbColorDisplayRenderer::instance();
}
......
......@@ -22,6 +22,9 @@
KoColorPatch::KoColorPatch( QWidget *parent ) : QFrame( parent )
{
m_displayRenderer = KoDumbColorDisplayRenderer::instance();
connect(m_displayRenderer, SIGNAL(displayConfigurationChanged()),
SLOT(update()), Qt::UniqueConnection);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
......@@ -40,6 +43,32 @@ void KoColorPatch::setColor(const KoColor& c)
update();
}
void KoColorPatch::setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
{
if (displayRenderer) {
if (m_displayRenderer) {
m_displayRenderer->disconnect(this);
}
m_displayRenderer = displayRenderer;
} else {
m_displayRenderer = KoDumbColorDisplayRenderer::instance();
}
connect(m_displayRenderer, SIGNAL(displayConfigurationChanged()),
SLOT(update()), Qt::UniqueConnection);
}
QColor KoColorPatch::getColorFromDisplayRenderer(KoColor c)
{
QColor col;
if (m_displayRenderer) {
c.convertTo(m_displayRenderer->getPaintingColorSpace());
col = m_displayRenderer->toQColor(c);
} else {
col = c.toQColor();
}
return col;
}
KoColor KoColorPatch::color() const
{
......@@ -55,9 +84,7 @@ void KoColorPatch::mousePressEvent (QMouseEvent *e )
void KoColorPatch::paintEvent(QPaintEvent *pe)
{
QColor qc;
m_color.toQColor(&qc);
QColor qc = getColorFromDisplayRenderer(m_color);
QFrame::paintEvent(pe);
QPainter painter( this );
painter.setPen(qc);
......
......@@ -23,6 +23,7 @@
#include <KoColor.h>
#include "kritawidgets_export.h"
#include <KoColorDisplayRendererInterface.h>
/**
* The small widget showing the selected color
......@@ -40,6 +41,20 @@ public:
*/
void setColor( const KoColor &c );
/**
* @brief setDisplayRenderer
* Set the display renderer of this object.
* @param displayRenderer
*/
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
/**
* @brief getColorFromDisplayRenderer
* Get QColor from the display renderers
* @param c
*/
QColor getColorFromDisplayRenderer(KoColor c);
/**
* @return current color shown by this patch
*/
......@@ -60,6 +75,7 @@ Q_SIGNALS:
private:
KoColor m_color;
const KoColorDisplayRendererInterface *m_displayRenderer;
};
#endif
......@@ -66,6 +66,8 @@ void KoColorSetWidget::KoColorSetWidgetPrivate::fillColors()
patch->setColor(colorSet->getColor(i).color);
connect(patch, SIGNAL(triggered(KoColorPatch *)), thePublic, SLOT(colorTriggered(KoColorPatch *)));
colorSetLayout->addWidget(patch, p/16, p%16);
patch->setDisplayRenderer(displayRenderer);
patchWidgetList.append(patch);
++p;
}
}
......@@ -115,6 +117,7 @@ void KoColorSetWidget::KoColorSetWidgetPrivate::addRecent(const KoColor &color)
if(numRecents<6) {
recentPatches[numRecents] = new KoColorPatch(thePublic);
recentPatches[numRecents]->setFrameShape(QFrame::Box);
recentPatches[numRecents]->setDisplayRenderer(displayRenderer);
recentsLayout->insertWidget(numRecents+1, recentPatches[numRecents]);
connect(recentPatches[numRecents], SIGNAL(triggered(KoColorPatch *)), thePublic, SLOT(colorTriggered(KoColorPatch *)));
numRecents++;
......@@ -228,6 +231,21 @@ KoColorSet* KoColorSetWidget::colorSet()
return d->colorSet;
}
void KoColorSetWidget::setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
{
if (displayRenderer) {
d->displayRenderer = displayRenderer;
Q_FOREACH(KoColorPatch *p, d->patchWidgetList) {
p->setDisplayRenderer(displayRenderer);
}
for (int i=0; i<6; i++) {
if (d->recentPatches[i]) {
d->recentPatches[i]->setDisplayRenderer(displayRenderer);
}
}
}
}
void KoColorSetWidget::resizeEvent(QResizeEvent *event)
{
emit widgetSizeChanged(event->size());
......
......@@ -25,6 +25,7 @@
#include <QFrame>
#include "kritawidgets_export.h"
#include <KoColorDisplayRendererInterface.h>
class KoColor;
class KoColorSet;
......@@ -60,6 +61,13 @@ public:
*/
void setColorSet(KoColorSet *colorSet);
/**
* @brief setDisplayRenderer
* Set the display renderer of this object.
* @param displayRenderer
*/
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
/**
* Gets the current color set
* @returns current color set,, 0 if none set
......
......@@ -41,6 +41,7 @@
#include <WidgetsDebug.h>
#include <resources/KoColorSet.h>
#include <KoColorDisplayRendererInterface.h>
class KoColorPatch;
......@@ -64,6 +65,10 @@ public:
void activateRecent(int i);
void fillColors();
void addRemoveColors();
QList<KoColorPatch*> patchWidgetList;
const KoColorDisplayRendererInterface *displayRenderer;
};
#endif
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