tdf#116108 Add option to fit images into their cell

Change-Id: I2e9a4f567049f11985e4bf914c2fa5bd1f181823
Reviewed-on: https://gerrit.libreoffice.org/50569
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
This commit is contained in:
Samuel Mehrbrodt
2018-03-01 12:17:46 +01:00
parent 1163bcd5da
commit 073b4eadd2
19 changed files with 99 additions and 0 deletions

View File

@@ -733,6 +733,9 @@ public:
void SetMarkProtect(bool bProt);
bool IsMarkProtect() const { return bMarkProt;}
/// Whether the aspect ratio should be kept by default when resizing.
virtual bool shouldKeepAspectRatio() const { return false; }
// application specific data
sal_uInt16 GetUserDataCount() const;
SdrObjUserData* GetUserData(sal_uInt16 nNum) const;

View File

@@ -211,6 +211,8 @@ public:
bool IsMirrored() const { return bMirrored;}
void SetMirrored( bool _bMirrored );
virtual bool shouldKeepAspectRatio() const override { return true; }
// Access to GrafAnimationAllowed flag
void SetGrafAnimationAllowed(bool bNew);

View File

@@ -69,6 +69,8 @@ public:
GetInputStream();
void SetInputStream(css::uno::Reference<css::io::XInputStream> const&);
virtual bool shouldKeepAspectRatio() const override { return true; }
private:
void mediaPropertiesChanged( const ::avmedia::MediaItem& rNewState );

View File

@@ -2181,6 +2181,11 @@
<value xml:lang="en-US">~Original Size</value>
</prop>
</node>
<node oor:name=".uno:FitCellSize" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~Fit to Cell Size</value>
</prop>
</node>
<node oor:name=".uno:GridMenu" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Gr~id and Helplines</value>

View File

@@ -93,6 +93,7 @@
#define STR_UNDO_DETREFRESH NC_("STR_UNDO_DETREFRESH", "Refresh Traces")
#define STR_UNDO_CHARTDATA NC_("STR_UNDO_CHARTDATA", "Modify chart data range")
#define STR_UNDO_ORIGINALSIZE NC_("STR_UNDO_ORIGINALSIZE", "Original Size")
#define STR_UNDO_FITCELLSIZE NC_("STR_UNDO_FITCELLSIZE", "Fit to Cell Size")
#define STR_UNDO_UPDATELINK NC_("STR_UNDO_UPDATELINK", "Update Link")
#define STR_UNDO_REMOVELINK NC_("STR_UNDO_REMOVELINK", "Unlink")
#define STR_UNDO_INSERTAREALINK NC_("STR_UNDO_INSERTAREALINK", "Insert Link")

View File

@@ -409,6 +409,7 @@
#define SID_ANCHOR_CELL_RESIZE (DRAW_BAR_START+26)
#define SID_ANCHOR_TOGGLE (DRAW_BAR_START+27)
#define SID_ORIGINALSIZE (DRAW_BAR_START+28)
#define SID_FITCELLSIZE (DRAW_BAR_START+29)
#define DRAW_BAR_END (DRAW_BAR_START+50)

View File

@@ -179,6 +179,7 @@ interface TableDraw
SID_ATTR_SIZE [ StateMethod = GetDrawAttrState; Export = FALSE; ]
SID_TABLE_CELL [ StateMethod = GetDrawAttrState; Export = FALSE; ]
SID_ORIGINALSIZE [ ExecMethod = ExecDrawFunc; StateMethod = GetDrawFuncState; Export = FALSE; ]
SID_FITCELLSIZE [ ExecMethod = ExecDrawFunc; StateMethod = GetDrawFuncState; Export = FALSE; ]
SID_HYPERLINK_SETLINK [ ExecMethod = ExecuteHLink; Export = FALSE; ]
SID_HYPERLINK_GETLINK [ StateMethod = GetHLinkState; Export = FALSE; ]
SID_ENABLE_HYPHENATION [ ExecMethod = ExecDrawFunc; StateMethod = GetDrawFuncState; Export = FALSE; ]

View File

@@ -3924,6 +3924,24 @@ SfxVoidItem OriginalSize SID_ORIGINALSIZE
]
SfxVoidItem FitCellSize SID_FITCELLSIZE
()
[
AutoUpdate = FALSE,
FastCall = FALSE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
AccelConfig = TRUE,
MenuConfig = TRUE,
ToolBoxConfig = TRUE,
GroupId = SfxGroupId::Format;
]
SfxBoolItem NormalViewMode FID_NORMALVIEWMODE
[

View File

@@ -208,6 +208,8 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // disable functions
rSet.DisableItem( SID_DRAW_HLINK_EDIT );
rSet.DisableItem( SID_DRAW_HLINK_DELETE );
rSet.DisableItem( SID_OPEN_HYPERLINK );
// Fit to cell only works with a single graphic
rSet.DisableItem( SID_FITCELLSIZE );
}
else if ( nMarkCount == 1 )
{
@@ -244,6 +246,11 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // disable functions
rSet.DisableItem( SID_ANCHOR_TOGGLE );
}
}
// Fit to cell is only available for cell anchored graphics obviously
if (pView->GetAnchorType() != SCA_CELL &&
pView->GetAnchorType() != SCA_CELL_RESIZE)
rSet.DisableItem( SID_FITCELLSIZE );
}
if ( !bCanRename )
{
@@ -267,6 +274,7 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // disable functions
// other
rSet.DisableItem( SID_ANCHOR_TOGGLE );
rSet.DisableItem( SID_ORIGINALSIZE );
rSet.DisableItem( SID_FITCELLSIZE );
rSet.DisableItem( SID_ATTR_TRANSFORM );
}

View File

@@ -458,6 +458,10 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
pView->SetMarkedOriginalSize();
break;
case SID_FITCELLSIZE:
pView->FitToCellSize();
break;
case SID_ENABLE_HYPHENATION:
{
const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(SID_ENABLE_HYPHENATION);

View File

@@ -108,6 +108,7 @@ public:
void UpdateUserViewOptions();
void SetMarkedOriginalSize();
void FitToCellSize();
bool SelectObject( const OUString& rName );
bool HasMarkedControl() const;

View File

@@ -40,6 +40,7 @@
#include <globstr.hrc>
#include <chartarr.hxx>
#include <gridwin.hxx>
#include <userdat.hxx>
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/embed/Aspects.hpp>
@@ -530,4 +531,49 @@ void ScDrawView::SetMarkedOriginalSize()
delete pUndoGroup;
}
void ScDrawView::FitToCellSize()
{
const SdrMarkList& rMarkList = GetMarkedObjectList();
if (rMarkList.GetMarkCount() != 1)
{
SAL_WARN("sc.ui", "Fit to cell only works with one graphic!");
return;
}
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObj);
if (aAnchorType != SCA_CELL && aAnchorType != SCA_CELL_RESIZE)
{
SAL_WARN("sc.ui", "Fit to cell only works with cell anchored graphics!");
return;
}
SdrUndoGroup* pUndoGroup = new SdrUndoGroup(*GetModel());
ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObj);
tools::Rectangle aGraphicRect = pObj->GetSnapRect();
tools::Rectangle aCellRect = ScDrawLayer::GetCellRect( *pDoc, pObjData->maStart, true);
// For graphic objects, we want to keep the aspect ratio
if (pObj->shouldKeepAspectRatio())
{
double fScaleX = static_cast<double>(aCellRect.GetWidth()) / static_cast<double>(aGraphicRect.GetWidth());
double fScaleY = static_cast<double>(aCellRect.GetHeight()) / static_cast<double>(aGraphicRect.GetHeight());
double fScaleMin = std::min(fScaleX, fScaleY);
aCellRect.setWidth(static_cast<double>(aGraphicRect.GetWidth()) * fScaleMin);
aCellRect.setHeight(static_cast<double>(aGraphicRect.GetHeight()) * fScaleMin);
}
pUndoGroup->AddAction( new SdrUndoGeoObj( *pObj ) );
pObj->SetSnapRect(aCellRect);
pUndoGroup->SetComment(ScGlobal::GetRscString( STR_UNDO_FITCELLSIZE ));
ScDocShell* pDocSh = pViewData->GetDocShell();
pDocSh->GetUndoManager()->AddUndoAction(pUndoGroup);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -430,6 +430,7 @@
<menu:menupopup>
<menu:menuitem menu:id=".uno:Crop"/>
<menu:menuitem menu:id=".uno:OriginalSize"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ExternalEdit"/>
<menu:menuitem menu:id=".uno:ChangePicture"/>

View File

@@ -17,6 +17,7 @@
<menu:menuitem menu:id=".uno:TextAttributes"/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuitem menu:id=".uno:OriginalSize"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>

View File

@@ -16,6 +16,7 @@
<menu:menuitem menu:id=".uno:FormatArea"/>
<menu:menuitem menu:id=".uno:TextAttributes"/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>

View File

@@ -13,6 +13,7 @@
<menu:menuitem menu:id=".uno:Paste"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>

View File

@@ -17,6 +17,7 @@
<menu:menuitem menu:id=".uno:TextAttributes"/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuitem menu:id=".uno:OriginalSize"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>

View File

@@ -13,6 +13,7 @@
<menu:menuitem menu:id=".uno:Paste"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>

View File

@@ -17,6 +17,7 @@
<menu:menuitem menu:id=".uno:TextAttributes"/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuitem menu:id=".uno:OriginalSize"/>
<menu:menuitem menu:id=".uno:FitCellSize"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>