Added placeholders list.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-12 11:40:58 +03:00
parent 9202418d7c
commit d81be4f778
6 changed files with 161 additions and 4 deletions

View File

@ -36,11 +36,15 @@
#include <QDir>
#include <QMessageBox>
#include <QFileDialog>
#include <QMenu>
#include <QDate>
//---------------------------------------------------------------------------------------------------------------------
DialogEditLabel::DialogEditLabel(QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogEditLabel)
ui(new Ui::DialogEditLabel),
m_placeholdersMenu(new QMenu(this)),
m_placeholders()
{
ui->setupUi(this);
@ -58,6 +62,11 @@ DialogEditLabel::DialogEditLabel(QWidget *parent)
connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate);
connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate);
connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate);
InitPlaceholders();
InitPlaceholdersMenu();
ui->pushButtonInsert->setMenu(m_placeholdersMenu);
}
//---------------------------------------------------------------------------------------------------------------------
@ -359,6 +368,17 @@ void DialogEditLabel::ImportTemplate()
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InsertPlaceholder()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
{
ui->lineEditLine->insert(action->data().toString());
ui->lineEditLine->setFocus();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::SetupControls()
{
@ -386,6 +406,27 @@ void DialogEditLabel::SetupControls()
ui->lineEditLine->setEnabled(enabled);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InitPlaceholdersMenu()
{
auto i = m_placeholders.constBegin();
while (i != m_placeholders.constEnd())
{
auto value = i.value();
QAction *action = m_placeholdersMenu->addAction(value.first);
action->setData(i.key());
connect(action, &QAction::triggered, this, &DialogEditLabel::InsertPlaceholder);
++i;
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InitPlaceholders()
{
QLocale locale(qApp->Settings()->GetLocale());
m_placeholders.insert("%date%", qMakePair(tr("Date"), locale.toString(QDate::currentDate(), "dd MMMM yyyy")));
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
{

View File

@ -30,6 +30,7 @@
#define DIALOGEDITLABEL_H
#include <QDialog>
#include <QMap>
namespace Ui
{
@ -37,6 +38,7 @@ namespace Ui
}
class VLabelTemplateLine;
class QMenu;
class DialogEditLabel : public QDialog
{
@ -56,12 +58,18 @@ private slots:
void NewTemplate();
void ExportTemplate();
void ImportTemplate();
void InsertPlaceholder();
private:
Q_DISABLE_COPY(DialogEditLabel)
Ui::DialogEditLabel *ui;
QMenu *m_placeholdersMenu;
QMap<QString, QPair<QString, QString>> m_placeholders;
void SetupControls();
void InitPlaceholdersMenu();
void InitPlaceholders();
QVector<VLabelTemplateLine> PrepareLines() const;
void InitLines(const QVector<VLabelTemplateLine> &lines);

View File

@ -283,7 +283,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLineEdit" name="lineEditLine">
<widget class="VLineEdit" name="lineEditLine">
<property name="enabled">
<bool>false</bool>
</property>
@ -324,6 +324,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>VLineEdit</class>
<extends>QLineEdit</extends>
<header>vlineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../vmisc/share/resources/icon.qrc"/>
</resources>

View File

@ -0,0 +1,55 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 8, 2017
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vlineedit.h"
//---------------------------------------------------------------------------------------------------------------------
VLineEdit::VLineEdit(QWidget *parent)
: QLineEdit(parent)
{}
//---------------------------------------------------------------------------------------------------------------------
VLineEdit::VLineEdit(const QString &contents, QWidget *parent)
: QLineEdit(contents, parent)
{}
//---------------------------------------------------------------------------------------------------------------------
void VLineEdit::focusOutEvent(QFocusEvent *e)
{
const int start = selectionStart();
int selectionLength = selectedText().length();
const bool wasTextSelected = hasSelectedText();
QLineEdit::focusOutEvent(e);
if (wasTextSelected)
{
setSelection(start, selectionLength);
}
}

View File

@ -0,0 +1,44 @@
/************************************************************************
**
** @file
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 8, 2017
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2017 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VLINEEDIT_H
#define VLINEEDIT_H
#include <QLineEdit>
class VLineEdit : public QLineEdit
{
public:
VLineEdit(QWidget * parent = nullptr);
VLineEdit(const QString &contents, QWidget *parent = nullptr);
protected:
virtual void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE;
};
#endif // VLINEEDIT_H

View File

@ -21,7 +21,8 @@ SOURCES += \
$$PWD/vcurvepathitem.cpp \
$$PWD/global.cpp \
$$PWD/vscenepoint.cpp \
$$PWD/scalesceneitems.cpp
$$PWD/scalesceneitems.cpp \
$$PWD/vlineedit.cpp
*msvc*:SOURCES += $$PWD/stable.cpp
@ -46,4 +47,5 @@ HEADERS += \
$$PWD/vcurvepathitem.h \
$$PWD/global.h \
$$PWD/vscenepoint.h \
$$PWD/scalesceneitems.h
$$PWD/scalesceneitems.h \
$$PWD/vlineedit.h