Kaydet (Commit) 3a56257e authored tarafından Gergő Mocsi's avatar Gergő Mocsi Kaydeden (comit) Andras Timar

Create Photo Album implementation

Added a checkbox to enable/diable Keep Aspect ratio.
Options 2 images/slide, 4 images/slide implemented.
UI tweaks: dialog window remembers last used directory (via config),
buttons get enabled/disabled according to the content of the ListBox.
ListBox show filename only, full path is shown lower in a label.
Dialog window reopens again, if slide preview is not in focus.
Added a title slide: author, title.

Conflicts:
	officecfg/registry/data/org/openoffice/Office/UI/DrawImpressCommands.xcu
	sd/uiconfig/simpress/ui/photoalbum.ui

Change-Id: I68d2a3e00f8c55b909fe4d98aa3958188653390e
Reviewed-on: https://gerrit.libreoffice.org/3169Reviewed-by: 's avatarAndras Timar <atimar@suse.com>
Tested-by: 's avatarAndras Timar <atimar@suse.com>
üst 857adead
......@@ -195,4 +195,9 @@
<value oor:separator=";">vnd.sun.star.expand:$BRAND_BASE_DIR/share/config/soffice.cfg/simpress/transitions.xml;vnd.sun.star.expand:$BRAND_BASE_DIR/share/config/soffice.cfg/simpress/transitions-ogl.xml</value>
</prop>
</node>
<node oor:name="Pictures" oor:op="fuse" oor:mandatory="true">
<prop oor:name="Path">
<value>$(work)</value>
</prop>
</node>
</oor:component-data>
......@@ -55,7 +55,7 @@
</node>
<node oor:name=".uno:PhotoAlbumDialog" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Create Photo Album</value>
<value xml:lang="en-US">Photo Album</value>
</prop>
<prop oor:name="Properties" oor:type="xs:int">
<value>1</value>
......
......@@ -1594,5 +1594,22 @@
</group>
</group>
</group>
<group oor:name="Pictures">
<info>
<desc>
Contains configuration items form Impress Photo Album function.
</desc>
</info>
<prop oor:name="Path" oor:type="xs:string" oor:nillable="false">
<info>
<author>GM</author>
<desc>
Access path, where images were loaded last time.
The default is work directory.
</desc>
</info>
<value>$(work)</value>
</prop>
</group>
</component>
</oor:component-schema>
......@@ -297,6 +297,7 @@ interface SlideSorterView
SID_PHOTOALBUM
[
ExecMethod = FuTemporary ;
StateMethod = GetMenuState ;
]
}
......
......@@ -216,6 +216,7 @@ interface ImpressEditView : DrawView
SID_PHOTOALBUM
[
ExecMethod = FuTemporary ;
StateMethod = GetMenuState ;
]
}
......
......@@ -529,7 +529,8 @@ interface OutlineView
]
SID_PHOTOALBUM
[
ExecMethod = FuTemporary;
ExecMethod = FuTemporary ;
StateMethod = GetMenuState ;
]
}
......
......@@ -9,17 +9,17 @@
#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 <comphelper/configurationhelper.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/container/XNameAccess.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/text/XText.hpp>
#include <sfx2/filedlghelper.hxx>
#include <tools/urlobj.hxx>
......@@ -29,17 +29,13 @@
#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;
#include <svx/unoshape.hxx>
namespace sd
{
OUString SdPhotoAlbumDialog::sDirUrl;
SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc)
: ModalDialog(pWindow, "PhotoAlbumCreatorDialog", "modules/simpress/ui/photoalbum.ui"),
pDoc(pActDoc)
......@@ -58,18 +54,26 @@ SdPhotoAlbumDialog::SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc)
get(pInsTypeCombo, "opt_combo");
get(pASRCheck, "asr_check");
get(pFilenameLab, "filename_lab");
pCancelBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CancelHdl));
pCreateBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, CreateHdl));
pFileBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, FileHdl));
pTextBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, TextHdl));
pUpBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, UpHdl));
pUpBtn->Disable();
pDownBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, DownHdl));
pDownBtn->Disable();
pRemoveBtn->SetClickHdl(LINK(this, SdPhotoAlbumDialog, RemoveHdl));
pRemoveBtn->Disable();
pImagesLst->SetSelectHdl(LINK(this, SdPhotoAlbumDialog, SelectHdl));
mpGraphicFilter = new GraphicFilter;
mpGraphicFilter = new GraphicFilter;
sDirUrl = "";
pFileBtn->GrabFocus();
pImagesLst->Clear();
}
SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
......@@ -78,7 +82,7 @@ SdPhotoAlbumDialog::~SdPhotoAlbumDialog()
IMPL_LINK_NOARG(SdPhotoAlbumDialog, CancelHdl)
{
EndDialog(0);
Close();
return 0;
}
......@@ -95,9 +99,20 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl)
Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY );
Reference< lang::XMultiServiceFactory > xShapeFactory( pDoc->getUnoModel(), uno::UNO_QUERY );
// insert text to the first slide
// Create the title slide
Reference< drawing::XDrawPage > xTitleSlide = appendNewSlide(AUTOLAYOUT_TITLE, xDrawPages);
SdPage* pFirstSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
pFirstSlide->SetAutoLayout(AUTOLAYOUT_TITLE, sal_True);
SvtUserOptions aUserOptions;
SdrObject* pTitleObj = pFirstSlide->GetPresObj(PRESOBJ_TITLE, 0);
SvxShapeText* pTitleText = new SvxShapeText(pTitleObj);
pTitleText->SetShapeType("com.sun.star.presentation.TitleTextShape");
pTitleText->setString(OUString("Photoalbum\n"));
SdrObject* pTextObj = pFirstSlide->GetPresObj(PRESOBJ_TEXT, 0);
SvxShapeText* pTextShape = new SvxShapeText(pTextObj);
pTextShape->SetShapeType("com.sun.star.presentation.TextShape");
pTextShape->setString(OUString("Author: ") + aUserOptions.GetFullName());
Reference< XComponentContext > xContext(::comphelper::getProcessComponentContext());
Reference< graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(xContext));
......@@ -106,126 +121,431 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, CreateHdl)
OUString sOpt = pInsTypeCombo->GetEntry(pInsTypeCombo->GetSelectEntryPos());
if ( sOpt == "Fit to slide")
{
setFirstSlide(pFirstSlide);
OUString sUrl;
OUString* pData;
for( sal_Int16 i = 0; i < pImagesLst->GetEntryCount(); ++i )
{
OUString sUrl = pImagesLst->GetEntry( i );
pData = (OUString*) pImagesLst->GetEntryData(i);
sUrl = *pData;
if (sUrl != "Text Box")
{
::comphelper::NamedValueCollection aMediaProperties;
aMediaProperties.put( "URL", OUString( sUrl ) );
Reference< drawing::XDrawPage > xSlide = appendNewSlide(AUTOLAYOUT_NONE, xDrawPages);
Reference< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
Reference< graphic::XGraphic> xGraphic =
xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl, xProvider);
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< beans::XPropertySet > xSlideProps( xSlide, uno::UNO_QUERY );
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);
}
}
delete pData;
}
else if( sOpt == "1 image with title" )
{
setFirstSlide(pFirstSlide);
OUString sUrl;
OUString* pData;
for( sal_Int16 i = 0; i < pImagesLst->GetEntryCount(); ++i )
{
OUString sUrl = pImagesLst->GetEntry( i );
pData = (OUString*) pImagesLst->GetEntryData(i);
sUrl = *pData;
if ( sUrl != "Text Box" )
{
::comphelper::NamedValueCollection aMediaProperties;
aMediaProperties.put( "URL", OUString( sUrl ) );
Reference< graphic::XGraphic> xGraphic =
xProvider->queryGraphic( aMediaProperties.getPropertyValues() );
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::XDrawPage > xSlide;
Reference< container::XIndexAccess > xIndexAccess( xDrawPages, uno::UNO_QUERY );
xSlide = xDrawPages->insertNewByIndex( xIndexAccess->getCount() );
::awt::Size aPicSize(xShape->getSize());
::awt::Size aPageSize;
xSlideProps->getPropertyValue(
OUString("Width")) >>= aPageSize.Width;
xSlideProps->getPropertyValue(
OUString("Height")) >>= aPageSize.Height;
::awt::Point aPicPos;
aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
xShape->setSize(aPicSize);
xShape->setPosition(aPicPos);
xSlide->add(xShape);
SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
pSlide->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT, sal_True);
}
else // insert an empty slide, with centered text box
{
appendNewSlide(AUTOLAYOUT_ONLY_TEXT, xDrawPages);
}
}
delete pData;
}
else if( sOpt == "2 images" )
{
OUString sUrl1("");
OUString sUrl2("");
OUString* pData;
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
pData = (OUString*) pImagesLst->GetEntryData(i);
sUrl1 = pData ? OUString(*pData) : "";
// grab the right one
pData = (OUString*) pImagesLst->GetEntryData(i+1);
sUrl2 = pData ? OUString(*pData) : "";
if( sUrl1 == "Text Box" ) // create a 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()){} // nothing to do
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
);
uno::UNO_QUERY);
Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY );
xProps->setPropertyValue("Graphic", ::uno::Any(xGraphic));
::awt::Size aPicSize = xShape->getSize();
::awt::Point aPicPos;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( sUrl2 == "Text Box" ) // create a 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()){} // nothing to do
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 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
aPicPos.Y = aPageSize.Height/2 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
}
delete pData;
}
else if( sOpt == "4 images" )
{
OUString sUrl1("");
OUString sUrl2("");
OUString sUrl3("");
OUString sUrl4("");
OUString* pData;
for( sal_Int32 i = 0; i < pImagesLst->GetEntryCount(); i+=4 )
{
// 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;
aPicSize.Width = aPageSize.Width/2;
aPicSize.Height = aPageSize.Height/2;
// grab the upper left one
pData = (OUString*) pImagesLst->GetEntryData(i);
sUrl1 = pData ? OUString(*pData) : "";
// grab the upper right one
pData = (OUString*) pImagesLst->GetEntryData(i+1);
sUrl2 = pData ? OUString(*pData) : "";
// grab the lower left one
pData = (OUString*) pImagesLst->GetEntryData(i+2);
sUrl3 = pData ? OUString(*pData) : "";
// grab the lower right one
pData = (OUString*) pImagesLst->GetEntryData(i+3);
sUrl4 = pData ? OUString(*pData) : "";
if( sUrl1 == "Text Box" ) // create a 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/2-100)), sal_True);
}
else if( sUrl1.isEmpty()){} // nothing to do
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;
aPicPos.X = (aPageSize.Width - aPicSize.Width)/2;
aPicPos.Y = (aPageSize.Height - aPicSize.Height)/2;
if(pASRCheck->IsChecked())
{
// Resize the image, with keeping ASR
aPicSize = createASRSize(aPicSize, ::awt::Size(aPageSize.Width/2 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( sUrl2 == "Text Box" ) // create a 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/2-100)), sal_True);
}
else if( sUrl2.isEmpty()){} // nothing to do
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 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( sUrl3 == "Text Box" ) // create a Text Box
{
SdPage* pSlide = pDoc->GetSdPage( pDoc->GetSdPageCount(PK_STANDARD)-1, PK_STANDARD);
pSlide->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT, sal_True);
pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(100,aPageSize.Height/2-100), Point(aPageSize.Width/2-100, aPageSize.Height-100)), sal_True);
}
else // insert an empty slide, with centered text box
else if( sUrl3.isEmpty()){} // nothing to do
else
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl3, 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 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2);
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
if( sUrl4 == "Text Box" ) // create a 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);
pSlide->CreatePresObj(PRESOBJ_TEXT, sal_False, Rectangle(Point(aPageSize.Width/2 + 100,aPageSize.Height/2 - 100), Point(aPageSize.Width-100, aPageSize.Height-100)), sal_True);
}
else if( sUrl4.isEmpty()){} // nothing to do
else
{
Reference< graphic::XGraphic > xGraphic = createXGraphicFromUrl(sUrl4, 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 - 100, aPageSize.Height/2 - 100));
}
else
{
aPicSize.Width = aPageSize.Width/2 - 100;
aPicSize.Height = aPageSize.Height/2 - 100;
}
xShape->setSize(aPicSize);
aPicPos.X = (aPageSize.Width/4 - aPicSize.Width/2) + aPageSize.Width/2;
aPicPos.Y = aPageSize.Height/4 - aPicSize.Height/2 + aPageSize.Height/2;
xShape->setPosition(aPicPos);
xSlide->add(xShape);
}
}
delete pData;
}
else
{
InfoBox aInfo(this, OUString("Function is not implemented!"));
aInfo.Execute();
}
EndDialog(0);
EndDialog();
return 0;
}
return 0;
}
......@@ -236,8 +556,31 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
SFXWB_GRAPHIC | SFXWB_MULTISELECTION
);
// Read configuration
OUString sUrl(".");
Reference< XInterface > xCfg;
try
{
xCfg = ::comphelper::ConfigurationHelper::openConfig(
::comphelper::getProcessComponentContext(),
OUString("/org.openoffice.Office.Impress/"),
::comphelper::ConfigurationHelper::E_READONLY);
::comphelper::ConfigurationHelper::readRelativeKey(
xCfg,
OUString("Pictures"),
OUString("Path")) >>= sUrl;
}
catch(const Exception&)
{
OSL_FAIL("Could not find config for Create Photo Album function");
}
INetURLObject aFile( SvtPathOptions().GetPalettePath() );
if (sUrl != "")
aDlg.SetDisplayDirectory(sUrl);
else
aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
if ( aDlg.Execute() == ERRCODE_NONE )
......@@ -245,9 +588,47 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
Sequence< OUString > aFilesArr = aDlg.GetSelectedFiles();
if( aFilesArr.getLength() )
{
for ( sal_Int32 i = 0; i < aFilesArr.getLength(); ++i )
sUrl = aDlg.GetDisplayDirectory();
// Write out configuration
try
{
Reference< XInterface > xCfg = ::comphelper::ConfigurationHelper::openConfig(
::comphelper::getProcessComponentContext(),
OUString("/org.openoffice.Office.Impress/"),
::comphelper::ConfigurationHelper::E_STANDARD);
::comphelper::ConfigurationHelper::writeRelativeKey(
xCfg,
OUString("Pictures"),
OUString("Path"),
uno::makeAny(sUrl));
::comphelper::ConfigurationHelper::flush(xCfg);
}
catch(const Exception&)
{
pImagesLst->InsertEntry( aFilesArr[i] );
OSL_FAIL("Could not find config for Create Photo Album function");
}
if( aFilesArr.getLength() == 1)
{
pRemoveBtn->Enable();
pUpBtn->Disable();
pDownBtn->Disable();
}
else
{
pRemoveBtn->Enable();
pUpBtn->Enable();
pDownBtn->Enable();
}
for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
{
// Store full path, show filename only
OUString sFileName = aFilesArr[i].copy(aFilesArr[i].lastIndexOf("/")).replaceAll("/","");
sal_Int16 nPos = pImagesLst->InsertEntry( sFileName );
pImagesLst->SetEntryData(nPos, (void*)new OUString(aFilesArr[i]));
}
}
}
......@@ -256,8 +637,22 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
IMPL_LINK_NOARG(SdPhotoAlbumDialog, TextHdl)
{
sal_uInt16 nInsertPos = pImagesLst->GetSelectEntryPos() + 1;
pImagesLst->InsertEntry( OUString("Text Box"), nInsertPos);
sal_Int16 nPos;
sal_Int16 nInsertPos = pImagesLst->GetSelectEntryPos();
if (nInsertPos < 0)
nPos = pImagesLst->InsertEntry( OUString("Text Box"));
else
nPos = pImagesLst->InsertEntry( OUString("Text Box"), nInsertPos);
OUString sStr("Text Box");
pImagesLst->SetEntryData(nPos, (void*)new OUString(sStr));
if(pImagesLst->GetEntryCount() >= 1)
{
pRemoveBtn->Enable();
pUpBtn->Disable();
pDownBtn->Disable();
}
return 0;
}
......@@ -267,15 +662,35 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl)
&& pImagesLst->GetSelectEntryPos() != 0)
{
OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) );
// actual data
OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
OUString sAct(*pActData);
sal_uInt16 nActPos = pImagesLst->GetSelectEntryPos();
OUString sUpperEntry( pImagesLst->GetEntry(nActPos - 1) );
// upper data
OUString* pUpperData = (OUString*) pImagesLst->GetEntryData(nActPos - 1);
OUString sUpper(*pUpperData);
pImagesLst->RemoveEntry( sActEntry );
pImagesLst->RemoveEntry( sUpperEntry );
pImagesLst->InsertEntry( sActEntry, nActPos - 1 );
pImagesLst->SetEntryData( nActPos - 1, (void*) new OUString(sAct));
pImagesLst->InsertEntry( sUpperEntry, nActPos );
pImagesLst->SetEntryData( nActPos, (void*) new OUString(sUpper));
pImagesLst->SelectEntryPos(nActPos - 1);
pDownBtn->Enable();
}
if(pImagesLst->GetSelectEntryPos() == 0)
{
pDownBtn->Enable();
pUpBtn->Disable();
}
return 0;
}
......@@ -286,15 +701,34 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl)
if (pImagesLst->GetEntry(nActPos + 1) != OUString("") )
{
OUString sActEntry( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) );
OUString* pActData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
OUString sAct(*pActData);
OUString sDownEntry( pImagesLst->GetEntry(nActPos + 1) );
OUString* pDownData = (OUString*) pImagesLst->GetEntryData(nActPos + 1);
OUString sDown(*pDownData);
pImagesLst->RemoveEntry( sActEntry );
pImagesLst->RemoveEntry( sDownEntry );
pImagesLst->InsertEntry( sDownEntry, nActPos );
pImagesLst->SetEntryData( nActPos, (void*) new OUString(sAct));
pImagesLst->InsertEntry( sActEntry, nActPos + 1 );
pImagesLst->SetEntryData( nActPos + 1, (void*) new OUString(sDown));
pImagesLst->SelectEntryPos(nActPos + 1);
}
if(pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos() + 1) != OUString(""))
{
pDownBtn->Enable();
pUpBtn->Enable();
}
else
{
pDownBtn->Disable();
}
return 0;
}
......@@ -302,17 +736,56 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl)
IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl)
{
pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
pImg->SetImage(Image());
pFilenameLab->SetText("");
if(pImagesLst->GetEntryCount() >= 1)
{
pRemoveBtn->Enable();
pUpBtn->Disable();
pDownBtn->Disable();
}
else
{
pRemoveBtn->Disable();
pUpBtn->Disable();
pDownBtn->Disable();
}
return 0;
}
IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
{
OUString sImgUrl( pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos()) );
if (sImgUrl != OUString("Text Box") )
OUString* pData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
OUString sImgUrl = pData ? OUString(*pData) : "";
// Some UI functionality: if you select the first/last item in the list,
// the Up/Down button gets enabled/diabled (meaning: you cannot move up/down the item)
// disable/enable moving up
if(pImagesLst->GetSelectEntryPos() == 0)
{
pUpBtn->Disable();
}
else
{
pUpBtn->Enable();
}
// disable/enable moving down
if(pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos() + 1) == OUString(""))
{
pDownBtn->Disable();
}
else
{
pDownBtn->Enable();
}
if (sImgUrl != "Text Box")
{
GraphicFilter aCurFilter;
Graphic aGraphic;
INetURLObject aURLObj( sImgUrl );
pFilenameLab->SetText(sImgUrl);
sal_uInt16 nFilter = GRFILTER_FORMAT_DONTKNOW;
......@@ -342,7 +815,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
Bitmap aBmp = aGraphic.GetBitmap();
sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
sal_Int32 nPrevWidth = 150;
sal_Int32 nPrevWidth = 200;
sal_Int32 nPrewHeight = 150;
double nXRatio = (double) nPrevWidth / nBmpWidth;
......@@ -358,22 +831,84 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
else
{
pImg->SetImage(Image());
pFilenameLab->SetText("");
}
return 0;
}
void SdPhotoAlbumDialog::setFirstSlide(SdPage* pFirstSlide)
Reference< drawing::XDrawPage > SdPhotoAlbumDialog::appendNewSlide(AutoLayout aLayout,
Reference< drawing::XDrawPages > xDrawPages
)
{
SdrTextObj* pTitleObj; // title
pTitleObj = dynamic_cast< SdrTextObj* >(pFirstSlide->GetPresObj(PRESOBJ_TITLE));
pFirstSlide->SetObjText(pTitleObj, NULL, PRESOBJ_TITLE, OUString("Photoalbum"));
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;
}
SdrTextObj* pAuthorObj; // author's full name
pAuthorObj = dynamic_cast< SdrTextObj* >(pFirstSlide->GetPresObj(PRESOBJ_TEXT));
awt::Size SdPhotoAlbumDialog::createASRSize(const awt::Size& aPicSize, const awt::Size& aMaxSize)
{
double resizeWidth = aPicSize.Width;
double resizeHeight = aPicSize.Height;
double aspect = resizeWidth/resizeHeight;
SvtUserOptions aUserOptions;
pFirstSlide->SetObjText(pAuthorObj, NULL, PRESOBJ_TEXT, OUString("Author: ") + aUserOptions.GetFullName());
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);
}
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;
}
short SdPhotoAlbumDialog::Execute()
{
return ModalDialog::Execute();
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -22,11 +22,22 @@
#include <vcl/field.hxx>
#include <vcl/graphicfilter.hxx>
#include <svx/svdotext.hxx>
#include <svx/svdobj.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>
#include <com/sun/star/configuration/theDefaultProvider.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
{
......@@ -36,7 +47,10 @@ public:
SdPhotoAlbumDialog(Window* pWindow, SdDrawDocument* pActDoc);
~SdPhotoAlbumDialog();
virtual short Execute();
private:
static OUString sDirUrl;
CancelButton* pCancelBtn;
PushButton* pCreateBtn;
......@@ -51,6 +65,10 @@ private:
ListBox* pInsTypeCombo;
CheckBox* pASRCheck;
FixedText* pFilenameLab;
SdDrawDocument* pDoc;
GraphicFilter* mpGraphicFilter;
......@@ -65,10 +83,21 @@ private:
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);
};
}
} // end of namespace sd
#endif // _SD_PHOTOALBUMDIALOG_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -688,13 +688,17 @@ void DrawViewShell::FuTemp04(SfxRequest& rReq)
case SID_PHOTOALBUM:
{
SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
VclAbstractDialog* pDlg = pFact ? pFact->CreateSdPhotoAlbumDialog(GetActiveWindow(),
GetDoc()
) : 0;
VclAbstractDialog* pDlg = pFact ? pFact->CreateSdPhotoAlbumDialog(
GetActiveWindow(),
GetDoc()) : 0;
if (pDlg)
{
pDlg->Execute();
delete pDlg;
}
Cancel();
rReq.Ignore ();
}
break;
......
......@@ -194,6 +194,7 @@
<menu:menu menu:id=".uno:GraphicMenu">
<menu:menupopup>
<menu:menuitem menu:id=".uno:InsertGraphic"/>
<menu:menuitem menu:id=".uno:PhotoAlbumDialog"/>
<menu:menu menu:id=".uno:Scan">
<menu:menupopup>
<menu:menuitem menu:id=".uno:TwainSelect"/>
......@@ -215,8 +216,6 @@
<menu:menuitem menu:id=".uno:InsertObjectFloatingFrame"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ImportFromFile"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:PhotoAlbumDialog"/>
</menu:menupopup>
</menu:menu>
<menu:menu menu:id=".uno:FormatMenu">
......
......@@ -86,7 +86,7 @@
<property name="row_spacing">6</property>
<child>
<object class="GtkImage" id="preview_img">
<property name="width_request">150</property>
<property name="width_request">200</property>
<property name="height_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -295,6 +295,25 @@
<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="active">True</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>
......@@ -324,6 +343,18 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="filename_lab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="justify">right</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
......@@ -395,7 +426,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
......
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