From 489597d339af14a6403ee079bea35908112720ec Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Fri, 19 May 2017 00:18:15 +0200 Subject: Watermark: extended configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * it is possible to set font family, color, angle and transparency Change-Id: Idea2fb9ee748394bb3d706fa790e109238584cdb Reviewed-on: https://gerrit.libreoffice.org/37793 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- sw/inc/editsh.hxx | 2 +- sw/source/core/edit/edfcol.cxx | 66 +++++++++++++---- sw/source/uibase/app/docsh2.cxx | 16 +++- sw/source/uibase/app/docst.cxx | 5 +- sw/source/uibase/dialog/watermarkdialog.cxx | 46 ++++++++++-- sw/source/uibase/inc/watermarkdialog.hxx | 7 ++ sw/uiconfig/swriter/ui/watermarkdialog.ui | 109 ++++++++++++++++++++++++++-- 7 files changed, 219 insertions(+), 32 deletions(-) (limited to 'sw') diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index db7a5346a586..e031303b6aae 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -367,7 +367,7 @@ public: void SetClassification(const OUString& rName, SfxClassificationPolicyType eType); SfxWatermarkItem GetWatermark(); - void SetWatermark(const OUString& rText); + void SetWatermark(const SfxWatermarkItem& rText); void Insert2(SwField&, const bool bForceExpandHints); diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 029eb57be727..4f1967dc9648 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -229,7 +229,9 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli } } - SetWatermark(aWatermark); + SfxWatermarkItem aWatermarkItem; + aWatermarkItem.SetText(aWatermark); + SetWatermark(aWatermarkItem); } if (bFooterIsNeeded) @@ -260,7 +262,7 @@ SfxWatermarkItem SwEditShell::GetWatermark() { SwDocShell* pDocShell = GetDoc()->GetDocShell(); if (!pDocShell) - return SfxWatermarkItem(SID_WATERMARK, ""); + return SfxWatermarkItem(); uno::Reference xModel = pDocShell->GetBaseModel(); uno::Reference xStyleFamiliesSupplier(xModel, uno::UNO_QUERY); @@ -286,14 +288,30 @@ SfxWatermarkItem SwEditShell::GetWatermark() if (xWatermark.is()) { + SfxWatermarkItem aItem; uno::Reference xTextRange(xWatermark, uno::UNO_QUERY); - return SfxWatermarkItem(SID_WATERMARK, xTextRange->getString()); + uno::Reference xPropertySet(xWatermark, uno::UNO_QUERY); + sal_uInt32 nColor; + sal_Int16 nTransparency; + OUString aFont; + + aItem.SetText(xTextRange->getString()); + + if (xPropertySet->getPropertyValue(UNO_NAME_CHAR_FONT_NAME) >>= aFont) + aItem.SetFont(aFont); + if (xPropertySet->getPropertyValue(UNO_NAME_FILLCOLOR) >>= nColor) + aItem.SetColor(nColor); + // TODO: aItem.SetAngle(nAngle); + if (xPropertySet->getPropertyValue(UNO_NAME_FILL_TRANSPARENCE) >>= nTransparency) + aItem.SetTransparency(nTransparency); + + return aItem; } } - return SfxWatermarkItem(SID_WATERMARK, ""); + return SfxWatermarkItem(); } -void SwEditShell::SetWatermark(const OUString& rWatermark) +void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark) { SwDocShell* pDocShell = GetDoc()->GetDocShell(); if (!pDocShell) @@ -326,12 +344,26 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) static const OUString sWatermark = SfxClassificationHelper::PROP_PREFIX_INTELLECTUALPROPERTY() + SfxClassificationHelper::PROP_DOCWATERMARK(); uno::Reference xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark); - bool bDeleteWatermark = rWatermark.isEmpty(); + bool bDeleteWatermark = rWatermark.GetText().isEmpty(); if (xWatermark.is()) { + sal_uInt32 nColor = 0xc0c0c0; + sal_Int16 nTransparency = 50; + OUString aFont = ""; + + uno::Reference xPropertySet(xWatermark, uno::UNO_QUERY); + xPropertySet->getPropertyValue(UNO_NAME_CHAR_FONT_NAME) >>= aFont; + xPropertySet->getPropertyValue(UNO_NAME_FILLCOLOR) >>= nColor; + // TODO: Angle + xPropertySet->getPropertyValue(UNO_NAME_FILL_TRANSPARENCE) >>= nTransparency; + // If the header already contains a watermark, see if it its text is up to date. uno::Reference xTextRange(xWatermark, uno::UNO_QUERY); - if (xTextRange->getString() != rWatermark || bDeleteWatermark) + if (xTextRange->getString() != rWatermark.GetText() + || aFont != rWatermark.GetFont() + || nColor != rWatermark.GetColor() + || nTransparency != rWatermark.GetTransparency() + || bDeleteWatermark) { // No: delete it and we'll insert a replacement. uno::Reference xComponent(xWatermark, uno::UNO_QUERY); @@ -342,12 +374,18 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) if (!xWatermark.is() && !bDeleteWatermark) { + OUString sFont = rWatermark.GetFont(); + sal_Int16 nAngle = rWatermark.GetAngle(); + sal_Int16 nTransparency = rWatermark.GetTransparency(); + sal_uInt32 nColor = rWatermark.GetColor(); + // Calc the ratio. double fRatio = 0; OutputDevice* pOut = Application::GetDefaultDevice(); vcl::Font aFont(pOut->GetFont()); + aFont.SetFamilyName(sFont); fRatio = aFont.GetFontSize().Height(); - fRatio /= pOut->GetTextWidth(rWatermark); + fRatio /= pOut->GetTextWidth(rWatermark.GetText()); // Calc the size. sal_Int32 nWidth = 0; @@ -378,7 +416,7 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) basegfx::B2DHomMatrix aTransformation; aTransformation.identity(); aTransformation.scale(nWidth, nHeight); - aTransformation.rotate(F_PI180 * -45); + aTransformation.rotate(F_PI180 * -1 * nAngle); drawing::HomogenMatrix3 aMatrix; aMatrix.Line1.Column1 = aTransformation.get(0, 0); aMatrix.Line1.Column2 = aTransformation.get(0, 1); @@ -397,9 +435,9 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) // The remaining properties have to be set after the shape is inserted: do that in one batch to avoid flickering. uno::Reference xLockable(xShape, uno::UNO_QUERY); xLockable->addActionLock(); - xPropertySet->setPropertyValue(UNO_NAME_FILLCOLOR, uno::makeAny(static_cast(0xc0c0c0))); + xPropertySet->setPropertyValue(UNO_NAME_FILLCOLOR, uno::makeAny(static_cast(nColor))); xPropertySet->setPropertyValue(UNO_NAME_FILLSTYLE, uno::makeAny(drawing::FillStyle_SOLID)); - xPropertySet->setPropertyValue(UNO_NAME_FILL_TRANSPARENCE, uno::makeAny(static_cast(50))); + xPropertySet->setPropertyValue(UNO_NAME_FILL_TRANSPARENCE, uno::makeAny(nTransparency)); xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT_RELATION, uno::makeAny(static_cast(text::RelOrientation::PAGE_PRINT_AREA))); xPropertySet->setPropertyValue(UNO_NAME_LINESTYLE, uno::makeAny(drawing::LineStyle_NONE)); xPropertySet->setPropertyValue(UNO_NAME_OPAQUE, uno::makeAny(false)); @@ -407,15 +445,15 @@ void SwEditShell::SetWatermark(const OUString& rWatermark) xPropertySet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWWIDTH, uno::makeAny(false)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEHEIGHT, uno::makeAny(nHeight)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::makeAny(nWidth)); - xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::makeAny(text::WrapTextMode_THROUGH)); + xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::makeAny(text::WrapTextMode_THROUGHT)); xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT_RELATION, uno::makeAny(static_cast(text::RelOrientation::PAGE_PRINT_AREA))); - xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::makeAny(OUString("Liberation Sans"))); + xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::makeAny(sFont)); xPropertySet->setPropertyValue("Transformation", uno::makeAny(aMatrix)); xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT, uno::makeAny(static_cast(text::HoriOrientation::CENTER))); xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT, uno::makeAny(static_cast(text::VertOrientation::CENTER))); uno::Reference xTextRange(xShape, uno::UNO_QUERY); - xTextRange->setString(rWatermark); + xTextRange->setString(rWatermark.GetText()); uno::Reference xDefaulter(xShape, uno::UNO_QUERY); xDefaulter->createCustomShapeDefaults("fontwork-plain-text"); diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx index 7268c502230e..55db8a619643 100644 --- a/sw/source/uibase/app/docsh2.cxx +++ b/sw/source/uibase/app/docsh2.cxx @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -1167,8 +1168,19 @@ void SwDocShell::Execute(SfxRequest& rReq) { if (pArgs && pArgs->GetItemState( SID_WATERMARK, false, &pItem ) == SfxItemState::SET) { - OUString aText = static_cast( pItem )->GetValue(); - pSh->SetWatermark( aText ); + SfxWatermarkItem aItem; + aItem.SetText( static_cast( pItem )->GetValue() ); + + if ( pArgs->GetItemState( SID_WATERMARK_FONT, false, &pItem ) == SfxItemState::SET ) + aItem.SetFont( static_cast( pItem )->GetValue() ); + if ( pArgs->GetItemState( SID_WATERMARK_ANGLE, false, &pItem ) == SfxItemState::SET ) + aItem.SetAngle( static_cast( pItem )->GetValue() ); + if ( pArgs->GetItemState( SID_WATERMARK_TRANSPARENCY, false, &pItem ) == SfxItemState::SET ) + aItem.SetTransparency( static_cast( pItem )->GetValue() ); + if ( pArgs->GetItemState( SID_WATERMARK_COLOR, false, &pItem ) == SfxItemState::SET ) + aItem.SetColor( static_cast( pItem )->GetValue() ); + + pSh->SetWatermark( aItem ); } else { diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index cffd2eca88ca..6eff974face6 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -276,10 +276,9 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) break; case SID_WATERMARK: { + SfxWatermarkItem aItem = pSh->GetWatermark(); if( pSh ) - rSet.Put(pSh->GetWatermark()); - - rSet.InvalidateItem(nWhich); + rSet.Put(aItem); } break; default: diff --git a/sw/source/uibase/dialog/watermarkdialog.cxx b/sw/source/uibase/dialog/watermarkdialog.cxx index bcc6077e9d03..1246eabce4cc 100644 --- a/sw/source/uibase/dialog/watermarkdialog.cxx +++ b/sw/source/uibase/dialog/watermarkdialog.cxx @@ -10,11 +10,14 @@ #include #include #include +#include +#include #include #include #include #include #include +#include SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindings ) : ModelessDialog( pParent, "WatermarkDialog", "modules/swriter/ui/watermarkdialog.ui" ) @@ -24,9 +27,10 @@ SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindin get( m_pEnableWatermarkCB, "EnableWatermarkCB" ); get( m_pTextInput, "TextInput" ); get( m_pOKButton, "ok" ); - - m_pEnableWatermarkCB->SetClickHdl( LINK( this, SwWatermarkDialog, CheckBoxHdl ) ); - m_pOKButton->SetClickHdl( LINK( this, SwWatermarkDialog, OKButtonHdl ) ); + get( m_pFont, "FontBox" ); + get( m_pAngle, "Angle" ); + get( m_pTransparency, "Transparency" ); + get( m_pColor, "Color" ); InitFields(); Update(); @@ -39,6 +43,10 @@ SwWatermarkDialog::~SwWatermarkDialog() void SwWatermarkDialog::dispose() { + m_pFont.clear(); + m_pAngle.clear(); + m_pTransparency.clear(); + m_pColor.clear(); m_pTextGrid.clear(); m_pEnableWatermarkCB.clear(); m_pTextInput.clear(); @@ -49,14 +57,36 @@ void SwWatermarkDialog::dispose() void SwWatermarkDialog::InitFields() { + // Update font list + SfxObjectShell* pDocSh = SfxObjectShell::Current(); + const SfxPoolItem* pFontItem; + const FontList* pFontList = nullptr; + + if ( pDocSh && ( ( pFontItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ) ) != nullptr ) ) + pFontList = static_cast( pFontItem )->GetFontList(); + + if(!pFontList) + pFontList = new FontList(Application::GetDefaultDevice(), nullptr); + + m_pFont->Fill( pFontList ); + + m_pEnableWatermarkCB->SetClickHdl( LINK( this, SwWatermarkDialog, CheckBoxHdl ) ); + m_pOKButton->SetClickHdl( LINK( this, SwWatermarkDialog, OKButtonHdl ) ); + + // Get watermark properties const SfxPoolItem* pItem; SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, pItem ); - if( eState >= SfxItemState::DEFAULT && pItem ) + if( eState >= SfxItemState::DEFAULT && pItem && pItem->Which() == SID_WATERMARK) { - OUString sText = static_cast( pItem )->GetText(); + const SfxWatermarkItem* pWatermark = static_cast( pItem ); + OUString sText = pWatermark->GetText(); m_pEnableWatermarkCB->Check( !sText.isEmpty() ); m_pTextInput->SetText( sText ); + m_pFont->SelectEntryPos( m_pFont->GetEntryPos( pWatermark->GetFont() ) ); + m_pAngle->SetValue( pWatermark->GetAngle() ); + m_pColor->SelectEntry( pWatermark->GetColor() ); + m_pTransparency->SetValue( pWatermark->GetTransparency() ); } } @@ -81,7 +111,11 @@ IMPL_LINK_NOARG( SwWatermarkDialog, OKButtonHdl, Button*, void ) css::uno::Sequence aPropertyValues( comphelper::InitPropertySequence( { - { "Text", css::uno::makeAny( sText ) } + { "Text", css::uno::makeAny( sText ) }, + { "Font", css::uno::makeAny( m_pFont->GetSelectEntry() ) }, + { "Angle", css::uno::makeAny( static_cast( m_pAngle->GetValue() ) ) }, + { "Transparency", css::uno::makeAny( static_cast( m_pTransparency->GetValue() ) ) }, + { "Color", css::uno::makeAny( static_cast( m_pColor->GetSelectEntryColor().GetRGBColor() ) ) } } ) ); comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues ); diff --git a/sw/source/uibase/inc/watermarkdialog.hxx b/sw/source/uibase/inc/watermarkdialog.hxx index e1a60b96637d..7f59fe0a2bb7 100644 --- a/sw/source/uibase/inc/watermarkdialog.hxx +++ b/sw/source/uibase/inc/watermarkdialog.hxx @@ -10,7 +10,10 @@ #define INCLUDED_SW_SOURCE_UIBASE_INC_WATERMARKDIALOG_HXX #include +#include #include +#include +#include class SwWatermarkDialog : public ModelessDialog { @@ -32,6 +35,10 @@ private: VclPtr m_pEnableWatermarkCB; VclPtr m_pTextInput; VclPtr m_pOKButton; + VclPtr m_pFont; + VclPtr m_pAngle; + VclPtr m_pTransparency; + VclPtr m_pColor; }; #endif diff --git a/sw/uiconfig/swriter/ui/watermarkdialog.ui b/sw/uiconfig/swriter/ui/watermarkdialog.ui index f4d9b6377440..316cd0c5d8bc 100644 --- a/sw/uiconfig/swriter/ui/watermarkdialog.ui +++ b/sw/uiconfig/swriter/ui/watermarkdialog.ui @@ -2,6 +2,17 @@ + + + 359 + 1 + 10 + + + 100 + 1 + 10 + False 6 @@ -86,6 +97,7 @@ True False Text + 0 0 @@ -103,6 +115,97 @@ 0 + + + True + True + + + 1 + 1 + + + + + True + False + Font + 0 + + + 0 + 1 + + + + + True + False + Angle + 0 + + + 0 + 2 + + + + + True + False + Transparency + 0 + + + 0 + 3 + + + + + True + False + Color + 0 + + + 0 + 4 + + + + + True + True + angle_adj + + + 1 + 2 + + + + + True + True + transparenct_adj + 50 + + + 1 + 3 + + + + + True + True + + + 1 + 4 + + True @@ -124,10 +227,4 @@ cancel - - You did not specify a new name for the attachment. - - - If you would like to provide one, please type it now. - -- cgit