kis_visual_color_selector.cpp 49.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (C) Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com>, (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 <QColor>
#include <QPixmap>
#include <QPainter>
#include <QPainterPath>
24
#include <QRect>
25 26 27
#include <QVector>
#include <QVBoxLayout>
#include <QList>
28 29
#include <QPolygon>
#include <QRect>
30
#include <QtMath>
31 32

#include "KoColorConversions.h"
33
#include "KoColorDisplayRendererInterface.h"
34
#include "KoChannelInfo.h"
35
#include <KoColorModelStandardIds.h>
36
#include <QPointer>
37
#include "kis_signal_compressor.h"
38 39 40 41 42 43

struct KisVisualColorSelector::Private
{
    KoColor currentcolor;
    const KoColorSpace *currentCS;
    QList <KisVisualColorSelectorShape*> widgetlist;
44
    bool updateSelf = false;
45
    const KoColorDisplayRendererInterface *displayRenderer = 0;
46 47 48 49 50 51
    //Current coordinates.
    QVector <float> currentCoordinates;
};

KisVisualColorSelector::KisVisualColorSelector(QWidget *parent) : QWidget(parent), m_d(new Private)
{
52
    this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
53 54
    QVBoxLayout *layout = new QVBoxLayout;
    this->setLayout(layout);
55
    //m_d->updateSelf = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this);
56 57 58 59 60 61 62 63 64
}

KisVisualColorSelector::~KisVisualColorSelector()
{

}

void KisVisualColorSelector::slotSetColor(KoColor c)
{
65 66 67 68 69
    if (m_d->updateSelf==false) {
        m_d->currentcolor = c;
        if (m_d->currentCS != c.colorSpace()) {
            slotsetColorSpace(c.colorSpace());
        }
70 71 72 73 74 75 76 77 78
    }
    updateSelectorElements();
}

void KisVisualColorSelector::slotsetColorSpace(const KoColorSpace *cs)
{
    if (m_d->currentCS != cs)
    {
        m_d->currentCS = cs;
79
        if (this->children().at(0)) {
80 81 82
            qDeleteAll(this->children());
        }
        m_d->widgetlist.clear();
83
        QLayout *layout = new QHBoxLayout;
84 85 86 87 88 89 90 91 92
        //redraw all the widgets.
        if (m_d->currentCS->colorChannelCount() == 1) {
            KisVisualRectangleSelectorShape *bar =  new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::onedimensional,KisVisualColorSelectorShape::Channel, cs, 0, 0);
            bar->setMaximumWidth(width()*0.1);
            bar->setMaximumHeight(height());
            connect (bar, SIGNAL(sigNewColor(KoColor)), this, SLOT(updateFromWidgets(KoColor)));
            layout->addWidget(bar);
            m_d->widgetlist.append(bar);
        } else if (m_d->currentCS->colorChannelCount() == 3) {
93
            /*KisVisualRectangleSelectorShape *bar =  new KisVisualRectangleSelectorShape(this,
94
                                                                                        KisVisualRectangleSelectorShape::onedimensional,
95 96
                                                                                        KisVisualColorSelectorShape::HSL,
                                                                                        cs, 0, 0,
Wolthera van Hövell's avatar
Wolthera van Hövell committed
97
                                                                                        m_d->displayRenderer, width()*0.05,KisVisualRectangleSelectorShape::borderMirrored);
98
            KisVisualRectangleSelectorShape *block =  new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,
99 100
                                                                                          KisVisualColorSelectorShape::HSL,
                                                                                          cs, 1, 2,
101 102 103 104 105 106 107
                                                                                          m_d->displayRenderer);*/
            int sizeValue = qMin(width(), height());
            int borderWidth = qMax(sizeValue*0.1, 20.0);
            KisVisualEllipticalSelectorShape *bar =  new KisVisualEllipticalSelectorShape(this,
                                                                                        KisVisualColorSelectorShape::onedimensional,
                                                                                        KisVisualColorSelectorShape::HSV,
                                                                                        cs, 0, 0,
108
                                                                                        m_d->displayRenderer, borderWidth,KisVisualEllipticalSelectorShape::borderMirrored);
109 110 111
            KisVisualTriangleSelectorShape *block =  new KisVisualTriangleSelectorShape(this, KisVisualColorSelectorShape::twodimensional,
                                                                                          KisVisualColorSelectorShape::HSV,
                                                                                          cs, 1, 2,
112
                                                                                          m_d->displayRenderer);
113 114 115 116 117 118
            bar->resize(sizeValue, sizeValue);
            QLineF barInnerRadius(bar->geometry().center(), QPointF(bar->geometry().right()-borderWidth, bar->geometry().center().y()));
            QRect geom = block->setGeometryByRadius(barInnerRadius);
            block->setGeometry(geom);
            block->setTriangle();
            //There's a really weird bug where touching the geometry makes the widget hide itself??? This didn't happen with layouts so, I am confused.//
119 120
            //block->show();
            //bar->show();
121 122 123
            bar->setColor(m_d->currentcolor);
            block->setColor(m_d->currentcolor);
            connect (bar, SIGNAL(sigNewColor(KoColor)), block, SLOT(setColorFromSibling(KoColor)));
124 125 126
            connect (block, SIGNAL(sigNewColor(KoColor)), SLOT(updateFromWidgets(KoColor)));
            m_d->widgetlist.append(bar);
            m_d->widgetlist.append(block);
127
            this->adjustSize();
128 129 130 131 132 133 134
        } else if (m_d->currentCS->colorChannelCount() == 4) {
            KisVisualRectangleSelectorShape *block =  new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,KisVisualColorSelectorShape::Channel, cs, 0, 1);
            KisVisualRectangleSelectorShape *block2 =  new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,KisVisualColorSelectorShape::Channel, cs, 2, 3);
            block->setMaximumWidth(width()*0.5);
            block->setMaximumHeight(height());
            block2->setMaximumWidth(width()*0.5);
            block2->setMaximumHeight(height());
135 136 137
            block->setColor(m_d->currentcolor);
            block2->setColor(m_d->currentcolor);
            connect (block, SIGNAL(sigNewColor(KoColor)), block2, SLOT(setColorFromSibling(KoColor)));
138 139 140 141 142 143 144 145 146 147 148
            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);
    }

}

