Commit 8441c26f authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix advanced color selector to adjust color when exposure changes

When "Lock current color" feature is off, the color selector should
adjust its view when exposure changes.
parent 3bdf84ea
......@@ -194,8 +194,6 @@ void KisColorSelector::hasAtLeastOneDocument(bool value)
void KisColorSelector::reset()
{
KisColorSelectorBase::reset();
if (m_mainComponent) {
m_mainComponent->setDirty();
}
......@@ -203,6 +201,8 @@ void KisColorSelector::reset()
if (m_subComponent) {
m_subComponent->setDirty();
}
KisColorSelectorBase::reset();
}
void KisColorSelector::paintEvent(QPaintEvent* e)
......
......@@ -77,9 +77,11 @@ void KisColorSelectorComponent::mouseEvent(int x, int y)
int newX=qBound(0, (x-m_x), width());
int newY=qBound(0, (y-m_y), height());
selectColor(newX, newY);
m_lastX=newX;
m_lastY=newY;
if (allowsColorSelectionAtPoint(QPoint(x, y))) {
m_lastSelectedColor = selectColor(newX, newY);
m_lastX=newX;
m_lastY=newY;
}
}
const KoColorSpace* KisColorSelectorComponent::colorSpace() const
......@@ -92,6 +94,7 @@ const KoColorSpace* KisColorSelectorComponent::colorSpace() const
void KisColorSelectorComponent::setDirty()
{
m_dirty = true;
setColor(m_lastSelectedColor);
}
void KisColorSelectorComponent::setGamutMask(KoGamutMask *gamutMask)
......@@ -133,6 +136,11 @@ bool KisColorSelectorComponent::containsPointInComponentCoords(int x, int y) con
return false;
}
bool KisColorSelectorComponent::allowsColorSelectionAtPoint(const QPoint &pt) const
{
return true;
}
KoColor KisColorSelectorComponent::currentColor()
{
return selectColor(m_lastX, m_lastY);
......@@ -230,6 +238,11 @@ void KisColorSelectorComponent::setConfiguration(Parameter param, Type type)
m_type = type;
}
void KisColorSelectorComponent::setColor(const KoColor &color)
{
m_lastSelectedColor = color;
}
void KisColorSelectorComponent::setLastMousePosition(int x, int y)
{
// prevent movement due to rounding errors
......
......@@ -57,7 +57,7 @@ public:
virtual void setColor(const KoColor& color) = 0;
/// force subsequent redraw of the component
void setDirty();
virtual 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);}
......@@ -93,6 +93,11 @@ protected:
/// 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;
/// a subclass can implement this method to note that the point, although it is in
/// containsPointInComponentCoords area, still cannot be selected as a color (e.g.
/// it is masked out). Default implementation always returns true.
virtual bool allowsColorSelectionAtPoint(const QPoint &pt) const;
// Workaround for Bug 287001
void setLastMousePosition(int x, int y);
......@@ -120,6 +125,7 @@ private:
int m_height;
bool m_dirty;
const KoColorSpace* m_lastColorSpace;
KoColor m_lastSelectedColor;
};
#endif // KIS_COLOR_SELECTOR_COMPONENT_H
......@@ -117,7 +117,7 @@ KoColor KisColorSelectorRing::selectColor(int x, int y)
m_lastHue=hue;
emit update();
return KoColor();
return m_parent->converter()->fromHsvF(hue, 1.0, 1.0);
}
void KisColorSelectorRing::setColor(const KoColor &color)
......@@ -133,6 +133,8 @@ void KisColorSelectorRing::setColor(const KoColor &color)
}
emit update();
KisColorSelectorComponent::setColor(color);
}
void KisColorSelectorRing::paintCache()
......
......@@ -257,6 +257,7 @@ void KisColorSelectorSimple::setColor(const KoColor &color)
emit update();
//Workaround for bug 317648
setLastMousePosition((m_lastClickPos.x()*width()), (m_lastClickPos.y()*height()));
KisColorSelectorComponent::setColor(color);
}
void KisColorSelectorSimple::paint(QPainter* painter)
......
......@@ -136,6 +136,7 @@ void KisColorSelectorTriangle::setColor(const KoColor &color)
emit paramChanged(-1, s, v, -1, -1, -1, -1, -1, -1);
emit update();
KisColorSelectorComponent::setColor(color);
}
int KisColorSelectorTriangle::triangleWidth() const
......
......@@ -177,6 +177,8 @@ void KisColorSelectorWheel::setColor(const KoColor &color)
setLastMousePosition(pos.x(), pos.y());
}
KisColorSelectorComponent::setColor(color);
}
void KisColorSelectorWheel::paint(QPainter* painter)
......@@ -257,18 +259,6 @@ void KisColorSelectorWheel::paint(QPainter* painter)
}
}
void KisColorSelectorWheel::mouseEvent(int x, int y)
{
int newX=qBound(0, (x-m_x), width());
int newY=qBound(0, (y-m_y), height());
if (coordIsClear(newX,newY)) {
selectColor(newX, newY);
m_lastX=newX;
m_lastY=newY;
}
}
KoColor KisColorSelectorWheel::colorAt(int x, int y, bool forceValid)
{
KoColor color(Qt::transparent, m_parent->colorSpace());
......@@ -327,15 +317,9 @@ KoColor KisColorSelectorWheel::colorAt(int x, int y, bool forceValid)
return color;
}
bool KisColorSelectorWheel::coordIsClear(int x, int y)
bool KisColorSelectorWheel::allowsColorSelectionAtPoint(const QPoint &pt) const
{
bool retval = false;
if (m_gamutMaskOn && m_currentGamutMask) {
bool isClear = m_currentGamutMask->coordIsClear(m_toRenderArea.map(QPointF(x,y)), *m_viewConverter, m_maskPreviewActive);
retval = (isClear) ? true : false;
} else {
retval = true;
}
return retval;
return !m_gamutMaskOn || !m_currentGamutMask ||
m_currentGamutMask->coordIsClear(m_toRenderArea.map(QPointF(pt)),
*m_viewConverter, m_maskPreviewActive);
}
......@@ -43,14 +43,13 @@ public:
protected:
KoColor selectColor(int x, int y) override;
void paint(QPainter*) override;
void mouseEvent(int x, int y) override;
private:
friend class Acs::PixelCacheRenderer;
KoColor colorAt(int x, int y, bool forceValid = false);
private:
bool coordIsClear(int x, int y);
bool allowsColorSelectionAtPoint(const QPoint &pt) const override;
QPointF m_lastClickPos;
QImage m_pixelCache;
QPoint m_pixelCacheOffset;
......
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