Added Preview tab.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-08-12 13:19:13 +03:00
parent 0c13d610eb
commit 4aa002f510
3 changed files with 306 additions and 224 deletions

View File

@ -58,7 +58,8 @@ DialogEditLabel::DialogEditLabel(QWidget *parent)
connect(ui->toolButtonTextLeft, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating);
connect(ui->toolButtonTextCenter, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating);
connect(ui->toolButtonTextRight, &QToolButton::toggled, this, &DialogEditLabel::SaveTextFormating);
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails);
connect(ui->listWidgetEdit, &QListWidget::itemSelectionChanged, this, &DialogEditLabel::ShowLineDetails);
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &DialogEditLabel::TabChanged);
connect(ui->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate);
connect(ui->toolButtonExportLabel, &QToolButton::clicked, this, &DialogEditLabel::ExportTemplate);
connect(ui->toolButtonImportLabel, &QToolButton::clicked, this, &DialogEditLabel::ImportTemplate);
@ -78,14 +79,13 @@ DialogEditLabel::~DialogEditLabel()
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::ShowLineDetails()
{
if (ui->listWidget->count() > 0)
if (ui->listWidgetEdit->count() > 0)
{
const QListWidgetItem *line = ui->listWidget->currentItem();
const QListWidgetItem *line = ui->listWidgetEdit->currentItem();
if (line)
{
ui->lineEditLine->blockSignals(true);
ui->lineEditLine->setText(line->text());
ui->lineEditLine->setFocus();
ui->lineEditLine->blockSignals(false);
const QFont lineFont = line->font();
@ -135,28 +135,28 @@ void DialogEditLabel::ShowLineDetails()
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::AddLine()
{
int row = ui->listWidget->currentRow();
ui->listWidget->insertItem(++row, new QListWidgetItem(tr("<empty>")));
ui->listWidget->setCurrentRow(row);
int row = ui->listWidgetEdit->currentRow();
ui->listWidgetEdit->insertItem(++row, new QListWidgetItem(tr("<empty>")));
ui->listWidgetEdit->setCurrentRow(row);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::RemoveLine()
{
ui->listWidget->blockSignals(true);
QListWidgetItem *curLine = ui->listWidget->takeItem(ui->listWidget->currentRow());
ui->listWidgetEdit->blockSignals(true);
QListWidgetItem *curLine = ui->listWidgetEdit->takeItem(ui->listWidgetEdit->currentRow());
if (curLine)
{
delete curLine;
}
ui->listWidget->blockSignals(false);
ui->listWidgetEdit->blockSignals(false);
ShowLineDetails();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::SaveLineText(const QString &text)
{
QListWidgetItem *curLine = ui->listWidget->currentItem();
QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
if (curLine)
{
curLine->setText(text);
@ -166,7 +166,7 @@ void DialogEditLabel::SaveLineText(const QString &text)
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::SaveFontStyle(bool checked)
{
QListWidgetItem *curLine = ui->listWidget->currentItem();
QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
if (curLine)
{
QFont lineFont = curLine->font();
@ -191,7 +191,7 @@ void DialogEditLabel::SaveFontStyle(bool checked)
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::SaveTextFormating(bool checked)
{
QListWidgetItem *curLine = ui->listWidget->currentItem();
QListWidgetItem *curLine = ui->listWidgetEdit->currentItem();
if (curLine)
{
QToolButton *button = qobject_cast<QToolButton *>(sender());
@ -254,7 +254,7 @@ void DialogEditLabel::SaveTextFormating(bool checked)
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::NewTemplate()
{
if (ui->listWidget->count() > 0)
if (ui->listWidgetEdit->count() > 0)
{
const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Create new template"),
tr("Creating new template will overwrite the current, do "
@ -266,9 +266,9 @@ void DialogEditLabel::NewTemplate()
}
}
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
ui->listWidget->blockSignals(false);
ui->listWidgetEdit->blockSignals(true);
ui->listWidgetEdit->clear();
ui->listWidgetEdit->blockSignals(false);
ShowLineDetails();
}
@ -333,7 +333,7 @@ void DialogEditLabel::ExportTemplate()
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::ImportTemplate()
{
if (ui->listWidget->count() > 0)
if (ui->listWidgetEdit->count() > 0)
{
const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Import template"),
tr("Import template will overwrite the current, do "
@ -358,7 +358,7 @@ void DialogEditLabel::ImportTemplate()
{
VLabelTemplate ltemplate;
ltemplate.setXMLContent(VLabelTemplateConverter(fileName).Convert());
InitLines(ltemplate.ReadLines());
InitEditLines(ltemplate.ReadLines());
}
catch (VException &e)
{
@ -378,10 +378,26 @@ void DialogEditLabel::InsertPlaceholder()
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::TabChanged(int index)
{
if (index == ui->tabWidget->indexOf(ui->tabPreview))
{
ui->toolButtonNewLabel->setDisabled(true);
ui->toolButtonImportLabel->setDisabled(true);
InitPreviewLines(PrepareLines());
}
else
{
ui->toolButtonNewLabel->setEnabled(ui->listWidgetEdit->count() > 0);
ui->toolButtonImportLabel->setEnabled(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::SetupControls()
{
const bool enabled = ui->listWidget->count() > 0;
const bool enabled = ui->listWidgetEdit->count() > 0;
if (not enabled)
{
@ -426,14 +442,26 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert("%date%", qMakePair(tr("Date"), locale.toString(QDate::currentDate(), "dd MMMM yyyy")));
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogEditLabel::ReplacePlaceholders(QString line) const
{
auto i = m_placeholders.constBegin();
while (i != m_placeholders.constEnd())
{
line.replace(i.key(), i.value().second);
++i;
}
return line;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
{
QVector<VLabelTemplateLine> lines;
for (int i=0; i<ui->listWidget->count(); ++i)
for (int i=0; i<ui->listWidgetEdit->count(); ++i)
{
const QListWidgetItem *lineItem = ui->listWidget->item(i);
const QListWidgetItem *lineItem = ui->listWidgetEdit->item(i);
if (lineItem)
{
VLabelTemplateLine line;
@ -452,10 +480,10 @@ QVector<VLabelTemplateLine> DialogEditLabel::PrepareLines() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InitLines(const QVector<VLabelTemplateLine> &lines)
void DialogEditLabel::InitEditLines(const QVector<VLabelTemplateLine> &lines)
{
ui->listWidget->blockSignals(true);
ui->listWidget->clear();
ui->listWidgetEdit->blockSignals(true);
ui->listWidgetEdit->clear();
int row = -1;
@ -469,13 +497,39 @@ void DialogEditLabel::InitLines(const QVector<VLabelTemplateLine> &lines)
font.setItalic(lines.at(i).italic);
item->setFont(font);
ui->listWidget->insertItem(++row, item);
ui->listWidgetEdit->insertItem(++row, item);
}
ui->listWidget->blockSignals(false);
ui->listWidgetEdit->blockSignals(false);
if (ui->listWidget->count() > 0)
if (ui->listWidgetEdit->count() > 0)
{
ui->listWidget->setCurrentRow(0);
ui->listWidgetEdit->setCurrentRow(0);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditLabel::InitPreviewLines(const QVector<VLabelTemplateLine> &lines)
{
ui->listWidgetPreview->clear();
int row = -1;
for (int i=0; i<lines.size(); ++i)
{
QListWidgetItem *item = new QListWidgetItem(ReplacePlaceholders(lines.at(i).line));
item->setTextAlignment(lines.at(i).alignment);
QFont font = item->font();
font.setBold(lines.at(i).bold);
font.setItalic(lines.at(i).italic);
item->setFont(font);
ui->listWidgetPreview->insertItem(++row, item);
}
if (ui->listWidgetPreview->count() > 0)
{
ui->listWidgetPreview->setCurrentRow(0);
}
}

View File

@ -59,6 +59,7 @@ private slots:
void ExportTemplate();
void ImportTemplate();
void InsertPlaceholder();
void TabChanged(int index);
private:
Q_DISABLE_COPY(DialogEditLabel)
@ -71,8 +72,11 @@ private:
void InitPlaceholdersMenu();
void InitPlaceholders();
QString ReplacePlaceholders(QString line) const;
QVector<VLabelTemplateLine> PrepareLines() const;
void InitLines(const QVector<VLabelTemplateLine> &lines);
void InitEditLines(const QVector<VLabelTemplateLine> &lines);
void InitPreviewLines(const QVector<VLabelTemplateLine> &lines);
};
#endif // DIALOGEDITLABEL_H

View File

@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>384</height>
<width>437</width>
<height>464</height>
</rect>
</property>
<property name="windowTitle">
@ -23,7 +23,7 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
@ -108,209 +108,233 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>6</number>
</property>
<widget class="QWidget" name="tabEdit">
<attribute name="title">
<string>Edit</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QToolButton" name="toolButtonBold">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string comment="Font formating">Bold</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-text-bold">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonItalic">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string comment="Font formating">Italic</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-text-italic">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonTextLeft">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Aligns with the left edge</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-justify-left">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonTextCenter">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Centers horizontally in the available space</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-justify-center">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonTextRight">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Aligns with the right edge</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-justify-right">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QToolButton" name="toolButtonAdd">
<widget class="QListWidget" name="listWidgetEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../app/valentina/dialogs</normaloff>../../../../app/valentina/dialogs</iconset>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="QToolButton" name="toolButtonRemove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../app/valentina/dialogs</normaloff>../../../../app/valentina/dialogs</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Text:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="VLineEdit" name="lineEditLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Line of text</string>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonInsert">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Insert placeholders</string>
</property>
<property name="text">
<string>Insert...</string>
</property>
</widget>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QToolButton" name="toolButtonBold">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string comment="Font formating">Bold</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-text-bold">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonItalic">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string comment="Font formating">Italic</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-text-italic">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonTextLeft">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Aligns with the left edge</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-justify-left">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonTextCenter">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Centers horizontally in the available space</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-justify-center">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonTextRight">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Aligns with the right edge</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="format-justify-right">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QToolButton" name="toolButtonAdd">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-add">
<normaloff>../../../../app/valentina/dialogs</normaloff>../../../../app/valentina/dialogs</iconset>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="QToolButton" name="toolButtonRemove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>../../../../app/valentina/dialogs</normaloff>../../../../app/valentina/dialogs</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Text:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="VLineEdit" name="lineEditLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Line of text</string>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonInsert">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Insert placeholders</string>
</property>
<property name="text">
<string>Insert...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabPreview">
<attribute name="title">
<string>Preview</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListWidget" name="listWidgetPreview"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">