149

150
void KisVisualColorSelector::setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer) {
151 152 153 154 155 156 157 158
    m_d->displayRenderer = displayRenderer;
    if (m_d->widgetlist.size()>0) {
        Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) {
            shape->setDisplayRenderer(displayRenderer);
        }
    }
}

159 160 161 162 163 164 165 166
void KisVisualColorSelector::updateSelectorElements()
{
    //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) {
167 168 169 170 171
        if (m_d->updateSelf==false) {
            shape->setColor(m_d->currentcolor);
        } else {
            shape->setColorFromSibling(m_d->currentcolor);
        }
172 173 174 175 176 177 178 179 180 181 182
    }
    Q_FOREACH (KisVisualColorSelectorShape *shape, m_d->widgetlist) {
        shape->blockSignals(false);
    }

}

void KisVisualColorSelector::updateFromWidgets(KoColor c)
{
    m_d->currentcolor = c;
    Q_EMIT sigNewColor(c);
183 184 185 186 187 188
    m_d->updateSelf = true;
}

void KisVisualColorSelector::leaveEvent(QEvent *)
{
    m_d->updateSelf = false;
189 190 191 192 193
}

/*------------Selector shape------------*/
struct KisVisualColorSelectorShape::Private
{
194 195 196
    QImage gradient;
    QImage fullSelector;
    bool imagesNeedUpdate= true;
197 198 199 200 201 202 203
    QPointF currentCoordinates;
    Dimensions dimension;
    ColorModel model;
    const KoColorSpace *cs;
    KoColor currentColor;
    int channel1;
    int channel2;
204
    KisSignalCompressor *updateTimer;
205
    KisSignalCompressor *siblingTimer;
206
    bool mousePressActive = false;
207
    const KoColorDisplayRendererInterface *displayRenderer = 0;
208 209 210
    qreal hue = 0.0;
    qreal sat = 0.0;

211 212 213 214 215 216 217
};

KisVisualColorSelectorShape::KisVisualColorSelectorShape(QWidget *parent,
                                                         KisVisualColorSelectorShape::Dimensions dimension,
                                                         KisVisualColorSelectorShape::ColorModel model,
                                                         const KoColorSpace *cs,
                                                         int channel1,
218
                                                         int channel2,
219
                                                         const KoColorDisplayRendererInterface *displayRenderer): QWidget(parent), m_d(new Private)
220 221 222 223 224 225 226 227 228 229 230
{
    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);
