From 6fc51d83b0991e40e570b0b3c970ed19401c1626 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 30 Dec 2019 14:43:06 +0200 Subject: [PATCH] Improve ergonomic. Allow a user to define both text and image, and control which will of them be active. --HG-- branch : develop --- src/app/valentina/watermarkwindow.cpp | 29 +++++++++++++++++------- src/app/valentina/watermarkwindow.ui | 13 +++++++++-- src/libs/ifc/ifcdef.h | 2 ++ src/libs/ifc/schema/watermark/v1.0.0.xsd | 2 ++ src/libs/vformat/vwatermark.cpp | 5 ++++ src/libs/vformat/vwatermark.h | 1 + src/libs/vlayout/vposter.cpp | 4 ++-- 7 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/app/valentina/watermarkwindow.cpp b/src/app/valentina/watermarkwindow.cpp index f801ade79..b54253cd3 100644 --- a/src/app/valentina/watermarkwindow.cpp +++ b/src/app/valentina/watermarkwindow.cpp @@ -68,7 +68,7 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) : WatermarkChangesWereSaved(false); }); - connect(ui->spinBoxTextRotation, QOverload::of(&QSpinBox::valueChanged),this, + connect(ui->spinBoxTextRotation, QOverload::of(&QSpinBox::valueChanged), this, [this](){WatermarkChangesWereSaved(false);}); connect(ui->toolButtonFont, &QToolButton::clicked, this, [this]() @@ -104,6 +104,9 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) : [this](){WatermarkChangesWereSaved(false);}); connect(ui->checkBoxGrayColor, &QCheckBox::stateChanged, this, [this](){WatermarkChangesWereSaved(false);}); + + connect(ui->groupBoxWatermarkText, &QGroupBox::toggled, this, [this](){WatermarkChangesWereSaved(false);}); + connect(ui->groupBoxWatermarkImage, &QGroupBox::toggled, this, [this](){WatermarkChangesWereSaved(false);}); } //--------------------------------------------------------------------------------------------------------------------- @@ -385,13 +388,13 @@ bool WatermarkWindow::on_actionSave_triggered() if (not changed) { - QMessageBox messageBox(this); - messageBox.setIcon(QMessageBox::Warning); - messageBox.setText(tr("Cannot set permissions for %1 to writable.").arg(m_curFile)); - messageBox.setInformativeText(tr("Could not save the file.")); - messageBox.setDefaultButton(QMessageBox::Ok); - messageBox.setStandardButtons(QMessageBox::Ok); - messageBox.exec(); + QMessageBox messageBoxWarning(this); + messageBoxWarning.setIcon(QMessageBox::Warning); + messageBoxWarning.setText(tr("Cannot set permissions for %1 to writable.").arg(m_curFile)); + messageBoxWarning.setInformativeText(tr("Could not save the file.")); + messageBoxWarning.setDefaultButton(QMessageBox::Ok); + messageBoxWarning.setStandardButtons(QMessageBox::Ok); + messageBoxWarning.exec(); return false; } } @@ -581,8 +584,10 @@ bool WatermarkWindow::ContinueFormatRewrite(const QString ¤tFormatVersion, bool WatermarkWindow::SaveWatermark(const QString &fileName, QString &error) { m_data.opacity = ui->spinBoxOpacity->value(); + m_data.showText = ui->groupBoxWatermarkText->isChecked(); m_data.text = ui->lineEditText->text(); m_data.textRotation = ui->spinBoxTextRotation->value(); + m_data.showImage = ui->groupBoxWatermarkImage->isChecked(); m_data.path = RelativeMPath(fileName, ui->lineEditPath->text()); m_data.imageRotation = ui->spinBoxImageRotation->value(); m_data.grayscale = ui->checkBoxGrayColor->isChecked(); @@ -677,6 +682,10 @@ void WatermarkWindow::ShowWatermark() ui->spinBoxOpacity->setValue(m_data.opacity); ui->spinBoxOpacity->blockSignals(false); + ui->groupBoxWatermarkText->blockSignals(true); + ui->groupBoxWatermarkText->setChecked(m_data.showText); + ui->groupBoxWatermarkText->blockSignals(false); + ui->lineEditText->blockSignals(true); ui->lineEditText->setText(m_data.text); ui->lineEditText->blockSignals(false); @@ -689,6 +698,10 @@ void WatermarkWindow::ShowWatermark() ui->lineEditFontSample->setFont(m_data.font); ui->lineEditFontSample->blockSignals(false); + ui->groupBoxWatermarkImage->blockSignals(true); + ui->groupBoxWatermarkImage->setChecked(m_data.showImage); + ui->groupBoxWatermarkImage->blockSignals(false); + ui->lineEditPath->blockSignals(true); ui->lineEditPath->setText(AbsoluteMPath(m_curFile, m_data.path)); ValidatePath(); diff --git a/src/app/valentina/watermarkwindow.ui b/src/app/valentina/watermarkwindow.ui index 98504975b..9258e69c0 100644 --- a/src/app/valentina/watermarkwindow.ui +++ b/src/app/valentina/watermarkwindow.ui @@ -77,7 +77,7 @@ - + 0 @@ -87,6 +87,12 @@ Text + + true + + + true + QFormLayout::ExpandingFieldsGrow @@ -182,7 +188,7 @@ - + 0 @@ -192,6 +198,9 @@ Image + + true + QFormLayout::ExpandingFieldsGrow diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 58fcb55d4..5c26cba2b 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -241,9 +241,11 @@ struct VLabelTemplateLine struct VWatermarkData { int opacity{20}; + bool showText{true}; QString text{}; int textRotation{0}; QFont font{}; + bool showImage{true}; QString path{}; int imageRotation{0}; bool grayscale{false}; diff --git a/src/libs/ifc/schema/watermark/v1.0.0.xsd b/src/libs/ifc/schema/watermark/v1.0.0.xsd index 1b9c44e31..1a24a6ab7 100644 --- a/src/libs/ifc/schema/watermark/v1.0.0.xsd +++ b/src/libs/ifc/schema/watermark/v1.0.0.xsd @@ -7,6 +7,7 @@ + @@ -18,6 +19,7 @@ + diff --git a/src/libs/vformat/vwatermark.cpp b/src/libs/vformat/vwatermark.cpp index 5d58ffa26..667802823 100644 --- a/src/libs/vformat/vwatermark.cpp +++ b/src/libs/vformat/vwatermark.cpp @@ -38,6 +38,7 @@ const QString VWatermark::AttrRotation = QStringLiteral("rotation"); const QString VWatermark::AttrFont = QStringLiteral("font"); const QString VWatermark::AttrPath = QStringLiteral("path"); const QString VWatermark::AttrGrayscale = QStringLiteral("grayscale"); +const QString VWatermark::AttrShow = QStringLiteral("show"); namespace { @@ -97,6 +98,7 @@ VWatermarkData VWatermark::GetWatermark() const QDomElement text = rootElement.firstChildElement(TagText); if (not text.isNull()) { + data.showText = GetParametrBool(text, AttrShow, trueStr); data.text = GetParametrEmptyString(text, AttrText); data.textRotation = GetParametrInt(text, AttrRotation, QChar('0')); data.font.fromString(GetParametrEmptyString(text, AttrFont)); @@ -105,6 +107,7 @@ VWatermarkData VWatermark::GetWatermark() const QDomElement image = rootElement.firstChildElement(TagImage); if (not image.isNull()) { + data.showImage = GetParametrBool(image, AttrShow, trueStr); data.path = GetParametrEmptyString(image, AttrPath); data.imageRotation = GetParametrInt(image, AttrRotation, QChar('0')); data.grayscale = GetParametrBool(image, AttrGrayscale, falseStr); @@ -126,6 +129,7 @@ void VWatermark::SetWatermark(const VWatermarkData &data) QDomElement text = rootElement.firstChildElement(TagText); if (not text.isNull()) { + SetAttribute(text, AttrShow, data.showText); SetAttributeOrRemoveIf(text, AttrText, data.text, data.text.isEmpty()); SetAttributeOrRemoveIf(text, AttrRotation, data.textRotation, data.textRotation == 0); const QString fontString = data.font.toString(); @@ -135,6 +139,7 @@ void VWatermark::SetWatermark(const VWatermarkData &data) QDomElement image = rootElement.firstChildElement(TagImage); if (not image.isNull()) { + SetAttribute(image, AttrShow, data.showImage); SetAttributeOrRemoveIf(image, AttrPath, data.path, data.path.isEmpty()); SetAttributeOrRemoveIf(image, AttrRotation, data.imageRotation, data.imageRotation == 0); SetAttributeOrRemoveIf(image, AttrGrayscale, data.grayscale, data.grayscale == false); diff --git a/src/libs/vformat/vwatermark.h b/src/libs/vformat/vwatermark.h index d1ff85fa6..c4dd0644b 100644 --- a/src/libs/vformat/vwatermark.h +++ b/src/libs/vformat/vwatermark.h @@ -54,6 +54,7 @@ public: static const QString AttrFont; static const QString AttrPath; static const QString AttrGrayscale; + static const QString AttrShow; private: Q_DISABLE_COPY(VWatermark) diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp index f1496c086..3727617dd 100644 --- a/src/libs/vlayout/vposter.cpp +++ b/src/libs/vlayout/vposter.cpp @@ -160,12 +160,12 @@ QVector VPoster::Tile(QGraphicsItem *parent, const PosterData & if (watermarkData.opacity > 0) { - if (not watermarkData.path.isEmpty()) + if (watermarkData.showImage && not watermarkData.path.isEmpty()) { data += ImageWatermark(parent, img, watermarkData, watermarkPath); } - if (not watermarkData.text.isEmpty()) + if (watermarkData.showText && not watermarkData.text.isEmpty()) { data += TextWatermark(parent, img, watermarkData); }