Watermark support.

This commit is contained in:
Roman Telezhynskyi 2021-09-11 19:39:38 +03:00
parent 54b0ca5ee5
commit 3fea813b9c
52 changed files with 2365 additions and 100 deletions

View File

@ -119,6 +119,7 @@ auto PuzzlePreferencesLayoutPage::Apply() -> QStringList
settings->SetLayoutSheetMargins(GetSheetMargins()); settings->SetLayoutSheetMargins(GetSheetMargins());
settings->SetLayoutTileShowTiles(ui->checkBoxTileShowTiles->isChecked()); settings->SetLayoutTileShowTiles(ui->checkBoxTileShowTiles->isChecked());
settings->SetLayoutTileShowWatermark(ui->checkBoxTileShowWatermark->isChecked());
settings->SetLayoutTilePaperHeight( settings->SetLayoutTilePaperHeight(
UnitConvertor(ui->doubleSpinBoxTilePaperHeight->value(), m_oldLayoutUnit, Unit::Px)); UnitConvertor(ui->doubleSpinBoxTilePaperHeight->value(), m_oldLayoutUnit, Unit::Px));
@ -602,6 +603,7 @@ void PuzzlePreferencesLayoutPage::ReadSettings()
TileSize(QSizeF(tileWidth, tileHeight)); TileSize(QSizeF(tileWidth, tileHeight));
ui->checkBoxTileShowTiles->setChecked(settings->GetLayoutTileShowTiles()); ui->checkBoxTileShowTiles->setChecked(settings->GetLayoutTileShowTiles());
ui->checkBoxTileShowWatermark->setChecked(settings->GetLayoutTileShowWatermark());
ui->checkBoxTileIgnoreFileds->setChecked(settings->GetLayoutTileIgnoreMargins()); ui->checkBoxTileIgnoreFileds->setChecked(settings->GetLayoutTileIgnoreMargins());
SetTileMargins(settings->GetLayoutSheetMargins()); SetTileMargins(settings->GetLayoutSheetMargins());

View File

@ -374,6 +374,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBoxTileShowWatermark">
<property name="toolTip">
<string>Show watermark preview</string>
</property>
<property name="text">
<string>Show watermark</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBoxPaperFormat_2"> <widget class="QGroupBox" name="groupBoxPaperFormat_2">
<property name="autoFillBackground"> <property name="autoFillBackground">

View File