231 232
    m_d->updateTimer = new KisSignalCompressor(30 /* ms */, KisSignalCompressor::POSTPONE, this);
    m_d->siblingTimer = new KisSignalCompressor(30 /* ms */, KisSignalCompressor::POSTPONE, this);
233
    setDisplayRenderer(displayRenderer);
234
    show();
235

236 237 238 239 240 241 242
}

KisVisualColorSelectorShape::~KisVisualColorSelectorShape()
{

}

243 244
void KisVisualColorSelectorShape::updateCursor()
{
245 246 247 248
    QPointF point1 = convertKoColorToShapeCoordinate(m_d->currentColor);
    if (point1 != m_d->currentCoordinates) {
        m_d->currentCoordinates = point1;
    }
249 250 251 252
}

QPointF KisVisualColorSelectorShape::getCursorPosition() {
    return m_d->currentCoordinates;
253 254 255 256 257 258 259 260
}

void KisVisualColorSelectorShape::setColor(KoColor c)
{
    if (c.colorSpace() != m_d->cs) {
        c.convertTo(m_d->cs);
    }
    m_d->currentColor = c;
261
    updateCursor();
262
    convertShapeCoordinateToKoColor(getCursorPosition(), true);
263
    m_d->imagesNeedUpdate = true;
264 265 266 267 268 269 270 271 272 273
    update();
}

void KisVisualColorSelectorShape::setColorFromSibling(KoColor c)
{
    if (c.colorSpace() != m_d->cs) {
        c.convertTo(m_d->cs);
    }
    m_d->currentColor = c;
    Q_EMIT sigNewColor(c);
274
    m_d->imagesNeedUpdate = true;
275 276 277
    update();
}

278 279 280 281 282 283 284 285 286 287
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();
    }
288 289
    connect(m_d->displayRenderer, SIGNAL(displayConfigurationChanged()),
            SLOT(updateFromChangedDisplayRenderer()), Qt::UniqueConnection);
290

291 292
}

293 294
void KisVisualColorSelectorShape::updateFromChangedDisplayRenderer()
{
295
    m_d->imagesNeedUpdate = true;
296
    updateCursor();
297
    //m_d->currentColor = convertShapeCoordinateToKoColor(getCursorPosition());
298
    update();
299 300
}

301 302
QColor KisVisualColorSelectorShape::getColorFromConverter(KoColor c){
    QColor col;
303
    if (m_d->displayRenderer && m_d->displayRenderer->getPaintingColorSpace()==m_d->cs) {
304 305 306 307 308 309 310
        col = m_d->displayRenderer->toQColor(c);
    } else {
        col = c.toQColor();
    }
    return col;
}

311 312 313 314 315
void KisVisualColorSelectorShape::slotSetActiveChannels(int channel1, int channel2)
{
    int maxchannel = m_d->cs->colorChannelCount()-1;
    m_d->channel1 = qBound(0, channel1, maxchannel);
    m_d->channel2 = qBound(0, channel2, maxchannel);
316
    m_d->imagesNeedUpdate = true;
317 318 319
    update();
}

320
QImage KisVisualColorSelectorShape::getImageMap()
321
{
322 323 324
    if (m_d->imagesNeedUpdate == true) {
        m_d->imagesNeedUpdate = false;
        m_d->gradient = QImage(width(), height(), QImage::Format_ARGB32);
325
        m_d->gradient.fill(Qt::transparent);
326 327
        QImage img(width(), height(), QImage::Format_ARGB32);
        img.fill(Qt::transparent);
328
        for (int y = 0; y<img.height(); y++) {
329 330
            uint* data = reinterpret_cast<uint*>(img.scanLine(y));
            for (int x=0; x<img.width(); x++,  ++data) {
331 332 333
                QPoint widgetPoint(x,y);
                QPointF newcoordinate = convertWidgetCoordinateToShapeCoordinate(widgetPoint);
                KoColor c = convertShapeCoordinateToKoColor(newcoordinate);
334
                QColor col = getColorFromConverter(c);
335
                *data = col.rgba();
336 337 338
            }
        }

339
        m_d->gradient = img;
340 341 342 343
    }
    return m_d->gradient;
}

