Skip to content

Commit

Permalink
Add selection cursor guide to make it easier to do selections
Browse files Browse the repository at this point in the history
Closes #47.
  • Loading branch information
mitchcurtis committed Mar 31, 2018
1 parent b987497 commit cf60fb5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/imagecanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ void ImageCanvas::drawPane(QPainter *painter, const CanvasPane &pane, int paneIn
}
}

if (shouldDrawSelectionCursorGuide())
drawSelectionCursorGuide(painter, pane, paneIndex);

painter->restore();
}

Expand Down Expand Up @@ -906,6 +909,34 @@ void ImageCanvas::drawGuide(QPainter *painter, const CanvasPane &pane, int paneI
painter->restore();
}

void ImageCanvas::drawSelectionCursorGuide(QPainter *painter, const CanvasPane &pane, int paneIndex)
{
painter->save();

QPen pen;
pen.setColor(Qt::gray);
pen.setStyle(Qt::DotLine);
painter->setPen(pen);

// Draw the vertical cursor selection guide.
painter->save();

int guidePosition = mCursorSceneX;
qreal zoomedGuidePosition = (guidePosition * pane.integerZoomLevel()) + (painter->pen().widthF() / 2.0);
painter->translate(0, -pane.offset().y());
painter->drawLine(QLineF(zoomedGuidePosition, 0, zoomedGuidePosition, height()));

painter->restore();

// Draw the horizontal cursor selection guide.
guidePosition = mCursorSceneY;
zoomedGuidePosition = (guidePosition * pane.integerZoomLevel()) + (painter->pen().widthF() / 2.0);
painter->translate(-pane.offset().x(), 0);
painter->drawLine(QLineF(0, zoomedGuidePosition, paneWidth(paneIndex), zoomedGuidePosition));

painter->restore();
}

int ImageCanvas::paneWidth(int index) const
{
return index == 0 ? mFirstPane.size() * width() : width() - mFirstPane.size() * width();
Expand Down Expand Up @@ -1316,6 +1347,11 @@ bool ImageCanvas::shouldDrawSelectionPreviewImage() const
return mMovingSelection || mHasMovedSelection || mIsSelectionFromPaste;
}

bool ImageCanvas::shouldDrawSelectionCursorGuide() const
{
return mTool == SelectionTool && !mHasSelection;
}

void ImageCanvas::confirmPasteSelection()
{
paintImageOntoPortionOfImage(mSelectionAreaBeforeFirstMove, mSelectionContents);
Expand Down Expand Up @@ -1793,6 +1829,9 @@ void ImageCanvas::updateCursorPos(const QPoint &eventPos)
// ShaderSourceEffect to pick the colour instead
setCursorPixelColour(contentImage().pixelColor(cursorScenePos));
}

if (shouldDrawSelectionCursorGuide())
update();
}

void ImageCanvas::onLoadedChanged()
Expand Down
2 changes: 2 additions & 0 deletions app/imagecanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ protected slots:
void drawPane(QPainter *painter, const CanvasPane &pane, int paneIndex);
void drawLine(QPainter *painter) const;
void drawGuide(QPainter *painter, const CanvasPane &pane, int paneIndex, const Guide &guide, int guideIndex);
void drawSelectionCursorGuide(QPainter *painter, const CanvasPane &pane, int paneIndex);
int paneWidth(int index) const;
void centrePanes(bool respectSceneCentred = true);
enum ResetPaneSizePolicy {
Expand Down Expand Up @@ -364,6 +365,7 @@ protected slots:
void setMovingSelection(bool movingSelection);
bool cursorOverSelection() const;
bool shouldDrawSelectionPreviewImage() const;
bool shouldDrawSelectionCursorGuide() const;
void confirmPasteSelection();
void setSelectionFromPaste(bool isSelectionFromPaste);

Expand Down

0 comments on commit cf60fb5

Please sign in to comment.