@ -31,9 +31,13 @@
#include "vpsheet.h" #include "vpsheet.h"
#include "../vpapplication.h" #include "../vpapplication.h"
#include "../vptilefactory.h" #include "../vptilefactory.h"
#include "../ifc/xml/vwatermarkconverter.h"
#include "../vformat/vwatermark.h"
#include "../ifc/exception/vexception.h"
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QUndoStack> #include <QUndoStack>
#include <QPixmapCache>
Q_LOGGING_CATEGORY(pLayout, "p.layout") Q_LOGGING_CATEGORY(pLayout, "p.layout")
@ -63,6 +67,7 @@ auto VPLayout::CreateLayout(QUndoStack *undoStack) -> VPLayoutPtr
layout->LayoutSettings().SetUnit(settings->LayoutUnit()); layout->LayoutSettings().SetUnit(settings->LayoutUnit());
layout->LayoutSettings().SetShowTiles(settings->GetLayoutTileShowTiles()); layout->LayoutSettings().SetShowTiles(settings->GetLayoutTileShowTiles());
layout->LayoutSettings().SetShowWatermark(settings->GetLayoutTileShowWatermark());
layout->LayoutSettings().SetTilesSize(QSizeF(settings->GetLayoutTilePaperWidth(), layout->LayoutSettings().SetTilesSize(QSizeF(settings->GetLayoutTilePaperWidth(),
settings->GetLayoutTilePaperHeight())); settings->GetLayoutTilePaperHeight()));
layout->LayoutSettings().SetIgnoreTilesMargins(settings->GetLayoutTileIgnoreMargins()); layout->LayoutSettings().SetIgnoreTilesMargins(settings->GetLayoutTileIgnoreMargins());
@ -138,6 +143,33 @@ void VPLayout::RefreshScenePieces() const
} }
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPLayout::WatermarkData() const -> VWatermarkData
{
VWatermarkData data;
if (not m_layoutSettings.WatermarkPath().isEmpty())
{
try
{
VWatermarkConverter converter(m_layoutSettings.WatermarkPath());
VWatermark watermark;
watermark.setXMLContent(converter.Convert());
data = watermark.GetWatermark();
}
catch (VException &e)
{
data.invalidFile = true;
data.opacity = 20;
data.showImage = true;
data.path = "fake.png";
data.showText = false;
return data;
}
}
return data;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPLayout::GetPieces() const -> QList<VPPiecePtr> auto VPLayout::GetPieces() const -> QList<VPPiecePtr>
{ {

View File

@ -39,6 +39,7 @@ class VPPiece;
class VPSheet; class VPSheet;
class QUndoStack; class QUndoStack;
class VPTileFactory; class VPTileFactory;
struct VWatermarkData;
class VPLayout : public QObject class VPLayout : public QObject
{ {
@ -93,6 +94,8 @@ public:
void RefreshScenePieces() const; void RefreshScenePieces() const;
auto WatermarkData() const -> VWatermarkData;
signals: signals:
void PieceSheetChanged(const VPPiecePtr &piece); void PieceSheetChanged(const VPPiecePtr &piece);
void ActiveSheetChanged(const VPSheetPtr &focusedSheet); void ActiveSheetChanged(const VPSheetPtr &focusedSheet);

View File

@ -330,7 +330,7 @@ void VPLayoutSettings::SetIgnoreTilesMargins(bool newIgnoreTilesMargins)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPLayoutSettings::HorizontalScale() const auto VPLayoutSettings::HorizontalScale() const -> qreal
{ {
return m_horizontalScale; return m_horizontalScale;
} }
@ -342,7 +342,7 @@ void VPLayoutSettings::SetHorizontalScale(qreal newHorizontalScale)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPLayoutSettings::VerticalScale() const auto VPLayoutSettings::VerticalScale() const -> qreal
{ {
return m_verticalScale; return m_verticalScale;
} }
@ -352,3 +352,27 @@ void VPLayoutSettings::SetVerticalScale(qreal newVerticalScale)
{ {
m_verticalScale = newVerticalScale; m_verticalScale = newVerticalScale;
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPLayoutSettings::WatermarkPath() const -> const QString &
{
return m_watermarkPath;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutSettings::SetWatermarkPath(const QString &newWatermarkPath)
{
m_watermarkPath = newWatermarkPath;
}
//---------------------------------------------------------------------------------------------------------------------
auto VPLayoutSettings::GetShowWatermark() const -> bool
{
return m_showWatermark;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutSettings::SetShowWatermark(bool newShowWatermark)
{
m_showWatermark = newShowWatermark;
}

View File

@ -306,6 +306,12 @@ public:
auto VerticalScale() const -> qreal; auto VerticalScale() const -> qreal;
void SetVerticalScale(qreal newVerticalScale); void SetVerticalScale(qreal newVerticalScale);
auto WatermarkPath() const -> const QString &;
void SetWatermarkPath(const QString &newWatermarkPath);
auto GetShowWatermark() const -> bool;
void SetShowWatermark(bool newShowWatermark);
private: private:
Unit m_unit{Unit::Cm}; Unit m_unit{Unit::Cm};
@ -329,6 +335,7 @@ private:
bool m_ignoreTilesMargins{false}; bool m_ignoreTilesMargins{false};
bool m_showTiles{false}; bool m_showTiles{false};
bool m_showWatermark{false};
// control // control
bool m_followGrainLine{false}; bool m_followGrainLine{false};
@ -357,6 +364,8 @@ private:
qreal m_horizontalScale{1.0}; qreal m_horizontalScale{1.0};
qreal m_verticalScale{1.0}; qreal m_verticalScale{1.0};
QString m_watermarkPath{};
}; };
#endif // VPLAYOUTSETTINGS_H #endif // VPLAYOUTSETTINGS_H

View File

@ -263,6 +263,9 @@ void VPSheetSceneData::PrepareTilesScheme()
{ {
m_showTilesSchemeTmp = layout->LayoutSettings().GetShowTiles(); m_showTilesSchemeTmp = layout->LayoutSettings().GetShowTiles();
layout->LayoutSettings().SetShowTiles(true); layout->LayoutSettings().SetShowTiles(true);
m_showTilesWatermarkSchemeTmp = layout->LayoutSettings().GetShowWatermark();
layout->LayoutSettings().SetShowWatermark(false);
} }
RefreshLayout(); RefreshLayout();
@ -275,6 +278,7 @@ void VPSheetSceneData::ClearTilesScheme()
if (not layout.isNull()) if (not layout.isNull())
{ {
layout->LayoutSettings().SetShowTiles(m_showTilesSchemeTmp); layout->LayoutSettings().SetShowTiles(m_showTilesSchemeTmp);
layout->LayoutSettings().SetShowWatermark(m_showTilesWatermarkSchemeTmp);
} }
RefreshLayout(); RefreshLayout();
@ -379,7 +383,7 @@ auto VPSheet::GetAsLayoutPieces() const -> QVector<VLayoutPiece>
QVector<VLayoutPiece> details; QVector<VLayoutPiece> details;
details.reserve(pieces.size()); details.reserve(pieces.size());
for (auto piece : pieces) for (const auto& piece : pieces)
{ {
if (not piece.isNull()) if (not piece.isNull())
{ {
@ -421,7 +425,7 @@ void VPSheet::SetVisible(bool visible)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
GrainlineType VPSheet::GrainlineOrientation() const auto VPSheet::GrainlineOrientation() const -> GrainlineType
{ {
if (m_grainlineType == GrainlineType::NotFixed) if (m_grainlineType == GrainlineType::NotFixed)
{ {
@ -694,7 +698,7 @@ void VPSheet::ClearSelection() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPageLayout::Orientation VPSheet::GetSheetOrientation() const auto VPSheet::GetSheetOrientation() const -> QPageLayout::Orientation
{ {
return m_size.height() >= m_size.width() ? QPageLayout::Portrait : QPageLayout::Landscape; return m_size.height() >= m_size.width() ? QPageLayout::Portrait : QPageLayout::Landscape;
} }

View File

@ -111,6 +111,7 @@ private:
bool m_showTilesTmp{false}; bool m_showTilesTmp{false};
bool m_showTilesSchemeTmp{false}; bool m_showTilesSchemeTmp{false};
bool m_showTilesWatermarkSchemeTmp{false};
/** /**
* variable to hold temporarly hte value of the show grid * variable to hold temporarly hte value of the show grid

View File

@ -189,15 +189,6 @@ noRunPath{ # For enable run qmake with CONFIG+=noRunPath
#win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib #win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib
#else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a #else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a
#VWidgets static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets
INCLUDEPATH += $$PWD/../../libs/vwidgets
DEPENDPATH += $$PWD/../../libs/vwidgets
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a
# VLayout static library (depend on VGeometry, VFormat) # VLayout static library (depend on VGeometry, VFormat)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout
@ -243,6 +234,15 @@ DEPENDPATH += $$PWD/../../libs/ifc
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/ifc.lib win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/ifc.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/libifc.a else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/libifc.a
#VWidgets static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets
INCLUDEPATH += $$PWD/../../libs/vwidgets
DEPENDPATH += $$PWD/../../libs/vwidgets
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a
#VMisc static library #VMisc static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vmisc/$${DESTDIR}/ -lvmisc unix|win32: LIBS += -L$$OUT_PWD/../../libs/vmisc/$${DESTDIR}/ -lvmisc

View File

@ -4,10 +4,15 @@
#include "../layout/vplayout.h" #include "../layout/vplayout.h"
#include "../layout/vpsheet.h" #include "../layout/vpsheet.h"
#include <QFileInfo>
#include <QImageReader>
#include <QPixmapCache>
#include <QSvgRenderer>
namespace namespace
{ {
constexpr qreal penWidth = 1; constexpr qreal penWidth = 1;
} } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPGraphicsTileGrid::VPGraphicsTileGrid(const VPLayoutPtr &layout, const QUuid &sheetUuid, QGraphicsItem *parent): VPGraphicsTileGrid::VPGraphicsTileGrid(const VPLayoutPtr &layout, const QUuid &sheetUuid, QGraphicsItem *parent):
@ -82,18 +87,44 @@ void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem
const int nbCol = layout->TileFactory()->ColNb(sheet); const int nbCol = layout->TileFactory()->ColNb(sheet);
const int nbRow = layout->TileFactory()->RowNb(sheet); const int nbRow = layout->TileFactory()->RowNb(sheet);
for(int i=0;i<=nbCol;++i) VWatermarkData watermarkData = layout->TileFactory()->WatermarkData();
{
// vertical lines
painter->drawLine(QPointF(sheetMargins.left()+i*width, sheetMargins.top()),
QPointF(sheetMargins.left()+i*width, sheetMargins.top() + nbRow*height));
}
for(int j=0;j<=nbRow;++j) for(int j=0;j<=nbRow;++j)
{ {
// horizontal lines // horizontal lines
painter->drawLine(QPointF(sheetMargins.left(), sheetMargins.top()+j*height), painter->drawLine(QPointF(sheetMargins.left(), sheetMargins.top()+j*height),
QPointF(sheetMargins.left()+nbCol*width, sheetMargins.top()+j*height)); QPointF(sheetMargins.left()+nbCol*width, sheetMargins.top()+j*height));
for(int i=0;i<=nbCol;++i)
{
// vertical lines
painter->drawLine(QPointF(sheetMargins.left()+i*width, sheetMargins.top()),
QPointF(sheetMargins.left()+i*width, sheetMargins.top() + nbRow*height));
if (j < nbRow && i < nbCol)
{
QRectF img(sheetMargins.left()+i*width, sheetMargins.top()+j*height,
width, height);
if (not layout->LayoutSettings().WatermarkPath().isEmpty() &&
layout->LayoutSettings().GetShowWatermark())
{
if (watermarkData.opacity > 0)
{
if (watermarkData.showImage && not watermarkData.path.isEmpty())
{
VPTileFactory::PaintWatermarkImage(painter, img, watermarkData,
layout->LayoutSettings().WatermarkPath());
}
if (watermarkData.showText && not watermarkData.text.isEmpty())
{
VPTileFactory::PaintWatermarkText(painter, img, watermarkData);
}
}
}
}
}
} }
} }
} }

View File

@ -38,6 +38,7 @@
class VPTileFactory; class VPTileFactory;
class VPLayout; class VPLayout;
struct VWatermarkData;
class VPGraphicsTileGrid : public QGraphicsItem class VPGraphicsTileGrid : public QGraphicsItem
{ {

View File

@ -20,5 +20,6 @@
<file>puzzleicon/32X32/horizontal_grainline@2x.png</file> <file>puzzleicon/32X32/horizontal_grainline@2x.png</file>
<file>puzzleicon/32X32/vertical_grainline.png</file> <file>puzzleicon/32X32/vertical_grainline.png</file>
<file>puzzleicon/32X32/vertical_grainline@2x.png</file> <file>puzzleicon/32X32/vertical_grainline@2x.png</file>
<file>puzzleicon/svg/no_watermark_image.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1 @@
<svg id="Capa_1" enable-background="new 0 0 512 512" height="512" viewBox="0 0 512 512" width="512" xmlns="http://www.w3.org/2000/svg"><g><g><path d="m502.681 198.27v68.85l-2.48 1.68-24.29 16.48-58.97-40-58.97 40-58.97-40-58.97 40-58.96-40-58.97 40-26.76-18.15v-219.75c0-22.03 17.85-39.88 39.87-39.88h176.7c15.88 0 67.31 43.85 112.77 90.03 41.48 42.15 78 86.24 78 100.74z" fill="#ddeafb"/><path d="m475.911 332.15 26.77-18.16v150.63c0 22.03-17.85 39.88-39.87 39.88h-327.6c-18.82 0-34.59-13.04-38.78-30.58l-.16-22.8-.93-135.78v-1.34l26.76 18.15 58.97-40 58.96 40 58.97-40 58.97 40 58.97-40z" fill="#ddeafb"/><path d="m502.681 198.27v68.85l-2.48 1.68c-15.77-94.08-100.61-101.12-129.94-130.45l54.42-40.82c41.48 42.15 78 86.24 78 100.74z" fill="#cbe2ff"/><path d="m311.906 7.5h-97.57c.11 0 .22.01.34.01 119.72 3 125.26 100.52 157.15 132.41l40.82-54.42c-42.15-41.48-86.24-78-100.74-78z" fill="#cbe2ff"/><path d="m502.681 198.276v16.868c0-35.514-28.798-64.312-64.312-64.312h-39.143c-22.019 0-39.877-17.858-39.877-39.877v-39.143c0-35.514-28.798-64.312-64.312-64.312h16.868c30.373 0 59.512 12.068 80.989 33.545l76.242 76.242c21.476 21.476 33.545 50.615 33.545 80.989z" fill="#bed8fb"/><circle cx="96.445" cy="141.864" fill="#dd636e" r="87.126"/><path d="m107.749 228.264c-3.7.48-7.48.73-11.31.73-48.12 0-87.12-39.01-87.12-87.13 0-48.11 39-87.12 87.12-87.12 3.83 0 7.61.25 11.31.73-42.78 5.54-75.82 42.11-75.82 86.39 0 44.29 33.04 80.86 75.82 86.4z" fill="#da4a54"/></g><g><path d="m510.181 198.276c0-32.598-12.693-63.244-35.741-86.292l-76.242-76.242c-23.05-23.049-53.695-35.742-86.293-35.742h-.006-176.7c-26.12 0-47.37 21.255-47.37 47.38v.257c-48.153 4.369-86.01 44.956-86.01 94.223 0 49.273 37.856 89.864 86.01 94.233v31.027c0 2.486 1.232 4.811 3.29 6.207l26.769 18.16c2.543 1.725 5.88 1.724 8.421 0l54.761-37.144 54.749 37.144c2.543 1.725 5.88 1.724 8.421 0l54.76-37.144 54.76 37.144c2.541 1.725 5.879 1.724 8.42 0l54.761-37.144 54.76 37.144c1.271.862 2.74 1.293 4.21 1.293s2.939-.431 4.21-1.293l26.76-18.15c2.058-1.396 3.29-3.721 3.29-6.207zm-122.591-151.928 76.242 76.242c12.185 12.184 21.069 26.788 26.205 42.729-13.069-13.549-31.401-21.988-51.669-21.988h-39.143c-17.853 0-32.377-14.524-32.377-32.377v-39.142c0-20.268-8.438-38.599-21.987-51.669 15.942 5.137 30.545 14.021 42.729 26.205zm88.319 229.87-54.76-37.144c-2.541-1.724-5.879-1.724-8.42 0l-54.761 37.144-54.76-37.144c-2.541-1.724-5.879-1.724-8.42 0l-54.76 37.144-54.749-37.144c-2.543-1.725-5.88-1.724-8.421 0l-54.761 37.144-19.27-13.072v-26.876c49.21-3.293 88.24-44.375 88.24-94.41 0-29.062-13.078-56.098-35.881-74.177-3.244-2.573-7.963-2.029-10.536 1.218-2.573 3.246-2.028 7.963 1.218 10.536 19.191 15.217 30.199 37.969 30.199 62.423 0 43.908-35.718 79.63-79.62 79.63-43.908 0-79.63-35.722-79.63-79.63 0-43.903 35.722-79.62 79.63-79.62 7.619 0 15.133 1.069 22.331 3.177 3.979 1.166 8.142-1.115 9.306-5.089 1.165-3.975-1.114-8.141-5.089-9.306-6.547-1.918-13.307-3.107-20.168-3.564v-.078c0-17.854 14.521-32.38 32.37-32.38h159.838c31.326 0 56.812 25.486 56.812 56.812v39.143c0 26.124 21.253 47.377 47.377 47.377h39.143c31.171 0 56.551 25.237 56.801 56.35v48.472z"/><path d="m507.608 308.351c-2.641-2.287-6.383-2.434-9.149-.558l-22.55 15.294-54.76-37.144c-2.541-1.725-5.878-1.724-8.421 0l-19.519 13.243c-3.399 2.306-4.586 6.937-2.382 10.403 2.279 3.586 7.05 4.555 10.543 2.187l15.569-10.563 54.76 37.144c2.541 1.725 5.879 1.724 8.42 0l15.05-10.208v136.471c0 17.883-14.497 32.38-32.38 32.38h-327.59c-.462 0-.921-.01-1.379-.029-16.775-.699-29.846-14.883-29.961-31.673l-.941-137.098 14.97 10.156c2.543 1.725 5.88 1.724 8.421 0l54.761-37.144 54.749 37.144c2.543 1.725 5.88 1.724 8.421 0l54.76-37.144 54.76 37.144c2.54 1.724 5.877 1.724 8.419.001l11.172-7.575c3.399-2.304 4.586-6.933 2.384-10.399-2.279-3.587-7.052-4.559-10.543-2.192l-7.221 4.896-54.761-37.145c-2.541-1.724-5.879-1.724-8.42 0l-54.76 37.144-54.749-37.144c-2.543-1.725-5.88-1.724-8.421 0l-54.761 37.144-22.379-15.18c-1.84-1.248-4.138-1.747-6.287-1.175-3.377.899-5.604 3.914-5.604 7.259v1.402l1.09 154.58c0 17.853 14.019 42.029 46.28 42.029h327.6c26.162 0 47.37-21.208 47.37-47.37v-150.416c0-2.225-.879-4.407-2.561-5.864z"/><path d="m131.2 96.501-34.755 34.755-34.756-34.755c-2.93-2.929-7.678-2.929-10.607 0s-2.929 7.677 0 10.606l34.756 34.756-34.756 34.757c-2.929 2.929-2.929 7.677 0 10.606 1.465 1.465 3.385 2.197 5.304 2.197s3.839-.732 5.304-2.197l34.755-34.755 34.755 34.755c1.465 1.465 3.385 2.197 5.304 2.197s3.839-.732 5.304-2.197c2.929-2.929 2.929-7.677 0-10.606l-34.756-34.756 34.756-34.756c2.929-2.929 2.929-7.677 0-10.606-2.93-2.93-7.678-2.93-10.608-.001z"/></g></g></svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -43,6 +43,7 @@
#include "../vlayout/vrawlayout.h" #include "../vlayout/vrawlayout.h"
#include "../vlayout/vlayoutexporter.h" #include "../vlayout/vlayoutexporter.h"
#include "../vlayout/vprintlayout.h" #include "../vlayout/vprintlayout.h"
#include "../vlayout/dialogs/watermarkwindow.h"
#include "../vmisc/vsysexits.h" #include "../vmisc/vsysexits.h"
#include "../vmisc/projectversion.h" #include "../vmisc/projectversion.h"
#include "../ifc/xml/vlayoutconverter.h" #include "../ifc/xml/vlayoutconverter.h"
@ -63,6 +64,8 @@
#endif #endif
#include <QLoggingCategory> #include <QLoggingCategory>
#include <chrono>
#include <thread>
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
@ -167,7 +170,8 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
m_undoStack(new QUndoStack(this)), m_undoStack(new QUndoStack(this)),
m_layout{VPLayout::CreateLayout(m_undoStack)}, m_layout{VPLayout::CreateLayout(m_undoStack)},
m_statusLabel(new QLabel(this)), m_statusLabel(new QLabel(this)),
m_layoutWatcher(new QFileSystemWatcher(this)) m_layoutWatcher(new QFileSystemWatcher(this)),
m_watermarkWatcher(new QFileSystemWatcher(this))
{ {
ui->setupUi(this); ui->setupUi(this);
@ -220,7 +224,49 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
{ {
if (not curFile.isEmpty() && curFile == path) if (not curFile.isEmpty() && curFile == path)
{ {
QFileInfo checkFile(path);
if (not checkFile.exists())
{
for(int i=0; i<=1000; i=i+10)
{
if (checkFile.exists())
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
UpdateWindowTitle(); UpdateWindowTitle();
if (checkFile.exists())
{
m_layoutWatcher->addPath(path);
}
}
});
connect(m_layoutWatcher, &QFileSystemWatcher::fileChanged, this, [this](const QString &path)
{
QFileInfo checkFile(path);
if (not checkFile.exists())
{
for(int i=0; i<=1000; i=i+10)
{
if (checkFile.exists())
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
m_layout->TileFactory()->refreshTileInfos();
m_graphicsView->RefreshLayout();
if (checkFile.exists())
{
m_layoutWatcher->addPath(path);
} }
}); });
@ -331,6 +377,14 @@ auto VPMainWindow::LoadFile(QString path) -> bool
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
ui->actionRemoveWatermark->setEnabled(not m_layout->LayoutSettings().WatermarkPath().isEmpty());
ui->actionEditCurrentWatermark->setEnabled(not m_layout->LayoutSettings().WatermarkPath().isEmpty());
if (not m_layout->LayoutSettings().WatermarkPath().isEmpty())
{
m_layoutWatcher->addPath(m_layout->LayoutSettings().WatermarkPath());
}
return true; return true;
} }
@ -527,6 +581,12 @@ void VPMainWindow::SetupMenu()
ui->menuSheet->addAction(redoAction); ui->menuSheet->addAction(redoAction);
ui->toolBarUndoCommands->addAction(redoAction); ui->toolBarUndoCommands->addAction(redoAction);
// Watermark
connect(ui->actionWatermarkEditor, &QAction::triggered, this, &VPMainWindow::CreateWatermark);
connect(ui->actionEditCurrentWatermark, &QAction::triggered, this, &VPMainWindow::EditCurrentWatermark);
connect(ui->actionLoadWatermark, &QAction::triggered, this, &VPMainWindow::LoadWatermark);
connect(ui->actionRemoveWatermark, &QAction::triggered, this, &VPMainWindow::RemoveWatermark);
// Window // Window
connect(ui->menuWindow, &QMenu::aboutToShow, this, [this]() connect(ui->menuWindow, &QMenu::aboutToShow, this, [this]()
{ {
@ -882,6 +942,17 @@ void VPMainWindow::InitPropertyTabTiles()
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView); VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
} }
}); });
connect(ui->checkBoxTilesShowWatermark, &QCheckBox::toggled, this, [this](bool checked)
{
if (not m_layout.isNull())
{
m_layout->LayoutSettings().SetShowWatermark(checked);
LayoutWasSaved(false);
m_graphicsView->RefreshLayout();
VMainGraphicsView::NewSceneRect(m_graphicsView->scene(), m_graphicsView);
}
});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1287,6 +1358,7 @@ void VPMainWindow::SetPropertyTabTilesData()
ui->groupBoxTilesControl->setDisabled(false); ui->groupBoxTilesControl->setDisabled(false);
SetCheckBoxValue(ui->checkBoxTilesShowTiles, m_layout->LayoutSettings().GetShowTiles()); SetCheckBoxValue(ui->checkBoxTilesShowTiles, m_layout->LayoutSettings().GetShowTiles());
SetCheckBoxValue(ui->checkBoxTilesShowWatermark, m_layout->LayoutSettings().GetShowWatermark());
} }
else else
{ {
@ -2586,8 +2658,9 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesS
const int nbCol = m_layout->TileFactory()->ColNb(sheet); const int nbCol = m_layout->TileFactory()->ColNb(sheet);
const int nbRow = m_layout->TileFactory()->RowNb(sheet); const int nbRow = m_layout->TileFactory()->RowNb(sheet);
QRectF source = QRectF(sheetRect.topLeft(), QSizeF(nbCol * ((width - VPTileFactory::tileStripeWidth) / xScale), QRectF source = QRectF(sheetRect.topLeft(),
nbRow * ((height - VPTileFactory::tileStripeWidth) / yScale))); QSizeF(nbCol * ((width - VPTileFactory::tileStripeWidth) / xScale),
nbRow * ((height - VPTileFactory::tileStripeWidth) / yScale)));
QRectF target; QRectF target;
if (tileOrientation != sheetOrientation) if (tileOrientation != sheetOrientation)
@ -2610,6 +2683,25 @@ void VPMainWindow::GeneratePdfTiledFile(const VPSheetPtr &sheet, bool showTilesS
sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source, sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source,
Qt::KeepAspectRatio); Qt::KeepAspectRatio);
VWatermarkData watermarkData = m_layout->TileFactory()->WatermarkData();
if (watermarkData.opacity > 0)
{
if (watermarkData.showImage && not watermarkData.path.isEmpty())
{
VPTileFactory::PaintWatermarkImage(painter, target, watermarkData,
layout->LayoutSettings().WatermarkPath(),
layout->LayoutSettings().HorizontalScale(),
layout->LayoutSettings().VerticalScale());
}
if (watermarkData.showText && not watermarkData.text.isEmpty())
{
VPTileFactory::PaintWatermarkText(painter, target, watermarkData,
layout->LayoutSettings().HorizontalScale(),
layout->LayoutSettings().VerticalScale());
}
}
sheet->SceneData()->ClearTilesScheme(); sheet->SceneData()->ClearTilesScheme();
firstPage = false; firstPage = false;
@ -2648,6 +2740,42 @@ void VPMainWindow::UpdateScaleConnection() const
ui->toolButtonScaleConnected->setIcon(icon); ui->toolButtonScaleConnected->setIcon(icon);
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::OpenWatermark(const QString &path)
{
QList<QPointer<WatermarkWindow>>::const_iterator i;
for (i = m_watermarkEditors.begin(); i != m_watermarkEditors.end(); ++i)
{
if (not (*i).isNull() && not (*i)->CurrentFile().isEmpty()
&& (*i)->CurrentFile() == AbsoluteMPath(curFile, path))
{
(*i)->show();
return;
}
}
auto *watermark = new WatermarkWindow(curFile, this);
connect(watermark, &WatermarkWindow::New, this, [this](){OpenWatermark();});
connect(watermark, &WatermarkWindow::OpenAnother, this, [this](const QString &path){OpenWatermark(path);});
m_watermarkEditors.append(watermark);
watermark->show();
watermark->Open(path);
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::CleanWaterkmarkEditors()
{
QMutableListIterator<QPointer<WatermarkWindow>> i(m_watermarkEditors);
while (i.hasNext())
{
QPointer<WatermarkWindow> watermarkEditor = i.next();
if (watermarkEditor.isNull())
{
i.remove();
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_actionNew_triggered() void VPMainWindow::on_actionNew_triggered()
{ {
@ -3715,6 +3843,67 @@ void VPMainWindow::on_actionPrintPreviewTiledSheet_triggered()
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::CreateWatermark()
{
CleanWaterkmarkEditors();
OpenWatermark();
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::EditCurrentWatermark()
{
CleanWaterkmarkEditors();
QString watermarkFile = m_layout->LayoutSettings().WatermarkPath();
if (not watermarkFile.isEmpty())
{
OpenWatermark(watermarkFile);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::LoadWatermark()
{
const QString filter(tr("Watermark files") + QLatin1String(" (*.vwm)"));
QString dir = QDir::homePath();
qDebug("Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr,
VAbstractApplication::VApp()->NativeFileDialog());
if (filePath.isEmpty())
{
return;
}
m_layout->LayoutSettings().SetWatermarkPath(filePath);
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_graphicsView->RefreshLayout();
ui->actionRemoveWatermark->setEnabled(true);
ui->actionEditCurrentWatermark->setEnabled(true);
if (not m_layout->LayoutSettings().WatermarkPath().isEmpty())
{
m_layoutWatcher->addPath(m_layout->LayoutSettings().WatermarkPath());
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::RemoveWatermark()
{
m_layout->LayoutSettings().SetWatermarkPath(QString());
LayoutWasSaved(false);
m_layout->TileFactory()->refreshTileInfos();
m_graphicsView->RefreshLayout();
ui->actionRemoveWatermark->setEnabled(false);
ui->actionEditCurrentWatermark->setEnabled(false);
if (not m_layout->LayoutSettings().WatermarkPath().isEmpty())
{
m_layoutWatcher->removePath(m_layout->LayoutSettings().WatermarkPath());
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
void VPMainWindow::AboutToShowDockMenu() void VPMainWindow::AboutToShowDockMenu()

View File

@ -55,6 +55,7 @@ class QFileSystemWatcher;
template <typename T> class QSharedPointer; template <typename T> class QSharedPointer;
class DialogPuzzlePreferences; class DialogPuzzlePreferences;
struct VPExportData; struct VPExportData;
class WatermarkWindow;
class VPMainWindow : public VAbstractMainWindow class VPMainWindow : public VAbstractMainWindow
{ {
@ -273,6 +274,11 @@ private slots:
void on_actionPrintTiledSheet_triggered(); void on_actionPrintTiledSheet_triggered();
void on_actionPrintPreviewTiledSheet_triggered(); void on_actionPrintPreviewTiledSheet_triggered();
void CreateWatermark();
void EditCurrentWatermark();
void LoadWatermark();
void RemoveWatermark();
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
void AboutToShowDockMenu(); void AboutToShowDockMenu();
#endif //defined(Q_OS_MAC) #endif //defined(Q_OS_MAC)
@ -318,6 +324,10 @@ private:
bool m_scaleConnected{true}; bool m_scaleConnected{true};
QList<QPointer<WatermarkWindow>> m_watermarkEditors{};
QFileSystemWatcher *m_watermarkWatcher{nullptr};
/** /**
* @brief InitMenuBar Inits the menu bar (File, Edit, Help ...) * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...)
*/ */
@ -451,6 +461,9 @@ private:
bool &firstPage); bool &firstPage);
void UpdateScaleConnection() const; void UpdateScaleConnection() const;
void OpenWatermark(const QString &path = QString());
void CleanWaterkmarkEditors();
}; };
#endif // VPMAINWINDOW_H #endif // VPMAINWINDOW_H

View File

@ -95,9 +95,20 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionExportLayout"/> <addaction name="actionExportLayout"/>
</widget> </widget>
<widget class="QMenu" name="menuWatermark">
<property name="title">
<string>Watermark</string>
</property>
<addaction name="actionWatermarkEditor"/>
<addaction name="actionEditCurrentWatermark"/>
<addaction name="separator"/>
<addaction name="actionLoadWatermark"/>
<addaction name="actionRemoveWatermark"/>
</widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuLayout"/> <addaction name="menuLayout"/>
<addaction name="menuSheet"/> <addaction name="menuSheet"/>
<addaction name="menuWatermark"/>
<addaction name="menuWindow"/> <addaction name="menuWindow"/>
<addaction name="menuHelp"/> <addaction name="menuHelp"/>
</widget> </widget>
@ -208,7 +219,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>2</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -1520,6 +1531,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBoxTilesShowWatermark">
<property name="toolTip">
<string>Show watermark preview</string>
</property>
<property name="text">
<string>Show watermark</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -2243,6 +2264,59 @@
<enum>QAction::ApplicationSpecificRole</enum> <enum>QAction::ApplicationSpecificRole</enum>
</property> </property>
</action> </action>
<action name="actionWatermarkEditor">
<property name="icon">
<iconset theme="document-new"/>
</property>
<property name="text">
<string>Editor</string>
</property>
<property name="toolTip">
<string>Create or edit a watermark</string>
</property>
<property name="menuRole">
<enum>QAction::ApplicationSpecificRole</enum>
</property>
</action>
<action name="actionEditCurrentWatermark">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit current</string>
</property>
<property name="menuRole">
<enum>QAction::ApplicationSpecificRole</enum>
</property>
</action>
<action name="actionLoadWatermark">
<property name="enabled">
<bool>true</bool>
</property>
<property name="icon">
<iconset theme="document-open"/>
</property>
<property name="text">
<string>Load</string>
</property>
<property name="menuRole">
<enum>QAction::ApplicationSpecificRole</enum>
</property>
</action>
<action name="actionRemoveWatermark">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="edit-delete"/>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="menuRole">
<enum>QAction::ApplicationSpecificRole</enum>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<tabstops> <tabstops>
@ -2270,8 +2344,8 @@
</resources> </resources>
<connections/> <connections/>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroupSheetOrientation"/>
<buttongroup name="buttonGroupRotationDirection"/> <buttongroup name="buttonGroupRotationDirection"/>
<buttongroup name="buttonGroupTileOrientation"/> <buttongroup name="buttonGroupTileOrientation"/>
<buttongroup name="buttonGroupSheetOrientation"/>
</buttongroups> </buttongroups>
</ui> </ui>

View File

@ -43,6 +43,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileMargins, (QLatin1Strin
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSheetIgnoreMargins, (QLatin1String("layout/sheetIgnoreMargins"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSheetIgnoreMargins, (QLatin1String("layout/sheetIgnoreMargins")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileIgnoreMargins, (QLatin1String("layout/tileIgnoreMargins"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileIgnoreMargins, (QLatin1String("layout/tileIgnoreMargins")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileShowTiles, (QLatin1String("layout/tileShowTiles"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileShowTiles, (QLatin1String("layout/tileShowTiles")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutTileShowWatermark, (QLatin1String("layout/tileShowWatermark")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutWarningPiecesSuperposition, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutWarningPiecesSuperposition,
(QLatin1String("layout/warningPiecesSuperposition"))) (QLatin1String("layout/warningPiecesSuperposition")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutStickyEdges, (QLatin1String("layout/stickyEdges"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutStickyEdges, (QLatin1String("layout/stickyEdges")))
@ -226,6 +227,18 @@ auto VPSettings::GetLayoutTileShowTiles() const -> bool
return value(*settingLayoutTileShowTiles, true).toBool(); return value(*settingLayoutTileShowTiles, true).toBool();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPSettings::SetLayoutTileShowWatermark(bool value)
{
setValue(*settingLayoutTileShowWatermark, value);
}
//---------------------------------------------------------------------------------------------------------------------
auto VPSettings::GetLayoutTileShowWatermark() const -> bool
{
return value(*settingLayoutTileShowWatermark, false).toBool();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSettings::SetLayoutWarningPiecesSuperposition(bool value) void VPSettings::SetLayoutWarningPiecesSuperposition(bool value)
{ {

View File

@ -78,6 +78,9 @@ public:
void SetLayoutTileShowTiles(bool value); void SetLayoutTileShowTiles(bool value);
auto GetLayoutTileShowTiles() const -> bool; auto GetLayoutTileShowTiles() const -> bool;
void SetLayoutTileShowWatermark(bool value);
auto GetLayoutTileShowWatermark() const -> bool;
void SetLayoutWarningPiecesSuperposition(bool value); void SetLayoutWarningPiecesSuperposition(bool value);
auto GetLayoutWarningPiecesSuperposition() const -> bool; auto GetLayoutWarningPiecesSuperposition() const -> bool;

View File

@ -12,8 +12,78 @@
namespace namespace
{ {
const QColor tileColor(180, 180, 180); const QColor tileColor(180, 180, 180);
//---------------------------------------------------------------------------------------------------------------------
auto Grayscale(QImage image) -> QImage
{
for (int ii = 0; ii < image.height(); ii++)
{
uchar* scan = image.scanLine(ii);
int depth = 4;
for (int jj = 0; jj < image.width(); jj++)
{
QRgb* rgbpixel = reinterpret_cast<QRgb*>(scan + jj * depth);
int gray = qGray(*rgbpixel);
*rgbpixel = QColor(gray, gray, gray, qAlpha(*rgbpixel)).rgba();
}
}
return image;
} }
//---------------------------------------------------------------------------------------------------------------------
auto WatermarkImageFromCache(const VWatermarkData &watermarkData, const QString &watermarkPath, qreal xScale,
qreal yScale, QString &error) -> QPixmap
{
const qreal opacity = watermarkData.opacity/100.;
QPixmap pixmap;
QString imagePath = AbsoluteMPath(watermarkPath, watermarkData.path);
QString imageCacheKey = QString("puzzle=path%1+opacity%2+rotation%3+grayscale%4+xscale%5+yxcale%6")
.arg(imagePath, QString::number(opacity), QString::number(watermarkData.imageRotation),
watermarkData.grayscale ? trueStr : falseStr ).arg(xScale).arg(yScale);
if (not QPixmapCache::find(imageCacheKey, &pixmap))
{
QImageReader imageReader(imagePath);
QImage watermark = imageReader.read();
if (watermark.isNull())
{
error = imageReader.errorString();
return pixmap;
}
if (watermarkData.grayscale)
{
watermark = Grayscale(watermark);
}
// Workaround for QGraphicsPixmapItem opacity problem.
// Opacity applied only if use a cached pixmap and only after first draw. First image always has opacity 1.
// Preparing an image manually allows to avoid the problem.
QSize scaledSize(qRound(watermark.width() * xScale), qRound(watermark.height() * yScale));
QImage tmp(scaledSize, watermark.format());
tmp = tmp.convertToFormat(QImage::Format_ARGB32);
tmp.fill(Qt::transparent);
QPainter p(&tmp);
p.setOpacity(opacity);
QTransform t;
t.translate(tmp.width()/2., tmp.height()/2.);
t.rotate(-watermarkData.imageRotation);
t.translate(-tmp.width()/2., -tmp.height()/2.);
p.setTransform(t);
p.drawImage(QRectF(QPointF(), scaledSize), watermark);
pixmap = QPixmap::fromImage(tmp);
QPixmapCache::insert(imageCacheKey, pixmap);
}
return pixmap;
}
} // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings): VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings):
m_layout(layout), m_layout(layout),
@ -45,6 +115,8 @@ void VPTileFactory::refreshTileInfos()
{ {
m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right(); m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right();
} }
m_watermarkData = layout->WatermarkData();
} }
} }
@ -229,6 +301,7 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
} }
DrawRuler(painter); DrawRuler(painter);
DrawWatermark(painter);
if(col < nbCol-1) if(col < nbCol-1)
{ {
@ -357,6 +430,12 @@ auto VPTileFactory::DrawingAreaWidth() const -> qreal
return m_drawingAreaWidth; return m_drawingAreaWidth;
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPTileFactory::WatermarkData() const -> const VWatermarkData &
{
return m_watermarkData;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawRuler(QPainter *painter) void VPTileFactory::DrawRuler(QPainter *painter)
{ {
@ -410,3 +489,143 @@ void VPTileFactory::DrawRuler(QPainter *painter)
painter->restore(); painter->restore();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawWatermark(QPainter *painter)
{
SCASSERT(painter != nullptr)
VPLayoutPtr layout = m_layout.toStrongRef();
if(layout.isNull())
{
return;
}
if (m_watermarkData.opacity > 0)
{
QRectF img(0, 0,
m_drawingAreaWidth - tileStripeWidth,
m_drawingAreaHeight - tileStripeWidth);
if (m_watermarkData.showImage && not m_watermarkData.path.isEmpty())
{
PaintWatermarkImage(painter, img, m_watermarkData,
layout->LayoutSettings().WatermarkPath(),
layout->LayoutSettings().HorizontalScale(),
layout->LayoutSettings().VerticalScale());
}
if (m_watermarkData.showText && not m_watermarkData.text.isEmpty())
{
PaintWatermarkText(painter, img, m_watermarkData,
layout->LayoutSettings().HorizontalScale(),
layout->LayoutSettings().VerticalScale());
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::PaintWatermarkText(QPainter *painter, const QRectF &img, const VWatermarkData &watermarkData,
qreal xScale, qreal yScale)
{
SCASSERT(painter != nullptr)
painter->save();
painter->setOpacity(watermarkData.opacity/100.);
QPen pen = painter->pen();
pen.setWidth(1);
pen.setColor(watermarkData.textColor);
pen.setStyle(Qt::SolidLine);
painter->setPen(pen);
painter->setBrush(watermarkData.textColor);
QTransform t;
t.translate(img.center().x(), img.center().y());
t.rotate(-watermarkData.textRotation);
t.translate(-img.center().x(), -img.center().y());
t.scale(xScale, yScale);
QPainterPath text;
text.addText(img.center(), watermarkData.font, watermarkData.text);
text = t.map(text);
QPointF center = img.center() - text.boundingRect().center();
t = QTransform();
t.translate(center.x(), center.y());
text = t.map(text);
painter->drawPath(text);
painter->restore();
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, const VWatermarkData &watermarkData,
const QString &watermarkPath, qreal xScale, qreal yScale)
{
SCASSERT(painter != nullptr)
auto BrokenImage = [img, watermarkData, watermarkPath]()
{
const qreal opacity = watermarkData.opacity/100.;
QPixmap watermark;
QString imagePath = QString("puzzle=path%1+opacity%2_broken")
.arg(AbsoluteMPath(watermarkPath, watermarkData.path), QString::number(opacity));
if (not QPixmapCache::find(imagePath, &watermark))
{
QScopedPointer<QSvgRenderer> svgRenderer(new QSvgRenderer());
QRect imageRect(0, 0, qRound(img.width()/4.), qRound(img.width()/4.));
watermark = QPixmap(imageRect.size());
watermark.fill(Qt::transparent);
QPainter imagePainter(&watermark);
imagePainter.setOpacity(opacity);
svgRenderer->load(QStringLiteral("://puzzleicon/svg/no_watermark_image.svg"));
svgRenderer->render(&imagePainter, imageRect);
QPixmapCache::insert(imagePath, watermark);
return watermark;
}
return watermark;
};
QPixmap watermark;
QFileInfo f(watermarkData.path);
if (f.suffix() == "png" || f.suffix() == "jpg" || f.suffix() == "jpeg" || f.suffix() == "bmp")
{
QString error;
watermark = WatermarkImageFromCache(watermarkData, watermarkPath, xScale, yScale, error);
if (watermark.isNull())
{
watermark = BrokenImage();
}
}
else
{
watermark = BrokenImage();
}
if (watermark.width() < img.width() && watermark.height() < img.height())
{
QRect imagePosition(0, 0, watermark.width(), watermark.height());
imagePosition.translate(img.center().toPoint() - imagePosition.center());
painter->drawPixmap(imagePosition, watermark);
}
else
{
painter->drawPixmap(img.toRect(), watermark);
}
}

View File

@ -33,6 +33,7 @@
#include <QObject> #include <QObject>
#include "layout/vplayout.h" #include "layout/vplayout.h"
#include "../ifc/ifcdef.h"
class QGraphicsScene; class QGraphicsScene;
class VCommonSettings; class VCommonSettings;
@ -90,6 +91,13 @@ public:
*/ */
static constexpr qreal tileStripeWidth = UnitConvertor(1, Unit::Cm, Unit::Px); static constexpr qreal tileStripeWidth = UnitConvertor(1, Unit::Cm, Unit::Px);
auto WatermarkData() const -> const VWatermarkData &;
static void PaintWatermarkText(QPainter *painter, const QRectF &img, const VWatermarkData &watermarkData,
qreal xScale = 1.0, qreal yScale = 1.0);
static void PaintWatermarkImage(QPainter *painter, const QRectF &img, const VWatermarkData &watermarkData,
const QString &watermarkPath, qreal xScale = 1.0, qreal yScale = 1.0);
private: private:
Q_DISABLE_COPY(VPTileFactory) Q_DISABLE_COPY(VPTileFactory)
@ -106,8 +114,10 @@ private:
*/ */
qreal m_drawingAreaWidth{0}; qreal m_drawingAreaWidth{0};
void DrawRuler(QPainter *painter); VWatermarkData m_watermarkData{};
void DrawRuler(QPainter *painter);
void DrawWatermark(QPainter *painter);
}; };
#endif // VPTILEFACTORY_H #endif // VPTILEFACTORY_H

View File

@ -243,7 +243,8 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout)
ML::TagDescription, // 2 ML::TagDescription, // 2
ML::TagControl, // 3 ML::TagControl, // 3
ML::TagTiles, // 4 ML::TagTiles, // 4
ML::TagScale // 5 ML::TagScale, // 5
ML::TagWatermark // 6
}; };
while (readNextStartElement()) while (readNextStartElement())
@ -276,6 +277,10 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout)
qDebug("read scale"); qDebug("read scale");
ReadScale(layout); ReadScale(layout);
break; break;
case 6: // watermark
qDebug("read watermark");
ReadWatermark(layout);
break;
default: default:
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement(); skipCurrentElement();
@ -818,6 +823,16 @@ auto VPLayoutFileReader::ReadLabelLine() -> TextLine
return line; return line;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadWatermark(const VPLayoutPtr &layout)
{
AssertRootTag(ML::TagWatermark);
QXmlStreamAttributes attribs = attributes();
layout->LayoutSettings().SetShowWatermark(ReadAttributeBool(attribs, ML::AttrShowPreview, falseStr));
layout->LayoutSettings().SetWatermarkPath(readElementText());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadLayoutMargins(const VPLayoutPtr &layout) void VPLayoutFileReader::ReadLayoutMargins(const VPLayoutPtr &layout)
{ {

View File

@ -75,6 +75,7 @@ private:
void ReadPatternLabel(const VPPiecePtr &piece); void ReadPatternLabel(const VPPiecePtr &piece);
auto ReadLabelLines() -> VTextManager; auto ReadLabelLines() -> VTextManager;
auto ReadLabelLine() -> TextLine; auto ReadLabelLine() -> TextLine;
void ReadWatermark(const VPLayoutPtr &layout);
void ReadLayoutMargins(const VPLayoutPtr &layout); void ReadLayoutMargins(const VPLayoutPtr &layout);
void ReadSheetMargins(const VPSheetPtr &sheet); void ReadSheetMargins(const VPSheetPtr &sheet);

View File

@ -184,6 +184,12 @@ void VPLayoutFileWriter::WriteLayoutProperties(const VPLayoutPtr &layout)
SetAttribute(ML::AttrYScale, layout->LayoutSettings().VerticalScale()); SetAttribute(ML::AttrYScale, layout->LayoutSettings().VerticalScale());
writeEndElement(); // scale writeEndElement(); // scale
writeStartElement(ML::TagWatermark);
SetAttributeOrRemoveIf<bool>(ML::AttrShowPreview, layout->LayoutSettings().GetShowWatermark(),
[](bool show){return not show;});
writeCharacters(layout->LayoutSettings().WatermarkPath());
writeEndElement(); // watermark
writeEndElement(); // properties writeEndElement(); // properties
} }

View File

@ -59,6 +59,7 @@ const QString TagPatternLabel = QStringLiteral("patternLabel");
const QString TagLines = QStringLiteral("lines"); const QString TagLines = QStringLiteral("lines");
const QString TagLine = QStringLiteral("line"); const QString TagLine = QStringLiteral("line");
const QString TagScale = QStringLiteral("scale"); const QString TagScale = QStringLiteral("scale");
const QString TagWatermark = QStringLiteral("watermark");
const QString AttrVersion = QStringLiteral("version"); const QString AttrVersion = QStringLiteral("version");
const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition"); const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition");
@ -102,6 +103,7 @@ const QString AttrGrainlineType = QStringLiteral("grainlineType");
const QString AttrXScale = QStringLiteral("xScale"); const QString AttrXScale = QStringLiteral("xScale");
const QString AttrYScale = QStringLiteral("yScale"); const QString AttrYScale = QStringLiteral("yScale");
const QString AttrIgnoreMargins = QStringLiteral("ignoreMargins"); const QString AttrIgnoreMargins = QStringLiteral("ignoreMargins");
const QString AttrShowPreview = QStringLiteral("showPreview");
const QString atFrontStr = QStringLiteral("atFront"); const QString atFrontStr = QStringLiteral("atFront");
const QString atRearStr = QStringLiteral("atRear"); const QString atRearStr = QStringLiteral("atRear");

View File

@ -64,6 +64,7 @@ extern const QString TagPatternLabel;
extern const QString TagLines; extern const QString TagLines;
extern const QString TagLine; extern const QString TagLine;
extern const QString TagScale; extern const QString TagScale;
extern const QString TagWatermark;
extern const QString AttrVersion; extern const QString AttrVersion;
extern const QString AttrWarningSuperposition; extern const QString AttrWarningSuperposition;
@ -107,6 +108,7 @@ extern const QString AttrGrainlineType;
extern const QString AttrXScale; extern const QString AttrXScale;
extern const QString AttrYScale; extern const QString AttrYScale;
extern const QString AttrIgnoreMargins; extern const QString AttrIgnoreMargins;
extern const QString AttrShowPreview;
extern const QString atFrontStr; extern const QString atFrontStr;
extern const QString atRearStr; extern const QString atRearStr;

View File

@ -65,7 +65,7 @@
#include "../qmuparser/qmuparsererror.h" #include "../qmuparser/qmuparsererror.h"
#include "../vtools/dialogs/support/dialogeditlabel.h" #include "../vtools/dialogs/support/dialogeditlabel.h"
#include "../vformat/vpatternrecipe.h" #include "../vformat/vpatternrecipe.h"
#include "watermarkwindow.h" #include "../vlayout/dialogs/watermarkwindow.h"
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#include "../vlayout/vlayoutexporter.h" #include "../vlayout/vlayoutexporter.h"
#include "../vwidgets/vgraphicssimpletextitem.h" #include "../vwidgets/vgraphicssimpletextitem.h"

View File

@ -1119,7 +1119,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-53</y> <y>0</y>
<width>126</width> <width>126</width>
<height>237</height> <height>237</height>
</rect> </rect>
@ -1713,7 +1713,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1100</width> <width>1100</width>
<height>21</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -3017,7 +3017,7 @@
</action> </action>
<action name="actionLoadWatermark"> <action name="actionLoadWatermark">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="document-open"> <iconset theme="document-open">

View File

@ -10,8 +10,7 @@ include(core/core.pri)
SOURCES += \ SOURCES += \
$$PWD/main.cpp \ $$PWD/main.cpp \
$$PWD/mainwindow.cpp \ $$PWD/mainwindow.cpp \
$$PWD/mainwindowsnogui.cpp \ $$PWD/mainwindowsnogui.cpp
$$PWD/watermarkwindow.cpp
*msvc*:SOURCES += $$PWD/stable.cpp *msvc*:SOURCES += $$PWD/stable.cpp
@ -20,10 +19,8 @@ HEADERS += \
$$PWD/mainwindow.h \ $$PWD/mainwindow.h \
$$PWD/stable.h \ $$PWD/stable.h \
$$PWD/version.h \ $$PWD/version.h \
$$PWD/mainwindowsnogui.h \ $$PWD/mainwindowsnogui.h
$$PWD/watermarkwindow.h
# Main forms # Main forms
FORMS += \ FORMS += \
$$PWD/mainwindow.ui \ $$PWD/mainwindow.ui
$$PWD/watermarkwindow.ui

View File

@ -588,6 +588,15 @@ DEPENDPATH += $$PWD/../../libs/vtools
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a
# VLayout static library (depend on IFC, VGeometry)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout
INCLUDEPATH += $$PWD/../../libs/vlayout
DEPENDPATH += $$PWD/../../libs/vlayout
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a
#VWidgets static library #VWidgets static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets
@ -606,7 +615,7 @@ DEPENDPATH += $$PWD/../../libs/vformat
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/vformat.lib win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/vformat.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/libvformat.a else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/libvformat.a
#VPatternDB static library (depend on vgeometry, vmisc, VLayout) #VPatternDB static library (depend on vgeometry, vmisc)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vpatterndb/$${DESTDIR} -lvpatterndb unix|win32: LIBS += -L$$OUT_PWD/../../libs/vpatterndb/$${DESTDIR} -lvpatterndb
INCLUDEPATH += $$PWD/../../libs/vpatterndb INCLUDEPATH += $$PWD/../../libs/vpatterndb
@ -615,15 +624,6 @@ DEPENDPATH += $$PWD/../../libs/vpatterndb
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/vpatterndb.lib win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/vpatterndb.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/libvpatterndb.a else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/libvpatterndb.a
# VLayout static library (depend on IFC, VGeometry)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout
INCLUDEPATH += $$PWD/../../libs/vlayout
DEPENDPATH += $$PWD/../../libs/vlayout
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a
# VGeometry static library (depend on ifc) # VGeometry static library (depend on ifc)
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/ -lvgeometry unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/ -lvgeometry

View File

@ -966,7 +966,7 @@ void VPattern::ParseDetailInternals(const QDomElement &domElement, VPiece &detai
if (version == 1) if (version == 1)
{ {
// TODO. Delete if minimal supported version is 0.4.0 // TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 4, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 4, 0),
"Time to refactor the code."); "Time to refactor the code.");
const bool closed = GetParametrUInt(domElement, AttrClosed, QChar('1')); const bool closed = GetParametrUInt(domElement, AttrClosed, QChar('1'));
const qreal width = GetParametrDouble(domElement, AttrWidth, QStringLiteral("0.0")); const qreal width = GetParametrDouble(domElement, AttrWidth, QStringLiteral("0.0"));

View File

@ -214,7 +214,7 @@ private:
void ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
// TODO. Delete if minimal supported version is 0.2.7 // TODO. Delete if minimal supported version is 0.2.7
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 2, 7), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 2, 7),
"Time to refactor the code."); "Time to refactor the code.");
void ParseOldToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseOldToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
@ -222,7 +222,7 @@ private:
void ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
// TODO. Delete if minimal supported version is 0.2.7 // TODO. Delete if minimal supported version is 0.2.7
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 2, 7), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 2, 7),
"Time to refactor the code."); "Time to refactor the code.");
void ParseOldToolSplinePath(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseOldToolSplinePath(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);

View File

@ -35,6 +35,7 @@
# include <qt_windows.h> # include <qt_windows.h>
#endif /*Q_OS_WIN*/ #endif /*Q_OS_WIN*/
#include <QColor>
#include <QFont> #include <QFont>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@ -262,6 +263,8 @@ struct VWatermarkData
QString path{}; QString path{};
int imageRotation{0}; int imageRotation{0};
bool grayscale{false}; bool grayscale{false};
bool invalidFile{false};
QColor textColor{Qt::black};
}; };
QT_WARNING_POP QT_WARNING_POP

View File

@ -82,6 +82,7 @@
<file>schema/individual_measurements/v0.5.1.xsd</file> <file>schema/individual_measurements/v0.5.1.xsd</file>
<file>schema/label_template/v1.0.0.xsd</file> <file>schema/label_template/v1.0.0.xsd</file>
<file>schema/watermark/v1.0.0.xsd</file> <file>schema/watermark/v1.0.0.xsd</file>
<file>schema/watermark/v1.1.0.xsd</file>
<file>schema/layout/v0.1.0.xsd</file> <file>schema/layout/v0.1.0.xsd</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -46,6 +46,15 @@
<xs:attribute type="LayoutScale" name="yScale"/> <xs:attribute type="LayoutScale" name="yScale"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="watermark">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:boolean" name="showPreview" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>

View File

@ -0,0 +1,54 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="watermark">
<xs:complexType>
<xs:sequence>
<xs:element type="formatVersion" name="version"/>
<xs:element name="text">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:boolean" name="show"/>
<xs:attribute type="xs:string" name="text"/>
<xs:attribute type="rotationType" name="rotation"/>
<xs:attribute type="xs:string" name="font"/>
<xs:attribute type="xs:string" name="color"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="image">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:boolean" name="show"/>
<xs:attribute type="xs:string" name="path"/>
<xs:attribute type="rotationType" name="rotation"/>
<xs:attribute type="xs:boolean" name="grayscale"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="opacityType" name="opacity"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="formatVersion">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="opacityType">
<xs:restriction base="xs:unsignedInt">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="rotationType">
<xs:restriction base="xs:int">
<xs:minInclusive value="-360"/>
<xs:maxInclusive value="360"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -27,6 +27,8 @@
*************************************************************************/ *************************************************************************/
#include "vwatermarkconverter.h" #include "vwatermarkconverter.h"
#include <QtGlobal>
/* /*
* Version rules: * Version rules:
* 1. Version have three parts "major.minor.patch"; * 1. Version have three parts "major.minor.patch";
@ -36,8 +38,8 @@
*/ */
const QString VWatermarkConverter::WatermarkMinVerStr = QStringLiteral("1.0.0"); const QString VWatermarkConverter::WatermarkMinVerStr = QStringLiteral("1.0.0");
const QString VWatermarkConverter::WatermarkMaxVerStr = QStringLiteral("1.0.0"); const QString VWatermarkConverter::WatermarkMaxVerStr = QStringLiteral("1.1.0");
const QString VWatermarkConverter::CurrentSchema = QStringLiteral("://schema/watermark/v1.0.0.xsd"); const QString VWatermarkConverter::CurrentSchema = QStringLiteral("://schema/watermark/v1.1.0.xsd");
//VWatermarkConverter::WatermarkMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VWatermarkConverter::WatermarkMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VWatermarkConverter::WatermarkMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VWatermarkConverter::WatermarkMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
@ -77,15 +79,18 @@ QString VWatermarkConverter::MaxVerStr() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VWatermarkConverter::XSDSchema(int ver) const QString VWatermarkConverter::XSDSchema(int ver) const
{ {
switch (ver) QHash <int, QString> schemas =
{ {
case (0x010000): std::make_pair(FormatVersion(1, 0, 0), QStringLiteral("://schema/watermark/v1.0.0.xsd")),
return CurrentSchema; std::make_pair(FormatVersion(1, 1, 0), CurrentSchema)
default: };
InvalidVersion(ver);
break; if (schemas.contains(ver))
{
return schemas.value(ver);
} }
return QString();//unreachable code
InvalidVersion(ver);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -93,11 +98,14 @@ void VWatermarkConverter::ApplyPatches()
{ {
switch (m_ver) switch (m_ver)
{ {
case (0x010000): case (FormatVersion(1, 0, 0)):
ToV1_1_0();
ValidateXML(XSDSchema(FormatVersion(1, 1, 0)));
Q_FALLTHROUGH();
case (FormatVersion(1, 1, 0)):
break; break;
default: default:
InvalidVersion(m_ver); InvalidVersion(m_ver);
break;
} }
} }
@ -107,3 +115,14 @@ void VWatermarkConverter::DowngradeToCurrentMaxVersion()
SetVersion(WatermarkMaxVerStr); SetVersion(WatermarkMaxVerStr);
Save(); Save();
} }
//---------------------------------------------------------------------------------------------------------------------
void VWatermarkConverter::ToV1_1_0()
{
// TODO. Delete if minimal supported version is 1.1.0
Q_STATIC_ASSERT_X(VWatermarkConverter::WatermarkMinVer < FormatVersion(1, 1, 0),
"Time to refactor the code.");
SetVersion(QStringLiteral("1.1.0"));
Save();
}

View File

@ -39,7 +39,7 @@ public:
static const QString WatermarkMaxVerStr; static const QString WatermarkMaxVerStr;
static const QString CurrentSchema; static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int WatermarkMinVer = FormatVersion(1, 0, 0); static Q_DECL_CONSTEXPR const int WatermarkMinVer = FormatVersion(1, 0, 0);
static Q_DECL_CONSTEXPR const int WatermarkMaxVer = FormatVersion(1, 0, 0); static Q_DECL_CONSTEXPR const int WatermarkMaxVer = FormatVersion(1, 1, 0);
protected: protected:
virtual int MinVer() const override; virtual int MinVer() const override;
@ -57,6 +57,8 @@ protected:
private: private:
Q_DISABLE_COPY(VWatermarkConverter) Q_DISABLE_COPY(VWatermarkConverter)
static const QString WatermarkMinVerStr; static const QString WatermarkMinVerStr;
void ToV1_1_0();
}; };
#endif // VWATERMARKCONVERTER_H #endif // VWATERMARKCONVERTER_H

View File

@ -28,6 +28,7 @@
#include "vwatermark.h" #include "vwatermark.h"
#include "../vmisc/projectversion.h" #include "../vmisc/projectversion.h"
#include "../ifc/xml/vwatermarkconverter.h"
const QString VWatermark::TagWatermark = QStringLiteral("watermark"); const QString VWatermark::TagWatermark = QStringLiteral("watermark");
const QString VWatermark::TagText = QStringLiteral("text"); const QString VWatermark::TagText = QStringLiteral("text");
@ -61,7 +62,7 @@ void VWatermark::CreateEmptyWatermark()
QDomElement wElement = this->createElement(TagWatermark); QDomElement wElement = this->createElement(TagWatermark);
wElement.appendChild(createComment(FileComment())); wElement.appendChild(createComment(FileComment()));
wElement.appendChild(CreateElementWithText(TagVersion, "1.0.0" /*VWatermarkConverter::WatermarkMaxVerStr*/)); wElement.appendChild(CreateElementWithText(TagVersion, VWatermarkConverter::WatermarkMaxVerStr));
wElement.appendChild(createElement(TagText)); wElement.appendChild(createElement(TagText));
wElement.appendChild(createElement(TagImage)); wElement.appendChild(createElement(TagImage));
@ -102,6 +103,12 @@ VWatermarkData VWatermark::GetWatermark() const
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));
QColor color(GetParametrString(text, AttrColor, QColor(Qt::black).name()));
if (not color.isValid())
{
color = Qt::black;
}
data.textColor = color;
} }
QDomElement image = rootElement.firstChildElement(TagImage); QDomElement image = rootElement.firstChildElement(TagImage);
@ -136,6 +143,7 @@ void VWatermark::SetWatermark(const VWatermarkData &data)
[](int textRotation){return textRotation == 0;}); [](int textRotation){return textRotation == 0;});
SetAttributeOrRemoveIf<QString>(text, AttrFont, data.font.toString(), SetAttributeOrRemoveIf<QString>(text, AttrFont, data.font.toString(),
[](const QString &fontString){return fontString.isEmpty();}); [](const QString &fontString){return fontString.isEmpty();});
SetAttribute(text, AttrColor, data.textColor.name());
} }
QDomElement image = rootElement.firstChildElement(TagImage); QDomElement image = rootElement.firstChildElement(TagImage);

View File

@ -3,11 +3,14 @@
HEADERS += \ HEADERS += \
$$PWD/dialoglayoutscale.h \ $$PWD/dialoglayoutscale.h \
$$PWD/vabstractlayoutdialog.h $$PWD/vabstractlayoutdialog.h \
$$PWD/watermarkwindow.h
SOURCES += \ SOURCES += \
$$PWD/dialoglayoutscale.cpp \ $$PWD/dialoglayoutscale.cpp \
$$PWD/vabstractlayoutdialog.cpp $$PWD/vabstractlayoutdialog.cpp \
$$PWD/watermarkwindow.cpp
FORMS += \ FORMS += \
$$PWD/dialoglayoutscale.ui $$PWD/dialoglayoutscale.ui \
$$PWD/watermarkwindow.ui

View File

@ -34,10 +34,11 @@
#include <QFontDialog> #include <QFontDialog>
#include <QFuture> #include <QFuture>
#include <QMessageBox> #include <QMessageBox>
#include <QStyle>
#include <QtConcurrent> #include <QtConcurrent>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "core/vapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vpropertyexplorer/checkablemessagebox.h" #include "../vpropertyexplorer/checkablemessagebox.h"
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "../ifc/xml/vwatermarkconverter.h" #include "../ifc/xml/vwatermarkconverter.h"
@ -109,6 +110,31 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) :
connect(ui->groupBoxWatermarkText, &QGroupBox::toggled, this, [this](){WatermarkChangesWereSaved(false);}); connect(ui->groupBoxWatermarkText, &QGroupBox::toggled, this, [this](){WatermarkChangesWereSaved(false);});
connect(ui->groupBoxWatermarkImage, &QGroupBox::toggled, this, [this](){WatermarkChangesWereSaved(false);}); connect(ui->groupBoxWatermarkImage, &QGroupBox::toggled, this, [this](){WatermarkChangesWereSaved(false);});
ui->pushButtonColorPicker->insertColor(Qt::black, tr("Black", "color"));
ui->pushButtonColorPicker->insertColor(Qt::red, tr("Red", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkRed, tr("Dark red", "color"));
ui->pushButtonColorPicker->insertColor(Qt::green, tr("Green", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkGreen, tr("Dark green", "color"));
ui->pushButtonColorPicker->insertColor(Qt::blue, tr("Blue", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkBlue, tr("Dark blue", "color"));
ui->pushButtonColorPicker->insertColor(Qt::cyan, tr("Cyan", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkCyan, tr("Dark cyan", "color"));
ui->pushButtonColorPicker->insertColor(Qt::magenta, tr("Magenta", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkMagenta, tr("Dark magenta", "color"));
ui->pushButtonColorPicker->insertColor(Qt::yellow, tr("Yellow", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkYellow, tr("Dark yellow", "color"));
ui->pushButtonColorPicker->insertColor(Qt::gray, tr("Gray", "color"));
ui->pushButtonColorPicker->insertColor(Qt::darkGray, tr("Dark gray", "color"));
ui->pushButtonColorPicker->insertColor(Qt::lightGray, tr("Light gray", "color"));
QVector<QColor> colors = VAbstractApplication::VApp()->Settings()->GetWatermarkCustomColors();
for (const auto& color : colors)
{
ui->pushButtonColorPicker->insertColor(color);
}
connect(ui->pushButtonColorPicker, &QtColorPicker::colorChanged, this, [this](){WatermarkChangesWereSaved(false);});
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -242,7 +268,7 @@ void WatermarkWindow::showEvent(QShowEvent *event)
} }
// do your init stuff here // do your init stuff here
QSize sz = VAbstractValApplication::VApp()->ValentinaSettings()->GetWatermarkEditorSize(); QSize sz = VAbstractApplication::VApp()->Settings()->GetWatermarkEditorSize();
if (sz.isEmpty() == false) if (sz.isEmpty() == false)
{ {
resize(sz); resize(sz);
@ -259,7 +285,7 @@ void WatermarkWindow::resizeEvent(QResizeEvent *event)
// window creating, which would // window creating, which would
if (m_isInitialized) if (m_isInitialized)
{ {
VAbstractValApplication::VApp()->ValentinaSettings()->SetWatermarkEditorSize(size()); VAbstractApplication::VApp()->Settings()->SetWatermarkEditorSize(size());
} }
QMainWindow::resizeEvent(event); QMainWindow::resizeEvent(event);
} }
@ -584,7 +610,7 @@ bool WatermarkWindow::ContinueFormatRewrite(const QString &currentFormatVersion,
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool WatermarkWindow::SaveWatermark(const QString &fileName, QString &error) auto WatermarkWindow::SaveWatermark(const QString &fileName, QString &error) -> bool
{ {
m_data.opacity = ui->spinBoxOpacity->value(); m_data.opacity = ui->spinBoxOpacity->value();
m_data.showText = ui->groupBoxWatermarkText->isChecked(); m_data.showText = ui->groupBoxWatermarkText->isChecked();
@ -594,6 +620,7 @@ bool WatermarkWindow::SaveWatermark(const QString &fileName, QString &error)
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();
m_data.textColor = ui->pushButtonColorPicker->currentColor();
VWatermark doc; VWatermark doc;
doc.CreateEmptyWatermark(); doc.CreateEmptyWatermark();
@ -605,6 +632,8 @@ bool WatermarkWindow::SaveWatermark(const QString &fileName, QString &error)
SetCurrentFile(fileName); SetCurrentFile(fileName);
statusBar()->showMessage(tr("File saved"), 5000); statusBar()->showMessage(tr("File saved"), 5000);
WatermarkChangesWereSaved(result); WatermarkChangesWereSaved(result);
VAbstractApplication::VApp()->Settings()->SetWatermarkCustomColors(ui->pushButtonColorPicker->CustomColors());
} }
return result; return result;
} }
@ -717,6 +746,10 @@ void WatermarkWindow::ShowWatermark()
ui->checkBoxGrayColor->blockSignals(true); ui->checkBoxGrayColor->blockSignals(true);
ui->checkBoxGrayColor->setChecked(m_data.grayscale); ui->checkBoxGrayColor->setChecked(m_data.grayscale);
ui->checkBoxGrayColor->blockSignals(false); ui->checkBoxGrayColor->blockSignals(false);
ui->pushButtonColorPicker->blockSignals(true);
ui->pushButtonColorPicker->setCurrentColor(m_data.textColor);
ui->pushButtonColorPicker->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -14,7 +14,7 @@
<string>Watermark</string> <string>Watermark</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc"> <iconset resource="../../vmisc/share/resources/icon.qrc">
<normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset> <normaloff>:/icon/64x64/icon64x64.png</normaloff>:/icon/64x64/icon64x64.png</iconset>
</property> </property>
<property name="toolButtonStyle"> <property name="toolButtonStyle">
@ -32,8 +32,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>512</width> <width>498</width>
<height>344</height> <height>367</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -132,6 +132,9 @@
<property name="suffix"> <property name="suffix">
<string notr="true">°</string> <string notr="true">°</string>
</property> </property>
<property name="minimum">
<number>-360</number>
</property>
<property name="maximum"> <property name="maximum">
<number>360</number> <number>360</number>
</property> </property>
@ -171,7 +174,7 @@
<string notr="true">...</string> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../libs/vmisc/share/resources/icon.qrc"> <iconset resource="../../vmisc/share/resources/icon.qrc">
<normaloff>:/icon/24x24/font_preferences.png</normaloff>:/icon/24x24/font_preferences.png</iconset> <normaloff>:/icon/24x24/font_preferences.png</normaloff>:/icon/24x24/font_preferences.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -184,6 +187,20 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="1">
<widget class="QtColorPicker" name="pushButtonColorPicker">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -245,8 +262,11 @@
<property name="suffix"> <property name="suffix">
<string notr="true">°</string> <string notr="true">°</string>
</property> </property>
<property name="minimum">
<number>-360</number>
</property>
<property name="maximum"> <property name="maximum">
<number>100</number> <number>360</number>
</property> </property>
</widget> </widget>
</item> </item>
@ -365,8 +385,15 @@
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QtColorPicker</class>
<extends>QPushButton</extends>
<header>qtcolorpicker.h</header>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../../libs/vmisc/share/resources/icon.qrc"/> <include location="../../vmisc/share/resources/icon.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -95,7 +95,6 @@ QPixmap WatermarkImageFromCache(const VWatermarkData &watermarkData, const QStri
if (watermarkData.grayscale) if (watermarkData.grayscale)
{ {
watermark = Grayscale(watermark); watermark = Grayscale(watermark);
watermark.save("/home/dismine/grayscale.png", "PNG");
} }
// Workaround for QGraphicsPixmapItem opacity problem. // Workaround for QGraphicsPixmapItem opacity problem.
@ -272,6 +271,11 @@ QVector<QGraphicsItem *> VPoster::TextWatermark(QGraphicsItem *parent, const Pos
QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(watermarkData.text, parent); QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(watermarkData.text, parent);
text->setFont(watermarkData.font); text->setFont(watermarkData.font);
QPen pen = text->pen();
pen.setColor(watermarkData.textColor);
text->setPen(pen);
text->setOpacity(watermarkData.opacity/100.); text->setOpacity(watermarkData.opacity/100.);
text->setTransformOriginPoint(text->boundingRect().center()); text->setTransformOriginPoint(text->boundingRect().center());
text->setRotation(-watermarkData.textRotation); text->setRotation(-watermarkData.textRotation);

View File

@ -42,6 +42,7 @@
#include <QFont> #include <QFont>
#include <QGlobalStatic> #include <QGlobalStatic>
#include <QMarginsF> #include <QMarginsF>
#include <QColor>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
@ -141,6 +142,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingAcceleration, (QLatin1S
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkEditorSize, (QLatin1String("watermarkEditorSize")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkCustomColors, (QLatin1String("watermarkCustomColors")))
// Reading settings file is very expensive, cache curve approximation to speed up getting value // Reading settings file is very expensive, cache curve approximation to speed up getting value
qreal curveApproximationCached = -1; qreal curveApproximationCached = -1;
Q_GLOBAL_STATIC(QString, localeCached) Q_GLOBAL_STATIC(QString, localeCached)
@ -1431,3 +1435,63 @@ void VCommonSettings::SetTiledPDFOrientation(PageOrientation value)
{ {
setValue(*settingTiledPDFOrientation, static_cast<bool> (value)); setValue(*settingTiledPDFOrientation, static_cast<bool> (value));
} }
//---------------------------------------------------------------------------------------------------------------------
QSize VCommonSettings::GetWatermarkEditorSize() const
{
return value(*settingWatermarkEditorSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetWatermarkEditorSize(const QSize &sz)
{
setValue(*settingWatermarkEditorSize, sz);
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QColor> VCommonSettings::GetWatermarkCustomColors() const
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
QStringList colors = settings.value(*settingPatternGraphicalOutput, 1).toStringList();
QVector<QColor> customColors;
customColors.reserve(colors.size());
for (auto color : colors)
{
QColor c(color);
if (c.isValid())
{
customColors.append(c);
}
}
if (customColors.count() > 7)
{
customColors.remove(0, customColors.count() - 7);
}
return customColors;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetWatermarkCustomColors(QVector<QColor> colors)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
if (colors.count() > 7)
{
colors.remove(0, colors.count() - 7);
}
QStringList customColors;
customColors.reserve(colors.size());
for (auto color : colors)
{
customColors.append(color.name());
}
settings.setValue(*settingWatermarkCustomColors, customColors);
settings.sync();
}

View File

@ -277,6 +277,12 @@ public:
bool GetGraphicalOutput() const; bool GetGraphicalOutput() const;
void SetGraphicalOutput(const bool &value); void SetGraphicalOutput(const bool &value);
auto GetWatermarkEditorSize() const -> QSize;
void SetWatermarkEditorSize(const QSize& sz);
auto GetWatermarkCustomColors() const -> QVector<QColor>;
void SetWatermarkCustomColors(QVector<QColor> colors);
protected: protected:
template <typename T> template <typename T>

View File

@ -93,8 +93,6 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetToolOptionsActive,
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetPatternMessagesActive, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetPatternMessagesActive,
(QLatin1String("dockWidget/patternMessagesActive"))) (QLatin1String("dockWidget/patternMessagesActive")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternMessagesFontSize, (QLatin1String("font/patternMessagesSize"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternMessagesFontSize, (QLatin1String("font/patternMessagesSize")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingWatermarkEditorSize, (QLatin1String("watermarkEditorSize")))
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -619,18 +617,6 @@ void VValentinaSettings::SetAutoRefreshPatternMessage(bool value)
setValue(*settingAutoRefreshPatternMessage, value); setValue(*settingAutoRefreshPatternMessage, value);
} }
//---------------------------------------------------------------------------------------------------------------------
QSize VValentinaSettings::GetWatermarkEditorSize() const
{
return value(*settingWatermarkEditorSize, QSize(0, 0)).toSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VValentinaSettings::SetWatermarkEditorSize(const QSize &sz)
{
setValue(*settingWatermarkEditorSize, sz);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VValentinaSettings::GetToolPanelScaling() const bool VValentinaSettings::GetToolPanelScaling() const
{ {

View File

@ -161,9 +161,6 @@ public:
bool GetAutoRefreshPatternMessage() const; bool GetAutoRefreshPatternMessage() const;
void SetAutoRefreshPatternMessage(bool value); void SetAutoRefreshPatternMessage(bool value);
QSize GetWatermarkEditorSize() const;
void SetWatermarkEditorSize(const QSize& sz);
bool GetToolPanelScaling() const; bool GetToolPanelScaling() const;
void SetToolPanelScaling(const bool &value); void SetToolPanelScaling(const bool &value);

View File

@ -1021,7 +1021,7 @@ void VToolSeamAllowance::RefreshDataInFile()
// Refresh only parts that we possibly need to update // Refresh only parts that we possibly need to update
{ {
// TODO. Delete if minimal supported version is 0.4.0 // TODO. Delete if minimal supported version is 0.4.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 4, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 4, 0),
"Time to refactor the code."); "Time to refactor the code.");
const uint version = doc->GetParametrUInt(domElement, AttrVersion, QChar('1')); const uint version = doc->GetParametrUInt(domElement, AttrVersion, QChar('1'));

View File

@ -1339,7 +1339,7 @@ void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qrea
{ {
// This check need for backward compatibility // This check need for backward compatibility
// Remove check and "else" part if min version is 0.3.2 // Remove check and "else" part if min version is 0.3.2
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 3, 2), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 3, 2),
"Time to refactor the code."); "Time to refactor the code.");
if (children.size() == countNodeD1 + countNodeD2-1) if (children.size() == countNodeD1 + countNodeD2-1)
{ {
@ -1396,7 +1396,7 @@ void UpdateUnitedNodes(const VToolUnionDetailsInitData &initData, qreal dx, qrea
QVector<quint32> FixChildren(QVector<quint32> records, QVector<quint32> children, VContainer *data) QVector<quint32> FixChildren(QVector<quint32> records, QVector<quint32> children, VContainer *data)
{ {
// TODO. Delete if minimal supported version is 0.7.0 // TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 7, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 7, 0),
"Time to refactor the code."); "Time to refactor the code.");
SCASSERT(data != nullptr) SCASSERT(data != nullptr)
@ -1434,7 +1434,7 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx
if (initData.version == 1) if (initData.version == 1)
{ {
// TODO. Delete if minimal supported version is 0.7.0 // TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 7, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 7, 0),
"Time to refactor the code."); "Time to refactor the code.");
// Fixing bug in first version of the tool. Mostly for backward compatibility. // Fixing bug in first version of the tool. Mostly for backward compatibility.
children = FixChildren(records, children, initData.data); children = FixChildren(records, children, initData.data);
@ -1447,7 +1447,7 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx
if (initData.version == 1) if (initData.version == 1)
{ {
// TODO. Delete if minimal supported version is 0.7.0 // TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 7, 0), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 7, 0),
"Time to refactor the code."); "Time to refactor the code.");
const quint32 updatedId = TakeNextId(children); const quint32 updatedId = TakeNextId(children);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,110 @@
/****************************************************************************
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of a Qt Solutions component.
**
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Solutions Commercial License Agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** Please note Third Party Software included with Qt Solutions may impose
** additional restrictions and it is the user's responsibility to ensure
** that they have met the licensing requirements of the GPL, LGPL, or Qt
** Solutions Commercial license and the relevant license of the Third
** Party Software they are using.
**
** If you are unsure which license is appropriate for your use, please
** contact Nokia at qt-info@nokia.com.
**
****************************************************************************/
#ifndef QTCOLORPICKER_H
#define QTCOLORPICKER_H
#include <QPushButton>
#include <QtCore/QString>
#include <QColor>
#include <QLabel>
#include <QtCore/QEvent>
#include <QFocusEvent>
class ColorPickerPopup;
class ColorPickerItem;
class QtColorPicker : public QPushButton
{
Q_OBJECT
Q_PROPERTY(bool colorDialog READ colorDialogEnabled WRITE setColorDialogEnabled)
public:
QtColorPicker(QWidget *parent = 0,
int columns = -1, bool enableColorDialog = true);
~QtColorPicker();
void insertColor(const QColor &color, const QString &text = QString(), int index = -1);
QColor currentColor() const;
QColor color(int index) const;
void setColorDialogEnabled(bool enabled);
bool colorDialogEnabled() const;
void setStandardColors();
auto CustomColors() const -> QVector<QColor>;
static QColor getColor(const QPoint &pos, bool allowCustomColors = true);
public Q_SLOTS:
void setCurrentColor(const QColor &col);
Q_SIGNALS:
void colorChanged(const QColor &);
protected:
void paintEvent(QPaintEvent *e);
private Q_SLOTS:
void buttonPressed(bool toggled);
void popupClosed();
private:
Q_DISABLE_COPY(QtColorPicker)
ColorPickerPopup *popup{nullptr};
QColor col{};
bool withColorDialog{false};
bool dirty{false};
bool firstInserted{false};
};
#endif

View File

@ -2,6 +2,7 @@
# This need for corect working file translations.pro # This need for corect working file translations.pro
SOURCES += \ SOURCES += \
$$PWD/qtcolorpicker.cpp \
$$PWD/vcomboboxdelegate.cpp \ $$PWD/vcomboboxdelegate.cpp \
$$PWD/vdecorationaligningdelegate.cpp \ $$PWD/vdecorationaligningdelegate.cpp \
$$PWD/velidedlabel.cpp \ $$PWD/velidedlabel.cpp \
@ -32,6 +33,7 @@ SOURCES += \
*msvc*:SOURCES += $$PWD/stable.cpp *msvc*:SOURCES += $$PWD/stable.cpp
HEADERS += \ HEADERS += \
$$PWD/qtcolorpicker.h \
$$PWD/stable.h \ $$PWD/stable.h \
$$PWD/vcomboboxdelegate.h \ $$PWD/vcomboboxdelegate.h \
$$PWD/vdecorationaligningdelegate.h \ $$PWD/vdecorationaligningdelegate.h \