Merge branch 'master' of https://github.com/NautiluX/slide into NautiluX-master

This commit is contained in:
Alfred Reynolds
2021-09-08 11:05:10 +12:00
3 changed files with 37 additions and 6 deletions

View File

@@ -8,6 +8,7 @@
#include <QApplication> #include <QApplication>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QRegularExpression>
#include <iostream> #include <iostream>
#include <sys/file.h> #include <sys/file.h>
#include <errno.h> #include <errno.h>
@@ -22,6 +23,9 @@ 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] [-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;
} }
QString overlayHexRGB = QString("#FFFFFF");
QRegularExpression hexRGBMatcher("^#([0-9A-Fa-f]{3}){1,2}$");
bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) { bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
int opt; int opt;
int debugInt = 0; int debugInt = 0;
@@ -30,9 +34,10 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
{ {
{"verbose", no_argument, &debugInt, 1}, {"verbose", no_argument, &debugInt, 1},
{"stretch", no_argument, &stretchInt, 1}, {"stretch", no_argument, &stretchInt, 1},
{"overlay-color", required_argument, 0, 'h'},
}; };
int option_index = 0; int option_index = 0;
while ((opt = getopt_long(argc, argv, "b:p:t:o:O:a:i:c:rsSv", long_options, &option_index)) != -1) { while ((opt = getopt_long(argc, argv, "b:p:t:o:O:a:i:c:h:rsSv", long_options, &option_index)) != -1) {
switch (opt) { switch (opt) {
case 0: case 0:
/* If this option set a flag, do nothing else now. */ /* If this option set a flag, do nothing else now. */
@@ -84,6 +89,9 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
case 'O': case 'O':
appConfig.overlay = optarg; appConfig.overlay = optarg;
break; break;
case 'h':
overlayHexRGB = QString::fromStdString(optarg);
break;
case 'v': case 'v':
appConfig.debugMode = true; appConfig.debugMode = true;
break; break;
@@ -123,8 +131,24 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig)
{ {
w.setBackgroundOpacity(appConfig.backgroundOpacity); w.setBackgroundOpacity(appConfig.backgroundOpacity);
} }
if (!overlayHexRGB.isEmpty())
{
if(!hexRGBMatcher.match(overlayHexRGB).hasMatch())
{
std::cout << "Error: hex rgb string expected. e.g. #FFFFFF or #FFF" << std::endl;
}
else
{
w.setOverlayHexRGB(overlayHexRGB);
}
}
if (!appConfig.overlay.empty())
{
std::unique_ptr<Overlay> o = std::unique_ptr<Overlay>(new Overlay(appConfig.overlay)); std::unique_ptr<Overlay> o = std::unique_ptr<Overlay>(new Overlay(appConfig.overlay));
w.setOverlay(o); w.setOverlay(o);
}
w.setBaseOptions(appConfig.baseDisplayOptions); w.setBaseOptions(appConfig.baseDisplayOptions);
} }

View File

@@ -281,7 +281,7 @@ void MainWindow::updateImage(bool immediately)
void MainWindow::drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment) { void MainWindow::drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment) {
QPainter pt(&image); QPainter pt(&image);
pt.setPen(QPen(Qt::white)); pt.setPen(QPen(QColor(overlayHexRGB)));
pt.setFont(QFont("Sans", fontsize, QFont::Bold)); pt.setFont(QFont("Sans", fontsize, QFont::Bold));
QRect marginRect = image.rect().adjusted( QRect marginRect = image.rect().adjusted(
margin, margin,
@@ -396,6 +396,11 @@ void MainWindow::setBackgroundOpacity(unsigned int backgroundOpacity)
this->backgroundOpacity = backgroundOpacity; this->backgroundOpacity = backgroundOpacity;
} }
void MainWindow::setOverlayHexRGB(QString overlayHexRGB)
{
this->overlayHexRGB = overlayHexRGB;
}
void MainWindow::warn(std::string text) void MainWindow::warn(std::string text)
{ {
QLabel *label = this->findChild<QLabel*>("image"); QLabel *label = this->findChild<QLabel*>("image");

View File

@@ -34,6 +34,7 @@ public:
const ImageDisplayOptions &getBaseOptions(); const ImageDisplayOptions &getBaseOptions();
void setImageSwitcher(ImageSwitcher *switcherIn); void setImageSwitcher(ImageSwitcher *switcherIn);
void setNetworkManager(QNetworkAccessManager *networkManagerIn); void setNetworkManager(QNetworkAccessManager *networkManagerIn);
void setOverlayHexRGB(QString overlayHexRGB);
public slots: public slots:
void checkWindowSize(); void checkWindowSize();
private slots: private slots:
@@ -50,6 +51,7 @@ private:
QNetworkAccessManager *networkManager = nullptr; QNetworkAccessManager *networkManager = nullptr;
QNetworkReply *pendingReply = nullptr; QNetworkReply *pendingReply = nullptr;
QSize lastScreenSize = {0,0}; QSize lastScreenSize = {0,0};
QString overlayHexRGB = "#FFFF";
std::unique_ptr<Overlay> overlay; std::unique_ptr<Overlay> overlay;
ImageSwitcher *switcher = nullptr; ImageSwitcher *switcher = nullptr;