From 2960ec8d215d7480bed08d85f88fd1394991a4ee Mon Sep 17 00:00:00 2001 From: pepe82sh Date: Sat, 12 Dec 2020 08:48:57 +0100 Subject: [PATCH 1/4] Fixed full screen behaviour In case the screen resulution did not match the size set in mainwindow.ui, you may only see part of the image shown. Putting the window in full screen explicitly fixes that issue. --- src/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f050002..bea10d6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,6 +25,7 @@ MainWindow::MainWindow(QWidget *parent) : QLabel *label = this->findChild("image"); setCentralWidget(label); label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + showFullScreen(); update(); } From 94d18177c215c12e858b9d61938af422c04fe7fe Mon Sep 17 00:00:00 2001 From: pepe82sh Date: Sat, 12 Dec 2020 11:45:00 +0100 Subject: [PATCH 2/4] Revert "Fixed full screen behaviour" This reverts commit 2960ec8d215d7480bed08d85f88fd1394991a4ee. --- src/mainwindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bea10d6..f050002 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,7 +25,6 @@ MainWindow::MainWindow(QWidget *parent) : QLabel *label = this->findChild("image"); setCentralWidget(label); label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - showFullScreen(); update(); } From 63134918166a316a5f76af9f1dcdfcb61c425ec7 Mon Sep 17 00:00:00 2001 From: pepe82sh Date: Sat, 12 Dec 2020 11:53:02 +0100 Subject: [PATCH 3/4] Fixed display issues with oversized window If the window defined in src/mainwindow.ui exceeds the size of the display, the program behaves weirdly. Growing the window size even further leads to crashes. Reducing the window size to 1x1px seems to work fine and should be smaller than any display size. --- src/mainwindow.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.ui b/src/mainwindow.ui index caa5029..d8e7991 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1500 - 945 + 1 + 1 From 70806017d1a32aca784099ec965b43f9480139c2 Mon Sep 17 00:00:00 2001 From: pepe82sh Date: Wed, 16 Dec 2020 20:54:06 +0100 Subject: [PATCH 4/4] Touch off feature The program will quit if all 4 corners of a touch screen are touched simultaniously. --- src/mainwindow.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++ src/mainwindow.h | 5 +++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f050002..e074947 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -20,6 +20,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + setAttribute(Qt::WA_AcceptTouchEvents); + QTimer::singleShot(5, this, SLOT(showFullScreen())); QApplication::setOverrideCursor(Qt::BlankCursor); QLabel *label = this->findChild("image"); @@ -44,6 +46,59 @@ void MainWindow::keyPressEvent(QKeyEvent* event) QWidget::keyPressEvent(event); } +bool isTouchEvent(const QEvent &event) +{ + if(event.type() == QEvent::TouchBegin) + return true; + if(event.type() == QEvent::TouchUpdate) + return true; + return false; +} + +bool isQuitCombination(const QTouchEvent &touchEvent) +{ + bool topLeftTouched = false; + bool topRightTouched = false; + bool bottomLeftTouched = false; + bool bottomRightTouched = false; + for(const auto &touchPoint : touchEvent.touchPoints()) + { + const qreal normalizedCornerSize = 0.1; + const qreal x = touchPoint.normalizedPos().x(); + const qreal y = touchPoint.normalizedPos().y(); + if(x < normalizedCornerSize) + { + if(y < normalizedCornerSize) + topLeftTouched = true; + else if(y > 1-normalizedCornerSize) + bottomLeftTouched = true; + } + else if(x > 1-normalizedCornerSize) + { + if(y < normalizedCornerSize) + topRightTouched = true; + else if(y > 1-normalizedCornerSize) + bottomRightTouched = true; + } + } + return topLeftTouched && topRightTouched + && bottomLeftTouched && bottomRightTouched; +} + +bool MainWindow::event(QEvent* event) +{ + if(isTouchEvent(*event)) + { + if(isQuitCombination(dynamic_cast(*event))) + QCoreApplication::quit(); + } + else + { + return QMainWindow::event(event); + } + return true; +} + void MainWindow::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); diff --git a/src/mainwindow.h b/src/mainwindow.h index 636ebb4..48f2e91 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -16,8 +16,9 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); - void keyPressEvent(QKeyEvent* event); - void resizeEvent(QResizeEvent* event); + void keyPressEvent(QKeyEvent* event) override; + bool event(QEvent* event) override; + void resizeEvent(QResizeEvent* event) override; ~MainWindow(); void setImage(std::string path); void setBlurRadius(unsigned int blurRadius);