diff --git a/libs/ui/widgets/kis_visual_color_selector.cpp b/libs/ui/widgets/kis_visual_color_selector.cpp index 43c09a598c..92d04b9420 100644 --- a/libs/ui/widgets/kis_visual_color_selector.cpp +++ b/libs/ui/widgets/kis_visual_color_selector.cpp @@ -1,1621 +1,1644 @@ /* * 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_visual_color_selector.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "KoColorConversions.h" #include "KoColorDisplayRendererInterface.h" #include "KoChannelInfo.h" #include #include #include "kis_signal_compressor.h" #include "kis_debug.h" struct KisVisualColorSelector::Private { KoColor currentcolor; const KoColorSpace *currentCS {0}; QList widgetlist; bool updateSelf {false}; bool updateLonesome {false}; //for Modal dialogs. bool circular {false}; const KoColorDisplayRendererInterface *displayRenderer {0}; - KisVisualColorSelector::Configuration acs_config; + KisColorSelectorConfiguration acs_config; //Current coordinates. KisSignalCompressor *updateTimer {0}; QVector currentCoordinates; }; KisVisualColorSelector::KisVisualColorSelector(QWidget *parent) : QWidget(parent) , m_d(new Private) { this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); QVBoxLayout *layout = new QVBoxLayout; this->setLayout(layout); KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); - m_d->acs_config = Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", KisVisualColorSelector::Configuration().toString())); + m_d->acs_config = KisColorSelectorConfiguration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelectorConfiguration().toString())); } KisVisualColorSelector::~KisVisualColorSelector() { } void KisVisualColorSelector::slotSetColor(KoColor c) { if (m_d->updateSelf == false) { m_d->currentcolor = c; if (m_d->currentCS != c.colorSpace()) { slotsetColorSpace(c.colorSpace()); } } updateSelectorElements(QObject::sender()); } void KisVisualColorSelector::slotsetColorSpace(const KoColorSpace *cs) { if (m_d->currentCS != cs) { m_d->currentCS = cs; slotRebuildSelectors(); } } void KisVisualColorSelector::setConfig(bool forceCircular, bool forceSelfUpdate) { m_d->updateLonesome = forceSelfUpdate; m_d->circular = forceCircular; } KoColor KisVisualColorSelector::getCurrentColor() { return m_d->currentcolor; } void KisVisualColorSelector::ConfigurationChanged() { - m_d->updateTimer = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this); m_d->updateTimer->start(); - connect(m_d->updateTimer, SIGNAL(timeout()), SLOT(slotRebuildSelectors()), Qt::UniqueConnection); } void KisVisualColorSelector::slotRebuildSelectors() { KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); - m_d->acs_config = Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", KisVisualColorSelector::Configuration().toString())); + m_d->acs_config = KisColorSelectorConfiguration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelectorConfiguration().toString())); qDeleteAll(children()); m_d->widgetlist.clear(); QLayout *layout = new QHBoxLayout; //redraw all the widgets. int sizeValue = qMin(width(), height()); int borderWidth = qMax(sizeValue*0.1, 20.0); if (m_d->currentCS->colorChannelCount() == 1) { KisVisualColorSelectorShape *bar; if (m_d->circular==false) { bar = new KisVisualRectangleSelectorShape(this, KisVisualColorSelectorShape::onedimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 0, 0,m_d->displayRenderer, borderWidth); bar->setMaximumWidth(width()*0.1); bar->setMaximumHeight(height()); } else { bar = new KisVisualEllipticalSelectorShape(this, KisVisualColorSelectorShape::onedimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 0, 0,m_d->displayRenderer, borderWidth, KisVisualEllipticalSelectorShape::borderMirrored); layout->setMargin(0); } connect (bar, SIGNAL(sigNewColor(KoColor)), this, SLOT(updateFromWidgets(KoColor))); layout->addWidget(bar); m_d->widgetlist.append(bar); } else if (m_d->currentCS->colorChannelCount() == 3) { QRect newrect(0,0, this->geometry().width(), this->geometry().height()); KisVisualColorSelectorShape::ColorModel modelS = KisVisualColorSelectorShape::HSV; int channel1 = 0; int channel2 = 1; int channel3 = 2; switch(m_d->acs_config.subTypeParameter) { - case H: + case KisColorSelectorConfiguration::H: channel1 = 0; break; - case hsyS: - case hsiS: - case hslS: - case hsvS: + case KisColorSelectorConfiguration::hsyS: + case KisColorSelectorConfiguration::hsiS: + case KisColorSelectorConfiguration::hslS: + case KisColorSelectorConfiguration::hsvS: channel1 = 1; break; - case V: - case L: - case I: - case Y: + case KisColorSelectorConfiguration::V: + case KisColorSelectorConfiguration::L: + case KisColorSelectorConfiguration::I: + case KisColorSelectorConfiguration::Y: channel1 = 2; break; default: Q_ASSERT_X(false, "", "Invalid acs_config.subTypeParameter"); } switch(m_d->acs_config.mainTypeParameter) { - case hsySH: + case KisColorSelectorConfiguration::hsySH: modelS = KisVisualColorSelectorShape::HSY; channel2 = 0; channel3 = 1; break; - case hsiSH: + case KisColorSelectorConfiguration::hsiSH: modelS = KisVisualColorSelectorShape::HSI; channel2 = 0; channel3 = 1; break; - case hslSH: + case KisColorSelectorConfiguration::hslSH: modelS = KisVisualColorSelectorShape::HSL; channel2 = 0; channel3 = 1; break; - case hsvSH: + case KisColorSelectorConfiguration::hsvSH: modelS = KisVisualColorSelectorShape::HSV; channel2 = 0; channel3 = 1; break; - case YH: + case KisColorSelectorConfiguration::YH: modelS = KisVisualColorSelectorShape::HSY; channel2 = 0; channel3 = 2; break; - case LH: + case KisColorSelectorConfiguration::LH: modelS = KisVisualColorSelectorShape::HSL; channel2 = 0; channel3 = 2; break; - case IH: + case KisColorSelectorConfiguration::IH: modelS = KisVisualColorSelectorShape::HSL; channel2 = 0; channel3 = 2; break; - case VH: + case KisColorSelectorConfiguration::VH: modelS = KisVisualColorSelectorShape::HSV; channel2 = 0; channel3 = 2; break; - case SY: + case KisColorSelectorConfiguration::SY: modelS = KisVisualColorSelectorShape::HSY; channel2 = 1; channel3 = 2; break; - case SI: + case KisColorSelectorConfiguration::SI: modelS = KisVisualColorSelectorShape::HSI; channel2 = 1; channel3 = 2; break; - case SL: + case KisColorSelectorConfiguration::SL: modelS = KisVisualColorSelectorShape::HSL; channel2 = 1; channel3 = 2; break; - case SV: - case SV2: + case KisColorSelectorConfiguration::SV: + case KisColorSelectorConfiguration::SV2: modelS = KisVisualColorSelectorShape::HSV; channel2 = 1; channel3 = 2; break; default: Q_ASSERT_X(false, "", "Invalid acs_config.mainTypeParameter"); } - if (m_d->acs_config.mainType==Triangle) { + if (m_d->acs_config.mainType == KisColorSelectorConfiguration::Triangle) { modelS = KisVisualColorSelectorShape::HSV; //Triangle only really works in HSV mode. } KisVisualColorSelectorShape *bar; - if (m_d->acs_config.subType==Ring) { + if (m_d->acs_config.subType == KisColorSelectorConfiguration::Ring) { bar = new KisVisualEllipticalSelectorShape(this, KisVisualColorSelectorShape::onedimensional, modelS, m_d->currentCS, channel1, channel1, m_d->displayRenderer, borderWidth,KisVisualEllipticalSelectorShape::border); bar->resize(sizeValue, sizeValue); - } else if (m_d->acs_config.subType==Slider && m_d->circular==false) { + } + else if (m_d->acs_config.subType == KisColorSelectorConfiguration::Slider && m_d->circular==false) { bar = new KisVisualRectangleSelectorShape(this, KisVisualColorSelectorShape::onedimensional, modelS, m_d->currentCS, channel1, channel1, m_d->displayRenderer, borderWidth); bar->setMaximumWidth(borderWidth); bar->setMinimumWidth(borderWidth); bar->setMinimumHeight(sizeValue); - } else if (m_d->acs_config.subType==Slider && m_d->circular==true) { + } + else if (m_d->acs_config.subType == KisColorSelectorConfiguration::Slider && m_d->circular==true) { bar = new KisVisualEllipticalSelectorShape(this, KisVisualColorSelectorShape::onedimensional, modelS, m_d->currentCS, channel1, channel1, m_d->displayRenderer, borderWidth, KisVisualEllipticalSelectorShape::borderMirrored); bar->resize(sizeValue, sizeValue); } else { // Accessing bar below would crash since it's not initialized. // Hopefully this can never happen. warnUI << "Invalid subType, cannot initialize KisVisualColorSelectorShape"; Q_ASSERT_X(false, "", "Invalid subType, cannot initialize KisVisualColorSelectorShape"); return; } bar->setColor(m_d->currentcolor); m_d->widgetlist.append(bar); KisVisualColorSelectorShape *block; - if (m_d->acs_config.mainType==Triangle) { + if (m_d->acs_config.mainType == KisColorSelectorConfiguration::Triangle) { block = new KisVisualTriangleSelectorShape(this, KisVisualColorSelectorShape::twodimensional, modelS, m_d->currentCS, channel2, channel3, m_d->displayRenderer); block->setGeometry(bar->getSpaceForTriangle(newrect)); - } else if (m_d->acs_config.mainType==Square) { + } else if (m_d->acs_config.mainType == KisColorSelectorConfiguration::Square) { block = new KisVisualRectangleSelectorShape(this, KisVisualColorSelectorShape::twodimensional, modelS, m_d->currentCS, channel2, channel3, m_d->displayRenderer); block->setGeometry(bar->getSpaceForSquare(newrect)); } else { block = new KisVisualEllipticalSelectorShape(this, KisVisualColorSelectorShape::twodimensional, modelS, m_d->currentCS, channel2, channel3, m_d->displayRenderer); block->setGeometry(bar->getSpaceForCircle(newrect)); } block->setColor(m_d->currentcolor); connect (bar, SIGNAL(sigNewColor(KoColor)), block, SLOT(setColorFromSibling(KoColor))); connect (block, SIGNAL(sigNewColor(KoColor)), SLOT(updateFromWidgets(KoColor))); connect (bar, SIGNAL(sigHSXchange()), SLOT(HSXwrangler())); connect (block, SIGNAL(sigHSXchange()), SLOT(HSXwrangler())); m_d->widgetlist.append(block); - } else if (m_d->currentCS->colorChannelCount() == 4) { + } + else if (m_d->currentCS->colorChannelCount() == 4) { KisVisualRectangleSelectorShape *block = new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 0, 1); KisVisualRectangleSelectorShape *block2 = new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,KisVisualColorSelectorShape::Channel, m_d->currentCS, 2, 3); block->setMaximumWidth(width()*0.5); block->setMaximumHeight(height()); block2->setMaximumWidth(width()*0.5); block2->setMaximumHeight(height()); block->setColor(m_d->currentcolor); block2->setColor(m_d->currentcolor); connect (block, SIGNAL(sigNewColor(KoColor)), block2, SLOT(setColorFromSibling(KoColor))); connect (block2, SIGNAL(sigNewColor(KoColor)), SLOT(updateFromWidgets(KoColor))); layout->addWidget(block); layout->addWidget(block2); m_d->widgetlist.append(block); m_d->widgetlist.append(block2); } this->setLayout(layout); } void KisVisualColorSelector::setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer) { m_d->displayRenderer = displayRenderer; if (m_d->widgetlist.size()>0) { Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) { shape->setDisplayRenderer(displayRenderer); } } } void KisVisualColorSelector::updateSelectorElements(QObject *source) { //first lock all elements from sending updates, then update all elements. Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) { shape->blockSignals(true); } Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) { if (shape!=source) { if (m_d->updateSelf) { shape->setColorFromSibling(m_d->currentcolor); } else { shape->setColor(m_d->currentcolor); } } } Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) { shape->blockSignals(false); } } void KisVisualColorSelector::updateFromWidgets(KoColor c) { m_d->currentcolor = c; m_d->updateSelf = true; if (m_d->updateLonesome) { slotSetColor(c); Q_EMIT sigNewColor(c); } else { Q_EMIT sigNewColor(c); } } void KisVisualColorSelector::leaveEvent(QEvent *) { m_d->updateSelf = false; } void KisVisualColorSelector::resizeEvent(QResizeEvent *) { int sizeValue = qMin(width(), height()); int borderWidth = qMax(sizeValue*0.1, 20.0); QRect newrect(0,0, this->geometry().width(), this->geometry().height()); if (!m_d->currentCS) { slotsetColorSpace(m_d->currentcolor.colorSpace()); } if (m_d->currentCS->colorChannelCount()==3) { - if (m_d->acs_config.subType==Ring) { + + if (m_d->acs_config.subType == KisColorSelectorConfiguration::Ring) { m_d->widgetlist.at(0)->resize(sizeValue,sizeValue); - } else if (m_d->acs_config.subType==Slider && m_d->circular==false) { + } + else if (m_d->acs_config.subType == KisColorSelectorConfiguration::Slider && m_d->circular==false) { m_d->widgetlist.at(0)->setMaximumWidth(borderWidth); m_d->widgetlist.at(0)->setMinimumWidth(borderWidth); m_d->widgetlist.at(0)->setMinimumHeight(sizeValue); m_d->widgetlist.at(0)->setMaximumHeight(sizeValue); - } else if (m_d->acs_config.subType==Slider && m_d->circular==true) { + } + else if (m_d->acs_config.subType == KisColorSelectorConfiguration::Slider && m_d->circular==true) { m_d->widgetlist.at(0)->resize(sizeValue,sizeValue); } m_d->widgetlist.at(0)->setBorderWidth(borderWidth); - if (m_d->acs_config.mainType==Triangle) { + if (m_d->acs_config.mainType == KisColorSelectorConfiguration::Triangle) { m_d->widgetlist.at(1)->setGeometry(m_d->widgetlist.at(0)->getSpaceForTriangle(newrect)); - } else if (m_d->acs_config.mainType==Square) { + } + else if (m_d->acs_config.mainType == KisColorSelectorConfiguration::Square) { m_d->widgetlist.at(1)->setGeometry(m_d->widgetlist.at(0)->getSpaceForSquare(newrect)); - } else if (m_d->acs_config.mainType==Wheel) { + } + else if (m_d->acs_config.mainType == KisColorSelectorConfiguration::Wheel) { m_d->widgetlist.at(1)->setGeometry(m_d->widgetlist.at(0)->getSpaceForCircle(newrect)); } } Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) { shape->update(); } } void KisVisualColorSelector::HSXwrangler() { m_d->currentCoordinates = QVector (3); QVector w1 = m_d->widgetlist.at(0)->getHSX(m_d->currentCoordinates, true); QVector w2 = m_d->widgetlist.at(1)->getHSX(m_d->currentCoordinates, true); QVector ch(3); ch[0] = m_d->widgetlist.at(0)->getChannels().at(0); ch[1] = m_d->widgetlist.at(1)->getChannels().at(0); ch[2] = m_d->widgetlist.at(1)->getChannels().at(1); m_d->currentCoordinates[ch[0]] = w1[ch[0]]; m_d->currentCoordinates[ch[1]] = w2[ch[1]]; m_d->currentCoordinates[ch[2]] = w2[ch[2]]; m_d->widgetlist.at(0)->setHSX(m_d->currentCoordinates, true); m_d->widgetlist.at(1)->setHSX(m_d->currentCoordinates, true); } /*------------Selector shape------------*/ struct KisVisualColorSelectorShape::Private { QImage gradient; QImage fullSelector; - bool imagesNeedUpdate= true; + bool imagesNeedUpdate {true}; QPointF currentCoordinates; Dimensions dimension; ColorModel model; const KoColorSpace *cs; KoColor currentColor; int channel1; int channel2; - KisSignalCompressor *updateTimer; + KisSignalCompressor *updateTimer {0}; bool mousePressActive = false; const KoColorDisplayRendererInterface *displayRenderer = 0; qreal hue = 0.0; qreal sat = 0.0; qreal tone = 0.0; }; KisVisualColorSelectorShape::KisVisualColorSelectorShape(QWidget *parent, KisVisualColorSelectorShape::Dimensions dimension, KisVisualColorSelectorShape::ColorModel model, const KoColorSpace *cs, int channel1, int channel2, const KoColorDisplayRendererInterface *displayRenderer): QWidget(parent), m_d(new Private) { m_d->dimension = dimension; m_d->model = model; m_d->cs = cs; m_d->currentColor = KoColor(); m_d->currentColor.setOpacity(1.0); m_d->currentColor.convertTo(cs); int maxchannel = m_d->cs->colorChannelCount()-1; m_d->channel1 = qBound(0, channel1, maxchannel); m_d->channel2 = qBound(0, channel2, maxchannel); this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_d->updateTimer = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this); + connect(m_d->updateTimer, SIGNAL(timeout()), SLOT(slotRebuildSelectors()), Qt::UniqueConnection); setDisplayRenderer(displayRenderer); show(); } KisVisualColorSelectorShape::~KisVisualColorSelectorShape() { - } void KisVisualColorSelectorShape::updateCursor() { QPointF point1 = convertKoColorToShapeCoordinate(m_d->currentColor); if (point1 != m_d->currentCoordinates) { m_d->currentCoordinates = point1; } } QPointF KisVisualColorSelectorShape::getCursorPosition() { return m_d->currentCoordinates; } void KisVisualColorSelectorShape::setColor(KoColor c) { + //qDebug()() << "KisVisualColorSelectorShape::setColor"; if (c.colorSpace() != m_d->cs) { c.convertTo(m_d->cs); } m_d->currentColor = c; updateCursor(); + m_d->imagesNeedUpdate = true; update(); } void KisVisualColorSelectorShape::setColorFromSibling(KoColor c) { + //qDebug()() << "setColorFromSibling"; if (c.colorSpace() != m_d->cs) { c.convertTo(m_d->cs); } m_d->currentColor = c; Q_EMIT sigNewColor(c); m_d->imagesNeedUpdate = true; update(); } void KisVisualColorSelectorShape::setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer) { if (displayRenderer) { if (m_d->displayRenderer) { m_d->displayRenderer->disconnect(this); } m_d->displayRenderer = displayRenderer; } else { m_d->displayRenderer = KoDumbColorDisplayRenderer::instance(); } connect(m_d->displayRenderer, SIGNAL(displayConfigurationChanged()), SLOT(updateFromChangedDisplayRenderer()), Qt::UniqueConnection); } void KisVisualColorSelectorShape::updateFromChangedDisplayRenderer() { + //qDebug()() << "updateFromChangedDisplayRenderer();"; m_d->imagesNeedUpdate = true; updateCursor(); //m_d->currentColor = convertShapeCoordinateToKoColor(getCursorPosition()); update(); } void KisVisualColorSelectorShape::forceImageUpdate() { + //qDebug()() << "forceImageUpdate"; m_d->imagesNeedUpdate = true; } QColor KisVisualColorSelectorShape::getColorFromConverter(KoColor c){ QColor col; KoColor color = c; if (m_d->displayRenderer) { color.convertTo(m_d->displayRenderer->getPaintingColorSpace()); col = m_d->displayRenderer->toQColor(c); } else { col = c.toQColor(); } return col; } void KisVisualColorSelectorShape::slotSetActiveChannels(int channel1, int channel2) { + //qDebug()() << "slotSetActiveChannels"; int maxchannel = m_d->cs->colorChannelCount()-1; m_d->channel1 = qBound(0, channel1, maxchannel); m_d->channel2 = qBound(0, channel2, maxchannel); m_d->imagesNeedUpdate = true; update(); } +bool KisVisualColorSelectorShape::imagesNeedUpdate() const { + return m_d->imagesNeedUpdate; +} + QImage KisVisualColorSelectorShape::getImageMap() { + //qDebug()() << ">>>>>>>>> getImageMap()" << m_d->imagesNeedUpdate; + if (m_d->imagesNeedUpdate == true) { - m_d->imagesNeedUpdate = false; m_d->gradient = QImage(width(), height(), QImage::Format_ARGB32); m_d->gradient.fill(Qt::transparent); QImage img(width(), height(), QImage::Format_ARGB32); img.fill(Qt::transparent); for (int y = 0; y(img.scanLine(y)); for (int x=0; ximagesNeedUpdate = false; m_d->gradient = img; } return m_d->gradient; } KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coordinates, bool cursor) { KoColor c = m_d->currentColor; QVector channelValues (c.colorSpace()->channelCount()); channelValues.fill(1.0); c.colorSpace()->normalisedChannelsValue(c.data(), channelValues); QVector channelValuesDisplay = channelValues; QVector maxvalue(c.colorSpace()->channelCount()); maxvalue.fill(1.0); if (m_d->displayRenderer && (m_d->cs->colorDepthId() == Float16BitsColorDepthID || m_d->cs->colorDepthId() == Float32BitsColorDepthID || m_d->cs->colorDepthId() == Float64BitsColorDepthID) && m_d->cs->colorModelId() != LABAColorModelID && m_d->cs->colorModelId() != CMYKAColorModelID) { for (int ch = 0; chcs->channels()[ch]; maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel); channelValues[ch] = channelValues[ch]/(maxvalue[ch]); channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(ch, m_d->cs->channels())] = channelValues[ch]; } } else { for (int i =0; ics->channels())] = qBound((float)0.0,channelValues[i], (float)1.0); } } qreal huedivider = 1.0; qreal huedivider2 = 1.0; if (m_d->channel1==0) { huedivider = 360.0; } if (m_d->channel2==0) { huedivider2 = 360.0; } if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") { if (c.colorSpace()->colorModelId().id() == "RGBA") { if (m_d->model == ColorModel::HSV){ /* * RGBToHSV has a undefined hue possibility. This means that hue will be -1. * This can be annoying for dealing with a selector, but I understand it is being * used for the KoColorSelector... For now implement a qMax here. */ QVector inbetween(3); RGBToHSV(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]); inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween))); inbetween[m_d->channel1] = coordinates.x()*huedivider; if (m_d->dimension == Dimensions::twodimensional) { inbetween[m_d->channel2] = coordinates.y()*huedivider2; } if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));Q_EMIT sigHSXchange();} HSVToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2], &channelValuesDisplay[0], &channelValuesDisplay[1], &channelValuesDisplay[2]); } else if (m_d->model == ColorModel::HSL) { /* * HSLToRGB can give negative values on the grey. I fixed the fromNormalisedChannel function to clamp, * but you might want to manually clamp for floating point values. */ QVector inbetween(3); RGBToHSL(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]); inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween))); inbetween[m_d->channel1] = fmod(coordinates.x()*huedivider, 360.0); if (m_d->dimension == Dimensions::twodimensional) { inbetween[m_d->channel2] = coordinates.y()*huedivider2; } if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));Q_EMIT sigHSXchange();} HSLToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2],&channelValuesDisplay[0],&channelValuesDisplay[1], &channelValuesDisplay[2]); } else if (m_d->model == ColorModel::HSI) { /* * HSI is a modified HSY function. */ QVector chan2 = convertvectorfloatToqreal(channelValuesDisplay); QVector inbetween(3); RGBToHSI(chan2[0],chan2[1], chan2[2], &inbetween[0], &inbetween[1], &inbetween[2]); inbetween = getHSX(inbetween); inbetween[m_d->channel1] = coordinates.x(); if (m_d->dimension == Dimensions::twodimensional) { inbetween[m_d->channel2] = coordinates.y(); } if (cursor==true){setHSX(inbetween);Q_EMIT sigHSXchange();} HSIToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[0],&chan2[1], &chan2[2]); channelValuesDisplay = convertvectorqrealTofloat(chan2); } else /*if (m_d->model == ColorModel::HSY)*/ { /* * HSY is pretty slow to render due being a pretty over-the-top function. * Might be worth investigating whether HCY can be used instead, but I have had * some weird results with that. */ QVector luma= m_d->cs->lumaCoefficients(); QVector chan2 = convertvectorfloatToqreal(channelValuesDisplay); QVector inbetween(3); RGBToHSY(chan2[0],chan2[1], chan2[2], &inbetween[0], &inbetween[1], &inbetween[2], luma[0], luma[1], luma[2]); inbetween = getHSX(inbetween); inbetween[m_d->channel1] = coordinates.x(); if (m_d->dimension == Dimensions::twodimensional) { inbetween[m_d->channel2] = coordinates.y(); } if (cursor==true){setHSX(inbetween);Q_EMIT sigHSXchange();} HSYToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[0],&chan2[1], &chan2[2], luma[0], luma[1], luma[2]); channelValuesDisplay = convertvectorqrealTofloat(chan2); } } } else { channelValuesDisplay[m_d->channel1] = coordinates.x(); if (m_d->dimension == Dimensions::twodimensional) { channelValuesDisplay[m_d->channel2] = coordinates.y(); } } for (int i=0; ics->channels())]*(maxvalue[i]); } c.colorSpace()->fromNormalisedChannelsValue(c.data(), channelValues); return c; } QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c) { if (c.colorSpace() != m_d->cs) { c.convertTo(m_d->cs); } QVector channelValues (m_d->currentColor.colorSpace()->channelCount()); channelValues.fill(1.0); m_d->cs->normalisedChannelsValue(c.data(), channelValues); QVector channelValuesDisplay = channelValues; QVector maxvalue(c.colorSpace()->channelCount()); maxvalue.fill(1.0); if (m_d->displayRenderer && (m_d->cs->colorDepthId() == Float16BitsColorDepthID || m_d->cs->colorDepthId() == Float32BitsColorDepthID || m_d->cs->colorDepthId() == Float64BitsColorDepthID) && m_d->cs->colorModelId() != LABAColorModelID && m_d->cs->colorModelId() != CMYKAColorModelID) { for (int ch = 0; chcs->channels()[ch]; maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel); channelValues[ch] = channelValues[ch]/(maxvalue[ch]); channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(ch, m_d->cs->channels())] = channelValues[ch]; } } else { for (int i =0; ics->channels())] = qBound((float)0.0,channelValues[i], (float)1.0); } } QPointF coordinates(0.0,0.0); qreal huedivider = 1.0; qreal huedivider2 = 1.0; if (m_d->channel1==0) { huedivider = 360.0; } if (m_d->channel2==0) { huedivider2 = 360.0; } if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") { if (c.colorSpace()->colorModelId().id() == "RGBA") { if (m_d->model == ColorModel::HSV){ QVector inbetween(3); RGBToHSV(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]); inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween))); coordinates.setX(inbetween[m_d->channel1]/huedivider); if (m_d->dimension == Dimensions::twodimensional) { coordinates.setY(inbetween[m_d->channel2]/huedivider2); } } else if (m_d->model == ColorModel::HSL) { QVector inbetween(3); RGBToHSL(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]); inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween))); coordinates.setX(inbetween[m_d->channel1]/huedivider); if (m_d->dimension == Dimensions::twodimensional) { coordinates.setY(inbetween[m_d->channel2]/huedivider2); } } else if (m_d->model == ColorModel::HSI) { QVector chan2 = convertvectorfloatToqreal(channelValuesDisplay); QVector inbetween(3); RGBToHSI(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]); inbetween = getHSX(inbetween); coordinates.setX(inbetween[m_d->channel1]); if (m_d->dimension == Dimensions::twodimensional) { coordinates.setY(inbetween[m_d->channel2]); } } else if (m_d->model == ColorModel::HSY) { QVector luma = m_d->cs->lumaCoefficients(); QVector chan2 = convertvectorfloatToqreal(channelValuesDisplay); QVector inbetween(3); RGBToHSY(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2], luma[0], luma[1], luma[2]); inbetween = getHSX(inbetween); coordinates.setX(inbetween[m_d->channel1]); if (m_d->dimension == Dimensions::twodimensional) { coordinates.setY(inbetween[m_d->channel2]); } } } } else { coordinates.setX(qBound((float)0.0, channelValuesDisplay[m_d->channel1], (float)1.0)); if (m_d->dimension == Dimensions::twodimensional) { coordinates.setY(qBound((float)0.0, channelValuesDisplay[m_d->channel2], (float)1.0)); } } return coordinates; } QVector KisVisualColorSelectorShape::convertvectorqrealTofloat(QVector real) { QVector vloat(real.size()); for (int i=0; i KisVisualColorSelectorShape::convertvectorfloatToqreal(QVector vloat) { QVector real(vloat.size()); for (int i=0; ibutton()==Qt::LeftButton) { m_d->mousePressActive = true; QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos()); KoColor col = convertShapeCoordinateToKoColor(coordinates, true); setColor(col); Q_EMIT sigNewColor(col); m_d->updateTimer->start(); } } void KisVisualColorSelectorShape::mouseMoveEvent(QMouseEvent *e) { if (m_d->mousePressActive==true && this->mask().contains(e->pos())) { QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos()); quint8* oldData = m_d->currentColor.data(); KoColor col = convertShapeCoordinateToKoColor(coordinates, true); QRect offsetrect(this->geometry().topLeft()+QPoint(7.0,7.0), this->geometry().bottomRight()-QPoint(7.0,7.0)); if (offsetrect.contains(e->pos()) || (m_d->cs->difference(col.data(), oldData)>5)) { setColor(col); if (!m_d->updateTimer->isActive()) { Q_EMIT sigNewColor(col); m_d->updateTimer->start(); } } } else { e->ignore(); } } void KisVisualColorSelectorShape::mouseReleaseEvent(QMouseEvent *) { m_d->mousePressActive = false; } void KisVisualColorSelectorShape::paintEvent(QPaintEvent*) { QPainter painter(this); //check if old and new colors differ. if (m_d->imagesNeedUpdate) { setMask(getMaskMap()); } drawCursor(); painter.drawImage(0,0,m_d->fullSelector); } KisVisualColorSelectorShape::Dimensions KisVisualColorSelectorShape::getDimensions() { return m_d->dimension; } KisVisualColorSelectorShape::ColorModel KisVisualColorSelectorShape::getColorModel() { return m_d->model; } void KisVisualColorSelectorShape::setFullImage(QImage full) { m_d->fullSelector = full; } KoColor KisVisualColorSelectorShape::getCurrentColor() { return m_d->currentColor; } QVector KisVisualColorSelectorShape::getHSX(QVector hsx, bool wrangler) { QVector ihsx = hsx; if (!wrangler){ //Ok, so this docker will not update luminosity if there's not at the least 3% more variation. //This is necessary for 8bit. if (m_d->cs->colorDepthId()==Integer8BitsColorDepthID){ if (hsx[2]>m_d->tone-0.03 && hsx[2]tone+0.03) { ihsx[2] = m_d->tone; } } else { if (hsx[2]>m_d->tone-0.005 && hsx[2]tone+0.005) { ihsx[2] = m_d->tone; } } if (m_d->model==HSV){ if (hsx[2]<=0.0) { ihsx[1] = m_d->sat; } } else { if ((hsx[2]<=0.0 || hsx[2]>=1.0)) { ihsx[1] = m_d->sat; } } if ((hsx[1]<=0.0 || hsx[0]<0.0)){ ihsx[0]=m_d->hue; } } else { ihsx[0]=m_d->hue; ihsx[1]=m_d->sat; ihsx[2]=m_d->tone; } return ihsx; } void KisVisualColorSelectorShape::setHSX(QVector hsx, bool wrangler) { if (wrangler){ m_d->tone = hsx[2]; m_d->sat = hsx[1]; m_d->hue = hsx[0]; } else { if (m_d->channel1==2 || m_d->channel2==2){ m_d->tone=hsx[2]; } if (m_d->model==HSV){ if (hsx[2]>0.0) { m_d->sat = hsx[1]; } } else { if ((hsx[2]>0.0 || hsx[2]<1.0)) { m_d->sat = hsx[1]; } } if ((hsx[1]>0.0 && hsx[0]>=0.0)){ m_d->hue = hsx[0]; } } } QVector KisVisualColorSelectorShape::getChannels() { QVector channels(2); channels[0] = m_d->channel1; channels[1] = m_d->channel2; return channels; } /*-----------Rectangle Shape------------*/ KisVisualRectangleSelectorShape::KisVisualRectangleSelectorShape(QWidget *parent, Dimensions dimension, ColorModel model, const KoColorSpace *cs, int channel1, int channel2, const KoColorDisplayRendererInterface *displayRenderer, int width, singelDTypes d) : KisVisualColorSelectorShape(parent, dimension, model, cs, channel1, channel2, displayRenderer) { m_type = d; m_barWidth = width; } KisVisualRectangleSelectorShape::~KisVisualRectangleSelectorShape() { } void KisVisualRectangleSelectorShape::setBorderWidth(int width) { m_barWidth = width; } QRect KisVisualRectangleSelectorShape::getSpaceForSquare(QRect geom) { QPointF tl; QPointF br; if (m_type==KisVisualRectangleSelectorShape::vertical) { br = geom.bottomRight(); tl = QPoint(geom.topLeft().x()+m_barWidth, geom.topLeft().y()); } else if (m_type==KisVisualRectangleSelectorShape::horizontal) { br = geom.bottomRight(); tl = QPoint(geom.topLeft().x(), geom.topLeft().y()+m_barWidth); } else { tl = QPointF (geom.topLeft().x()+m_barWidth, geom.topLeft().y()+m_barWidth); br = QPointF (geom.bottomRight().x()-m_barWidth, geom.bottomRight().y()-m_barWidth); } QRect a(tl.toPoint(), br.toPoint()); QRect r(a.left(), a.top(), qMin(a.height(), a.width()), qMin(a.height(), a.width())); return r; } QRect KisVisualRectangleSelectorShape::getSpaceForCircle(QRect geom) { return getSpaceForSquare(geom); } QRect KisVisualRectangleSelectorShape::getSpaceForTriangle(QRect geom) { return getSpaceForSquare(geom); } QPointF KisVisualRectangleSelectorShape::convertShapeCoordinateToWidgetCoordinate(QPointF coordinate) { qreal x = m_barWidth/2; qreal y = m_barWidth/2; qreal offset = 5.0; KisVisualColorSelectorShape::Dimensions dimension = getDimensions(); if (dimension == KisVisualColorSelectorShape::onedimensional) { if ( m_type == KisVisualRectangleSelectorShape::vertical) { y = qMin(coordinate.x()*(height()-offset*2)+offset, (qreal)height()); } else if (m_type == KisVisualRectangleSelectorShape::horizontal) { x = qMin(coordinate.x()*(width()-offset*2)+offset, (qreal)width()); } else if (m_type == KisVisualRectangleSelectorShape::border) { QRectF innerRect(m_barWidth/2, m_barWidth/2, width()-m_barWidth, height()-m_barWidth); QPointF left (innerRect.left(),innerRect.center().y()); QList polygonLines; polygonLines.append(QLineF(left, innerRect.topLeft())); polygonLines.append(QLineF(innerRect.topLeft(), innerRect.topRight())); polygonLines.append(QLineF(innerRect.topRight(), innerRect.bottomRight())); polygonLines.append(QLineF(innerRect.bottomRight(), innerRect.bottomLeft())); polygonLines.append(QLineF(innerRect.bottomLeft(), left)); qreal totalLength =0.0; Q_FOREACH(QLineF line, polygonLines) { totalLength += line.length(); } qreal length = coordinate.x()*totalLength; QPointF intersect(x,y); Q_FOREACH(QLineF line, polygonLines) { if (line.length()>length && length>0){ intersect = line.pointAt(length/line.length()); } length-=line.length(); } x = qRound(intersect.x()); y = qRound(intersect.y()); } else /*if (m_type == KisVisualRectangleSelectorShape::borderMirrored)*/ { QRectF innerRect(m_barWidth/2, m_barWidth/2, width()-m_barWidth, height()-m_barWidth); QPointF bottom (innerRect.center().x(), innerRect.bottom()); QList polygonLines; polygonLines.append(QLineF(bottom, innerRect.bottomLeft())); polygonLines.append(QLineF(innerRect.bottomLeft(), innerRect.topLeft())); polygonLines.append(QLineF(innerRect.topLeft(), innerRect.topRight())); polygonLines.append(QLineF(innerRect.topRight(), innerRect.bottomRight())); polygonLines.append(QLineF(innerRect.bottomRight(), bottom)); qreal totalLength =0.0; Q_FOREACH(QLineF line, polygonLines) { totalLength += line.length(); } qreal length = coordinate.x()*(totalLength/2); QPointF intersect(x,y); if (coordinate.y()==1) { for (int i = polygonLines.size()-1; i==0; i--) { QLineF line = polygonLines.at(i); if (line.length()>length && length>0){ intersect = line.pointAt(length/line.length()); } length-=line.length(); } } else { Q_FOREACH(QLineF line, polygonLines) { if (line.length()>length && length>0){ intersect = line.pointAt(length/line.length()); } length-=line.length(); } } x = qRound(intersect.x()); y = qRound(intersect.y()); } } else { x = qMin(coordinate.x()*(height()-offset*2)+offset, (qreal)height()); y = qMin(coordinate.y()*(width()-offset*2)+offset, (qreal)width()); } return QPointF(x,y); } QPointF KisVisualRectangleSelectorShape::convertWidgetCoordinateToShapeCoordinate(QPoint coordinate) { //default implementation: qreal x = 0.5; qreal y = 0.5; qreal offset = 5.0; KisVisualColorSelectorShape::Dimensions dimension = getDimensions(); if (getMaskMap().contains(coordinate)) { if (dimension == KisVisualColorSelectorShape::onedimensional ) { if (m_type == KisVisualRectangleSelectorShape::vertical) { x = qMax(((qreal)coordinate.y()-offset)/((qreal)height()-offset*2), 0.0); } else if (m_type == KisVisualRectangleSelectorShape::horizontal) { x = qMax(((qreal)coordinate.x()-offset)/((qreal)width()-offset*2),0.0); } else if (m_type == KisVisualRectangleSelectorShape::border) { //border QRectF innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2)); QPointF left (innerRect.left(),innerRect.center().y()); QList polygonLines; polygonLines.append(QLineF(left, innerRect.topLeft())); polygonLines.append(QLineF(innerRect.topLeft(), innerRect.topRight())); polygonLines.append(QLineF(innerRect.topRight(), innerRect.bottomRight())); polygonLines.append(QLineF(innerRect.bottomRight(), innerRect.bottomLeft())); polygonLines.append(QLineF(innerRect.bottomLeft(), left)); QLineF radius(coordinate, this->geometry().center()); QPointF intersect(0.5,0.5); qreal length = 0.0; qreal totalLength = 0.0; bool foundIntersect = false; Q_FOREACH(QLineF line, polygonLines) { if (line.intersect(radius,&intersect)==QLineF::BoundedIntersection && foundIntersect==false) { foundIntersect = true; length+=QLineF(line.p1(), intersect).length(); } if (foundIntersect==false) { length+=line.length(); } totalLength+=line.length(); } x = length/totalLength; } else /*if (m_type == KisVisualRectangleSelectorShape::borderMirrored)*/ { //border QRectF innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2)); QPointF bottom (innerRect.center().x(), innerRect.bottom()); QList polygonLines; polygonLines.append(QLineF(bottom, innerRect.bottomLeft())); polygonLines.append(QLineF(innerRect.bottomLeft(), innerRect.topLeft())); polygonLines.append(QLineF(innerRect.topLeft(), innerRect.topRight())); polygonLines.append(QLineF(innerRect.topRight(), innerRect.bottomRight())); polygonLines.append(QLineF(innerRect.bottomRight(), bottom)); QLineF radius(coordinate, this->geometry().center()); QPointF intersect(0.5,0.5); qreal length = 0.0; qreal totalLength = 0.0; bool foundIntersect = false; Q_FOREACH(QLineF line, polygonLines) { if (line.intersect(radius,&intersect)==QLineF::BoundedIntersection && foundIntersect==false) { foundIntersect = true; length+=QLineF(line.p1(), intersect).length(); } if (foundIntersect==false) { length+=line.length(); } totalLength+=line.length(); } int halflength = totalLength/2; if (length>halflength) { x = (halflength - (length-halflength))/halflength; y = 1.0; } else { x = length/halflength; y = 0.0; } } } else { x = qMax(((qreal)coordinate.x()-offset)/((qreal)width()-offset*2), 0.0); y = qMax(((qreal)coordinate.y()-offset)/((qreal)height()-offset*2), 0.0);; } } return QPointF(x, y); } QRegion KisVisualRectangleSelectorShape::getMaskMap() { QRegion mask = QRegion(0,0,width(),height()); if (m_type==KisVisualRectangleSelectorShape::border || m_type==KisVisualRectangleSelectorShape::borderMirrored) { mask = mask.subtracted(QRegion(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2))); } return mask; } void KisVisualRectangleSelectorShape::resizeEvent(QResizeEvent *) { + //qDebug()() << "KisVisualRectangleSelectorShape::resizeEvent"; forceImageUpdate(); } void KisVisualRectangleSelectorShape::drawCursor() { + //qDebug()() << "KisVisualRectangleSelectorShape::drawCursor: image needs update" << imagesNeedUpdate(); QPointF cursorPoint = convertShapeCoordinateToWidgetCoordinate(getCursorPosition()); QImage fullSelector = getImageMap(); QColor col = getColorFromConverter(getCurrentColor()); QPainter painter; painter.begin(&fullSelector); painter.setRenderHint(QPainter::Antialiasing); //QPainterPath path; QBrush fill; fill.setStyle(Qt::SolidPattern); int cursorwidth = 5; QRect rect(cursorPoint.toPoint().x()-cursorwidth,cursorPoint.toPoint().y()-cursorwidth, cursorwidth*2,cursorwidth*2); if (m_type==KisVisualRectangleSelectorShape::vertical){ int x = ( cursorPoint.x()-(width()/2)+1 ); int y = ( cursorPoint.y()-cursorwidth ); rect.setCoords(x, y, x+width()-2, y+(cursorwidth*2)); painter.save(); painter.setCompositionMode(QPainter::CompositionMode_Clear); QPen pen; pen.setWidth(5); painter.setPen(pen); painter.drawLine(QLine(QPoint(0.0,0.0), QPoint(0.0,height()))); painter.drawLine(QLine(QPoint(width(),0.0), QPoint(width(),height()))); painter.restore(); } else { int x = cursorPoint.x()-cursorwidth; int y = cursorPoint.y()-(height()/2)+1; rect.setCoords(x, y, x+(cursorwidth*2), y+cursorwidth-2); } QRectF innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2)); if (getDimensions() == KisVisualColorSelectorShape::onedimensional && m_type!=KisVisualRectangleSelectorShape::border && m_type!=KisVisualRectangleSelectorShape::borderMirrored) { painter.setPen(Qt::white); fill.setColor(Qt::white); painter.setBrush(fill); painter.drawRect(rect); //set filter conversion! fill.setColor(col); painter.setPen(Qt::black); painter.setBrush(fill); rect.setCoords(rect.topLeft().x()+1, rect.topLeft().y()+1, rect.topLeft().x()+rect.width()-2, rect.topLeft().y()+rect.height()-2); painter.drawRect(rect); }else if(m_type==KisVisualRectangleSelectorShape::borderMirrored){ painter.setPen(Qt::white); fill.setColor(Qt::white); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth); QPoint mirror(innerRect.center().x()+(innerRect.center().x()-cursorPoint.x()),cursorPoint.y()); painter.drawEllipse(mirror, cursorwidth, cursorwidth); fill.setColor(col); painter.setPen(Qt::black); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth-1, cursorwidth-1); painter.drawEllipse(mirror, cursorwidth-1, cursorwidth-1); } else { painter.save(); painter.setCompositionMode(QPainter::CompositionMode_Clear); QPen pen; pen.setWidth(5); painter.setPen(pen); painter.drawRect(QRect(0,0,width(),height())); painter.restore(); painter.setPen(Qt::white); fill.setColor(Qt::white); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth); fill.setColor(col); painter.setPen(Qt::black); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth-1.0, cursorwidth-1.0); } painter.end(); setFullImage(fullSelector); } //----------------Elliptical--------------------------// KisVisualEllipticalSelectorShape::KisVisualEllipticalSelectorShape(QWidget *parent, Dimensions dimension, ColorModel model, const KoColorSpace *cs, int channel1, int channel2, const KoColorDisplayRendererInterface *displayRenderer, int borwidth, singelDTypes d) : KisVisualColorSelectorShape(parent, dimension, model, cs, channel1, channel2, displayRenderer) { m_type = d; m_barWidth = borwidth; } KisVisualEllipticalSelectorShape::~KisVisualEllipticalSelectorShape() { } QSize KisVisualEllipticalSelectorShape::sizeHint() const { return QSize(180,180); } void KisVisualEllipticalSelectorShape::setBorderWidth(int width) { m_barWidth = width; } QRect KisVisualEllipticalSelectorShape::getSpaceForSquare(QRect geom) { int sizeValue = qMin(width(),height()); QRect b(geom.left(), geom.top(), sizeValue, sizeValue); QLineF radius(b.center(), QPointF(b.left()+m_barWidth, b.center().y()) ); radius.setAngle(135); QPointF tl = radius.p2(); radius.setAngle(315); QPointF br = radius.p2(); QRect r(tl.toPoint(), br.toPoint()); return r; } QRect KisVisualEllipticalSelectorShape::getSpaceForCircle(QRect geom) { int sizeValue = qMin(width(),height()); QRect b(geom.left(), geom.top(), sizeValue, sizeValue); QPointF tl = QPointF (b.topLeft().x()+m_barWidth, b.topLeft().y()+m_barWidth); QPointF br = QPointF (b.bottomRight().x()-m_barWidth, b.bottomRight().y()-m_barWidth); QRect r(tl.toPoint(), br.toPoint()); return r; } QRect KisVisualEllipticalSelectorShape::getSpaceForTriangle(QRect geom) { int sizeValue = qMin(width(),height()); QRect b(geom.left(), geom.top(), sizeValue, sizeValue); QLineF radius(b.center(), QPointF(b.left()+m_barWidth, b.center().y()) ); radius.setAngle(90);//point at yellowgreen :) QPointF t = radius.p2(); radius.setAngle(330);//point to purple :) QPointF br = radius.p2(); radius.setAngle(210);//point to cerulean :) QPointF bl = radius.p2(); QPointF tl = QPoint(bl.x(),t.y()); QRect r(tl.toPoint(), br.toPoint()); return r; } QPointF KisVisualEllipticalSelectorShape::convertShapeCoordinateToWidgetCoordinate(QPointF coordinate) { qreal x; qreal y; qreal offset=7.0; qreal a = (qreal)width()*0.5; QPointF center(a, a); QLineF line(center, QPoint((m_barWidth*0.5),a)); qreal angle = coordinate.x()*360.0; angle = fmod(angle+180.0,360.0); angle = 180.0-angle; angle = angle+180.0; if (m_type==KisVisualEllipticalSelectorShape::borderMirrored) { angle = (coordinate.x()/2)*360.0; angle = fmod((angle+90.0), 360.0); } line.setAngle(angle); if (getDimensions()!=KisVisualColorSelectorShape::onedimensional) { line.setLength(qMin(coordinate.y()*(a-offset), a-offset)); } x = qRound(line.p2().x()); y = qRound(line.p2().y()); return QPointF(x,y); } QPointF KisVisualEllipticalSelectorShape::convertWidgetCoordinateToShapeCoordinate(QPoint coordinate) { //default implementation: qreal x = 0.5; qreal y = 1.0; qreal offset = 7.0; QRect total(0, 0, width(), height()); QLineF line(total.center(), coordinate); qreal a = (total.width()/2); qreal angle; if (m_type!=KisVisualEllipticalSelectorShape::borderMirrored){ angle = fmod((line.angle()+180.0), 360.0); angle = 180.0-angle; angle = angle+180.0; x = angle/360.0; if (getDimensions()==KisVisualColorSelectorShape::twodimensional) { y = qBound(0.0,line.length()/(a-offset), 1.0); } } else { angle = fmod((line.angle()+270.0), 360.0); if (angle>180.0) { angle = 180.0-angle; angle = angle+180; } x = (angle/360.0)*2; if (getDimensions()==KisVisualColorSelectorShape::twodimensional) { y = qBound(0.0,(line.length()+offset)/a, 1.0); } } return QPointF(x, y); } QRegion KisVisualEllipticalSelectorShape::getMaskMap() { QRegion mask = QRegion(0,0,width(),height(), QRegion::Ellipse); if (getDimensions()==KisVisualColorSelectorShape::onedimensional) { mask = mask.subtracted(QRegion(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2), QRegion::Ellipse)); } return mask; } void KisVisualEllipticalSelectorShape::resizeEvent(QResizeEvent *) { + //qDebug()() << "KisVisualEllipticalSelectorShape::resizeEvent"; forceImageUpdate(); } void KisVisualEllipticalSelectorShape::drawCursor() { + //qDebug()() << "KisVisualEllipticalSelectorShape::drawCursor: image needs update" << imagesNeedUpdate(); QPointF cursorPoint = convertShapeCoordinateToWidgetCoordinate(getCursorPosition()); QImage fullSelector = getImageMap(); QColor col = getColorFromConverter(getCurrentColor()); QPainter painter; painter.begin(&fullSelector); painter.setRenderHint(QPainter::Antialiasing); QRect innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2)); painter.save(); painter.setCompositionMode(QPainter::CompositionMode_Clear); QPen pen; pen.setWidth(5); painter.setPen(pen); painter.drawEllipse(QRect(0,0,width(),height())); if (getDimensions()==KisVisualColorSelectorShape::onedimensional) { painter.setBrush(Qt::SolidPattern); painter.drawEllipse(innerRect); } painter.restore(); QBrush fill; fill.setStyle(Qt::SolidPattern); int cursorwidth = 5; if(m_type==KisVisualEllipticalSelectorShape::borderMirrored){ painter.setPen(Qt::white); fill.setColor(Qt::white); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth); QPoint mirror(innerRect.center().x()+(innerRect.center().x()-cursorPoint.x()),cursorPoint.y()); painter.drawEllipse(mirror, cursorwidth, cursorwidth); fill.setColor(col); painter.setPen(Qt::black); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth-1, cursorwidth-1); painter.drawEllipse(mirror, cursorwidth-1, cursorwidth-1); } else { painter.setPen(Qt::white); fill.setColor(Qt::white); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth); fill.setColor(col); painter.setPen(Qt::black); painter.setBrush(fill); painter.drawEllipse(cursorPoint, cursorwidth-1.0, cursorwidth-1.0); } painter.end(); setFullImage(fullSelector); } //----------------Triangle--------------------------// KisVisualTriangleSelectorShape::KisVisualTriangleSelectorShape(QWidget *parent, Dimensions dimension, ColorModel model, const KoColorSpace *cs, int channel1, int channel2, const KoColorDisplayRendererInterface *displayRenderer, int borwidth) : KisVisualColorSelectorShape(parent, dimension, model, cs, channel1, channel2, displayRenderer) { m_barWidth = borwidth; QRect total(0,0,width()*0.9,width()*0.9); setTriangle(); } KisVisualTriangleSelectorShape::~KisVisualTriangleSelectorShape() { } void KisVisualTriangleSelectorShape::setBorderWidth(int width) { m_barWidth = width; } QRect KisVisualTriangleSelectorShape::getSpaceForSquare(QRect geom) { return geom; } QRect KisVisualTriangleSelectorShape::getSpaceForCircle(QRect geom) { return geom; } QRect KisVisualTriangleSelectorShape::getSpaceForTriangle(QRect geom) { return geom; } void KisVisualTriangleSelectorShape::setTriangle() { QPoint apex = QPoint (width()*0.5,0); QPolygon triangle; triangle<< QPoint(0,height()) << apex << QPoint(width(),height()) << QPoint(0,height()); m_triangle = triangle; QLineF a(triangle.at(0),triangle.at(1)); QLineF b(triangle.at(0),triangle.at(2)); QLineF ap(triangle.at(2), a.pointAt(0.5)); QLineF bp(triangle.at(1), b.pointAt(0.5)); QPointF intersect; ap.intersect(bp,&intersect); m_center = intersect; QLineF r(triangle.at(0), intersect); m_radius = r.length(); } QPointF KisVisualTriangleSelectorShape::convertShapeCoordinateToWidgetCoordinate(QPointF coordinate) { qreal offset=7.0;//the offset is so we get a nice little border that allows selecting extreme colors better. qreal y = qMin(coordinate.y()*(height()-offset*2-5.0)+offset+5.0, (qreal)height()-offset); qreal triWidth = width(); qreal horizontalLineLength = y*(2./sqrt(3.)); qreal horizontalLineStart = triWidth/2.-horizontalLineLength/2.; qreal relativeX = coordinate.x()*(horizontalLineLength-offset*2); qreal x = qMin(relativeX + horizontalLineStart + offset, (qreal)width()-offset*2); if (y, (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 KISVISUALCOLORSELECTOR_H #define KISVISUALCOLORSELECTOR_H #include #include #include #include #include #include #include #include "KoColorDisplayRendererInterface.h" #include "kritaui_export.h" +class KRITAUI_EXPORT KisColorSelectorConfiguration { + +public: + + enum Type {Ring, Square, Wheel, Triangle, Slider}; + enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS}; + + Type mainType; + Type subType; + Parameters mainTypeParameter; + Parameters subTypeParameter; + + KisColorSelectorConfiguration(Type mainT = Triangle, Type subT = Ring, Parameters mainTP = SL, Parameters subTP = H) + : mainType(mainT) + , subType(subT) + , mainTypeParameter(mainTP) + , subTypeParameter(subTP) + { + } + + KisColorSelectorConfiguration(QString string) + { + readString(string); + } + + QString toString() const + { + return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter); + } + void readString(QString string) + { + QStringList strili = string.split('|'); + if(strili.length()!=4) return; + + int imt=strili.at(0).toInt(); + int ist=strili.at(1).toInt(); + int imtp=strili.at(2).toInt(); + int istp=strili.at(3).toInt(); + + if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before + return; + + mainType = Type(imt); + subType = Type(ist); + mainTypeParameter = Parameters(imtp); + subTypeParameter = Parameters(istp); + } + + static KisColorSelectorConfiguration fromString(QString string) + { + KisColorSelectorConfiguration ret; + ret.readString(string); + return ret; + } +}; + + /** * @brief The KisVisualColorSelector class - * this gives a color selector box that draws gradients and everything. - * Unlike other color selectors, this one draws the full gamut of the given colorspace. + * + * This gives a color selector box that draws gradients and everything. + * + * Unlike other color selectors, this one draws the full gamut of the given + * colorspace. */ class KRITAUI_EXPORT KisVisualColorSelector : public QWidget { Q_OBJECT public: - //Copied directly from the advanced color selector: - enum Type {Ring, Square, Wheel, Triangle, Slider}; - enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS}; - struct Configuration { - Type mainType; - Type subType; - Parameters mainTypeParameter; - Parameters subTypeParameter; - Configuration(Type mainT = Triangle, - Type subT = Ring, - Parameters mainTP = SL, - Parameters subTP = H) - : mainType(mainT), - subType(subT), - mainTypeParameter(mainTP), - subTypeParameter(subTP) - {} - Configuration(QString string) - { - readString(string); - } - - QString toString() const - { - return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter); - } - void readString(QString string) - { - QStringList strili = string.split('|'); - if(strili.length()!=4) return; - - int imt=strili.at(0).toInt(); - int ist=strili.at(1).toInt(); - int imtp=strili.at(2).toInt(); - int istp=strili.at(3).toInt(); - - if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before - return; - - mainType = Type(imt); - subType = Type(ist); - mainTypeParameter = Parameters(imtp); - subTypeParameter = Parameters(istp); - } - static Configuration fromString(QString string) - { - Configuration ret; - ret.readString(string); - return ret; - } - }; explicit KisVisualColorSelector(QWidget *parent = 0); ~KisVisualColorSelector(); /** * @brief setConfig * @param forceCircular * Force circular is for space where you only have room for a circular selector. * @param forceSelfUpdate * force self-update is for making it update itself when using a modal dialog. */ void setConfig(bool forceCircular, bool forceSelfUpdate); KoColor getCurrentColor(); Q_SIGNALS: void sigNewColor(KoColor c); public Q_SLOTS: void slotSetColor(KoColor c); void slotsetColorSpace(const KoColorSpace *cs); void slotRebuildSelectors(); void ConfigurationChanged(); void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer); private Q_SLOTS: void updateFromWidgets(KoColor c); void HSXwrangler(); protected: void leaveEvent(QEvent *); void resizeEvent(QResizeEvent *); private: struct Private; const QScopedPointer m_d; void updateSelectorElements(QObject *source); void drawGradients(); }; //kis_visual_color_selector_shape /** * @brief The KisVisualColorSelectorShape class * A 2d widget can represent at maximum 2 coordinates. * So first decide howmany coordinates you need. (onedimensional, or twodimensional) * Then the model, (Channel, HSV, HSL, HSI, YUV). Channel is the raw color channels. * When it finds a non-implemented feature it'll return to Channel. * Then, select the channels you wish to be affected. This uses the model, so for cmyk * the channel is c=0, m=1, y=2, k=3, but for hsv, hue=0, sat=1, and val=2 * These can also be set with 'slotsetactive channels'. * Then finally, connect the displayrenderer, you can also do this with 'setdisplayrenderer' * * Either way, this class is made to be subclassed, with a few virtuals so that the geometry * can be calculated properly. */ class KisVisualColorSelectorShape : public QWidget { Q_OBJECT public: /** * @brief The Dimensions enum * Wether or not the shape is single or two dimensional. **/ enum Dimensions{onedimensional, twodimensional}; enum ColorModel{Channel, HSV, HSL, HSI, HSY, YUV}; explicit KisVisualColorSelectorShape(QWidget *parent, KisVisualColorSelectorShape::Dimensions dimension, KisVisualColorSelectorShape::ColorModel model, const KoColorSpace *cs, int channel1, int channel2, const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance()); ~KisVisualColorSelectorShape(); /** * @brief getCursorPosition * @return current cursor position in shape-coordinates. */ QPointF getCursorPosition(); /** * @brief getDimensions * @return whether this is a single or twodimensional widget. */ Dimensions getDimensions(); /** * @brief getColorModel * @return the model of this widget. */ ColorModel getColorModel(); /** * @brief getPixmap * @return the pixmap of the gradient, for drawing on with a subclass. * the pixmap will not change unless 'm_d->setPixmap=true' which is toggled by * refresh and update functions. */ + bool imagesNeedUpdate() const; QImage getImageMap(); /** * @brief setFullImage * Set the full widget image to be painted. * @param full this should be the full image. */ void setFullImage(QImage full); /** * @brief getCurrentColor * @return the current kocolor */ KoColor getCurrentColor(); /** * @brief setDisplayRenderer * disconnect the old display renderer if needed and connect the new one. * @param displayRenderer */ void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer); /** * @brief getColorFromConverter * @param c a koColor. * @return get the qcolor from the given kocolorusing this widget's display renderer. */ QColor getColorFromConverter(KoColor c); /** * @brief getSpaceForSquare * @param geom the full widget rectangle * @return rectangle with enough space for second widget */ virtual QRect getSpaceForSquare(QRect geom) = 0; virtual QRect getSpaceForCircle(QRect geom) = 0; virtual QRect getSpaceForTriangle(QRect geom) = 0; /** * @brief forceImageUpdate * force the image to recache. */ void forceImageUpdate(); /** * @brief setBorderWidth * set the border of the single dimensional selector. * @param width */ virtual void setBorderWidth(int width) = 0; /** * @brief getChannels * get used channels * @return */ QVector getChannels(); /** * @brief setHSX * This is for the cursor not to change when selecting * black, white, and desaturated values. Will not change the non-native values. * @param hsx the hsx value. */ void setHSX(QVector hsx, bool wrangler=false); /** * @brief getHSX sets the sat and hue so they won't * switch around much. * @param hsx the hsx values. * @return returns hsx, corrected. */ QVector getHSX(QVector hsx, bool wrangler= false); Q_SIGNALS: void sigNewColor(KoColor col); void sigHSXchange(); public Q_SLOTS: /** * @brief setColor * Set this widget's current color and change the cursor position. * @param c */ void setColor(KoColor c); /** * @brief setColorFromSibling * set this widget's current color, but don't change the cursor position, * instead sent out a signal of the new color. * @param c */ void setColorFromSibling(KoColor c); /** * @brief slotSetActiveChannels * Change the active channels if necessary. * @param channel1 used by single and twodimensional widgets. * @param channel2 only used by twodimensional widgets. */ void slotSetActiveChannels(int channel1, int channel2); /** * @brief updateFromChangedDisplayRenderer * for updating from the display renderer... not sure why this one is public. */ void updateFromChangedDisplayRenderer(); protected: void mousePressEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); void paintEvent(QPaintEvent*); private: struct Private; const QScopedPointer m_d; /** * @brief convertShapeCoordinateToWidgetCoordinate * @return take the position in the shape and convert it to screen coordinates. */ virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF) = 0; /** * @brief convertWidgetCoordinateToShapeCoordinate * Convert a coordinate in the widget's height/width to a shape coordinate. * @param coordinate the position your wish to have the shape coordinates of. */ virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate) = 0; /** * @brief updateCursor * Update the cursor position. */ void updateCursor(); QPointF convertKoColorToShapeCoordinate(KoColor c); KoColor convertShapeCoordinateToKoColor(QPointF coordinates, bool cursor=false); /** * @brief getPixmap * @return the pixmap of this shape. */ virtual QRegion getMaskMap() = 0; virtual void drawCursor() = 0; QVector convertvectorqrealTofloat(QVector real); QVector convertvectorfloatToqreal(QVector vloat); }; class KisVisualRectangleSelectorShape : public KisVisualColorSelectorShape { Q_OBJECT public: enum singelDTypes{vertical, horizontal, border, borderMirrored}; explicit KisVisualRectangleSelectorShape(QWidget *parent, - Dimensions dimension, - ColorModel model, - const KoColorSpace *cs, - int channel1, int channel2, - const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int width=20, - KisVisualRectangleSelectorShape::singelDTypes d = KisVisualRectangleSelectorShape::vertical - ); + Dimensions dimension, + ColorModel model, + const KoColorSpace *cs, + int channel1, int channel2, + const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int width=20, + KisVisualRectangleSelectorShape::singelDTypes d = KisVisualRectangleSelectorShape::vertical + ); ~KisVisualRectangleSelectorShape(); void setBorderWidth(int width); /** * @brief getSpaceForSquare * @param geom the full widget rectangle * @return rectangle with enough space for second widget */ virtual QRect getSpaceForSquare(QRect geom); virtual QRect getSpaceForCircle(QRect geom); virtual QRect getSpaceForTriangle(QRect geom); protected: void resizeEvent(QResizeEvent *); private: virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate); virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate); singelDTypes m_type; int m_barWidth; virtual QRegion getMaskMap(); virtual void drawCursor(); }; class KisVisualEllipticalSelectorShape : public KisVisualColorSelectorShape { Q_OBJECT public: enum singelDTypes{border, borderMirrored}; explicit KisVisualEllipticalSelectorShape(QWidget *parent, - Dimensions dimension, - ColorModel model, - const KoColorSpace *cs, - int channel1, int channel2, - const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int borwidth=20, - KisVisualEllipticalSelectorShape::singelDTypes d = KisVisualEllipticalSelectorShape::border - ); + Dimensions dimension, + ColorModel model, + const KoColorSpace *cs, + int channel1, int channel2, + const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), int borwidth=20, + KisVisualEllipticalSelectorShape::singelDTypes d = KisVisualEllipticalSelectorShape::border + ); ~KisVisualEllipticalSelectorShape(); void setBorderWidth(int width); /** * @brief getSpaceForSquare * @param geom the full widget rectangle * @return rectangle with enough space for second widget */ virtual QRect getSpaceForSquare(QRect geom); virtual QRect getSpaceForCircle(QRect geom); virtual QRect getSpaceForTriangle(QRect geom); protected: void resizeEvent(QResizeEvent *); private: virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate); virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate); singelDTypes m_type; int m_barWidth; virtual QRegion getMaskMap(); virtual void drawCursor(); QSize sizeHint() const; }; class KisVisualTriangleSelectorShape : public KisVisualColorSelectorShape { Q_OBJECT public: enum singelDTypes{border, borderMirrored}; explicit KisVisualTriangleSelectorShape(QWidget *parent, - Dimensions dimension, - ColorModel model, - const KoColorSpace *cs, - int channel1, int channel2, - const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), - int borwidth=20 - ); + Dimensions dimension, + ColorModel model, + const KoColorSpace *cs, + int channel1, int channel2, + const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance(), + int borwidth=20 + ); ~KisVisualTriangleSelectorShape(); void setBorderWidth(int width); void setTriangle(); /** * @brief getSpaceForSquare * @param geom the full widget rectangle * @return rectangle with enough space for second widget */ virtual QRect getSpaceForSquare(QRect geom); virtual QRect getSpaceForCircle(QRect geom); virtual QRect getSpaceForTriangle(QRect geom); + protected: void resizeEvent(QResizeEvent *); + private: + virtual QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate); virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPoint coordinate); singelDTypes m_type; int m_barWidth; QPolygon m_triangle; QPointF m_center; qreal m_radius; virtual QRegion getMaskMap(); virtual void drawCursor(); }; #endif // KISVISUALCOLORSELECTOR_H diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector.cpp b/plugins/dockers/advancedcolorselector/kis_color_selector.cpp index 6e1526e07b..d1bfcb3a9e 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector.cpp +++ b/plugins/dockers/advancedcolorselector/kis_color_selector.cpp @@ -1,342 +1,345 @@ /* * Copyright (c) 2010 Adam Celarek * * 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_color_selector.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_color_selector_ring.h" #include "kis_color_selector_triangle.h" #include "kis_color_selector_simple.h" #include "kis_color_selector_wheel.h" #include "kis_color_selector_container.h" #include "kis_canvas2.h" #include "kis_signal_compressor.h" -KisColorSelector::KisColorSelector(Configuration conf, QWidget* parent) +KisColorSelector::KisColorSelector(KisColorSelectorConfiguration conf, QWidget* parent) : KisColorSelectorBase(parent), m_ring(0), m_triangle(0), m_slider(0), m_square(0), m_wheel(0), m_mainComponent(0), m_subComponent(0), m_grabbingComponent(0), m_blipDisplay(true) { init(); updateSettings(); setConfiguration(conf); } KisColorSelector::KisColorSelector(QWidget* parent) : KisColorSelectorBase(parent), m_ring(0), m_triangle(0), m_slider(0), m_square(0), m_wheel(0), m_button(0), m_mainComponent(0), m_subComponent(0), m_grabbingComponent(0), m_blipDisplay(true) { init(); updateSettings(); } KisColorSelectorBase* KisColorSelector::createPopup() const { KisColorSelectorBase* popup = new KisColorSelector(0); popup->setColor(m_lastRealColor); return popup; } -void KisColorSelector::setConfiguration(Configuration conf) +void KisColorSelector::setConfiguration(KisColorSelectorConfiguration conf) { m_configuration = conf; if(m_mainComponent!=0) { Q_ASSERT(m_subComponent!=0); m_mainComponent->setGeometry(0, 0, 0, 0); m_subComponent->setGeometry(0, 0, 0, 0); m_mainComponent->disconnect(); m_subComponent->disconnect(); } switch (m_configuration.mainType) { - case Square: + case KisColorSelectorConfiguration::Square: m_mainComponent=m_square; break; - case Wheel: + case KisColorSelectorConfiguration::Wheel: m_mainComponent=m_wheel; break; - case Triangle: + case KisColorSelectorConfiguration::Triangle: m_mainComponent=m_triangle; break; default: Q_ASSERT(false); } switch (m_configuration.subType) { - case Ring: + case KisColorSelectorConfiguration::Ring: m_subComponent=m_ring; break; - case Slider: + case KisColorSelectorConfiguration::Slider: m_subComponent=m_slider; break; default: Q_ASSERT(false); } connect(m_mainComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal)), m_subComponent, SLOT(setParam(qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal)), Qt::UniqueConnection); connect(m_subComponent, SIGNAL(paramChanged(qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal,qreal)), m_mainComponent, SLOT(setParam(qreal,qreal,qreal,qreal, qreal, qreal, qreal, qreal, qreal)), Qt::UniqueConnection); connect(m_mainComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection); connect(m_subComponent, SIGNAL(update()), m_signalCompressor, SLOT(start()), Qt::UniqueConnection); - + m_mainComponent->setConfiguration(m_configuration.mainTypeParameter, m_configuration.mainType); m_subComponent->setConfiguration(m_configuration.subTypeParameter, m_configuration.subType); QResizeEvent event(QSize(width(), height()), QSize()); resizeEvent(&event); } -KisColorSelector::Configuration KisColorSelector::configuration() const +KisColorSelectorConfiguration KisColorSelector::configuration() const { return m_configuration; } void KisColorSelector::updateSettings() { KisColorSelectorBase::updateSettings(); KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); - setConfiguration(Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelector::Configuration().toString()))); + setConfiguration(KisColorSelectorConfiguration::fromString(cfg.readEntry("colorSelectorConfiguration", KisColorSelectorConfiguration().toString()))); } void KisColorSelector::reset() { KisColorSelectorBase::reset(); if (m_mainComponent) { m_mainComponent->setDirty(); } if (m_subComponent) { m_subComponent->setDirty(); } } void KisColorSelector::paintEvent(QPaintEvent* e) { Q_UNUSED(e); QPainter p(this); p.fillRect(0,0,width(),height(),QColor(128,128,128)); p.setRenderHint(QPainter::Antialiasing); m_mainComponent->paintEvent(&p); m_subComponent->paintEvent(&p); } inline int iconSize(qreal width, qreal height) { qreal radius = qMin(width, height)/2.; qreal xm = width/2.; qreal ym = height/2.; if(xm>=2*ym || ym>=2*xm) return qBound(5., radius, 32.); qreal a=-2; qreal b=2.*(xm+ym); qreal c=radius*radius-xm*xm-ym*ym; return qBound(5., ((-b+sqrt(b*b-4*a*c))/(2*a)), 32.); } void KisColorSelector::resizeEvent(QResizeEvent* e) { - if(m_configuration.subType==Ring) { + if (m_configuration.subType == KisColorSelectorConfiguration::Ring) { + m_ring->setGeometry(0,0,width(), height()); - if(displaySettingsButton()) { + + if (displaySettingsButton()) { int size = iconSize(width(), height()); m_button->setGeometry(0, 0, size, size); } - if(m_configuration.mainType==Triangle) { + + if (m_configuration.mainType == KisColorSelectorConfiguration::Triangle) { m_triangle->setGeometry(width()/2-m_ring->innerRadius(), height()/2-m_ring->innerRadius(), m_ring->innerRadius()*2, m_ring->innerRadius()*2); } else { int size = m_ring->innerRadius()*2/sqrt(2.); m_square->setGeometry(width()/2-size/2, height()/2-size/2, size, size); } } else { // type wheel and square - if(m_configuration.mainType==Wheel) { + if (m_configuration.mainType == KisColorSelectorConfiguration::Wheel) { if(displaySettingsButton()) { int size = iconSize(width(), height()*0.9); m_button->setGeometry(0, height()*0.1, size, size); } m_mainComponent->setGeometry(0, height()*0.1, width(), height()*0.9); m_subComponent->setGeometry( 0, 0, width(), height()*0.1); } else { int buttonSize = 0; if(displaySettingsButton()) { buttonSize = qBound(20, int(0.1*height()), 32); m_button->setGeometry(0, 0, buttonSize, buttonSize); } if(height()>width()) { int selectorHeight=height()-buttonSize; m_mainComponent->setGeometry(0, buttonSize+selectorHeight*0.1, width(), selectorHeight*0.9); m_subComponent->setGeometry( 0, buttonSize, width(), selectorHeight*0.1); } else { int selectorWidth=width()-buttonSize; m_mainComponent->setGeometry(buttonSize, height()*0.1, selectorWidth, height()*0.9); m_subComponent->setGeometry( buttonSize, 0, selectorWidth, height()*0.1); } } } // reset the currect color after resizing the widget setColor(m_lastRealColor); KisColorSelectorBase::resizeEvent(e); } void KisColorSelector::mousePressEvent(QMouseEvent* e) { e->setAccepted(false); KisColorSelectorBase::mousePressEvent(e); if(!e->isAccepted()) { if(m_mainComponent->wantsGrab(e->x(), e->y())) m_grabbingComponent=m_mainComponent; else if(m_subComponent->wantsGrab(e->x(), e->y())) m_grabbingComponent=m_subComponent; mouseEvent(e); updatePreviousColorPreview(); e->accept(); } } void KisColorSelector::mouseMoveEvent(QMouseEvent* e) { KisColorSelectorBase::mouseMoveEvent(e); mouseEvent(e); e->accept(); } void KisColorSelector::mouseReleaseEvent(QMouseEvent* e) { e->setAccepted(false); KisColorSelectorBase::mousePressEvent(e); if(!e->isAccepted() && !(m_lastRealColor == m_currentRealColor)) { m_lastRealColor = m_currentRealColor; m_lastColorRole = Acs::buttonToRole(e->button()); updateColor(m_lastRealColor, m_lastColorRole, false); updateBaseColorPreview(m_currentRealColor); e->accept(); } m_grabbingComponent=0; } bool KisColorSelector::displaySettingsButton() { return dynamic_cast(parent()); } void KisColorSelector::setColor(const KoColor &color) { m_mainComponent->setColor(color); m_subComponent->setColor(color); m_lastRealColor = color; m_signalCompressor->start(); } void KisColorSelector::mouseEvent(QMouseEvent *e) { if (m_grabbingComponent && (e->buttons() & Qt::LeftButton || e->buttons() & Qt::RightButton)) { m_grabbingComponent->mouseEvent(e->x(), e->y()); KoColor color = m_mainComponent->currentColor(); Acs::ColorRole role = Acs::buttonsToRole(e->button(), e->buttons()); m_currentRealColor = color; requestUpdateColorAndPreview(color, role); } } void KisColorSelector::init() { setAcceptDrops(true); m_lastColorRole = Acs::Foreground; m_ring = new KisColorSelectorRing(this); m_triangle = new KisColorSelectorTriangle(this); m_slider = new KisColorSelectorSimple(this); m_square = new KisColorSelectorSimple(this); m_wheel = new KisColorSelectorWheel(this); if(displaySettingsButton()) { m_button = new QPushButton(this); m_button->setIcon(KisIconUtils::loadIcon("configure")); connect(m_button, SIGNAL(clicked()), SIGNAL(settingsButtonClicked())); } // a tablet can send many more signals, than a mouse // this causes many repaints, if updating after every signal. m_signalCompressor = new KisSignalCompressor(20, KisSignalCompressor::FIRST_INACTIVE, this); connect(m_signalCompressor, SIGNAL(timeout()), SLOT(update())); setMinimumSize(40, 40); } diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector.h b/plugins/dockers/advancedcolorselector/kis_color_selector.h index f9cf0f69bb..2958fdb51e 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector.h +++ b/plugins/dockers/advancedcolorselector/kis_color_selector.h @@ -1,143 +1,89 @@ /* * Copyright (c) 2010 Adam Celarek * * 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_COLOR_SELECTOR_H #define KIS_COLOR_SELECTOR_H #include "kis_color_selector_base.h" +#include class KisColorSelectorRing; class KisColorSelectorComponent; class KisColorSelectorSimple; class KisColorSelectorWheel; class QPushButton; class KisSignalCompressor; class KisColorSelector : public KisColorSelectorBase { Q_OBJECT public: - enum Type {Ring, Square, Wheel, Triangle, Slider}; - enum Parameters {H, hsvS, V, hslS, L, SL, SV, SV2, hsvSH, hslSH, VH, LH, SI, SY, hsiSH, hsySH, I, Y, IH, YH, hsiS, hsyS}; - struct Configuration { - Type mainType; - Type subType; - Parameters mainTypeParameter; - Parameters subTypeParameter; - Configuration(Type mainT = Triangle, - Type subT = Ring, - Parameters mainTP = SL, - Parameters subTP = H) - : mainType(mainT), - subType(subT), - mainTypeParameter(mainTP), - subTypeParameter(subTP) - {} - Configuration(QString string) - { - readString(string); - } - - QString toString() const - { - return QString("%1|%2|%3|%4").arg(mainType).arg(subType).arg(mainTypeParameter).arg(subTypeParameter); - } - void readString(QString string) - { - QStringList strili = string.split('|'); - if(strili.length()!=4) return; - - int imt=strili.at(0).toInt(); - int ist=strili.at(1).toInt(); - int imtp=strili.at(2).toInt(); - int istp=strili.at(3).toInt(); - - if(imt>Slider || ist>Slider || imtp>hsyS || istp>hsyS)//this was LH before - return; - - mainType = Type(imt); - subType = Type(ist); - mainTypeParameter = Parameters(imtp); - subTypeParameter = Parameters(istp); - } - static Configuration fromString(QString string) - { - Configuration ret; - ret.readString(string); - return ret; - } - }; - -// enum MainType {Ring, Square, Wheel}; -// enum SubType {Triangle, Square, Slider}; -// enum MainTypeParameter {SL, SV, SH, VH, LH, VSV/*experimental*/, SI, SY, YH, IH}; -// enum SubTypeParameter {H, S, V, L, I, Y, hsiS, hsyS}; - - KisColorSelector(Configuration conf, QWidget* parent = 0); + + KisColorSelector(KisColorSelectorConfiguration conf, QWidget* parent = 0); KisColorSelector(QWidget* parent=0); KisColorSelectorBase* createPopup() const; - void setConfiguration(Configuration conf); - Configuration configuration() const; + void setConfiguration(KisColorSelectorConfiguration conf); + KisColorSelectorConfiguration configuration() const; void setColor(const KoColor &color); public Q_SLOTS: void reset(); void updateSettings(); Q_SIGNALS: void settingsButtonClicked(); protected: void paintEvent(QPaintEvent*); void resizeEvent(QResizeEvent*); void mousePressEvent(QMouseEvent*); void mouseMoveEvent(QMouseEvent*); void mouseReleaseEvent(QMouseEvent*); bool displaySettingsButton(); private: void mouseEvent(QMouseEvent* e); void init(); KisColorSelectorRing* m_ring; KisColorSelectorComponent* m_triangle; KisColorSelectorSimple* m_slider; KisColorSelectorSimple* m_square; KisColorSelectorWheel* m_wheel; QPushButton* m_button; KisColorSelectorComponent* m_mainComponent; KisColorSelectorComponent* m_subComponent; KisColorSelectorComponent* m_grabbingComponent; KisSignalCompressor *m_signalCompressor; - Configuration m_configuration; + KisColorSelectorConfiguration m_configuration; KoColor m_lastRealColor; KoColor m_currentRealColor; bool m_blipDisplay; Acs::ColorRole m_lastColorRole; public: void setDisplayBlip(bool disp) {m_blipDisplay = disp;} bool displayBlip() const {return m_blipDisplay;} }; #endif // KIS_COLSELNG_COLOR_SELECTOR_H diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.cpp b/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.cpp index ff5d63832f..5c89d7b41a 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.cpp +++ b/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.cpp @@ -1,242 +1,242 @@ /* * Copyright (c) 2010 Adam Celarek * * 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 */ #include "kis_color_selector_combo_box.h" #include #include #include "kis_color_selector.h" #include "kis_canvas2.h" class KisColorSelectorComboBoxPrivate : public QWidget { public: int spacing; int selectorSize; QRect highlightArea; KisColorSelectorComboBoxPrivate(QWidget* parent) : QWidget(parent, Qt::Popup), spacing(20), selectorSize(100), highlightArea(-1,-1,0,0) { setMouseTracking(true); QGridLayout* layout = new QGridLayout(this); layout->setSpacing(spacing); //dbgKrita<<"Created list"; - - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Triangle, KisColorSelector::Ring, KisColorSelector::SL , KisColorSelector::H), this), 0,0); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SV , KisColorSelector::H), this), 0,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SV2, KisColorSelector::H), this), 0,2); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::VH, KisColorSelector::hsvS), this), 0,3); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hsvSH, KisColorSelector::V), this), 0,4); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SV2, KisColorSelector::H), this), 1,0); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SV, KisColorSelector::H), this), 1,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::VH, KisColorSelector::hsvS), this), 1,2); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::hsvSH, KisColorSelector::V), this), 1,3); - - - - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SL , KisColorSelector::H), this), 0,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::LH, KisColorSelector::hslS), this), 0,2); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hslSH, KisColorSelector::L), this), 0,3); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SL, KisColorSelector::H), this), 1,0); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::LH, KisColorSelector::hslS), this), 1,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::hslSH, KisColorSelector::L), this), 1,2); - - - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SI , KisColorSelector::H), this), 0,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::IH, KisColorSelector::hsiS), this), 0,2); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hsiSH, KisColorSelector::I), this), 0,3); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SI, KisColorSelector::H), this), 1,0); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::IH, KisColorSelector::hsiS), this), 1,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::hsiSH, KisColorSelector::I), this), 1,2); - - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Ring, KisColorSelector::SY , KisColorSelector::H), this), 0,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::YH, KisColorSelector::hsyS), this), 0,2); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Wheel, KisColorSelector::Slider, KisColorSelector::hsySH, KisColorSelector::Y), this), 0,3); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::SY, KisColorSelector::H), this), 1,0); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::YH, KisColorSelector::hsyS), this), 1,1); - layout->addWidget(new KisColorSelector(KisColorSelector::Configuration(KisColorSelector::Square, KisColorSelector::Slider, KisColorSelector::hsySH, KisColorSelector::Y), this), 1,2); + + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Triangle, KisColorSelectorConfiguration::Ring, KisColorSelectorConfiguration::SL , KisColorSelectorConfiguration::H), this), 0,0); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Ring, KisColorSelectorConfiguration::SV , KisColorSelectorConfiguration::H), this), 0,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Ring, KisColorSelectorConfiguration::SV2, KisColorSelectorConfiguration::H), this), 0,2); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::VH, KisColorSelectorConfiguration::hsvS), this), 0,3); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hsvSH, KisColorSelectorConfiguration::V), this), 0,4); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::SV2, KisColorSelectorConfiguration::H), this), 1,0); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::SV, KisColorSelectorConfiguration::H), this), 1,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::VH, KisColorSelectorConfiguration::hsvS), this), 1,2); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hsvSH, KisColorSelectorConfiguration::V), this), 1,3); + + + + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Ring, KisColorSelectorConfiguration::SL , KisColorSelectorConfiguration::H), this), 0,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::LH, KisColorSelectorConfiguration::hslS), this), 0,2); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hslSH, KisColorSelectorConfiguration::L), this), 0,3); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::SL, KisColorSelectorConfiguration::H), this), 1,0); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::LH, KisColorSelectorConfiguration::hslS), this), 1,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hslSH, KisColorSelectorConfiguration::L), this), 1,2); + + + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Ring, KisColorSelectorConfiguration::SI , KisColorSelectorConfiguration::H), this), 0,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::IH, KisColorSelectorConfiguration::hsiS), this), 0,2); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hsiSH, KisColorSelectorConfiguration::I), this), 0,3); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::SI, KisColorSelectorConfiguration::H), this), 1,0); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::IH, KisColorSelectorConfiguration::hsiS), this), 1,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hsiSH, KisColorSelectorConfiguration::I), this), 1,2); + + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Ring, KisColorSelectorConfiguration::SY , KisColorSelectorConfiguration::H), this), 0,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::YH, KisColorSelectorConfiguration::hsyS), this), 0,2); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Wheel, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hsySH, KisColorSelectorConfiguration::Y), this), 0,3); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::SY, KisColorSelectorConfiguration::H), this), 1,0); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::YH, KisColorSelectorConfiguration::hsyS), this), 1,1); + layout->addWidget(new KisColorSelector(KisColorSelectorConfiguration(KisColorSelectorConfiguration::Square, KisColorSelectorConfiguration::Slider, KisColorSelectorConfiguration::hsySH, KisColorSelectorConfiguration::Y), this), 1,2); setList(0); for(int i=0; ilayout()->count(); i++) { KisColorSelector* item = dynamic_cast(this->layout()->itemAt(i)->widget()); Q_ASSERT(item); if(item!=0) { item->setMaximumSize(selectorSize, selectorSize); item->setMinimumSize(selectorSize, selectorSize); item->setMouseTracking(true); item->setEnabled(false); item->setColor(KoColor(QColor(255,0,0), item->colorSpace())); item->setDisplayBlip(false); } } - + } void setList(int model){ for(int i=1; icount(); i++) { layout()->itemAt(i)->widget()->hide(); } - + if (model==0){ for(int i=1; i<9; i++) { layout()->itemAt(i)->widget()->show(); } } - + if (model==1){ for(int i=9; i<15; i++) { layout()->itemAt(i)->widget()->show(); } } - + if (model==2){ for(int i=15; i<21; i++) { layout()->itemAt(i)->widget()->show(); } } - + if (model==3){ for(int i=21; icount(); i++) { layout()->itemAt(i)->widget()->show(); } - } + } } protected: void paintEvent(QPaintEvent *) override { QPainter painter(this); painter.fillRect(0,0,width(), height(), QColor(128,128,128)); painter.fillRect(highlightArea, palette().highlight()); } void mouseMoveEvent(QMouseEvent * e) override { if(rect().contains(e->pos())) { for(int i=0; icount(); i++) { - + KisColorSelector* item = dynamic_cast(layout()->itemAt(i)->widget()); Q_ASSERT(item); - + if(layout()->itemAt(i)->widget()->isVisible()==true && item->geometry().adjusted(-spacing/2, -spacing/2, spacing/2, spacing/2).contains(e->pos())) { QRect oldArea=highlightArea; highlightArea=item->geometry().adjusted(-spacing/2, -spacing/2, spacing/2, spacing/2); m_lastActiveConfiguration=item->configuration(); update(highlightArea); update(oldArea); } } } else { highlightArea.setRect(-1,-1,0,0); } } void mousePressEvent(QMouseEvent* e) override { if(rect().contains(e->pos())) { KisColorSelectorComboBox* parent = dynamic_cast(this->parent()); Q_ASSERT(parent); parent->setConfiguration(m_lastActiveConfiguration); //setList(parent->m_model); } //dbgKrita<<"mousepress"; hide(); e->accept(); } - KisColorSelector::Configuration m_lastActiveConfiguration; + KisColorSelectorConfiguration m_lastActiveConfiguration; }; KisColorSelectorComboBox::KisColorSelectorComboBox(QWidget* parent) : QComboBox(parent), m_private(new KisColorSelectorComboBoxPrivate(this)), m_currentSelector(this) { QLayout* layout = new QGridLayout(this); layout->addWidget(&m_currentSelector); m_currentSelector.setEnabled(false); m_currentSelector.setDisplayBlip(false); m_currentSelector.setColor(KoColor(QColor(255,0,0), m_currentSelector.colorSpace())); // 30 pixels for the arrow of the combobox setMinimumSize(m_private->selectorSize+m_private->spacing+30,m_private->selectorSize+m_private->spacing); m_currentSelector.setMaximumSize(m_private->selectorSize, m_private->selectorSize); } KisColorSelectorComboBox::~KisColorSelectorComboBox() { } void KisColorSelectorComboBox::hidePopup() { QComboBox::hidePopup(); m_private->hide(); } void KisColorSelectorComboBox::showPopup() { // only show if this is not the popup QComboBox::showPopup(); m_private->move(mapToGlobal(QPoint(0,0))); m_private->show(); } void KisColorSelectorComboBox::setColorSpace(const KoColorSpace *colorSpace) { //this is not the popup, but we should set the canvas for all popup selectors for(int i=0; ilayout()->count(); i++) { KisColorSelector* item = dynamic_cast(m_private->layout()->itemAt(i)->widget()); Q_ASSERT(item); if(item!=0) { item->setColorSpace(colorSpace); } } m_currentSelector.setColorSpace(colorSpace); update(); } -KisColorSelector::Configuration KisColorSelectorComboBox::configuration() const +KisColorSelectorConfiguration KisColorSelectorComboBox::configuration() const { return m_configuration; } void KisColorSelectorComboBox::paintEvent(QPaintEvent *e) { QComboBox::paintEvent(e); } -void KisColorSelectorComboBox::setConfiguration(KisColorSelector::Configuration conf) +void KisColorSelectorComboBox::setConfiguration(KisColorSelectorConfiguration conf) { m_configuration=conf; m_currentSelector.setConfiguration(conf); m_currentSelector.setColor(KoColor(QColor(255,0,0), m_currentSelector.colorSpace())); update(); } void KisColorSelectorComboBox::setList(int model) { - m_private->setList(model); + m_private->setList(model); } diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.h b/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.h index 64955aa6c1..a141ffe5ca 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.h +++ b/plugins/dockers/advancedcolorselector/kis_color_selector_combo_box.h @@ -1,49 +1,49 @@ /* * Copyright (c) 2010 Adam Celarek * * 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 */ #ifndef KIS_COLOR_SELECTOR_COMBO_BOX_H #define KIS_COLOR_SELECTOR_COMBO_BOX_H #include #include "kis_color_selector.h" class KisColorSelectorComboBoxPrivate; class KoColorSpace; class KisColorSelectorComboBox : public QComboBox { Q_OBJECT public: KisColorSelectorComboBox(QWidget* parent=0); ~KisColorSelectorComboBox(); void hidePopup(); void showPopup(); - KisColorSelector::Configuration configuration() const; + KisColorSelectorConfiguration configuration() const; //int m_model; protected: void paintEvent(QPaintEvent *e); public Q_SLOTS: void setColorSpace(const KoColorSpace* colorSpace); - void setConfiguration(KisColorSelector::Configuration); + void setConfiguration(KisColorSelectorConfiguration); void setList(int model); private: KisColorSelectorComboBoxPrivate* m_private; - KisColorSelector::Configuration m_configuration; + KisColorSelectorConfiguration m_configuration; KisColorSelector m_currentSelector; }; #endif diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector_component.h b/plugins/dockers/advancedcolorselector/kis_color_selector_component.h index 13e1a3c7a1..eaaeeda3c4 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector_component.h +++ b/plugins/dockers/advancedcolorselector/kis_color_selector_component.h @@ -1,114 +1,114 @@ /* * Copyright (c) 2010 Adam Celarek * * 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 */ #ifndef KIS_COLOR_SELECTOR_COMPONENT_H #define KIS_COLOR_SELECTOR_COMPONENT_H #include #include #include "kis_color_selector.h" class KoColorSpace; class QPainter; class KisColorSelectorComponent : public QObject { Q_OBJECT public: - typedef KisColorSelector::Parameters Parameter; - typedef KisColorSelector::Type Type; + typedef KisColorSelectorConfiguration::Parameters Parameter; + typedef KisColorSelectorConfiguration::Type Type; explicit KisColorSelectorComponent(KisColorSelector* parent); void setGeometry(int x, int y, int width, int height); void paintEvent(QPainter*); /// saves the mouse position, so that a blip can be created. void mouseEvent(int x, int y); /// return the color, that was selected by calling mouseEvent KoColor currentColor(); int width() const; int height() const; /// setConfiguration can be ignored (for instance ring and triangle, as they can have only one config) void setConfiguration(Parameter param, Type type); /// set the color, blibs etc virtual void setColor(const KoColor& color) = 0; /// force subsequent redraw of the component void setDirty(); /// returns true, if this component wants to grab the mouse (normally true, if containsPoint returns true) bool wantsGrab(int x, int y) {return containsPointInComponentCoords(x-m_x, y-m_y);} public Q_SLOTS: /// set hue, saturation, value or/and lightness /// unused parameters should be set to -1 void setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma); Q_SIGNALS: /// request for repaint, for instance, if the hue changes. void update(); /// -1, if unaffected void paramChanged(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma); protected: const KoColorSpace* colorSpace() const; /// returns true, if ether the colour space, the size or the parameters have changed since the last paint event bool isDirty() const; /// this method must be overloaded to return the colour at position x/y and draw a marker on that position virtual KoColor selectColor(int x, int y) = 0; /// paint component using given painter /// the component should respect width() and height() (eg. scale to width and height), but doesn't /// have to care about x/y coordinates (top left corner) virtual void paint(QPainter*) = 0; /// a subclass can implement this method, the default returns true if the coordinates are in the component rect /// values for the subclasses are provided in component coordinates, eg (0,0) is top left of component virtual bool containsPointInComponentCoords(int x, int y) const; // Workaround for Bug 287001 void setLastMousePosition(int x, int y); qreal m_hue; qreal m_hsvSaturation; qreal m_value; qreal m_hslSaturation; qreal m_lightness; qreal m_hsiSaturation; qreal m_intensity; qreal m_hsySaturation; qreal m_luma; Parameter m_parameter; Type m_type; KisColorSelector* m_parent; private: int m_width; int m_height; int m_x; int m_y; bool m_dirty; const KoColorSpace* m_lastColorSpace; qreal m_lastX; qreal m_lastY; }; #endif // KIS_COLOR_SELECTOR_COMPONENT_H diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector_settings.cpp b/plugins/dockers/advancedcolorselector/kis_color_selector_settings.cpp index b83218ced2..e1458d2c92 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector_settings.cpp +++ b/plugins/dockers/advancedcolorselector/kis_color_selector_settings.cpp @@ -1,634 +1,634 @@ /* * Copyright (C) 2010 Celarek Adam * * 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_color_selector_settings.h" #include "ui_wdg_color_selector_settings.h" #include #include #include #include #include #include #include "KoColorSpace.h" #include "KoColorSpaceRegistry.h" #include "KoColorProfile.h" #include "kis_color_selector_combo_box.h" #include "kis_color_selector.h" #include "kis_config.h" KisColorSelectorSettings::KisColorSelectorSettings(QWidget *parent) : KisPreferenceSet(parent), ui(new Ui::KisColorSelectorSettings) { ui->setupUi(this); resize(minimumSize()); ui->colorSelectorConfiguration->setColorSpace(ui->colorSpace->currentColorSpace()); ui->useDifferentColorSpaceCheckbox->setChecked(false); connect(ui->useDifferentColorSpaceCheckbox, SIGNAL(clicked(bool)), this, SLOT(useDifferentColorSpaceChecked(bool))); /* color docker selector drop down */ ui->dockerColorSettingsComboBox->addItem(i18n("Advanced Color Selector")); ui->dockerColorSettingsComboBox->addItem(i18n("Color Sliders")); ui->dockerColorSettingsComboBox->addItem(i18n("Color Hotkeys")); ui->dockerColorSettingsComboBox->setCurrentIndex(0); // start off seeing advanced color selector properties connect( ui->dockerColorSettingsComboBox, SIGNAL(currentIndexChanged(int)),this, SLOT(changedColorDocker(int))); changedColorDocker(0); /* advanced color docker options */ ui->dockerResizeOptionsComboBox->addItem(i18n("Change to a Horizontal Layout")); ui->dockerResizeOptionsComboBox->addItem(i18n("Hide Shade Selector")); ui->dockerResizeOptionsComboBox->addItem(i18n("Do Nothing")); ui->dockerResizeOptionsComboBox->setCurrentIndex(0); ui->zoomSelectorOptionComboBox->addItem(i18n("When Pressing Middle Mouse Button")); ui->zoomSelectorOptionComboBox->addItem(i18n("On Mouse Over")); ui->zoomSelectorOptionComboBox->addItem(i18n("Never")); ui->zoomSelectorOptionComboBox->setCurrentIndex(0); ui->colorSelectorTypeComboBox->addItem(i18n("HSV")); ui->colorSelectorTypeComboBox->addItem(i18n("HSL")); ui->colorSelectorTypeComboBox->addItem(i18n("HSI")); ui->colorSelectorTypeComboBox->addItem(i18n("HSY'")); ui->colorSelectorTypeComboBox->setCurrentIndex(0); connect( ui->colorSelectorTypeComboBox, SIGNAL(currentIndexChanged(int)),this, SLOT(changedACSColorSelectorType(int))); changedACSColorSelectorType(0); // initialize everything to HSV at the start ui->ACSshadeSelectorMyPaintColorModelComboBox->addItem(i18n("HSV")); ui->ACSshadeSelectorMyPaintColorModelComboBox->addItem(i18n("HSL")); ui->ACSshadeSelectorMyPaintColorModelComboBox->addItem(i18n("HSI")); ui->ACSshadeSelectorMyPaintColorModelComboBox->addItem(i18n("HSY'")); ui->ACSshadeSelectorMyPaintColorModelComboBox->setCurrentIndex(0); ui->ACSShadeSelectorTypeComboBox->addItem(i18n("MyPaint")); ui->ACSShadeSelectorTypeComboBox->addItem(i18n("Minimal")); ui->ACSShadeSelectorTypeComboBox->addItem(i18n("Do Not Show")); ui->ACSShadeSelectorTypeComboBox->setCurrentIndex(0); changedACSShadeSelectorType(0); // show/hide UI elements for MyPaint settings connect( ui->ACSShadeSelectorTypeComboBox, SIGNAL(currentIndexChanged(int)),this, SLOT(changedACSShadeSelectorType(int))); ui->commonColorsAlignVertical->setChecked(true); ui->commonColorsAlignHorizontal->setChecked(true); connect( ui->commonColorsAlignHorizontal, SIGNAL(toggled(bool)), this, SLOT(changedACSColorAlignment(bool))); connect( ui->lastUsedColorsAlignHorizontal, SIGNAL(toggled(bool)), this, SLOT(changedACSLastUsedColorAlignment(bool))); changedACSColorAlignment(ui->commonColorsAlignHorizontal->isChecked()); changedACSLastUsedColorAlignment(ui->lastUsedColorsAlignHorizontal->isChecked()); connect(ui->colorSpace, SIGNAL(colorSpaceChanged(const KoColorSpace*)), ui->colorSelectorConfiguration, SLOT(setColorSpace(const KoColorSpace*))); connect(this, SIGNAL(hsxchanged(int)), ui->colorSelectorConfiguration, SLOT(setList(int))); connect(ui->minimalShadeSelectorLineCount, SIGNAL(valueChanged(int)), ui->minimalShadeSelectorLineSettings, SLOT(setLineCount(int))); connect(ui->minimalShadeSelectorLineSettings, SIGNAL(lineCountChanged(int)), ui->minimalShadeSelectorLineCount, SLOT(setValue(int))); connect(ui->minimalShadeSelectorAsGradient, SIGNAL(toggled(bool)), ui->minimalShadeSelectorLineSettings, SIGNAL(setGradient(bool))); connect(ui->minimalShadeSelectorAsColorPatches, SIGNAL(toggled(bool)), ui->minimalShadeSelectorLineSettings, SIGNAL(setPatches(bool))); connect(ui->minimalShadeSelectorLineHeight, SIGNAL(valueChanged(int)), ui->minimalShadeSelectorLineSettings, SIGNAL(setLineHeight(int))); connect(ui->minimalShadeSelectorPatchesPerLine, SIGNAL(valueChanged(int)), ui->minimalShadeSelectorLineSettings, SIGNAL(setPatchCount(int))); } KisColorSelectorSettings::~KisColorSelectorSettings() { delete ui; } QString KisColorSelectorSettings::id() { return QString("advancedColorSelector"); } QString KisColorSelectorSettings::name() { return header(); } QString KisColorSelectorSettings::header() { return QString(i18n("Color Selector Settings")); } QIcon KisColorSelectorSettings::icon() { return KisIconUtils::loadIcon("extended_color_selector"); } void KisColorSelectorSettings::savePreferences() const { // write cfg KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); KConfigGroup hsxcfg = KSharedConfig::openConfig()->group("hsxColorSlider"); KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys"); // advanced color selector cfg.writeEntry("onDockerResize", ui->dockerResizeOptionsComboBox->currentIndex()); cfg.writeEntry("zoomSelectorOptions", ui->zoomSelectorOptionComboBox->currentIndex() ); cfg.writeEntry("zoomSize", ui->popupSize->value()); bool useCustomColorSpace = ui->useDifferentColorSpaceCheckbox->isChecked(); const KoColorSpace* colorSpace = useCustomColorSpace ? ui->colorSpace->currentColorSpace() : 0; KisConfig kisconfig; kisconfig.setCustomColorSelectorColorSpace(colorSpace); //color patches cfg.writeEntry("lastUsedColorsShow", ui->lastUsedColorsShow->isChecked()); cfg.writeEntry("lastUsedColorsAlignment", ui->lastUsedColorsAlignVertical->isChecked()); cfg.writeEntry("lastUsedColorsScrolling", ui->lastUsedColorsAllowScrolling->isChecked()); cfg.writeEntry("lastUsedColorsNumCols", ui->lastUsedColorsNumCols->value()); cfg.writeEntry("lastUsedColorsNumRows", ui->lastUsedColorsNumRows->value()); cfg.writeEntry("lastUsedColorsCount", ui->lastUsedColorsPatchCount->value()); cfg.writeEntry("lastUsedColorsWidth", ui->lastUsedColorsWidth->value()); cfg.writeEntry("lastUsedColorsHeight", ui->lastUsedColorsHeight->value()); cfg.writeEntry("commonColorsShow", ui->commonColorsShow->isChecked()); cfg.writeEntry("commonColorsAlignment", ui->commonColorsAlignVertical->isChecked()); cfg.writeEntry("commonColorsScrolling", ui->commonColorsAllowScrolling->isChecked()); cfg.writeEntry("commonColorsNumCols", ui->commonColorsNumCols->value()); cfg.writeEntry("commonColorsNumRows", ui->commonColorsNumRows->value()); cfg.writeEntry("commonColorsCount", ui->commonColorsPatchCount->value()); cfg.writeEntry("commonColorsWidth", ui->commonColorsWidth->value()); cfg.writeEntry("commonColorsHeight", ui->commonColorsHeight->value()); cfg.writeEntry("commonColorsAutoUpdate", ui->commonColorsAutoUpdate->isChecked()); //shade selector int shadeSelectorTypeIndex = ui->ACSShadeSelectorTypeComboBox->currentIndex(); if(shadeSelectorTypeIndex == 0) { cfg.writeEntry("shadeSelectorType", "MyPaint"); } else if (shadeSelectorTypeIndex == 1) { cfg.writeEntry("shadeSelectorType", "Minimal"); } else { cfg.writeEntry("shadeSelectorType", "Hidden"); } cfg.writeEntry("shadeSelectorUpdateOnRightClick", ui->shadeSelectorUpdateOnRightClick->isChecked()); cfg.writeEntry("shadeSelectorUpdateOnForeground", ui->shadeSelectorUpdateOnForeground->isChecked()); cfg.writeEntry("shadeSelectorUpdateOnLeftClick", ui->shadeSelectorUpdateOnLeftClick->isChecked()); cfg.writeEntry("shadeSelectorUpdateOnBackground", ui->shadeSelectorUpdateOnBackground->isChecked()); cfg.writeEntry("hidePopupOnClickCheck", ui->hidePopupOnClickCheck->isChecked()); //mypaint model int shadeMyPaintComboBoxIndex = ui->ACSshadeSelectorMyPaintColorModelComboBox->currentIndex(); if (shadeMyPaintComboBoxIndex == 0 ) { cfg.writeEntry("shadeMyPaintType", "HSV"); } else if (shadeMyPaintComboBoxIndex == 1 ) { cfg.writeEntry("shadeMyPaintType", "HSL"); } else if (shadeMyPaintComboBoxIndex == 2 ) { cfg.writeEntry("shadeMyPaintType", "HSI"); } else { // HSY cfg.writeEntry("shadeMyPaintType", "HSY"); } cfg.writeEntry("minimalShadeSelectorAsGradient", ui->minimalShadeSelectorAsGradient->isChecked()); cfg.writeEntry("minimalShadeSelectorPatchCount", ui->minimalShadeSelectorPatchesPerLine->value()); cfg.writeEntry("minimalShadeSelectorLineConfig", ui->minimalShadeSelectorLineSettings->toString()); cfg.writeEntry("minimalShadeSelectorLineHeight", ui->minimalShadeSelectorLineHeight->value()); //color selector KisColorSelectorComboBox* cstw = dynamic_cast(ui->colorSelectorConfiguration); cfg.writeEntry("colorSelectorConfiguration", cstw->configuration().toString()); cfg.writeEntry("hsxSettingType", ui->colorSelectorTypeComboBox->currentIndex()); //luma// cfg.writeEntry("lumaR", ui->l_lumaR->value()); cfg.writeEntry("lumaG", ui->l_lumaG->value()); cfg.writeEntry("lumaB", ui->l_lumaB->value()); cfg.writeEntry("gamma", ui->SP_Gamma->value()); //slider// hsxcfg.writeEntry("hsvH", ui->csl_hsvH->isChecked()); hsxcfg.writeEntry("hsvS", ui->csl_hsvS->isChecked()); hsxcfg.writeEntry("hsvV", ui->csl_hsvV->isChecked()); hsxcfg.writeEntry("hslH", ui->csl_hslH->isChecked()); hsxcfg.writeEntry("hslS", ui->csl_hslS->isChecked()); hsxcfg.writeEntry("hslL", ui->csl_hslL->isChecked()); hsxcfg.writeEntry("hsiH", ui->csl_hsiH->isChecked()); hsxcfg.writeEntry("hsiS", ui->csl_hsiS->isChecked()); hsxcfg.writeEntry("hsiI", ui->csl_hsiI->isChecked()); hsxcfg.writeEntry("hsyH", ui->csl_hsyH->isChecked()); hsxcfg.writeEntry("hsyS", ui->csl_hsyS->isChecked()); hsxcfg.writeEntry("hsyY", ui->csl_hsyY->isChecked()); //hotkeys// hotkeycfg.writeEntry("steps_lightness", ui->sb_lightness->value()); hotkeycfg.writeEntry("steps_saturation", ui->sb_saturation->value()); hotkeycfg.writeEntry("steps_hue", ui->sb_hue->value()); hotkeycfg.writeEntry("steps_redgreen", ui->sb_rg->value()); hotkeycfg.writeEntry("steps_blueyellow", ui->sb_by->value()); emit settingsChanged(); } //void KisColorSelectorSettings::changeEvent(QEvent *e) //{ // QDialog::changeEvent(e); // switch (e->type()) { // case QEvent::LanguageChange: // ui->retranslateUi(this); // break; // default: // break; // } //} void KisColorSelectorSettings::changedColorDocker(int index) { // having a situation where too many sections are visible makes the window too large. turn all off before turning more on ui->colorSliderOptions->hide(); ui->advancedColorSelectorOptions->hide(); ui->hotKeyOptions->hide(); if (index == 0) { // advanced color selector options selected ui->advancedColorSelectorOptions->show(); ui->colorSliderOptions->hide(); ui->hotKeyOptions->hide(); } else if (index == 1) { // color slider options selected ui->advancedColorSelectorOptions->hide(); ui->hotKeyOptions->hide(); ui->colorSliderOptions->show(); } else { ui->colorSliderOptions->hide(); ui->advancedColorSelectorOptions->hide(); ui->hotKeyOptions->show(); } } void KisColorSelectorSettings::changedACSColorSelectorType(int index) { ui->lumaCoefficientGroupbox->setVisible(false); if (index == 0) { // HSV ui->ACSTypeDescriptionLabel->setText(i18n("Values goes from black to white, or black to the most saturated colour. Saturation, in turn, goes from the most saturated colour to white, grey or black.")); } else if (index == 1) { // HSL ui->ACSTypeDescriptionLabel->setText(i18n("Lightness goes from black to white, with middle grey being equal to the most saturated colour.")); } else if (index == 2) { // HSI ui->ACSTypeDescriptionLabel->setText(i18n("Intensity maps to the sum of rgb components")); } else { // HSY' ui->ACSTypeDescriptionLabel->setText(i18n("Luma(Y') is weighted by its coefficients which are configurable. Default values are set to 'rec 709'.")); ui->lumaCoefficientGroupbox->setVisible(true); } ui->colorSelectorConfiguration->update(); emit hsxchanged(index); } void KisColorSelectorSettings::changedACSColorAlignment(bool toggled) { // this slot is tied to the horizontal radio button's state being changed // you can infer the vertical state ui->lbl_commonColorsNumCols->setDisabled(toggled); ui->commonColorsNumCols->setDisabled(toggled); ui->lbl_commonColorsNumRows->setEnabled(toggled); ui->commonColorsNumRows->setEnabled(toggled); } void KisColorSelectorSettings::changedACSLastUsedColorAlignment(bool toggled) { // this slot is tied to the horizontal radio button's state being changed // you can infer the vertical state ui->lbl_lastUsedNumCols->setDisabled(toggled); ui->lastUsedColorsNumCols->setDisabled(toggled); ui->lbl_lastUsedNumRows->setEnabled(toggled); ui->lastUsedColorsNumRows->setEnabled(toggled); } void KisColorSelectorSettings::changedACSShadeSelectorType(int index) { if (index == 0) { // MyPaint ui->minimalShadeSelectorGroup->hide(); ui->myPaintColorModelLabel->show(); ui->ACSshadeSelectorMyPaintColorModelComboBox->show(); } else if (index == 1) { // Minimal ui->minimalShadeSelectorGroup->show(); ui->myPaintColorModelLabel->hide(); ui->ACSshadeSelectorMyPaintColorModelComboBox->hide(); }else { // do not show ui->minimalShadeSelectorGroup->hide(); ui->myPaintColorModelLabel->hide(); ui->ACSshadeSelectorMyPaintColorModelComboBox->hide(); } } void KisColorSelectorSettings::useDifferentColorSpaceChecked(bool enabled) { ui->colorSpace->setEnabled(enabled); } void KisColorSelectorSettings::loadPreferences() { //read cfg //don't forget to also add a new entry to the default preferences KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); KConfigGroup hsxcfg = KSharedConfig::openConfig()->group("hsxColorSlider"); KConfigGroup hotkeycfg = KSharedConfig::openConfig()->group("colorhotkeys"); // Advanced color selector ui->dockerResizeOptionsComboBox->setCurrentIndex( (int)cfg.readEntry("onDockerResize", 0) ); ui->zoomSelectorOptionComboBox->setCurrentIndex( (int) cfg.readEntry("zoomSelectorOptions", 0) ); ui->popupSize->setValue(cfg.readEntry("zoomSize", 280)); { KisConfig kisconfig; const KoColorSpace *cs = kisconfig.customColorSelectorColorSpace(); if(cs) { ui->useDifferentColorSpaceCheckbox->setChecked(true); ui->colorSpace->setEnabled(true); ui->colorSpace->setCurrentColorSpace(cs); } else { ui->useDifferentColorSpaceCheckbox->setChecked(false); ui->colorSpace->setEnabled(false); } } //color patches ui->lastUsedColorsShow->setChecked(cfg.readEntry("lastUsedColorsShow", true)); bool a = cfg.readEntry("lastUsedColorsAlignment", true); ui->lastUsedColorsAlignVertical->setChecked(a); ui->lastUsedColorsAlignHorizontal->setChecked(!a); ui->lastUsedColorsAllowScrolling->setChecked(cfg.readEntry("lastUsedColorsScrolling", true)); ui->lastUsedColorsNumCols->setValue(cfg.readEntry("lastUsedColorsNumCols", 1)); ui->lastUsedColorsNumRows->setValue(cfg.readEntry("lastUsedColorsNumRows", 1)); ui->lastUsedColorsPatchCount->setValue(cfg.readEntry("lastUsedColorsCount", 20)); ui->lastUsedColorsWidth->setValue(cfg.readEntry("lastUsedColorsWidth", 16)); ui->lastUsedColorsHeight->setValue(cfg.readEntry("lastUsedColorsHeight", 16)); ui->commonColorsShow->setChecked(cfg.readEntry("commonColorsShow", true)); a = cfg.readEntry("commonColorsAlignment", false); ui->commonColorsAlignVertical->setChecked(a); ui->commonColorsAlignHorizontal->setChecked(!a); ui->commonColorsAllowScrolling->setChecked(cfg.readEntry("commonColorsScrolling", false)); ui->commonColorsNumCols->setValue(cfg.readEntry("commonColorsNumCols", 1)); ui->commonColorsNumRows->setValue(cfg.readEntry("commonColorsNumRows", 1)); ui->commonColorsPatchCount->setValue(cfg.readEntry("commonColorsCount", 12)); ui->commonColorsWidth->setValue(cfg.readEntry("commonColorsWidth", 16)); ui->commonColorsHeight->setValue(cfg.readEntry("commonColorsHeight", 16)); ui->commonColorsAutoUpdate->setChecked(cfg.readEntry("commonColorsAutoUpdate", false)); //shade selector QString shadeSelectorType=cfg.readEntry("shadeSelectorType", "MyPaint"); if ( shadeSelectorType == "MyPaint") { ui->ACSShadeSelectorTypeComboBox->setCurrentIndex(0); } else if (shadeSelectorType == "Minimal") { ui->ACSShadeSelectorTypeComboBox->setCurrentIndex(1); } else { // Hidden ui->ACSShadeSelectorTypeComboBox->setCurrentIndex(2); } ui->shadeSelectorUpdateOnRightClick->setChecked(cfg.readEntry("shadeSelectorUpdateOnRightClick", false)); ui->shadeSelectorUpdateOnLeftClick->setChecked(cfg.readEntry("shadeSelectorUpdateOnLeftClick", false)); ui->shadeSelectorUpdateOnForeground->setChecked(cfg.readEntry("shadeSelectorUpdateOnForeground", true)); ui->shadeSelectorUpdateOnBackground->setChecked(cfg.readEntry("shadeSelectorUpdateOnBackground", true)); ui->hidePopupOnClickCheck->setChecked(cfg.readEntry("hidePopupOnClickCheck", false)); QString shadeMyPaintType = cfg.readEntry("shadeMyPaintType", "HSV"); if (shadeMyPaintType == "HSV" ) { ui->ACSshadeSelectorMyPaintColorModelComboBox->setCurrentIndex(0); } else if (shadeMyPaintType == "HSL" ) { ui->ACSshadeSelectorMyPaintColorModelComboBox->setCurrentIndex(1); } else if (shadeMyPaintType == "HSI" ) { ui->ACSshadeSelectorMyPaintColorModelComboBox->setCurrentIndex(2); } else { // HSY ui->ACSshadeSelectorMyPaintColorModelComboBox->setCurrentIndex(3); } bool asGradient = cfg.readEntry("minimalShadeSelectorAsGradient", true); if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true); else ui->minimalShadeSelectorAsColorPatches->setChecked(true); ui->minimalShadeSelectorPatchesPerLine->setValue(cfg.readEntry("minimalShadeSelectorPatchCount", 10)); ui->minimalShadeSelectorLineSettings->fromString(cfg.readEntry("minimalShadeSelectorLineConfig", "0|0.2|0|0|0|0|0;1|0|1|1|0|0|0;2|0|-1|1|0|0|0;")); ui->minimalShadeSelectorLineHeight->setValue(cfg.readEntry("minimalShadeSelectorLineHeight", 10)); int hsxSettingType= (int)cfg.readEntry("hsxSettingType", 0); ui->colorSelectorTypeComboBox->setCurrentIndex(hsxSettingType); //color selector KisColorSelectorComboBox* cstw = dynamic_cast(ui->colorSelectorConfiguration); - cstw->setConfiguration(KisColorSelector::Configuration::fromString(cfg.readEntry("colorSelectorConfiguration", "3|0|5|0"))); // triangle selector + cstw->setConfiguration(KisColorSelectorConfiguration::fromString(cfg.readEntry("colorSelectorConfiguration", "3|0|5|0"))); // triangle selector //luma values// ui->l_lumaR->setValue(cfg.readEntry("lumaR", 0.2126)); ui->l_lumaG->setValue(cfg.readEntry("lumaG", 0.7152)); ui->l_lumaB->setValue(cfg.readEntry("lumaB", 0.0722)); ui->SP_Gamma->setValue(cfg.readEntry("gamma", 2.2)); //color sliders// ui->csl_hsvH->setChecked(hsxcfg.readEntry("hsvH", false)); ui->csl_hsvS->setChecked(hsxcfg.readEntry("hsvS", false)); ui->csl_hsvV->setChecked(hsxcfg.readEntry("hsvV", false)); ui->csl_hslH->setChecked(hsxcfg.readEntry("hslH", true)); ui->csl_hslS->setChecked(hsxcfg.readEntry("hslS", true)); ui->csl_hslL->setChecked(hsxcfg.readEntry("hslL", true)); ui->csl_hsiH->setChecked(hsxcfg.readEntry("hsiH", false)); ui->csl_hsiS->setChecked(hsxcfg.readEntry("hsiS", false)); ui->csl_hsiI->setChecked(hsxcfg.readEntry("hsiI", false)); ui->csl_hsyH->setChecked(hsxcfg.readEntry("hsyH", false)); ui->csl_hsyS->setChecked(hsxcfg.readEntry("hsyS", false)); ui->csl_hsyY->setChecked(hsxcfg.readEntry("hsyY", false)); //hotkeys// ui->sb_lightness->setValue(hotkeycfg.readEntry("steps_lightness", 10)); ui->sb_saturation->setValue(hotkeycfg.readEntry("steps_saturation", 10)); ui->sb_hue->setValue(hotkeycfg.readEntry("steps_hue", 36)); ui->sb_rg->setValue(hotkeycfg.readEntry("steps_redgreen", 10)); ui->sb_by->setValue(hotkeycfg.readEntry("steps_blueyellow", 10)); } void KisColorSelectorSettings::loadDefaultPreferences() { //set defaults //if you change something, don't forget that loadPreferences should be kept in sync // advanced color selector docker ui->dockerResizeOptionsComboBox->setCurrentIndex(0); ui->zoomSelectorOptionComboBox->setCurrentIndex(0); ui->popupSize->setValue(280); ui->useDifferentColorSpaceCheckbox->setChecked(false); ui->colorSpace->setCurrentColorModel(KoID("RGBA")); ui->colorSpace->setCurrentColorDepth(KoID("U8")); ui->colorSpace->setCurrentProfile(KoColorSpaceRegistry::instance()->rgb8()->profile()->name()); //color patches ui->lastUsedColorsShow->setChecked(true); ui->lastUsedColorsAlignVertical->setChecked(true); ui->lastUsedColorsAlignHorizontal->setChecked(false); ui->lastUsedColorsAllowScrolling->setChecked(true); ui->lastUsedColorsNumCols->setValue(1); ui->lastUsedColorsNumRows->setValue(1); ui->lastUsedColorsPatchCount->setValue(20); ui->lastUsedColorsWidth->setValue(16); ui->lastUsedColorsHeight->setValue(16); ui->commonColorsShow->setChecked(true); ui->commonColorsAlignVertical->setChecked(false); ui->commonColorsAlignHorizontal->setChecked(true); ui->commonColorsAllowScrolling->setChecked(false); ui->commonColorsNumCols->setValue(1); ui->commonColorsNumRows->setValue(1); ui->commonColorsPatchCount->setValue(12); ui->commonColorsWidth->setValue(16); ui->commonColorsHeight->setValue(16); ui->commonColorsAutoUpdate->setChecked(false); //shade selector ui->ACSShadeSelectorTypeComboBox->setCurrentIndex(0); // MyPaint ui->ACSshadeSelectorMyPaintColorModelComboBox->setCurrentIndex(0); ui->shadeSelectorUpdateOnRightClick->setChecked(false); ui->shadeSelectorUpdateOnLeftClick->setChecked(false); ui->shadeSelectorUpdateOnForeground->setChecked(true); ui->shadeSelectorUpdateOnBackground->setChecked(true); bool asGradient = true; if(asGradient) ui->minimalShadeSelectorAsGradient->setChecked(true); else ui->minimalShadeSelectorAsColorPatches->setChecked(true); ui->minimalShadeSelectorPatchesPerLine->setValue(10); ui->minimalShadeSelectorLineSettings->fromString("0|0.2|0|0|0|0|0;1|0|1|1|0|0|0;2|0|-1|1|0|0|0;"); ui->minimalShadeSelectorLineHeight->setValue(10); // set advanced color selector to use HSV ui->colorSelectorTypeComboBox->setCurrentIndex(0); KisColorSelectorComboBox* cstw = dynamic_cast(ui->colorSelectorConfiguration); - cstw->setConfiguration(KisColorSelector::Configuration("3|0|5|0")); // triangle selector + cstw->setConfiguration(KisColorSelectorConfiguration("3|0|5|0")); // triangle selector //luma// ui->l_lumaR->setValue(0.2126); ui->l_lumaG->setValue(0.7152); ui->l_lumaB->setValue(0.0722); ui->SP_Gamma->setValue(2.2); //color sliders// ui->csl_hsvH->setChecked(false); ui->csl_hsvS->setChecked(false); ui->csl_hsvV->setChecked(false); ui->csl_hslH->setChecked(true); ui->csl_hslS->setChecked(true); ui->csl_hslL->setChecked(true); ui->csl_hsiH->setChecked(false); ui->csl_hsiS->setChecked(false); ui->csl_hsiI->setChecked(false); ui->csl_hsyH->setChecked(false); ui->csl_hsyS->setChecked(false); ui->csl_hsyY->setChecked(false); //hotkeys// ui->sb_lightness->setValue(10); ui->sb_saturation->setValue(10); ui->sb_hue->setValue(36); ui->sb_rg->setValue(10); ui->sb_by->setValue(10); } KisColorSelectorSettingsDialog::KisColorSelectorSettingsDialog(QWidget *parent) : QDialog(parent), m_widget(new KisColorSelectorSettings(this)) { QLayout* l = new QVBoxLayout(this); l->addWidget(m_widget); m_widget->loadPreferences(); QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults, Qt::Horizontal, this); l->addWidget(buttonBox); connect(buttonBox, SIGNAL(accepted()), m_widget, SLOT(savePreferences())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), m_widget, SLOT(loadDefaultPreferences())); } diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector_simple.cpp b/plugins/dockers/advancedcolorselector/kis_color_selector_simple.cpp index aebd1f2194..f9e1e1a5e0 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector_simple.cpp +++ b/plugins/dockers/advancedcolorselector/kis_color_selector_simple.cpp @@ -1,415 +1,415 @@ /* * Copyright (c) 2010 Adam Celarek * * 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 */ #include "kis_color_selector_simple.h" #include #include #include #include #include #include #include #include "kis_display_color_converter.h" #include "kis_acs_pixel_cache_renderer.h" KisColorSelectorSimple::KisColorSelectorSimple(KisColorSelector *parent) : KisColorSelectorComponent(parent), m_lastClickPos(-1,-1) { } KoColor KisColorSelectorSimple::selectColor(int x, int y) { m_lastClickPos.setX(x/qreal(width())); m_lastClickPos.setY(y/qreal(height())); qreal xRel = x/qreal(width()); qreal yRel = 1.-y/qreal(height()); qreal relPos; if(height()>width()) relPos = 1.-y/qreal(height()); else relPos = x/qreal(width()); switch (m_parameter) { - case KisColorSelector::H: + case KisColorSelectorConfiguration::H: emit paramChanged(relPos, -1, -1, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hsvS: + case KisColorSelectorConfiguration::hsvS: emit paramChanged(-1, relPos, -1, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hslS: + case KisColorSelectorConfiguration::hslS: emit paramChanged(-1, -1, -1, relPos, -1, -1, -1, -1, -1); break; - case KisColorSelector::hsiS: + case KisColorSelectorConfiguration::hsiS: emit paramChanged(-1, -1, -1, -1, -1, relPos, -1, -1, -1); break; - case KisColorSelector::hsyS: + case KisColorSelectorConfiguration::hsyS: emit paramChanged(-1, -1, -1, -1, -1, -1, -1, relPos, -1); - break; - case KisColorSelector::V: + break; + case KisColorSelectorConfiguration::V: emit paramChanged(-1, -1, relPos, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::L: + case KisColorSelectorConfiguration::L: emit paramChanged(-1, -1, -1, -1, relPos, -1, -1, -1, -1); break; - case KisColorSelector::I: + case KisColorSelectorConfiguration::I: emit paramChanged(-1, -1, -1, -1, -1, -1, relPos, -1, -1); break; - case KisColorSelector::Y: + case KisColorSelectorConfiguration::Y: emit paramChanged(-1, -1, -1, -1, -1, -1, -1, -1, relPos); break; - case KisColorSelector::SL: + case KisColorSelectorConfiguration::SL: emit paramChanged(-1, -1, -1, xRel, yRel, -1, -1, -1, -1); break; - case KisColorSelector::SI: + case KisColorSelectorConfiguration::SI: emit paramChanged(-1, -1, -1, -1, -1, xRel, yRel, -1, -1); break; - case KisColorSelector::SY: + case KisColorSelectorConfiguration::SY: emit paramChanged(-1, -1, -1, -1, -1, -1, -1, xRel, yRel); break; - case KisColorSelector::SV2: - case KisColorSelector::SV: + case KisColorSelectorConfiguration::SV2: + case KisColorSelectorConfiguration::SV: emit paramChanged(-1, xRel, yRel, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hsvSH: + case KisColorSelectorConfiguration::hsvSH: emit paramChanged(xRel, yRel, -1, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hslSH: + case KisColorSelectorConfiguration::hslSH: emit paramChanged(xRel, -1, -1, yRel, -1, -1, -1, -1, -1); break; - case KisColorSelector::hsiSH: + case KisColorSelectorConfiguration::hsiSH: emit paramChanged(xRel, -1, -1, -1, -1, yRel, -1, -1, -1); break; - case KisColorSelector::hsySH: + case KisColorSelectorConfiguration::hsySH: emit paramChanged(xRel, -1, -1, -1, -1, -1, -1, yRel, -1); break; - case KisColorSelector::VH: + case KisColorSelectorConfiguration::VH: emit paramChanged(xRel, -1, yRel, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::LH: + case KisColorSelectorConfiguration::LH: emit paramChanged(xRel, -1, -1, -1, yRel, -1, -1, -1, -1); break; - case KisColorSelector::IH: + case KisColorSelectorConfiguration::IH: emit paramChanged(xRel, -1, -1, -1, -1, -1, yRel, -1, -1); break; - case KisColorSelector::YH: + case KisColorSelectorConfiguration::YH: emit paramChanged(xRel, -1, -1, -1, -1, -1, -1, -1, yRel); break; } emit update(); return colorAt(x, y); } void KisColorSelectorSimple::setColor(const KoColor &color) { qreal hsvH, hsvS, hsvV; qreal hslH, hslS, hslL; - qreal hsiH, hsiS, hsiI; - qreal hsyH, hsyS, hsyY; + qreal hsiH, hsiS, hsiI; + qreal hsyH, hsyS, hsyY; KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); R = cfg.readEntry("lumaR", 0.2126); G = cfg.readEntry("lumaG", 0.7152); B = cfg.readEntry("lumaB", 0.0722); Gamma = cfg.readEntry("gamma", 2.2); m_parent->converter()->getHsvF(color, &hsvH, &hsvS, &hsvV); m_parent->converter()->getHslF(color, &hslH, &hslS, &hslL); //here we add our convertor options m_parent->converter()->getHsiF(color, &hsiH, &hsiS, &hsiI); m_parent->converter()->getHsyF(color, &hsyH, &hsyS, &hsyY, R, G, B, Gamma); - //workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly. - hsiH=hslH; - hsyH=hslH; + //workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly. + hsiH=hslH; + hsyH=hslH; switch (m_parameter) { - case KisColorSelector::SL: + case KisColorSelectorConfiguration::SL: m_lastClickPos.setX(hslS); m_lastClickPos.setY(1 - hslL); emit paramChanged(-1, -1, -1, hslS, hslL, -1, -1, -1, -1); break; - case KisColorSelector::SI: + case KisColorSelectorConfiguration::SI: m_lastClickPos.setX(hsiS); m_lastClickPos.setY(1 - hsiI); emit paramChanged(-1, -1, -1, -1, -1, hsiS, hsiI, -1, -1); break; - case KisColorSelector::SY: + case KisColorSelectorConfiguration::SY: m_lastClickPos.setX(hsyS); m_lastClickPos.setY(1 - hsyY); emit paramChanged(-1, -1, -1, -1, -1, -1, -1, hsyS, hsyY); break; - case KisColorSelector::LH: + case KisColorSelectorConfiguration::LH: m_lastClickPos.setX(qBound(0., hslH, 1.)); m_lastClickPos.setY(1 - hslL); emit paramChanged(hslH, -1, -1, -1, hslL, -1, -1, -1, -1); break; - case KisColorSelector::SV: + case KisColorSelectorConfiguration::SV: m_lastClickPos.setX(hsvS); m_lastClickPos.setY(1 - hsvV); emit paramChanged(-1, hsvS, hsvV, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::SV2: { + case KisColorSelectorConfiguration::SV2: { qreal xRel = hsvS; qreal yRel = 0.5; if(xRel != 1.0) yRel = 1.0 - qBound(0.0, (hsvV - xRel) / (1.0 - xRel), 1.0); m_lastClickPos.setX(xRel); m_lastClickPos.setY(yRel); emit paramChanged(-1, -1, -1, xRel, yRel, -1, -1, -1, -1); break; } - case KisColorSelector::VH: + case KisColorSelectorConfiguration::VH: m_lastClickPos.setX(qBound(0., hsvH, 1.)); m_lastClickPos.setY(1 - hsvV); emit paramChanged(hsvH, -1, hsvV, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::IH: + case KisColorSelectorConfiguration::IH: m_lastClickPos.setX(qBound(0., hsiH, 1.)); m_lastClickPos.setY(1 - hsiI); emit paramChanged(hsiH, -1, -1, -1, -1, -1, hsiI, -1, -1); break; - case KisColorSelector::YH: + case KisColorSelectorConfiguration::YH: m_lastClickPos.setX(qBound(0., hsyH, 1.)); m_lastClickPos.setY(1 - hsyY); emit paramChanged(hsyH, -1, -1, -1, -1, -1, -1, -1, hsyY); break; - case KisColorSelector::hsvSH: + case KisColorSelectorConfiguration::hsvSH: m_lastClickPos.setX(qBound(0., hsvH, 1.)); m_lastClickPos.setY(1 - hsvS); emit paramChanged(hsvH, hsvS, -1, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hslSH: + case KisColorSelectorConfiguration::hslSH: m_lastClickPos.setX(qBound(0., hslH, 1.)); m_lastClickPos.setY(1 - hslS); emit paramChanged(hslH, -1, -1, hslS, -1, -1, -1, -1, -1); break; - - case KisColorSelector::hsiSH: + + case KisColorSelectorConfiguration::hsiSH: m_lastClickPos.setX(qBound(0., hsiH, 1.)); m_lastClickPos.setY(1 - hsiS); emit paramChanged(hsiH, -1, -1, hsiS, -1, -1, -1, -1, -1); break; - - case KisColorSelector::hsySH: + + case KisColorSelectorConfiguration::hsySH: m_lastClickPos.setX(qBound(0., hsyH, 1.)); m_lastClickPos.setY(1 - hsyS); emit paramChanged(hsyH, -1, -1, hsyS, -1, -1, -1, -1, -1); break; - case KisColorSelector::L: + case KisColorSelectorConfiguration::L: m_lastClickPos.setX(qBound(0., hslL, 1.)); emit paramChanged(-1, -1, -1, -1, hslL, -1, -1, -1, -1); break; - case KisColorSelector::I: + case KisColorSelectorConfiguration::I: m_lastClickPos.setX(qBound(0., hsiI, 1.)); emit paramChanged(-1, -1, -1, -1, -1, -1, hsiI, -1, -1); break; - case KisColorSelector::V: + case KisColorSelectorConfiguration::V: m_lastClickPos.setX(hsvV); emit paramChanged(-1, -1, hsvV, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::Y: + case KisColorSelectorConfiguration::Y: m_lastClickPos.setX(qBound(0., hsyY, 1.)); emit paramChanged(-1, -1, -1, -1, -1, -1, -1, -1, hsyY); break; - case KisColorSelector::hsvS: + case KisColorSelectorConfiguration::hsvS: m_lastClickPos.setX( hsvS ); emit paramChanged(-1, hsvS, -1, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hslS: + case KisColorSelectorConfiguration::hslS: m_lastClickPos.setX( hslS ); emit paramChanged(-1, -1, -1, hslS, -1, -1, -1, -1, -1); break; - case KisColorSelector::hsiS: + case KisColorSelectorConfiguration::hsiS: m_lastClickPos.setX( hsiS ); emit paramChanged(-1, -1, -1, -1, -1, hsiS, -1, -1, -1); break; - case KisColorSelector::hsyS: + case KisColorSelectorConfiguration::hsyS: m_lastClickPos.setX( hsyS ); emit paramChanged(-1, -1, -1, -1, -1, -1, -1, hsyS, -1); break; - case KisColorSelector::H: + case KisColorSelectorConfiguration::H: m_lastClickPos.setX(qBound(0., hsvH, 1.)); emit paramChanged(hsvH, -1, -1, -1, -1, -1, -1, -1, -1); break; default: Q_ASSERT(false); break; } emit update(); //Workaround for bug 317648 setLastMousePosition((m_lastClickPos.x()*width()), (m_lastClickPos.y()*height())); } void KisColorSelectorSimple::paint(QPainter* painter) { if(isDirty()) { KisPaintDeviceSP realPixelCache; QPoint pixelCacheOffset; Acs::PixelCacheRenderer::render(this, m_parent->converter(), QRect(0, 0, width(), height()), realPixelCache, m_pixelCache, pixelCacheOffset); // if (!pixelCacheOffset.isNull()) { // warnKrita << "WARNING: offset of the rectangle selector is not null!"; // } } painter->drawImage(0,0, m_pixelCache); // draw blip if(m_lastClickPos!=QPointF(-1,-1) && m_parent->displayBlip()) { switch (m_parameter) { - case KisColorSelector::H: - case KisColorSelector::hsvS: - case KisColorSelector::hslS: - case KisColorSelector::hsiS: - case KisColorSelector::hsyS: - case KisColorSelector::V: - case KisColorSelector::L: - case KisColorSelector::I: - case KisColorSelector::Y: + case KisColorSelectorConfiguration::H: + case KisColorSelectorConfiguration::hsvS: + case KisColorSelectorConfiguration::hslS: + case KisColorSelectorConfiguration::hsiS: + case KisColorSelectorConfiguration::hsyS: + case KisColorSelectorConfiguration::V: + case KisColorSelectorConfiguration::L: + case KisColorSelectorConfiguration::I: + case KisColorSelectorConfiguration::Y: if(width()>height()) { painter->setPen(QColor(0,0,0)); painter->drawLine(m_lastClickPos.x()*width()-1, 0, m_lastClickPos.x()*width()-1, height()); painter->setPen(QColor(255,255,255)); painter->drawLine(m_lastClickPos.x()*width()+1, 0, m_lastClickPos.x()*width()+1, height()); } else { painter->setPen(QColor(0,0,0)); painter->drawLine(0, m_lastClickPos.x()*height()-1, width(), m_lastClickPos.x()*height()-1); painter->setPen(QColor(255,255,255)); painter->drawLine(0, m_lastClickPos.x()*height()+1, width(), m_lastClickPos.x()*height()+1); } break; - case KisColorSelector::SL: - case KisColorSelector::SV: - case KisColorSelector::SV2: - case KisColorSelector::SI: - case KisColorSelector::SY: - case KisColorSelector::hslSH: - case KisColorSelector::hsvSH: - case KisColorSelector::hsiSH: - case KisColorSelector::hsySH: - case KisColorSelector::VH: - case KisColorSelector::LH: - case KisColorSelector::IH: - case KisColorSelector::YH: + case KisColorSelectorConfiguration::SL: + case KisColorSelectorConfiguration::SV: + case KisColorSelectorConfiguration::SV2: + case KisColorSelectorConfiguration::SI: + case KisColorSelectorConfiguration::SY: + case KisColorSelectorConfiguration::hslSH: + case KisColorSelectorConfiguration::hsvSH: + case KisColorSelectorConfiguration::hsiSH: + case KisColorSelectorConfiguration::hsySH: + case KisColorSelectorConfiguration::VH: + case KisColorSelectorConfiguration::LH: + case KisColorSelectorConfiguration::IH: + case KisColorSelectorConfiguration::YH: painter->setPen(QColor(0,0,0)); painter->drawEllipse(m_lastClickPos.x()*width()-5, m_lastClickPos.y()*height()-5, 10, 10); painter->setPen(QColor(255,255,255)); painter->drawEllipse(m_lastClickPos.x()*width()-4, m_lastClickPos.y()*height()-4, 8, 8); break; } } } KoColor KisColorSelectorSimple::colorAt(int x, int y) { qreal xRel = x/qreal(width()); qreal yRel = 1.-y/qreal(height()); qreal relPos; if(height()>width()) relPos = 1.-y/qreal(height()); else relPos = x/qreal(width()); KoColor color(Qt::transparent, m_parent->colorSpace()); switch(m_parameter) { - case KisColorSelector::SL: + case KisColorSelectorConfiguration::SL: color = m_parent->converter()->fromHslF(m_hue, xRel, yRel); break; - case KisColorSelector::SV: + case KisColorSelectorConfiguration::SV: color = m_parent->converter()->fromHsvF(m_hue, xRel, yRel); break; - case KisColorSelector::SV2: + case KisColorSelectorConfiguration::SV2: color = m_parent->converter()->fromHsvF(m_hue, xRel, xRel + (1.0-xRel)*yRel); break; - case KisColorSelector::SI: + case KisColorSelectorConfiguration::SI: color = m_parent->converter()->fromHsiF(m_hue, xRel, yRel); break; - case KisColorSelector::SY: + case KisColorSelectorConfiguration::SY: color = m_parent->converter()->fromHsyF(m_hue, xRel, yRel, R, G, B, Gamma); break; - case KisColorSelector::hsvSH: + case KisColorSelectorConfiguration::hsvSH: color = m_parent->converter()->fromHsvF(xRel, yRel, m_value); break; - case KisColorSelector::hslSH: + case KisColorSelectorConfiguration::hslSH: color = m_parent->converter()->fromHslF(xRel, yRel, m_lightness); break; - case KisColorSelector::hsiSH: + case KisColorSelectorConfiguration::hsiSH: color = m_parent->converter()->fromHsiF(xRel, yRel, m_intensity); break; - case KisColorSelector::hsySH: + case KisColorSelectorConfiguration::hsySH: color = m_parent->converter()->fromHsyF(xRel, yRel, m_luma, R, G, B, Gamma); break; - case KisColorSelector::VH: + case KisColorSelectorConfiguration::VH: color = m_parent->converter()->fromHsvF(xRel, m_hsvSaturation, yRel); break; - case KisColorSelector::LH: + case KisColorSelectorConfiguration::LH: color = m_parent->converter()->fromHslF(xRel, m_hslSaturation, yRel); break; - case KisColorSelector::IH: + case KisColorSelectorConfiguration::IH: color = m_parent->converter()->fromHsiF(xRel, m_hsiSaturation, yRel); break; - case KisColorSelector::YH: + case KisColorSelectorConfiguration::YH: color = m_parent->converter()->fromHsyF(xRel, m_hsySaturation, yRel, R, G, B, Gamma); break; - case KisColorSelector::H: + case KisColorSelectorConfiguration::H: color = m_parent->converter()->fromHsvF(relPos, 1, 1); break; - case KisColorSelector::hsvS: + case KisColorSelectorConfiguration::hsvS: color = m_parent->converter()->fromHsvF(m_hue, relPos, m_value); break; - case KisColorSelector::hslS: + case KisColorSelectorConfiguration::hslS: color = m_parent->converter()->fromHslF(m_hue, relPos, m_lightness); break; - case KisColorSelector::V: + case KisColorSelectorConfiguration::V: color = m_parent->converter()->fromHsvF(m_hue, m_hsvSaturation, relPos); break; - case KisColorSelector::L: + case KisColorSelectorConfiguration::L: color = m_parent->converter()->fromHslF(m_hue, m_hslSaturation, relPos); break; - case KisColorSelector::hsiS: + case KisColorSelectorConfiguration::hsiS: color = m_parent->converter()->fromHsiF(m_hue, relPos, m_intensity); - break; - case KisColorSelector::I: + break; + case KisColorSelectorConfiguration::I: color = m_parent->converter()->fromHsiF(m_hue, m_hsiSaturation, relPos); break; - case KisColorSelector::hsyS: + case KisColorSelectorConfiguration::hsyS: color = m_parent->converter()->fromHsyF(m_hue, relPos, m_luma, R, G, B, Gamma); - break; - case KisColorSelector::Y: + break; + case KisColorSelectorConfiguration::Y: color = m_parent->converter()->fromHsyF(m_hue, m_hsySaturation, relPos, R, G, B, Gamma); break; default: Q_ASSERT(false); return color; } return color; } diff --git a/plugins/dockers/advancedcolorselector/kis_color_selector_wheel.cpp b/plugins/dockers/advancedcolorselector/kis_color_selector_wheel.cpp index 5866b87088..5be47466d6 100644 --- a/plugins/dockers/advancedcolorselector/kis_color_selector_wheel.cpp +++ b/plugins/dockers/advancedcolorselector/kis_color_selector_wheel.cpp @@ -1,268 +1,268 @@ /* * Copyright (c) 2010 Adam Celarek * * 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 */ #include "kis_color_selector_wheel.h" #include #include #include #include #include #include #include #include "kis_display_color_converter.h" #include "kis_acs_pixel_cache_renderer.h" KisColorSelectorWheel::KisColorSelectorWheel(KisColorSelector *parent) : KisColorSelectorComponent(parent), m_lastClickPos(-1,-1) { } KoColor KisColorSelectorWheel::selectColor(int x, int y) { int xWheel = x-width()/2; int yWheel = y-height()/2; qreal radius = sqrt((double)xWheel*xWheel+yWheel*yWheel); radius/=qMin(width(), height()); if(radius>0.5) radius=0.5; radius*=2.; qreal angle = std::atan2((qreal)yWheel, (qreal)xWheel); angle+=M_PI; angle/=2*M_PI; switch (m_parameter) { - case KisColorSelector::hsvSH: + case KisColorSelectorConfiguration::hsvSH: emit paramChanged(angle, radius, -1, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::hslSH: + case KisColorSelectorConfiguration::hslSH: emit paramChanged(angle, -1, -1, radius, -1, -1, -1, -1, -1); break; - case KisColorSelector::hsiSH: + case KisColorSelectorConfiguration::hsiSH: emit paramChanged(angle, -1, -1, -1, -1, radius, -1, -1, -1); break; - case KisColorSelector::hsySH: + case KisColorSelectorConfiguration::hsySH: emit paramChanged(angle, -1, -1, -1, -1, -1, -1, radius, -1); break; - case KisColorSelector::VH: + case KisColorSelectorConfiguration::VH: emit paramChanged(angle, -1, radius, -1, -1, -1, -1, -1, -1); break; - case KisColorSelector::LH: + case KisColorSelectorConfiguration::LH: emit paramChanged(angle, -1, -1, -1, radius, -1, -1, -1, -1); break; - case KisColorSelector::IH: + case KisColorSelectorConfiguration::IH: emit paramChanged(angle, -1, -1, -1, -1, -1, radius, -1, -1); break; - case KisColorSelector::YH: + case KisColorSelectorConfiguration::YH: emit paramChanged(angle, -1, -1, -1, -1, -1, -1, -1, radius); break; default: Q_ASSERT(false); break; } emit update(); angle *= 2. * M_PI; angle -= M_PI; radius*=0.5; m_lastClickPos.setX(cos(angle)*radius+0.5); m_lastClickPos.setY(sin(angle)*radius+0.5); return colorAt(x, y, true); } void KisColorSelectorWheel::setColor(const KoColor &color) { qreal hsvH, hsvS, hsvV; qreal hslH, hslS, hslL; - qreal hsiH, hsiS, hsiI; - qreal hsyH, hsyS, hsyY; - KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); - R = cfg.readEntry("lumaR", 0.2126); + qreal hsiH, hsiS, hsiI; + qreal hsyH, hsyS, hsyY; + KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector"); + R = cfg.readEntry("lumaR", 0.2126); G = cfg.readEntry("lumaG", 0.7152); B = cfg.readEntry("lumaB", 0.0722); Gamma = cfg.readEntry("gamma", 2.2); m_parent->converter()->getHsvF(color, &hsvH, &hsvS, &hsvV); m_parent->converter()->getHslF(color, &hslH, &hslS, &hslL); m_parent->converter()->getHsiF(color, &hsiH, &hsiS, &hsiI); m_parent->converter()->getHsyF(color, &hsyH, &hsyS, &hsyY, R, G, B, Gamma); - //workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly. - hsiH=hslH; - hsyH=hslH; + //workaround, for some reason the HSI and HSY algorithms are fine, but they don't seem to update the selectors properly. + hsiH=hslH; + hsyH=hslH; qreal angle = 0.0, radius = 0.0; angle = hsvH; angle *= 2. * M_PI; angle -= M_PI; switch (m_parameter) { - case KisColorSelector::LH: + case KisColorSelectorConfiguration::LH: emit paramChanged(hslH, -1, -1, -1, hslL, -1, -1, -1, -1); radius = hslL; break; - case KisColorSelector::VH: + case KisColorSelectorConfiguration::VH: emit paramChanged(hsvH, -1, hsvV, -1, -1, -1, -1, -1, -1); radius = hsvV; break; - case KisColorSelector::IH: + case KisColorSelectorConfiguration::IH: emit paramChanged(hslH, -1, -1, -1, -1, -1, hsiI, -1, -1); radius = hsiI; break; - case KisColorSelector::YH: + case KisColorSelectorConfiguration::YH: emit paramChanged(hsvH, -1, -1, -1, -1, -1, -1, -1, hsyY); radius = hsyY; break; - case KisColorSelector::hsvSH: + case KisColorSelectorConfiguration::hsvSH: emit paramChanged(hsvH, hsvS, -1, -1, -1, -1, -1, -1, -1); radius = hsvS; break; - case KisColorSelector::hslSH: + case KisColorSelectorConfiguration::hslSH: emit paramChanged(hslH, -1, -1, hslS, -1, -1, -1, -1, -1); radius = hslS; break; - case KisColorSelector::hsiSH: + case KisColorSelectorConfiguration::hsiSH: emit paramChanged(hsiH, -1, -1, -1, -1, hsiS, -1, -1, -1); radius = hsiS; break; - case KisColorSelector::hsySH: + case KisColorSelectorConfiguration::hsySH: emit paramChanged(hsyH, -1, -1, -1, -1, -1, -1, hsyS, -1); radius = hsyS; break; default: Q_ASSERT(false); break; } radius *= 0.5; m_lastClickPos.setX(cos(angle)*radius+0.5); m_lastClickPos.setY(sin(angle)*radius+0.5); //workaround for bug 279500 if(m_lastClickPos!=QPoint(-1,-1) && m_parent->displayBlip()) { QPoint pos = (m_lastClickPos*qMin(width(), height())).toPoint(); if(width() < height()) { pos.setY(pos.y()+height()/2-width()/2); } else { pos.setX(pos.x()+width()/2-height()/2); } setLastMousePosition(pos.x(), pos.y()); } } void KisColorSelectorWheel::paint(QPainter* painter) { if(isDirty()) { KisPaintDeviceSP realPixelCache; Acs::PixelCacheRenderer::render(this, m_parent->converter(), QRect(0, 0, width(), height()), realPixelCache, m_pixelCache, m_pixelCacheOffset); //antialiasing for wheel QPainter tmpPainter(&m_pixelCache); tmpPainter.setRenderHint(QPainter::Antialiasing); tmpPainter.setPen(QPen(QColor(0,0,0,0), 2.5)); tmpPainter.setCompositionMode(QPainter::CompositionMode_Clear); int size=qMin(width(), height()); QPoint ellipseCenter(width() / 2 - size / 2, height() / 2 - size / 2); ellipseCenter -= m_pixelCacheOffset; tmpPainter.drawEllipse(ellipseCenter.x(), ellipseCenter.y(), size, size); } painter->drawImage(m_pixelCacheOffset.x(),m_pixelCacheOffset.y(), m_pixelCache); // draw blips - + if(m_lastClickPos!=QPoint(-1,-1) && m_parent->displayBlip()) { QPoint pos = (m_lastClickPos*qMin(width(), height())).toPoint(); if(width()setPen(QColor(0,0,0)); painter->drawEllipse(pos, 5, 5); painter->setPen(QColor(255,255,255)); painter->drawEllipse(pos, 4, 4); } } KoColor KisColorSelectorWheel::colorAt(int x, int y, bool forceValid) { KoColor color(Qt::transparent, m_parent->colorSpace()); Q_ASSERT(x>=0 && x<=width()); Q_ASSERT(y>=0 && y<=height()); qreal xRel = x-width()/2.; qreal yRel = y-height()/2.; qreal radius = sqrt(xRel*xRel+yRel*yRel); if(radius > qMin(width(), height())/2) { if (!forceValid) { return color; } else { radius = qMin(width(), height())/2; } } radius /= qMin(width(), height())/2.; qreal angle = std::atan2(yRel, xRel); angle += M_PI; angle /= 2 * M_PI; switch(m_parameter) { - case KisColorSelector::hsvSH: + case KisColorSelectorConfiguration::hsvSH: color = m_parent->converter()->fromHsvF(angle, radius, m_value); break; - case KisColorSelector::hslSH: + case KisColorSelectorConfiguration::hslSH: color = m_parent->converter()->fromHslF(angle, radius, m_lightness); break; - case KisColorSelector::hsiSH: + case KisColorSelectorConfiguration::hsiSH: color = m_parent->converter()->fromHsiF(angle, radius, m_intensity); break; - case KisColorSelector::hsySH: + case KisColorSelectorConfiguration::hsySH: color = m_parent->converter()->fromHsyF(angle, radius, m_luma, R, G, B, Gamma); break; - case KisColorSelector::VH: + case KisColorSelectorConfiguration::VH: color = m_parent->converter()->fromHsvF(angle, m_hsvSaturation, radius); break; - case KisColorSelector::LH: + case KisColorSelectorConfiguration::LH: color = m_parent->converter()->fromHslF(angle, m_hslSaturation, radius); break; - case KisColorSelector::IH: + case KisColorSelectorConfiguration::IH: color = m_parent->converter()->fromHsiF(angle, m_hsiSaturation, radius); break; - case KisColorSelector::YH: + case KisColorSelectorConfiguration::YH: color = m_parent->converter()->fromHsyF(angle, m_hsySaturation, radius, R, G, B, Gamma); break; default: Q_ASSERT(false); return color; } return color; }