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 "overlay.h"
#include <QApplication>
#include <QRegularExpression>
#include <iostream>
#include <sys/file.h>
#include <errno.h>
@@ -35,15 +36,18 @@ int main(int argc, char *argv[])
bool fitAspectAxisToWindow = false;
std::string valid_aspects = "alp"; // all, landscape, portait
std::string overlay = "";
QString overlayHexRGB = QString();
QRegularExpression hexRGBMatcher("^#([0-9A-Fa-f]{3}){1,2}$");
int debugInt = 0;
int stretchInt = 0;
static struct option long_options[] =
{
{"verbose", no_argument, &debugInt, 1},
{"stretch", no_argument, &stretchInt, 1},
{"overlay-color", required_argument, 0, 'c'},
};
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) {
case 0:
/* If this option set a flag, do nothing else now. */
@@ -85,6 +89,9 @@ int main(int argc, char *argv[])
case 'O':
overlay = optarg;
break;
case 'c':
overlayHexRGB = QString::fromStdString(optarg);
break;
case 'v':
debugMode = true;
break;
@@ -109,6 +116,16 @@ int main(int argc, char *argv[])
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;
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) {
//std::cout << "text: " << text.toStdString() << " margin: " << margin << " fontsize: " << fontsize<< std::endl;
QPainter pt(&image);
pt.setPen(QPen(Qt::white));
pt.setPen(QPen(QColor(overlayHexRGB)));
pt.setFont(QFont("Sans", fontsize, QFont::Bold));
QRect marginRect = image.rect().adjusted(
margin,
@@ -337,6 +337,11 @@ void MainWindow::setBackgroundOpacity(unsigned int backgroundOpacity)
this->backgroundOpacity = backgroundOpacity;
}
void MainWindow::setOverlayHexRGB(QString overlayHexRGB)
{
this->overlayHexRGB = overlayHexRGB;
}
void MainWindow::warn(std::string text)
{
QLabel *label = this->findChild<QLabel*>("image");

View File

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