~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/mouse/mouseengine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright © 2007 Fredrik Höglund <fredrik@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License version 2 as
 
6
 *   published by the Free Software Foundation
 
7
 *
 
8
 *   This program is distributed in the hope that it will be useful,
 
9
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *   GNU General Public License for more details
 
12
 *
 
13
 *   You should have received a copy of the GNU Library General Public
 
14
 *   License along with this program; if not, write to the
 
15
 *   Free Software Foundation, Inc.,
 
16
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "mouseengine.h"
 
20
 
 
21
#include <QCursor>
 
22
 
 
23
#ifdef HAVE_XFIXES
 
24
#  include "cursornotificationhandler.h"
 
25
#endif
 
26
 
 
27
 
 
28
MouseEngine::MouseEngine(QObject* parent, const QVariantList& args)
 
29
    : Plasma::DataEngine(parent, args), timerId(0)
 
30
#ifdef HAVE_XFIXES
 
31
, handler(0)
 
32
#endif
 
33
{
 
34
    Q_UNUSED(args)
 
35
}
 
36
 
 
37
 
 
38
MouseEngine::~MouseEngine()
 
39
{
 
40
    if (timerId)
 
41
        killTimer(timerId);
 
42
#ifdef HAVE_XFIXES
 
43
    delete handler;
 
44
#endif
 
45
}
 
46
 
 
47
 
 
48
QStringList MouseEngine::sources() const
 
49
{
 
50
   QStringList list;
 
51
 
 
52
   list << QLatin1String("Position");
 
53
#ifdef HAVE_XFIXES
 
54
   list << QLatin1String("Name");
 
55
#endif
 
56
 
 
57
   return list;
 
58
}
 
59
 
 
60
 
 
61
void MouseEngine::init()
 
62
{
 
63
    if (!timerId)
 
64
        timerId = startTimer(40);
 
65
 
 
66
    // Init cursor position
 
67
    QPoint pos = QCursor::pos();
 
68
    setData(QLatin1String("Position"), QVariant(pos));
 
69
    lastPosition = pos;
 
70
 
 
71
#ifdef HAVE_XFIXES
 
72
    handler = new CursorNotificationHandler;
 
73
    connect(handler, SIGNAL(cursorNameChanged(QString)), SLOT(updateCursorName(QString)));
 
74
 
 
75
    setData(QLatin1String("Name"), QVariant(handler->cursorName()));
 
76
#endif
 
77
 
 
78
    scheduleSourcesUpdated();
 
79
}
 
80
 
 
81
 
 
82
void MouseEngine::timerEvent(QTimerEvent *)
 
83
{
 
84
    QPoint pos = QCursor::pos();
 
85
 
 
86
    if (pos != lastPosition)
 
87
    {
 
88
        setData(QLatin1String("Position"), QVariant(pos));
 
89
        lastPosition = pos;
 
90
 
 
91
        scheduleSourcesUpdated();
 
92
    }
 
93
}
 
94
 
 
95
 
 
96
void MouseEngine::updateCursorName(const QString &name)
 
97
{
 
98
    setData(QLatin1String("Name"), QVariant(name));
 
99
    scheduleSourcesUpdated();
 
100
}
 
101
 
 
102
#include "mouseengine.moc"
 
103