Skip to content

Commit

Permalink
Merge branch 'pen-tool'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchcurtis committed Nov 23, 2018
2 parents bce180e + 15cf014 commit d9e2481
Show file tree
Hide file tree
Showing 33 changed files with 786 additions and 108 deletions.
Binary file added app/images/circle-tool-shape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions app/images/circle-tool-shape.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/circle-tool-shape@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/circle-tool-shape@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/circle-tool-shape@4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<file>change-tool-size@3x.png</file>
<file>change-tool-size@4x.png</file>
<file>checker.png</file>
<file>circle-tool-shape.svg</file>
<file>circle-tool-shape@4x.png</file>
<file>circle-tool-shape@3x.png</file>
<file>circle-tool-shape@2x.png</file>
<file>circle-tool-shape.png</file>
<file>fill.png</file>
<file>fill@2x.png</file>
<file>fill@3X.png</file>
Expand Down Expand Up @@ -63,6 +68,11 @@
<file>splitscreen@2x.png</file>
<file>splitscreen@3x.png</file>
<file>splitscreen@4x.png</file>
<file>square-tool-shape.svg</file>
<file>square-tool-shape@4x.png</file>
<file>square-tool-shape@3x.png</file>
<file>square-tool-shape@2x.png</file>
<file>square-tool-shape.png</file>
<file>textured-fill.png</file>
<file>textured-fill@2x.png</file>
<file>textured-fill@3x.png</file>
Expand Down
Binary file added app/images/square-tool-shape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions app/images/square-tool-shape.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/square-tool-shape@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/square-tool-shape@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/square-tool-shape@4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions app/qml/ui/ToolBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,54 @@ ToolBar {
}
}

ToolButton {
id: toolShapeButton
objectName: "toolShapeButton"
hoverEnabled: true
focusPolicy: Qt.NoFocus

readonly property bool squareShape: canvas && canvas.toolShape === ImageCanvas.SquareToolShape
icon.source: squareShape ? "qrc:/images/square-tool-shape.png" : "qrc:/images/circle-tool-shape.png"

ToolTip.text: qsTr("Choose brush shape")
ToolTip.visible: hovered

onClicked: toolShapeMenu.visible = !toolShapeMenu.visible

ToolButtonMenuIndicator {
color: toolShapeButton.icon.color
anchors.right: parent.contentItem.right
anchors.bottom: parent.contentItem.bottom
anchors.margins: 6
}

Menu {
id: toolShapeMenu
objectName: "toolShapeMenu"
y: toolShapeButton.height
width: 260

MenuItem {
objectName: "squareToolShapeMenuItem"
text: qsTr("Square")
icon.source: "qrc:/images/square-tool-shape.png"
autoExclusive: true
checkable: true
checked: canvas && canvas.toolShape === ImageCanvas.SquareToolShape
onTriggered: canvas.toolShape = ImageCanvas.SquareToolShape
}
MenuItem {
objectName: "circleToolShapeMenuItem"
text: qsTr("Circle")
icon.source: "qrc:/images/circle-tool-shape.png"
autoExclusive: true
checkable: true
checked: canvas && canvas.toolShape === ImageCanvas.CircleToolShape
onTriggered: canvas.toolShape = ImageCanvas.CircleToolShape
}
}
}

ToolSeparator {
id: toolSeparator
}
Expand Down
50 changes: 40 additions & 10 deletions lib/applypixellinecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,49 @@
#include "applypixellinecommand.h"

#include <QLoggingCategory>
#include <QPainter>
#include <QImage>

#include "commands.h"

Q_LOGGING_CATEGORY(lcApplyPixelLineCommand, "app.undo.applyPixelLineCommand")

ApplyPixelLineCommand::ApplyPixelLineCommand(ImageCanvas *canvas, int layerIndex, const QImage &imageWithLine,
const QImage &imageWithoutLine, const QRect &lineRect,
const QPoint &newLastPixelPenReleaseScenePos, const QPoint &oldLastPixelPenReleaseScenePos, QUndoCommand *parent) :
// The undo command for lines needs the project image before and after
// the line was drawn on it.
ApplyPixelLineCommand::ApplyPixelLineCommand(ImageCanvas *canvas, int layerIndex, QImage &currentProjectImage, const QPointF point1, const QPointF point2,
const QPointF &newLastPixelPenReleaseScenePos, const QPointF &oldLastPixelPenReleaseScenePos,
const QPainter::CompositionMode mode, QUndoCommand *parent) :
QUndoCommand(parent),
mCanvas(canvas),
mLayerIndex(layerIndex),
mImageWithLine(imageWithLine),
mImageWithoutLine(imageWithoutLine),
mLineRect(lineRect),
mNewLastPixelPenReleaseScenePos(newLastPixelPenReleaseScenePos),
mOldLastPixelPenReleaseScenePos(oldLastPixelPenReleaseScenePos)
mOldLastPixelPenReleaseScenePos(oldLastPixelPenReleaseScenePos),
subImageDatas()
{
const QRect lineRect = mCanvas->normalisedLineRect(point1, point2);
const QList<ImageCanvas::SubImage> subImages = canvas->subImagesInBounds(lineRect);
for (auto const &subImage : subImages) {
// subimage-space to scene-space offset
const QPoint offset = subImage.bounds.topLeft() - subImage.offset;
// line rect offset to scene space and clipped to subimage bounds
const QRect subImageLineRect = subImage.bounds.intersected(lineRect.translated(offset));

SubImageData subImageData;
subImageData.subImage = subImage;
subImageData.lineRect = subImageLineRect;
subImageData.imageWithoutLine = currentProjectImage.copy(subImageLineRect);

QPainter painter(&currentProjectImage);
// Clip drawing to subimage
painter.setClipRect(subImageLineRect);
// Draw line with offset to subimage
mCanvas->drawLine(&painter, point1 + offset, point2 + offset, mode);
painter.end();

subImageData.imageWithLine = currentProjectImage.copy(subImageLineRect);
subImageDatas.append(subImageData);
}

qCDebug(lcApplyPixelLineCommand) << "constructed" << this;
}

