diff --git a/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.cc b/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.cc index bb4dea922b..c6dc9bea51 100644 --- a/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.cc +++ b/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.cc @@ -1,215 +1,236 @@ /* * Copyright (c) 2008 Cyrille Berger * Copyright (c) 2015 Moritz Molch * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_specific_color_selector_widget.h" #include #include #include #include #include #include #include #include #include #include #include #include "kis_color_input.h" #include #include "kis_debug.h" #include "kis_color_space_selector.h" #include "kis_signal_compressor.h" +#include "kis_display_color_converter.h" KisSpecificColorSelectorWidget::KisSpecificColorSelectorWidget(QWidget* parent) : QWidget(parent) , m_colorSpace(0) , m_spacer(0) , m_updateCompressor(new KisSignalCompressor(10, KisSignalCompressor::POSTPONE, this)) , m_customColorSpaceSelected(false) - , m_displayRenderer(0) - , m_fallbackRenderer(new KoDumbColorDisplayRenderer()) + , m_displayConverter(0) { m_layout = new QVBoxLayout(this); m_layout->setContentsMargins(0,0,0,0); m_layout->setSpacing(1); m_updateAllowed = true; connect(m_updateCompressor, SIGNAL(timeout()), SLOT(updateTimeout())); m_colorspaceSelector = new KisColorSpaceSelector(this); m_colorspaceSelector->layout()->setSpacing(1); connect(m_colorspaceSelector, SIGNAL(colorSpaceChanged(const KoColorSpace*)), this, SLOT(setCustomColorSpace(const KoColorSpace*))); m_chkShowColorSpaceSelector = new QCheckBox(i18n("Show Colorspace Selector"), this); connect(m_chkShowColorSpaceSelector, SIGNAL(toggled(bool)), m_colorspaceSelector, SLOT(setVisible(bool))); KConfigGroup cfg = KSharedConfig::openConfig()->group(""); m_chkShowColorSpaceSelector->setChecked(cfg.readEntry("SpecificColorSelector/ShowColorSpaceSelector", true)); m_colorspaceSelector->setVisible(m_chkShowColorSpaceSelector->isChecked()); m_colorspaceSelector->showColorBrowserButton(false); m_layout->addWidget(m_chkShowColorSpaceSelector); m_layout->addWidget(m_colorspaceSelector); m_spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); m_layout->addItem(m_spacer); } KisSpecificColorSelectorWidget::~KisSpecificColorSelectorWidget() { KConfigGroup cfg = KSharedConfig::openConfig()->group(""); cfg.writeEntry("SpecificColorSelector/ShowColorSpaceSelector", m_chkShowColorSpaceSelector->isChecked()); - delete m_fallbackRenderer; } bool KisSpecificColorSelectorWidget::customColorSpaceUsed() { return m_customColorSpaceSelected; } -void KisSpecificColorSelectorWidget::setDisplayRenderer(KoColorDisplayRendererInterface *displayRenderer) +void KisSpecificColorSelectorWidget::setDisplayConverter(KisDisplayColorConverter *displayConverter) { - m_displayRenderer = displayRenderer; + const bool needsForceUpdate = m_displayConverter != displayConverter; - if (m_colorSpace) { - setColorSpace(m_colorSpace); + m_displayConverter = displayConverter; + + if (m_displayConverter) { + m_converterConnection.clear(); + m_converterConnection.addConnection(m_displayConverter, SIGNAL(displayConfigurationChanged()), this, SLOT(rereadCurrentColorSpace())); + } + + rereadCurrentColorSpace(needsForceUpdate); +} + +void KisSpecificColorSelectorWidget::rereadCurrentColorSpace(bool force) +{ + if (m_displayConverter && !m_customColorSpaceSelected) { + m_colorSpace = m_displayConverter->paintingColorSpace(); } + + setColorSpace(m_colorSpace, force); + setColor(m_color); } -void KisSpecificColorSelectorWidget::setColorSpace(const KoColorSpace* cs) +void KisSpecificColorSelectorWidget::setColorSpace(const KoColorSpace* cs, bool force) { Q_ASSERT(cs); dbgPlugins << cs->id() << " " << cs->profile()->name(); - if (cs == m_colorSpace) { + if (*m_colorSpace == *cs && !force) { + Q_FOREACH (KisColorInput* input, m_inputs) { + input->update(); + } + return; } m_colorSpace = KoColorSpaceRegistry::instance()->colorSpace(cs->colorModelId().id(), cs->colorDepthId().id(), cs->profile()); Q_ASSERT(m_colorSpace); Q_ASSERT(*m_colorSpace == *cs); m_color = KoColor(m_color, m_colorSpace); Q_FOREACH (KisColorInput* input, m_inputs) { delete input; } m_inputs.clear(); m_layout->removeItem(m_spacer); QList channels = KoChannelInfo::displayOrderSorted(m_colorSpace->channels()); - KoColorDisplayRendererInterface *displayRenderer = m_displayRenderer ? m_displayRenderer : m_fallbackRenderer; + KoColorDisplayRendererInterface *displayRenderer = + m_displayConverter ? + m_displayConverter->displayRendererInterface() : + KisDisplayColorConverter::dumbConverterInstance()->displayRendererInterface(); Q_FOREACH (KoChannelInfo* channel, channels) { if (channel->channelType() == KoChannelInfo::COLOR) { KisColorInput* input = 0; switch (channel->channelValueType()) { case KoChannelInfo::UINT8: case KoChannelInfo::UINT16: case KoChannelInfo::UINT32: { input = new KisIntegerColorInput(this, channel, &m_color, displayRenderer); } break; case KoChannelInfo::FLOAT16: case KoChannelInfo::FLOAT32: { input = new KisFloatColorInput(this, channel, &m_color, displayRenderer); } break; default: Q_ASSERT(false); input = 0; } if (input) { connect(input, SIGNAL(updated()), this, SLOT(update())); connect(this, SIGNAL(updated()), input, SLOT(update())); m_inputs.append(input); m_layout->addWidget(input); } } } QList labels; int labelWidth = 0; Q_FOREACH (KisColorInput* input, m_inputs) { Q_FOREACH (QLabel* label, input->findChildren()) { labels.append(label); labelWidth = qMax(labelWidth, label->sizeHint().width()); } } Q_FOREACH (QLabel *label, labels) { label->setMinimumWidth(labelWidth); } bool allChannels8Bit = true; Q_FOREACH (KoChannelInfo* channel, channels) { if (channel->channelType() == KoChannelInfo::COLOR && channel->channelValueType() != KoChannelInfo::UINT8) { allChannels8Bit = false; } } if (allChannels8Bit) { KisColorInput* input = new KisHexColorInput(this, &m_color, displayRenderer); m_inputs.append(input); m_layout->addWidget(input); connect(input, SIGNAL(updated()), this, SLOT(update())); connect(this, SIGNAL(updated()), input, SLOT(update())); } m_layout->addItem(m_spacer); m_colorspaceSelector->blockSignals(true); m_colorspaceSelector->setCurrentColorSpace(cs); m_colorspaceSelector->blockSignals(false); m_updateAllowed = false; emit(updated()); m_updateAllowed = true; } void KisSpecificColorSelectorWidget::update() { if (m_updateAllowed) { m_updateCompressor->start(); } } void KisSpecificColorSelectorWidget::setColor(const KoColor& c) { m_updateAllowed = false; m_color.fromKoColor(c); emit(updated()); m_updateAllowed = true; } void KisSpecificColorSelectorWidget::updateTimeout() { emit(colorChanged(m_color)); } void KisSpecificColorSelectorWidget::setCustomColorSpace(const KoColorSpace *colorSpace) { m_customColorSpaceSelected = true; setColorSpace(colorSpace); setColor(m_color); } #include "moc_kis_specific_color_selector_widget.cpp" diff --git a/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.h b/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.h index f91f46010f..c0330f5e3b 100644 --- a/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.h +++ b/plugins/dockers/specificcolorselector/kis_specific_color_selector_widget.h @@ -1,67 +1,71 @@ /* * Copyright (c) 2008 Cyrille Berger * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_SPECIFIC_COLOR_SELECTOR_WIDGET_H_ #define _KIS_SPECIFIC_COLOR_SELECTOR_WIDGET_H_ #include #include +#include "kis_signal_auto_connection.h" class KoColorSpace; -class KoColorDisplayRendererInterface; class QVBoxLayout; class KisColorInput; class KisColorSpaceSelector; class QCheckBox; class KisSignalCompressor; class QSpacerItem; +class KisDisplayColorConverter; class KisSpecificColorSelectorWidget : public QWidget { Q_OBJECT public: KisSpecificColorSelectorWidget(QWidget* parent); ~KisSpecificColorSelectorWidget(); bool customColorSpaceUsed(); public Q_SLOTS: - void setDisplayRenderer(KoColorDisplayRendererInterface *displayRenderer); - void setColorSpace(const KoColorSpace*); + void setDisplayConverter(KisDisplayColorConverter *colorConverter); + + void setColorSpace(const KoColorSpace *cs, bool force = false); void setColor(const KoColor&); private Q_SLOTS: void update(); void updateTimeout(); void setCustomColorSpace(const KoColorSpace *); + void rereadCurrentColorSpace(bool force = false); Q_SIGNALS: void colorChanged(const KoColor&); void updated(); private: QList m_inputs; const KoColorSpace* m_colorSpace; QVBoxLayout *m_layout; QSpacerItem *m_spacer; KoColor m_color; bool m_updateAllowed; KisSignalCompressor *m_updateCompressor; KisColorSpaceSelector *m_colorspaceSelector; bool m_customColorSpaceSelected; QCheckBox *m_chkShowColorSpaceSelector; - KoColorDisplayRendererInterface *m_displayRenderer; - KoColorDisplayRendererInterface *m_fallbackRenderer; + + KisDisplayColorConverter *m_displayConverter; + KisSignalAutoConnectionsStore m_converterConnection; }; #endif diff --git a/plugins/dockers/specificcolorselector/specificcolorselector_dock.cc b/plugins/dockers/specificcolorselector/specificcolorselector_dock.cc index 3a2c19fe26..8a32792677 100644 --- a/plugins/dockers/specificcolorselector/specificcolorselector_dock.cc +++ b/plugins/dockers/specificcolorselector/specificcolorselector_dock.cc @@ -1,97 +1,74 @@ /* * Copyright (c) 2008 Cyrille Berger * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "specificcolorselector_dock.h" #include #include #include #include #include #include #include #include #include "kis_specific_color_selector_widget.h" SpecificColorSelectorDock::SpecificColorSelectorDock() : QDockWidget(i18n("Specific Color Selector")) , m_canvas(0) , m_view(0) , m_colorSelector(new KisSpecificColorSelectorWidget(this)) { setWidget(m_colorSelector); widget()->setContentsMargins(4,4,4,0); } void SpecificColorSelectorDock::setCanvas(KoCanvasBase * canvas) { setEnabled(canvas != 0); if (m_canvas) { m_canvas->disconnectCanvasObserver(this); - m_canvas->image()->disconnect(m_colorSelector); } - + KisCanvas2* kisCanvas = dynamic_cast(canvas); m_canvas = kisCanvas; if (!kisCanvas) { return; } - connect(kisCanvas->image(), SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), m_colorSelector, SLOT(setColorSpace(const KoColorSpace*))); - m_colorSelector->setDisplayRenderer(kisCanvas->displayColorConverter()->displayRendererInterface()); - - if (m_view && m_view->activeNode()) { - m_colorSelector->setColorSpace(m_view->activeNode()->colorSpace()); - } - + m_colorSelector->setDisplayConverter(kisCanvas->displayColorConverter()); } void SpecificColorSelectorDock::unsetCanvas() { setEnabled(false); m_canvas = 0; - m_colorSelector->setDisplayRenderer(0); + m_colorSelector->setDisplayConverter(0); } void SpecificColorSelectorDock::setMainWindow(KisViewManager* kisview) { m_view = kisview; connect(m_view->resourceProvider(), SIGNAL(sigFGColorChanged(const KoColor&)), m_colorSelector, SLOT(setColor(const KoColor&))); connect(m_colorSelector, SIGNAL(colorChanged(const KoColor&)), m_view->resourceProvider(), SLOT(slotSetFGColor(const KoColor&))); - connect(m_view->resourceProvider(), SIGNAL(sigNodeChanged(const KisNodeSP)), this, SLOT(layerChanged(const KisNodeSP))); -} - -void SpecificColorSelectorDock::layerChanged(const KisNodeSP node) -{ - if (!node) return; - if (!node->projection()) return; - if (!m_colorSelector) return; - if (!m_colorSelector->customColorSpaceUsed()) { - const KoColorSpace *cs = node->projection() ? - node->projection()->compositionSourceColorSpace() : - node->colorSpace(); - - m_colorSelector->setColorSpace(cs); - } - m_colorSelector->setColor(m_view->resourceProvider()->fgColor()); } #include "moc_specificcolorselector_dock.cpp" diff --git a/plugins/dockers/specificcolorselector/specificcolorselector_dock.h b/plugins/dockers/specificcolorselector/specificcolorselector_dock.h index f899b10d87..d1dd630580 100644 --- a/plugins/dockers/specificcolorselector/specificcolorselector_dock.h +++ b/plugins/dockers/specificcolorselector/specificcolorselector_dock.h @@ -1,50 +1,49 @@ /* * Copyright (c) 2008 Cyrille Berger * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _SPECIFICCOLORSELECTOR_DOCK_H_ #define _SPECIFICCOLORSELECTOR_DOCK_H_ #include #include #include class KisViewManager; class KisCanvas2; class KisSpecificColorSelectorWidget; class SpecificColorSelectorDock : public QDockWidget, public KisMainwindowObserver { Q_OBJECT public: SpecificColorSelectorDock(); QString observerName() { return "SpecificColorSelectorDock"; } /// reimplemented from KoCanvasObserverBase/KisMainwindowObserver virtual void setCanvas(KoCanvasBase *canvas); virtual void unsetCanvas(); virtual void setMainWindow(KisViewManager* kisview); -public Q_SLOTS: - void layerChanged(const KisNodeSP); + private: KisCanvas2 *m_canvas; KisViewManager *m_view; KisSpecificColorSelectorWidget* m_colorSelector; }; #endif