344
KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coordinates, bool cursor)
345 346 347 348
{
    KoColor c = m_d->currentColor;
    QVector <float> channelValues (c.colorSpace()->channelCount());
    channelValues.fill(1.0);
349
    c.colorSpace()->normalisedChannelsValue(c.data(), channelValues);
350
    QVector <float> channelValuesDisplay = channelValues;
351 352
    QVector <qreal> maxvalue(c.colorSpace()->channelCount());
    maxvalue.fill(1.0);
353 354
    if (m_d->displayRenderer
            && m_d->displayRenderer->getPaintingColorSpace()==m_d->cs
355 356 357 358 359
            && 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) {
360
        for (int ch = 0; ch<maxvalue.size(); ch++) {
361 362
            KoChannelInfo *channel = m_d->cs->channels()[ch];
            maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel);
363
            channelValues[ch] = channelValues[ch]/(maxvalue[ch]);
364
            channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(ch, m_d->cs->channels())] = qBound((float)0.0,channelValues[ch], (float)1.0);
365 366 367
        }
    } else {
        for (int i =0; i<channelValues.size();i++) {
368
            channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels())] = qBound((float)0.0,channelValues[i], (float)1.0);
369 370
        }
    }
Wolthera van Hövell's avatar
Wolthera van Hövell committed
371 372
    qreal huedivider = 1.0;
    qreal huedivider2 = 1.0;
373

Wolthera van Hövell's avatar
Wolthera van Hövell committed
374 375 376 377 378 379
    if (m_d->channel1==0) {
        huedivider = 360.0;
    }
    if (m_d->channel2==0) {
        huedivider2 = 360.0;
    }
Wolthera van Hövell's avatar
Wolthera van Hövell committed
380
    if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") {
381 382
        if (c.colorSpace()->colorModelId().id() == "RGBA") {
            if (m_d->model == ColorModel::HSV){
Wolthera van Hövell's avatar
Wolthera van Hövell committed
383 384 385 386 387
                /*
                 * 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.
                 */
388
                QVector <float> inbetween(3);
389
                RGBToHSV(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
390
                inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
Wolthera van Hövell's avatar
Wolthera van Hövell committed
391
                inbetween[m_d->channel1] = coordinates.x()*huedivider;
392
                if (m_d->dimension == Dimensions::twodimensional) {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
393
                    inbetween[m_d->channel2] = coordinates.y()*huedivider2;
394
                }
395
                if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));}
396
                HSVToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2], &channelValuesDisplay[0], &channelValuesDisplay[1], &channelValuesDisplay[2]);
397
            } else if (m_d->model == ColorModel::HSL) {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
398 399 400 401
                /*
                 * 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.
                 */
402
                QVector <float> inbetween(3);
403
                RGBToHSL(channelValuesDisplay[1],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
404
                inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
Wolthera van Hövell's avatar
Wolthera van Hövell committed
405
                inbetween[m_d->channel1] = coordinates.x()*huedivider;
406
                if (m_d->dimension == Dimensions::twodimensional) {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
407
                    inbetween[m_d->channel2] = coordinates.y()*huedivider2;
408
                }
409
                if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));}
410
                HSLToRGB(inbetween[0], inbetween[1], inbetween[2],&channelValuesDisplay[0],&channelValuesDisplay[1], &channelValuesDisplay[2]);
411
            } else if (m_d->model == ColorModel::HSI) {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
412 413 414
                /*
                 * HSI is a modified HSY function.
                 */
415
                QVector <qreal> chan2 = convertvectorfloatToqreal(channelValuesDisplay);
416
                QVector <qreal> inbetween(3);
417
                RGBToHSI(chan2[0],chan2[1], chan2[2], &inbetween[0], &inbetween[1], &inbetween[2]);
418
                inbetween = getHSX(inbetween);
419 420 421 422
                inbetween[m_d->channel1] = coordinates.x();
                if (m_d->dimension == Dimensions::twodimensional) {
                    inbetween[m_d->channel2] = coordinates.y();
                }
423
                if (cursor==true){setHSX(inbetween);}
424 425
                HSIToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[0],&chan2[1], &chan2[2]);
                channelValuesDisplay = convertvectorqrealTofloat(chan2);
426
            } else /*if (m_d->model == ColorModel::HSY)*/ {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
427 428 429 430 431
                /*
                 * 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.
                 */
432
                QVector <qreal> luma= m_d->cs->lumaCoefficients();
433
                QVector <qreal> chan2 = convertvectorfloatToqreal(channelValuesDisplay);
434
                QVector <qreal> inbetween(3);
435
                RGBToHSY(chan2[0],chan2[1], chan2[2], &inbetween[0], &inbetween[1], &inbetween[2],
436
                        luma[0], luma[1], luma[2]);
437
                inbetween = getHSX(inbetween);
438 439 440 441
                inbetween[m_d->channel1] = coordinates.x();
                if (m_d->dimension == Dimensions::twodimensional) {
                    inbetween[m_d->channel2] = coordinates.y();
                }
442
                if (cursor==true){setHSX(inbetween);}
443
                HSYToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[0],&chan2[1], &chan2[1],
444
                        luma[0], luma[1], luma[2]);
445
                channelValuesDisplay = convertvectorqrealTofloat(chan2);
446 447
            }
        }
Wolthera van Hövell's avatar
Wolthera van Hövell committed
448
    } else {
449
        channelValuesDisplay[m_d->channel1] = coordinates.x();
Wolthera van Hövell's avatar
Wolthera van Hövell committed
450
        if (m_d->dimension == Dimensions::twodimensional) {
451
            channelValuesDisplay[m_d->channel2] = coordinates.y();
Wolthera van Hövell's avatar
Wolthera van Hövell committed
452
        }
453
    }
454
    for (int i=0; i<channelValues.size();i++) {
455
        channelValues[i] = qBound(0.0,channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels())]*(maxvalue[i]),1.0);
456
    }
457 458 459 460 461 462 463 464 465 466 467 468
    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 <float> channelValues (m_d->currentColor.colorSpace()->channelCount());
    channelValues.fill(1.0);
    m_d->cs->normalisedChannelsValue(c.data(), channelValues);
469
    QVector <float> channelValuesDisplay = channelValues;
470 471
    QVector <qreal> maxvalue(c.colorSpace()->channelCount());
    maxvalue.fill(1.0);
472 473
    if (m_d->displayRenderer
            && m_d->displayRenderer->getPaintingColorSpace()==m_d->cs
474 475 476 477 478
            && 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) {
479
        for (int ch = 0; ch<maxvalue.size(); ch++) {
480 481
            KoChannelInfo *channel = m_d->cs->channels()[ch];
            maxvalue[ch] = m_d->displayRenderer->maxVisibleFloatValue(channel);
482
            channelValues[ch] = channelValues[ch]/(maxvalue[ch]);
483
            channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(ch, m_d->cs->channels())] = qBound((float)0.0,channelValues[ch], (float)1.0);
484 485 486
        }
    } else {
        for (int i =0; i<channelValues.size();i++) {
487
            channelValuesDisplay[KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels())] = qBound((float)0.0,channelValues[i], (float)1.0);
488 489
        }
    }
490
    QPointF coordinates(0.0,0.0);
Wolthera van Hövell's avatar
Wolthera van Hövell committed
491 492 493 494 495 496 497 498
    qreal huedivider = 1.0;
    qreal huedivider2 = 1.0;
    if (m_d->channel1==0) {
        huedivider = 360.0;
    }
    if (m_d->channel2==0) {
        huedivider2 = 360.0;
    }
