From b60bb2ed272972847cb533be2e86bd2d7e565918 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Mon, 13 Apr 2015 08:37:00 +0200 Subject: Adds tasks 2 and 3 --- GUI_SS2015.pro | 6 ++++-- dlgpreferences.cpp | 6 +++++- interactioncanvas.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ interactioncanvas.h | 24 ++++++++++++++++++++++++ mainwindow.cpp | 7 +++++++ mainwindow.h | 6 ++++++ mainwindow.ui | 36 +----------------------------------- 7 files changed, 87 insertions(+), 38 deletions(-) create mode 100644 interactioncanvas.cpp create mode 100644 interactioncanvas.h diff --git a/GUI_SS2015.pro b/GUI_SS2015.pro index 5bb0a3e..f6527fc 100644 --- a/GUI_SS2015.pro +++ b/GUI_SS2015.pro @@ -14,10 +14,12 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ - dlgpreferences.cpp + dlgpreferences.cpp \ + interactioncanvas.cpp HEADERS += mainwindow.h \ - dlgpreferences.h + dlgpreferences.h \ + interactioncanvas.h FORMS += mainwindow.ui \ dlgpreferences.ui diff --git a/dlgpreferences.cpp b/dlgpreferences.cpp index 9174401..01e094c 100644 --- a/dlgpreferences.cpp +++ b/dlgpreferences.cpp @@ -7,7 +7,7 @@ DlgPreferences::DlgPreferences(QWidget *parent) : { ui->setupUi(this); - QIntValidator *val = new QIntValidator(100,800,this); + QIntValidator *val = new QIntValidator(100, 800, this); ui->lineEditHeight->setValidator(val); ui->lineEditWidth->setValidator(val); } @@ -25,7 +25,9 @@ DlgPreferences::~DlgPreferences() void DlgPreferences::setHeight(int arg) { if (m_Height == arg) + { return; + } m_Height = arg; ui->lineEditHeight->setText(QString::number(m_Height)); @@ -40,7 +42,9 @@ void DlgPreferences::setHeight(int arg) void DlgPreferences::setWidth(int arg) { if (m_Width == arg) + { return; + } m_Width = arg; ui->lineEditWidth->setText(QString::number(m_Width)); diff --git a/interactioncanvas.cpp b/interactioncanvas.cpp new file mode 100644 index 0000000..c289c40 --- /dev/null +++ b/interactioncanvas.cpp @@ -0,0 +1,40 @@ +#include "interactioncanvas.h" + +InteractionCanvas::InteractionCanvas() +{ + setFocusPolicy(Qt::StrongFocus); + setMouseTracking(true); +} + +InteractionCanvas::~InteractionCanvas() +{ + +} + +void InteractionCanvas::mouseMoveEvent(QMouseEvent *mouseEvent) +{ + qDebug() << "InteractionCanvas:" << mouseEvent->pos(); +} + + +void InteractionCanvas::mousePressEvent(QMouseEvent *mouseEvent) +{ + qDebug() << "InteractionCanvas: Mouse: pressed:" << mouseEvent->button(); +} + +void InteractionCanvas::mouseReleaseEvent(QMouseEvent *mouseEvent) +{ + qDebug() << "InteractionCanvas: Mouse: released:"<< mouseEvent->button(); +} + +void InteractionCanvas::keyPressEvent(QKeyEvent *keyEvent) +{ + qDebug() << "InteractionCanvas: Key: pressed:" << keyEvent->key() << "(" << + keyEvent->text() << ")" << (keyEvent->isAutoRepeat() ? "druck" : ""); +} + +void InteractionCanvas::keyReleaseEvent(QKeyEvent *keyEvent) +{ + qDebug() << "InteractionCanvas: Key: released:" << keyEvent->key() << "(" << + keyEvent->text() << ")" << (keyEvent->isAutoRepeat() ? "druck" : ""); +} diff --git a/interactioncanvas.h b/interactioncanvas.h new file mode 100644 index 0000000..efdf9a2 --- /dev/null +++ b/interactioncanvas.h @@ -0,0 +1,24 @@ +#ifndef INTERACTIONCANVAS_H +#define INTERACTIONCANVAS_H + +#include +#include +#include + +class InteractionCanvas : public QLabel +{ +public: + InteractionCanvas(); + ~InteractionCanvas(); + + // QWidget interface +protected: + void mouseMoveEvent(QMouseEvent *mouseEvent); + void mousePressEvent(QMouseEvent *mouseEvent); + void mouseReleaseEvent(QMouseEvent *mouseEvent); + void keyPressEvent(QKeyEvent *keyEvent); + void keyReleaseEvent(QKeyEvent *keyEvent); + +}; + +#endif // INTERACTIONCANVAS_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 155bd28..5a548db 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + setCentralWidget(new InteractionCanvas()); } MainWindow::~MainWindow() @@ -41,3 +42,9 @@ void MainWindow::on_actionPreferences_triggered() delete tmp; } + + +void MainWindow::mouseMoveEvent(QMouseEvent *mouseEvent) +{ + qDebug() << "MainWindow:" << mouseEvent->pos(); +} diff --git a/mainwindow.h b/mainwindow.h index 6f225be..410878f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,7 +3,9 @@ #include #include +#include #include "dlgpreferences.h" +#include "interactioncanvas.h" namespace Ui { class MainWindow; @@ -24,6 +26,10 @@ private slots: void on_actionPreferences_triggered(); private: Ui::MainWindow *ui; + + // QWidget interface +protected: + void mouseMoveEvent(QMouseEvent *mouseEvent); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 43bf0f5..8e92663 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -14,41 +14,7 @@ GUIProjekt SS2015_SS - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Hello Qt World. - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + -- cgit v1.2.3-70-g09d2