From 4217b00d88875a1fa898592a6611b52b4e8a8f51 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Thu, 23 Jan 2020 16:37:55 +0100 Subject: [PATCH] scrolol ready --- src/GUI/IntelliPhotoGui.cpp | 9 +++++++-- src/GUI/IntelliPhotoGui.h | 2 +- src/Layer/PaintingArea.cpp | 21 ++++++++++++--------- src/Layer/PaintingArea.h | 4 ++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index cddc0ed..1600370 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -7,6 +7,8 @@ #include "QCloseEvent" #include "QScrollBar" +#include + // IntelliPhotoGui constructor IntelliPhotoGui::IntelliPhotoGui(){ // create Gui elements and lay them out @@ -19,7 +21,7 @@ IntelliPhotoGui::IntelliPhotoGui(){ setIntelliStyle(); // Size the app resize(600,600); - setDefaultToolValue(); + setDefaultValues(); } // User tried to close the app @@ -118,6 +120,8 @@ void IntelliPhotoGui::slotChangeDim(){ int height = IntelliInputDialog::getInt("New Canvas Size", "Height:", 600, 1, 50000, 1, &ok2); + + // Change dimension if (ok1&&ok2) { paintingArea->setLayerDimensions(width,height); @@ -768,6 +772,7 @@ void IntelliPhotoGui::createGui(){ mainLayout->addWidget(dimActive,13,2,1,2); mainLayout->addWidget(dimCanvas,14,2,1,2); mainLayout->setHorizontalSpacing(0); + } void IntelliPhotoGui::setIntelliStyle(){ @@ -828,7 +833,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){ } } -void IntelliPhotoGui::setDefaultToolValue(){ +void IntelliPhotoGui::setDefaultValues(){ slotEnterPressed(); } diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 7a20ccc..8cf59fe 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -110,7 +110,7 @@ bool maybeSave(); bool saveFile(const QByteArray &fileFormat); //basic to set tool values to begin -void setDefaultToolValue(); +void setDefaultValues(); // What we'll draw on PaintingArea* paintingArea; diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 334a4d4..48774a1 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -54,6 +54,9 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ this->maxHeight = maxHeight; Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); + this->offsetXDimension = maxWidth/2; + this->offsetYDimension = maxHeight/2; + // Roots the widget to the top left even if resized setAttribute(Qt::WA_StaticContents); @@ -265,12 +268,12 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){ } if(Tool == nullptr) return; - int x = event->x() - layerBundle[static_cast(activeLayer)].widthOffset; - int y = event->y() - layerBundle[static_cast(activeLayer)].heightOffset; + int x = event->x() - layerBundle[static_cast(activeLayer)].widthOffset-offsetXDimension; + int y = event->y() - layerBundle[static_cast(activeLayer)].heightOffset-offsetYDimension; if(event->button() == Qt::LeftButton) { - Tool->onMouseLeftPressed(x, y); + Tool->onMouseLeftPressed(x, y); }else if(event->button() == Qt::RightButton) { - Tool->onMouseRightPressed(x, y); + Tool->onMouseRightPressed(x, y); } update(); } @@ -284,8 +287,8 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){ } if(Tool == nullptr) return; - int x = event->x() - layerBundle[static_cast(activeLayer)].widthOffset; - int y = event->y() - layerBundle[static_cast(activeLayer)].heightOffset; + int x = event->x() - layerBundle[static_cast(activeLayer)].widthOffset-offsetXDimension; + int y = event->y() - layerBundle[static_cast(activeLayer)].heightOffset-offsetYDimension; Tool->onMouseMoved(x, y); update(); } @@ -296,8 +299,8 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){ return; if(Tool == nullptr) return; - int x = event->x() - layerBundle[static_cast(activeLayer)].widthOffset; - int y = event->y() - layerBundle[static_cast(activeLayer)].heightOffset; + int x = event->x() - layerBundle[static_cast(activeLayer)].widthOffset-offsetXDimension; + int y = event->y() - layerBundle[static_cast(activeLayer)].heightOffset-offsetYDimension; if(event->button() == Qt::LeftButton) { Tool->onMouseLeftReleased(x, y); }else if(event->button() == Qt::RightButton) { @@ -332,7 +335,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){ //calulate image here for scroll //Todo set offset in first to parameters and calulate them into mouse position - painter.drawImage(0, 0, *Canvas, 0, 0); + painter.drawImage(0, 0, *Canvas, -offsetXDimension, -offsetYDimension); update(); } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 731e972..fb8ac02 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -222,6 +222,10 @@ void wheelEvent(QWheelEvent*event) override; void paintEvent(QPaintEvent*event) override; private: +//offset for the displayable +int offsetXDimension; +int offsetYDimension; + void setLayerDimensions(int maxWidth, int maxHeight); void selectLayerUp(); void selectLayerDown();