From 7f570106dbd585fadbbbf42ba61c87accc492595 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 10 Aug 2017 14:47:56 +0300 Subject: [PATCH] Finished basic functions. --HG-- branch : feature --- .../dialogs/support/dialogeditlabel.cpp | 291 +++++++++++++++++- .../vtools/dialogs/support/dialogeditlabel.h | 41 +++ .../vtools/dialogs/support/dialogeditlabel.ui | 8 +- 3 files changed, 333 insertions(+), 7 deletions(-) diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index fcee126b6..08fee00ac 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -1,14 +1,299 @@ +/************************************************************************ + ** + ** @file dialogeditlabel.cpp + ** @author Roman Telezhynskyi + ** @date 11 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) 2013-2017 Valentina project + ** 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 . + ** + *************************************************************************/ + #include "dialogeditlabel.h" #include "ui_dialogeditlabel.h" +#include "../vmisc/vabstractapplication.h" -DialogEditLabel::DialogEditLabel(QWidget *parent) : - QDialog(parent), - ui(new Ui::DialogEditLabel) +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogEditLabel::DialogEditLabel(QWidget *parent) + : QDialog(parent), + ui(new Ui::DialogEditLabel) { ui->setupUi(this); + + ui->lineEditLine->setClearButtonEnabled(true); + + connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogEditLabel::AddLine); + connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogEditLabel::RemoveLine); + connect(ui->lineEditLine, &QLineEdit::textEdited, this, &DialogEditLabel::SaveLineText); + connect(ui->toolButtonBold, &QToolButton::toggled, this, &DialogEditLabel::SaveFontStyle); + connect(ui->toolButtonItalic, &QToolButton::toggled, this, &DialogEditLabel::SaveFontStyle); + 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->toolButtonNewLabel, &QToolButton::clicked, this, &DialogEditLabel::NewTemplate); } +//--------------------------------------------------------------------------------------------------------------------- DialogEditLabel::~DialogEditLabel() { delete ui; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::ShowLineDetails() +{ + if (ui->listWidget->count() > 0) + { + const QListWidgetItem *line = ui->listWidget->currentItem(); + if (line) + { + ui->lineEditLine->blockSignals(true); + ui->lineEditLine->setText(line->text()); + ui->lineEditLine->selectAll(); + ui->lineEditLine->setFocus(); + ui->lineEditLine->blockSignals(false); + + const QFont lineFont = line->font(); + + ui->toolButtonBold->blockSignals(true); + ui->toolButtonBold->setChecked(lineFont.bold()); + ui->toolButtonBold->blockSignals(false); + + ui->toolButtonItalic->blockSignals(true); + ui->toolButtonItalic->setChecked(lineFont.italic()); + ui->toolButtonItalic->blockSignals(false); + + ui->toolButtonTextLeft->blockSignals(true); + ui->toolButtonTextCenter->blockSignals(true); + ui->toolButtonTextRight->blockSignals(true); + + const int lineAlignment = line->textAlignment(); + + if (lineAlignment & Qt::AlignLeft) + { + ui->toolButtonTextLeft->setChecked(true); + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else if (lineAlignment & Qt::AlignCenter) + { + ui->toolButtonTextLeft->setChecked(false); + ui->toolButtonTextCenter->setChecked(true); + ui->toolButtonTextRight->setChecked(false); + } + else if (lineAlignment & Qt::AlignRight) + { + ui->toolButtonTextLeft->setChecked(false); + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(true); + } + + ui->toolButtonTextLeft->blockSignals(false); + ui->toolButtonTextCenter->blockSignals(false); + ui->toolButtonTextRight->blockSignals(false); + } + } + + SetupControls(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::AddLine() +{ + int row = ui->listWidget->currentRow(); + ui->listWidget->insertItem(++row, new QListWidgetItem(tr(""))); + ui->listWidget->setCurrentRow(row); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::RemoveLine() +{ + ui->listWidget->blockSignals(true); + QListWidgetItem *curLine = ui->listWidget->takeItem(ui->listWidget->currentRow()); + if (curLine) + { + delete curLine; + } + ui->listWidget->blockSignals(false); + ShowLineDetails(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveLineText(const QString &text) +{ + QListWidgetItem *curLine = ui->listWidget->currentItem(); + if (curLine) + { + curLine->setText(text); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveFontStyle(bool checked) +{ + QListWidgetItem *curLine = ui->listWidget->currentItem(); + if (curLine) + { + QFont lineFont = curLine->font(); + + QToolButton *button = qobject_cast(sender()); + if (button) + { + if (button == ui->toolButtonBold) + { + lineFont.setBold(checked); + } + else if (button == ui->toolButtonItalic) + { + lineFont.setItalic(checked); + } + } + + curLine->setFont(lineFont); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SaveTextFormating(bool checked) +{ + QListWidgetItem *curLine = ui->listWidget->currentItem(); + if (curLine) + { + QToolButton *button = qobject_cast(sender()); + if (button) + { + ui->toolButtonTextLeft->blockSignals(true); + ui->toolButtonTextCenter->blockSignals(true); + ui->toolButtonTextRight->blockSignals(true); + + if (button == ui->toolButtonTextLeft) + { + if (checked) + { + curLine->setTextAlignment(Qt::AlignLeft); + + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else + { + button->setChecked(true); + } + } + else if (button == ui->toolButtonTextCenter) + { + if (checked) + { + curLine->setTextAlignment(Qt::AlignCenter); + + ui->toolButtonTextLeft->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else + { + button->setChecked(true); + } + } + else if (button == ui->toolButtonTextRight) + { + if (checked) + { + curLine->setTextAlignment(Qt::AlignRight); + + ui->toolButtonTextCenter->setChecked(false); + ui->toolButtonTextRight->setChecked(false); + } + else + { + button->setChecked(true); + } + } + + ui->toolButtonTextLeft->blockSignals(false); + ui->toolButtonTextCenter->blockSignals(false); + ui->toolButtonTextRight->blockSignals(false); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::NewTemplate() +{ + if (ui->listWidget->count() > 0) + { + const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Create new template"), + tr("Creating new template will overwrite the current, do " + "you want to continue?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (answer == QMessageBox::No) + { + return; + } + } + + ui->listWidget->blockSignals(true); + ui->listWidget->clear(); + ui->listWidget->blockSignals(false); + ShowLineDetails(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::ExportTemplate() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::ImportTemplate() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditLabel::SetupControls() +{ + const bool enabled = ui->listWidget->count() > 0; + + if (not enabled) + { + ui->lineEditLine->blockSignals(true); + ui->lineEditLine->clear(); + ui->lineEditLine->blockSignals(false); + } + + ui->toolButtonAdd->setEnabled(true); + ui->toolButtonImportLabel->setEnabled(true); + + ui->toolButtonRemove->setEnabled(enabled); + ui->toolButtonBold->setEnabled(enabled); + ui->toolButtonItalic->setEnabled(enabled); + ui->toolButtonTextLeft->setEnabled(enabled); + ui->toolButtonTextCenter->setEnabled(enabled); + ui->toolButtonTextRight->setEnabled(enabled); + ui->pushButtonInsert->setEnabled(enabled); + ui->toolButtonNewLabel->setEnabled(enabled); + ui->toolButtonExportLabel->setEnabled(enabled); + ui->lineEditLine->setEnabled(enabled); +} diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.h b/src/libs/vtools/dialogs/support/dialogeditlabel.h index c046e931f..1c29af271 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.h +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.h @@ -1,3 +1,31 @@ +/************************************************************************ + ** + ** @file dialogeditlabel.h + ** @author Roman Telezhynskyi + ** @date 11 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) 2013-2017 Valentina project + ** 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 . + ** + *************************************************************************/ + #ifndef DIALOGEDITLABEL_H #define DIALOGEDITLABEL_H @@ -16,9 +44,22 @@ public: explicit DialogEditLabel(QWidget *parent = nullptr); virtual ~DialogEditLabel(); +private slots: + void ShowLineDetails(); + void AddLine(); + void RemoveLine(); + void SaveLineText(const QString &text); + void SaveFontStyle(bool checked); + void SaveTextFormating(bool checked); + void NewTemplate(); + void ExportTemplate(); + void ImportTemplate(); + private: Q_DISABLE_COPY(DialogEditLabel) Ui::DialogEditLabel *ui; + + void SetupControls(); }; #endif // DIALOGEDITLABEL_H diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.ui b/src/libs/vtools/dialogs/support/dialogeditlabel.ui index f39f918d1..de611d6a6 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.ui +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.ui @@ -241,7 +241,7 @@ - + 0 @@ -258,7 +258,7 @@ - + false @@ -283,7 +283,7 @@ - + false @@ -291,7 +291,7 @@ Line of text - true + false