From 67a72fe4879f6e26c55dc49df623bc22d195b161 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Mon, 16 Dec 2019 19:23:56 +0100 Subject: [PATCH] Scroll implemented --- src/Layer/PaintingArea.cpp | 10 +++++++++- src/Layer/PaintingArea.h | 1 + src/Tool/IntelliTool.cpp | 4 ++++ src/Tool/IntelliTool.h | 2 ++ src/Tool/IntelliToolCircle.cpp | 12 ++++++++++-- src/Tool/IntelliToolCircle.h | 12 +++++++----- src/Tool/IntelliToolLine.cpp | 8 ++++++++ src/Tool/IntelliToolLine.h | 2 ++ src/Tool/IntelliToolPen.cpp | 8 ++++++++ src/Tool/IntelliToolPen.h | 2 ++ src/Tool/IntelliToolPlain.cpp | 4 ++++ src/Tool/IntelliToolPlain.h | 13 ++++++++----- src/Tool/IntelliToolRechteck.cpp | 8 ++++++++ src/Tool/IntelliToolRechteck.h | 2 ++ 14 files changed, 75 insertions(+), 13 deletions(-) diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 4ec5ea3..1783a40 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -19,7 +19,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ //test yout tool here and reset after accomplished test - this->Tool = nullptr; + this->Tool = new IntelliToolRechteck(this, &colorPicker); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); @@ -234,6 +234,14 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event){ update(); } +void PaintingArea::wheelEvent(QWheelEvent *event){ + QPoint numDegrees = event->angleDelta() / 8; + if(!numDegrees.isNull()){ + QPoint numSteps = numDegrees / 15; + Tool->onWheelScrolled(numSteps.y()*-1); + } +} + // QPainter provides functions to draw on the widget // The QPaintEvent is sent to widgets that need to // update themselves diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index a4ec3fa..fa85425 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -70,6 +70,7 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; + void wheelEvent(QWheelEvent *event) override; // Updates the painting area where we are painting void paintEvent(QPaintEvent *event) override; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 606459c..608770e 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -43,6 +43,10 @@ void IntelliTool::onMouseMoved(int x, int y){ Canvas->image->calculateVisiblity(); } +void IntelliTool::onWheelScrolled(int value){ + //if needed for future general tasks implement in here +} + void IntelliTool::createToolLayer(){ Area->createTempLayerAfter(Area->activeLayer); this->Active=&Area->layerBundle[Area->activeLayer]; diff --git a/src/Tool/IntelliTool.h b/src/Tool/IntelliTool.h index b534257..2531a55 100644 --- a/src/Tool/IntelliTool.h +++ b/src/Tool/IntelliTool.h @@ -29,6 +29,8 @@ public: virtual void onMouseLeftPressed(int x, int y); virtual void onMouseLeftReleased(int x, int y); + virtual void onWheelScrolled(int value); + virtual void onMouseMoved(int x, int y); }; #endif diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp index 7e16e77..a129d7d 100644 --- a/src/Tool/IntelliToolCircle.cpp +++ b/src/Tool/IntelliToolCircle.cpp @@ -27,8 +27,8 @@ void IntelliToolCircle::drawCyrcle(int radius){ this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1); } - //TODO implement circle drawing algorithm - radius = radius +(this->edgeWidth/2.)-0.5; + //TODO implement circle drawing algorithm bresenham + radius = radius +(this->edgeWidth/2.)-1.; yMin = (Middle.y()-radius); yMax = (Middle.y()+radius); for(int i=yMin; i<=yMax; i++){ @@ -68,6 +68,14 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){ IntelliTool::onMouseLeftReleased(x,y); } +void IntelliToolCircle::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->edgeWidth+=value; + if(this->edgeWidth<=0){ + this->edgeWidth=1; + } +} + void IntelliToolCircle::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); if(this->drawing){ diff --git a/src/Tool/IntelliToolCircle.h b/src/Tool/IntelliToolCircle.h index 93e7af3..488bdb4 100644 --- a/src/Tool/IntelliToolCircle.h +++ b/src/Tool/IntelliToolCircle.h @@ -15,12 +15,14 @@ public: IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker); virtual ~IntelliToolCircle() override; - virtual void onMouseRightPressed(int x, int y); - virtual void onMouseRightReleased(int x, int y); - virtual void onMouseLeftPressed(int x, int y); - virtual void onMouseLeftReleased(int x, int y); + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; - virtual void onMouseMoved(int x, int y); + virtual void onWheelScrolled(int value) override; + + virtual void onMouseMoved(int x, int y) override; }; #endif // INTELLITOOLCIRCLE_H diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index b3f1bf7..0b088cd 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -34,6 +34,14 @@ void IntelliToolLine::onMouseLeftReleased(int x, int y){ IntelliTool::onMouseLeftReleased(x,y); } +void IntelliToolLine::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->lineWidth+=value; + if(this->lineWidth<=0){ + this->lineWidth=1; + } +} + void IntelliToolLine::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); if(this->drawing){ diff --git a/src/Tool/IntelliToolLine.h b/src/Tool/IntelliToolLine.h index ffde866..af1f874 100644 --- a/src/Tool/IntelliToolLine.h +++ b/src/Tool/IntelliToolLine.h @@ -24,6 +24,8 @@ public: virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override; + virtual void onWheelScrolled(int value) override; + virtual void onMouseMoved(int x, int y) override; }; diff --git a/src/Tool/IntelliToolPen.cpp b/src/Tool/IntelliToolPen.cpp index 14db6dd..8012970 100644 --- a/src/Tool/IntelliToolPen.cpp +++ b/src/Tool/IntelliToolPen.cpp @@ -40,3 +40,11 @@ void IntelliToolPen::onMouseMoved(int x, int y){ } IntelliTool::onMouseMoved(x,y); } + +void IntelliToolPen::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->penWidth+=value; + if(this->penWidth<=0){ + this->penWidth=1; + } +} diff --git a/src/Tool/IntelliToolPen.h b/src/Tool/IntelliToolPen.h index a5acc49..c923ddd 100644 --- a/src/Tool/IntelliToolPen.h +++ b/src/Tool/IntelliToolPen.h @@ -17,6 +17,8 @@ public: virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override; + virtual void onWheelScrolled(int value) override; + virtual void onMouseMoved(int x, int y) override; }; diff --git a/src/Tool/IntelliToolPlain.cpp b/src/Tool/IntelliToolPlain.cpp index aaa2a02..34e3c5f 100644 --- a/src/Tool/IntelliToolPlain.cpp +++ b/src/Tool/IntelliToolPlain.cpp @@ -28,3 +28,7 @@ void IntelliToolPlainTool::onMouseRightReleased(int x, int y){ void IntelliToolPlainTool::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); } + +void IntelliToolPlainTool::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); +} diff --git a/src/Tool/IntelliToolPlain.h b/src/Tool/IntelliToolPlain.h index 9ff1b7a..aad7633 100644 --- a/src/Tool/IntelliToolPlain.h +++ b/src/Tool/IntelliToolPlain.h @@ -8,11 +8,14 @@ class IntelliToolPlainTool : public IntelliTool{ public: IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker); - void onMouseLeftPressed(int x, int y) override; - void onMouseLeftReleased(int x, int y) override; - void onMouseRightPressed(int x, int y) override; - void onMouseRightReleased(int x, int y) override; - void onMouseMoved(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + + virtual void onWheelScrolled(int value) override; + + virtual void onMouseMoved(int x, int y) override; }; diff --git a/src/Tool/IntelliToolRechteck.cpp b/src/Tool/IntelliToolRechteck.cpp index ded8346..05b1e79 100644 --- a/src/Tool/IntelliToolRechteck.cpp +++ b/src/Tool/IntelliToolRechteck.cpp @@ -58,3 +58,11 @@ void IntelliToolRechteck::onMouseMoved(int x, int y){ } IntelliTool::onMouseMoved(x,y); } + +void IntelliToolRechteck::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->edgeWidth+=value; + if(this->edgeWidth<=0){ + this->edgeWidth=1; + } +} diff --git a/src/Tool/IntelliToolRechteck.h b/src/Tool/IntelliToolRechteck.h index 76886bc..f3db883 100644 --- a/src/Tool/IntelliToolRechteck.h +++ b/src/Tool/IntelliToolRechteck.h @@ -21,6 +21,8 @@ public: virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override; + virtual void onWheelScrolled(int value) override; + virtual void onMouseMoved(int x, int y) override; };