Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kwin / effects / zoom.cpp
blob8a3ea5b9b97648afd4ef7ae21f116e06a5c13947
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "zoom.h"
23 #include <kaction.h>
24 #include <kactioncollection.h>
25 #include <kstandardaction.h>
27 namespace KWin
30 KWIN_EFFECT( zoom, ZoomEffect )
32 ZoomEffect::ZoomEffect()
33 : zoom( 1 )
34 , target_zoom( 1 )
36 KActionCollection* actionCollection = new KActionCollection( this );
37 KAction* a;
38 a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomIn, this, SLOT( zoomIn())));
39 a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Equal));
40 a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomOut, this, SLOT( zoomOut())));
41 a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Minus));
42 a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ActualSize, this, SLOT( actualSize())));
43 a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_0));
46 void ZoomEffect::prePaintScreen( ScreenPrePaintData& data, int time )
48 if( zoom != target_zoom )
50 double diff = time / 500.0;
51 if( target_zoom > zoom )
52 zoom = qMin( zoom * qMax( 1 + diff, 1.2 ), target_zoom );
53 else
54 zoom = qMax( zoom * qMin( 1 - diff, 0.8 ), target_zoom );
56 if( zoom != 1.0 )
57 data.mask |= PAINT_SCREEN_TRANSFORMED;
58 effects->prePaintScreen( data, time );
61 void ZoomEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
63 if( zoom != 1.0 )
65 data.xScale *= zoom;
66 data.yScale *= zoom;
67 QPoint cursor = cursorPos();
68 // set the position so that the cursor is in the same position in the scaled view
69 data.xTranslate = - int( cursor.x() * ( zoom - 1 ));
70 data.yTranslate = - int( cursor.y() * ( zoom - 1 ));
72 effects->paintScreen( mask, region, data );
75 void ZoomEffect::postPaintScreen()
77 if( zoom != target_zoom )
78 effects->addRepaintFull();
79 effects->postPaintScreen();
82 void ZoomEffect::zoomIn()
84 target_zoom *= 1.2;
85 effects->addRepaintFull();
88 void ZoomEffect::zoomOut()
90 target_zoom /= 1.2;
91 if( target_zoom < 1 )
92 target_zoom = 1;
93 effects->addRepaintFull();
96 void ZoomEffect::actualSize()
98 target_zoom = 1;
99 effects->addRepaintFull();
102 void ZoomEffect::mouseChanged( const QPoint& pos, const QPoint& old, Qt::MouseButtons,
103 Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers )
105 if( pos != old && zoom != 1 )
106 effects->addRepaintFull();
109 } // namespace
111 #include "zoom.moc"