~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kwin/effects/lookingglass.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
 
6
 
 
7
You can Freely distribute this program under the GNU General Public
 
8
License. See the file "COPYING" for the exact licensing terms.
 
9
******************************************************************/
 
10
 
 
11
 
 
12
#include "lookingglass.h"
 
13
 
 
14
#include <kwinglutils.h>
 
15
 
 
16
#include <kactioncollection.h>
 
17
#include <kaction.h>
 
18
#include <klocale.h>
 
19
#include <kdebug.h>
 
20
 
 
21
 
 
22
namespace KWin
 
23
{
 
24
 
 
25
KWIN_EFFECT( lookingglass, LookingGlassEffect )
 
26
KWIN_EFFECT_SUPPORTED( lookingglass, ShaderEffect::supported() )
 
27
 
 
28
 
 
29
LookingGlassEffect::LookingGlassEffect() : QObject(), ShaderEffect("lookingglass")
 
30
    {
 
31
    zoom = 1.0f;
 
32
    target_zoom = 1.0f;
 
33
 
 
34
    KActionCollection* actionCollection = new KActionCollection( this );
 
35
    KAction* a;
 
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
 
43
    }
 
44
 
 
45
void LookingGlassEffect::toggle()
 
46
    {
 
47
    if( target_zoom == 1.0f )
 
48
        target_zoom = 2.0f;
 
49
    else
 
50
        target_zoom = 1.0f;
 
51
    setEnabled( true );
 
52
    }
 
53
 
 
54
void LookingGlassEffect::zoomIn()
 
55
    {
 
56
    target_zoom = qMin(7.0f, target_zoom + 0.5f);
 
57
    setEnabled( true );
 
58
    effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
 
59
    }
 
60
 
 
61
void LookingGlassEffect::zoomOut()
 
62
    {
 
63
    target_zoom -= 0.5;
 
64
    if( target_zoom < 1 )
 
65
        {
 
66
        target_zoom = 1;
 
67
        setEnabled( false );
 
68
        }
 
69
    effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
 
70
    }
 
71
 
 
72
void LookingGlassEffect::prePaintScreen( ScreenPrePaintData& data, int time )
 
73
    {
 
74
    if( zoom != target_zoom )
 
75
        {
 
76
        float diff = time / 500.0f;
 
77
        if( target_zoom > zoom )
 
78
            zoom = qMin( zoom * qMax( 1.0f + diff, 1.2f ), target_zoom );
 
79
        else
 
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);
 
83
 
 
84
        if( zoom > 1.0f )
 
85
            {
 
86
            shader()->bind();
 
87
            shader()->setUniform("zoom", zoom);
 
88
            shader()->setUniform("radius", (float)radius);
 
89
            shader()->unbind();
 
90
            }
 
91
        else
 
92
            {
 
93
            setEnabled( false );
 
94
            }
 
95
 
 
96
        effects->addRepaint( cursorPos().x() - radius, cursorPos().y() - radius, 2*radius, 2*radius );
 
97
        }
 
98
 
 
99
    ShaderEffect::prePaintScreen( data, time );
 
100
    }
 
101
 
 
102
void LookingGlassEffect::mouseChanged( const QPoint& pos, const QPoint& old, Qt::MouseButtons, Qt::KeyboardModifiers )
 
103
    {
 
104
    if( pos != old && isEnabled() )
 
105
        {
 
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 );
 
108
        }
 
109
    }
 
110
 
 
111
} // namespace
 
112
 
 
113
#include "lookingglass.moc"