From 0e6ce309c9211e12e9e3e17d680e7ade1d9bb045 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Wed, 15 Jan 2020 19:04:51 +0100 Subject: [PATCH] code cleanup #2 --- src/GUI/IntelliInputDialog.cpp | 17 +++----- src/GUI/IntelliInputDialog.h | 5 +++ src/GUI/IntelliPhotoGui.cpp | 80 ++++++++++++---------------------- src/GUI/IntelliPhotoGui.h | 2 - 4 files changed, 38 insertions(+), 66 deletions(-) diff --git a/src/GUI/IntelliInputDialog.cpp b/src/GUI/IntelliInputDialog.cpp index ebcc72c..d12b1f1 100644 --- a/src/GUI/IntelliInputDialog.cpp +++ b/src/GUI/IntelliInputDialog.cpp @@ -11,6 +11,11 @@ IntelliInputDialog::IntelliInputDialog(QEventLoop* Loop, QString Title, QString Loop->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); + return dialog.valueInt; +} + void IntelliInputDialog::createInputBox(QString Title, QString Label, int value, int minValue, int maxValue, int step){ this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); if(Title == nullptr) { @@ -86,15 +91,5 @@ void IntelliInputDialog::slotCloseEvent(){ } void IntelliInputDialog::slotEingabe(){ - QFile File("test.txt"); - - if(!File.open(QIODevice::WriteOnly | QIODevice::Text)){ - qDebug() << "Error Write to File"; - } - std::string test = QString("%1").arg(Input->value()).toStdString(); - const char* p = test.c_str(); - File.write(p); - File.close(); - - this->close(); + valueInt= QString("%1").arg(Input->value()).toInt(); } diff --git a/src/GUI/IntelliInputDialog.h b/src/GUI/IntelliInputDialog.h index d02ecdb..915473e 100644 --- a/src/GUI/IntelliInputDialog.h +++ b/src/GUI/IntelliInputDialog.h @@ -10,6 +10,8 @@ public: IntelliInputDialog(QEventLoop* Loop = nullptr, QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); +static int getInt(QEventLoop* Loop = nullptr, QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); + public slots: void slotCloseEvent(); void slotEingabe(); @@ -20,8 +22,11 @@ void createConnections(QEventLoop* Loop = nullptr); void setValuesOfPalette(); void setInputBoxStyle(); +int valueInt; + QGridLayout* Layout; QDialogButtonBox* ButtonBox; +QEventLoop loop; const QSize Linesize = QSize(150,20); const QSize Buttonsize = QSize(72,20); diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index b23feac..e6a5350 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -15,8 +15,8 @@ IntelliPhotoGui::IntelliPhotoGui(){ setIntelliStyle(); // Size the app resize(600,600); - //showMaximized(); - setDefaultToolValue(); + //showMaximized(); + setDefaultToolValue(); } // User tried to close the app @@ -70,13 +70,9 @@ void IntelliPhotoGui::slotCreateNewLayer(){ // "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 - IntelliInputDialog widthDialog(&Loop, "New Layer", "Width:", 200, 0, 5000, 1); + int width = IntelliInputDialog::getInt(&Loop, "New Layer", "Width:", 200, 0, 5000, 1); - int width = getReturnValueOfDialog(); - - IntelliInputDialog heightDialog(&Loop, "New Layer", "Height:", 200, 0, 5000, 1); - - int height = getReturnValueOfDialog(); + int height = IntelliInputDialog::getInt(&Loop, "New Layer", "Height:", 200, 0, 5000, 1); // Create New Layer paintingArea->addLayer(width,height,0,0); @@ -88,8 +84,7 @@ void IntelliPhotoGui::slotDeleteLayer(){ // "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 - IntelliInputDialog dialog(&Loop, "Delete Layer", "Number:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); - int layerNumber = getReturnValueOfDialog(); + int layerNumber = IntelliInputDialog::getInt(&Loop, "Delete Layer", "Number:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); // Create New Layer paintingArea->deleteLayer(layerNumber-1); @@ -101,12 +96,10 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ // the next tr is the text to display // Define the standard Value, min, max, step and ok button - IntelliInputDialog layerDialog(&Loop, "Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); - int layer = getReturnValueOfDialog(); + int layer = IntelliInputDialog::getInt(&Loop, "Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); // "New Alpha" is the title of the window - IntelliInputDialog alphaDialog;(&Loop, "New Alpha", "Alpha:", 255, 0, 255, 1); - int alpha = getReturnValueOfDialog(); + int alpha = IntelliInputDialog::getInt(&Loop, "Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer()+1, 1, 501, 1); paintingArea->setLayerAlpha(layer-1,alpha); UpdateGui(); } @@ -146,21 +139,17 @@ void IntelliPhotoGui::slotClearActiveLayer(){ // the next tr is the text to display // Define the standard Value, min, max, step and ok button - - IntelliInputDialog redDialog(&Loop, "Red Input", "Red:", 255, 0, 255, 1); - int red = getReturnValueOfDialog(); + // "Red Input" is the title of the window + int red = IntelliInputDialog::getInt(&Loop, "Green Input", "Green:", 255, 0, 255, 1); // "Green Input" is the title of the window - IntelliInputDialog greenDialog(&Loop, "Green Input", "Green:", 255, 0, 255, 1); - int green = getReturnValueOfDialog(); + int green = IntelliInputDialog::getInt(&Loop, "Green Input", "Green:", 255, 0, 255, 1); // "Blue Input" is the title of the window - IntelliInputDialog blueDialog(&Loop, "Blue Input", "Blue:", 255, 0, 255, 1); - int blue = getReturnValueOfDialog(); + int blue = IntelliInputDialog::getInt(&Loop, "Blue Input", "Blue:", 255, 0, 255, 1); - // "Alpha Input" is the title of the window - IntelliInputDialog alphaDialog(&Loop, "Alpha Input", "Alpha:", 255, 0, 255, 1); - int alpha = getReturnValueOfDialog(); + // "Alpha Input" is the title of the window + int alpha = IntelliInputDialog::getInt(&Loop, "Alpha Input", "Alpha:", 255, 0, 255, 1); paintingArea->floodFill(red, green, blue, alpha); UpdateGui(); @@ -170,8 +159,7 @@ void IntelliPhotoGui::slotSetActiveLayer(){ // "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 - IntelliInputDialog dialog(&Loop, "Layer to set on", "Layer:", 1, 1, 501, 1); - int layer = getReturnValueOfDialog(); + int layer = IntelliInputDialog::getInt(&Loop, "Layer to set on", "Layer:", 1, 1, 501, 1); paintingArea->setLayerActive(layer-1); UpdateGui(); } @@ -244,16 +232,16 @@ void IntelliPhotoGui::slotAboutDialog(){ } void IntelliPhotoGui::slotEnterPressed(){ - QString string = EditLineWidth->text(); - if(string.toInt() > 50) { - EditLineWidth->setText("50"); - } - paintingArea->Toolsettings.setLineWidth(string.toInt()); - string = EditLineInnerAlpha->text(); - if(string.toInt() > 255) { - EditLineInnerAlpha->setText("255"); - } - paintingArea->Toolsettings.setInnerAlpha(string.toInt()); + QString string = EditLineWidth->text(); + if(string.toInt() > 50) { + EditLineWidth->setText("50"); + } + paintingArea->Toolsettings.setLineWidth(string.toInt()); + string = EditLineInnerAlpha->text(); + if(string.toInt() > 255) { + EditLineInnerAlpha->setText("255"); + } + paintingArea->Toolsettings.setInnerAlpha(string.toInt()); } void IntelliPhotoGui::slotResetTools(){ @@ -267,14 +255,12 @@ void IntelliPhotoGui::slotResetTools(){ } void IntelliPhotoGui::slotSetWidth(){ - IntelliInputDialog dialog(&Loop, "Toolsettings", "Width:", 5, 1, 50, 1); - paintingArea->Toolsettings.setLineWidth(getReturnValueOfDialog()); + paintingArea->Toolsettings.setLineWidth(IntelliInputDialog::getInt(&Loop, "Toolsettings", "Width:", 5, 1, 50, 1)); EditLineWidth->setText(QString("%1").arg(paintingArea->Toolsettings.getLineWidth())); } void IntelliPhotoGui::slotSetInnerAlpha(){ - IntelliInputDialog dialog(&Loop, "Toolsettings", "Inner Alpha:", 255, 0, 255, 1); - paintingArea->Toolsettings.setInnerAlpha(getReturnValueOfDialog()); + paintingArea->Toolsettings.setInnerAlpha(IntelliInputDialog::getInt(&Loop, "Toolsettings", "Width:", 5, 1, 50, 1)); EditLineInnerAlpha->setText(QString("%1").arg(paintingArea->Toolsettings.getInnerAlpha())); } @@ -768,7 +754,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){ } void IntelliPhotoGui::setDefaultToolValue(){ - slotEnterPressed(); + slotEnterPressed(); } void IntelliPhotoGui::setToolWidth(int value){ @@ -799,15 +785,3 @@ void IntelliPhotoGui::UpdateGui(){ string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name()); SecondColorButton->setStyleSheet(string); } - -int IntelliPhotoGui::getReturnValueOfDialog(){ - QFile File("test.txt"); - if(!File.open(QIODevice::ReadOnly | QIODevice::Text)){ - qDebug() << "Error Read from File"; - } - - QByteArray line = File.readLine(); - File.close(); - - return line.toInt(); -} diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 6aea72d..8f18180 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -105,8 +105,6 @@ bool saveFile(const QByteArray &fileFormat); void setDefaultToolValue(); -int getReturnValueOfDialog(); - // What we'll draw on PaintingArea* paintingArea; QEventLoop Loop;