configurable transition time
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
#include <memory>
|
||||
|
||||
void usage(std::string programName) {
|
||||
std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-a aspect('l','p','a')] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder [-r] [-s] [-v] [--verbose] [--stretch]" << std::endl;
|
||||
std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-T transition_seconds] [-c/--overlay-color #rrggbb] [-a aspect('l','p','a')] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder [-r] [-O overlay_string] [-s] [-S] [-v] [--verbose] [--stretch]" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
|
||||
{"overlay-color", required_argument, 0, 'c'},
|
||||
};
|
||||
int option_index = 0;
|
||||
while ((opt = getopt_long(argc, argv, "b:p:t:o:O:c:a:rsSv", long_options, &option_index)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, "b:p:t:T:o:O:c:a:rsSv", long_options, &option_index)) != -1) {
|
||||
switch (opt) {
|
||||
case 0:
|
||||
/* If this option set a flag, do nothing else now. */
|
||||
@@ -70,6 +70,9 @@ int main(int argc, char *argv[])
|
||||
case 't':
|
||||
rotationSeconds = atoi(optarg);
|
||||
break;
|
||||
case 'T':
|
||||
w.setTransitionTime(atoi(optarg));
|
||||
break;
|
||||
case 'b':
|
||||
w.setBlurRadius(atoi(optarg));
|
||||
break;
|
||||
|
||||
@@ -105,13 +105,14 @@ bool MainWindow::event(QEvent* event)
|
||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QMainWindow::resizeEvent(event);
|
||||
updateImage(true);
|
||||
this->findChild<QLabel*>("image")->clear();
|
||||
updateImage();
|
||||
}
|
||||
|
||||
void MainWindow::setImage(std::string path)
|
||||
{
|
||||
currentImage = path;
|
||||
updateImage(false);
|
||||
updateImage();
|
||||
}
|
||||
|
||||
int MainWindow::getImageRotation()
|
||||
@@ -149,14 +150,14 @@ int MainWindow::getImageRotation()
|
||||
return degrees;
|
||||
}
|
||||
|
||||
void MainWindow::updateImage(bool immediately)
|
||||
void MainWindow::updateImage()
|
||||
{
|
||||
if (currentImage == "")
|
||||
return;
|
||||
|
||||
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);
|
||||
@@ -199,13 +200,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);
|
||||
@@ -340,6 +341,10 @@ void MainWindow::setBackgroundOpacity(unsigned int backgroundOpacity)
|
||||
void MainWindow::setOverlayHexRGB(QString overlayHexRGB)
|
||||
{
|
||||
this->overlayHexRGB = overlayHexRGB;
|
||||
|
||||
void MainWindow::setTransitionTime(unsigned int transitionSeconds)
|
||||
{
|
||||
this->transitionSeconds = transitionSeconds;
|
||||
}
|
||||
|
||||
void MainWindow::warn(std::string text)
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
void setImage(std::string path);
|
||||
void setBlurRadius(unsigned int blurRadius);
|
||||
void setBackgroundOpacity(unsigned int opacity);
|
||||
void setTransitionTime(unsigned int transitionSeconds);
|
||||
void warn(std::string text);
|
||||
void setOverlay(Overlay* overlay);
|
||||
void setAspect(char aspectIn);
|
||||
@@ -36,6 +37,7 @@ private:
|
||||
std::string currentImage;
|
||||
unsigned int blurRadius = 20;
|
||||
unsigned int backgroundOpacity = 150;
|
||||
unsigned int transitionSeconds = 1;
|
||||
char aspect = 'a';
|
||||
bool debugMode = false;
|
||||
bool fitAspectAxisToWindow = false;
|
||||
@@ -45,7 +47,7 @@ private:
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user