From 74d0a4a6f634010db71d05536cffef15bfb1edd9 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Sun, 29 Mar 2015 19:11:23 +0200 Subject: Initial Commit --- GUI_SS2015.pro | 23 ++++++++ dlgpreferences.cpp | 60 ++++++++++++++++++++ dlgpreferences.h | 56 +++++++++++++++++++ dlgpreferences.ui | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 11 ++++ mainwindow.cpp | 39 +++++++++++++ mainwindow.h | 26 +++++++++ mainwindow.ui | 143 ++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 515 insertions(+) create mode 100644 GUI_SS2015.pro create mode 100644 dlgpreferences.cpp create mode 100644 dlgpreferences.h create mode 100644 dlgpreferences.ui create mode 100644 main.cpp create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 mainwindow.ui diff --git a/GUI_SS2015.pro b/GUI_SS2015.pro new file mode 100644 index 0000000..5bb0a3e --- /dev/null +++ b/GUI_SS2015.pro @@ -0,0 +1,23 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-03-19T13:14:53 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = GUI_SS2015 +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + dlgpreferences.cpp + +HEADERS += mainwindow.h \ + dlgpreferences.h + +FORMS += mainwindow.ui \ + dlgpreferences.ui diff --git a/dlgpreferences.cpp b/dlgpreferences.cpp new file mode 100644 index 0000000..4661fa5 --- /dev/null +++ b/dlgpreferences.cpp @@ -0,0 +1,60 @@ +#include "dlgpreferences.h" +#include "ui_dlgpreferences.h" + +DlgPreferences::DlgPreferences(QWidget *parent) : + QDialog(parent), + ui(new Ui::DlgPreferences) +{ + ui->setupUi(this); + + QIntValidator *val = new QIntValidator(100,800,this); + ui->lineEditHeight->setValidator(val); + ui->lineEditWidth->setValidator(val); +} + +DlgPreferences::~DlgPreferences() +{ + delete ui; +} + +void DlgPreferences::setHeight(int arg) +{ + if (m_Height == arg) + return; + + m_Height = arg; + ui->lineEditHeight->setText(QString::number(m_Height)); + emit HeightChanged(arg); +} + +void DlgPreferences::setWidth(int arg) +{ + if (m_Width == arg) + return; + + m_Width = arg; + ui->lineEditWidth->setText(QString::number(m_Width)); + emit WidthChanged(arg); +} + + + +void DlgPreferences::on_buttonOk_clicked() +{ + qDebug() << "Height: " << ui->lineEditHeight->text(); + qDebug() << "Width:" << ui->lineEditWidth->text(); +} + + +void DlgPreferences::accept() +{ + setHeight(ui->lineEditHeight->text().toInt()); + setWidth(ui->lineEditWidth->text().toInt()); + + QDialog::accept(); +} + +void DlgPreferences::reject() +{ + QDialog::reject(); +} diff --git a/dlgpreferences.h b/dlgpreferences.h new file mode 100644 index 0000000..2921959 --- /dev/null +++ b/dlgpreferences.h @@ -0,0 +1,56 @@ +#ifndef DLGPREFERENCES_H +#define DLGPREFERENCES_H + +#include +#include + +namespace Ui { +class DlgPreferences; +} + +class DlgPreferences : public QDialog +{ + Q_OBJECT + + Q_PROPERTY(int Height READ Height WRITE setHeight NOTIFY HeightChanged) + Q_PROPERTY(int Width READ Width WRITE setWidth NOTIFY WidthChanged) + +public: + explicit DlgPreferences(QWidget *parent = 0); + ~DlgPreferences(); + + int Height() const + { + return m_Height; + } + + int Width() const + { + return m_Width; + } + +public slots: + void setHeight(int arg); + + void setWidth(int arg); + +signals: + void HeightChanged(int arg); + + void WidthChanged(int arg); + +private slots: + void on_buttonOk_clicked(); + +private: + Ui::DlgPreferences *ui; + int m_Height; + int m_Width; + + // QDialog interface +public slots: + void accept(); + void reject(); +}; + +#endif // DLGPREFERENCES_H diff --git a/dlgpreferences.ui b/dlgpreferences.ui new file mode 100644 index 0000000..dfc95c2 --- /dev/null +++ b/dlgpreferences.ui @@ -0,0 +1,157 @@ + + + DlgPreferences + + + + 0 + 0 + 346 + 273 + + + + Qt::WheelFocus + + + Preferences + + + + + + Preferences + + + + + + + + Width + + + + + + + + + + 32767 + + + + + + + Height + + + + + + + + + + 32767 + + + + + + + + + + + Cancel + + + false + + + true + + + + + + + Qt::Horizontal + + + + 37 + 17 + + + + + + + + Ok + + + true + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + buttonCancel + clicked() + DlgPreferences + reject() + + + 62 + 130 + + + -23 + 107 + + + + + buttonOk + clicked() + DlgPreferences + accept() + + + 267 + 138 + + + 365 + 130 + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..94b879e --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,39 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_action_Preferences_triggered() +{ + qDebug() << "Preferences called"; + DlgPreferences *tmp = new DlgPreferences(this); + + tmp->setHeight(size().height()); + tmp->setWidth(size().width()); + + if(tmp->exec()) + { + qDebug() << "DlgPreferences okay clicked."; + + int width = tmp->width(); + int height = tmp->height(); + + if(width >= 100 && width <= 800 && height >= 100 && height <= 800) + { + qDebug() << "Resizing QMainWindow."; + resize(width,height); + } + } + + delete tmp; +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..87080d1 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,26 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include "dlgpreferences.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_action_Preferences_triggered(); +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..5f71cc1 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,143 @@ + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + GUIProjekt SS2015_SS + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Hello Qt World. + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + 400 + 29 + + + + + Fi&le + + + + + + Edi&t + + + + + + Hel&p + + + + + + + + + + false + + + &Exit + + + + + &Preferences + + + + + &About + + + + + + + + actionExit + triggered() + MainWindow + close() + + + -1 + -1 + + + 199 + 149 + + + + + actionPreferences + triggered() + MainWindow + on_action_Preferences_triggered() + + + -1 + -1 + + + 199 + 149 + + + + + + on_action_Preferences_triggered() + + -- cgit v1.2.3-70-g09d2