Move from SLabel to ActiveLabel
[shopper.git] / src / ui / Gesture.cc
blob7c9951e3484dadf16133248ba2eb17307365fbde
1 /* Shopper
2 * Copyright (C) 2008 David Greaves <david@dgreaves.com>
4 * This software is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1 of
7 * the License, or (at your option) any later version.
9 * This software is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this software; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA
21 //#define DEBUG_SHOPPER 1
22 #include "Gesture.h"
23 #include "shopper.h" // automake, i8n, gettext
25 #include <QList>
26 #include <QHash>
28 GestureConnectionStore::GestureConnectionStore() : QObject() {};
30 struct Gesture::Private
32 // available via public API
33 QString shape; // holds the string encoding of the shape.
35 // avialable via friend API, populated by 'connect'
36 GestureConnectionStore * connectionStore;
40 // Public
41 Gesture::Gesture(QString shape)
43 p = new Private;
44 p->shape = shape;
45 p->connectionStore = 0;
47 // Protected
48 Gesture::Gesture(Gesture *g)
50 p = new Private;
51 p->shape = g->p->shape;
52 p->connectionStore = 0;
55 Gesture::Gesture(const Gesture &g)
57 p = new Private;
58 p->shape = g.p->shape;
59 p->connectionStore = 0;
62 Gesture::~Gesture()
64 if (p->connectionStore)
65 delete p->connectionStore;
67 delete p;
70 ////////////////////////////////////////////////////////////////
71 // operators
72 bool operator==(const Gesture &A, const Gesture &B)
74 return A.p->shape == B.p->shape;
77 uint qHash(const Gesture &A)
79 QString s=A.p->shape;
80 return qHash(s);
84 ////////////////////////////////////////////////////////////////
85 // Public interface
86 void Gesture::addStroke(QString stroke)
88 p->shape+=stroke;
91 QString Gesture::shape() const
93 return p->shape;
97 ////////////////////////////////////////////////////////////////
98 // Protected interface
99 void Gesture::connect(QObject* receiver, const char* method)
101 if (p->connectionStore == 0)
102 p->connectionStore = new GestureConnectionStore;
104 p->connectionStore->connect(p->connectionStore, SIGNAL(activated()),
105 receiver, method);
108 bool Gesture::disconnect(QObject* receiver, const char* method)
110 Q_ASSERT(p->connectionStore != 0);
111 if (p->connectionStore == 0)
112 return false;
114 return p->connectionStore->disconnect(p->connectionStore, SIGNAL(activated()),
115 receiver, method);
118 void Gesture::invoke()
120 if (p->connectionStore)
121 p->connectionStore->activated();