-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Manuel Dewald
committed
Mar 4, 2021
1 parent
c84f014
commit d4beb46
Showing
7 changed files
with
262 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "overlay.h" | ||
#include <QString> | ||
#include <QDateTime> | ||
#include <libexif/exif-data.h> | ||
#include <unistd.h> | ||
#include <QDate> | ||
#include <QLocale> | ||
#include <QTime> | ||
#include <QStringList> | ||
#include <QRegExp> | ||
#include <iostream> | ||
|
||
Overlay::Overlay(const std::string overlayInput): | ||
overlayInput(overlayInput) | ||
{ | ||
parseInput(); | ||
} | ||
|
||
Overlay::~Overlay() {} | ||
|
||
void Overlay::parseInput() { | ||
QString str = QString(overlayInput.c_str()); | ||
QStringList corners = str.split(QLatin1Char(';')); | ||
if (corners.size() > 0) { | ||
QStringList components = getOverlayComponents(corners[0]); | ||
topLeftTemplate = getTemplate(components); | ||
topLeftMargin = getMargin(components); | ||
topLeftFontsize = getFontsize(components); | ||
} | ||
if (corners.size() > 1) { | ||
QStringList components = getOverlayComponents(corners[1]); | ||
topRightTemplate = getTemplate(components); | ||
topRightMargin = getMargin(components); | ||
topRightFontsize = getFontsize(components); | ||
} | ||
if (corners.size() > 2) { | ||
QStringList components = getOverlayComponents(corners[2]); | ||
bottomLeftTemplate = getTemplate(components); | ||
bottomLeftMargin = getMargin(components); | ||
bottomLeftFontsize = getFontsize(components); | ||
} | ||
if (corners.size() > 3) { | ||
QStringList components = getOverlayComponents(corners[3]); | ||
bottomRightTemplate = getTemplate(components); | ||
bottomRightMargin = getMargin(components); | ||
bottomRightFontsize = getFontsize(components); | ||
} | ||
} | ||
|
||
QString Overlay::getTemplate(QStringList components){ | ||
if (components.size()>3) { | ||
std::cout << "template: " << components[3].toStdString() << std::endl; | ||
return components[3]; | ||
} | ||
return ""; | ||
} | ||
|
||
int Overlay::getMargin(QStringList components){ | ||
if (components.size()>1) { | ||
std::cout << "margin: " << components[1].toStdString() << std::endl; | ||
int num = components[1].toInt(); | ||
if (num > 0) { | ||
return num; | ||
} | ||
} | ||
|
||
return 20; | ||
} | ||
|
||
int Overlay::getFontsize(QStringList components){ | ||
if (components.size()>2) { | ||
std::cout << "fontsize: " << components[2].toStdString() << std::endl; | ||
int num = components[2].toInt(); | ||
if (num > 0) { | ||
return num; | ||
} | ||
} | ||
|
||
return 12; | ||
} | ||
|
||
|
||
QStringList Overlay::getOverlayComponents(QString corner) { | ||
QRegExp regex("([\\d]*)\\|([\\d]*)\\|(.*)"); | ||
if (regex.exactMatch(corner)){ | ||
return regex.capturedTexts(); | ||
} | ||
QStringList malformed; | ||
malformed << "" << "" << "" << corner; | ||
return malformed; | ||
} | ||
|
||
std::string Overlay::getRenderedTopLeft(std::string filename) { | ||
return renderString(topLeftTemplate, filename); | ||
} | ||
std::string Overlay::getRenderedTopRight(std::string filename) { | ||
return renderString(topRightTemplate, filename); | ||
} | ||
std::string Overlay::getRenderedBottomLeft(std::string filename) { | ||
return renderString(bottomLeftTemplate, filename); | ||
} | ||
std::string Overlay::getRenderedBottomRight(std::string filename) { | ||
return renderString(bottomRightTemplate, filename); | ||
} | ||
|
||
int Overlay::getMarginTopLeft() {return topLeftMargin;} | ||
int Overlay::getFontsizeTopLeft() {return topLeftFontsize;} | ||
int Overlay::getMarginTopRight() {return topRightMargin;} | ||
int Overlay::getFontsizeTopRight() {return topRightFontsize;} | ||
int Overlay::getMarginBottomLeft() {return bottomLeftMargin;} | ||
int Overlay::getFontsizeBottomLeft() {return bottomLeftFontsize;} | ||
int Overlay::getMarginBottomRight() {return bottomRightMargin;} | ||
int Overlay::getFontsizeBottomRight() {return bottomRightFontsize;} | ||
|
||
std::string Overlay::renderString(QString overlayTemplate, std::string filename) { | ||
QString result = overlayTemplate; | ||
result.replace("<datetime>", QLocale::system().toString(QDateTime::currentDateTime())); | ||
result.replace("<date>", QLocale::system().toString(QDate::currentDate())); | ||
result.replace("<time>", QTime::currentTime().toString("hh:mm")); | ||
result.replace("<filename>", filename.c_str()); | ||
result.replace("<exifdatetime>", getExifDate(filename)); | ||
return result.toStdString(); | ||
} | ||
|
||
QString Overlay::getExifDate(std::string filename) { | ||
|
||
QString dateTime; | ||
ExifData *exifData = exif_data_new_from_file(filename.c_str()); | ||
if (exifData) | ||
{ | ||
ExifEntry *exifEntry = exif_data_get_entry(exifData, EXIF_TAG_DATE_TIME_ORIGINAL); | ||
|
||
if (exifEntry) | ||
{ | ||
char buf[2048]; | ||
dateTime = exif_entry_get_value(exifEntry, buf, sizeof(buf)); | ||
} | ||
exif_data_free(exifData); | ||
QString exifDateFormat = "yyyy:MM:dd hh:mm:ss"; | ||
QDateTime exifDateTime = QDateTime::fromString(dateTime, exifDateFormat); | ||
return QLocale::system().toString(exifDateTime); | ||
} | ||
return dateTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef OVERLAY_H | ||
#define OVERLAY_H | ||
|
||
#include <iostream> | ||
#include <QDir> | ||
#include <iostream> | ||
#include <QString> | ||
#include <QStringList> | ||
|
||
class MainWindow; | ||
class Overlay | ||
{ | ||
public: | ||
Overlay(const std::string path); | ||
virtual ~Overlay(); | ||
std::string getRenderedTopLeft(std::string filename); | ||
std::string getRenderedTopRight(std::string filename); | ||
std::string getRenderedBottomLeft(std::string filename); | ||
std::string getRenderedBottomRight(std::string filename); | ||
|
||
int getMarginTopLeft(); | ||
int getFontsizeTopLeft(); | ||
int getMarginTopRight(); | ||
int getFontsizeTopRight(); | ||
int getMarginBottomLeft(); | ||
int getFontsizeBottomLeft(); | ||
int getMarginBottomRight(); | ||
int getFontsizeBottomRight(); | ||
|
||
|
||
private: | ||
const std::string overlayInput; | ||
int margin; | ||
int fontsize; | ||
|
||
QString topLeftTemplate; | ||
QString topRightTemplate; | ||
QString bottomLeftTemplate; | ||
QString bottomRightTemplate; | ||
|
||
int topLeftMargin; | ||
int topRightMargin; | ||
int bottomLeftMargin; | ||
int bottomRightMargin; | ||
|
||
int topLeftFontsize; | ||
int topRightFontsize; | ||
int bottomLeftFontsize; | ||
int bottomRightFontsize; | ||
|
||
QStringList getOverlayComponents(QString corner); | ||
int getMargin(QStringList components); | ||
int getFontsize(QStringList components); | ||
QString getTemplate(QStringList components); | ||
|
||
QString getExifDate(std::string filename); | ||
void parseInput(); | ||
std::string renderString(QString overlayTemplate, std::string filename); | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d4beb46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thank you!
d4beb46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more template strings with the latest version (0.9.11), please take a look