Developer documentation
Version 3.0.3-105-gd3941f44
base.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __gui_mrview_tool_base_h__
18#define __gui_mrview_tool_base_h__
19
20#include "file/config.h"
21
22#include "gui/mrview/window.h"
23#include "gui/projection.h"
24
25#define LAYOUT_SPACING 3
26
27#define __STR__(x) #x
28#define __STR(x) __STR__(x)
29
30namespace MR
31{
32 namespace App {
33 class OptionList;
34 class Options;
35 }
36
37 namespace GUI
38 {
39 namespace MRView
40 {
41 namespace Tool
42 {
43 class Base;
44
45
48 public:
49 CameraInteractor () : _active (false) { }
50 bool active () const { return _active; }
51 virtual void deactivate ();
52 virtual bool slice_move_event (const ModelViewProjection& projection, float inc);
53 virtual bool pan_event (const ModelViewProjection& projection);
54 virtual bool panthrough_event (const ModelViewProjection& projection);
55 virtual bool tilt_event (const ModelViewProjection& projection);
56 virtual bool rotate_event (const ModelViewProjection& projection);
57 protected:
58 bool _active;
59 void set_active (bool onoff) { _active = onoff; }
60 };
61
62
63
64 class Dock : public QDockWidget
66 public:
67 Dock (const QString& name, bool floating) :
68 QDockWidget (name, Window::main), tool (nullptr) {
69 Window::main->addDockWidget (Qt::RightDockWidgetArea, this);
70 setFloating (floating);
71 }
73
74 void closeEvent (QCloseEvent*) override;
75
77 };
78
79
80
81
82
83
84 class Base : public QFrame { NOMEMALIGN
85 public:
86 Base (Dock* parent);
87 Window& window () const { return *Window::main; }
88
89 std::string current_folder;
90
93
94 virtual QSize sizeHint () const override;
95
96 void grab_focus () {
97 window().tool_has_focus = this;
98 window().set_cursor();
99 }
101 if (window().tool_has_focus == this) {
102 window().tool_has_focus = nullptr;
103 window().set_cursor();
104 }
105 }
106
107 class HBoxLayout : public QHBoxLayout { NOMEMALIGN
108 public:
109 HBoxLayout () : QHBoxLayout () { init(); }
110 HBoxLayout (QWidget* parent) : QHBoxLayout (parent) { init(); }
111 protected:
112 void init () {
113 setSpacing (LAYOUT_SPACING);
115 }
116 };
117
118 class VBoxLayout : public QVBoxLayout { NOMEMALIGN
119 public:
120 VBoxLayout () : QVBoxLayout () { init(); }
121 VBoxLayout (QWidget* parent) : QVBoxLayout (parent) { init(); }
122 protected:
123 void init () {
124 setSpacing (LAYOUT_SPACING);
126 }
127 };
128
129 class GridLayout : public QGridLayout { NOMEMALIGN
130 public:
131 GridLayout () : QGridLayout () { init(); }
132 GridLayout (QWidget* parent) : QGridLayout (parent) { init(); }
133 protected:
134 void init () {
135 setSpacing (LAYOUT_SPACING);
137 }
138 };
139
140
141 class FormLayout : public QFormLayout { NOMEMALIGN
142 public:
143 FormLayout () : QFormLayout () { init(); }
144 FormLayout (QWidget* parent) : QFormLayout (parent) { init(); }
145 protected:
146 void init () {
147 setSpacing (LAYOUT_SPACING);
149 }
150 };
151
152 virtual void draw (const Projection& transform, bool is_3D, int axis, int slice);
153 virtual void draw_colourbars ();
154 virtual size_t visible_number_colourbars () { return 0; }
155 virtual int draw_tool_labels (int, int, const Projection&) const { return 0; }
156 virtual bool mouse_press_event ();
157 virtual bool mouse_move_event ();
158 virtual bool mouse_release_event ();
159 virtual void close_event() { }
160 virtual void reset_event () { }
161 virtual QCursor* get_cursor ();
162 void update_cursor() { window().set_cursor(); }
163
164 void dragEnterEvent (QDragEnterEvent* event) override {
165 event->acceptProposedAction();
166 }
167 void dragMoveEvent (QDragMoveEvent* event) override {
168 event->acceptProposedAction();
169 }
170 void dragLeaveEvent (QDragLeaveEvent* event) override {
171 event->accept();
172 }
173 };
174
175
176
177
178
179
180
182
183 inline Dock::~Dock () { delete tool; }
184
185
186
187 class __Action__ : public QAction
188 { NOMEMALIGN
189 public:
190 __Action__ (QActionGroup* parent,
191 const char* const name,
192 const char* const description,
193 int index) :
194 QAction (name, parent),
195 dock (nullptr) {
196 setCheckable (true);
197 setShortcut (tr (std::string ("Ctrl+F" + str (index)).c_str()));
198 setStatusTip (tr (description));
199 }
200
201 virtual ~__Action__ () { delete dock; }
202
203 virtual Dock* create (bool floating) = 0;
204 Dock* dock;
205 };
207
208
209 template <class T>
210 Dock* create (const QString& text, bool floating)
211 {
212 Dock* dock = new Dock (text, floating);
213 dock->tool = new T (dock);
214 dock->setWidget (dock->tool);
215 dock->show();
216 return dock;
217 }
218
219
220 template <class T>
221 class Action : public __Action__
222 { NOMEMALIGN
223 public:
224 Action (QActionGroup* parent,
225 const char* const name,
226 const char* const description,
227 int index) :
228 __Action__ (parent, name, description, index) { }
229
230 virtual Dock* create (bool floating) {
231 dock = Tool::create<T> (this->text(), floating);
232 return dock;
233 }
234 };
235
236
237
238
239 }
240 }
241 }
242}
243
244#endif
245
246
a class to hold the list of option groups
Definition: app.h:139
object storing information about option parsed from command-line
Definition: app.h:286
virtual Dock * create(bool floating)
Definition: base.h:230
Action(QActionGroup *parent, const char *const name, const char *const description, int index)
Definition: base.h:224
void dragMoveEvent(QDragMoveEvent *event) override
Definition: base.h:167
virtual size_t visible_number_colourbars()
Definition: base.h:154
virtual void draw_colourbars()
static void add_commandline_options(MR::App::OptionList &options)
virtual int draw_tool_labels(int, int, const Projection &) const
Definition: base.h:155
void dragLeaveEvent(QDragLeaveEvent *event) override
Definition: base.h:170
void dragEnterEvent(QDragEnterEvent *event) override
Definition: base.h:164
virtual bool process_commandline_option(const MR::App::ParsedOption &opt)
virtual void draw(const Projection &transform, bool is_3D, int axis, int slice)
virtual bool mouse_move_event()
virtual bool mouse_press_event()
virtual bool mouse_release_event()
virtual QSize sizeHint() const override
virtual QCursor * get_cursor()
virtual void close_event()
Definition: base.h:159
std::string current_folder
Definition: base.h:89
Window & window() const
Definition: base.h:87
virtual void reset_event()
Definition: base.h:160
virtual bool panthrough_event(const ModelViewProjection &projection)
virtual bool pan_event(const ModelViewProjection &projection)
virtual bool tilt_event(const ModelViewProjection &projection)
virtual bool rotate_event(const ModelViewProjection &projection)
virtual bool slice_move_event(const ModelViewProjection &projection, float inc)
Dock(const QString &name, bool floating)
Definition: base.h:67
void closeEvent(QCloseEvent *) override
static Window * main
Definition: window.h:160
int main(int cmdline_argc, char **cmdline_argv)
Definition: command.h:77
#define NOMEMALIGN
Definition: memory.h:22
const App::OptionGroup Options
Definition: app.h:274
Dock * create(const QString &text, bool floating)
Definition: base.h:210
Definition: base.h:24
std::string str(const T &value, int precision=0)
Definition: mrtrix.h:247
int axis
size_t index
#define LAYOUT_SPACING
Definition: base.h:25
const std::string name
Definition: thread.h:108