Skip to content

Commit

Permalink
WIP: preview
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Nov 17, 2024
1 parent 39b55de commit 004227c
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 95 deletions.
30 changes: 20 additions & 10 deletions src/desktop/scene/canvasscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/desktop/scene/canvasscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
50 changes: 32 additions & 18 deletions src/desktop/scene/canvasview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1465,8 +1465,7 @@ void CanvasView::penReleaseEvent(
}

if(m_pickingColor) {
m_scene->setColorPick(
int(tools::ColorPickSource::Canvas), QPointF(), QColor());
hideSceneColorPick();
m_pickingColor = false;
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -2166,6 +2166,9 @@ void CanvasView::scrollTo(const QPointF &point)

void CanvasView::setDrag(const SetDragParams &params)
{
ViewDragMode prevMode = m_dragmode;
CanvasShortcuts::Action prevAction = m_dragAction;

if(params.hasPenMode()) {
m_penmode = params.penMode();
}
Expand Down Expand Up @@ -2205,6 +2208,18 @@ void CanvasView::setDrag(const SetDragParams &params)
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)
Expand Down Expand Up @@ -2290,30 +2305,29 @@ 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)
{
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<void()> &block)
{
QPointF outlinePoint = fromCanvasTransform().map(m_prevoutlinepoint);
Expand Down
5 changes: 2 additions & 3 deletions src/desktop/scene/canvasview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<view::Lock::Reason> reasons);
void setLockDescription(const QString &lockDescription);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/desktop/scene/colorpickitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,8 +57,6 @@ bool ColorPickItem::shouldShow(int source, int visibility, const QColor &color)
default:
return true;
}
} else {
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/desktop/scene/colorpickitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions src/desktop/scene/scenewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 004227c

Please sign in to comment.