Add helper widget for filename configuration

This commit is contained in:
dharkael
2017-07-20 13:48:00 +02:00
parent 58f0b12112
commit b14d3cb5f0
7 changed files with 105 additions and 111 deletions

View File

@@ -18,23 +18,30 @@
#include "filenameeditor.h"
#include "src/utils/filenamehandler.h"
#include "src/utils/confighandler.h"
#include <QGridLayout>
#include "src/config/strftimechooserwidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
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);
}
}

View File

@@ -19,12 +19,13 @@
#define FILENAMEEDITOR_H
#include <QFrame>
#include <QPointer>
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<StrftimeChooserWidget> m_buttonHelper;
void initLayout();
void initWidgets();
private slots:
void savePattern();
void showParsedPattern(const QString &);
void addToNameEditor(QString s);
void openHelper();
};
#endif // FILENAMEEDITOR_H

View File

@@ -16,95 +16,53 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "strftimechooserwidget.h"
#include <QMap>
#include <QGridLayout>
#include <QPushButton>
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<QString>()
// << "%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<QString>()
// << "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<QString, QString> 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"},
};

View File

@@ -30,8 +30,7 @@ signals:
void variableEmitted(const QString &);
private:
static QStringList m_valuesStr;
static QStringList m_buttonLabel;
static QMap<QString, QString> m_buttonData;
};
#endif // STRFTIMECHOOSERWIDGET_H

View File

@@ -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();
}
}

View File

@@ -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<int> buttons;
auto listTypes = CaptureButton::getIterableButtonTypes();

View File

@@ -57,6 +57,7 @@ public:
bool initiatedIsSet();
void setInitiated();
void setNotInitiated();
void setDefaults();
void setAllTheButtons();