Developer documentation
Version 3.0.3-105-gd3941f44
adjust_button.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_adjust_button_h__
18#define __gui_mrview_adjust_button_h__
19
20#include "mrtrix.h"
21#include "gui/opengl/gl.h"
22
23#define ADJUST_BUTTON_DEADZONE_SIZE 8
24
25namespace MR
26{
27 namespace GUI
28 {
29 namespace MRView
30 {
31
32 class AdjustButton : public QLineEdit
34 Q_OBJECT
35
36 public:
37 AdjustButton (QWidget* parent, float change_rate = 1.0);
38
39 float value () const {
40 if (text().isEmpty())
41 return NAN;
42 try {
43 return to<float> (text().toStdString());
44 }
45 catch (Exception) {
46 return NAN;
47 }
48 }
49
50 bool isMin() const { return is_min; }
51 bool isMax() const { return is_max; }
52
53 void setValue (float val) {
54 if (std::isfinite (val)) {
55 if (val >= max) {
56 setText (str(max).c_str());
57 is_min = false; is_max = true;
58 } else if (val <= min) {
59 setText (str(min).c_str());
60 is_min = true; is_max = false;
61 } else {
62 setText (str(val).c_str());
63 is_min = is_max = false;
64 }
65 }
66 else {
67 clear();
68 is_min = is_max = false;
69 }
70 }
71
72
73 void setRate (float new_rate) {
74 rate = new_rate;
75 }
76
77 void setMin (float val) {
78 min = val;
79 if (value() <= val) {
80 setValue (val);
81 is_min = true;
82 emit valueChanged();
83 emit valueChanged (val);
84 }
85 }
86
87 void setMax (float val) {
88 max = val;
89 if (value() >= val) {
90 setValue (val);
91 is_max = true;
92 emit valueChanged();
93 emit valueChanged (val);
94 }
95 }
96
97 float getMin() const { return min; }
98 float getMax() const { return max; }
99
100 signals:
102 void valueChanged (float val);
103
104 protected slots:
105 void onSetValue ();
106
107 protected:
108 float rate, min, max;
111
114
115 bool eventFilter (QObject *obj, QEvent *event);
116 };
117
118
119 }
120 }
121}
122
123#endif
124
AdjustButton(QWidget *parent, float change_rate=1.0)
void setRate(float new_rate)
Definition: adjust_button.h:73
bool eventFilter(QObject *obj, QEvent *event)
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24
std::string str(const T &value, int precision=0)
Definition: mrtrix.h:247