Vuo 2.4.4
Loading...
Searching...
No Matches
VuoSpinBox.cc
Go to the documentation of this file.
1
10#include "VuoSpinBox.hh"
11
15VuoSpinBox::VuoSpinBox(QWidget *parent)
16 : QSpinBox(parent)
17{
18 buttonMinimum = INT_MIN;
19 buttonMaximum = INT_MAX;
20
21 setKeyboardTracking(false);
23}
24
28QAbstractSpinBox::StepEnabled VuoSpinBox::stepEnabled() const
29{
30 int v = valueFromText(text());
31 QAbstractSpinBox::StepEnabled e = 0;
32 if (v > buttonMinimum)
33 e |= StepDownEnabled;
34 if (v < buttonMaximum)
35 e |= StepUpEnabled;
36 return e;
37}
38
42void VuoSpinBox::stepBy(int steps)
43{
44 int _value = valueFromText(text());
45 int _singleStep = singleStep();
46
47 if (_singleStep > 0)
48 {
49 if (_value + steps * _singleStep < buttonMinimum)
50 {
51 setValue(buttonMinimum);
52 return;
53 }
54 else if (_value + steps * _singleStep > buttonMaximum)
55 {
56 setValue(buttonMaximum);
57 return;
58 }
59 }
60
61 QSpinBox::stepBy(steps);
62}
63
68{
69 setMinimum(INT_MIN);
70 setMaximum(INT_MAX);
71}
72
76void VuoSpinBox::setButtonMinimum(int buttonMinimum)
77{
78 this->buttonMinimum = buttonMinimum;
79}
80
84void VuoSpinBox::setButtonMaximum(int buttonMaximum)
85{
86 this->buttonMaximum = buttonMaximum;
87}
88
93void VuoSpinBox::focusOutEvent(QFocusEvent * event)
94{
95 Qt::FocusReason reason = event->reason();
96
97 // if tabbing lost focus, keep the value
98 if( reason == Qt::MouseFocusReason ||
99 reason == Qt::TabFocusReason ||
100 reason == Qt::BacktabFocusReason )
101 QSpinBox::focusOutEvent(event);
102}
103
108void VuoSpinBox::hideEvent(QHideEvent * event)
109{
110 // If hideEvent is called while the window still has focus
111 // that means the mouse clicked outside the window and we
112 // should commit the changes.
113 //
114 // This is necessary because in focusOutEvent the FocusReason
115 // does not distinguish the difference between clicking
116 // outside a window and hitting Escape to exit - both
117 // return "ActiveWindowFocusReason"
118
119 if(hasFocus())
120 QSpinBox::hideEvent(event);
121}