Mantid
Loading...
Searching...
No Matches
InputController.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "DllOption.h"
10#include <QColor>
11#include <QMouseEvent>
12#include <QObject>
13#include <QPolygonF>
14#include <QRect>
15
16class QMouseEvent;
17class QWheelEvent;
18class QKeyEvent;
19class QPainter;
20class QPixmap;
21
22namespace MantidQt {
23namespace MantidWidgets {
24
38 Q_OBJECT
39public:
40 explicit InputController(QObject *parent, bool contextAllowed = true);
41 ~InputController() override = default;
42
43 virtual void mousePressEvent(QMouseEvent * /*unused*/) {}
44 virtual void mouseMoveEvent(QMouseEvent *event) {
45 emit touchPointAt(event->position().toPoint().x(), event->position().toPoint().y());
46 }
47 virtual void mouseReleaseEvent(QMouseEvent * /*unused*/) {}
48 virtual void wheelEvent(QWheelEvent * /*unused*/) {}
49 virtual void keyPressEvent(QKeyEvent * /*unused*/) {}
50 virtual void enterEvent(QEvent * /*unused*/) {}
51 virtual void leaveEvent(QEvent * /*unused*/) {}
53 virtual void onPaint(QPainter & /*unused*/) {}
56 virtual void onEnabled() { emit enabled(); }
59 virtual void onDisabled() { emit disabled(); }
60
61 virtual void freezeRotation(bool) {}
62
65 bool canShowContextMenu() const { return m_canShowContextMenu; }
66
67signals:
68 void enabled();
69 void disabled();
70 void touchPointAt(int /*_t1*/, int /*_t2*/);
71
72private:
74};
75
82 Q_OBJECT
83
84public:
85 InputController3DMove(QObject *parent);
86 void mousePressEvent(QMouseEvent * /*unused*/) override;
87 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
88 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
89 void wheelEvent(QWheelEvent * /*unused*/) override;
90 void freezeRotation(bool) override;
91
92signals:
94 void initZoom(int x, int y);
96 void initRotation(int x, int y);
98 void initTranslation(int x, int y);
100 void zoom(int x, int y);
102 void wheelZoom(int x, int y, int d);
104 void rotate(int x, int y);
106 void translate(int x, int y);
108 void finish();
109
110private:
112 bool m_isRotationFrozen = false;
113};
114
119 Q_OBJECT
120
121public:
122 InputControllerPick(QObject *parent);
123 void mousePressEvent(QMouseEvent * /*unused*/) override;
124 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
125 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
126
127signals:
128 void pickPointAt(int /*_t1*/, int /*_t2*/);
129 void touchPointAt(int /*_t1*/, int /*_t2*/);
130 void setSelection(const QRect & /*_t1*/);
132
133private:
135 QRect m_rect;
136};
137
142 Q_OBJECT
143
144public:
145 InputControllerDrawShape(QObject *parent);
146 void mousePressEvent(QMouseEvent * /*unused*/) override;
147 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
148 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
149 void keyPressEvent(QKeyEvent * /*unused*/) override;
150 void leaveEvent(QEvent * /*unused*/) override;
151
152signals:
156 void addShape(const QString &type, int x, int y, const QColor &borderColor, const QColor &fillColor);
159 void moveRightBottomTo(int /*_t1*/, int /*_t2*/);
161 void selectAt(int /*_t1*/, int /*_t2*/);
163 void selectCtrlAt(int /*_t1*/, int /*_t2*/);
165 void moveBy(int /*_t1*/, int /*_t2*/);
167 void touchPointAt(int /*_t1*/, int /*_t2*/);
173 void setSelection(const QRect & /*_t1*/);
175 void finishSelection(const QRect & /*_t1*/);
180
181public slots:
182 void startCreatingShape2D(const QString &type, const QColor &borderColor, const QColor &fillColor);
183 void onDisabled() override;
184
185private:
187 int m_x, m_y;
188 QString m_shapeType;
189 QColor m_borderColor, m_fillColor;
191 QRect m_rect;
192};
193
198 Q_OBJECT
199
200public:
201 InputControllerMoveUnwrapped(QObject *parent);
202 void mousePressEvent(QMouseEvent * /*unused*/) override;
203 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
204 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
205
206signals:
207 void setSelectionRect(const QRect & /*_t1*/);
208 void zoom();
209 void resetZoom();
210 void unzoom();
211
212private:
214 QRect m_rect;
215};
216
221 Q_OBJECT
222
223public:
224 InputControllerDraw(QObject *parent);
225 ~InputControllerDraw() override;
226 void mousePressEvent(QMouseEvent * /*unused*/) override;
227 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
228 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
229 void wheelEvent(QWheelEvent * /*unused*/) override;
230
231 void enterEvent(QEvent * /*unused*/) override;
232 void leaveEvent(QEvent * /*unused*/) override;
233
234protected:
235 int cursorSize() const { return m_size; }
236 bool isLeftButtonPressed() const { return m_isLeftButtonPressed; }
237 bool isRightButtonPressed() const { return m_isRightButtonPressed; }
238 bool isActive() const { return m_isActive; }
239
240private:
241 void redrawCursor();
242 virtual void signalLeftClick() = 0;
243 virtual void signalRightClick();
244 virtual void drawCursor(QPixmap *cursor) = 0;
245 virtual void setPosition(const QPoint &pos) = 0;
246 virtual void resize() = 0;
247
248 const int m_max_size;
249 int m_size;
253 QPixmap *m_cursor;
254};
255
260 Q_OBJECT
261
262public:
263 InputControllerSelection(QObject *parent, QPixmap *icon);
264 ~InputControllerSelection() override;
265 void onPaint(QPainter & /*unused*/) override;
266
267signals:
268 void selection(const QRect & /*_t1*/);
269
270private:
271 void drawCursor(QPixmap *cursor) override;
272 void setPosition(const QPoint &pos) override;
273 void resize() override;
274 void signalLeftClick() override;
275
276 QPixmap *m_image;
277 QRect m_rect;
278};
279
284 Q_OBJECT
285
286public:
287 InputControllerDrawAndErase(QObject *parent);
288
289signals:
290 void draw(const QPolygonF & /*_t1*/);
291 void erase(const QPolygonF & /*_t1*/);
292 void addShape(const QPolygonF &poly, const QColor &borderColor, const QColor &fillColor);
293
294public slots:
295 void startCreatingShape2D(const QColor &borderColor, const QColor &fillColor);
296
297private:
298 void drawCursor(QPixmap *cursor) override;
299 void signalLeftClick() override;
300 void signalRightClick() override;
301 void setPosition(const QPoint &pos) override;
302 void resize() override;
303 void makePolygon();
304
305 QPoint m_pos;
306 QPolygonF m_rect;
307 QColor m_borderColor, m_fillColor;
309};
310} // namespace MantidWidgets
311} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
size_t m_size
Maximum size of the store.
void(ComponentInfo::* setPosition)(const size_t, const Mantid::Kernel::V3D &)
Controller for moving the instrument on Projection3D surface: translation, rotation and zooming.
void initRotation(int x, int y)
Init rotation. x and y is the starting point on the screen.
void initZoom(int x, int y)
Init zooming. x and y is the zoom starting point on the screen.
void initTranslation(int x, int y)
Init translation. x and y is the starting point on the screen.
void translate(int x, int y)
Translate.
void wheelZoom(int x, int y, int d)
Wheel zoom.
Controller for drawing and erasing arbitrary shapes on an unwrapped surface.
void addShape(const QPolygonF &poly, const QColor &borderColor, const QColor &fillColor)
void finishSelection(const QRect &)
Rubber band selection is done.
void restoreOverrideCursor()
Restore the cursor to its default image.
void selectCtrlAt(int, int)
Select a shape with ctrl key pressed at a location on the screen.
void removeSelectedShapes()
Remove the selected shapes.
void selectAt(int, int)
Select a shape or a conrol point at a location on the screen.
void copySelectedShapes()
Copy the selected shapes.
void setSelection(const QRect &)
Update the rubber band selection.
void moveBy(int, int)
Move selected shape or a control point by a displacement vector.
void addShape(const QString &type, int x, int y, const QColor &borderColor, const QColor &fillColor)
Add a new shape.
void moveRightBottomTo(int, int)
Resize the current shape by moving the right-bottom control point to a location on the screen.
bool m_creating
a shape is being created with a mouse
void deselectAll()
Deselect all selected shapes.
void pasteCopiedShapes()
Paste previously copied shapes.
void touchPointAt(int, int)
Sent when the mouse is moved to a new position with the buttons up.
Controller for free drawing on an unwrapped surface.
virtual void drawCursor(QPixmap *cursor)=0
virtual void setPosition(const QPoint &pos)=0
Controller for moving the instrument on an unwrapped surface.
Controller for picking detectors.
Controller for erasing peaks on an unwrapped surface.
The base class for the mouse and keyboard controllers to work with ProjectionSurfaces.
virtual void wheelEvent(QWheelEvent *)
bool canShowContextMenu() const
Returns true if a surface using this controller can show a context menu on right-click.
virtual void onPaint(QPainter &)
To be called after the owner widget has drawn its content.
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *)
virtual void onEnabled()
To be called when this controller takes control of the input.
virtual void keyPressEvent(QKeyEvent *)
virtual void mousePressEvent(QMouseEvent *)
virtual void onDisabled()
To be called when this controller looses control.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...