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

Make the display color converter of the dualcolor button get updated.

This enables the the display color converter on the internal color selector too.
There are still update and range bugs, the range bugs being tricky and the update bugs being probably due wrong signal being connect, but I am pretty pleased with this.

Ref T2337
parent ca0a0333
......@@ -440,6 +440,7 @@ void KisViewManager::setCurrentView(KisView *view)
resourceProvider()->slotImageSizeChanged();
resourceProvider()->slotOnScreenResolutionChanged();
Q_EMIT viewChanged();
}
......
......@@ -212,6 +212,11 @@ public Q_SLOTS:
Q_SIGNALS:
void floatingMessageRequested(const QString &message, const QString &iconName);
/**
* @brief viewChanged
* sent out when the view has changed.
*/
void viewChanged();
private Q_SLOTS:
......
......@@ -104,6 +104,16 @@ void KisInternalColorSelector::colorSpaceChanged(const KoColorSpace *cs)
}
void KisInternalColorSelector::setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
{
if (displayRenderer) {
m_d->displayRenderer = displayRenderer;
m_ui->visualSelector->setDisplayRenderer(displayRenderer);
} else {
m_d->displayRenderer = KoDumbColorDisplayRenderer::instance();
}
}
KoColor KisInternalColorSelector::getModalColorDialog(const KoColor color, bool chooseAlpha, QWidget* parent, QString caption)
{
KisInternalColorSelector dialog(parent, color, true, caption);
......
......@@ -46,6 +46,13 @@ public:
*/
void colorSpaceChanged(const KoColorSpace *cs);
/**
* @brief setDisplayRenderer
* Set the display renderer. This is necessary for HDR color manage support.
* @param displayRenderer
*/
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
/**
* @brief getModalColorDialog
* Excecute this dialog modally. The function returns
......
......@@ -109,21 +109,22 @@ void KisControlFrame::setup(QWidget *parent)
// XXX: KOMVC we don't have a canvas here yet, needs a setImageView
const KoColorDisplayRendererInterface *displayRenderer = \
KisDisplayColorConverter::dumbConverterInstance()->displayRendererInterface();
KoDualColorButton * dual = new KoDualColorButton(m_viewManager->resourceProvider()->fgColor(),
m_dual = new KoDualColorButton(m_viewManager->resourceProvider()->fgColor(),
m_viewManager->resourceProvider()->bgColor(), displayRenderer,
m_viewManager->mainWindow(), m_viewManager->mainWindow());
dual->setPopDialog(true);
m_dual->setPopDialog(true);
action = new QWidgetAction(this);
action->setText(i18n("&Color"));
m_viewManager->actionCollection()->addAction("dual", action);
action->setDefaultWidget(dual);
connect(dual, SIGNAL(foregroundColorChanged(KoColor)), m_viewManager->resourceProvider(), SLOT(slotSetFGColor(KoColor)));
connect(dual, SIGNAL(backgroundColorChanged(KoColor)), m_viewManager->resourceProvider(), SLOT(slotSetBGColor(KoColor)));
connect(m_viewManager->resourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), dual, SLOT(setForegroundColor(KoColor)));
connect(m_viewManager->resourceProvider(), SIGNAL(sigBGColorChanged(KoColor)), dual, SLOT(setBackgroundColor(KoColor)));
action->setDefaultWidget(m_dual);
connect(m_dual, SIGNAL(foregroundColorChanged(KoColor)), m_viewManager->resourceProvider(), SLOT(slotSetFGColor(KoColor)));
connect(m_dual, SIGNAL(backgroundColorChanged(KoColor)), m_viewManager->resourceProvider(), SLOT(slotSetBGColor(KoColor)));
connect(m_viewManager->resourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), m_dual, SLOT(setForegroundColor(KoColor)));
connect(m_viewManager->resourceProvider(), SIGNAL(sigBGColorChanged(KoColor)), m_dual, SLOT(setBackgroundColor(KoColor)));
connect(m_viewManager->resourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), m_gradientWidget, SLOT(update()));
connect(m_viewManager->resourceProvider(), SIGNAL(sigBGColorChanged(KoColor)), m_gradientWidget, SLOT(update()));
dual->setFixedSize(28, 28);
m_dual->setFixedSize(28, 28);
connect(m_viewManager, SIGNAL(viewChanged()), SLOT(slotUpdateDisplayRenderer()));
m_paintopBox = new KisPaintopBox(m_viewManager, parent, "paintopbox");
......@@ -133,6 +134,13 @@ void KisControlFrame::setup(QWidget *parent)
action->setDefaultWidget(m_paintopBox);
}
void KisControlFrame::slotUpdateDisplayRenderer()
{
if (m_viewManager->canvasBase()){
m_dual->setDisplayRenderer(m_viewManager->canvasBase()->displayColorConverter()->displayRendererInterface());
}
}
void KisControlFrame::slotSetPattern(KoPattern * pattern)
{
m_patternWidget->slotSetItem(pattern);
......
......@@ -37,6 +37,7 @@ class KisPaintopBox;
class KisViewManager;
class KisIconWidget;
class KoPattern;
class KoDualColorButton;
/**
* Control Frame - status display with access to
......@@ -60,6 +61,7 @@ private Q_SLOTS:
void slotSetPattern(KoPattern * pattern);
void slotSetGradient(KoAbstractGradient * gradient);
void slotUpdateDisplayRenderer();
private:
......@@ -85,6 +87,8 @@ private:
KisPaintopBox *m_paintopBox;
KoDualColorButton *m_dual;
};
#endif
......
......@@ -160,6 +160,14 @@ void KoDualColorButton::setBackgroundColor( const KoColor &color )
repaint();
}
void KoDualColorButton::setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer)
{
if (displayRenderer) {
d->displayRenderer = displayRenderer;
d->colorSelectorDialog->setDisplayRenderer(displayRenderer);
}
}
void KoDualColorButton::setPopDialog( bool popDialog )
{
d->popDialog = popDialog;
......
......@@ -117,6 +117,8 @@ class KRITAWIDGETS_EXPORT KoDualColorButton : public QWidget
void slotSetForeGroundColorFromDialog (const KoColor color);
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
/**
* 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
......
......@@ -28,6 +28,7 @@
#include "KoColorConversions.h"
#include "KoColorDisplayRendererInterface.h"
#include "KoChannelInfo.h"
#include <QPointer>
#include "kis_signal_compressor.h"
......@@ -262,12 +263,18 @@ void KisVisualColorSelectorShape::setDisplayRenderer (const KoColorDisplayRender
}
m_d->displayRenderer = displayRenderer;
connect(m_d->displayRenderer, SIGNAL(displayConfigurationChanged()),
SLOT(update()), Qt::UniqueConnection);
SLOT(updateFromChangedDisplayRenderer()), Qt::UniqueConnection);
} else {
m_d->displayRenderer = KoDumbColorDisplayRenderer::instance();
}
}
void KisVisualColorSelectorShape::updateFromChangedDisplayRenderer()
{
m_d->pixmapsNeedUpdate = true;
repaint();
}
QColor KisVisualColorSelectorShape::getColorFromConverter(KoColor c){
QColor col;
if (m_d->displayRenderer) {
......@@ -316,9 +323,20 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
KoColor c = m_d->currentColor;
QVector <float> channelValues (c.colorSpace()->channelCount());
channelValues.fill(1.0);
QVector <qreal> maxvalue(c.colorSpace()->channelCount());
maxvalue.fill(1.0);
if (m_d->displayRenderer) {
for (int ch = 0; ch<maxvalue.size(); ch++) {
//KoChannelInfo *channel = m_d->cs->channels()[ch];
//maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel);
channelValues[ch] = channelValues[ch]/(maxvalue[ch]);
}
}
c.colorSpace()->normalisedChannelsValue(c.data(), channelValues);
qreal huedivider = 1.0;
qreal huedivider2 = 1.0;
if (m_d->channel1==0) {
huedivider = 360.0;
}
......@@ -374,6 +392,9 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
channelValues[m_d->channel2] = coordinates.y();
}
}
for (int i=0; i<channelValues.size();i++) {
channelValues[i] = channelValues[i]*(maxvalue[i]);
}
c.colorSpace()->fromNormalisedChannelsValue(c.data(), channelValues);
return c;
}
......@@ -386,6 +407,15 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
QVector <float> channelValues (m_d->currentColor.colorSpace()->channelCount());
channelValues.fill(1.0);
m_d->cs->normalisedChannelsValue(c.data(), channelValues);
QVector <qreal> maxvalue(c.colorSpace()->channelCount());
maxvalue.fill(1.0);
if (m_d->displayRenderer) {
for (int ch = 0; ch<maxvalue.size(); ch++) {
//KoChannelInfo *channel = m_d->cs->channels()[ch];
//maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel);
channelValues[ch] = channelValues[ch]/(maxvalue[ch]);
}
}
QPointF coordinates(0.0,0.0);
qreal huedivider = 1.0;
qreal huedivider2 = 1.0;
......
......@@ -101,6 +101,7 @@ public Q_SLOTS:
void setColor(KoColor c);
void setColorFromSibling(KoColor c);
void slotSetActiveChannels(int channel1, int channel2);
void updateFromChangedDisplayRenderer();
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
......
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