diff --git a/src/main.cpp b/src/main.cpp index accc571..f9f03b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "pathtraverser.h" #include "overlay.h" #include +#include #include #include #include @@ -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}, + {"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; if (recursive) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 61f2f94..752ffd4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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("image"); diff --git a/src/mainwindow.h b/src/mainwindow.h index 42eaa04..bcd4225 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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;