diff --git a/libs/ui/dialogs/kis_internal_color_selector.cpp b/libs/ui/dialogs/kis_internal_color_selector.cpp index a2ac0be91c..39131c85a5 100644 --- a/libs/ui/dialogs/kis_internal_color_selector.cpp +++ b/libs/ui/dialogs/kis_internal_color_selector.cpp @@ -1,122 +1,152 @@ /* * 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" +#include "ui_wdgdlginternalcolorselector.h" struct KisInternalColorSelector::Private { bool allowUpdates = true; KoColor currentColor; const KoColorSpace *currentColorSpace; - - - KisSpinboxColorSelector *spinBoxSelector; + bool chooseAlpha = false; + //KisSpinboxColorSelector *spinBoxSelector; KisSignalCompressor *compressColorChanges; }; -KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, const QString &caption) +KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor color, bool modal, const QString &caption) : QDialog(parent) ,m_d(new Private) { - setModal(false); + setModal(modal); + m_ui = new Ui_WdgDlgInternalColorSelector(); + m_ui->setupUi(this); + if (!modal) { + m_ui->buttonBox->hide(); + } + 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))); + + 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 ui; + 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::slotColorSpaceChanged(const KoColorSpace *cs) +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_d->spinBoxSelector->slotSetColorSpace(m_d->currentColorSpace); + 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_d->spinBoxSelector) { - m_d->spinBoxSelector->slotSetColor(m_d->currentColor); + 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 e842f1a40b..e2a49a3892 100644 --- a/libs/ui/dialogs/kis_internal_color_selector.h +++ b/libs/ui/dialogs/kis_internal_color_selector.h @@ -1,97 +1,115 @@ /* * 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 "kis_canvas2.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, const QString &caption); + KisInternalColorSelector(QWidget* parent, KoColor color, bool modal, const QString &caption); ~KisInternalColorSelector(); /** * @brief slotColorSpaceChanged - * Color space has changed. + * Color space has changed, use this dialog to change the colorspace. */ - void slotColorSpaceChanged(const KoColorSpace *cs); + 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 *ui; //the UI + 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/forms/wdgdlginternalcolorselector.ui b/libs/ui/forms/wdgdlginternalcolorselector.ui index 2df3e7e167..cce7ba65d6 100644 --- a/libs/ui/forms/wdgdlginternalcolorselector.ui +++ b/libs/ui/forms/wdgdlginternalcolorselector.ui @@ -1,67 +1,82 @@ WdgDlgInternalColorSelector 0 0 400 300 Dialog - + + + + 0 + 0 + + + Qt::Horizontal QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + KisSpinboxColorSelector + QWidget +
kis_spinbox_color_selector.h
+ 1 +
+
buttonBox accepted() WdgDlgInternalColorSelector accept() 248 254 157 274 buttonBox rejected() WdgDlgInternalColorSelector reject() 316 260 286 274
diff --git a/libs/ui/widgets/KoDualColorButton.cpp b/libs/ui/widgets/KoDualColorButton.cpp index b834c6cf8b..3083a8f8cd 100644 --- a/libs/ui/widgets/KoDualColorButton.cpp +++ b/libs/ui/widgets/KoDualColorButton.cpp @@ -1,352 +1,358 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Daniel M. Duley This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KoDualColorButton.h" #include "KoColor.h" #include "KoColorDisplayRendererInterface.h" #include #include "dcolorarrow.xbm" #include "dcolorreset.xpm" #include #include "dialogs/kis_internal_color_selector.h" #include #include #include #include #include #include class Q_DECL_HIDDEN KoDualColorButton::Private { public: Private(const KoColor &fgColor, const KoColor &bgColor, QWidget *_dialogParent, const KoColorDisplayRendererInterface *_displayRenderer) : dialogParent(_dialogParent) , dragFlag( false ) , miniCtlFlag( false ) , foregroundColor(fgColor) , backgroundColor(bgColor) , displayRenderer(_displayRenderer) { updateArrows(); resetPixmap = QPixmap( (const char **)dcolorreset_xpm ); popDialog = true; } void updateArrows() { arrowBitmap = QPixmap(12,12); arrowBitmap.fill(Qt::transparent); QPainter p(&arrowBitmap); p.setPen(dialogParent->palette().foreground().color()); // arrow pointing left p.drawLine(0, 3, 7, 3); p.drawLine(1, 2, 1, 4); p.drawLine(2, 1, 2, 5); p.drawLine(3, 0, 3, 6); // arrow pointing down p.drawLine(8, 4, 8, 11); p.drawLine(5, 8, 11, 8); p.drawLine(6, 9, 10, 9); p.drawLine(7, 10, 9, 10); } QWidget* dialogParent; QPixmap arrowBitmap; QPixmap resetPixmap; bool dragFlag, miniCtlFlag; KoColor foregroundColor; KoColor backgroundColor; KisInternalColorSelector *colorSelectorDialog; QPoint dragPosition; Selection tmpSelection; bool popDialog; const KoColorDisplayRendererInterface *displayRenderer; void init(KoDualColorButton *q); }; void KoDualColorButton::Private::init(KoDualColorButton *q) { if ( q->sizeHint().isValid() ) q->setMinimumSize( q->sizeHint() ); q->setAcceptDrops( true ); QString caption = "Select a color"; - colorSelectorDialog = new KisInternalColorSelector(q, foregroundColor, caption); + colorSelectorDialog = new KisInternalColorSelector(q, foregroundColor, false, caption); connect(colorSelectorDialog, SIGNAL(signalForegroundColorChosen(KoColor)), q, SLOT(slotSetForeGroundColorFromDialog(KoColor))); connect(q, SIGNAL(foregroundColorChanged(KoColor)), colorSelectorDialog, SLOT(slotColorUpdated(KoColor))); } KoDualColorButton::KoDualColorButton(const KoColor &foregroundColor, const KoColor &backgroundColor, QWidget *parent, QWidget* dialogParent ) : QWidget( parent ), d( new Private(foregroundColor, backgroundColor, dialogParent, KoDumbColorDisplayRenderer::instance()) ) { d->init(this); } KoDualColorButton::KoDualColorButton(const KoColor &foregroundColor, const KoColor &backgroundColor, const KoColorDisplayRendererInterface *displayRenderer, QWidget *parent, QWidget* dialogParent) : QWidget( parent ), d( new Private(foregroundColor, backgroundColor, dialogParent, displayRenderer) ) { d->init(this); } KoDualColorButton::~KoDualColorButton() { delete d; } KoColor KoDualColorButton::foregroundColor() const { return d->foregroundColor; } KoColor KoDualColorButton::backgroundColor() const { return d->backgroundColor; } bool KoDualColorButton::popDialog() const { return d->popDialog; } QSize KoDualColorButton::sizeHint() const { return QSize( 34, 34 ); } void KoDualColorButton::setForegroundColor( const KoColor &color ) { d->foregroundColor = color; d->colorSelectorDialog->slotColorUpdated(color); repaint(); } void KoDualColorButton::setBackgroundColor( const KoColor &color ) { d->backgroundColor = color; repaint(); } void KoDualColorButton::setPopDialog( bool popDialog ) { d->popDialog = popDialog; } void KoDualColorButton::metrics( QRect &foregroundRect, QRect &backgroundRect ) { foregroundRect = QRect( 0, 0, width() - 14, height() - 14 ); backgroundRect = QRect( 14, 14, width() - 14, height() - 14 ); } void KoDualColorButton::paintEvent(QPaintEvent *) { QRect foregroundRect; QRect backgroundRect; QPainter painter( this ); metrics( foregroundRect, backgroundRect ); QBrush defBrush = palette().brush( QPalette::Button ); QBrush foregroundBrush( d->displayRenderer->toQColor(d->foregroundColor), Qt::SolidPattern ); QBrush backgroundBrush( d->displayRenderer->toQColor(d->backgroundColor), Qt::SolidPattern ); qDrawShadeRect( &painter, backgroundRect, palette(), false, 1, 0, isEnabled() ? &backgroundBrush : &defBrush ); qDrawShadeRect( &painter, foregroundRect, palette(), false, 1, 0, isEnabled() ? &foregroundBrush : &defBrush ); painter.setPen( palette().color( QPalette::Shadow ) ); painter.drawPixmap( foregroundRect.right() + 2, 1, d->arrowBitmap ); painter.drawPixmap( 1, foregroundRect.bottom() + 2, d->resetPixmap ); } void KoDualColorButton::dragEnterEvent( QDragEnterEvent *event ) { event->setAccepted( isEnabled() && KColorMimeData::canDecode( event->mimeData() ) ); } void KoDualColorButton::dropEvent( QDropEvent *event ) { Q_UNUSED(event); /* QColor color = KColorMimeData::fromMimeData( event->mimeData() ); if ( color.isValid() ) { if ( d->selection == Foreground ) { d->foregroundColor = color; emit foregroundColorChanged( color ); } else { d->backgroundColor = color; emit backgroundColorChanged( color ); } repaint(); } */ } void KoDualColorButton::slotSetForeGroundColorFromDialog(const KoColor color) { d->foregroundColor = color; repaint(); qDebug()<<"Color as sent by the dual color button: "<foregroundColor); } void KoDualColorButton::mousePressEvent( QMouseEvent *event ) { QRect foregroundRect; QRect backgroundRect; metrics( foregroundRect, backgroundRect ); d->dragPosition = event->pos(); d->dragFlag = false; if ( foregroundRect.contains( d->dragPosition ) ) { d->tmpSelection = Foreground; d->miniCtlFlag = false; } else if( backgroundRect.contains( d->dragPosition ) ) { d->tmpSelection = Background; d->miniCtlFlag = false; } else if ( event->pos().x() > foregroundRect.width() ) { // We handle the swap and reset controls as soon as the mouse is // is pressed and ignore further events on this click (mosfet). KoColor tmp = d->foregroundColor; d->foregroundColor = d->backgroundColor; d->backgroundColor = tmp; emit backgroundColorChanged( d->backgroundColor ); emit foregroundColorChanged( d->foregroundColor ); d->miniCtlFlag = true; } else if ( event->pos().x() < backgroundRect.x() ) { d->foregroundColor = d->displayRenderer->approximateFromRenderedQColor(Qt::black); d->backgroundColor = d->displayRenderer->approximateFromRenderedQColor(Qt::white); emit backgroundColorChanged( d->backgroundColor ); emit foregroundColorChanged( d->foregroundColor ); d->miniCtlFlag = true; } repaint(); } void KoDualColorButton::mouseMoveEvent( QMouseEvent *event ) { if ( !d->miniCtlFlag ) { int delay = QApplication::startDragDistance(); if ( event->x() >= d->dragPosition.x() + delay || event->x() <= d->dragPosition.x() - delay || event->y() >= d->dragPosition.y() + delay || event->y() <= d->dragPosition.y() - delay ) { KColorMimeData::createDrag( d->tmpSelection == Foreground ? d->displayRenderer->toQColor(d->foregroundColor) : d->displayRenderer->toQColor(d->backgroundColor), this )->start(); d->dragFlag = true; } } } void KoDualColorButton::mouseReleaseEvent( QMouseEvent *event ) { d->dragFlag = false; if ( d->miniCtlFlag ) return; d->miniCtlFlag = false; QRect foregroundRect; QRect backgroundRect; metrics( foregroundRect, backgroundRect ); if ( foregroundRect.contains( event->pos() )) { if(d->tmpSelection == Foreground ) { if( d->popDialog) { d->colorSelectorDialog->show(); + //QColor c = d->displayRenderer->toQColor(d->foregroundColor); //c = QColorDialog::getColor(c, this) ; + //if (c.isValid()) { // d->foregroundColor = d->displayRenderer->approximateFromRenderedQColor(c); // emit foregroundColorChanged(d->foregroundColor); //} } else emit pleasePopDialog( d->foregroundColor); } else { d->foregroundColor = d->backgroundColor; emit foregroundColorChanged( d->foregroundColor ); } } else if ( backgroundRect.contains( event->pos() )) { if(d->tmpSelection == Background ) { if( d->popDialog) { - QColor c = d->displayRenderer->toQColor(d->backgroundColor); + KoColor c = d->backgroundColor; + c = KisInternalColorSelector::getModalColorDialog(c, false, this); + d->backgroundColor = c; + emit backgroundColorChanged(d->backgroundColor); + /*QColor c = d->displayRenderer->toQColor(d->backgroundColor); c = QColorDialog::getColor(c, this); if (c.isValid()) { d->backgroundColor = d->displayRenderer->approximateFromRenderedQColor(c); emit backgroundColorChanged(d->backgroundColor); - } + }*/ } else emit pleasePopDialog( d->backgroundColor); } else { d->backgroundColor = d->foregroundColor; emit backgroundColorChanged( d->backgroundColor ); } } repaint(); } void KoDualColorButton::changeEvent(QEvent *event) { QWidget::changeEvent(event); switch (event->type()) { case QEvent::StyleChange: case QEvent::PaletteChange: d->updateArrows(); default: break; } } diff --git a/libs/ui/widgets/kis_spinbox_color_selector.cpp b/libs/ui/widgets/kis_spinbox_color_selector.cpp index 911f0adb6a..5aa3f540bf 100644 --- a/libs/ui/widgets/kis_spinbox_color_selector.cpp +++ b/libs/ui/widgets/kis_spinbox_color_selector.cpp @@ -1,210 +1,211 @@ /* * 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 { QList spinBoxList; QList doubleSpinBoxList; KoColor color; const KoColorSpace *cs; }; -KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent, KoColor color) : QWidget(parent) , m_d(new Private) +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 (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; 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() { 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; 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 e6b3c4c7f3..a4babd6af2 100644 --- a/libs/ui/widgets/kis_spinbox_color_selector.h +++ b/libs/ui/widgets/kis_spinbox_color_selector.h @@ -1,57 +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); + explicit KisSpinboxColorSelector(QWidget *parent); ~KisSpinboxColorSelector(); 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