configurable overlay color

This commit is contained in:
gdzhu
2021-08-28 07:38:48 +01:00
committed by Guodong Zhu
parent 687a2eb91a
commit 1fa6eb300c
3 changed files with 28 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
#include "pathtraverser.h" #include "pathtraverser.h"
#include "overlay.h" #include "overlay.h"
#include <QApplication> #include <QApplication>
#include <QRegularExpression>
#include <iostream> #include <iostream>
#include <sys/file.h> #include <sys/file.h>
#include <errno.h> #include <errno.h>
@@ -35,15 +36,18 @@ int main(int argc, char *argv[])
bool fitAspectAxisToWindow = false; bool fitAspectAxisToWindow = false;
std::string valid_aspects = "alp"; // all, landscape, portait std::string valid_aspects = "alp"; // all, landscape, portait
std::string overlay = ""; std::string overlay = "";
QString overlayHexRGB = QString();
QRegularExpression hexRGBMatcher("^#([0-9A-Fa-f]{3}){1,2}$");
int debugInt = 0; int debugInt = 0;
int stretchInt = 0; int stretchInt = 0;
static struct option long_options[] = static struct option long_options[] =
{ {
{"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, 'c'},
}; };
int option_index = 0; int option_index = 0;
while ((opt = getopt_long(argc, argv, "b:p:t:o:O:a:rsSv", long_options, &option_index)) != -1) { while ((opt = getopt_long(argc, argv, "b:p:t:o:O:c:a: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. */
@@ -85,6 +89,9 @@ int main(int argc, char *argv[])
case 'O': case 'O':
overlay = optarg; overlay = optarg;
break; break;
case 'c':
overlayHexRGB = QString::fromStdString(optarg);
break;
case 'v': case 'v':
debugMode = true; debugMode = true;
break; break;
@@ -109,6 +116,16 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
if (!overlayHexRGB.isEmpty())
{
if(!hexRGBMatcher.match(overlayHexRGB).hasMatch())
{
std::cout << "Error: hex rgb string expected. e.g. #FFFFFF or #FFF" << std::endl;
return 1;
}
w.setOverlayHexRGB(overlayHexRGB);
}
std::unique_ptr<PathTraverser> pathTraverser; std::unique_ptr<PathTraverser> pathTraverser;
if (recursive) if (recursive)
{ {

View File

@@ -217,7 +217,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) {
//std::cout << "text: " << text.toStdString() << " margin: " << margin << " fontsize: " << fontsize<< std::endl; //std::cout << "text: " << text.toStdString() << " margin: " << margin << " fontsize: " << fontsize<< std::endl;
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,
@@ -337,6 +337,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

@@ -29,6 +29,7 @@ public:
void setAspect(char aspectIn); void setAspect(char aspectIn);
void setDebugMode(bool debugModeIn) {debugMode = debugModeIn;} void setDebugMode(bool debugModeIn) {debugMode = debugModeIn;}
void setFitAspectAxisToWindow(bool fitAspectAxisToWindowIn) { fitAspectAxisToWindow = fitAspectAxisToWindowIn; } void setFitAspectAxisToWindow(bool fitAspectAxisToWindowIn) { fitAspectAxisToWindow = fitAspectAxisToWindowIn; }
void setOverlayHexRGB(QString overlayHexRGB);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
@@ -38,6 +39,7 @@ private:
char aspect = 'a'; char aspect = 'a';
bool debugMode = false; bool debugMode = false;
bool fitAspectAxisToWindow = false; bool fitAspectAxisToWindow = false;
QString overlayHexRGB;
Overlay* overlay; Overlay* overlay;