Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/3169
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/69/3169/1
Create Photo Album implementation
Added a checkbox to enable/diable Keep Aspect ratio, plus 2 images/slide option is implemented.
Change-Id: I68d2a3e00f8c55b909fe4d98aa3958188653390e
---
M sd/source/ui/dlg/PhotoAlbumDialog.cxx
M sd/source/ui/dlg/PhotoAlbumDialog.hxx
M sd/uiconfig/simpress/ui/photoalbum.ui
3 files changed, 276 insertions(+), 61 deletions(-)
diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.cxx b/sd/source/ui/dlg/PhotoAlbumDialog.cxx
index 03ccd07..ff0e7d7 100644
--- a/sd/source/ui/dlg/PhotoAlbumDialog.cxx
+++ b/sd/source/ui/dlg/PhotoAlbumDialog.cxx
@@ -8,17 +8,15 @@
*/
#include "PhotoAlbumDialog.hxx"
-#include <com/sun/star/graphic/GraphicProvider.hpp>
-#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/componentcontext.hxx>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
-#include <com/sun/star/drawing/XDrawPages.hpp>
-#include <com/sun/star/drawing/XDrawPage.hpp>
+
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/text/XText.hpp>
#include <sfx2/filedlghelper.hxx>
#include <tools/urlobj.hxx>
@@ -28,13 +26,6 @@
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/msgbox.hxx>
-
-
-
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::presentation;
namespace sd
{
@@ -57,6 +48,8 @@
get(pInsTypeCombo, "opt_combo");
+ get(pASRCheck, "asr_check");
+
pCancelBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CancelHdl));
pCreateBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CreateHdl));
@@ -67,6 +60,7 @@
pRemoveBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
pImagesLst->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, SelectHdl));
+
mpGraphicFilter = new GraphicFilter;
}
@@ -111,52 +105,52 @@
OUString sUrl = pImagesLst->GetEntry( i );
if (sUrl != "Text Box")
{
- ::comphelper::NamedValueCollection aMediaProperties;
- aMediaProperties.put( "URL", OUString( sUrl ) );
-
- Reference< graphic::XGraphic> xGraphic =
- xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
-
- Reference< drawing::XDrawPage > xSlide;
- Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY
);
- xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
- SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1,
PK_STANDARD);
- pSlide->SetAutoLayout(AUTOLAYOUT_NONE, sal_True);
-
+ Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE,
xDrawPages);
Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
+
+ Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl,
xProvider);
+
+ Image aImg(xGraphic);
+ // Save the original size, multiplied with 100
+ ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100,
aImg.GetSizePixel().Height()*100);
Reference< drawing::XShape > xShape(
xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
- uno::UNO_QUERY
- );
+ uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
- ::awt::Size aPicSize = xShape->getSize();
+
::awt::Size aPageSize;
xSlideProps->getPropertyValue(
OUString("Width")) >>= aPageSize.Width;
xSlideProps->getPropertyValue(
OUString("Height")) >>= aPageSize.Height;
- aPicSize.Width = aPageSize.Width;
- aPicSize.Height = aPageSize.Height;
+
::awt::Point aPicPos;
+ if(pASRCheck->IsChecked())
+ {
+ // Resize the image, with keeping ASR
+ aPicSize = createASRSize(aPicSize, aPageSize);
+ }
+ else
+ {
+ aPicSize.Width = aPageSize.Width;
+ aPicSize.Height = aPageSize.Height;
+ }
+ xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
- xShape->setSize(aPicSize);
+
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
else // insert an empty slide, with centered text box
{
- Reference< drawing::XDrawPage > xSlide;
- Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY
);
- xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
- SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1,
PK_STANDARD);
- pSlide->SetAutoLayout(AUTOLAYOUT_ONLY_TEXT, sal_True);
+ appendNewSlide(AUTOLAYOUT_ONLY_TEXT, xDrawPages);
}
}
}
@@ -168,35 +162,18 @@
OUString sUrl = pImagesLst->GetEntry( i );
if ( sUrl != "Text Box" )
{
- ::comphelper::NamedValueCollection aMediaProperties;
- aMediaProperties.put( "URL", OUString( sUrl ) );
-
- Reference< graphic::XGraphic> xGraphic =
- xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
-
- Reference< drawing::XDrawPage > xSlide;
- Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY
);
- xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
-
+ Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE,
xDrawPages);
Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
+ Reference< drawing::XShape > xShape = createXShapeFromUrl(sUrl, xShapeFactory,
xProvider);
- Reference< drawing::XShape > xShape(
- xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
- uno::UNO_QUERY
- );
-
- Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
- xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
-
- ::awt::Size aPicSize = xShape->getSize();
+ ::awt::Size aPicSize(xShape->getSize());
::awt::Size aPageSize;
xSlideProps->getPropertyValue(
OUString("Width")) >>= aPageSize.Width;
xSlideProps->getPropertyValue(
OUString("Height")) >>= aPageSize.Height;
- aPicSize.Width = aPageSize.Width/2;
- aPicSize.Height = aPageSize.Height/2;
+
::awt::Point aPicPos;
aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
@@ -211,12 +188,116 @@
}
else // insert an empty slide, with centered text box
{
- Reference< drawing::XDrawPage > xSlide;
- Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY
);
- xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
- SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1,
PK_STANDARD);
- pSlide->SetAutoLayout(AUTOLAYOUT_ONLY_TEXT, sal_True);
+ appendNewSlide(AUTOLAYOUT_ONLY_TEXT, xDrawPages);
}
+ }
+ }
+ else if( sOpt == "2 images" )
+ {
+ OUString sUrl1("");
+ OUString sUrl2("");
+
+ for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=2 )
+ {
+ // create the slide
+ Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE,
xDrawPages);
+ Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
+ //Slide dimensions
+ ::awt::Size aPageSize;
+
+ xSlideProps->getPropertyValue(
+ OUString("Width")) >>= aPageSize.Width;
+ xSlideProps->getPropertyValue(
+ OUString("Height")) >>= aPageSize.Height;
+
+ // grab the left one
+ sUrl1 = pImagesLst->GetEntry( i );
+ // grab the right one
+ sUrl2 = pImagesLst->GetEntry( i+1 );
+
+ if( sUrl1 == "Text Box" )
+ {
+ SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1,
PK_STANDARD);
+ pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(100,100),
Point(aPageSize.Width/2-100, aPageSize.Height-100)), sal_True);
+ }
+ else if( sUrl1.isEmpty()){}
+ else
+ {
+
+ Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl1,
xProvider);
+
+ Image aImg(xGraphic);
+ // Save the original size, multiplied with 100
+ ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100,
aImg.GetSizePixel().Height()*100);
+
+ Reference< drawing::XShape > xShape(
+ xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
+ uno::UNO_QUERY);
+
+ Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
+ xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
+
+ ::awt::Point aPicPos;
+
+ if(pASRCheck->IsChecked())
+ {
+ // Resize the image, with keeping ASR
+ aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2,
aPageSize.Height/2));
+ }
+ else
+ {
+ aPicSize.Width = aPageSize.Width/2;
+ aPicSize.Height = aPageSize.Height/2;
+ }
+ xShape->setSize(aPicSize);
+ aPicPos.X = 0;
+ aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
+
+ xShape->setPosition(aPicPos);
+ xSlide->add(xShape);
+ }
+
+ if( sUrl2 == "Text Box" )
+ {
+ SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1,
PK_STANDARD);
+ pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False,
Rectangle(Point(aPageSize.Width/2 + 100,100), Point(aPageSize.Width-100, aPageSize.Height-100)),
sal_True);
+ }
+ else if( sUrl2.isEmpty()){}
+ else
+ {
+ Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl2,
xProvider);
+
+ Image aImg(xGraphic);
+ // Save the original size, multiplied with 100
+ ::awt::Size aPicSize(aImg.GetSizePixel().Width()*100,
aImg.GetSizePixel().Height()*100);
+
+ Reference< drawing::XShape > xShape(
+ xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
+ uno::UNO_QUERY);
+
+ Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
+ xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
+
+ ::awt::Point aPicPos;
+
+ if(pASRCheck->IsChecked())
+ {
+ // Resize the image, with keeping ASR
+ aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2,
aPageSize.Height/2));
+ }
+ else
+ {
+ aPicSize.Width = aPageSize.Width/2;
+ aPicSize.Height = aPageSize.Height/2;
+ }
+ xShape->setSize(aPicSize);
+ aPicPos.X = aPageSize.Width/2;
+ aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
+
+ xShape->setPosition(aPicPos);
+ xSlide->add(xShape);
+ }
+
}
}
else
@@ -301,6 +382,7 @@
IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl)
{
pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
+ pImg->SetImage(Image());
return 0;
}
@@ -374,5 +456,97 @@
pFirstSlide->SetObjText(pAuthorObj, NULL, PRESOBJ_TEXT, OUString("Author: ") +
aUserOptions.GetFullName());
}
+Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
+ Reference< drawing::XDrawPages > xDrawPages
+)
+{
+ Reference< drawing::XDrawPage > xSlide; // Create the slide
+ Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
+ xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
+ SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
+ pSlide->SetAutoLayout(aLayout, sal_True); // Set the layout here
+ return xSlide;
+}
+
+awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
+{
+ double resizeWidth = aPicSize.Width;
+ double resizeHeight = aPicSize.Height;
+ double aspect = resizeWidth/resizeHeight;
+
+ if( resizeWidth > aMaxSize.Width )
+ {
+ resizeWidth = aMaxSize.Width;
+ resizeHeight = resizeWidth / aspect;
+ }
+
+ if( resizeHeight > aMaxSize.Height )
+ {
+ aspect = resizeWidth/resizeHeight;
+ resizeHeight = aMaxSize.Height;
+ resizeWidth = resizeHeight * aspect;
+ }
+ return awt::Size(resizeWidth, resizeHeight);
+ /*double wRatio, hRatio, resizeRatio;
+ if(aPicSize.Width >= aPicSize.Height)
+ {
+ if(aPicSize.Width <= aMaxSize.Width && aPicSize.Height <= aMaxSize.Height)
+ {
+ // no resize required
+ return aPicSize;
+ }
+ wRatio = aMaxSize.Width / aPicSize.Width;
+ hRatio = aMaxSize.Height / aPicSize.Height;
+ }
+ else
+ {
+ if(aPicSize.Height <= aMaxSize.Width && aPicSize.Width <= aMaxSize.Height)
+ {
+ // no resize required
+ return aPicSize;
+ }
+ wRatio = aMaxSize.Height / aPicSize.Width;
+ hRatio = aMaxSize.Width / aPicSize.Height;
+ }
+ if(wRatio <= hRatio)
+ resizeRatio = wRatio;
+ else
+ resizeRatio = hRatio;
+ return awt::Size(aPicSize.Width * resizeRatio, aPicSize.Height * resizeRatio);*/
+}
+
+Reference< drawing::XShape > SdPhotoAlbumDialog::createXShapeFromUrl(const OUString& sUrl,
+ Reference< lang::XMultiServiceFactory > xShapeFactory,
+ Reference< graphic::XGraphicProvider> xProvider
+)
+{
+ //First, we create an XGraphic
+ ::comphelper::NamedValueCollection aMediaProperties;
+ aMediaProperties.put( "URL", OUString( sUrl ) );
+ Reference< graphic::XGraphic> xGraphic =
+ xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
+ //And then, we can create the XShape from the XGraphic
+ Reference< drawing::XShape > xShape(
+ xShapeFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"),
+ uno::UNO_QUERY
+ );
+
+ Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
+ xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
+
+ return xShape; // Image loaded into XShape
+}
+
+Reference< graphic::XGraphic> SdPhotoAlbumDialog::createXGraphicFromUrl(const OUString& sUrl,
+ Reference< graphic::XGraphicProvider> xProvider
+)
+{
+ ::comphelper::NamedValueCollection aMediaProperties;
+ aMediaProperties.put( "URL", OUString( sUrl ) );
+ Reference< graphic::XGraphic> xGraphic =
+ xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
+ return xGraphic;
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.hxx b/sd/source/ui/dlg/PhotoAlbumDialog.hxx
index cf70fc8..a03d441 100644
--- a/sd/source/ui/dlg/PhotoAlbumDialog.hxx
+++ b/sd/source/ui/dlg/PhotoAlbumDialog.hxx
@@ -23,9 +23,18 @@
#include <vcl/graphicfilter.hxx>
#include <svx/svdotext.hxx>
+#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/drawing/XDrawPages.hpp>
+#include <com/sun/star/graphic/GraphicProvider.hpp>
+#include <com/sun/star/graphic/XGraphicProvider.hpp>
+
class SdrTextObj;
class SdDrawDocument;
class SdPage;
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::presentation;
namespace sd
{
@@ -49,7 +58,9 @@
ListBox* pImagesLst;
FixedImage* pImg;
- ListBox* pInsTypeCombo;
+ ListBox* pInsTypeCombo;
+
+ CheckBox* pASRCheck;
SdDrawDocument* pDoc;
GraphicFilter* mpGraphicFilter;
@@ -66,6 +77,18 @@
DECL_LINK(SelectHdl, void*);
void setFirstSlide(SdPage* pFirstSlide);
+
+ Reference< drawing::XDrawPage > appendNewSlide(AutoLayout aLayout,
+ Reference< drawing::XDrawPages > xDrawPages);
+
+ awt::Size createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize);
+
+ Reference< drawing::XShape > createXShapeFromUrl(const OUString& sUrl,
+ Reference< lang::XMultiServiceFactory > xShapeFactory,
+ Reference< graphic::XGraphicProvider> xProvider);
+
+ Reference< graphic::XGraphic> createXGraphicFromUrl(const OUString& sUrl,
+ Reference< graphic::XGraphicProvider> xProvider);
};
}
diff --git a/sd/uiconfig/simpress/ui/photoalbum.ui b/sd/uiconfig/simpress/ui/photoalbum.ui
index e88b2cb..b071667 100644
--- a/sd/uiconfig/simpress/ui/photoalbum.ui
+++ b/sd/uiconfig/simpress/ui/photoalbum.ui
@@ -297,6 +297,24 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="asr_check">
+ <property name="label" translatable="yes">Keep Aspect
Ratio</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">0</property>
--
To view, visit https://gerrit.libreoffice.org/3169
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I68d2a3e00f8c55b909fe4d98aa3958188653390e
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Gergő Mocsi <gmocsi91@gmail.com>
Context
- [PATCH] Create Photo Album implementation · via Code Review
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.