diff --git a/libs/ui/dialogs/kis_internal_color_selector.cpp b/libs/ui/dialogs/kis_internal_color_selector.cpp index 0224343e42..a2ac0be91c 100644 --- a/libs/ui/dialogs/kis_internal_color_selector.cpp +++ b/libs/ui/dialogs/kis_internal_color_selector.cpp @@ -1,122 +1,122 @@ /* * Copyright (C) Wolthera van Hovell tot Westerflier , (C) 2016 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU 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 #include #include #include #include "KoColorSpaceRegistry.h" #include "kis_signal_compressor.h" #include "kis_canvas_resource_provider.h" #include "KisViewManager.h" #include "KoColorDisplayRendererInterface.h" #include "kis_display_color_converter.h" #include "kis_spinbox_color_selector.h" #include "kis_internal_color_selector.h" struct KisInternalColorSelector::Private { bool allowUpdates = true; KoColor currentColor; const KoColorSpace *currentColorSpace; KisSpinboxColorSelector *spinBoxSelector; KisSignalCompressor *compressColorChanges; }; KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, const QString &caption) : QDialog(parent) ,m_d(new Private) { setModal(false); setWindowTitle(caption); this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); m_d->currentColor = color; m_d->currentColorSpace = m_d->currentColor.colorSpace(); m_d->spinBoxSelector = new KisSpinboxColorSelector(this, m_d->currentColor); if (m_d->spinBoxSelector) {qDebug()<<"valid";} //ui->base->addWidget(m_d->spinBoxSelector); //ui->verticalLayout->addWidget(m_d->spinBoxSelector); connect(m_d->spinBoxSelector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor))); connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector())); - m_d->compressColorChanges = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this); + m_d->compressColorChanges = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this); connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(endUpdateWithNewColor())); } KisInternalColorSelector::~KisInternalColorSelector() { delete ui; //TODO: Does the scoped pointer also need to be deleted??? } void KisInternalColorSelector::slotColorUpdated(KoColor newColor) { //if the update did not come from this selector... if (m_d->allowUpdates || QObject::sender() == this->parent()) { qDebug()<<"Color as received by the internal color selector" << KoColor::toQString(newColor); m_d->currentColor = newColor; updateAllElements(QObject::sender()); } } void KisInternalColorSelector::slotColorSpaceChanged(const KoColorSpace *cs) { if (cs == m_d->currentColorSpace) { return; } m_d->currentColorSpace = KoColorSpaceRegistry::instance()->colorSpace(cs->colorModelId().id(), cs->colorDepthId().id(), cs->profile()); //Empty the layout. m_d->spinBoxSelector->slotSetColorSpace(m_d->currentColorSpace); } void KisInternalColorSelector::slotConfigurationChanged() { //m_d->canvas->displayColorConverter()-> //slotColorSpaceChanged(m_d->canvas->image()->colorSpace()); } void KisInternalColorSelector::slotLockSelector() { m_d->allowUpdates = false; } void KisInternalColorSelector::updateAllElements(QObject *source) { //update everything!!! if (source != m_d->spinBoxSelector) { m_d->spinBoxSelector->slotSetColor(m_d->currentColor); } if (source != this->parent()) { emit(signalForegroundColorChosen(m_d->currentColor)); m_d->compressColorChanges->start(); } } void KisInternalColorSelector::endUpdateWithNewColor() { m_d->allowUpdates = true; } diff --git a/libs/ui/widgets/kis_spinbox_color_selector.cpp b/libs/ui/widgets/kis_spinbox_color_selector.cpp index 53fee9107f..911f0adb6a 100644 --- a/libs/ui/widgets/kis_spinbox_color_selector.cpp +++ b/libs/ui/widgets/kis_spinbox_color_selector.cpp @@ -1,209 +1,210 @@ /* * Copyright (C) Wolthera van Hovell tot Westerflier , (C) 2016 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU 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_spinbox_color_selector.h" #include #include #include #include #include "kis_signal_compressor.h" #include "KoChannelInfo.h" #include "KoColorSpaceTraits.h" #include "KoColorSpaceMaths.h" #include "KoColorSpaceRegistry.h" struct KisSpinboxColorSelector::Private { - bool allowUpdates = false; QList spinBoxList; QList doubleSpinBoxList; KoColor color; const KoColorSpace *cs; - KisSignalCompressor *compressUpdates; }; KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent, KoColor color) : QWidget(parent) , m_d(new Private) { - QFormLayout *layout = new QFormLayout(this); this->setLayout(layout); + this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); m_d->color = color; slotSetColorSpace(m_d->color.colorSpace()); - - m_d->compressUpdates = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this); - connect(m_d->compressUpdates, SIGNAL(timeout()), this, SLOT(slotFinishUpdate())); } KisSpinboxColorSelector::~KisSpinboxColorSelector() { } void KisSpinboxColorSelector::slotSetColor(KoColor color) { m_d->color = color; if (m_d->color.colorSpace() != m_d->cs) { slotSetColorSpace(m_d->color.colorSpace()); } - if (m_d->allowUpdates || QObject::sender() != this) { - updateSpinboxesWithNewValues(); - } + updateSpinboxesWithNewValues(); } void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs) { if (cs == m_d->cs) { return; } m_d->cs = KoColorSpaceRegistry::instance()->colorSpace(cs->colorModelId().id(), cs->colorDepthId().id(), cs->profile()); //remake spinboxes Q_FOREACH (QSpinBox *input, m_d->spinBoxList) { this->layout()->removeWidget(input); delete input; } m_d->spinBoxList.clear(); Q_FOREACH (QDoubleSpinBox *input, m_d->doubleSpinBoxList) { this->layout()->removeWidget(input); delete input; } m_d->doubleSpinBoxList.clear(); QList channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels()); Q_FOREACH (KoChannelInfo* channel, channels) { if (channel->channelType() == KoChannelInfo::COLOR) { switch (channel->channelValueType()) { case KoChannelInfo::UINT8: { QSpinBox *input = new QSpinBox(this); input->setMinimum(0); input->setMaximum(0xFF); m_d->spinBoxList.append(input); this->layout()->addWidget(input); if (input) { connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes())); } } break; case KoChannelInfo::UINT16: { QSpinBox *input = new QSpinBox(this); input->setMinimum(0); input->setMaximum(0xFFFF); m_d->spinBoxList.append(input); this->layout()->addWidget(input); if (input) { connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes())); } } break; case KoChannelInfo::UINT32: { QSpinBox *input = new QSpinBox(this); input->setMinimum(0); input->setMaximum(0xFFFFFFFF); m_d->spinBoxList.append(input); this->layout()->addWidget(input); if (input) { connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes())); } } break; case KoChannelInfo::FLOAT16: case KoChannelInfo::FLOAT32: { QDoubleSpinBox *input = new QDoubleSpinBox(this); input->setMinimum(0); input->setMaximum(1.0); m_d->doubleSpinBoxList.append(input); this->layout()->addWidget(input); if (input) { connect(input, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateFromSpinBoxes())); } } break; default: Q_ASSERT(false); } } } } void KisSpinboxColorSelector::createColorFromSpinboxValues() { KoColor newColor; int channelcount = m_d->cs->channelCount(); quint8 *data = new quint8[m_d->cs->pixelSize()]; QVector channelValues(channelcount); channelValues.fill(1.0); QList channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels()); - for (int i=0; ispinBoxList.size()); i++) { + for (int i=0; ics->colorChannelCount()); i++) { if (m_d->spinBoxList.at(i)) { if (channels.at(i)->channelValueType()==KoChannelInfo::UINT8){ int value = m_d->spinBoxList.at(i)->value(); channelValues[i] = KoColorSpaceMaths::scaleToA(value); } else if (channels.at(i)->channelValueType()==KoChannelInfo::UINT16){ channelValues[i] = KoColorSpaceMaths::scaleToA(m_d->spinBoxList.at(i)->value()); } } else if (m_d->doubleSpinBoxList.at(i)){ channelValues[i] = m_d->doubleSpinBoxList.at(i)->value(); } } m_d->cs->fromNormalisedChannelsValue(data, channelValues); newColor.setColor(data, m_d->cs); newColor.setOpacity(m_d->color.opacityU8()); m_d->color = newColor; } void KisSpinboxColorSelector::slotUpdateFromSpinBoxes() { - m_d->allowUpdates = false; createColorFromSpinboxValues(); emit sigNewColor(m_d->color); - m_d->compressUpdates->start(); -} - -void KisSpinboxColorSelector::slotFinishUpdate() -{ - m_d->allowUpdates = true; } void KisSpinboxColorSelector::updateSpinboxesWithNewValues() { int channelcount = m_d->cs->channelCount(); QVector channelValues(channelcount); channelValues.fill(1.0); m_d->cs->normalisedChannelsValue(m_d->color.data(), channelValues); QList channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels()); - for (int i=0; ispinBoxList.size()); i++) { + int i; + for (i=0; ispinBoxList.size(); i++) { + m_d->spinBoxList.at(i)->blockSignals(true); + } + for (i=0; idoubleSpinBoxList.size(); i++) { + m_d->doubleSpinBoxList.at(i)->blockSignals(true); + } + + for (i=0; ics->colorChannelCount()); i++) { if (m_d->spinBoxList.at(i)) { if (channels.at(i)->channelValueType() == KoChannelInfo::UINT8) { int value = KoColorSpaceMaths::scaleToA(channelValues[i]); m_d->spinBoxList.at(i)->setValue(value); } else if (channels.at(i)->channelValueType() == KoChannelInfo::UINT16) { m_d->spinBoxList.at(i)->setValue(KoColorSpaceMaths::scaleToA(channelValues[i])); } } else if (m_d->doubleSpinBoxList.at(i)) { m_d->doubleSpinBoxList.at(i)->setValue(channelValues[i]); } } + + for (i=0; ispinBoxList.size(); i++) { + m_d->spinBoxList.at(i)->blockSignals(false); + } + for (i=0; idoubleSpinBoxList.size(); i++) { + m_d->doubleSpinBoxList.at(i)->blockSignals(false); + } } diff --git a/libs/ui/widgets/kis_spinbox_color_selector.h b/libs/ui/widgets/kis_spinbox_color_selector.h index 21a2be95fd..e6b3c4c7f3 100644 --- a/libs/ui/widgets/kis_spinbox_color_selector.h +++ b/libs/ui/widgets/kis_spinbox_color_selector.h @@ -1,58 +1,57 @@ /* * Copyright (C) Wolthera van Hovell tot Westerflier , (C) 2016 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU 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 KISSPINBOXCOLORSELECTOR_H #define KISSPINBOXCOLORSELECTOR_H #include #include "kritaui_export.h" #include #include "KoColor.h" #include "KoColorSpace.h" /** * @brief The KisSpinboxColorSelector class * This will give a widget with spinboxes depending on the color space * Take responsibility for changing the color space. */ class KRITAUI_EXPORT KisSpinboxColorSelector : public QWidget { Q_OBJECT public: explicit KisSpinboxColorSelector(QWidget *parent, KoColor color); ~KisSpinboxColorSelector(); Q_SIGNALS: void sigNewColor(KoColor color); public Q_SLOTS: void slotSetColorSpace(const KoColorSpace *cs); void slotSetColor(KoColor color); private Q_SLOTS: void slotUpdateFromSpinBoxes(); - void slotFinishUpdate(); private: struct Private; const QScopedPointer m_d; void createColorFromSpinboxValues(); void updateSpinboxesWithNewValues(); }; #endif // KISSPINBOXCOLORSELECTOR_H