Commit 14ee7993 authored by Alexey Kapustin's avatar Alexey Kapustin Committed by Timothée Giet

Show previous color in color selector

When picking a color in color selector, the colour previously used displayed next to the box showing the current color being chosen.
Differential Revision: https://phabricator.kde.org/D2259
BUG:358673
parent 48287eb3
......@@ -256,6 +256,7 @@ void KisColorSelector::mousePressEvent(QMouseEvent* e)
m_grabbingComponent=m_subComponent;
mouseEvent(e);
updatePreviousColorPreview();
e->accept();
}
}
......@@ -280,6 +281,7 @@ void KisColorSelector::mouseReleaseEvent(QMouseEvent* e)
m_lastColorRole = Acs::buttonToRole(e->button());
updateColor(m_lastRealColor, m_lastColorRole, false);
updateBaseColorPreview(m_currentRealColor);
e->accept();
}
......
......@@ -48,6 +48,9 @@ public:
setWindowFlags(Qt::ToolTip);
setQColor(QColor(0,0,0));
setMouseTracking(true);
m_baseColor = QColor(0,0,0,0);
m_previousColor = QColor(0,0,0,0);
m_lastUsedColor = QColor(0,0,0,0);
}
void show()
......@@ -70,7 +73,8 @@ public:
} else {
targetPos = QPoint(parentPos.x(), parentPos.y() + m_parent->height());
}
setGeometry(targetPos.x(), targetPos.y(), 100, 100);
setGeometry(targetPos.x(), targetPos.y(), 100, 150);
setAttribute(Qt::WA_TranslucentBackground);
}
void setQColor(const QColor& color)
......@@ -79,16 +83,38 @@ public:
update();
}
void setPreviousColor()
{
m_previousColor = m_baseColor;
}
void setBaseColor(const QColor& color)
{
m_baseColor = color;
update();
}
void setLastUsedColor(const QColor& color)
{
m_lastUsedColor = color;
update();
}
protected:
void paintEvent(QPaintEvent *e) {
Q_UNUSED(e);
QPainter p(this);
p.fillRect(0,0, width(), width(), m_color);
p.fillRect(0, 0, width(), width(), m_color);
p.fillRect(50, width(), width(), height(), m_previousColor);
p.fillRect(0, width(), 50, height(), m_lastUsedColor);
}
private:
KisColorSelectorBase* m_parent;
QColor m_color;
QColor m_baseColor;
QColor m_previousColor;
QColor m_lastUsedColor;
};
KisColorSelectorBase::KisColorSelectorBase(QWidget *parent) :
......@@ -151,6 +177,9 @@ void KisColorSelectorBase::setCanvas(KisCanvas2 *canvas)
connect(m_canvas->displayColorConverter(), SIGNAL(displayConfigurationChanged()),
SLOT(reset()));
connect(canvas->imageView()->resourceProvider(), SIGNAL(sigFGColorUsed(KoColor)),
this, SLOT(updateLastUsedColorPreview(KoColor)), Qt::UniqueConnection);
if (m_canvas->viewManager() && m_canvas->viewManager()->resourceProvider()) {
setColor(Acs::currentColor(m_canvas->viewManager()->resourceProvider(), Acs::Foreground));
}
......@@ -476,6 +505,21 @@ void KisColorSelectorBase::reset()
update();
}
void KisColorSelectorBase::updateBaseColorPreview(const KoColor &color)
{
m_colorPreviewPopup->setBaseColor(converter()->toQColor(color));
}
void KisColorSelectorBase::updatePreviousColorPreview()
{
m_colorPreviewPopup->setPreviousColor();
}
void KisColorSelectorBase::updateLastUsedColorPreview(const KoColor &color)
{
m_colorPreviewPopup->setLastUsedColor(converter()->toQColor(color));
}
KisDisplayColorConverter* KisColorSelectorBase::converter() const
{
return m_canvas ?
......
......@@ -55,6 +55,8 @@ public:
void updateColor(const KoColor &color, Acs::ColorRole role, bool needsExplicitColorReset);
void updateColorPreview(const KoColor &color);
void showColorPreview();
void updateBaseColorPreview(const KoColor &color);
void updatePreviousColorPreview();
virtual void setColor(const KoColor& color);
......@@ -94,6 +96,8 @@ protected Q_SLOTS:
/// if you overwrite this, keep in mind, that you should set the colour only, if m_colorUpdateAllowed is true
virtual void canvasResourceChanged(int key, const QVariant& v);
void updateLastUsedColorPreview(const KoColor &color);
public:
// This is a private interface for signal compressor, don't use it.
// Use requestUpdateColorAndPreview() instead
......
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