Blur and Command line opts
* blur background image
* command line options for
* background blur radius
* background opacity
* path to image folder
* timeout for password rotation
This commit is contained in:
50
src/main.cpp
50
src/main.cpp
@@ -5,27 +5,51 @@
|
||||
#include <sys/file.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void usage(std::string programName) {
|
||||
std::cerr << "Usage: " << programName << " [-t rotation_seconds] [-o background_opacity(0..255)] [-b blur_radius] -p image_folder" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int rotationSeconds = 30;
|
||||
std::string path = "";
|
||||
|
||||
int pid_file = open("/tmp/slide.pid", O_CREAT | O_RDWR, 0666);
|
||||
int rc = flock(pid_file, LOCK_EX | LOCK_NB);
|
||||
if(rc) {
|
||||
if(EWOULDBLOCK == errno) {
|
||||
std::cout << "Already running. Exiting" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (argc < 2) {
|
||||
std::cout << "Error: Path expected." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
QApplication a(argc, argv);
|
||||
|
||||
MainWindow w;
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "b:p:t:o:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
path = optarg;
|
||||
break;
|
||||
case 't':
|
||||
rotationSeconds = atoi(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
w.setBlurRadius(atoi(optarg));
|
||||
break;
|
||||
case 'o':
|
||||
w.setBackgroundOpacity(atoi(optarg));
|
||||
break;
|
||||
default: /* '?' */
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.empty()) {
|
||||
std::cout << "Error: Path expected." << std::endl;
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
w.show();
|
||||
|
||||
ImageSelector is(w, 30000, argv[1]);
|
||||
ImageSelector is(w, rotationSeconds * 1000, path);
|
||||
is.start();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <libexif/exif-data.h>
|
||||
#include <iostream>
|
||||
#include <QPainter>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <sstream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
image(new QLabel)
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||||
@@ -20,7 +23,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
QApplication::setOverrideCursor(Qt::BlankCursor);
|
||||
QLabel *label = this->findChild<QLabel*>("image");
|
||||
setCentralWidget(label);
|
||||
label->setStyleSheet("QLabel { background-color: rgba(0, 0, 0, 180);}");
|
||||
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
update();
|
||||
|
||||
@@ -100,7 +102,12 @@ void MainWindow::updateImage()
|
||||
QLabel *label = this->findChild<QLabel*>("image");
|
||||
label->setPixmap(scaled);
|
||||
|
||||
std::stringstream style;
|
||||
style << "QLabel { background-color: rgba(0, 0, 0, " << (255 - backgroundOpacity) << ");}";
|
||||
label->setStyleSheet(style.str().c_str());
|
||||
|
||||
drawBackground(rotated, scaled);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -122,15 +129,41 @@ void MainWindow::drawBackground(const QPixmap& originalSize, const QPixmap& scal
|
||||
{
|
||||
QPalette palette;
|
||||
if (scaled.width() < width()) {
|
||||
QPixmap background = originalSize.scaledToWidth(width());
|
||||
QPixmap background = blur(originalSize.scaledToWidth(width()));
|
||||
QRect rect(0, (background.height() - height())/2, width(), height());
|
||||
background = background.copy(rect);
|
||||
palette.setBrush(QPalette::Background, background);
|
||||
} else {
|
||||
QPixmap background = originalSize.scaledToHeight(height());
|
||||
QPixmap background = blur(originalSize.scaledToHeight(height()));
|
||||
QRect rect((background.width() - width())/2, 0, width(), height());
|
||||
background = background.copy(rect);
|
||||
palette.setBrush(QPalette::Background, background);
|
||||
}
|
||||
this->setPalette(palette);
|
||||
}
|
||||
|
||||
QPixmap MainWindow::blur(const QPixmap& input)
|
||||
{
|
||||
QGraphicsScene scene;
|
||||
QGraphicsPixmapItem item;
|
||||
item.setPixmap(input);
|
||||
QGraphicsBlurEffect effect;
|
||||
effect.setBlurRadius(blurRadius);
|
||||
item.setGraphicsEffect(&effect);
|
||||
scene.addItem(&item);
|
||||
QImage res(input.size(), QImage::Format_ARGB32);
|
||||
res.fill(Qt::transparent);
|
||||
QPainter ptr(&res);
|
||||
scene.render(&ptr, QRectF(), QRectF( 0, 0, input.width(), input.height()) );
|
||||
return QPixmap::fromImage(res);
|
||||
}
|
||||
|
||||
void MainWindow::setBlurRadius(unsigned int blurRadius)
|
||||
{
|
||||
this->blurRadius = blurRadius;
|
||||
}
|
||||
|
||||
void MainWindow::setBackgroundOpacity(unsigned int backgroundOpacity)
|
||||
{
|
||||
this->backgroundOpacity = backgroundOpacity;
|
||||
}
|
||||
|
||||
@@ -20,17 +20,23 @@ public:
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
~MainWindow();
|
||||
void setImage(std::string path);
|
||||
void setBlurRadius(unsigned int blurRadius);
|
||||
void setBackgroundOpacity(unsigned int opacity);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QLabel *image;
|
||||
|
||||
std::string currentImage;
|
||||
unsigned int blurRadius = 20;
|
||||
unsigned int backgroundOpacity = 150;
|
||||
|
||||
void updateImage();
|
||||
int getImageRotation();
|
||||
|
||||
QPixmap getRotatedPixmap(const QPixmap& p);
|
||||
QPixmap getScaledPixmap(const QPixmap& p);
|
||||
void drawBackground(const QPixmap& originalSize, const QPixmap& scaled);
|
||||
QPixmap blur(const QPixmap& input);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.6.2, 2019-01-21T21:06:46. -->
|
||||
<!-- Written by QtCreator 4.6.2, 2019-01-21T22:24:23. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -310,7 +310,7 @@
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">slide.pro</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/manuel/slide/build-slide-Desktop-Debug</value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
|
||||
Reference in New Issue
Block a user