1
/*****************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
7
You can Freely distribute this program under the GNU General Public
8
License. See the file "COPYING" for the exact licensing terms.
9
******************************************************************/
12
#include "lookingglass.h"
14
#include <kwinglutils.h>
16
#include <kactioncollection.h>
25
KWIN_EFFECT( lookingglass, LookingGlassEffect )
26
KWIN_EFFECT_SUPPORTED( lookingglass, ShaderEffect::supported() )
29
LookingGlassEffect::LookingGlassEffect() : QObject(), ShaderEffect("lookingglass")
34
KActionCollection* actionCollection = new KActionCollection( this );
36
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomIn, this, SLOT( zoomIn())));
37
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Plus));
38
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ZoomOut, this, SLOT( zoomOut())));
39
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Minus));
40
a = static_cast< KAction* >( actionCollection->addAction( KStandardAction::ActualSize, this, SLOT( toggle())));
41
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_0));
42
radius = 200; // TODO config option
45
void LookingGlassEffect::toggle()
47
if( target_zoom == 1.0f )
54
void LookingGlassEffect::zoomIn()
56
target_zoom = qMin(7.0f, target_zoom + 0.5f);
58
effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
61
void LookingGlassEffect::zoomOut()
69
effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
72
void LookingGlassEffect::prePaintScreen( ScreenPrePaintData& data, int time )
74
if( zoom != target_zoom )
76
float diff = time / 500.0f;
77
if( target_zoom > zoom )
78
zoom = qMin( zoom * qMax( 1.0f + diff, 1.2f ), target_zoom );
80
zoom = qMax( zoom * qMin( 1.0f - diff, 0.8f ), target_zoom );
81
kDebug() << "zoom is now " << zoom;
82
radius = qBound(200.0f, 200.0f * zoom, 500.0f);
87
shader()->setUniform("zoom", zoom);
88
shader()->setUniform("radius", (float)radius);
96
effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
99
ShaderEffect::prePaintScreen( data, time );
102
void LookingGlassEffect::mouseChanged( const QPoint& pos, const QPoint& old, Qt::MouseButtons, Qt::KeyboardModifiers )
104
if( pos != old && isEnabled() )
106
effects->addRepaint( pos.x() - radius, pos.y() - radius, 2*radius, 2*radius );
107
effects->addRepaint( old.x() - radius, old.y() - radius, 2*radius, 2*radius );
113
#include "lookingglass.moc"