Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit StrokeManager use to stroke tools #1814

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core_lib/core_lib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HEADERS += \
src/tool/polylinetool.h \
src/tool/selecttool.h \
src/tool/smudgetool.h \
src/tool/strokemanager.h \
src/tool/strokeinterpolator.h \
src/tool/stroketool.h \
src/util/blitrect.h \
src/util/cameraeasingtype.h \
Expand Down Expand Up @@ -169,7 +169,7 @@ SOURCES += src/graphics/bitmap/bitmapimage.cpp \
src/tool/polylinetool.cpp \
src/tool/selecttool.cpp \
src/tool/smudgetool.cpp \
src/tool/strokemanager.cpp \
src/tool/strokeinterpolator.cpp \
src/tool/stroketool.cpp \
src/util/blitrect.cpp \
src/util/cameraeasingtype.cpp \
Expand Down
32 changes: 9 additions & 23 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GNU General Public License for more details.
#include <QGuiApplication>
#include <QMessageBox>
#include <QPixmapCache>
#include <QTimer>

#include "pointerevent.h"
#include "beziercurve.h"
Expand All @@ -38,7 +39,6 @@ GNU General Public License for more details.

#include "colormanager.h"
#include "toolmanager.h"
#include "strokemanager.h"
#include "layermanager.h"
#include "playbackmanager.h"
#include "viewmanager.h"
Expand All @@ -54,8 +54,6 @@ ScribbleArea::ScribbleArea(QWidget* parent) : QWidget(parent),
// Qt::WA_StaticContents ensure that the widget contents are rooted to the top-left corner
// and don't change when the widget is resized.
setAttribute(Qt::WA_StaticContents);

mStrokeManager.reset(new StrokeManager);
}

ScribbleArea::~ScribbleArea()
Expand Down Expand Up @@ -573,7 +571,7 @@ void ScribbleArea::wheelEvent(QWheelEvent* event)

void ScribbleArea::tabletEvent(QTabletEvent *e)
{
PointerEvent event(e);
PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->posF()));

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (event.pointerType() == QPointingDevice::PointerType::Eraser)
Expand All @@ -591,8 +589,6 @@ void ScribbleArea::tabletEvent(QTabletEvent *e)
if (event.eventType() == PointerEvent::Press)
{
event.accept();
mStrokeManager->pointerPressEvent(&event);
mStrokeManager->setTabletInUse(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointer events now passed to strokemanager from stroke tools, tabletinuse now managed implicitly by strokemanager

if (mIsFirstClick)
{
mIsFirstClick = false;
Expand All @@ -601,7 +597,8 @@ void ScribbleArea::tabletEvent(QTabletEvent *e)
}
else
{
qreal distance = QLineF(currentTool()->getCurrentPressPoint(), currentTool()->getLastPressPoint()).length();
qreal distance = QLineF(e->posF(), mTabletPressPos).length();
mTabletPressPos = e->posF();

if (mDoubleClickMillis <= DOUBLE_CLICK_THRESHOLD && distance < 5.0) {
currentTool()->pointerDoubleClickEvent(&event);
Expand All @@ -618,7 +615,6 @@ void ScribbleArea::tabletEvent(QTabletEvent *e)
{
if (!(event.buttons() & (Qt::LeftButton | Qt::RightButton)) || mTabletInUse)
{
mStrokeManager->pointerMoveEvent(&event);
pointerMoveEvent(&event);
}
}
Expand All @@ -628,9 +624,7 @@ void ScribbleArea::tabletEvent(QTabletEvent *e)
mMouseFilterTimer->start();
if (mTabletInUse)
{
mStrokeManager->pointerReleaseEvent(&event);
pointerReleaseEvent(&event);
mStrokeManager->setTabletInUse(false);
mTabletInUse = false;
}
}
Expand Down Expand Up @@ -733,41 +727,33 @@ void ScribbleArea::mousePressEvent(QMouseEvent* e)
return;
}

PointerEvent event(e);

mStrokeManager->pointerPressEvent(&event);

PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos()));
pointerPressEvent(&event);
mMouseInUse = event.isAccepted();
}

