diff --git a/src/config/filenameeditor.cpp b/src/config/filenameeditor.cpp index fb1147c0..6168a7ec 100644 --- a/src/config/filenameeditor.cpp +++ b/src/config/filenameeditor.cpp @@ -18,23 +18,30 @@ #include "filenameeditor.h" #include "src/utils/filenamehandler.h" #include "src/utils/confighandler.h" -#include +#include "src/config/strftimechooserwidget.h" +#include +#include #include #include -#include FileNameEditor::FileNameEditor(QWidget *parent) : QFrame(parent) { setFrameStyle(QFrame::StyledPanel); initWidgets(); - initLayout(); + initLayout(); } void FileNameEditor::initLayout() { - m_layout = new QGridLayout(this); - m_layout->addWidget(m_nameEditor, 0,1); - m_layout->addWidget(m_saveButton, 0, 0); - m_layout->addWidget(new QLabel("Preview: ", this), 1, 0); - m_layout->addWidget(m_outputLabel, 1, 1); + m_layout = new QVBoxLayout(this); + m_layout->addWidget(m_nameEditor); + m_layout->addWidget(m_outputLabel); + + QPushButton *openHelp = new QPushButton(tr("Open Helper"), this); + connect(openHelp, &QPushButton::clicked, this, &FileNameEditor::openHelper); + m_layout->addWidget(m_saveButton); + QHBoxLayout *horizLayout = new QHBoxLayout(); + horizLayout->addWidget(m_saveButton); + horizLayout->addWidget(openHelp); + m_layout->addLayout(horizLayout); } void FileNameEditor::initWidgets() { @@ -43,14 +50,20 @@ void FileNameEditor::initWidgets() { m_nameEditor = new QLineEdit(this); m_nameEditor->setMaxLength(FileNameHandler::MAX_CHARACTERS); - m_outputLabel = new QLabel(this); - m_saveButton = new QPushButton(tr("Save"), this); + m_outputLabel = new QLineEdit(this); + m_outputLabel->setReadOnly(true); + m_outputLabel->setFocusPolicy(Qt::NoFocus); + QPalette pal = m_outputLabel->palette(); + QColor color = pal.color(QPalette::Disabled, m_outputLabel->backgroundRole()); + pal.setColor(QPalette::Active, m_outputLabel->backgroundRole(), color); + m_outputLabel->setPalette(pal); connect(m_nameEditor, &QLineEdit::textChanged, this, &FileNameEditor::showParsedPattern); m_nameEditor->setText(ConfigHandler().getFilenamePattern()); m_outputLabel->setText(m_nameHandler->getParsedPattern()); + m_saveButton = new QPushButton(tr("Save"), this); connect(m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern); } @@ -63,3 +76,18 @@ void FileNameEditor::showParsedPattern(const QString &p) { QString output = m_nameHandler->parseFilename(p); m_outputLabel->setText(output); } + +void FileNameEditor::addToNameEditor(QString s) { + m_nameEditor->setText(m_nameEditor->text() + s); +} + +void FileNameEditor::openHelper() { + if (!m_buttonHelper) { + m_buttonHelper = new StrftimeChooserWidget(); + m_buttonHelper.data()->show(); + connect(this, &FileNameEditor::destroyed, + m_buttonHelper, &StrftimeChooserWidget::deleteLater); + connect(m_buttonHelper, &StrftimeChooserWidget::variableEmitted, + this, &FileNameEditor::addToNameEditor); + } +} diff --git a/src/config/filenameeditor.h b/src/config/filenameeditor.h index 2aec4a0a..ee1a4242 100644 --- a/src/config/filenameeditor.h +++ b/src/config/filenameeditor.h @@ -19,12 +19,13 @@ #define FILENAMEEDITOR_H #include +#include -class QGridLayout; -class QLabel; +class QVBoxLayout; class QLineEdit; class FileNameHandler; class QPushButton; +class StrftimeChooserWidget; class FileNameEditor : public QFrame { @@ -33,18 +34,22 @@ public: explicit FileNameEditor(QWidget *parent = nullptr); private: - QGridLayout *m_layout; - QLabel *m_outputLabel; + QVBoxLayout *m_layout; + QLineEdit *m_outputLabel; QLineEdit *m_nameEditor; QPushButton *m_saveButton; FileNameHandler *m_nameHandler; + QPointer m_buttonHelper; + void initLayout(); void initWidgets(); private slots: void savePattern(); void showParsedPattern(const QString &); + void addToNameEditor(QString s); + void openHelper(); }; #endif // FILENAMEEDITOR_H diff --git a/src/config/strftimechooserwidget.cpp b/src/config/strftimechooserwidget.cpp index 28ef34aa..6b56aa3a 100644 --- a/src/config/strftimechooserwidget.cpp +++ b/src/config/strftimechooserwidget.cpp @@ -16,95 +16,53 @@ // along with Flameshot. If not, see . #include "strftimechooserwidget.h" +#include +#include +#include StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent) { - + setAttribute(Qt::WA_DeleteOnClose); + setWindowIcon(QIcon(":img/flameshot.png")); + QGridLayout *layout = new QGridLayout(this); + auto k = m_buttonData.keys(); + int middle = k.length()/2; + // add the buttons in 2 columns (they need to be even) + for(int i = 0; i < 2; i++) { + for(int j = 0; j < middle; j++) { + QString key = k.last(); + k.pop_back(); + QString variable = m_buttonData.value(key); + QPushButton *button = new QPushButton(this); + button->setText(key); + button->setToolTip(variable); + layout->addWidget(button, j, i); + connect(button, &QPushButton::clicked, + this, [variable, this](){Q_EMIT variableEmitted(variable);}); + } + } + setLayout(layout); } -//QStringList StrftimeChooserWidget::m_valuesStr = QList() -// << "%a" -// << "%A" -// << "%b" -// << "%B" -// << "%C" -// << "%d" -// << "%D" -// << "%e" -// << "%E" -// << "%F" -// << "%G" -// << "%g" -// << "%h" -// << "%H" -// << "%I" -// << "%j" -// << "%k" -// << "%l" -// << "%m" -// << "%M" -// << "%n" -// << "%O" -// << "%p" -// << "%P" -// << "%r" -// << "%R" -// << "%s" -// << "%S" -// << "%t" -// << "%T" -// << "%u" -// << "%U" -// << "%V" -// << "%w" -// << "%W" -// << "%x" -// << "%X" -// << "%y" -// << "%Y" -// << "%z" -// << "%Z" -// << "%%"; - -//QStringList StrftimeChooserWidget::m_buttonLabel = QList() -// << "Day (Mon)" //"%a" -// << "Day (Monday)" //"%A" -// << "Month (Jan)" //"%b" -// << "Month (1...12)" //"%B" -// << "Century (21)" //"%C" -// << "Day (01...31)" //"%d" -// << "Full Date (%m/%d/%y)" //"%D" -// << " ()" //"%e" -// << " ()" //"%E" -// << " ()" //"%F" -// << " ()" //"%G" -// << " ()" //"%g" -// << " ()" //"%h" -// << " ()" //"%H" -// << " ()" //"%I" -// << " ()" //"%j" -// << " ()" //"%k" -// << " ()" //"%l" -// << " ()" //"%m" -// << " ()" //"%M" -// << " ()" //"%n" -// << " ()" //"%O" -// << " ()" //"%p" -// << " ()" //"%P" -// << " ()" //"%r" -// << " ()" //"%R" -// << " ()" //"%s" -// << " ()" //"%S" -// << " ()" //"%t" -// << " ()" //"%T" -// << " ()" //"%u" -// << " ()" //"%U" -// << " ()" //"%V" -// << " ()" //"%w" -// << " ()" //"%W" -// << " ()" //"%x" -// << " ()" //"%X" -// << " ()" //"%y" -// << " ()" //"%Y" -// << " ()" //"%z" -// << " ()" //"%Z" -// << "%"; //"%%"; +QMap StrftimeChooserWidget::m_buttonData { + { "Century (00-99)", "%C"}, + { "Year (00-99)", "%y"}, + { "Year (2000)", "%Y"}, + { "Month Name (jan)", "%b"}, + { "Month Name (january)", "%B"}, + { "Month (01-12)", "%m"}, + { "Week Day (1-7)", "%u"}, + { "week (01-53)", "%V"}, + { "Day Name (mon)", "%a"}, + { "Day Name (monday)", "%A"}, + { "Day (01-31)", "%d"}, + { "Day of Month (1-31)", "%e"}, + { "Day (001-366)", "%j"}, + { "Time (%H:%M:%S)", "%T"}, + { "Time (%H:%M)", "%R"}, + { "Hour (00-23)", "%H"}, + { "Hour (01-12)", "%I"}, + { "Minute (00-59)", "%M"}, + { "Second (00-59)", "%S"}, + { "Full Date (%m/%d/%y)", "%D"}, + { "Full Date (%Y-%m-%d)", "%F"}, +}; diff --git a/src/config/strftimechooserwidget.h b/src/config/strftimechooserwidget.h index fb01e7fe..63d03207 100644 --- a/src/config/strftimechooserwidget.h +++ b/src/config/strftimechooserwidget.h @@ -30,8 +30,7 @@ signals: void variableEmitted(const QString &); private: - static QStringList m_valuesStr; - static QStringList m_buttonLabel; + static QMap m_buttonData; }; #endif // STRFTIMECHOOSERWIDGET_H diff --git a/src/controller.cpp b/src/controller.cpp index 5eba09c6..6f453607 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -93,13 +93,7 @@ void Controller::initDefaults() { ConfigHandler config; //config.setNotInitiated(); if (!config.initiatedIsSet()) { - config.setInitiated(); - config.setShowHelp(true); - config.setDesktopNotification(true); - config.setDrawColor(QColor(Qt::red)); - config.setUIMainColor(QColor(116, 0, 150)); - config.setUIContrastColor(QColor(86, 0, 120)); - config.setAllTheButtons(); + config.setDefaults(); } } diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 111e833d..caac1a3a 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -105,6 +105,15 @@ void ConfigHandler::setNotInitiated() { m_settings->setValue("initiated", false); } +void ConfigHandler::setDefaults() { + setShowHelp(true); + setDesktopNotification(true); + setDrawColor(QColor(Qt::red)); + setUIMainColor(QColor(116, 0, 150)); + setUIContrastColor(QColor(86, 0, 120)); + setAllTheButtons(); +} + void ConfigHandler::setAllTheButtons() { QList buttons; auto listTypes = CaptureButton::getIterableButtonTypes(); diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index c266714b..45861996 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -57,6 +57,7 @@ public: bool initiatedIsSet(); void setInitiated(); void setNotInitiated(); + void setDefaults(); void setAllTheButtons();