diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-11-28 16:52:14 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-11-29 09:52:26 +0100 |
commit | 62623f7604df0437316c101803098760f4fe4651 (patch) | |
tree | 7ee5c164a22af37302fcefe36d9c385398af1719 /svx/source | |
parent | 7eaaf96e17c14ac49f98da9722a06c0c95f0c5c0 (diff) |
weld GalleryFilesPage
Change-Id: I5fa399144fb12bb19c3b88bf99f99dad6a64e052
Reviewed-on: https://gerrit.libreoffice.org/64188
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/gallery2/galctrl.cxx | 86 |
1 files changed, 84 insertions, 2 deletions
diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx index af00c3fd15e0..6e68f49cb644 100644 --- a/svx/source/gallery2/galctrl.cxx +++ b/svx/source/gallery2/galctrl.cxx @@ -51,8 +51,6 @@ GalleryPreview::GalleryPreview(vcl::Window* pParent, WinBits nStyle, GalleryThem InitSettings(); } -VCL_BUILDER_FACTORY_CONSTRUCTOR(GalleryPreview, WB_TABSTOP) - Size GalleryPreview::GetOptimalSize() const { return LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont)); @@ -257,6 +255,90 @@ void GalleryPreview::PreviewMedia( const INetURLObject& rURL ) #endif } +SvxGalleryPreview::SvxGalleryPreview() +{ +} + +void SvxGalleryPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea) +{ + CustomWidgetController::SetDrawingArea(pDrawingArea); + Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont))); + pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); + pDrawingArea->set_help_id(HID_GALLERY_WINDOW); +} + +bool SvxGalleryPreview::SetGraphic( const INetURLObject& _aURL ) +{ + bool bRet = true; + Graphic aGraphic; +#if HAVE_FEATURE_AVMEDIA + if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ), "" ) ) + { + aGraphic = BitmapEx(RID_SVXBMP_GALLERY_MEDIA); + } + else +#endif + { + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + GalleryProgress aProgress( &rFilter ); + if( rFilter.ImportGraphic( aGraphic, _aURL ) ) + bRet = false; + } + + SetGraphic( aGraphic ); + Invalidate(); + return bRet; +} + +bool SvxGalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const +{ + const Size aWinSize(GetOutputSizePixel()); + Size aNewSize(GetDrawingArea()->get_ref_device().LogicToPixel(rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode())); + bool bRet = false; + + if( aNewSize.Width() && aNewSize.Height() ) + { + // scale to fit window + const double fGrfWH = static_cast<double>(aNewSize.Width()) / aNewSize.Height(); + const double fWinWH = static_cast<double>(aWinSize.Width()) / aWinSize.Height(); + + if ( fGrfWH < fWinWH ) + { + aNewSize.setWidth( static_cast<long>( aWinSize.Height() * fGrfWH ) ); + aNewSize.setHeight( aWinSize.Height() ); + } + else + { + aNewSize.setWidth( aWinSize.Width() ); + aNewSize.setHeight( static_cast<long>( aWinSize.Width() / fGrfWH) ); + } + + const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1, + ( aWinSize.Height() - aNewSize.Height() ) >> 1 ); + + rResultRect = tools::Rectangle( aNewPos, aNewSize ); + bRet = true; + } + + return bRet; +} + +void SvxGalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) +{ + rRenderContext.SetBackground(Wallpaper(GALLERY_BG_COLOR)); + + if (ImplGetGraphicCenterRect(aGraphicObj.GetGraphic(), aPreviewRect)) + { + const Point aPos( aPreviewRect.TopLeft() ); + const Size aSize( aPreviewRect.GetSize() ); + + if( aGraphicObj.IsAnimated() ) + aGraphicObj.StartAnimation(&rRenderContext, aPos, aSize); + else + aGraphicObj.Draw(&rRenderContext, aPos, aSize); + } +} + static void drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize) { |