Commit 62931e1d authored by Mathias Wein's avatar Mathias Wein

Add color preview tooltip to Wide Gamut Selector

In order to do this nicely, the individual controls gained a signal
that indicates when interaction started or ended, so the tooltip can be
shown and hidden.
Currently it hides only when the mouse leaves the docker, but a timer
based or even instant auto-hide may be nicer.
parent a38d75bb
......@@ -93,6 +93,12 @@ Q_SIGNALS:
*/
void sigColorModelChanged();
void sigHSXChanged(const QVector3D &hsx);
/**
* @brief sigInteraction is emitted whenever mouse interaction status changes
* @param active when true, the user started dragging a handle, when false the
* interaction has just finished
*/
void sigInteraction(bool active);
protected:
void resizeEvent(QResizeEvent *) override;
......
......@@ -290,6 +290,7 @@ void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
m_d->dragStart = e->localPos();
emit colorSelector()->sigInteraction(true);
QPointF coordinates = mousePositionToShapeCoordinate(e->localPos(), m_d->dragStart);
setCursorPosition(coordinates, true);
}
......@@ -310,7 +311,9 @@ void KisVisualColorSelectorShape::mouseMoveEvent(QMouseEvent *e)
void KisVisualColorSelectorShape::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() != Qt::LeftButton) {
if (e->button() == Qt::LeftButton) {
emit colorSelector()->sigInteraction(false);
} else {
e->ignore();
}
}
......
......@@ -79,6 +79,7 @@ QSize KisWGShadeSlider::minimumSizeHint() const
void KisWGShadeSlider::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
emit sigInteraction(true);
qreal sliderPos = convertWidgetCoordinateToSliderValue(event->localPos());
if (!qFuzzyIsNull(m_d->sliderValue - sliderPos)) {
m_d->sliderValue = sliderPos;
......@@ -100,6 +101,13 @@ void KisWGShadeSlider::mouseMoveEvent(QMouseEvent *event)
}
}
void KisWGShadeSlider::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
emit sigInteraction(false);
}
}
void KisWGShadeSlider::paintEvent(QPaintEvent*)
{
if (m_d->imageNeedsUpdate) {
......
......@@ -38,12 +38,13 @@ public:
QSize minimumSizeHint() const override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
//void mouseReleaseEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
//void tabletEvent(QTabletEvent *event) override;
void paintEvent(QPaintEvent*) override;
void resizeEvent(QResizeEvent *) override;
Q_SIGNALS:
void sigHSXChanged(const QVector3D &hsx);
void sigInteraction(bool active);
public Q_SLOTS:
void slotSetHSX(const QVector3D &hsx);
......
......@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "WGColorPreviewPopup.h"
#include "WGColorSelectorDock.h"
#include "WGShadeSelector.h"
#include "KisVisualColorSelector.h"
......@@ -24,6 +25,7 @@
#include <klocalizedstring.h>
#include <kis_canvas2.h>
#include <kis_canvas_resource_provider.h>
#include <kis_display_color_converter.h>
#include <kis_signal_compressor.h>
#include <KoCanvasResourceProvider.h>
......@@ -37,6 +39,7 @@
WGColorSelectorDock::WGColorSelectorDock()
: QDockWidget()
, m_colorChangeCompressor(new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this))
, m_previewPopup(new WGColorPreviewPopup(this))
{
setWindowTitle(i18n("Wide Gamut Color Selector"));
......@@ -45,6 +48,7 @@ WGColorSelectorDock::WGColorSelectorDock()
m_selector = new KisVisualColorSelector(mainWidget);
connect(m_selector, SIGNAL(sigNewColor(KoColor)), SLOT(slotColorSelected(KoColor)));
connect(m_selector, SIGNAL(sigInteraction(bool)), SLOT(slotColorInteraction(bool)));
connect(m_colorChangeCompressor, SIGNAL(timeout()), SLOT(slotSetNewColors()));
mainWidget->layout()->addWidget(m_selector);
......@@ -52,15 +56,22 @@ WGColorSelectorDock::WGColorSelectorDock()
connect(m_toggle, SIGNAL(toggled(bool)), SLOT(slotColorSourceToggled(bool)));
mainWidget->layout()->addWidget(m_toggle);
WGShadeSelector *shadeSelector = new WGShadeSelector(m_selector, this);
mainWidget->layout()->addWidget(shadeSelector);
connect(m_selector, SIGNAL(sigHSXChanged(QVector3D)), shadeSelector, SLOT(slotChannelValuesChanged(QVector3D)));
connect(shadeSelector, SIGNAL(sigChannelValuesChanged(QVector3D)), m_selector, SLOT(slotSetHSX(QVector3D)));
m_shadeSelector = new WGShadeSelector(m_selector, this);
mainWidget->layout()->addWidget(m_shadeSelector);
connect(m_selector, SIGNAL(sigHSXChanged(QVector3D)), m_shadeSelector, SLOT(slotChannelValuesChanged(QVector3D)));
connect(m_shadeSelector, SIGNAL(sigChannelValuesChanged(QVector3D)), m_selector, SLOT(slotSetHSX(QVector3D)));
connect(m_shadeSelector, SIGNAL(sigColorInteraction(bool)), SLOT(slotColorInteraction(bool)));
setWidget(mainWidget);
setEnabled(false);
}
void WGColorSelectorDock::leaveEvent(QEvent *event)
{
Q_UNUSED(event)
m_previewPopup->hide();
}
void WGColorSelectorDock::setCanvas(KoCanvasBase *canvas)
{
if (m_canvas.data() == canvas)
......@@ -78,6 +89,8 @@ void WGColorSelectorDock::setCanvas(KoCanvasBase *canvas)
connect(dri, SIGNAL(displayConfigurationChanged()), this, SLOT(slotDisplayConfigurationChanged()));
connect(m_canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)),
this, SLOT(slotCanvasResourceChanged(int,QVariant)));
connect(m_canvas->imageView()->resourceProvider(), SIGNAL(sigFGColorUsed(KoColor)),
this, SLOT(slotFGColorUsed(KoColor)), Qt::UniqueConnection);
}
setEnabled(canvas != 0);
}
......@@ -111,14 +124,16 @@ void WGColorSelectorDock::slotDisplayConfigurationChanged()
void WGColorSelectorDock::slotColorSelected(const KoColor &color)
{
bool selectingBg = m_toggle->isChecked();
QColor displayCol = m_canvas->displayColorConverter()->toQColor(color);
m_previewPopup->setCurrentColor(displayCol);
if (selectingBg) {
m_toggle->setBackgroundColor(m_canvas->displayColorConverter()->toQColor(color));
m_toggle->setBackgroundColor(displayCol);
m_pendingBgUpdate = true;
m_bgColor = color;
m_colorChangeCompressor->start();
}
else {
m_toggle->setForegroundColor(m_canvas->displayColorConverter()->toQColor(color));
m_toggle->setForegroundColor(displayCol);
m_pendingFgUpdate = true;
m_fgColor = color;
m_colorChangeCompressor->start();
......@@ -135,6 +150,26 @@ void WGColorSelectorDock::slotColorSourceToggled(bool selectingBg)
}
}
void WGColorSelectorDock::slotColorInteraction(bool active)
{
if (active) {
QColor baseCol = m_selector->displayRenderer()->toQColor(m_selector->getCurrentColor());
m_previewPopup->setCurrentColor(baseCol);
m_previewPopup->setPreviousColor(baseCol);
if (sender() == m_shadeSelector) {
m_previewPopup->show(m_shadeSelector);
} else {
m_previewPopup->show(this);
}
}
}
void WGColorSelectorDock::slotFGColorUsed(const KoColor &color)
{
QColor lastCol = m_selector->displayRenderer()->toQColor(color);
m_previewPopup->setLastUsedColor(lastCol);
}
void WGColorSelectorDock::slotSetNewColors()
{
KIS_SAFE_ASSERT_RECOVER_RETURN(m_pendingFgUpdate || m_pendingBgUpdate);
......
......@@ -29,6 +29,8 @@ class KisCanvas2;
class KisColorSourceToggle;
class KisSignalCompressor;
class KisVisualColorSelector;
class WGColorPreviewPopup;
class WGShadeSelector;
class QVariant;
class WGColorSelectorDock : public QDockWidget, public KoCanvasObserverBase // public KisMainwindowObserver ?
......@@ -37,6 +39,7 @@ class WGColorSelectorDock : public QDockWidget, public KoCanvasObserverBase // p
public:
WGColorSelectorDock();
protected:
void leaveEvent(QEvent *event) override;
void setCanvas(KoCanvasBase *canvas) override;
void unsetCanvas() override;
......@@ -46,6 +49,8 @@ private Q_SLOTS:
void slotDisplayConfigurationChanged();
void slotColorSelected(const KoColor &color);
void slotColorSourceToggled(bool selectingBg);
void slotColorInteraction(bool active);
void slotFGColorUsed(const KoColor&color);
void slotSetNewColors();
void slotCanvasResourceChanged(int key, const QVariant &value);
private:
......@@ -53,6 +58,8 @@ private:
KisVisualColorSelector *m_selector {0};
KisColorSourceToggle *m_toggle {0};
KisSignalCompressor *m_colorChangeCompressor;
WGColorPreviewPopup *m_previewPopup {0};
WGShadeSelector *m_shadeSelector {0};
bool m_pendingFgUpdate {false};
bool m_pendingBgUpdate {false};
KoColor m_fgColor;
......
......@@ -54,6 +54,7 @@ void WGShadeSelector::updateSettings()
m_sliders.append(line);
layout()->addWidget(m_sliders.last());
connect(line, SIGNAL(sigHSXChanged(QVector3D)), SLOT(slotSliderValuesChanged(QVector3D)));
connect(line, SIGNAL(sigInteraction(bool)), SIGNAL(sigColorInteraction(bool)));
}
while (config.size() < m_sliders.size()) {
layout()->removeWidget(m_sliders.last());
......
......@@ -48,6 +48,7 @@ private Q_SLOTS:
Q_SIGNALS:
void sigChannelValuesChanged(const QVector3D &hsx);
void sigColorInteraction(bool active);
private:
KisVisualColorSelector *m_selector;
QVector<KisWGShadeSlider *> m_sliders;
......
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