Added placeholders list.
--HG-- branch : feature
This commit is contained in:
parent
9202418d7c
commit
d81be4f778
|
@ -36,11 +36,15 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogEditLabel::DialogEditLabel(QWidget *parent)
|
DialogEditLabel::DialogEditLabel(QWidget *parent)
|
||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
ui(new Ui::DialogEditLabel)
|
ui(new Ui::DialogEditLabel),
|
||||||
|
m_placeholdersMenu(new QMenu(this)),
|
||||||
|
m_placeholders()
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -58,6 +62,11 @@ DialogEditLabel::DialogEditLabel(QWidget *parent)
|
||||||
connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate);
|
connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate);
|
||||||
connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate);
|
connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate);
|
||||||
connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate);
|
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()
|
void DialogEditLabel::SetupControls()
|
||||||
{
|
{
|
||||||
|
@ -386,6 +406,27 @@ void DialogEditLabel::SetupControls()
|
||||||
ui->lineEditLine->setEnabled(enabled);
|
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
|
QVector<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define DIALOGEDITLABEL_H
|
#define DIALOGEDITLABEL_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
|
@ -37,6 +38,7 @@ namespace Ui
|
||||||
}
|
}
|
||||||
|
|
||||||
class VLabelTemplateLine;
|
class VLabelTemplateLine;
|
||||||
|
class QMenu;
|
||||||
|
|
||||||
class DialogEditLabel : public QDialog
|
class DialogEditLabel : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -56,12 +58,18 @@ private slots:
|
||||||
void NewTemplate();
|
void NewTemplate();
|
||||||
void ExportTemplate();
|
void ExportTemplate();
|
||||||
void ImportTemplate();
|
void ImportTemplate();
|
||||||
|
void InsertPlaceholder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(DialogEditLabel)
|
Q_DISABLE_COPY(DialogEditLabel)
|
||||||
Ui::DialogEditLabel *ui;
|
Ui::DialogEditLabel *ui;
|
||||||
|
QMenu *m_placeholdersMenu;
|
||||||
|
|
||||||
|
QMap<QString, QPair<QString, QString>> m_placeholders;
|
||||||
|
|
||||||
void SetupControls();
|
void SetupControls();
|
||||||
|
void InitPlaceholdersMenu();
|
||||||
|
void InitPlaceholders();
|
||||||
|
|
||||||
QVector<VLabelTemplateLine> PrepareLines() const;
|
QVector<VLabelTemplateLine> PrepareLines() const;
|
||||||
void InitLines(const QVector<VLabelTemplateLine> &lines);
|
void InitLines(const QVector<VLabelTemplateLine> &lines);
|
||||||
|
|
|
@ -283,7 +283,7 @@
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEditLine">
|
<widget class="VLineEdit" name="lineEditLine">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -324,6 +324,13 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>VLineEdit</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>vlineedit.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../../vmisc/share/resources/icon.qrc"/>
|
<include location="../../../vmisc/share/resources/icon.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
55
src/libs/vwidgets/vlineedit.cpp
Normal file
55
src/libs/vwidgets/vlineedit.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
src/libs/vwidgets/vlineedit.h
Normal file
44
src/libs/vwidgets/vlineedit.h
Normal 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
|
|
@ -21,7 +21,8 @@ SOURCES += \
|
||||||
$$PWD/vcurvepathitem.cpp \
|
$$PWD/vcurvepathitem.cpp \
|
||||||
$$PWD/global.cpp \
|
$$PWD/global.cpp \
|
||||||
$$PWD/vscenepoint.cpp \
|
$$PWD/vscenepoint.cpp \
|
||||||
$$PWD/scalesceneitems.cpp
|
$$PWD/scalesceneitems.cpp \
|
||||||
|
$$PWD/vlineedit.cpp
|
||||||
|
|
||||||
*msvc*:SOURCES += $$PWD/stable.cpp
|
*msvc*:SOURCES += $$PWD/stable.cpp
|
||||||
|
|
||||||
|
@ -46,4 +47,5 @@ HEADERS += \
|
||||||
$$PWD/vcurvepathitem.h \
|
$$PWD/vcurvepathitem.h \
|
||||||
$$PWD/global.h \
|
$$PWD/global.h \
|
||||||
$$PWD/vscenepoint.h \
|
$$PWD/vscenepoint.h \
|
||||||
$$PWD/scalesceneitems.h
|
$$PWD/scalesceneitems.h \
|
||||||
|
$$PWD/vlineedit.h
|
||||||
|
|
Loading…
Reference in New Issue
Block a user