From 2960ec8d215d7480bed08d85f88fd1394991a4ee Mon Sep 17 00:00:00 2001 From: pepe82sh Date: Sat, 12 Dec 2020 08:48:57 +0100 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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); From e3435c515350081da7ad4e4caf6b8c498565c4bc Mon Sep 17 00:00:00 2001 From: Manuel Dewald Date: Mon, 2 Aug 2021 10:49:54 +0200 Subject: [PATCH 5/6] refactor image filtering --- src/imageselector.cpp | 125 +++++++++++++++++++++--------------------- src/imageselector.h | 7 ++- 2 files changed, 69 insertions(+), 63 deletions(-) diff --git a/src/imageselector.cpp b/src/imageselector.cpp index 5271291..ab2341f 100644 --- a/src/imageselector.cpp +++ b/src/imageselector.cpp @@ -19,7 +19,7 @@ ImageSelector::ImageSelector(std::unique_ptr& pathTraverser, char ImageSelector::~ImageSelector(){} -int ImageSelector::getImageRotation(const std::string &fileName) +int ImageSelector::getImageRotation(const std::string& fileName) { int orientation = 0; ExifData *exifData = exif_data_new_from_file(fileName.c_str()); @@ -50,7 +50,29 @@ int ImageSelector::getImageRotation(const std::string &fileName) return degrees; } -bool ImageSelector::imageValidForAspect(const std::string &fileName) +bool ImageSelector::imageMatchesFilter(const std::string& fileName) +{ + if(!QFileInfo::exists(QString(fileName.c_str()))) + { + if(debugMode) + { + std::cout << "file not found: " << fileName << std::endl; + } + return false; + } + + if(!imageValidForAspect(fileName)) { + if(debugMode) + { + std::cout << "image aspect ratio doesn't match filter '" << aspect << "' : " << fileName << std::endl; + } + return false; + } + + return true; +} + +bool ImageSelector::imageValidForAspect(const std::string& fileName) { QPixmap p( fileName.c_str() ); int imageWidth = p.width(); @@ -96,17 +118,14 @@ std::string RandomImageSelector::getNextImage() std:: string filename; try { - while (filename.empty()) + QStringList images = pathTraverser->getImages(); + unsigned int selectedImage = selectRandom(images); + filename = pathTraverser->getImagePath(images.at(selectedImage).toStdString()); + while(!imageMatchesFilter(filename)) { - QStringList images = pathTraverser->getImages(); unsigned int selectedImage = selectRandom(images); filename = pathTraverser->getImagePath(images.at(selectedImage).toStdString()); - if (!imageValidForAspect(filename)) - { - filename.clear(); - } } - } catch(const std::string& err) { @@ -142,6 +161,24 @@ ShuffleImageSelector::~ShuffleImageSelector() } std::string ShuffleImageSelector::getNextImage() +{ + reloadImagesIfNoneLeft(); + if (images.size() == 0) + { + return ""; + } + std::string filename = pathTraverser->getImagePath(images.at(current_image_shuffle).toStdString()); + current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image + while(!imageMatchesFilter(filename)) { + reloadImagesIfNoneLeft(); + std::string filename = pathTraverser->getImagePath(images.at(current_image_shuffle).toStdString()); + current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image + } + std::cout << "updating image: " << filename << std::endl; + return filename; +} + +void ShuffleImageSelector::reloadImagesIfNoneLeft() { if (images.size() == 0 || current_image_shuffle >= images.size()) { @@ -152,32 +189,6 @@ std::string ShuffleImageSelector::getNextImage() std::mt19937 randomizer(rd()); std::shuffle(images.begin(), images.end(), randomizer); } - if (images.size() == 0) - { - return ""; - } - std::string filename = pathTraverser->getImagePath(images.at(current_image_shuffle).toStdString()); - if(!QFileInfo::exists(QString(filename.c_str()))) - { - if(debugMode) - { - std::cout << "file not found: " << filename << std::endl; - } - current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image - return getNextImage(); - } - if (!imageValidForAspect(filename)) - { - if(debugMode) - { - std::cout << "image has invalid aspect: " << filename << "(images left:" << (images.size()-current_image_shuffle) << ")" << std::endl; - } - current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image - return getNextImage(); - } - std::cout << "updating image: " << filename << std::endl; - current_image_shuffle = current_image_shuffle + 1; - return filename; } SortedImageSelector::SortedImageSelector(std::unique_ptr& pathTraverser, char aspect): @@ -204,6 +215,23 @@ bool operator<(const QString& lhs, const QString& rhs) noexcept{ } std::string SortedImageSelector::getNextImage() +{ + reloadImagesIfEmpty(); + if (images.size() == 0) + { + return ""; + } + std::string filename = pathTraverser->getImagePath(images.takeFirst().toStdString()); + while(!imageMatchesFilter(filename)) { + reloadImagesIfEmpty(); + filename = pathTraverser->getImagePath(images.takeFirst().toStdString()); + } + + std::cout << "updating image: " << filename << std::endl; + return filename; +} + +void SortedImageSelector::reloadImagesIfEmpty() { if (images.size() == 0) { @@ -213,33 +241,8 @@ std::string SortedImageSelector::getNextImage() { std::cout << "read " << images.size() << " images." << std::endl; for (int i = 0;i getImagePath(images.takeFirst().toStdString()); - if(!QFileInfo::exists(QString(filename.c_str()))) - { - if(debugMode) - { - std::cout << "file not found: " << filename << std::endl; - } - return getNextImage(); - } - if (!imageValidForAspect(filename)) - { - if(debugMode) - { - std::cout << "image has invalid aspect: " << filename << std::endl; - } - return getNextImage(); - } - - std::cout << "updating image: " << filename << std::endl; - return filename; -} +} \ No newline at end of file diff --git a/src/imageselector.h b/src/imageselector.h index 645f5af..0efd61e 100644 --- a/src/imageselector.h +++ b/src/imageselector.h @@ -17,8 +17,9 @@ public: void setDebugMode(bool debugModeIn) { debugMode = debugModeIn;} protected: - int getImageRotation(const std::string &fileName); - bool imageValidForAspect(const std::string &fileName); + int getImageRotation(const std::string& fileName); + bool imageMatchesFilter(const std::string& fileName); + bool imageValidForAspect(const std::string& fileName); std::unique_ptr& pathTraverser; char aspect; bool debugMode = false; @@ -43,6 +44,7 @@ public: virtual std::string getNextImage(); private: + void reloadImagesIfNoneLeft(); int current_image_shuffle; QStringList images; }; @@ -55,6 +57,7 @@ public: virtual std::string getNextImage(); private: + void reloadImagesIfEmpty(); QStringList images; }; #endif // IMAGESELECTOR_H From 687a2eb91abf5f6dcd2198976805b6d4f3bae9e6 Mon Sep 17 00:00:00 2001 From: Manuel Dewald Date: Mon, 2 Aug 2021 11:00:56 +0200 Subject: [PATCH 6/6] Add instructions to exit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0246fe4..73b6833 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ slide [-t rotation_seconds] [-a aspect] [-o background_opacity(0..255)] [-b blur * ``path to the current image without filename * Example: `slide -p ./images -O "20|60|Time: