From 8e187ba6b369912a084c00c1f53bb7440be22404 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Wed, 22 Jan 2020 21:19:24 +0100 Subject: [PATCH 1/3] basics of zoom and scroll --- src/GUI/IntelliPhotoGui.cpp | 16 ++++++--- src/GUI/IntelliPhotoGui.h | 70 +++++++++++++++++++++++-------------- src/Layer/PaintingArea.cpp | 17 +++++---- src/Layer/PaintingArea.h | 5 +-- src/Tool/IntelliTool.cpp | 4 +-- 5 files changed, 71 insertions(+), 41 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 5734d47..9fec611 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -18,7 +18,6 @@ IntelliPhotoGui::IntelliPhotoGui(){ setIntelliStyle(); // Size the app resize(600,600); - showMaximized(); setDefaultToolValue(); } @@ -550,6 +549,7 @@ void IntelliPhotoGui::createMenus(){ layerCreationMenu = new QMenu(tr("&Create new Layer"), this); layerCreationMenu->addAction(actionCreateNewRasterLayer); layerCreationMenu->addAction(actionCreateNewShapedLayer); + // Attach all actions to Layer layerMenu = new QMenu(tr("&Layer"), this); layerMenu->addMenu(layerCreationMenu); @@ -626,7 +626,7 @@ void IntelliPhotoGui::createGui(){ // create Gui elements // get and set max width and height paintingArea = new PaintingArea(1280, 720); - paintingArea->DummyGui = this; + paintingArea->guiReference = this; preview = QPixmap(":/Icons/Buttons/icons/circle-tool.svg"); CircleButton = new QPushButton(); @@ -740,8 +740,14 @@ void IntelliPhotoGui::createGui(){ QString String = QString("%1x%2").arg(paintingArea->Canvas->width()).arg(paintingArea->Canvas->height()); dimCanvas->setText(String); + ScrollArea = new QScrollArea(this); + ScrollArea->setBackgroundRole(QPalette::Dark); + ScrollArea->setWidget(paintingArea); + ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + // set gui elements - mainLayout->addWidget(paintingArea,1,1,20,1); + mainLayout->addWidget(ScrollArea,1,1,20,1); mainLayout->addWidget(CircleButton,1,2,1,1); mainLayout->addWidget(FloodFillButton,1,3,1,1); mainLayout->addWidget(LineButton,2,2,1,1); @@ -846,7 +852,9 @@ void IntelliPhotoGui::UpdateGui(){ tmp.fill(Qt::transparent); preview = preview.fromImage(tmp); } - ActiveLayerImageLabel->setPixmap(preview.scaled(Buttonsize * 2)); + + + ActiveLayerImageLabel->setPixmap(preview.scaled(Buttonsize * 2)); string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); FirstColorButton->setStyleSheet(string); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 8d164a4..7a20ccc 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "IntelliInputDialog.h" //for unit testing @@ -96,10 +97,11 @@ void slotSetInnerAlpha(); void slotResetTools(); private: + +//setup functions for gui void createActions(); void createMenus(); void createGui(); -// Set the style of the GUI void setIntelliStyle(); // Will check if changes have occurred since last save @@ -107,13 +109,19 @@ bool maybeSave(); // Opens the Save dialog and saves bool saveFile(const QByteArray &fileFormat); +//basic to set tool values to begin void setDefaultToolValue(); // What we'll draw on PaintingArea* paintingArea; -const QSize Buttonsize = QSize(35,35); +//used to display a preview of the active layer QPixmap preview; + +//size of all buttons +const QSize Buttonsize = QSize(35,35); + +//buttons used for gui QPushButton* CircleButton; QPushButton* FloodFillButton; QPushButton* LineButton; @@ -121,35 +129,42 @@ QPushButton* PenButton; QPushButton* PlainButton; QPushButton* PolygonButton; QPushButton* RectangleButton; -QLabel* WidthLine; -QLabel* innerAlphaLine; -QLineEdit* EditLineWidth; -QLineEdit* EditLineInnerAlpha; -QIntValidator* ValidatorLineWidth; -QIntValidator* ValidatorInnerAlpha; - QPushButton* FirstColorButton; QPushButton* SecondColorButton; QPushButton* SwitchColorButton; - -QLabel* ActiveLayerLine; -QLabel* ActiveLayerImageLabel; - QPushButton* dimActive; QPushButton* dimCanvas; +//labels used for gui +QLabel* WidthLine; +QLabel* innerAlphaLine; +QLabel* ActiveLayerLine; +QLabel* ActiveLayerImageLabel; + +//scroll area to display canvas +QScrollArea* ScrollArea; + +//line edits used for gui +QLineEdit* EditLineWidth; +QLineEdit* EditLineInnerAlpha; + +//int validator used for gui +QIntValidator* ValidatorLineWidth; +QIntValidator* ValidatorInnerAlpha; + + // The menu widgets -QMenu*saveAsMenu; -QMenu*fileMenu; -QMenu*renderMenu; -QMenu*optionMenu; -QMenu*layerCreationMenu; -QMenu*layerMenu; -QMenu*colorMenu; -QMenu*toolCreationMenu; -QMenu*toolSettingsMenu; -QMenu*toolMenu; -QMenu*helpMenu; +QMenu* saveAsMenu; +QMenu* fileMenu; +QMenu* renderMenu; +QMenu* optionMenu; +QMenu* layerCreationMenu; +QMenu* layerMenu; +QMenu* colorMenu; +QMenu* toolCreationMenu; +QMenu* toolSettingsMenu; +QMenu* toolMenu; +QMenu* helpMenu; // All the actions that can occur // meta image actions (need further modularisation) @@ -175,7 +190,9 @@ QAction* actionCreatePolygonTool; QAction* actionCreateFloodFillTool; // dimension actions -QAction*actionChangeDim; +QAction* actionChangeDim; +QAction* actionSetWidth; +QAction* actionSetInnerAlpha; // dialog actions QAction* actionAboutDialog; @@ -198,8 +215,7 @@ QAction* actionMoveLayerDown; // Actions tied to specific file formats QList actionSaveAs; -QAction* actionSetWidth; -QAction* actionSetInnerAlpha; + // main GUI elements QWidget* centralGuiWidget; diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index b471da0..2e23384 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -20,7 +20,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) - : QWidget(parent){ + : QLabel(parent){ this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); @@ -120,7 +120,7 @@ void PaintingArea::setPolygon(int idx){ delete this->Tool; this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); isSettingPolygon = true; - this->DummyGui->setToolWidth(5); + this->guiReference->setToolWidth(5); } } } @@ -174,7 +174,7 @@ void PaintingArea::moveActiveLayer(int idx){ }else if(idx==-1) { this->selectLayerDown(); } - DummyGui->UpdateGui(); + guiReference->UpdateGui(); } void PaintingArea::slotActivateLayer(int a){ @@ -322,11 +322,16 @@ void PaintingArea::wheelEvent(QWheelEvent*event){ // The QPaintEvent is sent to widgets that need to // update themselves void PaintingArea::paintEvent(QPaintEvent*event){ + this->setFixedSize(QSize(maxWidth,maxHeight)); this->drawLayers(); - QPainter painter(this); - QRect dirtyRec = event->rect(); - painter.drawImage(dirtyRec, *Canvas, dirtyRec); + QPainter painter(this); + + //insert zoom factor here + painter.scale(1,1); + + //calulate image here for scroll + painter.drawImage(0,0, *Canvas); update(); } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 58eb411..731e972 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -50,7 +50,7 @@ struct LayerObject { /*! * \brief The PaintingArea class manages the methods and stores information about the current painting area, which is the currently opened project */ -class PaintingArea : public QWidget +class PaintingArea : public QLabel { friend UnitTest; // Declares our class as a QObject which is the base class @@ -228,6 +228,7 @@ void selectLayerDown(); IntelliTool* copyActiveTool(); QImage* Canvas; +QImage ScaledCanvas; int maxWidth; int maxHeight; @@ -235,7 +236,7 @@ bool isSettingPolygon = false; IntelliRenderSettings renderSettings; IntelliTool* Tool; -IntelliPhotoGui* DummyGui; +IntelliPhotoGui* guiReference; std::vector layerBundle; int activeLayer = -1; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 11ed60b..0088f05 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -50,7 +50,7 @@ void IntelliTool::onMouseMoved(int x, int y){ void IntelliTool::onWheelScrolled(int value){ //if needed for future general tasks implement in here - Area->DummyGui->setToolWidth(value + Toolsettings->getLineWidth()); + Area->guiReference->setToolWidth(value + Toolsettings->getLineWidth()); } bool IntelliTool::createToolLayer(){ @@ -88,7 +88,7 @@ void IntelliTool::mergeToolLayer(){ if(Canvas->image->getPolygonData().size() > 0) { activeLayer->image->setPolygon(Canvas->image->getPolygonData()); } - Area->DummyGui->UpdateGui(); + Area->guiReference->UpdateGui(); } void IntelliTool::deleteToolLayer(){ From 651bf806fc7fe5eac9e8bf541582ba26660b6c4d Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Wed, 22 Jan 2020 21:52:08 +0100 Subject: [PATCH 2/3] upset for future work --- src/GUI/IntelliPhotoGui.cpp | 1 + src/Layer/PaintingArea.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 9fec611..cddc0ed 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -5,6 +5,7 @@ #include "QEvent" #include "QCloseEvent" +#include "QScrollBar" // IntelliPhotoGui constructor IntelliPhotoGui::IntelliPhotoGui(){ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 2e23384..334a4d4 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -322,7 +322,7 @@ void PaintingArea::wheelEvent(QWheelEvent*event){ // The QPaintEvent is sent to widgets that need to // update themselves void PaintingArea::paintEvent(QPaintEvent*event){ - this->setFixedSize(QSize(maxWidth,maxHeight)); + this->setFixedSize(QSize(maxWidth*2,maxHeight*2)); this->drawLayers(); QPainter painter(this); @@ -331,7 +331,8 @@ void PaintingArea::paintEvent(QPaintEvent*event){ painter.scale(1,1); //calulate image here for scroll - painter.drawImage(0,0, *Canvas); + //Todo set offset in first to parameters and calulate them into mouse position + painter.drawImage(0, 0, *Canvas, 0, 0); update(); } From 4217b00d88875a1fa898592a6611b52b4e8a8f51 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Thu, 23 Jan 2020 16:37:55 +0100 Subject: [PATCH 3/3] 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();