Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/input/kis_abstract_input_action.cpp
Show All 27 Lines | |||||
28 | public: | 28 | public: | ||
29 | QString id; | 29 | QString id; | ||
30 | QString name; | 30 | QString name; | ||
31 | QString description; | 31 | QString description; | ||
32 | QHash<QString, int> indexes; | 32 | QHash<QString, int> indexes; | ||
33 | 33 | | |||
34 | QPointF lastCursorPosition; | 34 | QPointF lastCursorPosition; | ||
35 | 35 | | |||
36 | static KisInputManager* inputManager; | 36 | static KisInputManager *inputManager; | ||
37 | }; | 37 | }; | ||
38 | 38 | | |||
39 | KisInputManager *KisAbstractInputAction::Private::inputManager = 0; | 39 | KisInputManager *KisAbstractInputAction::Private::inputManager = 0; | ||
40 | 40 | | |||
41 | KisAbstractInputAction::KisAbstractInputAction(const QString & id) | 41 | KisAbstractInputAction::KisAbstractInputAction(const QString &id) | ||
42 | : d(new Private) | 42 | : d(new Private) | ||
43 | { | 43 | { | ||
44 | d->id = id; | 44 | d->id = id; | ||
45 | d->indexes.insert(i18n("Activate"), 0); | 45 | d->indexes.insert(i18n("Activate"), 0); | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | KisAbstractInputAction::~KisAbstractInputAction() | 48 | KisAbstractInputAction::~KisAbstractInputAction() | ||
49 | { | 49 | { | ||
Show All 14 Lines | |||||
64 | { | 64 | { | ||
65 | Q_UNUSED(shortcut); | 65 | Q_UNUSED(shortcut); | ||
66 | 66 | | |||
67 | if (event) { | 67 | if (event) { | ||
68 | d->lastCursorPosition = eventPosF(event); | 68 | d->lastCursorPosition = eventPosF(event); | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | void KisAbstractInputAction::inputEvent(QEvent* event) | 72 | void KisAbstractInputAction::inputEvent(QEvent *event) | ||
73 | { | 73 | { | ||
74 | if (event) { | 74 | if (event) { | ||
75 | QPointF newPosition = eventPosF(event); | 75 | QPointF newPosition = eventPosF(event); | ||
76 | cursorMoved(d->lastCursorPosition, newPosition); | 76 | cursorMoved(d->lastCursorPosition, newPosition); | ||
77 | d->lastCursorPosition = newPosition; | 77 | d->lastCursorPosition = newPosition; | ||
78 | } | 78 | } | ||
79 | } | 79 | } | ||
80 | 80 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 129 | { | |||
130 | return d->indexes; | 130 | return d->indexes; | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | QString KisAbstractInputAction::id() const | 133 | QString KisAbstractInputAction::id() const | ||
134 | { | 134 | { | ||
135 | return d->id; | 135 | return d->id; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | void KisAbstractInputAction::setName(const QString& name) | 138 | void KisAbstractInputAction::setName(const QString &name) | ||
139 | { | 139 | { | ||
140 | d->name = name; | 140 | d->name = name; | ||
141 | } | 141 | } | ||
142 | 142 | | |||
143 | void KisAbstractInputAction::setDescription(const QString& description) | 143 | void KisAbstractInputAction::setDescription(const QString &description) | ||
144 | { | 144 | { | ||
145 | d->description = description; | 145 | d->description = description; | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | void KisAbstractInputAction::setShortcutIndexes(const QHash< QString, int >& indexes) | 148 | void KisAbstractInputAction::setShortcutIndexes(const QHash< QString, int > &indexes) | ||
149 | { | 149 | { | ||
150 | d->indexes = indexes; | 150 | d->indexes = indexes; | ||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | void KisAbstractInputAction::setInputManager(KisInputManager *manager) | 153 | void KisAbstractInputAction::setInputManager(KisInputManager *manager) | ||
154 | { | 154 | { | ||
155 | Private::inputManager = manager; | 155 | Private::inputManager = manager; | ||
156 | } | 156 | } | ||
157 | 157 | | |||
158 | bool KisAbstractInputAction::isShortcutRequired(int shortcut) const | 158 | bool KisAbstractInputAction::isShortcutRequired(int shortcut) const | ||
159 | { | 159 | { | ||
160 | Q_UNUSED(shortcut); | 160 | Q_UNUSED(shortcut); | ||
161 | return false; | 161 | return false; | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | 164 | QPoint KisAbstractInputAction::eventPos(const QEvent *event) | |||
165 | QPoint KisAbstractInputAction::eventPos(const QEvent *event) { | 165 | { | ||
166 | | ||||
167 | if(!event) { | 166 | if(!event) { | ||
168 | return QPoint(); | 167 | return QPoint(); | ||
169 | } | 168 | } | ||
170 | 169 | | |||
171 | switch (event->type()) { | 170 | switch (event->type()) { | ||
172 | case QEvent::MouseMove: | 171 | case QEvent::MouseMove: | ||
173 | case QEvent::MouseButtonPress: | 172 | case QEvent::MouseButtonPress: | ||
173 | case QEvent::MouseButtonDblClick: | ||||
174 | case QEvent::MouseButtonRelease: | 174 | case QEvent::MouseButtonRelease: | ||
175 | return static_cast<const QMouseEvent*>(event)->pos(); | 175 | return static_cast<const QMouseEvent*>(event)->pos(); | ||
176 | 176 | | |||
177 | case QEvent::TabletMove: | 177 | case QEvent::TabletMove: | ||
178 | case QEvent::TabletPress: | 178 | case QEvent::TabletPress: | ||
179 | case QEvent::TabletRelease: | 179 | case QEvent::TabletRelease: | ||
180 | return static_cast<const QTabletEvent*>(event)->pos(); | 180 | return static_cast<const QTabletEvent*>(event)->pos(); | ||
181 | 181 | | |||
182 | case QEvent::Wheel: | 182 | case QEvent::Wheel: | ||
183 | return static_cast<const QWheelEvent*>(event)->pos(); | 183 | return static_cast<const QWheelEvent*>(event)->pos(); | ||
184 | 184 | | |||
185 | case QEvent::NativeGesture: | 185 | case QEvent::NativeGesture: | ||
186 | return static_cast<const QNativeGestureEvent*>(event)->pos(); | 186 | return static_cast<const QNativeGestureEvent*>(event)->pos(); | ||
187 | 187 | | |||
188 | default: | 188 | default: | ||
189 | warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type(); | 189 | warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type(); | ||
190 | return QPoint(); | 190 | return QPoint(); | ||
191 | } | 191 | } | ||
192 | } | 192 | } | ||
193 | 193 | | |||
194 | | ||||
195 | QPointF KisAbstractInputAction::eventPosF(const QEvent *event) { | 194 | QPointF KisAbstractInputAction::eventPosF(const QEvent *event) { | ||
196 | 195 | | |||
197 | switch (event->type()) { | 196 | switch (event->type()) { | ||
198 | case QEvent::MouseMove: | 197 | case QEvent::MouseMove: | ||
199 | case QEvent::MouseButtonPress: | 198 | case QEvent::MouseButtonPress: | ||
199 | case QEvent::MouseButtonDblClick: | ||||
200 | case QEvent::MouseButtonRelease: | 200 | case QEvent::MouseButtonRelease: | ||
201 | return static_cast<const QMouseEvent*>(event)->localPos(); | 201 | return static_cast<const QMouseEvent*>(event)->localPos(); | ||
202 | 202 | | |||
203 | case QEvent::TabletMove: | 203 | case QEvent::TabletMove: | ||
204 | case QEvent::TabletPress: | 204 | case QEvent::TabletPress: | ||
205 | case QEvent::TabletRelease: | 205 | case QEvent::TabletRelease: | ||
206 | return static_cast<const QTabletEvent*>(event)->posF(); | 206 | return static_cast<const QTabletEvent*>(event)->posF(); | ||
207 | 207 | | |||
Show All 16 Lines |