This commit is contained in:
AshBastian
2020-01-10 21:10:49 +01:00
parent dbf1cda101
commit 7491472962
5 changed files with 121 additions and 40 deletions

View File

@@ -1,35 +1,71 @@
#include "IntelliInputDialog.h" #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(); setValuesOfPalette();
setInputBoxStyle();
} }
void IntelliInputDialog::Input(){ void IntelliInputDialog::createInputBox(QString Title, QString Label, int value, int minValue, int maxValue, int step){
QDialog* Dialog = new QDialog(); this->Dialog = new QDialog();
QGridLayout* Layout = new QGridLayout(); Dialog->setWindowFlags(Dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
QDialogButtonBox* ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 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(); InputLabel = new QLabel();
Button->setFixedSize(Buttonsize); 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->setAutoDefault(false);
okButton->setDefault(false); okButton->setDefault(false);
QPushButton* cancelButton = ButtonBox->button(QDialogButtonBox::Cancel); cancelButton = ButtonBox->button(QDialogButtonBox::Cancel);
cancelButton->setFixedSize(Buttonsize);
cancelButton->setAutoDefault(false); cancelButton->setAutoDefault(false);
cancelButton->setDefault(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); okButton->setPalette(Palette);
cancelButton->setPalette(Palette); cancelButton->setPalette(Palette);
Layout->addWidget(Button);
Layout->addWidget(ButtonBox);
Dialog->setLayout(Layout);
Dialog->setStyleSheet("background-color:rgb(64,64,64)"); Dialog->setStyleSheet("background-color:rgb(64,64,64)");
connect(okButton, SIGNAL(clicked()),Dialog,SLOT(slotCloseEvent()));
} }
void IntelliInputDialog::setValuesOfPalette(){ void IntelliInputDialog::setValuesOfPalette(){
@@ -43,3 +79,21 @@ void IntelliInputDialog::setValuesOfPalette(){
Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255)); Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255));
Palette.setBrush(QPalette::Text, 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);
}

View File

@@ -2,24 +2,45 @@
#define INTELLIINPUTDIALOG_H #define INTELLIINPUTDIALOG_H
#include <QtWidgets> #include <QtWidgets>
#include <QDebug>
#include "IntelliPhotoGui.h" #include "IntelliPhotoGui.h"
class IntelliInputDialog class Speichereinheit{
int value;
};
class IntelliInputDialog : public QDialog
{ {
Q_OBJECT
public: 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 slotCloseEvent();
void slotEingabe(Speichereinheit &Speicher);
private: private:
IntelliPhotoGui* DummyGui; void createInputBox(QString Title = nullptr, QString Label = nullptr, int value = 5, int minValue = -2147483647, int maxValue = 2147483647, int step = 1);
const QSize Buttonsize = QSize(35,35); void createConnections(QEventLoop* Loop = nullptr);
QPalette Palette;
void setValuesOfPalette(); 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 #endif // INTELLIINPUTDIALOG_H

View File

@@ -4,7 +4,8 @@
#include "Layer/PaintingArea.h" #include "Layer/PaintingArea.h"
// IntelliPhotoGui constructor // IntelliPhotoGui constructor
IntelliPhotoGui::IntelliPhotoGui(){ IntelliPhotoGui::IntelliPhotoGui(IntelliInputDialog* InputDialog){
//this->InputDialog = InputDialog;
// create Gui elements and lay them out // create Gui elements and lay them out
createGui(); createGui();
// Create actions // Create actions
@@ -15,7 +16,7 @@ IntelliPhotoGui::IntelliPhotoGui(){
setIntelliStyle(); setIntelliStyle();
// Size the app // Size the app
resize(600,600); resize(600,600);
showMaximized(); //showMaximized();
setDefaultToolValue(); setDefaultToolValue();
} }
@@ -68,25 +69,22 @@ void IntelliPhotoGui::slotSave(){
// Opens a dialog that allows the user to create a New Layer // Opens a dialog that allows the user to create a New Layer
void IntelliPhotoGui::slotCreateNewLayer(){ void IntelliPhotoGui::slotCreateNewLayer(){
// Stores button value // Stores button value
bool ok1, ok2;
// "New Layer" is the title of the window // "New Layer" is the title of the window
// the next tr is the text to display // the next tr is the text to display
// Define the standard Value, min, max, step and ok button // 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"), qDebug() << width;
tr("Width:"),
200,1, 500, 1, &ok1); 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 // Create New Layer
if (ok1&&ok2){ paintingArea->addLayer(width,height,0,0);
paintingArea->addLayer(width,height,0,0); UpdateGui();
UpdateGui();
}*/
} }
// Opens a dialog that allows the user to delete a Layer // Opens a dialog that allows the user to delete a Layer
@@ -496,7 +494,6 @@ void IntelliPhotoGui::createMenus(){
foreach (QAction *action, actionSaveAs) foreach (QAction *action, actionSaveAs)
saveAsMenu->addAction(action); saveAsMenu->addAction(action);
// Attach all actions to File // Attach all actions to File
fileMenu = new QMenu(tr("&File"), this); fileMenu = new QMenu(tr("&File"), this);
fileMenu->addAction(actionOpen); fileMenu->addAction(actionOpen);

View File

@@ -11,6 +11,9 @@
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include "IntelliInputDialog.h"
// PaintingArea used to paint the image // PaintingArea used to paint the image
class PaintingArea; 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 * \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 UpdateGui();
void setToolWidth(int value); void setToolWidth(int value);
int returnValueOfInputDialog = 5;
protected: protected:
// Function used to close an event // Function used to close an event
@@ -104,6 +108,8 @@ void setDefaultToolValue();
// What we'll draw on // What we'll draw on
PaintingArea* paintingArea; PaintingArea* paintingArea;
IntelliInputDialog* InputDialog;
QEventLoop Loop;
const QSize Buttonsize = QSize(35,35); const QSize Buttonsize = QSize(35,35);
QPixmap preview; QPixmap preview;

View File

@@ -1,4 +1,5 @@
#include "GUI/IntelliPhotoGui.h" #include "GUI/IntelliPhotoGui.h"
#include "GUI/IntelliInputDialog.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <vector> #include <vector>
@@ -7,9 +8,11 @@ int main(int argc, char*argv[]){
// The main application // The main application
QApplication app(argc, argv); QApplication app(argc, argv);
IntelliInputDialog* InputDialog;
// Create and open the main window // Create and open the main window
IntelliPhotoGui window; IntelliPhotoGui window(InputDialog);
window.show(); window.show();
return app.exec(); return app.exec();
} }