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