Commit 408ffc85 authored by Boudewijn Rempt's avatar Boudewijn Rempt

BUG:309998: Make the saturation slider behave

Patch by Wolthera. Thanks!
CCMAIL: griffinvalley@gmail.com
parent a9099c51
......@@ -224,7 +224,7 @@ void KisColorSelector::resizeEvent(QResizeEvent* e) {
if(m_canvas && m_canvas->resourceManager()) {
if (m_lastColorRole==Foreground) {
setColor(m_canvas->resourceManager()->foregroundColor().toQColor());
} else {
} else if (m_lastColorRole==Background) {
setColor(m_canvas->resourceManager()->backgroundColor().toQColor());
}
}
......@@ -263,12 +263,14 @@ void KisColorSelector::mouseReleaseEvent(QMouseEvent* e)
if(!e->isAccepted() &&
m_lastColor != m_currentColor &&
m_currentColor.isValid()) {
m_lastColor=m_currentColor;
if(e->button() == Qt::LeftButton)
m_lastColorRole=Foreground;
else
m_lastColorRole=Background;
{
m_lastColorRole=Foreground;}
else if (e->button() == Qt::RightButton)
{
m_lastColorRole=Background;}
commitColor(KoColor(m_currentColor, colorSpace()), m_lastColorRole);
e->accept();
......@@ -298,7 +300,7 @@ void KisColorSelector::mouseEvent(QMouseEvent *e)
if (m_grabbingComponent && (e->buttons() & Qt::LeftButton || e->buttons() & Qt::RightButton)) {
m_grabbingComponent->mouseEvent(e->x(), e->y());
m_currentColor=m_mainComponent->currentColor();
KoColor kocolor(m_currentColor, colorSpace());
updateColorPreview(kocolor.toQColor());
......
......@@ -154,10 +154,17 @@ void KisColorSelectorBase::unsetCanvas()
m_canvas = 0;
}
void KisColorSelectorBase::mousePressEvent(QMouseEvent* event)
{
event->accept();
//this boolean here is to check if the colour selector is updating the resource, so it won't update itself when the resource is updated//
if (m_colorUpdateSelf==false)
{m_colorUpdateSelf=true;}
if(!m_isPopup && m_popupOnMouseClick &&
event->button() == Qt::MidButton) {
......@@ -195,8 +202,9 @@ void KisColorSelectorBase::mousePressEvent(QMouseEvent* event)
}
void KisColorSelectorBase::mouseReleaseEvent(QMouseEvent *e) {
Q_UNUSED(e);
Q_UNUSED(e);
if (e->button() == Qt::MidButton) {
e->accept();
}
......@@ -257,6 +265,7 @@ void KisColorSelectorBase::leaveEvent(QEvent *e)
Q_UNUSED(e);
if (m_colorPreviewPopup->isVisible()) {
m_colorUpdateSelf=false; //this is for allowing advanced selector to listen to outside colour-change events.
m_colorPreviewPopup->hide();
}
......@@ -414,6 +423,7 @@ void KisColorSelectorBase::commitColor(const KoColor& color, ColorRole role)
if (!m_canvas)
return;
m_colorUpdateAllowed=false;
if (role == Foreground)
......@@ -434,7 +444,7 @@ void KisColorSelectorBase::canvasResourceChanged(int key, const QVariant &v)
if (key == KoCanvasResourceManager::ForegroundColor || key == KoCanvasResourceManager::BackgroundColor) {
QColor c = findGeneratingColor(v.value<KoColor>());
updateColorPreview(c);
if (m_colorUpdateAllowed) {
if (m_colorUpdateAllowed && !m_colorUpdateSelf) {
setColor(c);
}
}
......
......@@ -63,6 +63,7 @@ public:
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
protected:
void keyPressEvent(QKeyEvent *);
virtual KisColorSelectorBase* createPopup() const = 0;
......@@ -85,6 +86,7 @@ protected:
KisColorSelectorBase* m_popup;
QWidget* m_parent;
bool m_colorUpdateAllowed;
bool m_colorUpdateSelf;
private:
QTimer* m_hideTimer;
......
......@@ -96,6 +96,7 @@ bool KisColorSelectorComponent::containsPointInComponentCoords(int x, int y) con
QColor KisColorSelectorComponent::currentColor()
{
return selectColor(m_lastX, m_lastY);
}
......
......@@ -32,17 +32,17 @@ void KisColorSelectorSimple::setColor(const QColor &c)
switch (m_parameter) {
case KisColorSelector::SL:
m_lastClickPos.setX(c.hslSaturationF());
m_lastClickPos.setY(1. - c.lightnessF());
m_lastClickPos.setY(1 - c.lightnessF());
emit paramChanged(-1, -1, -1, c.hslSaturationF(), c.lightnessF());
break;
case KisColorSelector::LH:
m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
m_lastClickPos.setY(1. - c.lightnessF());
m_lastClickPos.setY(1 - c.lightnessF());
emit paramChanged(c.hueF(), -1, -1, -1, c.lightnessF());
break;
case KisColorSelector::SV:
m_lastClickPos.setX(c.saturationF());
m_lastClickPos.setY(1. - c.valueF());
m_lastClickPos.setY(1 - c.valueF());
emit paramChanged(-1, c.saturationF(), c.valueF(), -1, -1);
break;
case KisColorSelector::SV2: {
......@@ -59,21 +59,21 @@ void KisColorSelectorSimple::setColor(const QColor &c)
}
case KisColorSelector::VH:
m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
m_lastClickPos.setY(1. - c.valueF());
m_lastClickPos.setY(1 - c.valueF());
emit paramChanged(c.hueF(), -1, c.valueF(), -1, -1);
break;
case KisColorSelector::hsvSH:
m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
m_lastClickPos.setY(1. - c.saturationF());
m_lastClickPos.setY(1 - c.saturationF());
emit paramChanged(c.hueF(), c.saturationF(), -1, -1, -1);
break;
case KisColorSelector::hslSH:
m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
m_lastClickPos.setX(qBound<qreal>(0., c.hslHueF(), 1.));
m_lastClickPos.setY(1 - c.hslSaturationF());
emit paramChanged(c.hueF(), -1, -1, c.hslSaturationF(), -1);
break;
case KisColorSelector::L:
m_lastClickPos.setX(c.lightnessF());
m_lastClickPos.setX(qBound<qreal>(0., c.lightnessF(), 1.));
emit paramChanged(-1, -1, -1, -1, c.lightnessF());
break;
case KisColorSelector::V:
......@@ -81,11 +81,11 @@ void KisColorSelectorSimple::setColor(const QColor &c)
emit paramChanged(-1, -1, c.valueF(), -1, -1);
break;
case KisColorSelector::hsvS:
m_lastClickPos.setX(c.saturationF());
m_lastClickPos.setX( c.saturationF() );
emit paramChanged(-1, c.saturationF(), -1, -1, -1);
break;
case KisColorSelector::hslS:
m_lastClickPos.setX(c.hslSaturationF());
m_lastClickPos.setX( c.hslSaturationF() );
emit paramChanged(-1, -1, -1, c.hslSaturationF(), -1);
break;
case KisColorSelector::H:
......@@ -97,10 +97,14 @@ void KisColorSelectorSimple::setColor(const QColor &c)
break;
}
emit update();
setLastMousePosition((m_lastClickPos.x()*width()), (m_lastClickPos.y()*height()));
}
QColor KisColorSelectorSimple::selectColor(int x, int y)
{
m_kocolor.convertTo(colorSpace());
m_lastClickPos.setX(x/qreal(width()));
......
......@@ -61,13 +61,25 @@ void KisColorSelectorWheel::setColor(const QColor &c)
m_lastClickPos.setY(sin(angle)*radius+0.5);
//workaround for bug 279500
setLastMousePosition(m_lastClickPos.x()*width(), m_lastClickPos.y()*height());
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());
}
}
QColor KisColorSelectorWheel::selectColor(int x, int y)
{
m_kocolor.convertTo(colorSpace());
int xWheel = x-width()/2;
int yWheel = y-height()/2;
......@@ -108,11 +120,13 @@ QColor KisColorSelectorWheel::selectColor(int x, int y)
m_lastClickPos.setX(cos(angle)*radius+0.5);
m_lastClickPos.setY(sin(angle)*radius+0.5);
return colorAt(x, y, true);
}
void KisColorSelectorWheel::paint(QPainter* painter)
{
if(isDirty()) {
m_kocolor.convertTo(colorSpace());
......@@ -144,6 +158,7 @@ void KisColorSelectorWheel::paint(QPainter* painter)
painter->drawImage(0,0, m_pixelCache);
// draw blips
if(m_lastClickPos!=QPoint(-1,-1) && m_parent->displayBlip()) {
QPoint pos = (m_lastClickPos*qMin(width(), height())).toPoint();
if(width()<height())
......@@ -198,8 +213,8 @@ const QColor& KisColorSelectorWheel::colorAt(int x, int y, bool forceValid)
default:
Q_ASSERT(false);
m_qcolor = QColor();
return m_qcolor;
}
return m_qcolor;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment