From b695a25128688b00a8791ceb37a152b4dff7ed09 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Thu, 16 Jan 2020 00:00:27 +0100 Subject: [PATCH] Fixed Inputboxes and Design Todo pls merge me. --- src/GUI/IntelliInputDialog.cpp | 42 ++++------ src/GUI/IntelliInputDialog.h | 9 +-- src/GUI/IntelliPhotoGui.cpp | 96 +++++++++++------------ src/GUI/IntelliPhotoGui.h | 3 - src/IntelliHelper/IntelliToolsettings.cpp | 12 +++ src/Layer/PaintingArea.cpp | 9 +++ src/Layer/PaintingArea.h | 4 + 7 files changed, 92 insertions(+), 83 deletions(-) diff --git a/src/GUI/IntelliInputDialog.cpp b/src/GUI/IntelliInputDialog.cpp index d778e59..8ed0465 100644 --- a/src/GUI/IntelliInputDialog.cpp +++ b/src/GUI/IntelliInputDialog.cpp @@ -2,18 +2,21 @@ #include -IntelliInputDialog::IntelliInputDialog(QEventLoop* Loop, QString Title, QString Label, int value, int minValue, int maxValue, int step) +IntelliInputDialog::IntelliInputDialog(QString Title, QString Label, int value, int minValue, int maxValue, int step, bool* ok) { this->valueInt = value; + this->notClosed = ok; + if(notClosed != nullptr){ + *notClosed = false; + } createInputBox(Title, Label, value, minValue, maxValue, step); - createConnections(Loop); - setValuesOfPalette(); + createConnections(); setInputBoxStyle(); - Loop->exec(); + this->exec(); } -int IntelliInputDialog::getInt(QEventLoop* Loop, QString Title, QString Label, int value, int minValue, int maxValue, int step){ - IntelliInputDialog dialog(Loop, Title, Label, value, minValue, maxValue, step); +int IntelliInputDialog::getInt(QString Title, QString Label, int value, int minValue, int maxValue, int step, bool* ok){ + IntelliInputDialog dialog(Title, Label, value, minValue, maxValue, step, ok); return dialog.valueInt; } @@ -40,6 +43,7 @@ void IntelliInputDialog::createInputBox(QString Title, QString Label, int value, this->Input = new QSpinBox(); this->Input->setFixedSize(Linesize); this->Input->setRange(minValue,maxValue); + this->Input->setSingleStep(step); this->Input->setValue(value); this->okButton = ButtonBox->button(QDialogButtonBox::Ok); @@ -60,31 +64,13 @@ void IntelliInputDialog::createInputBox(QString Title, QString Label, int value, this->show(); } -void IntelliInputDialog::createConnections(QEventLoop* Loop){ +void IntelliInputDialog::createConnections(){ connect(okButton, SIGNAL(clicked()), this, SLOT(slotEingabe())); - connect(okButton, SIGNAL(clicked()), Loop, SLOT(quit())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotCloseEvent())); - connect(cancelButton, SIGNAL(clicked()), Loop, SLOT(quit())); } void IntelliInputDialog::setInputBoxStyle(){ - InputLabel->setPalette(Palette); - Input->setPalette(Palette); - okButton->setPalette(Palette); - cancelButton->setPalette(Palette); - this->setStyleSheet("background-color:rgb(64,64,64)"); -} - -void IntelliInputDialog::setValuesOfPalette(){ - Palette.setBrush(QPalette::HighlightedText, QColor(200, 10, 10)); - Palette.setBrush(QPalette::Highlight, QColor(100, 5, 5)); - Palette.setBrush(QPalette::ButtonText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::Button, QColor(64, 64, 64)); - Palette.setBrush(QPalette::Window, QColor(64, 64, 64)); - Palette.setBrush(QPalette::WindowText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::PlaceholderText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::Text, QColor(255, 255, 255)); + this->setStyleSheet("color: white;" "background-color: rgb(64, 64, 64);" "selection-color: rgb(200, 10, 10);" "selection-background-color: rgb(64, 64, 64);"); } void IntelliInputDialog::slotCloseEvent(){ @@ -93,4 +79,8 @@ void IntelliInputDialog::slotCloseEvent(){ void IntelliInputDialog::slotEingabe(){ valueInt = QString("%1").arg(Input->value()).toInt(); + if(notClosed != nullptr){ + *notClosed = true; + } + this->close(); } diff --git a/src/GUI/IntelliInputDialog.h b/src/GUI/IntelliInputDialog.h index 915473e..a8b25da 100644 --- a/src/GUI/IntelliInputDialog.h +++ b/src/GUI/IntelliInputDialog.h @@ -7,10 +7,10 @@ class IntelliInputDialog : public QDialog { Q_OBJECT public: -IntelliInputDialog(QEventLoop* Loop = nullptr, QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); +IntelliInputDialog(QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1, bool* ok = nullptr); -static int getInt(QEventLoop* Loop = nullptr, QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); +static int getInt(QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1, bool* ok = nullptr); public slots: void slotCloseEvent(); @@ -18,8 +18,7 @@ void slotEingabe(); private: void createInputBox(QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); -void createConnections(QEventLoop* Loop = nullptr); -void setValuesOfPalette(); +void createConnections(); void setInputBoxStyle(); int valueInt; @@ -27,10 +26,10 @@ int valueInt; QGridLayout* Layout; QDialogButtonBox* ButtonBox; QEventLoop loop; +bool* notClosed; const QSize Linesize = QSize(150,20); const QSize Buttonsize = QSize(72,20); -QPalette Palette; QLabel* InputLabel; QSpinBox* Input; QPushButton* okButton; diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index e6a5350..e1a3d2c 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -67,41 +67,54 @@ void IntelliPhotoGui::slotSave(){ // Opens a dialog that allows the user to create a New Layer void IntelliPhotoGui::slotCreateNewLayer(){ + + bool ok1, ok2; // "New Layer" is the title of the window // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int width = IntelliInputDialog::getInt(&Loop, "New Layer", "Width:", 200, 0, 5000, 1); + int width = IntelliInputDialog::getInt("New Layer", "Width:", 200, 1, paintingArea->getMaxWidth(), 1, &ok1); - int height = IntelliInputDialog::getInt(&Loop, "New Layer", "Height:", 200, 0, 5000, 1); + int height = IntelliInputDialog::getInt("New Layer", "Height:", 200, 1, paintingArea->getMaxHeight(), 1, &ok2); // Create New Layer - paintingArea->addLayer(width,height,0,0); - UpdateGui(); + if(ok1&&ok2){ + paintingArea->addLayer(width,height,0,0); + UpdateGui(); + } } // Opens a dialog that allows the user to delete a Layer void IntelliPhotoGui::slotDeleteLayer(){ + + bool ok1; // "delete Layer" is the title of the window // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int layerNumber = IntelliInputDialog::getInt(&Loop, "Delete Layer", "Number:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); + int layerNumber = IntelliInputDialog::getInt("Delete Layer", "Number:", paintingArea->getNumberOfActiveLayer()+1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); // Create New Layer - paintingArea->deleteLayer(layerNumber-1); - UpdateGui(); + if(ok1){ + paintingArea->deleteLayer(layerNumber-1); + UpdateGui(); + } } void IntelliPhotoGui::slotSetActiveAlpha(){ + + bool ok1, ok2; // "Layer to set on" is the title of the window // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int layer = IntelliInputDialog::getInt(&Loop, "Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); + int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer()+1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); // "New Alpha" is the title of the window - int alpha = IntelliInputDialog::getInt(&Loop, "Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); - paintingArea->setLayerAlpha(layer-1,alpha); - UpdateGui(); + int alpha = IntelliInputDialog::getInt("Layer to set on", "Alpha:", 255, 0, 255, 1, &ok2); + + if(ok1&&ok2){ + paintingArea->setLayerAlpha(layer-1,alpha); + UpdateGui(); + } } void IntelliPhotoGui::slotPositionMoveUp(){ @@ -140,28 +153,31 @@ void IntelliPhotoGui::slotClearActiveLayer(){ // Define the standard Value, min, max, step and ok button // "Red Input" is the title of the window - int red = IntelliInputDialog::getInt(&Loop, "Green Input", "Green:", 255, 0, 255, 1); + int red = IntelliInputDialog::getInt("Green Input", "Green:", 255, 0, 255, 1); // "Green Input" is the title of the window - int green = IntelliInputDialog::getInt(&Loop, "Green Input", "Green:", 255, 0, 255, 1); + int green = IntelliInputDialog::getInt("Green Input", "Green:", 255, 0, 255, 1); // "Blue Input" is the title of the window - int blue = IntelliInputDialog::getInt(&Loop, "Blue Input", "Blue:", 255, 0, 255, 1); + int blue = IntelliInputDialog::getInt("Blue Input", "Blue:", 255, 0, 255, 1); // "Alpha Input" is the title of the window - int alpha = IntelliInputDialog::getInt(&Loop, "Alpha Input", "Alpha:", 255, 0, 255, 1); + int alpha = IntelliInputDialog::getInt("Alpha Input", "Alpha:", 255, 0, 255, 1); paintingArea->floodFill(red, green, blue, alpha); UpdateGui(); } void IntelliPhotoGui::slotSetActiveLayer(){ + bool ok1; // "Layer to set on" is the title of the window // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int layer = IntelliInputDialog::getInt(&Loop, "Layer to set on", "Layer:", 1, 1, 501, 1); - paintingArea->setLayerActive(layer-1); - UpdateGui(); + int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); + if(ok1){ + paintingArea->setLayerActive(layer-1); + UpdateGui(); + } } void IntelliPhotoGui::slotUpdateRenderSettingsOn(){ @@ -255,13 +271,21 @@ void IntelliPhotoGui::slotResetTools(){ } void IntelliPhotoGui::slotSetWidth(){ - paintingArea->Toolsettings.setLineWidth(IntelliInputDialog::getInt(&Loop, "Toolsettings", "Width:", 5, 1, 50, 1)); - EditLineWidth->setText(QString("%1").arg(paintingArea->Toolsettings.getLineWidth())); + bool ok1; + int temp = IntelliInputDialog::getInt("Toolsettings", "Width:", 5, 1, 50, 1, &ok1); + if(ok1){ + paintingArea->Toolsettings.setLineWidth(temp); + EditLineWidth->setText(QString("%1").arg(temp)); + } } void IntelliPhotoGui::slotSetInnerAlpha(){ - paintingArea->Toolsettings.setInnerAlpha(IntelliInputDialog::getInt(&Loop, "Toolsettings", "Width:", 5, 1, 50, 1)); - EditLineInnerAlpha->setText(QString("%1").arg(paintingArea->Toolsettings.getInnerAlpha())); + bool ok1; + int temp = IntelliInputDialog::getInt("Toolsettings", "Width:", 5, 1, 50, 1, &ok1); + if(ok1){ + paintingArea->Toolsettings.setInnerAlpha(temp); + EditLineInnerAlpha->setText(QString("%1").arg(temp)); + } } // Define menu actions that call functions @@ -670,34 +694,8 @@ void IntelliPhotoGui::createGui(){ void IntelliPhotoGui::setIntelliStyle(){ // Set the title setWindowTitle("IntelliPhoto Prototype"); - Palette.setBrush(QPalette::HighlightedText, QColor(200, 10, 10)); - Palette.setBrush(QPalette::Highlight, QColor(100, 5, 5)); - Palette.setBrush(QPalette::ButtonText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::Button, QColor(64, 64, 64)); - Palette.setBrush(QPalette::Window, QColor(64, 64, 64)); - Palette.setBrush(QPalette::WindowText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::PlaceholderText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::Text, QColor(255, 255, 255)); // Set style sheet - this->setStyleSheet("background-color:rgb(64,64,64)"); - this->menuBar()->setPalette(Palette); - this->fileMenu->setPalette(Palette); - this->saveAsMenu->setPalette(Palette); - this->optionMenu->setPalette(Palette); - this->helpMenu->setPalette(Palette); - this->renderMenu->setPalette(Palette); - this->toolMenu->setPalette(Palette); - this->layerMenu->setPalette(Palette); - this->colorMenu->setPalette(Palette); - this->toolCreationMenu->setPalette(Palette); - this->toolSettingsMenu->setPalette(Palette); - - this->WidthLine->setPalette(Palette); - this->EditLineWidth->setPalette(Palette); - this->innerAlphaLine->setPalette(Palette); - this->EditLineInnerAlpha->setPalette(Palette); - this->ActiveLayerLine->setPalette(Palette); + this->setStyleSheet("color: white;" "background-color: rgb(64, 64, 64);" "selection-color: rgb(200, 10, 10);" "selection-background-color: rgb(64, 64, 64);"); QString 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 8f18180..5142897 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -107,7 +107,6 @@ void setDefaultToolValue(); // What we'll draw on PaintingArea* paintingArea; -QEventLoop Loop; const QSize Buttonsize = QSize(35,35); QPixmap preview; @@ -132,8 +131,6 @@ QPushButton* SwitchColorButton; QLabel* ActiveLayerLine; QLabel* ActiveLayerImageLabel; -QPalette Palette; - // The menu widgets QMenu*saveAsMenu; QMenu*fileMenu; diff --git a/src/IntelliHelper/IntelliToolsettings.cpp b/src/IntelliHelper/IntelliToolsettings.cpp index 2232cc0..5436438 100644 --- a/src/IntelliHelper/IntelliToolsettings.cpp +++ b/src/IntelliHelper/IntelliToolsettings.cpp @@ -17,6 +17,12 @@ int IntelliToolsettings::getLineWidth(){ } void IntelliToolsettings::setLineWidth(int LineWidth){ + if(LineWidth < 1){ + LineWidth = 1; + } + else if(LineWidth > 50){ + LineWidth = 50; + } lineWidth = LineWidth; } @@ -25,6 +31,12 @@ int IntelliToolsettings::getInnerAlpha(){ } void IntelliToolsettings::setInnerAlpha(int innerAlpha){ + if(innerAlpha < 0){ + innerAlpha = 0; + } + else if(innerAlpha > 255){ + innerAlpha = 255; + } this->innerAlpha = innerAlpha; } diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 7b93abc..d42d28f 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -182,6 +182,7 @@ void PaintingArea::moveActiveLayer(int idx){ }else if(idx==-1) { this->selectLayerDown(); } + DummyGui->UpdateGui(); } void PaintingArea::slotActivateLayer(int a){ @@ -253,6 +254,14 @@ int PaintingArea::getHeightOfActive(){ return this->layerBundle[static_cast(activeLayer)].height; } +int PaintingArea::getMaxWidth(){ + return this->maxWidth; +} + +int PaintingArea::getMaxHeight(){ + return this->maxHeight; +} + IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){ return this->layerBundle[static_cast(activeLayer)].image->getTypeOfImage(); } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 95eef55..df53a11 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -169,6 +169,10 @@ int getWidthOfActive(); */ int getHeightOfActive(); +int getMaxWidth(); + +int getMaxHeight(); + IntelliImage::ImageType getTypeOfImageRealLayer(); std::vector getPolygonDataOfRealLayer();