Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoQtSlider.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24#ifndef _SO_QT_SLIDER_
25#define _SO_QT_SLIDER_
26
27#include <Inventor/Qt/OivQtCompat.h>
28#include <Inventor/misc/SoCallbackList.h>
29#include <Inventor/Qt/SoQtComponent.h>
30#include <Inventor/Qt/SoQtBasicSlider.h>
31
32#include <QPointer>
33
34class SoFloatCallbackList;
35class QLayout;
36class QHBoxLayout;
37class QLineEdit;
38class QLabel;
39
40// callback function prototypes
41typedef void SoQtSliderCB(void *userData, float val);
42
43
45// Class: SoQtSlider
46//
47// This is the basic slider type, which lets you set the slider value with a
48// slot and emit signals (and register callbacks) when the slider is being
49// moved (either as soon as the slider changes values, or when the slider has
50// stopped moving (mouse up)).
51
52{
53 Q_OBJECT
54
55 public:
56
57 // constructor/destructor
58 SoQtSlider( QWidget* parent = NULL,
59 const char *name = NULL,
60 SbBool buildInsideParent = TRUE);
61 ~SoQtSlider();
62
63 // Access functions
64 float getValue() const;
65 void setLabel(const QString&);
66 const QString& getLabel() const;
67
68 // Display a numeric value in a text field to the right of the slider
69 // which can be edited to change the value of the slider.
70 // Default is TRUE (display the numeric value).
71 void setNumericFieldVisible(SbBool b = TRUE);
72 SbBool isNumericFieldVisible() const { return numberVisible; }
73
74 // Those routines are used to register callbacks for the different slider
75 // actions.
76 // NOTE: the start and finish callbacks are only to signal when the mouse
77 // goes down and up. No valid callback data is passed (0.0 passed).
78 void addStartCallback (SoQtSliderCB *f, void *userData = NULL);
79 void addValueChangedCallback (SoQtSliderCB *f, void *userData = NULL);
80 void addFinishCallback (SoQtSliderCB *f, void *userData = NULL);
81
82 void removeStartCallback (SoQtSliderCB *f, void *userData = NULL);
83 void removeValueChangedCallback (SoQtSliderCB *f, void *userData = NULL);
84 void removeFinishCallback (SoQtSliderCB *f, void *userData = NULL);
85
86 // true while the value is changing interactively
87 void interactivity( SbBool flag ) { sliderWidget->interactivity(flag); }
88 SbBool isInteractive() { return sliderWidget->isInteractive(); }
89
90 // sets/gets the size of the actual slider, excluding the label and
91 // text field widget sizes which are fixed in size.
92 // This is the prefered behavior since it allows a user to align
93 // multiple sliders (same size) regardless of the text label size
94 // (which are usually different).
95 // NOTE: this is different from most widgets, which do resize their
96 // container widgets. This functionality can still be achieved using
97 // the setSize() and getSize() methods.
98 void setSliderSize(const SbVec2s &size);
99 SbVec2s getSliderSize();
100
101
102 private:
103 // This constructor takes a boolean whether to build the widget now.
104 // Subclasses can pass FALSE, then call SoQtSlider::buildWidget()
105 // when they are ready for it to be built.
106 SoEXTENDER SoQtSlider (QWidget* parent,
107 const char *name,
108 SbBool buildInsideParent,
109 SbBool buildNow);
110
111 // Actualy build the widgets
112 QWidget* buildWidget(QWidget* parent, SoQtBasicSlider::Type t = SoQtBasicSlider::PLAIN_SLIDER);
113
114 // Data
115 SoQtBasicSlider* sliderWidget;
116
117 private:
118 // Data
119 QPointer<QWidget> mgrWidget;
120 QPointer<QLineEdit> numberWidget;
121 QPointer<QLabel> labelWidget;
122 QHBoxLayout* layout;
123 SbBool numberVisible;
124 SbVec2s sliderSize;
125 QString labelString;
126
127 // build routines
128 void constructorCommon(SbBool buildNow);
129 void doLayout();
130 void updateText ();
131
132 // Callbacks
133 void sliderChanged(float val);
134 static void sliderChangedCB(void *p, float val) { ((SoQtSlider*)p)->sliderChanged (val); };
135 void sliderStart();
136 static void sliderStartCB(void *p, float val);
137 void sliderStop();
138 static void sliderStopCB(void *p, float val);
139 static void textFieldCB(QWidget*, SoQtSlider *, XtPointer);
140
141 private Q_SLOTS:
142 // internal use only
143 void textChangedSlot();
144
145 public Q_SLOTS:
146 // Set the value of the slider
147 void setValue(float v);
148
149 Q_SIGNALS:
150 // Those signals are the pendant of the callbacks routines
151 void start ();
152 void valueChanged (float value);
153 void finish ();
154
155};
156
157inline void
158SoQtSlider::sliderStartCB(void *p, float )
159{
160 ((SoQtSlider*)p)->sliderStart ();
161}
162
163inline void
164SoQtSlider::sliderStopCB(void *p, float )
165{
166 ((SoQtSlider*)p)->sliderStop ();
167}
168
169#endif /* _SO_QT_SLIDER_ */
170
171
2D vector class.
Definition SbVec.h:700
int SbBool
Boolean type.
Definition SbBase.h:87
void * XtPointer
Definition SoQtDef.h:122