- merge from main

This commit is contained in:
Alfred Reynolds
2021-09-09 08:56:03 +12:00
parent 8bb97ed926
commit b45e7dbda9
5 changed files with 30 additions and 13 deletions

View File

@@ -9,6 +9,7 @@
struct Config {
public:
unsigned int rotationSeconds = 30;
unsigned int transitionTime = 1;
int blurRadius = -1;
int backgroundOpacity = -1;
ImageDisplayOptions baseDisplayOptions;

View File

@@ -20,7 +20,7 @@
#include <memory>
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}$");

View File

@@ -119,8 +119,9 @@ bool MainWindow::event(QEvent* event)
void MainWindow::resizeEvent(QResizeEvent* event)
{
QMainWindow::resizeEvent(event);
updateImage(true);
QMainWindow::resizeEvent(event);
this->findChild<QLabel*>("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<QLabel*>("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<QLabel*>("image");

View File

@@ -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> &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> 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);