From 6c971a4462c245c8e9f5b46323d0199c2a8cc79e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Fri, 13 Apr 2007 14:42:37 +0000 Subject: [PATCH] ZoomIn/ZoomOut/ActualSize actions. svn path=/branches/work/kwin_composite/; revision=653520 --- effects/zoom.cpp | 40 +++++++++++++++++++++++++++++++++++++--- effects/zoom.h | 7 ++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/effects/zoom.cpp b/effects/zoom.cpp index 1644b71c30..56dea8ec45 100644 --- a/effects/zoom.cpp +++ b/effects/zoom.cpp @@ -10,6 +10,10 @@ License. See the file "COPYING" for the exact licensing terms. #include "zoom.h" +#include +#include +#include + namespace KWin { @@ -17,8 +21,16 @@ KWIN_EFFECT( Zoom, ZoomEffect ) ZoomEffect::ZoomEffect() : zoom( 1 ) - , target_zoom( 2 ) + , target_zoom( 1 ) { + KActionCollection* actionCollection = new KActionCollection( this ); + KAction* a; + a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomIn, this, SLOT( zoomIn()))); + a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Equal)); + a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomOut, this, SLOT( zoomOut()))); + a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Minus)); + a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ActualSize, this, SLOT( actualSize()))); + a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_0)); } void ZoomEffect::prePaintScreen( int* mask, QRegion* region, int time ) @@ -27,9 +39,9 @@ void ZoomEffect::prePaintScreen( int* mask, QRegion* region, int time ) { double diff = time / 500.0; if( target_zoom > zoom ) - zoom = qMin( zoom + diff, target_zoom ); + zoom = qMin( zoom * qMax( 1 + diff, 1.2 ), target_zoom ); else - zoom = qMax( zoom - diff, target_zoom ); + zoom = qMax( zoom * qMin( 1 - diff, 0.8 ), target_zoom ); } if( zoom != 1.0 ) *mask |= PAINT_SCREEN_TRANSFORMED; @@ -57,4 +69,26 @@ void ZoomEffect::postPaintScreen() effects->postPaintScreen(); } +void ZoomEffect::zoomIn() + { + target_zoom *= 1.2; + effects->addRepaintFull(); + } + +void ZoomEffect::zoomOut() + { + target_zoom /= 1.2; + if( target_zoom < 1 ) + target_zoom = 1; + effects->addRepaintFull(); + } + +void ZoomEffect::actualSize() + { + target_zoom = 1; + effects->addRepaintFull(); + } + } // namespace + +#include "zoom.moc" diff --git a/effects/zoom.h b/effects/zoom.h index 61723a9e1c..44eda47cac 100644 --- a/effects/zoom.h +++ b/effects/zoom.h @@ -17,13 +17,18 @@ namespace KWin { class ZoomEffect - : public Effect + : public QObject, public Effect { + Q_OBJECT public: ZoomEffect(); virtual void prePaintScreen( int* mask, QRegion* region, int time ); virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); virtual void postPaintScreen(); + private slots: + void zoomIn(); + void zoomOut(); + void actualSize(); private: double zoom; double target_zoom;