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

« back to all changes in this revision

Viewing changes to kwin/effects/mousemark.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) 2006 Lubos Lunak <l.lunak@kde.org>
 
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
#include "mousemark.h"
 
12
 
 
13
#include <config-X11.h>
 
14
 
 
15
#include <kaction.h>
 
16
#include <kactioncollection.h>
 
17
#include <kglobal.h>
 
18
#include <klocale.h>
 
19
#include <kstandarddirs.h>
 
20
 
 
21
#include <math.h>
 
22
 
 
23
#ifdef HAVE_OPENGL
 
24
#include <GL/gl.h>
 
25
#endif
 
26
 
 
27
#include <kdebug.h>
 
28
 
 
29
namespace KWin
 
30
{
 
31
 
 
32
KWIN_EFFECT( mousemark, MouseMarkEffect )
 
33
 
 
34
MouseMarkEffect::MouseMarkEffect()
 
35
    {
 
36
    KActionCollection* actionCollection = new KActionCollection( this );
 
37
    KAction* a = static_cast< KAction* >( actionCollection->addAction( "ClearMouseMarks" ));
 
38
    a->setText( i18n( "ClearMouseMarks" ));
 
39
    a->setGlobalShortcut( KShortcut( Qt::SHIFT + Qt::META + Qt::Key_F11 ));
 
40
    connect( a, SIGNAL( triggered( bool )), this, SLOT( clear()));
 
41
    }
 
42
 
 
43
void MouseMarkEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
 
44
    {
 
45
    effects->paintScreen( mask, region, data ); // paint normal screen
 
46
    if( marks.isEmpty() && drawing.isEmpty())
 
47
        return;
 
48
    glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LINE_BIT );
 
49
    glColor4f( 1, 0, 0, 1 ); // red
 
50
    glEnable( GL_LINE_SMOOTH );
 
51
    glLineWidth( 3 );
 
52
    foreach( const Mark& mark, marks )
 
53
        {
 
54
        glBegin( GL_LINE_STRIP );
 
55
        foreach( const QPoint& p, mark )
 
56
            glVertex2i( p.x(), p.y());
 
57
        glEnd();
 
58
        }
 
59
    if( !drawing.isEmpty())
 
60
        {
 
61
        glBegin( GL_LINE_STRIP );
 
62
        foreach( const QPoint& p, drawing )
 
63
            glVertex2i( p.x(), p.y());
 
64
        glEnd();
 
65
        }
 
66
    glPopAttrib();
 
67
    }
 
68
 
 
69
void MouseMarkEffect::mouseChanged( const QPoint& pos, const QPoint&,
 
70
    Qt::MouseButtons, Qt::KeyboardModifiers modifiers )
 
71
    {
 
72
    if( modifiers == ( Qt::META | Qt::SHIFT )) // activated
 
73
        {
 
74
        if( drawing.isEmpty())
 
75
            drawing.append( pos );
 
76
        if( drawing.last() == pos )
 
77
            return;
 
78
        QPoint pos2 = drawing.last();
 
79
        drawing.append( pos );
 
80
        effects->addRepaint( QRect( qMin( pos.x(), pos2.x()), qMin( pos.y(), pos2.y()),
 
81
            qMax( pos.x(), pos2.x()), qMax( pos.y(), pos2.y())));
 
82
        }
 
83
    else if( !drawing.isEmpty())
 
84
        {
 
85
        marks.append( drawing );
 
86
        drawing.clear();
 
87
        }
 
88
    }
 
89
 
 
90
void MouseMarkEffect::clear()
 
91
    {
 
92
    drawing.clear();
 
93
    marks.clear();
 
94
    effects->addRepaintFull();
 
95
    }
 
96
 
 
97
} // namespace
 
98
 
 
99
#include "mousemark.moc"