summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-01-31 09:57:37 +0000
committerCaolán McNamara <caolanm@redhat.com>2014-01-31 21:21:37 +0000
commit344a1abd2f28f4556746f72a06358a08dd23abbe (patch)
tree299581c3fe10457dbb9809e74a0f1f491e0be40a /cui
parentb0da0f644330b78a2c11842a90ff71fe95d8419d (diff)
introduce a layout aware GraphicFilterDialog
Change-Id: I932e4be6b7f4a2717748de561c424302ef429d63
Diffstat (limited to 'cui')
-rw-r--r--cui/source/dialogs/cuigrfflt.cxx148
-rw-r--r--cui/source/inc/cuigrfflt.hxx62
2 files changed, 198 insertions, 12 deletions
diff --git a/cui/source/dialogs/cuigrfflt.cxx b/cui/source/dialogs/cuigrfflt.cxx
index d7ac4bafb91f..06381de76367 100644
--- a/cui/source/dialogs/cuigrfflt.cxx
+++ b/cui/source/dialogs/cuigrfflt.cxx
@@ -29,10 +29,6 @@
#include <cuires.hrc>
#include <svx/dialogs.hrc>
-// --------------------------------------
-// - oldGraphicFilterDialog::PreviewWindow -
-// --------------------------------------
-
oldGraphicFilterDialog::PreviewWindow::PreviewWindow( Window* pParent, const ResId& rResId ) :
Control( pParent, rResId )
{
@@ -74,10 +70,6 @@ void oldGraphicFilterDialog::PreviewWindow::SetGraphic( const Graphic& rGraphic
Paint( Rectangle( Point(), GetOutputSizePixel() ) );
}
-// -----------------------
-// - oldGraphicFilterDialog -
-// -----------------------
-
oldGraphicFilterDialog::oldGraphicFilterDialog( Window* pParent, const ResId& rResId, const Graphic& rGraphic ) :
ModalDialog ( pParent, rResId ),
maModifyHdl ( LINK( this, oldGraphicFilterDialog, ImplModifyHdl ) ),
@@ -151,6 +143,146 @@ IMPL_LINK_NOARG(oldGraphicFilterDialog, ImplModifyHdl)
return 0;
}
+GraphicFilterDialog::PreviewWindow::PreviewWindow(Window* pParent,
+ const WinBits nStyle)
+ : Control(pParent, nStyle)
+ , mpOrigGraphic(NULL)
+ , mfScaleX(0.0)
+ , mfScaleY(0.0)
+{
+}
+
+Size GraphicFilterDialog::PreviewWindow::GetOptimalSize() const
+{
+ return LogicToPixel(Size(81, 73), MAP_APPFONT);
+}
+
+// -----------------------------------------------------------------------------
+
+void GraphicFilterDialog::PreviewWindow::Paint( const Rectangle& rRect )
+{
+ Control::Paint( rRect );
+
+ const Size aOutputSize( GetOutputSizePixel() );
+
+ if( maPreview.IsAnimated() )
+ {
+ const Size aGraphicSize( LogicToPixel( maPreview.GetPrefSize(), maPreview.GetPrefMapMode() ) );
+ const Point aGraphicPosition( ( aOutputSize.Width() - aGraphicSize.Width() ) >> 1,
+ ( aOutputSize.Height() - aGraphicSize.Height() ) >> 1 );
+ maPreview.StartAnimation( this, aGraphicPosition, aGraphicSize );
+ }
+ else
+ {
+ const Size aGraphicSize( maPreview.GetSizePixel() );
+ const Point aGraphicPosition( ( aOutputSize.Width() - aGraphicSize.Width() ) >> 1,
+ ( aOutputSize.Height() - aGraphicSize.Height() ) >> 1 );
+ maPreview.Draw( this, aGraphicPosition, aGraphicSize );
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void GraphicFilterDialog::PreviewWindow::SetPreview( const Graphic& rGraphic )
+{
+ maPreview = rGraphic;
+
+ if( maPreview.IsAnimated() || maPreview.IsTransparent() )
+ Invalidate();
+ else
+ Paint( Rectangle( Point(), GetOutputSizePixel() ) );
+}
+
+void GraphicFilterDialog::PreviewWindow::ScaleImageToFit()
+{
+ if (!mpOrigGraphic)
+ return;
+
+ const Size aPreviewSize( GetOutputSizePixel() );
+ Size aSizePixel(LogicToPixel(mpOrigGraphic->GetPrefSize(),
+ mpOrigGraphic->GetPrefMapMode()));
+ Size aGrfSize(aSizePixel);
+
+ if( mpOrigGraphic->GetType() == GRAPHIC_BITMAP &&
+ aPreviewSize.Width() && aPreviewSize.Height() &&
+ aGrfSize.Width() && aGrfSize.Height() )
+ {
+ const double fGrfWH = (double) aGrfSize.Width() / aGrfSize.Height();
+ const double fPreWH = (double) aPreviewSize.Width() / aPreviewSize.Height();
+
+ if( fGrfWH < fPreWH )
+ {
+ aGrfSize.Width() = (long) ( aPreviewSize.Height() * fGrfWH );
+ aGrfSize.Height() = aPreviewSize.Height();
+ }
+ else
+ {
+ aGrfSize.Width() = aPreviewSize.Width();
+ aGrfSize.Height() = (long) ( aPreviewSize.Width() / fGrfWH );
+ }
+
+ mfScaleX = (double) aGrfSize.Width() / aSizePixel.Width();
+ mfScaleY = (double) aGrfSize.Height() / aSizePixel.Height();
+
+ if( !mpOrigGraphic->IsAnimated() )
+ {
+ BitmapEx aBmpEx( mpOrigGraphic->GetBitmapEx() );
+
+ if( aBmpEx.Scale( aGrfSize, BMP_SCALE_DEFAULT ) )
+ maPreview = aBmpEx;
+ }
+ }
+}
+
+void GraphicFilterDialog::PreviewWindow::Resize()
+{
+ Control::Resize();
+ ScaleImageToFit();
+}
+
+GraphicFilterDialog::GraphicFilterDialog(Window* pParent,
+ const OString& rID, const OUString& rUIXMLDescription,
+ const Graphic& rGraphic)
+ : ModalDialog(pParent, rID, rUIXMLDescription)
+ , maModifyHdl(LINK( this, GraphicFilterDialog, ImplModifyHdl))
+ , maSizePixel(LogicToPixel(rGraphic.GetPrefSize(),
+ rGraphic.GetPrefMapMode()))
+{
+ bIsBitmap = rGraphic.GetType() == GRAPHIC_BITMAP;
+
+ get(mpPreview, "preview");
+ mpPreview->init(&rGraphic);
+
+ maTimer.SetTimeoutHdl( LINK( this, GraphicFilterDialog, ImplPreviewTimeoutHdl ) );
+ maTimer.SetTimeout( 100 );
+ ImplModifyHdl( NULL );
+}
+
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK_NOARG(GraphicFilterDialog, ImplPreviewTimeoutHdl)
+{
+ maTimer.Stop();
+ mpPreview->SetPreview(GetFilteredGraphic(mpPreview->GetScaledOriginal(),
+ mpPreview->GetScaleX(), mpPreview->GetScaleY()));
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+IMPL_LINK_NOARG(GraphicFilterDialog, ImplModifyHdl)
+{
+ if (bIsBitmap)
+ {
+ maTimer.Stop();
+ maTimer.Start();
+ }
+
+ return 0;
+}
+
// ----------------
// - FilterMosaic -
// ----------------
diff --git a/cui/source/inc/cuigrfflt.hxx b/cui/source/inc/cuigrfflt.hxx
index b4fcfac12fa1..04d8da269bd7 100644
--- a/cui/source/inc/cuigrfflt.hxx
+++ b/cui/source/inc/cuigrfflt.hxx
@@ -32,10 +32,6 @@
#include <svx/dlgctrl.hxx>
#include <svx/rectenum.hxx>
-// -----------------------
-// - oldGraphicFilterDialog -
-// -----------------------
-
class oldGraphicFilterDialog : public ModalDialog
{
private:
@@ -84,6 +80,64 @@ public:
virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) = 0;
};
+class GraphicFilterDialog : public ModalDialog
+{
+private:
+
+ class PreviewWindow : public Control
+ {
+ private:
+ const Graphic* mpOrigGraphic;
+ Graphic maScaledOrig;
+ Graphic maPreview;
+ double mfScaleX;
+ double mfScaleY;
+
+ virtual void Paint(const Rectangle& rRect);
+ virtual void Resize();
+ virtual Size GetOptimalSize() const;
+
+ void ScaleImageToFit();
+
+ public:
+
+ PreviewWindow(Window* pParent, WinBits nStyle);
+ void init(const Graphic *pOrigGraphic)
+ {
+ mpOrigGraphic = pOrigGraphic;
+ ScaleImageToFit();
+ }
+
+ void SetPreview(const Graphic& rGraphic);
+ const Graphic& GetScaledOriginal() const { return maScaledOrig; }
+ double GetScaleX() const { return mfScaleX; }
+ double GetScaleY() const { return mfScaleY; }
+ };
+
+private:
+
+ Timer maTimer;
+ Link maModifyHdl;
+ Size maSizePixel;
+ bool bIsBitmap;
+
+ DECL_LINK(ImplPreviewTimeoutHdl, void *);
+ DECL_LINK( ImplModifyHdl, void* p );
+
+protected:
+ PreviewWindow* mpPreview;
+
+ const Link& GetModifyHdl() const { return maModifyHdl; }
+ const Size& GetGraphicSizePixel() const { return maSizePixel; }
+
+public:
+
+ GraphicFilterDialog(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const Graphic& rGraphic);
+
+ virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) = 0;
+};
+
+
// -------------------------
// - GraphicFilterSmooth -
// -------------------------