Kaydet (Commit) ed4a2031 authored tarafından Muhammet Kara's avatar Muhammet Kara

Forge the freeform redaction tool

out of the Freeform Line tool in Draw.

* Replace .uno:LineToolbox with .uno:Freeline_Unfilled in Redaction toolbar

* Add new parameters to .uno:Freeline_Unfilled
  - SfxUInt16Item Transparence, SfxStringItem Color,
    SfxUInt16Item Width, SfxBoolItem IsSticky

* Handle the params in FuConstructBezierPolygon

* Now the freeform line draw tool on the Redaction toolbar
  works with a default width of 5mm, color of COL_GRAY7,
  and a transparency of 50%; and it sticks when it is
  clicked/selected once until user deliberately deselects it
  by clicking on another tool or by clicking outside of the page.

* Known problem: icon is not displayed on the toolbar after adding the params

Change-Id: I6b09276ca82782dbf214aab8d2ba3b407fb0d81c
Reviewed-on: https://gerrit.libreoffice.org/66916
Tested-by: Jenkins
Reviewed-by: 's avatarMuhammet Kara <muhammet.kara@collabora.com>
üst b1d35c80
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#include <svx/svxids.hrc> #include <svx/svxids.hrc>
#include <svx/svdpagv.hxx> #include <svx/svdpagv.hxx>
#include <svx/xlnclit.hxx>
#include <svx/xlntrit.hxx>
#include <svx/xlnwtit.hxx>
#include <app.hrc> #include <app.hrc>
#include <ViewShell.hxx> #include <ViewShell.hxx>
...@@ -50,7 +53,10 @@ using namespace ::com::sun::star::uno; ...@@ -50,7 +53,10 @@ using namespace ::com::sun::star::uno;
namespace sd { namespace sd {
/*//Extra attributes coming from parameters
sal_uInt16 mnTransparence; // Default: 0
OUString msColor; // Default: ""
sal_uInt16 mnWidth; // Default: 0*/
FuConstructBezierPolygon::FuConstructBezierPolygon ( FuConstructBezierPolygon::FuConstructBezierPolygon (
ViewShell* pViewSh, ViewShell* pViewSh,
::sd::Window* pWin, ::sd::Window* pWin,
...@@ -58,8 +64,29 @@ FuConstructBezierPolygon::FuConstructBezierPolygon ( ...@@ -58,8 +64,29 @@ FuConstructBezierPolygon::FuConstructBezierPolygon (
SdDrawDocument* pDoc, SdDrawDocument* pDoc,
SfxRequest& rReq) SfxRequest& rReq)
: FuConstruct(pViewSh, pWin, pView, pDoc, rReq), : FuConstruct(pViewSh, pWin, pView, pDoc, rReq),
nEditMode(SID_BEZIER_MOVE) nEditMode(SID_BEZIER_MOVE),
mnTransparence(0),
mnWidth(0)
{
}
namespace{
/// Checks to see if the request has a parameter of IsSticky:bool=true
/// It means that the selected command/button will stay selected after use
bool isSticky(SfxRequest& rReq)
{ {
const SfxItemSet *pArgs = rReq.GetArgs ();
if (pArgs)
{
const SfxBoolItem* pIsSticky = rReq.GetArg<SfxBoolItem>(FN_PARAM_4);
if (pIsSticky && pIsSticky->GetValue())
return true;
}
return false;
}
} }
rtl::Reference<FuPoor> FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent ) rtl::Reference<FuPoor> FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
...@@ -67,7 +94,7 @@ rtl::Reference<FuPoor> FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::s ...@@ -67,7 +94,7 @@ rtl::Reference<FuPoor> FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::s
FuConstructBezierPolygon* pFunc; FuConstructBezierPolygon* pFunc;
rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructBezierPolygon( pViewSh, pWin, pView, pDoc, rReq ) ); rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructBezierPolygon( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq); xFunc->DoExecute(rReq);
pFunc->SetPermanent(bPermanent); pFunc->SetPermanent(bPermanent || isSticky(rReq));
return xFunc; return xFunc;
} }
...@@ -76,11 +103,32 @@ void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq ) ...@@ -76,11 +103,32 @@ void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq )
FuConstruct::DoExecute( rReq ); FuConstruct::DoExecute( rReq );
const SfxItemSet* pArgs = rReq.GetArgs(); const SfxItemSet* pArgs = rReq.GetArgs();
if( pArgs ) if( pArgs )
{ {
const SfxPoolItem* pPoolItem = nullptr; const SfxPoolItem* pPoolItem = nullptr;
if( SfxItemState::SET == pArgs->GetItemState( SID_ADD_MOTION_PATH, true, &pPoolItem ) ) if( SfxItemState::SET == pArgs->GetItemState( SID_ADD_MOTION_PATH, true, &pPoolItem ) )
maTargets = static_cast<const SfxUnoAnyItem*>( pPoolItem )->GetValue(); maTargets = static_cast<const SfxUnoAnyItem*>( pPoolItem )->GetValue();
if (nSlotId == SID_DRAW_FREELINE_NOFILL)
{
const SfxUInt16Item* pTransparence = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
const SfxStringItem* pColor = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
const SfxUInt16Item* pWidth = rReq.GetArg<SfxUInt16Item>(FN_PARAM_3);
if (pTransparence && pTransparence->GetValue() > 0)
{
mnTransparence = pTransparence->GetValue();
}
if (pColor && !pColor->GetValue().isEmpty())
{
msColor = pColor->GetValue();
}
if (pWidth && pWidth->GetValue() > 0)
{
mnWidth = pWidth->GetValue();
}
}
} }
} }
...@@ -126,6 +174,7 @@ bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt) ...@@ -126,6 +174,7 @@ bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt)
{ {
SfxItemSet aAttr(mpDoc->GetPool()); SfxItemSet aAttr(mpDoc->GetPool());
SetStyleSheet(aAttr, pObj); SetStyleSheet(aAttr, pObj);
SetAttributes(aAttr);
pObj->SetMergedItemSet(aAttr); pObj->SetMergedItemSet(aAttr);
} }
} }
...@@ -285,6 +334,37 @@ void FuConstructBezierPolygon::SelectionHasChanged() ...@@ -285,6 +334,37 @@ void FuConstructBezierPolygon::SelectionHasChanged()
*mpView); *mpView);
} }
namespace {
/// Returns the color based on the color names listed in core/include/tools/color.hxx
/// Feel free to extend with more color names from color.hxx
Color strToColor(const OUString& sColor)
{
Color aColor = COL_AUTO;
if (sColor == "COL_GRAY")
aColor = COL_GRAY;
else if (sColor == "COL_GRAY3")
aColor = COL_GRAY3;
else if (sColor == "COL_GRAY7")
aColor = COL_GRAY7;
return aColor;
}
}
void FuConstructBezierPolygon::SetAttributes(SfxItemSet& rAttr)
{
if (nSlotId == SID_DRAW_FREELINE_NOFILL)
{
if (mnTransparence > 0 && mnTransparence <= 100)
rAttr.Put(XLineTransparenceItem(mnTransparence));
if (!msColor.isEmpty())
rAttr.Put(XLineColorItem(OUString(), strToColor(msColor)));
if (mnWidth > 0)
rAttr.Put(XLineWidthItem(mnWidth));
}
}
/** /**
* Set current bezier edit mode * Set current bezier edit mode
*/ */
......
...@@ -47,6 +47,11 @@ public: ...@@ -47,6 +47,11 @@ public:
void SetEditMode(sal_uInt16 nMode); void SetEditMode(sal_uInt16 nMode);
sal_uInt16 GetEditMode() { return nEditMode; } sal_uInt16 GetEditMode() { return nEditMode; }
/**
* set attribute for the object to be created
*/
void SetAttributes(SfxItemSet& rAttr);
virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle) override; virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle) override;
private: private:
...@@ -59,6 +64,11 @@ private: ...@@ -59,6 +64,11 @@ private:
sal_uInt16 nEditMode; sal_uInt16 nEditMode;
css::uno::Any maTargets; // used for creating a path for custom animations css::uno::Any maTargets; // used for creating a path for custom animations
//Extra attributes coming from parameters
sal_uInt16 mnTransparence; // Default: 0
OUString msColor; // Default: ""
sal_uInt16 mnWidth; // Default: 0
}; };
} // end of namespace sd } // end of namespace sd
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
--> -->
<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink"> <toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink">
<toolbar:toolbaritem xlink:href=".uno:Rect?FillTransparence:short=50&amp;FillColor:string=COL_GRAY7&amp;LineStyle:short=0&amp;IsSticky:bool=true"/> <toolbar:toolbaritem xlink:href=".uno:Rect?FillTransparence:short=50&amp;FillColor:string=COL_GRAY7&amp;LineStyle:short=0&amp;IsSticky:bool=true"/>
<toolbar:toolbaritem xlink:href=".uno:LineToolbox"/> <toolbar:toolbaritem xlink:href=".uno:Freeline_Unfilled?Transparence:short=50&amp;Color:string=COL_GRAY7&amp;Width:short=500&amp;IsSticky:bool=true"/>
<toolbar:toolbarseparator/> <toolbar:toolbarseparator/>
<toolbar:toolbaritem xlink:href=".uno:ExportDirectToPDF"/> <toolbar:toolbaritem xlink:href=".uno:ExportDirectToPDF"/>
</toolbar:toolbar> </toolbar:toolbar>
...@@ -3472,7 +3472,8 @@ SfxBoolItem Freeline SID_DRAW_FREELINE ...@@ -3472,7 +3472,8 @@ SfxBoolItem Freeline SID_DRAW_FREELINE
SfxBoolItem Freeline_Unfilled SID_DRAW_FREELINE_NOFILL SfxBoolItem Freeline_Unfilled SID_DRAW_FREELINE_NOFILL
(SfxUInt16Item Transparence FN_PARAM_1, SfxStringItem Color FN_PARAM_2,
SfxUInt16Item Width FN_PARAM_3, SfxBoolItem IsSticky FN_PARAM_4)
[ [
AutoUpdate = TRUE, AutoUpdate = TRUE,
FastCall = FALSE, FastCall = FALSE,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment