Improve ergonomic. Allow a user to define both text and image, and control

which will of them be active.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-12-30 14:43:06 +02:00
parent d0dc209c45
commit 6fc51d83b0
7 changed files with 44 additions and 12 deletions

View File

@ -104,6 +104,9 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) :
[this](){WatermarkChangesWereSaved(false);}); [this](){WatermarkChangesWereSaved(false);});
connect(ui->checkBoxGrayColor, &QCheckBox::stateChanged, this, [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) if (not changed)
{ {
QMessageBox messageBox(this); QMessageBox messageBoxWarning(this);
messageBox.setIcon(QMessageBox::Warning); messageBoxWarning.setIcon(QMessageBox::Warning);
messageBox.setText(tr("Cannot set permissions for %1 to writable.").arg(m_curFile)); messageBoxWarning.setText(tr("Cannot set permissions for %1 to writable.").arg(m_curFile));
messageBox.setInformativeText(tr("Could not save the file.")); messageBoxWarning.setInformativeText(tr("Could not save the file."));
messageBox.setDefaultButton(QMessageBox::Ok); messageBoxWarning.setDefaultButton(QMessageBox::Ok);
messageBox.setStandardButtons(QMessageBox::Ok); messageBoxWarning.setStandardButtons(QMessageBox::Ok);
messageBox.exec(); messageBoxWarning.exec();
return false; return false;
} }
} }
@ -581,8 +584,10 @@ bool WatermarkWindow::ContinueFormatRewrite(const QString &currentFormatVersion,
bool WatermarkWindow::SaveWatermark(const QString &fileName, QString &error) bool WatermarkWindow::SaveWatermark(const QString &fileName, QString &error)
{ {
m_data.opacity = ui->spinBoxOpacity->value(); m_data.opacity = ui->spinBoxOpacity->value();
m_data.showText = ui->groupBoxWatermarkText->isChecked();
m_data.text = ui->lineEditText->text(); m_data.text = ui->lineEditText->text();
m_data.textRotation = ui->spinBoxTextRotation->value(); m_data.textRotation = ui->spinBoxTextRotation->value();
m_data.showImage = ui->groupBoxWatermarkImage->isChecked();
m_data.path = RelativeMPath(fileName, ui->lineEditPath->text()); m_data.path = RelativeMPath(fileName, ui->lineEditPath->text());
m_data.imageRotation = ui->spinBoxImageRotation->value(); m_data.imageRotation = ui->spinBoxImageRotation->value();
m_data.grayscale = ui->checkBoxGrayColor->isChecked(); m_data.grayscale = ui->checkBoxGrayColor->isChecked();
@ -677,6 +682,10 @@ void WatermarkWindow::ShowWatermark()
ui->spinBoxOpacity->setValue(m_data.opacity); ui->spinBoxOpacity->setValue(m_data.opacity);
ui->spinBoxOpacity->blockSignals(false); ui->spinBoxOpacity->blockSignals(false);
ui->groupBoxWatermarkText->blockSignals(true);
ui->groupBoxWatermarkText->setChecked(m_data.showText);
ui->groupBoxWatermarkText->blockSignals(false);
ui->lineEditText->blockSignals(true); ui->lineEditText->blockSignals(true);
ui->lineEditText->setText(m_data.text); ui->lineEditText->setText(m_data.text);
ui->lineEditText->blockSignals(false); ui->lineEditText->blockSignals(false);
@ -689,6 +698,10 @@ void WatermarkWindow::ShowWatermark()
ui->lineEditFontSample->setFont(m_data.font); ui->lineEditFontSample->setFont(m_data.font);
ui->lineEditFontSample->blockSignals(false); ui->lineEditFontSample->blockSignals(false);
ui->groupBoxWatermarkImage->blockSignals(true);
ui->groupBoxWatermarkImage->setChecked(m_data.showImage);
ui->groupBoxWatermarkImage->blockSignals(false);
ui->lineEditPath->blockSignals(true); ui->lineEditPath->blockSignals(true);
ui->lineEditPath->setText(AbsoluteMPath(m_curFile, m_data.path)); ui->lineEditPath->setText(AbsoluteMPath(m_curFile, m_data.path));
ValidatePath(); ValidatePath();

View File

@ -77,7 +77,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBoxWatermarkText">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -87,6 +87,12 @@
<property name="title"> <property name="title">
<string>Text</string> <string>Text</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_3"> <layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum> <enum>QFormLayout::ExpandingFieldsGrow</enum>
@ -182,7 +188,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBoxWatermarkImage">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -192,6 +198,9 @@
<property name="title"> <property name="title">
<string>Image</string> <string>Image</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum> <enum>QFormLayout::ExpandingFieldsGrow</enum>

View File

@ -241,9 +241,11 @@ struct VLabelTemplateLine
struct VWatermarkData struct VWatermarkData
{ {
int opacity{20}; int opacity{20};
bool showText{true};
QString text{}; QString text{};
int textRotation{0}; int textRotation{0};
QFont font{}; QFont font{};
bool showImage{true};
QString path{}; QString path{};
int imageRotation{0}; int imageRotation{0};
bool grayscale{false}; bool grayscale{false};

View File

@ -7,6 +7,7 @@
<xs:complexType> <xs:complexType>
<xs:simpleContent> <xs:simpleContent>
<xs:extension base="xs:string"> <xs:extension base="xs:string">
<xs:attribute type="xs:boolean" name="show"/>
<xs:attribute type="xs:string" name="text"/> <xs:attribute type="xs:string" name="text"/>
<xs:attribute type="rotationType" name="rotation"/> <xs:attribute type="rotationType" name="rotation"/>
<xs:attribute type="xs:string" name="font"/> <xs:attribute type="xs:string" name="font"/>
@ -18,6 +19,7 @@
<xs:complexType> <xs:complexType>
<xs:simpleContent> <xs:simpleContent>
<xs:extension base="xs:string"> <xs:extension base="xs:string">
<xs:attribute type="xs:boolean" name="show"/>
<xs:attribute type="xs:string" name="path"/> <xs:attribute type="xs:string" name="path"/>
<xs:attribute type="rotationType" name="rotation"/> <xs:attribute type="rotationType" name="rotation"/>
<xs:attribute type="xs:boolean" name="grayscale"/> <xs:attribute type="xs:boolean" name="grayscale"/>

View File

@ -38,6 +38,7 @@ const QString VWatermark::AttrRotation = QStringLiteral("rotation");
const QString VWatermark::AttrFont = QStringLiteral("font"); const QString VWatermark::AttrFont = QStringLiteral("font");
const QString VWatermark::AttrPath = QStringLiteral("path"); const QString VWatermark::AttrPath = QStringLiteral("path");
const QString VWatermark::AttrGrayscale = QStringLiteral("grayscale"); const QString VWatermark::AttrGrayscale = QStringLiteral("grayscale");
const QString VWatermark::AttrShow = QStringLiteral("show");
namespace namespace
{ {
@ -97,6 +98,7 @@ VWatermarkData VWatermark::GetWatermark() const
QDomElement text = rootElement.firstChildElement(TagText); QDomElement text = rootElement.firstChildElement(TagText);
if (not text.isNull()) if (not text.isNull())
{ {
data.showText = GetParametrBool(text, AttrShow, trueStr);
data.text = GetParametrEmptyString(text, AttrText); data.text = GetParametrEmptyString(text, AttrText);
data.textRotation = GetParametrInt(text, AttrRotation, QChar('0')); data.textRotation = GetParametrInt(text, AttrRotation, QChar('0'));
data.font.fromString(GetParametrEmptyString(text, AttrFont)); data.font.fromString(GetParametrEmptyString(text, AttrFont));
@ -105,6 +107,7 @@ VWatermarkData VWatermark::GetWatermark() const
QDomElement image = rootElement.firstChildElement(TagImage); QDomElement image = rootElement.firstChildElement(TagImage);
if (not image.isNull()) if (not image.isNull())
{ {
data.showImage = GetParametrBool(image, AttrShow, trueStr);
data.path = GetParametrEmptyString(image, AttrPath); data.path = GetParametrEmptyString(image, AttrPath);
data.imageRotation = GetParametrInt(image, AttrRotation, QChar('0')); data.imageRotation = GetParametrInt(image, AttrRotation, QChar('0'));
data.grayscale = GetParametrBool(image, AttrGrayscale, falseStr); data.grayscale = GetParametrBool(image, AttrGrayscale, falseStr);
@ -126,6 +129,7 @@ void VWatermark::SetWatermark(const VWatermarkData &data)
QDomElement text = rootElement.firstChildElement(TagText); QDomElement text = rootElement.firstChildElement(TagText);
if (not text.isNull()) if (not text.isNull())
{ {
SetAttribute(text, AttrShow, data.showText);
SetAttributeOrRemoveIf(text, AttrText, data.text, data.text.isEmpty()); SetAttributeOrRemoveIf(text, AttrText, data.text, data.text.isEmpty());
SetAttributeOrRemoveIf(text, AttrRotation, data.textRotation, data.textRotation == 0); SetAttributeOrRemoveIf(text, AttrRotation, data.textRotation, data.textRotation == 0);
const QString fontString = data.font.toString(); const QString fontString = data.font.toString();
@ -135,6 +139,7 @@ void VWatermark::SetWatermark(const VWatermarkData &data)
QDomElement image = rootElement.firstChildElement(TagImage); QDomElement image = rootElement.firstChildElement(TagImage);
if (not image.isNull()) if (not image.isNull())
{ {
SetAttribute(image, AttrShow, data.showImage);
SetAttributeOrRemoveIf(image, AttrPath, data.path, data.path.isEmpty()); SetAttributeOrRemoveIf(image, AttrPath, data.path, data.path.isEmpty());
SetAttributeOrRemoveIf(image, AttrRotation, data.imageRotation, data.imageRotation == 0); SetAttributeOrRemoveIf(image, AttrRotation, data.imageRotation, data.imageRotation == 0);
SetAttributeOrRemoveIf(image, AttrGrayscale, data.grayscale, data.grayscale == false); SetAttributeOrRemoveIf(image, AttrGrayscale, data.grayscale, data.grayscale == false);

View File

@ -54,6 +54,7 @@ public:
static const QString AttrFont; static const QString AttrFont;
static const QString AttrPath; static const QString AttrPath;
static const QString AttrGrayscale; static const QString AttrGrayscale;
static const QString AttrShow;
private: private:
Q_DISABLE_COPY(VWatermark) Q_DISABLE_COPY(VWatermark)

View File

@ -160,12 +160,12 @@ QVector<QGraphicsItem *> VPoster::Tile(QGraphicsItem *parent, const PosterData &
if (watermarkData.opacity > 0) if (watermarkData.opacity > 0)
{ {
if (not watermarkData.path.isEmpty()) if (watermarkData.showImage && not watermarkData.path.isEmpty())
{ {
data += ImageWatermark(parent, img, watermarkData, watermarkPath); data += ImageWatermark(parent, img, watermarkData, watermarkPath);
} }
if (not watermarkData.text.isEmpty()) if (watermarkData.showText && not watermarkData.text.isEmpty())
{ {
data += TextWatermark(parent, img, watermarkData); data += TextWatermark(parent, img, watermarkData);
} }