void ScribbleArea::mouseMoveEvent(QMouseEvent* e)
{
if (mTabletInUse || (mMouseFilterTimer->isActive() && mTabletReleaseMillisAgo < MOUSE_FILTER_THRESHOLD)) { e->ignore(); return; }
PointerEvent event(e);

mStrokeManager->pointerMoveEvent(&event);

PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos()));
pointerMoveEvent(&event);
}

void ScribbleArea::mouseReleaseEvent(QMouseEvent* e)
{
if (mTabletInUse || (mMouseFilterTimer->isActive() && mTabletReleaseMillisAgo < MOUSE_FILTER_THRESHOLD)) { e->ignore(); return; }
PointerEvent event(e);

mStrokeManager->pointerReleaseEvent(&event);

PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos()));
pointerReleaseEvent(&event);
mMouseInUse = (e->buttons() & Qt::RightButton) || (e->buttons() & Qt::LeftButton);
}

void ScribbleArea::mouseDoubleClickEvent(QMouseEvent* e)
{
if (mStrokeManager->isTabletInUse()) { e->ignore(); return; }
PointerEvent event(e);
mStrokeManager->pointerPressEvent(&event);
if (mTabletInUse) { e->ignore(); return; }

PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos()));
currentTool()->pointerDoubleClickEvent(&event);
}

Expand Down
5 changes: 1 addition & 4 deletions core_lib/src/interface/scribblearea.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ GNU General Public License for more details.
#include "canvaspainter.h"
#include "overlaypainter.h"
#include "preferencemanager.h"
#include "strokemanager.h"
#include "selectionpainter.h"
#include "camerapainter.h"
#include "tiledbuffer.h"
Expand All @@ -63,7 +62,6 @@ class ScribbleArea : public QWidget

bool init();
void setEditor(Editor* e) { mEditor = e; }
StrokeManager* getStrokeManager() const { return mStrokeManager.get(); }
Editor* editor() const { return mEditor; }

void deleteSelection();
Expand Down Expand Up @@ -217,8 +215,6 @@ public slots:
BitmapImage* currentBitmapImage(Layer* layer) const;
VectorImage* currentVectorImage(Layer* layer) const;

std::unique_ptr<StrokeManager> mStrokeManager;

Editor* mEditor = nullptr;

LayerVisibility mLayerVisibility = LayerVisibility::ALL;
Expand Down Expand Up @@ -246,6 +242,7 @@ public slots:
// Microsoft suggests that a double click action should be no more than 500 ms
const int DOUBLE_CLICK_THRESHOLD = 500;
QTimer* mDoubleClickTimer = nullptr;
QPointF mTabletPressPos;
int mTabletReleaseMillisAgo;
const int MOUSE_FILTER_THRESHOLD = 200;

Expand Down
47 changes: 3 additions & 44 deletions core_lib/src/tool/basetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GNU General Public License for more details.
#include "editor.h"
#include "viewmanager.h"
#include "scribblearea.h"
#include "strokemanager.h"
#include "strokeinterpolator.h"
#include "pointerevent.h"

QString BaseTool::TypeName(ToolType type)
Expand Down Expand Up @@ -81,7 +81,6 @@ void BaseTool::initialize(Editor* editor)
mScribbleArea = editor->getScribbleArea();
Q_ASSERT(mScribbleArea);

mStrokeManager = mEditor->getScribbleArea()->getStrokeManager();
loadSettings();
}

Expand Down Expand Up @@ -119,49 +118,9 @@ bool BaseTool::isDrawingTool()
return true;
}

bool BaseTool::isActive()
bool BaseTool::isActive() const
{
return strokeManager()->isActive();
}

QPointF BaseTool::getCurrentPressPixel() const
{
return strokeManager()->getCurrentPressPixel();
}

QPointF BaseTool::getCurrentPressPoint() const
{
return mEditor->view()->mapScreenToCanvas(strokeManager()->getCurrentPressPixel());
}

QPointF BaseTool::getCurrentPixel() const
{
return strokeManager()->getCurrentPixel();
}

QPointF BaseTool::getCurrentPoint() const
{
return mEditor->view()->mapScreenToCanvas(getCurrentPixel());
}

