24 #include <QtGui/QActionEvent>
36 class KGestureMapContainer {
52 return &g_instance->gestureMap;
56 KGestureMap::KGestureMap()
58 m_gestureTimeout.setSingleShot(
true);
59 connect(&m_gestureTimeout, SIGNAL(
timeout()),
this, SLOT(stopAcquisition()));
64 qApp->installEventFilter(
this);
72 kDebug(283) <<
"KGestureMap::addGesture(KShapeGesture ...)";
73 if (!m_shapeGestures.contains(gesture))
74 m_shapeGestures.insert(gesture, act);
76 kDebug(283) <<
"Tried to register an action for a gesture already taken";
84 kDebug(283) <<
"KGestureMap::addGesture(KRockerGesture ...)";
85 if (!m_rockerGestures.contains(gesture))
86 m_rockerGestures.insert(gesture, act);
88 kDebug(283) <<
"Tried to register an action for a gesture already taken";
96 kDebug(283) <<
"KGestureMap::removeGesture(KShapeGesture ...)";
97 KAction *oldAct = m_shapeGestures.value(gesture);
98 if (oldAct == act || !act )
99 m_shapeGestures.remove(gesture);
107 kDebug(283) <<
"KGestureMap::removeGesture(KRockerGesture ...)";
108 KAction *oldAct = m_rockerGestures.value(gesture);
109 if (oldAct == act || !act )
110 m_rockerGestures.remove(gesture);
116 return m_shapeGestures.value(gesture);
122 return m_rockerGestures.value(gesture);
126 void KGestureMap::installEventFilterOnMe(
KApplication *app)
128 app->installEventFilter(
this);
132 inline int KGestureMap::bitCount(
int n)
143 void KGestureMap::handleAction(
KAction *kact)
147 kDebug(283) <<
"handleAction";
154 void KGestureMap::matchShapeGesture()
158 float dist, minDist = 20.0;
162 it != m_shapeGestures.constEnd(); ++it) {
163 dist = m_shapeGesture.
distance(it.key(), 1000.0);
164 if (dist < minDist) {
166 bestMatch = it.value();
169 handleAction(bestMatch);
174 void KGestureMap::stopAcquisition()
176 m_gestureTimeout.stop();
197 int type = e->type();
203 if (type == QEvent::ContextMenu) {
204 QContextMenuEvent *cme =
static_cast<QContextMenuEvent *
>(e);
205 if (cme->reason() == QContextMenuEvent::Mouse) {
212 if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove)
215 QMouseEvent *me =
static_cast<QMouseEvent *
>(e);
216 if (type == QEvent::MouseButtonPress) {
217 int nButtonsDown = bitCount(me->buttons());
218 kDebug(283) <<
"number of buttons down:" << nButtonsDown;
221 if (nButtonsDown == 1 && me->button() == Qt::RightButton) {
224 m_gestureTimeout.start(4000);
225 kDebug(283) <<
"========================";
227 m_points.append(me->pos());
229 }
else if (nButtonsDown != 2)
234 int buttonHeld = me->buttons() ^ me->button();
235 m_rockerGesture.
setButtons(static_cast<Qt::MouseButton>(buttonHeld), me->button());
236 KAction *match = m_rockerGestures.value(m_rockerGesture);
244 if (type == QEvent::MouseMove) {
245 m_points.append(me->pos());
249 if (m_points.size() > 1010)
252 }
else if (type == QEvent::MouseButtonRelease && me->button() == Qt::RightButton) {
259 for (
int i = 1; i < m_points.size(); i++) {
260 dist += (m_points[i] - m_points[i-1]).manhattanLength();
274 #include "kgesturemap.moc"
Controls and provides information to all KDE applications.
float distance(const KShapeGesture &other, float abortThreshold) const
Return a difference measurement betwenn this gesture and the other gesture.
void removeGesture(const KShapeGesture &gesture, KAction *kact)
virtual bool eventFilter(QObject *obj, QEvent *e)
bool isValid() const
Return true if this gesture is valid.
#define K_GLOBAL_STATIC(TYPE, NAME)
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static KGestureMap * self()
void setShape(const QPolygon &shape)
Set the shape to draw to trigger this gesture.
Class to encapsulate user-driven action or event.
bool isValid() const
Return true if this gesture is valid.
KAction * findAction(const KShapeGesture &gesture) const
void setButtons(Qt::MouseButton hold, Qt::MouseButton thenPush)
set button combination to trigger
void addGesture(const KShapeGesture &gesture, KAction *kact)