Commit 431ea89f authored by David Redondo's avatar David Redondo 🏎 Committed by Nate Graham

Make the filename placeholders clickable

Summary:
This allows the user to click the placeholders. First step to improve the filename template configuration. I also moved the available placeholders to the ExportManager. The SaveOptionsPage doesn't need to care about which options are present and we have to change them in only one class if we want to make changes.
Further steps I plan to do are displaying a preview, improving the Layout (we had to increase the size already) and eventually using better placeholders.

BUG: 390856
FIXED-IN: 19.04.0

Test Plan:
- Click on placeholder
- It appears in the LineEdit

Reviewers: #spectacle, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: ngraham

Tags: #spectacle

Differential Revision: https://phabricator.kde.org/D19755
parent c1459f5e
...@@ -513,3 +513,16 @@ void ExportManager::doPrint(QPrinter *printer) ...@@ -513,3 +513,16 @@ void ExportManager::doPrint(QPrinter *printer)
delete printer; delete printer;
return; return;
} }
const QMap<QString, QString> ExportManager::filenamePlaceholders {
{QStringLiteral("%Y"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Year (4 digit)")},
{QStringLiteral("%y"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Year (2 digit)")},
{QStringLiteral("%M"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Month")},
{QStringLiteral("%D"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Day")},
{QStringLiteral("%H"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Hour")},
{QStringLiteral("%m"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Minute")},
{QStringLiteral("%S"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Second")},
{QStringLiteral("%T"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Window Title")},
{QStringLiteral("%d"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Sequential numbering")},
{QStringLiteral("%Nd"), i18nc("A placeholder in the user configurable filename will replaced by the specified value","Sequential numbering, padded out to N digits")},
};
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <QObject> #include <QObject>
#include <QIODevice> #include <QIODevice>
#include <QMap>
#include <QPrinter> #include <QPrinter>
#include <QPixmap> #include <QPixmap>
#include <QDateTime> #include <QDateTime>
...@@ -67,6 +68,8 @@ class ExportManager : public QObject ...@@ -67,6 +68,8 @@ class ExportManager : public QObject
ImageGrabber::GrabMode grabMode() const; ImageGrabber::GrabMode grabMode() const;
void setGrabMode(const ImageGrabber::GrabMode &grabMode); void setGrabMode(const ImageGrabber::GrabMode &grabMode);
static const QMap<QString, QString> filenamePlaceholders;
Q_SIGNALS: Q_SIGNALS:
void errorMessage(const QString &str); void errorMessage(const QString &str);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "SaveOptionsPage.h" #include "SaveOptionsPage.h"
#include "SpectacleConfig.h" #include "SpectacleConfig.h"
#include "ExportManager.h"
#include <KIOWidgets/KUrlRequester> #include <KIOWidgets/KUrlRequester>
#include <KLocalizedString> #include <KLocalizedString>
...@@ -123,35 +124,23 @@ SaveOptionsPage::SaveOptionsPage(QWidget *parent) : ...@@ -123,35 +124,23 @@ SaveOptionsPage::SaveOptionsPage(QWidget *parent) :
saveNameLayout->addLayout(saveFieldLayout); saveNameLayout->addLayout(saveFieldLayout);
// now the save filename format layout // now the save filename format layout
const QString helpText = i18nc("%1 is the default filename of a screenshot", QString helpText = i18n(
"<p>You can use the following placeholders in the filename, which will be replaced " "You can use the following placeholders in the filename, which will be replaced "
"with actual text when the file is saved:</p>" "with actual text when the file is saved:<blockquote>"
"<blockquote>"
"<b>%Y</b>: Year (4 digit)<br />"
"<b>%y</b>: Year (2 digit)<br />"
"<b>%M</b>: Month<br />"
"<b>%D</b>: Day<br />"
"<b>%H</b>: Hour<br />"
"<b>%m</b>: Minute<br />"
"<b>%S</b>: Second<br />"
"<b>%T</b>: Window title<br />"
"<b>%d</b>: Sequential numbering<br />"
"<b>%Nd</b>: Sequential numbering, padded out to N digits"
"</blockquote>"
"<p>To save to a sub-folder, use slashes, e.g.:</p>"
"<blockquote>"
"<b>%Y</b>/<b>%M</b>/%1"
"</blockquote>",
SpectacleConfig::instance()->defaultFilename() + SpectacleConfig::instance()->defaultTimestampTemplate()
); );
for (auto option = ExportManager::filenamePlaceholders.cbegin();
option != ExportManager::filenamePlaceholders.cend(); ++option) {
helpText += QStringLiteral("<a href=%1>%1</a>: %2<br>").arg(option.key(), option.value());
}
helpText += QStringLiteral("<a href='/'>/</a>: ") + i18n("To save to a sub-folder");
helpText += QStringLiteral("</blockquote>");
QLabel *fmtHelpText = new QLabel(helpText, this); QLabel *fmtHelpText = new QLabel(helpText, this);
fmtHelpText->setWordWrap(true); fmtHelpText->setWordWrap(true);
fmtHelpText->setTextFormat(Qt::RichText); fmtHelpText->setTextFormat(Qt::RichText);
fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
connect(fmtHelpText, &QLabel::linkActivated, [this](const QString& placeholder) {
mSaveNameFormat->insert(placeholder);
});
saveNameLayout->addWidget(fmtHelpText); saveNameLayout->addWidget(fmtHelpText);
mainLayout->addRow(i18n("Filename:"), saveNameLayout); mainLayout->addRow(i18n("Filename:"), saveNameLayout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment