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) { emit touchPointAt(event->x(), event->y()); }
45 virtual void mouseReleaseEvent(QMouseEvent * /*unused*/) {}
46 virtual void wheelEvent(QWheelEvent * /*unused*/) {}
47 virtual void keyPressEvent(QKeyEvent * /*unused*/) {}
48 virtual void enterEvent(QEvent * /*unused*/) {}
49 virtual void leaveEvent(QEvent * /*unused*/) {}
51 virtual void onPaint(QPainter & /*unused*/) {}
54 virtual void onEnabled() { emit enabled(); }
57 virtual void onDisabled() { emit disabled(); }
58
59 virtual void freezeRotation(bool) {}
60
63 bool canShowContextMenu() const { return m_canShowContextMenu; }
64
65signals:
66 void enabled();
67 void disabled();
68 void touchPointAt(int /*_t1*/, int /*_t2*/);
69
70private:
72};
73
80 Q_OBJECT
81
82public:
83 InputController3DMove(QObject *parent);
84 void mousePressEvent(QMouseEvent * /*unused*/) override;
85 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
86 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
87 void wheelEvent(QWheelEvent * /*unused*/) override;
88 void freezeRotation(bool) override;
89
90signals:
92 void initZoom(int x, int y);
94 void initRotation(int x, int y);
96 void initTranslation(int x, int y);
98 void zoom(int x, int y);
100 void wheelZoom(int x, int y, int d);
102 void rotate(int x, int y);
104 void translate(int x, int y);
106 void finish();
107
108private:
110 bool m_isRotationFrozen = false;
111};
112
117 Q_OBJECT
118
119public:
120 InputControllerPick(QObject *parent);
121 void mousePressEvent(QMouseEvent * /*unused*/) override;
122 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
123 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
124
125signals:
126 void pickPointAt(int /*_t1*/, int /*_t2*/);
127 void touchPointAt(int /*_t1*/, int /*_t2*/);
128 void setSelection(const QRect & /*_t1*/);
130
131private:
133 QRect m_rect;
134};
135
140 Q_OBJECT
141
142public:
143 InputControllerDrawShape(QObject *parent);
144 void mousePressEvent(QMouseEvent * /*unused*/) override;
145 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
146 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
147 void keyPressEvent(QKeyEvent * /*unused*/) override;
148 void leaveEvent(QEvent * /*unused*/) override;
149
150signals:
154 void addShape(const QString &type, int x, int y, const QColor &borderColor, const QColor &fillColor);
157 void moveRightBottomTo(int /*_t1*/, int /*_t2*/);
159 void selectAt(int /*_t1*/, int /*_t2*/);
161 void selectCtrlAt(int /*_t1*/, int /*_t2*/);
163 void moveBy(int /*_t1*/, int /*_t2*/);
165 void touchPointAt(int /*_t1*/, int /*_t2*/);
171 void setSelection(const QRect & /*_t1*/);
173 void finishSelection(const QRect & /*_t1*/);
178
179public slots:
180 void startCreatingShape2D(const QString &type, const QColor &borderColor, const QColor &fillColor);
181 void onDisabled() override;
182
183private:
185 int m_x, m_y;
186 QString m_shapeType;
187 QColor m_borderColor, m_fillColor;
189 QRect m_rect;
190};
191
196 Q_OBJECT
197
198public:
199 InputControllerMoveUnwrapped(QObject *parent);
200 void mousePressEvent(QMouseEvent * /*unused*/) override;
201 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
202 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
203
204signals:
205 void setSelectionRect(const QRect & /*_t1*/);
206 void zoom();
207 void resetZoom();
208 void unzoom();
209
210private:
212 QRect m_rect;
213};
214
219 Q_OBJECT
220
221public:
222 InputControllerDraw(QObject *parent);
223 ~InputControllerDraw() override;
224 void mousePressEvent(QMouseEvent * /*unused*/) override;
225 void mouseMoveEvent(QMouseEvent * /*unused*/) override;
226 void mouseReleaseEvent(QMouseEvent * /*unused*/) override;
227 void wheelEvent(QWheelEvent * /*unused*/) override;
228
229 void enterEvent(QEvent * /*unused*/) override;
230 void leaveEvent(QEvent * /*unused*/) override;
231
232protected:
233 int cursorSize() const { return m_size; }
234 bool isLeftButtonPressed() const { return m_isLeftButtonPressed; }
235 bool isRightButtonPressed() const { return m_isRightButtonPressed; }
236 bool isActive() const { return m_isActive; }
237
238private:
239 void redrawCursor();
240 virtual void signalLeftClick() = 0;
241 virtual void signalRightClick();
242 virtual void drawCursor(QPixmap *cursor) = 0;
243 virtual void setPosition(const QPoint &pos) = 0;
244 virtual void resize() = 0;
245
246 const int m_max_size;
247 int m_size;
251 QPixmap *m_cursor;
252};
253
258 Q_OBJECT
259
260public:
261 InputControllerSelection(QObject *parent, QPixmap *icon);
262 ~InputControllerSelection() override;
263 void onPaint(QPainter & /*unused*/) override;
264
265signals:
266 void selection(const QRect & /*_t1*/);
267
268private:
269 void drawCursor(QPixmap *cursor) override;
270 void setPosition(const QPoint &pos) override;
271 void resize() override;
272 void signalLeftClick() override;
273
274 QPixmap *m_image;
275 QRect m_rect;
276};
277
282 Q_OBJECT
283
284public:
285 InputControllerDrawAndErase(QObject *parent);
286
287signals:
288 void draw(const QPolygonF & /*_t1*/);
289 void erase(const QPolygonF & /*_t1*/);
290 void addShape(const QPolygonF &poly, const QColor &borderColor, const QColor &fillColor);
291
292public slots:
293 void startCreatingShape2D(const QColor &borderColor, const QColor &fillColor);
294
295private:
296 void drawCursor(QPixmap *cursor) override;
297 void signalLeftClick() override;
298 void signalRightClick() override;
299 void setPosition(const QPoint &pos) override;
300 void resize() override;
301 void makePolygon();
302
303 QPoint m_pos;
304 QPolygonF m_rect;
305 QColor m_borderColor, m_fillColor;
307};
308} // namespace MantidWidgets
309} // 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)
Controller for drawing mask shapes.
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...