diff options
| -rw-r--r-- | GUI_SS2015.pro | 23 | ||||
| -rw-r--r-- | dlgpreferences.cpp | 60 | ||||
| -rw-r--r-- | dlgpreferences.h | 56 | ||||
| -rw-r--r-- | dlgpreferences.ui | 157 | ||||
| -rw-r--r-- | main.cpp | 11 | ||||
| -rw-r--r-- | mainwindow.cpp | 39 | ||||
| -rw-r--r-- | mainwindow.h | 26 | ||||
| -rw-r--r-- | mainwindow.ui | 143 |
8 files changed, 515 insertions, 0 deletions
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 <QDialog> +#include <QDebug> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>DlgPreferences</class> + <widget class="QDialog" name="DlgPreferences"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>346</width> + <height>273</height> + </rect> + </property> + <property name="focusPolicy"> + <enum>Qt::WheelFocus</enum> + </property> + <property name="windowTitle"> + <string>Preferences</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Preferences</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Width</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEditWidth"> + <property name="inputMask"> + <string/> + </property> + <property name="maxLength"> + <number>32767</number> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Height</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="lineEditHeight"> + <property name="inputMask"> + <string/> + </property> + <property name="maxLength"> + <number>32767</number> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="buttonCancel"> + <property name="text"> + <string>Cancel</string> + </property> + <property name="checkable"> + <bool>false</bool> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>37</width> + <height>17</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="buttonOk"> + <property name="text"> + <string>Ok</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>DlgPreferences</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>62</x> + <y>130</y> + </hint> + <hint type="destinationlabel"> + <x>-23</x> + <y>107</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>DlgPreferences</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>267</x> + <y>138</y> + </hint> + <hint type="destinationlabel"> + <x>365</x> + <y>130</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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 <QApplication> + +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 <QMainWindow> +#include <QDebug> +#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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>GUIProjekt SS2015_SS</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Hello Qt World.</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QStatusBar" name="statusBar"/> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>29</height> + </rect> + </property> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>Fi&le</string> + </property> + <addaction name="actionExit"/> + </widget> + <widget class="QMenu" name="menuEdir"> + <property name="title"> + <string>Edi&t</string> + </property> + <addaction name="actionPreferences"/> + </widget> + <widget class="QMenu" name="menuHelp"> + <property name="title"> + <string>Hel&p</string> + </property> + <addaction name="actionAbout"/> + </widget> + <addaction name="menuFile"/> + <addaction name="menuEdir"/> + <addaction name="menuHelp"/> + </widget> + <action name="actionExit"> + <property name="checkable"> + <bool>false</bool> + </property> + <property name="text"> + <string>&Exit</string> + </property> + </action> + <action name="actionPreferences"> + <property name="text"> + <string>&Preferences</string> + </property> + </action> + <action name="actionAbout"> + <property name="text"> + <string>&About</string> + </property> + </action> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections> + <connection> + <sender>actionExit</sender> + <signal>triggered()</signal> + <receiver>MainWindow</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionPreferences</sender> + <signal>triggered()</signal> + <receiver>MainWindow</receiver> + <slot>on_action_Preferences_triggered()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>on_action_Preferences_triggered()</slot> + </slots> +</ui> |
