diff --git a/libs/ui/dialogs/kis_internal_color_selector.cpp b/libs/ui/dialogs/kis_internal_color_selector.cpp index 39131c85a5..6c15a70626 100644 --- a/libs/ui/dialogs/kis_internal_color_selector.cpp +++ b/libs/ui/dialogs/kis_internal_color_selector.cpp @@ -1,152 +1,144 @@ /* * 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 "KisViewManager.h" #include "KoColorDisplayRendererInterface.h" #include "kis_display_color_converter.h" #include "kis_spinbox_color_selector.h" #include "kis_internal_color_selector.h" #include "ui_wdgdlginternalcolorselector.h" struct KisInternalColorSelector::Private { bool allowUpdates = true; KoColor currentColor; const KoColorSpace *currentColorSpace; bool chooseAlpha = false; - //KisSpinboxColorSelector *spinBoxSelector; KisSignalCompressor *compressColorChanges; }; KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, bool modal, const QString &caption) : QDialog(parent) ,m_d(new Private) { setModal(modal); m_ui = new Ui_WdgDlgInternalColorSelector(); m_ui->setupUi(this); if (!modal) { m_ui->buttonBox->hide(); } setWindowTitle(caption); m_d->currentColor = color; m_d->currentColorSpace = m_d->currentColor.colorSpace(); m_ui->spinboxselector->slotSetColor(color); connect(m_ui->spinboxselector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor))); connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector())); m_d->compressColorChanges = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this); connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(endUpdateWithNewColor())); connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); } KisInternalColorSelector::~KisInternalColorSelector() { delete m_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::colorSpaceChanged(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_ui->spinboxselector->slotSetColorSpace(m_d->currentColorSpace); } KoColor KisInternalColorSelector::getModalColorDialog(const KoColor color, bool chooseAlpha, QWidget* parent, QString caption) { KisInternalColorSelector dialog(parent, color, true, caption); dialog.chooseAlpha(chooseAlpha); dialog.exec(); return dialog.getCurrentColor(); } KoColor KisInternalColorSelector::getCurrentColor() { return m_d->currentColor; } void KisInternalColorSelector::chooseAlpha(bool chooseAlpha) { m_d->chooseAlpha = chooseAlpha; } -void KisInternalColorSelector::setDialogModal(bool modal) -{ - m_ui->buttonBox->show(); - setModal(true); -} - 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_ui->spinboxselector) { m_ui->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/dialogs/kis_internal_color_selector.h b/libs/ui/dialogs/kis_internal_color_selector.h index e2a49a3892..9af75c2374 100644 --- a/libs/ui/dialogs/kis_internal_color_selector.h +++ b/libs/ui/dialogs/kis_internal_color_selector.h @@ -1,115 +1,114 @@ /* * 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 KISINTERNALCOLORSELECTOR_H #define KISINTERNALCOLORSELECTOR_H #include "kritaui_export.h" #include "KoColor.h" #include "KoColorSpace.h" #include #include "ui_wdgdlginternalcolorselector.h" /** * @brief The KisInternalColorSelector class * * A non-modal color selector dialog that is not a plugin and can thus be used for filters. */ class KRITAUI_EXPORT KisInternalColorSelector : public QDialog { Q_OBJECT public: KisInternalColorSelector(QWidget* parent, KoColor color, bool modal, const QString &caption); ~KisInternalColorSelector(); /** * @brief slotColorSpaceChanged * Color space has changed, use this dialog to change the colorspace. */ void colorSpaceChanged(const KoColorSpace *cs); /** * @brief getModalColorDialog * Excecute this dialog modally. The function returns * the KoColor you want. * @param color - The current color. Make sure this is in the color space you want your * end color to be in. * @param chooseAlpha - Whether or not the alpha-choosing functionality should be used. */ static KoColor getModalColorDialog(const KoColor color, bool chooseAlpha = false, QWidget* parent = Q_NULLPTR, QString caption = QString()); /** * @brief getCurrentColor * @return gives currently active color; */ KoColor getCurrentColor(); void chooseAlpha(bool chooseAlpha); - void setDialogModal(bool modal); Q_SIGNALS: /** * @brief signalForegroundColorChosen * The most important signal. This will sent out when a color has been picked from the selector. * There will be a small delay to make sure that the selector causes too many updates. * * Do not connect this to slotColorUpdated. * @param color The new color chosen */ void signalForegroundColorChosen(KoColor color); public Q_SLOTS: /** * @brief slotColorUpdated * Very important slot. Is connected to krita's resources to make sure it has * the currently active color. It's very important that this function is able to understand * when the signal came from itself. * @param newColor This is the new color. */ void slotColorUpdated(KoColor newColor); private Q_SLOTS: /** * @brief slotLockSelector * This slot will prevent the color from being updated. */ void slotLockSelector(); /** * @brief slotConfigurationChanged * Wrapper slot for changes to the colorspace. */ void slotConfigurationChanged(); void endUpdateWithNewColor(); private: Ui_WdgDlgInternalColorSelector *m_ui; //the UI struct Private; //The private struct const QScopedPointer m_d; //the private pointer /** * @brief updateAllElements * Updates each widget with the new element, and if it's responsible for the update sents * a signal out that there's a new color. */ void updateAllElements(QObject *source); }; #endif // KISINTERNALCOLORSELECTOR_H diff --git a/libs/ui/widgets/kis_spinbox_color_selector.cpp b/libs/ui/widgets/kis_spinbox_color_selector.cpp index ef85e7dede..0c790b798c 100644 --- a/libs/ui/widgets/kis_spinbox_color_selector.cpp +++ b/libs/ui/widgets/kis_spinbox_color_selector.cpp @@ -1,210 +1,232 @@ /* * 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 "kis_double_parse_spin_box.h" #include "kis_int_parse_spin_box.h" #include "kis_signal_compressor.h" #include "KoChannelInfo.h" #include "KoColorSpaceTraits.h" #include "KoColorSpaceMaths.h" #include "KoColorSpaceRegistry.h" struct KisSpinboxColorSelector::Private { QList spinBoxList; QList doubleSpinBoxList; KoColor color; const KoColorSpace *cs; + bool chooseAlpha = false; }; KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent) : QWidget(parent) , m_d(new Private) { - QFormLayout *layout = new QFormLayout(this); - this->setLayout(layout); this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); KoColor color = KoColor(); m_d->color = color; slotSetColorSpace(m_d->color.colorSpace()); } KisSpinboxColorSelector::~KisSpinboxColorSelector() { } void KisSpinboxColorSelector::slotSetColor(KoColor color) { m_d->color = color; if (m_d->color.colorSpace() != m_d->cs) { slotSetColorSpace(m_d->color.colorSpace()); } 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 (KisIntParseSpinBox *input, m_d->spinBoxList) { - this->layout()->removeWidget(input); - delete input; + if (this->layout()) { + qDeleteAll(this->children()); } m_d->spinBoxList.clear(); - Q_FOREACH (KisDoubleParseSpinBox *input, m_d->doubleSpinBoxList) { - this->layout()->removeWidget(input); - delete input; - } m_d->doubleSpinBoxList.clear(); + QFormLayout *layout = new QFormLayout(this); QList channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels()); Q_FOREACH (KoChannelInfo* channel, channels) { - if (channel->channelType() == KoChannelInfo::COLOR) { - switch (channel->channelValueType()) { - case KoChannelInfo::UINT8: { - KisIntParseSpinBox *input = new KisIntParseSpinBox(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())); - } + QString inputLabel = channel->name(); + switch (channel->channelValueType()) { + case KoChannelInfo::UINT8: { + KisIntParseSpinBox *input = new KisIntParseSpinBox(this); + input->setMinimum(0); + input->setMaximum(0xFF); + m_d->spinBoxList.append(input); + layout->addRow(inputLabel,input); + if (input) { + connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes())); } - break; - case KoChannelInfo::UINT16: { - KisIntParseSpinBox *input = new KisIntParseSpinBox(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())); - } + if (channel->channelType()==KoChannelInfo::ALPHA && m_d->chooseAlpha == false) { + input->setEnabled(false); + input->blockSignals(true); } + } break; - case KoChannelInfo::UINT32: { - KisIntParseSpinBox *input = new KisIntParseSpinBox(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())); - } + case KoChannelInfo::UINT16: { + KisIntParseSpinBox *input = new KisIntParseSpinBox(this); + input->setMinimum(0); + input->setMaximum(0xFFFF); + m_d->spinBoxList.append(input); + layout->addRow(inputLabel,input); + if (input) { + connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes())); } + if (channel->channelType()==KoChannelInfo::ALPHA && m_d->chooseAlpha == false) { + input->setEnabled(false); + input->blockSignals(true); + } + } break; - case KoChannelInfo::FLOAT16: - case KoChannelInfo::FLOAT32: { - KisDoubleParseSpinBox *input = new KisDoubleParseSpinBox(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())); - } + case KoChannelInfo::UINT32: { + KisIntParseSpinBox *input = new KisIntParseSpinBox(this); + input->setMinimum(0); + input->setMaximum(0xFFFFFFFF); + m_d->spinBoxList.append(input); + layout->addRow(inputLabel,input); + if (input) { + connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes())); } + if (channel->channelType()==KoChannelInfo::ALPHA && m_d->chooseAlpha == false) { + input->setEnabled(false); + input->blockSignals(true); + } + } break; - default: - Q_ASSERT(false); + case KoChannelInfo::FLOAT16: + case KoChannelInfo::FLOAT32: { + KisDoubleParseSpinBox *input = new KisDoubleParseSpinBox(this); + input->setMinimum(0); + input->setMaximum(1.0); + m_d->doubleSpinBoxList.append(input); + layout->addRow(inputLabel,input); + if (input) { + connect(input, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateFromSpinBoxes())); + } + if (channel->channelType()==KoChannelInfo::ALPHA && m_d->chooseAlpha == false) { + input->setEnabled(false); + input->blockSignals(true); } - } + break; + default: + Q_ASSERT(false); + } + } + this->setLayout(layout); } 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; ics->colorChannelCount()); i++) { + int channelposition = KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels()); 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); + channelValues[channelposition] = KoColorSpaceMaths::scaleToA(value); } else if (channels.at(i)->channelValueType()==KoChannelInfo::UINT16){ - channelValues[i] = KoColorSpaceMaths::scaleToA(m_d->spinBoxList.at(i)->value()); + channelValues[channelposition] = KoColorSpaceMaths::scaleToA(m_d->spinBoxList.at(i)->value()); } } else if (m_d->doubleSpinBoxList.at(i)){ - channelValues[i] = m_d->doubleSpinBoxList.at(i)->value(); + channelValues[channelposition] = 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() { createColorFromSpinboxValues(); emit sigNewColor(m_d->color); } 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()); int i; + /*while (QLayoutItem *item = this->layout()->takeAt(0)) + { + item->widget()->blockSignals(true); + }*/ 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++) { + int channelposition = KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels()); if (m_d->spinBoxList.at(i)) { if (channels.at(i)->channelValueType() == KoChannelInfo::UINT8) { - int value = KoColorSpaceMaths::scaleToA(channelValues[i]); + int value = KoColorSpaceMaths::scaleToA(channelValues[channelposition]); 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])); + m_d->spinBoxList.at(i)->setValue(KoColorSpaceMaths::scaleToA(channelValues[channelposition])); } } else if (m_d->doubleSpinBoxList.at(i)) { - m_d->doubleSpinBoxList.at(i)->setValue(channelValues[i]); + m_d->doubleSpinBoxList.at(i)->setValue(channelValues[channelposition]); } } 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); } + /*while (QLayoutItem *item = this->layout()->takeAt(0)) + { + item->widget()->blockSignals(false); + }*/ } diff --git a/libs/ui/widgets/kis_spinbox_color_selector.h b/libs/ui/widgets/kis_spinbox_color_selector.h index a4babd6af2..7c3106f485 100644 --- a/libs/ui/widgets/kis_spinbox_color_selector.h +++ b/libs/ui/widgets/kis_spinbox_color_selector.h @@ -1,57 +1,59 @@ /* * 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); ~KisSpinboxColorSelector(); + void chooseAlpha(bool chooseAlpha); + Q_SIGNALS: void sigNewColor(KoColor color); public Q_SLOTS: void slotSetColorSpace(const KoColorSpace *cs); void slotSetColor(KoColor color); private Q_SLOTS: void slotUpdateFromSpinBoxes(); private: struct Private; const QScopedPointer m_d; void createColorFromSpinboxValues(); void updateSpinboxesWithNewValues(); }; #endif // KISSPINBOXCOLORSELECTOR_H