From b45e7dbda9cd89f41ec2eab3373bb763c172be95 Mon Sep 17 00:00:00 2001 From: Alfred Reynolds Date: Thu, 9 Sep 2021 08:56:03 +1200 Subject: [PATCH] - merge from main --- README.md | 5 ++++- src/appconfig.h | 1 + src/main.cpp | 9 +++++++-- src/mainwindow.cpp | 24 +++++++++++++++--------- src/mainwindow.h | 4 +++- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 18521a5..d487fb6 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This project is maintained by myself during my spare time. If you like and use i ## Usage ``` -slide [-t rotation_seconds] [-a aspect] [-o background_opacity(0..255)] [-b blur_radius] [-p image_folder|-i imageFile,...] [-r] [-O overlay_string] [-v] [--verbose] [--stretch] [-c path_to_config_json] +slide [-t rotation_seconds] [-T transition_seconds] [-h/--overlay-color overlay_color(#rrggbb)] [-a aspect] [-o background_opacity(0..255)] [-b blur_radius] [-p image_folder|-i imageFile,...] [-r] [-O overlay_string] [-v] [--verbose] [--stretch] [-c path_to_config_json] ``` * `image_folder`: where to search for images (.jpg files) @@ -30,10 +30,13 @@ slide [-t rotation_seconds] [-a aspect] [-o background_opacity(0..255)] [-b blur * `-S` for sorted rotation (files ordered by name, first images then subfolders) * `rotation_seconds(default=30)`: time until next random image is chosen from the given folder * `aspect(default=a)`: the required aspect ratio of the picture to display. Valid values are 'a' (all), 'l' (landscape), 'p' (portrait) and 'm' (monitor). Monitor will match the aspect ratio of the display we are running on. +* `transition_seconds(default=1)`: time of image transition animation. Default is 1 second, and transition animation will be disabled if the value is set to 0 +* `aspect(default=a)`: the required aspect ratio of the picture to display. Valid values are 'a' (all), 'l' (landscape) and 'p' (portrait) * `background_opacity(default=150)`: opacity of the background filling image between 0 (black background) and 255 * `blur_radius(default=20)`: blur radius of the background filling image * `-v` or `--verbose`: Verbose debug output when running, plus a thumbnail of the original image in the bottom left of the screen * `--stretch`: When in aspect mode 'l','p' or 'm' crop the image rather than leaving a blurred background. For example, in landscape mode this will make images as wide as the screen and crop the top and bottom to fit. +* `-h` or `--overlay-color` the color of the overlay text, in the form of 3 or 6 digits hex rgb string prefixed by `#`, for example `#00FF00` or `#0F0` for color 🟢 * `-O` is used to create a overlay string. * It defines overlays for all four edges in the order `top-left;top-right;bottom-left;bottom-right` * All edges overlays are separated by `;` diff --git a/src/appconfig.h b/src/appconfig.h index c5b3df1..64b22e2 100644 --- a/src/appconfig.h +++ b/src/appconfig.h @@ -9,6 +9,7 @@ struct Config { public: unsigned int rotationSeconds = 30; + unsigned int transitionTime = 1; int blurRadius = -1; int backgroundOpacity = -1; ImageDisplayOptions baseDisplayOptions; diff --git a/src/main.cpp b/src/main.cpp index 3dd747a..4a3b42d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ #include void usage(std::string programName) { - std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-a aspect('l','p','a', 'm')] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder [-r] [-s] [-v] [--verbose] [--stretch] [-c config_file_path]" << std::endl; + std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-T transition_seconds] [-h/--overlay-color #rrggbb] [-a aspect('l','p','a', 'm')] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder [-r] [-s] [-S] [-v] [--verbose] [--stretch] [-c config_file_path]" << std::endl; } bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) { @@ -34,7 +34,7 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) { {"overlay-color", required_argument, 0, 'h'}, }; int option_index = 0; - while ((opt = getopt_long(argc, argv, "b:p:t:o:O:a:i:c:h:rsSv", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "b:p:t:T:o:O:a:i:c:h:rsSv", long_options, &option_index)) != -1) { switch (opt) { case 0: /* If this option set a flag, do nothing else now. */ @@ -61,6 +61,9 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) { case 't': appConfig.rotationSeconds = atoi(optarg); break; + case 'T': + appConfig.transitionTime =atoi(optarg); + break; case 'b': appConfig.blurRadius = atoi(optarg); break; @@ -129,6 +132,8 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig) w.setBackgroundOpacity(appConfig.backgroundOpacity); } + w.setTransitionTime(appConfig.transitionTime); + if (!appConfig.overlayHexRGB.isEmpty()) { QRegularExpression hexRGBMatcher("^#([0-9A-Fa-f]{3}){1,2}$"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 717c133..5c3ffcd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -119,8 +119,9 @@ bool MainWindow::event(QEvent* event) void MainWindow::resizeEvent(QResizeEvent* event) { - QMainWindow::resizeEvent(event); - updateImage(true); + QMainWindow::resizeEvent(event); + this->findChild("image")->clear(); + updateImage(); } void MainWindow::checkWindowSize() @@ -133,7 +134,7 @@ void MainWindow::checkWindowSize() { Log("Resizing Window", screenSize.width(), "," , screenSize.height() ); setFixedSize(screenSize); - updateImage(true); + updateImage(); } if (imageAspectMatchesMonitor) @@ -166,7 +167,7 @@ void MainWindow::setImage(const ImageDetails &imageDetails) { pendingReply->abort(); } - updateImage(false); + updateImage(); } void MainWindow::fileDownloaded(QNetworkReply* netReply) @@ -179,12 +180,12 @@ void MainWindow::fileDownloaded(QNetworkReply* netReply) { downloadedData = netReply->readAll(); netReply->deleteLater(); - updateImage(false); + updateImage(); } } } -void MainWindow::updateImage(bool immediately) +void MainWindow::updateImage() { checkWindowSize(); if (currentImage.filename == "") @@ -203,7 +204,7 @@ void MainWindow::updateImage(bool immediately) QLabel *label = this->findChild("image"); const QPixmap* oldImage = label->pixmap(); - if (oldImage != NULL && !immediately) + if (oldImage != NULL && transitionSeconds > 0) { QPalette palette; palette.setBrush(QPalette::Background, *oldImage); @@ -256,13 +257,13 @@ void MainWindow::updateImage(bool immediately) label->setPixmap(background); - if (oldImage != NULL && !immediately) + if (oldImage != NULL && transitionSeconds > 0) { auto effect = new QGraphicsOpacityEffect(label); effect->setOpacity(0.0); label->setGraphicsEffect(effect); QPropertyAnimation* animation = new QPropertyAnimation(effect, "opacity"); - animation->setDuration(1000); + animation->setDuration(transitionSeconds*1000); animation->setStartValue(0); animation->setEndValue(1); animation->start(QAbstractAnimation::DeleteWhenStopped); @@ -393,6 +394,11 @@ void MainWindow::setOverlayHexRGB(QString overlayHexRGB) this->overlayHexRGB = overlayHexRGB; } +void MainWindow::setTransitionTime(unsigned int transitionSeconds) +{ + this->transitionSeconds = transitionSeconds; +} + void MainWindow::warn(std::string text) { QLabel *label = this->findChild("image"); diff --git a/src/mainwindow.h b/src/mainwindow.h index fcfac94..916d249 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,6 +28,7 @@ public: void setImage(const ImageDetails &imageDetails); void setBlurRadius(unsigned int blurRadius); void setBackgroundOpacity(unsigned int opacity); + void setTransitionTime(unsigned int transitionSeconds); void warn(std::string text); void setOverlay(std::unique_ptr &overlay); void setBaseOptions(const ImageDisplayOptions &baseOptionsIn); @@ -52,13 +53,14 @@ private: QNetworkReply *pendingReply = nullptr; QSize lastScreenSize = {0,0}; QString overlayHexRGB = "#FFFF"; + unsigned int transitionSeconds = 1; std::unique_ptr overlay; ImageSwitcher *switcher = nullptr; void drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment); - void updateImage(bool immediately); + void updateImage(); int getImageRotation(); QPixmap getBlurredBackground(const QPixmap& originalSize, const QPixmap& scaled);