Wolthera van Hövell's avatar
Wolthera van Hövell committed
499
    if (m_d->model != ColorModel::Channel && c.colorSpace()->colorModelId().id() == "RGBA") {
500 501
        if (c.colorSpace()->colorModelId().id() == "RGBA") {
            if (m_d->model == ColorModel::HSV){
502
                QVector <float> inbetween(3);
503
                RGBToHSV(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
504
                inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
Wolthera van Hövell's avatar
Wolthera van Hövell committed
505
                coordinates.setX(inbetween[m_d->channel1]/huedivider);
506
                if (m_d->dimension == Dimensions::twodimensional) {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
507
                    coordinates.setY(inbetween[m_d->channel2]/huedivider2);
508
                }
509 510
            } else if (m_d->model == ColorModel::HSL) {
                QVector <float> inbetween(3);
511
                RGBToHSL(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
512
                inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
Wolthera van Hövell's avatar
Wolthera van Hövell committed
513
                coordinates.setX(inbetween[m_d->channel1]/huedivider);
514
                if (m_d->dimension == Dimensions::twodimensional) {
Wolthera van Hövell's avatar
Wolthera van Hövell committed
515
                    coordinates.setY(inbetween[m_d->channel2]/huedivider2);
516
                }
517
            } else if (m_d->model == ColorModel::HSI) {
518
                QVector <qreal> chan2 = convertvectorfloatToqreal(channelValuesDisplay);
519
                QVector <qreal> inbetween(3);
520
                RGBToHSI(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2]);
521
                inbetween = getHSX(inbetween);
522 523 524 525 526 527
                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 <qreal> luma = m_d->cs->lumaCoefficients();
528
                QVector <qreal> chan2 = convertvectorfloatToqreal(channelValuesDisplay);
529
                QVector <qreal> inbetween(3);
530
                RGBToHSY(channelValuesDisplay[0],channelValuesDisplay[1], channelValuesDisplay[2], &inbetween[0], &inbetween[1], &inbetween[2], luma[0], luma[1], luma[2]);
531
                inbetween = getHSX(inbetween);
532 533 534 535
                coordinates.setX(inbetween[m_d->channel1]);
                if (m_d->dimension == Dimensions::twodimensional) {
                    coordinates.setY(inbetween[m_d->channel2]);
                }
536 537
            }
        }
Wolthera van Hövell's avatar
Wolthera van Hövell committed
538
    } else {
539
        coordinates.setX(channelValuesDisplay[m_d->channel1]);
Wolthera van Hövell's avatar
Wolthera van Hövell committed
540
        if (m_d->dimension == Dimensions::twodimensional) {
541
            coordinates.setY(channelValuesDisplay[m_d->channel2]);
Wolthera van Hövell's avatar
Wolthera van Hövell committed
542
        }
543 544 545 546
    }
    return coordinates;
}

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
QVector<float> KisVisualColorSelectorShape::convertvectorqrealTofloat(QVector<qreal> real)
{
    QVector <float> vloat(real.size());
    for (int i=0; i<real.size(); i++) {
        vloat[i] = real[i];
    }
    return vloat;
}

QVector<qreal> KisVisualColorSelectorShape::convertvectorfloatToqreal(QVector <float> vloat)
{
    QVector <qreal> real(vloat.size());
    for (int i=0; i<vloat.size(); i++) {
        real[i] = vloat[i];
    }
    return real;
}

565 566
void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e)
{
567
    m_d->mousePressActive = true;
568 569 570 571 572
    QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos());
    KoColor col = convertShapeCoordinateToKoColor(coordinates);
    setColor(col);
    Q_EMIT sigNewColor(col);
    m_d->updateTimer->start();
573
}
574 575

void KisVisualColorSelectorShape::mouseMoveEvent(QMouseEvent *e)
576
{
577 578 579 580 581 582 583 584 585 586 587 588
    if (m_d->mousePressActive==true && this->mask().contains(e->pos())) {
        QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos());
        KoColor col = convertShapeCoordinateToKoColor(coordinates);
        setColor(col);
        if (!m_d->updateTimer->isActive()) {
            Q_EMIT sigNewColor(col);
            m_d->updateTimer->start();
        }
    } else {
        e->ignore();
    }
}
589

590 591 592
void KisVisualColorSelectorShape::mouseReleaseEvent(QMouseEvent *)
{
    m_d->mousePressActive = false;
593 594 595 596 597
}
void KisVisualColorSelectorShape::paintEvent(QPaintEvent*)
{
    QPainter painter(this);

598 599
    //check if old and new colors differ.

600
    if (m_d->imagesNeedUpdate) {
601 602 603
        setMask(getMaskMap());
    }
    drawCursor();
604
    painter.drawImage(0,0,m_d->fullSelector);
605 606 607 608 609 610 611 612 613 614 615 616
}

KisVisualColorSelectorShape::Dimensions KisVisualColorSelectorShape::getDimensions()
{
    return m_d->dimension;
}

KisVisualColorSelectorShape::ColorModel KisVisualColorSelectorShape::getColorModel()
{
    return m_d->model;
}

617
void KisVisualColorSelectorShape::setFullImage(QImage full)
618 619 620 621 622 623 624 625
{
    m_d->fullSelector = full;
}
KoColor KisVisualColorSelectorShape::getCurrentColor()
{
    return m_d->currentColor;
}

626 627
QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx)
{
628
    if ((hsx[2]<=0.0 || hsx[2]>1.0) && hsx[1]<=0.0 && m_d->channel1!=2 && m_d->channel2!=2) {
629
        hsx[1] = m_d->sat;
630 631
    }
    if (hsx[1]<=0.0 && m_d->channel1!=1 && m_d->channel2!=1){
632 633 634 635 636 637 638
        hsx[0]=m_d->hue;
    }
    return hsx;
}

void KisVisualColorSelectorShape::setHSX(QVector<qreal> hsx)
{
639
    if (hsx[2]>0.0 && hsx[2<=1.0] && m_d->channel1!=2 && m_d->channel2!=2){
640 641 642 643 644 645 646
        m_d->sat = hsx[1];
    }
    if (hsx[1]>0.0) {
        m_d->hue = hsx[0];
    }
}

647 648 649 650 651 652 653
/*-----------Rectangle Shape------------*/

KisVisualRectangleSelectorShape::KisVisualRectangleSelectorShape(QWidget *parent,
                                                                 Dimensions dimension,
                                                                 ColorModel model,
                                                                 const KoColorSpace *cs,
                                                                 int channel1, int channel2,
654
                                                                 const KoColorDisplayRendererInterface *displayRenderer,
655
                                                                 int width,
656
                                                                 singelDTypes d)
657
    : KisVisualColorSelectorShape(parent, dimension, model, cs, channel1, channel2, displayRenderer)
658 659
{
    m_type = d;
660
    m_barWidth = width;
661 662 663 664 665 666 667
}

KisVisualRectangleSelectorShape::~KisVisualRectangleSelectorShape()
{

}

668 669 670 671 672
void KisVisualRectangleSelectorShape::setBarWidth(int width)
{
    m_barWidth = width;
}

673 674 675 676 677
QPointF KisVisualRectangleSelectorShape::convertShapeCoordinateToWidgetCoordinate(QPointF coordinate)
{
    qreal x = width()/2;
    qreal y = height()/2;
    KisVisualColorSelectorShape::Dimensions dimension = getDimensions();
678 679 680 681 682
    if (dimension == KisVisualColorSelectorShape::onedimensional) {
        if ( m_type == KisVisualRectangleSelectorShape::vertical) {
            y = coordinate.x()*height();
        } else if (m_type == KisVisualRectangleSelectorShape::horizontal) {
            x = coordinate.x()*width();
Wolthera van Hövell's avatar
Wolthera van Hövell committed
683
        } else if (m_type == KisVisualRectangleSelectorShape::border) {
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710

            QRectF innerRect(m_barWidth/2, m_barWidth/2, width()-m_barWidth, height()-m_barWidth);
            QPointF left (innerRect.left(),innerRect.center().y());
            QList <QLineF> 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());

Wolthera van Hövell's avatar
Wolthera van Hövell committed
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
        } 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 <QLineF> 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());

750
        }
751 752 753 754 755 756 757 758 759 760 761 762 763
    } else {
        x = coordinate.x()*width();
        y = coordinate.y()*height();
    }
    return QPointF(x,y);
}

QPointF KisVisualRectangleSelectorShape::convertWidgetCoordinateToShapeCoordinate(QPoint coordinate)
{
    //default implementation:
    qreal x = 0.5;
    qreal y = 0.5;
    KisVisualColorSelectorShape::Dimensions dimension = getDimensions();
Wolthera van Hövell's avatar
Wolthera van Hövell committed
764 765
    if (getMaskMap().contains(coordinate)) {
        if (dimension == KisVisualColorSelectorShape::onedimensional ) {
766 767 768 769
            if (m_type == KisVisualRectangleSelectorShape::vertical) {
                x = (qreal)coordinate.y()/(qreal)height();
            } else if (m_type == KisVisualRectangleSelectorShape::horizontal) {
                x = (qreal)coordinate.x()/(qreal)width();
Wolthera van Hövell's avatar
Wolthera van Hövell committed
770
            } else if (m_type == KisVisualRectangleSelectorShape::border) {
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
                //border

                QRectF innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2));
                QPointF left (innerRect.left(),innerRect.center().y());
                QList <QLineF> 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;
Wolthera van Hövell's avatar
Wolthera van Hövell committed
787
                Q_FOREACH(QLineF line, polygonLines) {
788 789 790 791 792 793 794 795 796 797 798 799 800 801
                    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;

Wolthera van Hövell's avatar
Wolthera van Hövell committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
            } 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 <QLineF> 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;
                }
840 841 842 843 844
            }
        }
        else {
            x = (qreal)coordinate.x()/(qreal)width();
            y = (qreal)coordinate.y()/(qreal)height();
Wolthera van Hövell's avatar
Wolthera van Hövell committed
845 846
        }
    }
