From 004227cc573c65a6a2eba4161efba8e1f21277c3 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Sat, 16 Nov 2024 23:03:54 +0100 Subject: [PATCH] WIP: preview --- src/desktop/scene/canvasscene.cpp | 30 +++++--- src/desktop/scene/canvasscene.h | 5 +- src/desktop/scene/canvasview.cpp | 50 +++++++++----- src/desktop/scene/canvasview.h | 5 +- src/desktop/scene/colorpickitem.cpp | 8 +-- src/desktop/scene/colorpickitem.h | 2 +- src/desktop/scene/scenewrapper.cpp | 10 ++- src/desktop/view/canvascontroller.cpp | 87 ++++++++++++++---------- src/desktop/view/canvascontroller.h | 2 +- src/desktop/view/canvasscene.cpp | 47 ++++++++++--- src/desktop/view/canvasscene.h | 6 +- src/desktop/view/viewwrapper.cpp | 10 ++- src/libclient/canvas/canvasshortcuts.cpp | 12 ++++ src/libclient/canvas/canvasshortcuts.h | 2 + src/libclient/tools/colorpicker.cpp | 6 +- src/libclient/tools/enums.h | 2 +- src/libclient/tools/toolcontroller.cpp | 1 + src/libclient/tools/toolcontroller.h | 5 +- 18 files changed, 195 insertions(+), 95 deletions(-) diff --git a/src/desktop/scene/canvasscene.cpp b/src/desktop/scene/canvasscene.cpp index 2d56ffec8e..a6a30e8550 100644 --- a/src/desktop/scene/canvasscene.cpp +++ b/src/desktop/scene/canvasscene.cpp @@ -886,6 +886,14 @@ void CanvasScene::setOutlineVisibleInMode(bool visibleInMode) m_outlineItem->setVisibleInMode(visibleInMode); } +void CanvasScene::setForegroundColor(const QColor &foregroundColor) +{ + m_foregroundColor = foregroundColor; + if(m_colorPick) { + m_colorPick->setColor(foregroundColor); + } +} + void CanvasScene::setComparisonColor(const QColor &comparisonColor) { m_comparisonColor = comparisonColor; @@ -894,25 +902,27 @@ void CanvasScene::setComparisonColor(const QColor &comparisonColor) } } -bool CanvasScene::setColorPick( - int source, const QPointF &pos, const QColor &color) +bool CanvasScene::showColorPick(int source, const QPointF &pos) { - if(ColorPickItem::shouldShow(source, m_colorPickVisibility, color)) { - if(m_colorPick) { - m_colorPick->setColor(color); - } else { - m_colorPick = new ColorPickItem(color, m_comparisonColor); + if(ColorPickItem::shouldShow(source, m_colorPickVisibility)) { + if(!m_colorPick) { + m_colorPick = + new ColorPickItem(m_foregroundColor, m_comparisonColor); addItem(m_colorPick); } m_colorPick->updatePosition(pos); return true; } else { - delete m_colorPick; - m_colorPick = nullptr; - return false; + return m_colorPick; } } +void CanvasScene::hideColorPick() +{ + delete m_colorPick; + m_colorPick = nullptr; +} + void CanvasScene::setColorPickVisibility(int colorPickVisibility) { m_colorPickVisibility = colorPickVisibility; diff --git a/src/desktop/scene/canvasscene.h b/src/desktop/scene/canvasscene.h index 6ccb3f1312..113d6af68e 100644 --- a/src/desktop/scene/canvasscene.h +++ b/src/desktop/scene/canvasscene.h @@ -105,8 +105,10 @@ class CanvasScene final : public QGraphicsScene { void setOutlineSquare(bool square); void setOutlineWidth(qreal width); void setOutlineVisibleInMode(bool visibleInMode); + void setForegroundColor(const QColor &foregroundColor); void setComparisonColor(const QColor &comparisonColor); - bool setColorPick(int source, const QPointF &pos, const QColor &color); + bool showColorPick(int source, const QPointF &pos); + void hideColorPick(); void setColorPickVisibility(int colorPickVisibility); bool isCursorOnCanvas() const { return m_cursorOnCanvas; } void setCursorOnCanvas(bool onCanvas); @@ -221,6 +223,7 @@ private slots: OutlineItem *m_outlineItem; ColorPickItem *m_colorPick = nullptr; + QColor m_foregroundColor; QColor m_comparisonColor; #ifdef HAVE_EMULATED_BITMAP_CURSOR CursorItem *m_cursorItem; diff --git a/src/desktop/scene/canvasview.cpp b/src/desktop/scene/canvasview.cpp index 14e361ff88..b97749d560 100644 --- a/src/desktop/scene/canvasview.cpp +++ b/src/desktop/scene/canvasview.cpp @@ -298,7 +298,7 @@ CanvasView::CanvasView(QWidget *parent) &CanvasView::touchColorPick, Qt::DirectConnection); connect( m_touch, &TouchHandler::touchColorPickFinished, this, - &CanvasView::finishTouchColorPick, Qt::DirectConnection); + &CanvasView::hideSceneColorPick, Qt::DirectConnection); } @@ -1028,10 +1028,10 @@ void CanvasView::focusInEvent(QFocusEvent *event) void CanvasView::clearKeys() { m_keysDown.clear(); - m_dragmode = ViewDragMode::None; - m_penmode = PenMode::Normal; - updateOutline(); - resetCursor(); + setDrag(SetDragParams::fromNone() + .setPenMode(PenMode::Normal) + .setUpdateOutline() + .setResetCursor()); } bool CanvasView::isTouchDrawEnabled() const @@ -1465,8 +1465,7 @@ void CanvasView::penReleaseEvent( } if(m_pickingColor) { - m_scene->setColorPick( - int(tools::ColorPickSource::Canvas), QPointF(), QColor()); + hideSceneColorPick(); m_pickingColor = false; } @@ -1820,6 +1819,7 @@ void CanvasView::keyReleaseEvent(QKeyEvent *event) case CanvasShortcuts::COLOR_H_ADJUST: case CanvasShortcuts::COLOR_S_ADJUST: case CanvasShortcuts::COLOR_V_ADJUST: + updateOutlinePos(mapToCanvas(m_dragLastPoint)); setDrag(SetDragParams::fromNone().setResetCursor()); break; default: @@ -2166,6 +2166,9 @@ void CanvasView::scrollTo(const QPointF &point) void CanvasView::setDrag(const SetDragParams ¶ms) { + ViewDragMode prevMode = m_dragmode; + CanvasShortcuts::Action prevAction = m_dragAction; + if(params.hasPenMode()) { m_penmode = params.penMode(); } @@ -2205,6 +2208,18 @@ void CanvasView::setDrag(const SetDragParams ¶ms) resetCursor(); } } + + if(m_dragmode == ViewDragMode::Started) { + if(prevMode != ViewDragMode::Started && + CanvasShortcuts::isColorAdjustAction(m_dragAction)) { + showSceneColorPick( + int(tools::ColorPickSource::Adjust), m_dragLastPoint); + } + } else if( + prevMode == ViewDragMode::Started && + CanvasShortcuts::isColorAdjustAction(prevAction)) { + m_scene->hideColorPick(); + } } void CanvasView::dragAdjust(int type, int delta) @@ -2290,17 +2305,22 @@ void CanvasView::moveDrag(const QPoint &point) m_dragLastPoint = point; } -bool CanvasView::setSceneColorPick( - int source, const QPointF &posf, const QColor &color) +bool CanvasView::showSceneColorPick(int source, const QPointF &posf) +{ + return m_scene->showColorPick(source, mapToScene(posf.toPoint())); +} + +void CanvasView::hideSceneColorPick() { - return m_scene->setColorPick(source, mapToScene(posf.toPoint()), color); + m_scene->hideColorPick(); + m_pickingColor = false; } void CanvasView::pickColor( int source, const QPointF &point, const QPointF &posf) { - QColor color = m_scene->model()->pickColor(point.x(), point.y(), 0, 0); - m_pickingColor = setSceneColorPick(source, posf, color); + m_scene->model()->pickColor(point.x(), point.y(), 0, 0); + m_pickingColor = showSceneColorPick(source, posf); } void CanvasView::touchColorPick(const QPointF &posf) @@ -2308,12 +2328,6 @@ void CanvasView::touchColorPick(const QPointF &posf) pickColor(int(tools::ColorPickSource::Touch), mapToCanvas(posf), posf); } -void CanvasView::finishTouchColorPick() -{ - m_scene->setColorPick( - int(tools::ColorPickSource::Touch), QPointF(), QColor()); -} - void CanvasView::updateCanvasTransform(const std::function &block) { QPointF outlinePoint = fromCanvasTransform().map(m_prevoutlinepoint); diff --git a/src/desktop/scene/canvasview.h b/src/desktop/scene/canvasview.h index 59a42b996d..9f72560d29 100644 --- a/src/desktop/scene/canvasview.h +++ b/src/desktop/scene/canvasview.h @@ -189,8 +189,8 @@ public slots: void setViewFlip(bool flip); void setViewMirror(bool mirror); - bool - setSceneColorPick(int source, const QPointF &posf, const QColor &color); + bool showSceneColorPick(int source, const QPointF &posfr); + void hideSceneColorPick(); void setLockReasons(QFlags reasons); void setLockDescription(const QString &lockDescription); @@ -302,7 +302,6 @@ private slots: void moveDrag(const QPoint &point); void pickColor(int source, const QPointF &point, const QPointF &posf); void touchColorPick(const QPointF &posf); - void finishTouchColorPick(); QTransform fromCanvasTransform() const; QTransform toCanvasTransform() const; diff --git a/src/desktop/scene/colorpickitem.cpp b/src/desktop/scene/colorpickitem.cpp index 86e2f27c1f..fd6b1fca81 100644 --- a/src/desktop/scene/colorpickitem.cpp +++ b/src/desktop/scene/colorpickitem.cpp @@ -44,9 +44,11 @@ void ColorPickItem::setComparisonColor(const QColor &comparisonColor) } } -bool ColorPickItem::shouldShow(int source, int visibility, const QColor &color) +bool ColorPickItem::shouldShow(int source, int visibility) { - if(color.isValid() && color.alpha() > 0) { + if(source == int(tools::ColorPickSource::Adjust)) { + return true; + } else { switch(visibility) { case int(desktop::settings::SamplingRingVisibility::Never): return false; @@ -55,8 +57,6 @@ bool ColorPickItem::shouldShow(int source, int visibility, const QColor &color) default: return true; } - } else { - return false; } } diff --git a/src/desktop/scene/colorpickitem.h b/src/desktop/scene/colorpickitem.h index 1ae2667e12..d3abc7f0d9 100644 --- a/src/desktop/scene/colorpickitem.h +++ b/src/desktop/scene/colorpickitem.h @@ -23,7 +23,7 @@ class ColorPickItem final : public BaseItem { void setColor(const QColor &color); void setComparisonColor(const QColor &comparisonColor); - static bool shouldShow(int source, int visibility, const QColor &color); + static bool shouldShow(int source, int visibility); static int defaultVisibility(); protected: diff --git a/src/desktop/scene/scenewrapper.cpp b/src/desktop/scene/scenewrapper.cpp index e966054fca..1c73568dcc 100644 --- a/src/desktop/scene/scenewrapper.cpp +++ b/src/desktop/scene/scenewrapper.cpp @@ -315,12 +315,18 @@ void SceneWrapper::connectDocument(Document *doc) connect( toolCtrl, &tools::ToolController::zoomRequested, m_view, &CanvasView::zoomTo); + connect( + toolCtrl, &tools::ToolController::foregroundColorChanged, m_scene, + &CanvasScene::setForegroundColor); connect( toolCtrl, &tools::ToolController::colorUsed, m_scene, &CanvasScene::setComparisonColor); connect( - toolCtrl, &tools::ToolController::colorPickRequested, m_view, - &CanvasView::setSceneColorPick); + toolCtrl, &tools::ToolController::showColorPickRequested, m_view, + &CanvasView::showSceneColorPick); + connect( + toolCtrl, &tools::ToolController::hideColorPickRequested, m_view, + &CanvasView::hideSceneColorPick); connect( toolCtrl, &tools::ToolController::maskPreviewRequested, m_scene, &CanvasScene::setMaskPreview); diff --git a/src/desktop/view/canvascontroller.cpp b/src/desktop/view/canvascontroller.cpp index 067ee2d488..04a6fa52d0 100644 --- a/src/desktop/view/canvascontroller.cpp +++ b/src/desktop/view/canvascontroller.cpp @@ -53,6 +53,19 @@ class CanvasController::SetDragParams { match.inverted(), match.swapAxes(), -1); } + SetDragParams( + CanvasShortcuts::Action action, Qt::MouseButton button, + Qt::KeyboardModifiers modifiers, bool inverted, bool swapAxes, + int dragMode) + : m_action(action) + , m_button(button) + , m_modifiers(modifiers) + , m_dragMode(dragMode) + , m_inverted(inverted) + , m_swapAxes(swapAxes) + { + } + CanvasShortcuts::Action action() const { return m_action; } Qt::MouseButton button() const { return m_button; } Qt::KeyboardModifiers modifiers() const { return m_modifiers; } @@ -113,24 +126,10 @@ class CanvasController::SetDragParams { SetDragParams &setResetCursor() { m_resetCursor = true; - m_updateOutline = true; return *this; } private: - SetDragParams( - CanvasShortcuts::Action action, Qt::MouseButton button, - Qt::KeyboardModifiers modifiers, bool inverted, bool swapAxes, - int dragMode) - : m_action(action) - , m_button(button) - , m_modifiers(modifiers) - , m_dragMode(dragMode) - , m_inverted(inverted) - , m_swapAxes(swapAxes) - { - } - CanvasShortcuts::Action m_action; Qt::MouseButton m_button; Qt::KeyboardModifiers m_modifiers; @@ -211,7 +210,7 @@ CanvasController::CanvasController(CanvasScene *scene, QWidget *parent) &CanvasController::touchColorPick, Qt::DirectConnection); connect( m_touch, &TouchHandler::touchColorPickFinished, this, - &CanvasController::finishTouchColorPick, Qt::DirectConnection); + &CanvasController::hideSceneColorPick, Qt::DirectConnection); resetCanvasTransform(); } @@ -577,10 +576,10 @@ void CanvasController::handleFocusIn() void CanvasController::clearKeys() { m_keysDown.clear(); - m_dragMode = ViewDragMode::None; - m_penMode = PenMode::Normal; - updateOutline(); - resetCursor(); + setDrag(SetDragParams::fromNone() + .setPenMode(PenMode::Normal) + .setUpdateOutline() + .setResetCursor()); } void CanvasController::handleMouseMove(QMouseEvent *event) @@ -923,7 +922,9 @@ void CanvasController::handleKeyPress(QKeyEvent *event) case CanvasShortcuts::COLOR_H_ADJUST: case CanvasShortcuts::COLOR_S_ADJUST: case CanvasShortcuts::COLOR_V_ADJUST: - setDrag(SetDragParams::fromMouseMatch(mouseMatch).setResetCursor()); + setDrag(SetDragParams::fromMouseMatch(mouseMatch) + .setUpdateOutline() + .setResetCursor()); break; default: break; @@ -1031,7 +1032,9 @@ void CanvasController::handleKeyRelease(QKeyEvent *event) case CanvasShortcuts::COLOR_H_ADJUST: case CanvasShortcuts::COLOR_S_ADJUST: case CanvasShortcuts::COLOR_V_ADJUST: - setDrag(SetDragParams::fromNone().setResetCursor()); + updateOutlinePos(mapPointToCanvasF(m_dragLastPoint)); + setDrag( + SetDragParams::fromNone().setUpdateOutline().setResetCursor()); break; default: break; @@ -1057,6 +1060,7 @@ void CanvasController::handleKeyRelease(QKeyEvent *event) setDrag(SetDragParams::fromMouseMatch(mouseMatch) .setDragMode(ViewDragMode::Started) .setResetDragRotation() + .setUpdateOutline() .setResetCursor()); break; default: @@ -1457,13 +1461,11 @@ void CanvasController::penPressEvent( if(m_dragMode == ViewDragMode::Prepared) { m_dragLastPoint = posf.toPoint(); m_dragCanvasPoint = mapPointToCanvas(m_dragLastPoint); - m_dragMode = ViewDragMode::Started; - m_dragButton = button; - m_dragModifiers = modifiers; - m_dragDiscreteRotation = 0.0; - m_dragSnapRotation = this->rotation(); - resetCursor(); - + setDrag(SetDragParams( + m_dragAction, button, modifiers, m_dragInverted, + m_dragSwapAxes, int(ViewDragMode::Started)) + .setResetDragRotation() + .setResetCursor()); } else if( (button == Qt::LeftButton || button == Qt::RightButton || penMode != PenMode::Normal) && @@ -1554,9 +1556,7 @@ void CanvasController::penReleaseEvent( } if(m_pickingColor) { - m_scene->setColorPick( - int(tools::ColorPickSource::Canvas), QPointF(), QColor()); - m_pickingColor = false; + hideSceneColorPick(); } m_penState = PenState::Up; @@ -1640,6 +1640,9 @@ void CanvasController::touchZoomRotate(qreal zoom, qreal rotation) void CanvasController::setDrag(const SetDragParams ¶ms) { + ViewDragMode prevMode = m_dragMode; + CanvasShortcuts::Action prevAction = m_dragAction; + if(params.hasPenMode()) { m_penMode = params.penMode(); } @@ -1679,6 +1682,18 @@ void CanvasController::setDrag(const SetDragParams ¶ms) resetCursor(); } } + + if(m_dragMode == ViewDragMode::Started) { + if(prevMode != ViewDragMode::Started && + CanvasShortcuts::isColorAdjustAction(m_dragAction)) { + m_scene->showColorPick( + int(tools::ColorPickSource::Adjust), m_dragLastPoint); + } + } else if( + prevMode == ViewDragMode::Started && + CanvasShortcuts::isColorAdjustAction(prevAction)) { + m_scene->hideColorPick(); + } } void CanvasController::moveDrag(const QPoint &point) @@ -1769,8 +1784,8 @@ void CanvasController::dragAdjust(int type, int delta) void CanvasController::pickColor( int source, const QPointF &point, const QPointF &posf) { - QColor color = m_canvasModel->pickColor(point.x(), point.y(), 0, 0); - m_pickingColor = m_scene->setColorPick(source, posf, color); + m_canvasModel->pickColor(point.x(), point.y(), 0, 0); + m_pickingColor = m_scene->showColorPick(source, posf); } void CanvasController::touchColorPick(const QPointF &posf) @@ -1779,10 +1794,10 @@ void CanvasController::touchColorPick(const QPointF &posf) int(tools::ColorPickSource::Touch), mapPointToCanvasF(posf), posf); } -void CanvasController::finishTouchColorPick() +void CanvasController::hideSceneColorPick() { - m_scene->setColorPick( - int(tools::ColorPickSource::Touch), QPointF(), QColor()); + m_scene->hideColorPick(); + m_pickingColor = false; } void CanvasController::resetCursor() diff --git a/src/desktop/view/canvascontroller.h b/src/desktop/view/canvascontroller.h index 4c664c537d..cfe074e2c3 100644 --- a/src/desktop/view/canvascontroller.h +++ b/src/desktop/view/canvascontroller.h @@ -240,7 +240,7 @@ class CanvasController : public QObject { void dragAdjust(int type, int delta); void pickColor(int source, const QPointF &point, const QPointF &posf); void touchColorPick(const QPointF &posf); - void finishTouchColorPick(); + void hideSceneColorPick(); void resetCursor(); void updateOutlinePos(QPointF point); diff --git a/src/desktop/view/canvasscene.cpp b/src/desktop/view/canvasscene.cpp index 2eaa80910f..17b6110475 100644 --- a/src/desktop/view/canvasscene.cpp +++ b/src/desktop/view/canvasscene.cpp @@ -359,6 +359,14 @@ void CanvasScene::setOutline( } } +void CanvasScene::setForegroundColor(const QColor &foregroundColor) +{ + m_foregroundColor = foregroundColor; + if(m_colorPick) { + m_colorPick->setColor(foregroundColor); + } +} + void CanvasScene::setComparisonColor(const QColor &comparisonColor) { m_comparisonColor = comparisonColor; @@ -367,30 +375,49 @@ void CanvasScene::setComparisonColor(const QColor &comparisonColor) } } -bool CanvasScene::setColorPick( - int source, const QPointF &pos, const QColor &color) +bool CanvasScene::showColorPick(int source, const QPointF &pos) { - if(ColorPickItem::shouldShow(source, m_colorPickVisibility, color)) { - if(m_colorPick) { - m_colorPick->setColor(color); - } else { - m_colorPick = new ColorPickItem(color, m_comparisonColor); + if(ColorPickItem::shouldShow(source, m_colorPickVisibility)) { + if(!m_colorPick) { + m_colorPick = + new ColorPickItem(m_foregroundColor, m_comparisonColor); addSceneItem(m_colorPick); } m_colorPick->updatePosition(pos); return true; } else { - delete m_colorPick; - m_colorPick = nullptr; - return false; + return m_colorPick; } } +void CanvasScene::hideColorPick() +{ + delete m_colorPick; + m_colorPick = nullptr; +} + void CanvasScene::setColorPickVisibility(int colorPickVisibility) { m_colorPickVisibility = colorPickVisibility; } +bool CanvasScene::setColorAdjust(bool visible, const QPointF &pos) +{ + if(visible) { + if(!m_colorPick) { + m_colorPick = + new ColorPickItem(m_foregroundColor, m_comparisonColor); + addSceneItem(m_colorPick); + } + m_colorPick->updatePosition(pos); + return true; + } else { + delete m_colorPick; + m_colorPick = nullptr; + return false; + } +} + #ifdef HAVE_EMULATED_BITMAP_CURSOR void CanvasScene::setCursor(const QCursor &cursor) { diff --git a/src/desktop/view/canvasscene.h b/src/desktop/view/canvasscene.h index ea012a2a5b..3b379f7147 100644 --- a/src/desktop/view/canvasscene.h +++ b/src/desktop/view/canvasscene.h @@ -90,9 +90,12 @@ class CanvasScene final : public QGraphicsScene { bool visibleInMode, const QPointF &pos, qreal rotation, qreal outlineSize, qreal outlineWidth, bool square); + void setForegroundColor(const QColor &foregroundColor); void setComparisonColor(const QColor &comparisonColor); - bool setColorPick(int source, const QPointF &pos, const QColor &color); + bool showColorPick(int source, const QPointF &pos); + void hideColorPick(); void setColorPickVisibility(int colorPickVisibility); + bool setColorAdjust(bool visible, const QPointF &pos); #ifdef HAVE_EMULATED_BITMAP_CURSOR void setCursor(const QCursor &cursor); @@ -187,6 +190,7 @@ class CanvasScene final : public QGraphicsScene { TransformItem *m_transform = nullptr; OutlineItem *m_outline = nullptr; ColorPickItem *m_colorPick = nullptr; + QColor m_foregroundColor; QColor m_comparisonColor; #ifdef HAVE_EMULATED_BITMAP_CURSOR diff --git a/src/desktop/view/viewwrapper.cpp b/src/desktop/view/viewwrapper.cpp index c92ee88985..22fc28348e 100644 --- a/src/desktop/view/viewwrapper.cpp +++ b/src/desktop/view/viewwrapper.cpp @@ -303,12 +303,18 @@ void ViewWrapper::connectDocument(Document *doc) connect( toolCtrl, &tools::ToolController::zoomRequested, m_controller, &CanvasController::zoomTo); + connect( + toolCtrl, &tools::ToolController::foregroundColorChanged, m_scene, + &CanvasScene::setForegroundColor); connect( toolCtrl, &tools::ToolController::colorUsed, m_scene, &CanvasScene::setComparisonColor); connect( - toolCtrl, &tools::ToolController::colorPickRequested, m_scene, - &CanvasScene::setColorPick); + toolCtrl, &tools::ToolController::showColorPickRequested, m_scene, + &CanvasScene::showColorPick); + connect( + toolCtrl, &tools::ToolController::hideColorPickRequested, m_scene, + &CanvasScene::hideColorPick); connect( toolCtrl, &tools::ToolController::maskPreviewRequested, m_scene, &CanvasScene::setMaskPreview); diff --git a/src/libclient/canvas/canvasshortcuts.cpp b/src/libclient/canvas/canvasshortcuts.cpp index 00108078f6..758fac25a2 100644 --- a/src/libclient/canvas/canvasshortcuts.cpp +++ b/src/libclient/canvas/canvasshortcuts.cpp @@ -329,6 +329,18 @@ CanvasShortcuts::ConstraintMatch CanvasShortcuts::matchConstraints( return match; } +bool CanvasShortcuts::isColorAdjustAction(Action action) +{ + switch(action) { + case COLOR_H_ADJUST: + case COLOR_S_ADJUST: + case COLOR_V_ADJUST: + return true; + default: + return false; + } +} + bool CanvasShortcuts::Shortcut::conflictsWith(const Shortcut &other) const { return type == other.type && mods == other.mods && keys == other.keys && diff --git a/src/libclient/canvas/canvasshortcuts.h b/src/libclient/canvas/canvasshortcuts.h index 17867f244e..da54533e99 100644 --- a/src/libclient/canvas/canvasshortcuts.h +++ b/src/libclient/canvas/canvasshortcuts.h @@ -125,6 +125,8 @@ class CanvasShortcuts { ConstraintMatch matchConstraints( Qt::KeyboardModifiers mods, const QSet &keys) const; + static bool isColorAdjustAction(Action action); + private: static constexpr Qt::KeyboardModifiers MODS_MASK = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | diff --git a/src/libclient/tools/colorpicker.cpp b/src/libclient/tools/colorpicker.cpp index 2f38a8adec..356ca0edac 100644 --- a/src/libclient/tools/colorpicker.cpp +++ b/src/libclient/tools/colorpicker.cpp @@ -32,7 +32,7 @@ void ColorPicker::motion(const MotionParams ¶ms) void ColorPicker::end(const EndParams &) { m_picking = false; - m_owner.colorPickRequested(int(ColorPickSource::Tool), QPointF(), QColor()); + m_owner.hideColorPickRequested(); } void ColorPicker::pick(const QPointF &point, const QPointF &viewPos) const @@ -40,8 +40,8 @@ void ColorPicker::pick(const QPointF &point, const QPointF &viewPos) const canvas::CanvasModel *canvas = m_owner.model(); if(canvas) { int layer = m_pickFromCurrentLayer ? m_owner.activeLayer() : 0; - QColor color = canvas->pickColor(point.x(), point.y(), layer, m_size); - m_owner.colorPickRequested(int(ColorPickSource::Tool), viewPos, color); + canvas->pickColor(point.x(), point.y(), layer, m_size); + m_owner.showColorPickRequested(int(ColorPickSource::Tool), viewPos); } } diff --git a/src/libclient/tools/enums.h b/src/libclient/tools/enums.h index 2fa19dc89d..28c4e8ec69 100644 --- a/src/libclient/tools/enums.h +++ b/src/libclient/tools/enums.h @@ -4,7 +4,7 @@ namespace tools { -enum class ColorPickSource { Canvas, Tool, Touch }; +enum class ColorPickSource { Canvas, Tool, Touch, Adjust }; enum class DeviceType { Mouse, Tablet, Touch }; enum class QuickAdjustType { Tool, ColorH, ColorS, ColorV }; diff --git a/src/libclient/tools/toolcontroller.cpp b/src/libclient/tools/toolcontroller.cpp index 79e06c3569..6ce8c4f6da 100644 --- a/src/libclient/tools/toolcontroller.cpp +++ b/src/libclient/tools/toolcontroller.cpp @@ -233,6 +233,7 @@ void ToolController::setForegroundColor(const QColor &color) if(m_activeTool) { m_activeTool->setForegroundColor(color); } + emit foregroundColorChanged(color); } } diff --git a/src/libclient/tools/toolcontroller.h b/src/libclient/tools/toolcontroller.h index 8937f9bfbe..3b22e9846d 100644 --- a/src/libclient/tools/toolcontroller.h +++ b/src/libclient/tools/toolcontroller.h @@ -222,9 +222,10 @@ public slots: void stabilizerUseBrushSampleCountChanged(bool useBrushSampleCount); void actionCancelled(); + void foregroundColorChanged(const QColor &color); void colorUsed(const QColor &color); - void - colorPickRequested(int source, const QPointF &pos, const QColor &color); + void showColorPickRequested(int source, const QPointF &pos); + void hideColorPickRequested(); void panRequested(int x, int y); void zoomRequested(const QRect &rect, int steps); void maskPreviewRequested(const QPoint &pos, const QImage &mask);