Expand All @@ -48,13 +74,17 @@ ApplyPixelLineCommand::~ApplyPixelLineCommand()
void ApplyPixelLineCommand::undo()
{
qCDebug(lcApplyPixelLineCommand) << "undoing" << this;
mCanvas->applyPixelLineTool(mLayerIndex, mImageWithoutLine, mLineRect, mOldLastPixelPenReleaseScenePos);
for (auto const &subImageData : subImageDatas) {
mCanvas->applyPixelLineTool(mLayerIndex, subImageData.imageWithoutLine, subImageData.lineRect, mOldLastPixelPenReleaseScenePos);
}
}

void ApplyPixelLineCommand::redo()
{
qCDebug(lcApplyPixelLineCommand) << "redoing" << this;
mCanvas->applyPixelLineTool(mLayerIndex, mImageWithLine, mLineRect, mNewLastPixelPenReleaseScenePos);
for (auto const &subImageData : subImageDatas) {
mCanvas->applyPixelLineTool(mLayerIndex, subImageData.imageWithLine, subImageData.lineRect, mNewLastPixelPenReleaseScenePos);
}
}

int ApplyPixelLineCommand::id() const
Expand All @@ -71,7 +101,7 @@ QDebug operator<<(QDebug debug, const ApplyPixelLineCommand *command)
{
debug.nospace() << "(ApplyPixelLineCommand"
<< " layerIndex=" << command->mLayerIndex
<< ", lineRect" << command->mLineRect
// << ", lineRect" << command->mLineRect
<< ", newLastPixelPenReleaseScenePos=" << command->mNewLastPixelPenReleaseScenePos
<< ", oldLastPixelPenReleaseScenePos=" << command->mOldLastPixelPenReleaseScenePos
<< ")";
Expand Down
21 changes: 13 additions & 8 deletions lib/applypixellinecommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
class SLATE_EXPORT ApplyPixelLineCommand : public QUndoCommand
{
public:
ApplyPixelLineCommand(ImageCanvas *canvas, int layerIndex, const QImage &imageWithLine,
const QImage &imageWithoutLine, const QRect &lineRect, const QPoint &newLastPixelPenReleaseScenePos,
const QPoint &oldLastPixelPenReleaseScenePos, QUndoCommand *parent = nullptr);
ApplyPixelLineCommand(ImageCanvas *canvas, int layerIndex, QImage &currentProjectImage, const QPointF point1, const QPointF point2,
const QPointF &newLastPixelPenReleaseScenePos, const QPointF &oldLastPixelPenReleaseScenePos,
const QPainter::CompositionMode mode, QUndoCommand *parent = nullptr);
~ApplyPixelLineCommand();

void undo() override;
Expand All @@ -46,11 +46,16 @@ class SLATE_EXPORT ApplyPixelLineCommand : public QUndoCommand

ImageCanvas *mCanvas;
int mLayerIndex;
QImage mImageWithLine;
QImage mImageWithoutLine;
QRect mLineRect;
QPoint mNewLastPixelPenReleaseScenePos;
QPoint mOldLastPixelPenReleaseScenePos;
QPointF mNewLastPixelPenReleaseScenePos;
QPointF mOldLastPixelPenReleaseScenePos;

struct SubImageData {
ImageCanvas::SubImage subImage;
QRect lineRect;
QImage imageWithoutLine;
QImage imageWithLine;
};
QList<SubImageData> subImageDatas;
};


Expand Down
3 changes: 2 additions & 1 deletion lib/canvaspane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void CanvasPane::reset()
QDebug operator<<(QDebug debug, const CanvasPane *pane)
{
QDebugStateSaver stateSaver(debug);
debug.nospace() << "(CanvasPane offset=" << pane->integerOffset()
debug.nospace() << "(CanvasPane objectName=" << pane->objectName()
<< "offset=" << pane->integerOffset()
<< " size=" << pane->size()
<< " zoomLevel=" << pane->zoomLevel()
<< ")";
Expand Down
2 changes: 1 addition & 1 deletion lib/canvaspane.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ class SLATE_EXPORT CanvasPane : public QObject
bool mSceneCentered;
};

QDebug operator<<(QDebug debug, const CanvasPane *pane);
SLATE_EXPORT QDebug operator<<(QDebug debug, const CanvasPane *pane);

#endif // CANVASPANE_H
Loading

0 comments on commit d9e2481

Please sign in to comment.