2006-12-03 13:36:40 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "zoom.h"
|
|
|
|
|
2007-04-13 14:42:37 +00:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kstandardaction.h>
|
|
|
|
|
2007-04-05 12:07:35 +00:00
|
|
|
namespace KWin
|
2006-12-03 13:36:40 +00:00
|
|
|
{
|
|
|
|
|
2007-04-13 10:08:18 +00:00
|
|
|
KWIN_EFFECT( Zoom, ZoomEffect )
|
|
|
|
|
2007-02-04 22:19:17 +00:00
|
|
|
ZoomEffect::ZoomEffect()
|
2006-12-03 13:36:40 +00:00
|
|
|
: zoom( 1 )
|
2007-04-13 14:42:37 +00:00
|
|
|
, target_zoom( 1 )
|
2006-12-03 13:36:40 +00:00
|
|
|
{
|
2007-04-13 14:42:37 +00:00
|
|
|
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));
|
2006-12-03 13:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ZoomEffect::prePaintScreen( int* mask, QRegion* region, int time )
|
|
|
|
{
|
|
|
|
if( zoom != target_zoom )
|
|
|
|
{
|
2006-12-04 18:29:16 +00:00
|
|
|
double diff = time / 500.0;
|
2006-12-03 13:36:40 +00:00
|
|
|
if( target_zoom > zoom )
|
2007-04-13 14:42:37 +00:00
|
|
|
zoom = qMin( zoom * qMax( 1 + diff, 1.2 ), target_zoom );
|
2006-12-03 13:36:40 +00:00
|
|
|
else
|
2007-04-13 14:42:37 +00:00
|
|
|
zoom = qMax( zoom * qMin( 1 - diff, 0.8 ), target_zoom );
|
2006-12-03 13:36:40 +00:00
|
|
|
}
|
|
|
|
if( zoom != 1.0 )
|
2007-04-11 15:22:36 +00:00
|
|
|
*mask |= PAINT_SCREEN_TRANSFORMED;
|
2006-12-03 13:36:40 +00:00
|
|
|
effects->prePaintScreen( mask, region, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoomEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
|
|
|
|
{
|
|
|
|
if( zoom != 1.0 )
|
|
|
|
{
|
|
|
|
data.xScale *= zoom;
|
|
|
|
data.yScale *= zoom;
|
2007-01-05 17:45:54 +00:00
|
|
|
QPoint cursor = cursorPos();
|
2006-12-03 13:36:40 +00:00
|
|
|
// set the position so that the cursor is in the same position in the scaled view
|
|
|
|
data.xTranslate = - int( cursor.x() * ( zoom - 1 ));
|
|
|
|
data.yTranslate = - int( cursor.y() * ( zoom - 1 ));
|
|
|
|
}
|
|
|
|
effects->paintScreen( mask, region, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoomEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( zoom != target_zoom )
|
2007-04-11 15:22:36 +00:00
|
|
|
effects->addRepaintFull();
|
2006-12-03 13:36:40 +00:00
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2007-04-13 14:42:37 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2007-04-14 16:10:58 +00:00
|
|
|
void ZoomEffect::cursorMoved( const QPoint&, Qt::MouseButtons )
|
|
|
|
{
|
|
|
|
if( zoom != 1 )
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
2006-12-03 13:36:40 +00:00
|
|
|
} // namespace
|
2007-04-13 14:42:37 +00:00
|
|
|
|
|
|
|
#include "zoom.moc"
|