QPointF BaseTool::getLastPixel() const
{
return strokeManager()->getLastPixel();
}

QPointF BaseTool::getLastPoint() const
{
return mEditor->view()->mapScreenToCanvas(getLastPixel());
}

QPointF BaseTool::getLastPressPixel() const
{
return strokeManager()->getLastPressPixel();
}

QPointF BaseTool::getLastPressPoint() const
{
return mEditor->view()->mapScreenToCanvas(getLastPressPixel());
return false;
}

void BaseTool::setWidth(const qreal width)
Expand Down
16 changes: 1 addition & 15 deletions core_lib/src/tool/basetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ScribbleArea;
class QKeyEvent;
class QMouseEvent;
class QTabletEvent;
class StrokeManager;
class PointerEvent;

class Properties
Expand Down Expand Up @@ -101,7 +100,7 @@ class BaseTool : public QObject
*
* @return Returns true if the tool is currently active, else returns false.
*/
virtual bool isActive();
virtual bool isActive() const;

virtual void setWidth(const qreal width);
virtual void setFeather(const qreal feather);
Expand Down Expand Up @@ -136,33 +135,20 @@ class BaseTool : public QObject

Properties properties;

QPointF getCurrentPressPixel() const;
QPointF getCurrentPressPoint() const;
QPointF getCurrentPixel() const;
QPointF getCurrentPoint() const;
QPointF getLastPixel() const;
QPointF getLastPoint() const;
QPointF getLastPressPixel() const;
QPointF getLastPressPoint() const;

bool isPropertyEnabled(ToolPropertyType t) { return mPropertyEnabled[t]; }
bool isDrawingTool();

signals:
bool isActiveChanged(ToolType, bool);

protected:
StrokeManager* strokeManager() const { return mStrokeManager; }
Editor* editor() { return mEditor; }

QHash<ToolPropertyType, bool> mPropertyEnabled;

Editor* mEditor = nullptr;
ScribbleArea* mScribbleArea = nullptr;
QList<QMetaObject::Connection> mActiveConnections;

private:
StrokeManager* mStrokeManager = nullptr;
};

#endif // BASETOOL_H
14 changes: 9 additions & 5 deletions core_lib/src/tool/brushtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ GNU General Public License for more details.
#include "vectorimage.h"
#include "editor.h"
#include "colormanager.h"
#include "strokemanager.h"
#include "layermanager.h"
#include "viewmanager.h"
#include "selectionmanager.h"
Expand Down Expand Up @@ -141,6 +140,7 @@ QCursor BrushTool::cursor()

void BrushTool::pointerPressEvent(PointerEvent *event)
{
mInterpolator.pointerPressEvent(event);
if (handleQuickSizing(event)) {
return;
}
Expand All @@ -155,23 +155,27 @@ void BrushTool::pointerPressEvent(PointerEvent *event)

void BrushTool::pointerMoveEvent(PointerEvent* event)
{
mInterpolator.pointerMoveEvent(event);
if (handleQuickSizing(event)) {
return;
}

if (event->buttons() & Qt::LeftButton && event->inputType() == mCurrentInputType)
{
mCurrentPressure = strokeManager()->getPressure();
mCurrentPressure = mInterpolator.getPressure();
drawStroke();
if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel())
strokeManager()->setStabilizerLevel(properties.stabilizerLevel);
if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel())
{
mInterpolator.setStabilizerLevel(properties.stabilizerLevel);
}
}

StrokeTool::pointerMoveEvent(event);
}

void BrushTool::pointerReleaseEvent(PointerEvent *event)
{
mInterpolator.pointerReleaseEvent(event);
if (handleQuickSizing(event)) {
return;
}
Expand Down Expand Up @@ -223,7 +227,7 @@ void BrushTool::paintAt(QPointF point)
void BrushTool::drawStroke()
{
StrokeTool::drawStroke();
QList<QPointF> p = strokeManager()->interpolateStroke();
QList<QPointF> p = mInterpolator.interpolateStroke();

Layer* layer = mEditor->layers()->currentLayer();

Expand Down
Loading
Loading