847 848 849 850 851 852
    return QPointF(x, y);
}

QRegion KisVisualRectangleSelectorShape::getMaskMap()
{
    QRegion mask = QRegion(0,0,width(),height());
Wolthera van Hövell's avatar
Wolthera van Hövell committed
853
    if (m_type==KisVisualRectangleSelectorShape::border || m_type==KisVisualRectangleSelectorShape::borderMirrored) {
854 855
        mask = mask.subtracted(QRegion(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2)));
    }
856 857 858 859 860
    return mask;
}

void KisVisualRectangleSelectorShape::drawCursor()
{
861
    QPointF cursorPoint = convertShapeCoordinateToWidgetCoordinate(getCursorPosition());
862
    QImage fullSelector = getImageMap();
863
    QColor col = getColorFromConverter(getCurrentColor());
864 865 866 867 868 869
    QPainter painter;
    painter.begin(&fullSelector);
    painter.setRenderHint(QPainter::Antialiasing);
    //QPainterPath path;
    QBrush fill;
    fill.setStyle(Qt::SolidPattern);
870 871 872 873 874 875 876 877 878 879 880 881 882

    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));
    } else {
        int x = cursorPoint.x()-cursorwidth;
        int y = cursorPoint.y()-(height()/2)+1;
        rect.setCoords(x, y, x+(cursorwidth*2), y+cursorwidth-2);
    }
Wolthera van Hövell's avatar
Wolthera van Hövell committed
883 884
    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) {
885 886 887 888 889
        painter.setPen(Qt::white);
        fill.setColor(Qt::white);
        painter.setBrush(fill);
        painter.drawRect(rect);
        //set filter conversion!
890
        fill.setColor(col);
891 892 893 894 895 896
        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);

Wolthera van Hövell's avatar
Wolthera van Hövell committed
897 898 899 900 901 902 903 904 905 906 907 908 909
    }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);

910 911 912 913 914
    } else {
        painter.setPen(Qt::white);
        fill.setColor(Qt::white);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth);
915
        fill.setColor(col);
916 917 918 919
        painter.setPen(Qt::black);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth-1.0, cursorwidth-1.0);
    }
920 921 922
    painter.end();
    setFullImage(fullSelector);
}
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954

//----------------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::setBarWidth(int width)
{
    m_barWidth = width;
}

QPointF KisVisualEllipticalSelectorShape::convertShapeCoordinateToWidgetCoordinate(QPointF coordinate)
{
955 956 957 958 959 960 961
    qreal x;
    qreal y;
    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);
962 963 964 965 966 967
    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);
    }
968 969
    line.setAngle(angle);
    if (getDimensions()!=KisVisualColorSelectorShape::onedimensional) {
970
        line.setLength(coordinate.y()*a);
971
    }
972 973
    x = qRound(line.p2().x());
    y = qRound(line.p2().y());
974 975 976 977 978 979 980 981
    return QPointF(x,y);
}

QPointF KisVisualEllipticalSelectorShape::convertWidgetCoordinateToShapeCoordinate(QPoint coordinate)
{
    //default implementation:
    qreal x = 0.5;
    qreal y = 1.0;
982 983 984 985 986 987 988 989 990 991 992 993
    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, 1.0);
994 995
        }

996 997 998 999 1000 1001 1002 1003 1004 1005
    } 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 = line.length()/a;
        }
1006
    }
1007 1008


1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
    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::drawCursor()
{
    QPointF cursorPoint = convertShapeCoordinateToWidgetCoordinate(getCursorPosition());
1024
    QImage fullSelector = getImageMap();
1025 1026 1027 1028
    QColor col = getColorFromConverter(getCurrentColor());
    QPainter painter;
    painter.begin(&fullSelector);
    painter.setRenderHint(QPainter::Antialiasing);
1029 1030

    painter.save();
1031
    painter.setCompositionMode(QPainter::CompositionMode_Clear);
1032 1033 1034 1035 1036 1037 1038 1039 1040
    QPen pen;
    pen.setWidth(5);
    painter.setPen(pen);
    painter.drawEllipse(this->geometry());
    if (getDimensions()==KisVisualColorSelectorShape::onedimensional) {
        painter.drawEllipse(QRect(this->geometry().top()+m_barWidth, this->geometry().left()+m_barWidth, this->geometry().width()-(m_barWidth*2), this->geometry().height()-(m_barWidth*2)));
    }
    painter.restore();

1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074