diff --git a/src/GUI/IntelliInputDialog.cpp b/src/GUI/IntelliInputDialog.cpp index 1e35545..7afa6b1 100644 --- a/src/GUI/IntelliInputDialog.cpp +++ b/src/GUI/IntelliInputDialog.cpp @@ -1,35 +1,71 @@ #include "IntelliInputDialog.h" -IntelliInputDialog::IntelliInputDialog() +IntelliInputDialog::IntelliInputDialog(Speichereinheit &Speicher, QEventLoop* Loop, IntelliInputDialog* Dialog, QString Title, QString Label, int value, int minValue, int maxValue, int step) { + this->Dialog = Dialog; + createInputBox(Title, Label, value, minValue, maxValue, step); + createConnections(Loop); setValuesOfPalette(); + setInputBoxStyle(); } -void IntelliInputDialog::Input(){ - QDialog* Dialog = new QDialog(); - QGridLayout* Layout = new QGridLayout(); - QDialogButtonBox* ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); +void IntelliInputDialog::createInputBox(QString Title, QString Label, int value, int minValue, int maxValue, int step){ + this->Dialog = new QDialog(); + Dialog->setWindowFlags(Dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint); + if(Title == nullptr){ + Dialog->setWindowTitle("Input Box"); + } + else{ + Dialog->setWindowTitle(Title); + } + Layout = new QGridLayout(); + ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - QPushButton* Button = new QPushButton(); - Button->setFixedSize(Buttonsize); + InputLabel = new QLabel(); + if(Label == nullptr){ + InputLabel->setText("Width:"); + } + else{ + InputLabel->setText(Label); + } + InputLabel->setFixedSize(Linesize); - QPushButton* okButton = ButtonBox->button(QDialogButtonBox::Ok); + Input = new QSpinBox(); + Input->setFixedSize(Linesize); + Input->setRange(minValue,maxValue); + Input->setValue(value); + + okButton = ButtonBox->button(QDialogButtonBox::Ok); + okButton->setFixedSize(Buttonsize); okButton->setAutoDefault(false); okButton->setDefault(false); - QPushButton* cancelButton = ButtonBox->button(QDialogButtonBox::Cancel); + cancelButton = ButtonBox->button(QDialogButtonBox::Cancel); + cancelButton->setFixedSize(Buttonsize); cancelButton->setAutoDefault(false); cancelButton->setDefault(false); - Button->setPalette(Palette); + Layout->addWidget(InputLabel,1,1,1,1); + Layout->addWidget(Input,2,1,1,1); + Layout->addWidget(ButtonBox,3,1,1,1); + Dialog->setLayout(Layout); + Dialog->resize(172,94); + Dialog->show(); +} + +void IntelliInputDialog::createConnections(QEventLoop* Loop){ + connect(okButton, SIGNAL(clicked()), this, SLOT(slotEingabe(Speicher))); + 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); - - Layout->addWidget(Button); - Layout->addWidget(ButtonBox); - Dialog->setLayout(Layout); Dialog->setStyleSheet("background-color:rgb(64,64,64)"); - connect(okButton, SIGNAL(clicked()),Dialog,SLOT(slotCloseEvent())); } void IntelliInputDialog::setValuesOfPalette(){ @@ -43,3 +79,21 @@ void IntelliInputDialog::setValuesOfPalette(){ Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255)); Palette.setBrush(QPalette::Text, QColor(255, 255, 255)); } + +void IntelliInputDialog::slotCloseEvent(){ + Dialog->close(); +} + +void IntelliInputDialog::slotEingabe(Speichereinheit &Speicher){ + qDebug() << Input->value(); + SetValueToGUI(); + Dialog->close(); +} + +void IntelliInputDialog::SetValueToGUI(){ + Input->value(); +} + +void IntelliInputDialog::getIntInput(Speichereinheit &Speicher, QEventLoop* Loop, IntelliInputDialog* Dialog, QString Title, QString Label, int value, int minValue, int maxValue, int step){ + this->Dialog = new IntelliInputDialog(Speicher, Loop, Dialog, Title, Label, value, minValue, maxValue, step); +} diff --git a/src/GUI/IntelliInputDialog.h b/src/GUI/IntelliInputDialog.h index 49af2b5..bcc9a12 100644 --- a/src/GUI/IntelliInputDialog.h +++ b/src/GUI/IntelliInputDialog.h @@ -2,24 +2,45 @@ #define INTELLIINPUTDIALOG_H #include - +#include #include "IntelliPhotoGui.h" -class IntelliInputDialog +class Speichereinheit{ + int value; +}; + +class IntelliInputDialog : public QDialog { +Q_OBJECT public: - IntelliInputDialog(); + IntelliInputDialog(Speichereinheit &Speicher, QEventLoop* Loop = nullptr, IntelliInputDialog* Dialog = nullptr, QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); - void Input(); + void getIntInput(Speichereinheit &Speicher, QEventLoop* Loop = nullptr, IntelliInputDialog* Dialog = nullptr, QString Title = "InputBox", QString Label = "Weight:", int value = 0, int minValue = -2147483647, int maxValue = 2147483647, int step = 1); -private slots: +public slots: void slotCloseEvent(); + void slotEingabe(Speichereinheit &Speicher); private: - IntelliPhotoGui* DummyGui; - const QSize Buttonsize = QSize(35,35); - QPalette Palette; + 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 setInputBoxStyle(); + + void SetValueToGUI(); + + QDialog* Dialog; + + QGridLayout* Layout; + QDialogButtonBox* ButtonBox; + + const QSize Linesize = QSize(150,20); + const QSize Buttonsize = QSize(72,20); + QPalette Palette; + QLabel* InputLabel; + QSpinBox* Input; + QPushButton* okButton; + QPushButton* cancelButton; }; #endif // INTELLIINPUTDIALOG_H diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 9f3b4b4..7297c47 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -4,7 +4,8 @@ #include "Layer/PaintingArea.h" // IntelliPhotoGui constructor -IntelliPhotoGui::IntelliPhotoGui(){ +IntelliPhotoGui::IntelliPhotoGui(IntelliInputDialog* InputDialog){ + //this->InputDialog = InputDialog; // create Gui elements and lay them out createGui(); // Create actions @@ -15,7 +16,7 @@ IntelliPhotoGui::IntelliPhotoGui(){ setIntelliStyle(); // Size the app resize(600,600); - showMaximized(); + //showMaximized(); setDefaultToolValue(); } @@ -68,25 +69,22 @@ void IntelliPhotoGui::slotSave(){ // Opens a dialog that allows the user to create a New Layer void IntelliPhotoGui::slotCreateNewLayer(){ // Stores button value - 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 + Speichereinheit Speicher; + this->InputDialog->getIntInput(Speicher, &Loop, this->InputDialog, "New Layer", "Width:", 5, 0, 5000, 1); + int width = returnValueOfInputDialog; - /*int width = QInputDialog::getInt(this, tr("New Layer"), - tr("Width:"), - 200,1, 500, 1, &ok1); + qDebug() << width; + + int height = 25;//QInputDialog::getInt(this, tr("New Layer"),tr("Height:"),200,1, 500, 1, &ok2); - int height = QInputDialog::getInt(this, tr("New Layer"), - tr("Height:"), - 200,1, 500, 1, &ok2); // Create New Layer - if (ok1&&ok2){ - paintingArea->addLayer(width,height,0,0); - UpdateGui(); - }*/ + paintingArea->addLayer(width,height,0,0); + UpdateGui(); } // Opens a dialog that allows the user to delete a Layer @@ -496,7 +494,6 @@ void IntelliPhotoGui::createMenus(){ foreach (QAction *action, actionSaveAs) saveAsMenu->addAction(action); - // Attach all actions to File fileMenu = new QMenu(tr("&File"), this); fileMenu->addAction(actionOpen); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 55920ff..27909ee 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -11,6 +11,9 @@ #include #include +#include "IntelliInputDialog.h" + + // PaintingArea used to paint the image class PaintingArea; @@ -30,11 +33,12 @@ public: /*! * \brief The IntelliPhotoGui method is the constructor and is used to create a new instance of the main program window */ -IntelliPhotoGui(); +IntelliPhotoGui(IntelliInputDialog* InputDialog); void UpdateGui(); void setToolWidth(int value); +int returnValueOfInputDialog = 5; protected: // Function used to close an event @@ -104,6 +108,8 @@ void setDefaultToolValue(); // What we'll draw on PaintingArea* paintingArea; +IntelliInputDialog* InputDialog; +QEventLoop Loop; const QSize Buttonsize = QSize(35,35); QPixmap preview; diff --git a/src/main.cpp b/src/main.cpp index 30adab2..d6a8dd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "GUI/IntelliPhotoGui.h" +#include "GUI/IntelliInputDialog.h" #include #include #include @@ -7,9 +8,11 @@ int main(int argc, char*argv[]){ // The main application QApplication app(argc, argv); + IntelliInputDialog* InputDialog; + // Create and open the main window - IntelliPhotoGui window; - window.show(); + IntelliPhotoGui window(InputDialog); + window.show(); return app.exec(); }