Merge branch 'dev-scrollbar' into dev-history

This commit is contained in:
Jonas Mucke
2020-01-23 20:32:38 +01:00
5 changed files with 94 additions and 52 deletions

View File

@@ -20,8 +20,7 @@ IntelliPhotoGui::IntelliPhotoGui(){
setIntelliStyle(); setIntelliStyle();
// Size the app // Size the app
resize(600,600); resize(600,600);
showMaximized(); setDefaultValues();
setDefaultToolValue();
} }
// User tried to close the app // User tried to close the app
@@ -138,6 +137,8 @@ void IntelliPhotoGui::slotChangeDim(){
int height = IntelliInputDialog::getInt("New Canvas Size", "Height:", 600, 1, 50000, 1, &ok2); int height = IntelliInputDialog::getInt("New Canvas Size", "Height:", 600, 1, 50000, 1, &ok2);
// Change dimension // Change dimension
if (ok1&&ok2) { if (ok1&&ok2) {
paintingArea->setLayerDimensions(width,height); paintingArea->setLayerDimensions(width,height);
@@ -594,6 +595,7 @@ void IntelliPhotoGui::createMenus(){
layerCreationMenu = new QMenu(tr("&Create new Layer"), this); layerCreationMenu = new QMenu(tr("&Create new Layer"), this);
layerCreationMenu->addAction(actionCreateNewRasterLayer); layerCreationMenu->addAction(actionCreateNewRasterLayer);
layerCreationMenu->addAction(actionCreateNewShapedLayer); layerCreationMenu->addAction(actionCreateNewShapedLayer);
// Attach all actions to Layer // Attach all actions to Layer
layerMenu = new QMenu(tr("&Layer"), this); layerMenu = new QMenu(tr("&Layer"), this);
layerMenu->addMenu(layerCreationMenu); layerMenu->addMenu(layerCreationMenu);
@@ -672,7 +674,7 @@ void IntelliPhotoGui::createGui(){
// create Gui elements // create Gui elements
// get and set max width and height // get and set max width and height
paintingArea = new PaintingArea(1280, 720); paintingArea = new PaintingArea(1280, 720);
paintingArea->DummyGui = this; paintingArea->guiReference = this;
preview = QPixmap(":/Icons/Buttons/icons/circle-tool.svg"); preview = QPixmap(":/Icons/Buttons/icons/circle-tool.svg");
CircleButton = new QPushButton(); CircleButton = new QPushButton();
@@ -786,8 +788,14 @@ void IntelliPhotoGui::createGui(){
QString String = QString("%1x%2").arg(paintingArea->Canvas->width()).arg(paintingArea->Canvas->height()); QString String = QString("%1x%2").arg(paintingArea->Canvas->width()).arg(paintingArea->Canvas->height());
dimCanvas->setText(String); 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 // 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(CircleButton,1,2,1,1);
mainLayout->addWidget(FloodFillButton,1,3,1,1); mainLayout->addWidget(FloodFillButton,1,3,1,1);
mainLayout->addWidget(LineButton,2,2,1,1); mainLayout->addWidget(LineButton,2,2,1,1);
@@ -807,6 +815,7 @@ void IntelliPhotoGui::createGui(){
mainLayout->addWidget(dimActive,13,2,1,2); mainLayout->addWidget(dimActive,13,2,1,2);
mainLayout->addWidget(dimCanvas,14,2,1,2); mainLayout->addWidget(dimCanvas,14,2,1,2);
mainLayout->setHorizontalSpacing(0); mainLayout->setHorizontalSpacing(0);
} }
void IntelliPhotoGui::setIntelliStyle(){ void IntelliPhotoGui::setIntelliStyle(){
@@ -871,7 +880,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
} }
} }
void IntelliPhotoGui::setDefaultToolValue(){ void IntelliPhotoGui::setDefaultValues(){
slotEnterPressed(); slotEnterPressed();
} }
@@ -896,7 +905,9 @@ void IntelliPhotoGui::UpdateGui(){
tmp.fill(Qt::transparent); tmp.fill(Qt::transparent);
preview = preview.fromImage(tmp); 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()); string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name());
FirstColorButton->setStyleSheet(string); FirstColorButton->setStyleSheet(string);

View File

@@ -14,6 +14,7 @@
#include <QTextEdit> #include <QTextEdit>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QScrollArea>
#include "IntelliInputDialog.h" #include "IntelliInputDialog.h"
#include "IntelliHelper/IntelliDatamanager.h" #include "IntelliHelper/IntelliDatamanager.h"
@@ -100,10 +101,11 @@ void slotGoBack();
void slotGoForward(); void slotGoForward();
private: private:
//setup functions for gui
void createActions(); void createActions();
void createMenus(); void createMenus();
void createGui(); void createGui();
// Set the style of the GUI
void setIntelliStyle(); void setIntelliStyle();
// Will check if changes have occurred since last save // Will check if changes have occurred since last save
@@ -111,13 +113,19 @@ bool maybeSave();
// Opens the Save dialog and saves // Opens the Save dialog and saves
bool saveFile(const QByteArray &fileFormat); bool saveFile(const QByteArray &fileFormat);
void setDefaultToolValue(); //basic to set tool values to begin
void setDefaultValues();
// What we'll draw on // What we'll draw on
PaintingArea* paintingArea; PaintingArea* paintingArea;
const QSize Buttonsize = QSize(35,35); //used to display a preview of the active layer
QPixmap preview; QPixmap preview;
//size of all buttons
const QSize Buttonsize = QSize(35,35);
//buttons used for gui
QPushButton* CircleButton; QPushButton* CircleButton;
QPushButton* FloodFillButton; QPushButton* FloodFillButton;
QPushButton* LineButton; QPushButton* LineButton;
@@ -125,35 +133,42 @@ QPushButton* PenButton;
QPushButton* PlainButton; QPushButton* PlainButton;
QPushButton* PolygonButton; QPushButton* PolygonButton;
QPushButton* RectangleButton; QPushButton* RectangleButton;
QLabel* WidthLine;
QLabel* innerAlphaLine;
QLineEdit* EditLineWidth;
QLineEdit* EditLineInnerAlpha;
QIntValidator* ValidatorLineWidth;
QIntValidator* ValidatorInnerAlpha;
QPushButton* FirstColorButton; QPushButton* FirstColorButton;
QPushButton* SecondColorButton; QPushButton* SecondColorButton;
QPushButton* SwitchColorButton; QPushButton* SwitchColorButton;
QLabel* ActiveLayerLine;
QLabel* ActiveLayerImageLabel;
QPushButton* dimActive; QPushButton* dimActive;
QPushButton* dimCanvas; 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 // The menu widgets
QMenu*saveAsMenu; QMenu* saveAsMenu;
QMenu*fileMenu; QMenu* fileMenu;
QMenu*renderMenu; QMenu* renderMenu;
QMenu*optionMenu; QMenu* optionMenu;
QMenu*layerCreationMenu; QMenu* layerCreationMenu;
QMenu*layerMenu; QMenu* layerMenu;
QMenu*colorMenu; QMenu* colorMenu;
QMenu*toolCreationMenu; QMenu* toolCreationMenu;
QMenu*toolSettingsMenu; QMenu* toolSettingsMenu;
QMenu*toolMenu; QMenu* toolMenu;
QMenu*helpMenu; QMenu* helpMenu;
// All the actions that can occur // All the actions that can occur
// meta image actions (need further modularisation) // meta image actions (need further modularisation)
@@ -179,7 +194,9 @@ QAction* actionCreatePolygonTool;
QAction* actionCreateFloodFillTool; QAction* actionCreateFloodFillTool;
// dimension actions // dimension actions
QAction*actionChangeDim; QAction* actionChangeDim;
QAction* actionSetWidth;
QAction* actionSetInnerAlpha;
// dialog actions // dialog actions
QAction* actionAboutDialog; QAction* actionAboutDialog;
@@ -202,8 +219,7 @@ QAction* actionMoveLayerDown;
// actions tied to specific file formats // actions tied to specific file formats
QList<QAction*> actionSaveAs; QList<QAction*> actionSaveAs;
QAction* actionSetWidth;
QAction* actionSetInnerAlpha;
// history actions // history actions
QAction* actionGoBack; QAction* actionGoBack;

View File

@@ -37,7 +37,7 @@ LayerObject::LayerObject(const LayerObject& layer){
} }
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){ : QLabel(parent){
this->Tool = nullptr; this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight); this->setLayerDimensions(maxWidth, maxHeight);
@@ -75,6 +75,9 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
this->maxHeight = maxHeight; this->maxHeight = maxHeight;
Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); 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 // Roots the widget to the top left even if resized
setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_StaticContents);
@@ -151,7 +154,7 @@ void PaintingArea::setPolygon(int idx){
delete this->Tool; delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true; isSettingPolygon = true;
this->DummyGui->setToolWidth(5); this->guiReference->setToolWidth(5);
} }
} }
} }
@@ -213,7 +216,7 @@ void PaintingArea::moveActiveLayer(int idx){
}else if(idx==-1) { }else if(idx==-1) {
this->selectLayerDown(); this->selectLayerDown();
} }
DummyGui->UpdateGui(); guiReference->UpdateGui();
historyadd(); historyadd();
} }
@@ -305,12 +308,12 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){
} }
if(Tool == nullptr) if(Tool == nullptr)
return; return;
int x = event->x() - layerBundle[static_cast<size_t>(activeLayer)].widthOffset; int x = event->x() - layerBundle[static_cast<size_t>(activeLayer)].widthOffset-offsetXDimension;
int y = event->y() - layerBundle[static_cast<size_t>(activeLayer)].heightOffset; int y = event->y() - layerBundle[static_cast<size_t>(activeLayer)].heightOffset-offsetYDimension;
if(event->button() == Qt::LeftButton) { if(event->button() == Qt::LeftButton) {
Tool->onMouseLeftPressed(x, y); Tool->onMouseLeftPressed(x, y);
}else if(event->button() == Qt::RightButton) { }else if(event->button() == Qt::RightButton) {
Tool->onMouseRightPressed(x, y); Tool->onMouseRightPressed(x, y);
} }
update(); update();
} }
@@ -324,8 +327,8 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){
} }
if(Tool == nullptr) if(Tool == nullptr)
return; return;
int x = event->x() - layerBundle[static_cast<size_t>(activeLayer)].widthOffset; int x = event->x() - layerBundle[static_cast<size_t>(activeLayer)].widthOffset-offsetXDimension;
int y = event->y() - layerBundle[static_cast<size_t>(activeLayer)].heightOffset; int y = event->y() - layerBundle[static_cast<size_t>(activeLayer)].heightOffset-offsetYDimension;
Tool->onMouseMoved(x, y); Tool->onMouseMoved(x, y);
update(); update();
} }
@@ -336,8 +339,8 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
return; return;
if(Tool == nullptr) if(Tool == nullptr)
return; return;
int x = event->x() - layerBundle[static_cast<size_t>(activeLayer)].widthOffset; int x = event->x() - layerBundle[static_cast<size_t>(activeLayer)].widthOffset-offsetXDimension;
int y = event->y() - layerBundle[static_cast<size_t>(activeLayer)].heightOffset; int y = event->y() - layerBundle[static_cast<size_t>(activeLayer)].heightOffset-offsetYDimension;
if(event->button() == Qt::LeftButton) { if(event->button() == Qt::LeftButton) {
Tool->onMouseLeftReleased(x, y); Tool->onMouseLeftReleased(x, y);
}else if(event->button() == Qt::RightButton) { }else if(event->button() == Qt::RightButton) {
@@ -362,11 +365,17 @@ void PaintingArea::wheelEvent(QWheelEvent*event){
// The QPaintEvent is sent to widgets that need to // The QPaintEvent is sent to widgets that need to
// update themselves // update themselves
void PaintingArea::paintEvent(QPaintEvent*event){ void PaintingArea::paintEvent(QPaintEvent*event){
this->setFixedSize(QSize(maxWidth*2,maxHeight*2));
this->drawLayers(); this->drawLayers();
QPainter painter(this); QPainter painter(this);
QRect dirtyRec = event->rect();
painter.drawImage(dirtyRec, *Canvas, dirtyRec); //insert zoom factor here
painter.scale(1,1);
//calulate image here for scroll
//Todo set offset in first to parameters and calulate them into mouse position
painter.drawImage(0, 0, *Canvas, -offsetXDimension, -offsetYDimension);
update(); update();
} }

View File

@@ -7,6 +7,7 @@
#include <QPoint> #include <QPoint>
#include <QWidget> #include <QWidget>
#include <QList> #include <QList>
#include <QLabel>
#include "Image/IntelliImage.h" #include "Image/IntelliImage.h"
#include "Image/IntelliRasterImage.h" #include "Image/IntelliRasterImage.h"
#include "Image/IntelliShapedImage.h" #include "Image/IntelliShapedImage.h"
@@ -53,7 +54,7 @@ struct LayerObject {
/*! /*!
* \brief The PaintingArea class manages the methods and stores information about the current painting area, which is the currently opened project * \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; friend UnitTest;
// Declares our class as a QObject which is the base class // Declares our class as a QObject which is the base class
@@ -250,11 +251,16 @@ void wheelEvent(QWheelEvent*event) override;
void paintEvent(QPaintEvent*event) override; void paintEvent(QPaintEvent*event) override;
private: private:
//offset for the displayable
int offsetXDimension;
int offsetYDimension;
void selectLayerUp(); void selectLayerUp();
void selectLayerDown(); void selectLayerDown();
IntelliTool* copyActiveTool(); IntelliTool* copyActiveTool();
QImage* Canvas; QImage* Canvas;
QImage ScaledCanvas;
int maxWidth; int maxWidth;
int maxHeight; int maxHeight;
@@ -262,7 +268,7 @@ bool isSettingPolygon = false;
IntelliRenderSettings renderSettings; IntelliRenderSettings renderSettings;
IntelliTool* Tool; IntelliTool* Tool;
IntelliPhotoGui* DummyGui; IntelliPhotoGui* guiReference;
std::vector<LayerObject> layerBundle; std::vector<LayerObject> layerBundle;
int activeLayer = -1; int activeLayer = -1;

View File

@@ -51,7 +51,7 @@ void IntelliTool::onMouseMoved(int x, int y){
void IntelliTool::onWheelScrolled(int value){ void IntelliTool::onWheelScrolled(int value){
//if needed for future general tasks implement in here //if needed for future general tasks implement in here
Area->DummyGui->setToolWidth(value + Toolsettings->getLineWidth()); Area->guiReference->setToolWidth(value + Toolsettings->getLineWidth());
} }
bool IntelliTool::createToolLayer(){ bool IntelliTool::createToolLayer(){
@@ -89,7 +89,7 @@ void IntelliTool::mergeToolLayer(){
if(Canvas->image->getPolygonData().size() > 0) { if(Canvas->image->getPolygonData().size() > 0) {
activeLayer->image->setPolygon(Canvas->image->getPolygonData()); activeLayer->image->setPolygon(Canvas->image->getPolygonData());
} }
Area->DummyGui->UpdateGui(); Area->guiReference->UpdateGui();
Area->historyadd(); Area->historyadd();
} }