Engines
mouseengine.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mouseengine.h"
00020
00021 #include <QCursor>
00022
00023 #ifdef HAVE_XFIXES
00024 # include "cursornotificationhandler.h"
00025 #endif
00026
00027
00028 MouseEngine::MouseEngine(QObject* parent, const QVariantList& args)
00029 : Plasma::DataEngine(parent, args), timerId(0)
00030 #ifdef HAVE_XFIXES
00031 , handler(0)
00032 #endif
00033 {
00034 Q_UNUSED(args)
00035 }
00036
00037
00038 MouseEngine::~MouseEngine()
00039 {
00040 if (timerId)
00041 killTimer(timerId);
00042 #ifdef HAVE_XFIXES
00043 delete handler;
00044 #endif
00045 }
00046
00047
00048 QStringList MouseEngine::sources() const
00049 {
00050 QStringList list;
00051
00052 list << QLatin1String("Position");
00053 #ifdef HAVE_XFIXES
00054 list << QLatin1String("Name");
00055 #endif
00056
00057 return list;
00058 }
00059
00060
00061 void MouseEngine::init()
00062 {
00063 if (!timerId)
00064 timerId = startTimer(40);
00065
00066
00067 QPoint pos = QCursor::pos();
00068 setData(QLatin1String("Position"), QVariant(pos));
00069 lastPosition = pos;
00070
00071 #ifdef HAVE_XFIXES
00072 handler = new CursorNotificationHandler;
00073 connect(handler, SIGNAL(cursorNameChanged(QString)), SLOT(updateCursorName(QString)));
00074
00075 setData(QLatin1String("Name"), QVariant(handler->cursorName()));
00076 #endif
00077
00078 scheduleSourcesUpdated();
00079 }
00080
00081
00082 void MouseEngine::timerEvent(QTimerEvent *)
00083 {
00084 QPoint pos = QCursor::pos();
00085
00086 if (pos != lastPosition)
00087 {
00088 setData(QLatin1String("Position"), QVariant(pos));
00089 lastPosition = pos;
00090
00091 scheduleSourcesUpdated();
00092 }
00093 }
00094
00095
00096 void MouseEngine::updateCursorName(const QString &name)
00097 {
00098 setData(QLatin1String("Name"), QVariant(name));
00099 scheduleSourcesUpdated();
00100 }
00101
00102 #include "mouseengine.moc"
00103