Logo ROOT   6.10/09
Reference Guide
TEveGValuators.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TEveGValuators.h"
13 
14 #include "TMath.h"
15 #include "TGLabel.h"
16 #include "TGSlider.h"
17 #include "TGDoubleSlider.h"
18 
19 /** \class TEveGValuatorBase
20 \ingroup TEve
21 Base class for composite GUI elements for setting of numeric values.
22 */
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Constructor.
28 
30  UInt_t w, UInt_t h, Int_t widgetId) :
31  TGCompositeFrame(p, w, h), TGWidget(widgetId),
32 
33  fLabelWidth (0),
34  fAlignRight (kFALSE),
35  fShowSlider (kTRUE),
36 
37  fNELength (5),
38  fNEHeight (20),
39 
40  fLabel (0)
41 {
42  SetName(name);
43 }
44 
45 /** \class TEveGValuator
46 \ingroup TEve
47 Composite GUI element for single value selection (supports label,
48 number-entry and slider).
49 */
50 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Constructor.
55 
56 TEveGValuator::TEveGValuator(const TGWindow *p, const char* title,
57  UInt_t w, UInt_t h, Int_t widgetId) :
58  TEveGValuatorBase(p, title, w, h, widgetId),
59 
60  fValue (0),
61  fMin (0),
62  fMax (0),
63 
64  fSliderNewLine (kFALSE),
65  fSliderDivs (-1),
66  fEntry (0),
67  fSlider (0)
68 {
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Create sub-components (label, number entry, slider).
73 
75 {
76  TGCompositeFrame *hf1, *hfs;
79  hf1 = new TGHorizontalFrame(this);
80  hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
81  AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
82  hfs = new TGHorizontalFrame(this);
83  hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
84  AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
85  } else {
86  hf1 = this;
87  hfs = this;
89  }
90 
91  // label
92  {
93  TGLayoutHints *labh, *labfrh;
94  if(fAlignRight) {
95  labh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,0,0,0);
96  labfrh = new TGLayoutHints(kLHintsRight);
97  } else {
98  labh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,0,0,0);
99  labfrh = new TGLayoutHints(kLHintsLeft);
100  }
101  TGCompositeFrame *labfr =
104  fLabel = new TGLabel(labfr, fName);
105  labfr->AddFrame(fLabel, labh);
106  hf1->AddFrame(labfr, labfrh);
107  }
108 
109  // number-entry
110  TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
111  fEntry = new TGNumberEntry(hf1, 0, fNELength);
113  fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value");
114  hf1->AddFrame(fEntry, elh);
115 
116  if (connect)
117  fEntry->Connect("ValueSet(Long_t)",
118  "TEveGValuator", this, "EntryCallback()");
119 
120  // slider
121  if(fShowSlider) {
122  fSlider = new TGHSlider(hfs, GetWidth(), kSlider1 | kScaleBoth);
123  hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsLeft|kLHintsTop, 1,1,0,0));
124 
125  if (connect)
126  fSlider->Connect("PositionChanged(Int_t)",
127  "TEveGValuator", this, "SliderCallback()");
128  }
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Set limits of the represented value.
133 
136 {
137  fMin = Float_t(min);
138  fMax = Float_t(max);
139  fEntry->SetFormat(nef);
141 
142  if(fSlider) {
143  fSliderDivs = npos - 1;
145  }
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Set limits of the represented value for integer values.
150 
152 {
153  fMin = Float_t(min);
154  fMax = Float_t(max);
157 
158  if(fSlider) {
159  fSliderDivs = max - min;
161  }
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Return slider position for given value.
166 
168 {
169  return (Int_t) TMath::Nint((v - fMin)*fSliderDivs/(fMax - fMin));
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Callback for change in number-entry.
174 
176 {
177  fValue = fEntry->GetNumber();
178  if(fSlider) {
180  }
181  ValueSet(fValue);
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Callback for change in slider position.
186 
188 {
191  ValueSet(fValue);
192 }
193 
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Emit "ValueSet(Double_t)" signal.
197 
199 {
200  Emit("ValueSet(Double_t)", val);
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// Set value, optionally emit signal.
205 
207 {
208  fValue = val;
210 
211  if(fSlider){
213  }
214  if(emit)
215  ValueSet(val);
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Set the tooltip of the number-entry.
220 
221 void TEveGValuator::SetToolTip(const char* tip)
222 {
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Set enabled state of the whole widget.
228 
230 {
231  fEntry->GetNumberEntry()->SetEnabled(state);
232  fEntry->GetButtonUp()->SetEnabled(state);
233  fEntry->GetButtonDown()->SetEnabled(state);
234  if(fSlider) {
235  if(state) fSlider->MapWindow();
236  else fSlider->UnmapWindow();
237  }
238 }
239 
240 /** \class TEveGDoubleValuator
241 \ingroup TEve
242 Composite GUI element for selection of range (label, two
243 number-entries and double-slider).
244 */
245 
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Constructor.
250 
252  UInt_t w, UInt_t h, Int_t widgetId) :
253  TEveGValuatorBase(p, title, w, h, widgetId),
254 
255  fMinEntry(0),
256  fMaxEntry(0),
257  fSlider(0)
258 {
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Create sub-components (label, number entries, double-slider).
263 
265 {
266  TGCompositeFrame *hf1, *hfs;
267  if(fShowSlider) {
269  hf1 = new TGHorizontalFrame(this);
270  hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
271  AddFrame(hf1, new TGLayoutHints(kLHintsTop));
272  hfs = new TGHorizontalFrame(this);
273  hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
274  AddFrame(hfs, new TGLayoutHints(kLHintsTop));
275  } else {
276  hf1 = this;
277  hfs = this;
279  }
280 
281  // label
282  TGLayoutHints* lh;
283  if(fAlignRight)
284  lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 4,0,0,0);
285  else
286  lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,4,0,0);
287 
288  if(fLabelWidth > 0) {
290  fLabel = new TGLabel(lf, fName);
291  lf->AddFrame(fLabel, lh);
292  // add label frame to top horizontal frame
293  TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
294  hf1->AddFrame(lf, lfh);
295  } else {
296  fLabel = new TGLabel(hf1, fName);
297  hf1->AddFrame(fLabel, lh);
298  }
299 
300  // entries
301  fMinEntry = new TGNumberEntry(hf1, 0, fNELength);
303  fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value");
304  hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
305  if (connect)
306  fMinEntry->Connect("ValueSet(Long_t)",
307  "TEveGDoubleValuator", this, "MinEntryCallback()");
308 
309  fMaxEntry = new TGNumberEntry(hf1, 0, fNELength);
311  fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value");
312  hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
313  if (connect)
314  fMaxEntry->Connect("ValueSet(Long_t)",
315  "TEveGDoubleValuator", this, "MaxEntryCallback()");
316 
317  // slider
318  if(fShowSlider) {
320  hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0,0,1,0));
321  if (connect)
322  fSlider->Connect("PositionChanged()",
323  "TEveGDoubleValuator", this, "SliderCallback()");
324  }
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Set limits of the represented range for integer values.
329 
331 {
336 
337  if(fSlider) {
338  fSlider->SetRange(min, max);
339  }
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 /// Set limits of the represented range.
344 
347 {
348  // printf("TEveGDoubleValuator::SetLimits(Float_t min, Float_t max, Int_ \n");
350  fMinEntry->SetFormat(nef);
352  fMaxEntry->SetFormat(nef);
353 
354  if(fSlider) fSlider->SetRange(min, max);
355 }
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Callback for change in low number-entry.
359 
361 {
362  if(GetMin() > GetMax())
365  ValueSet();
366 }
367 
368 ////////////////////////////////////////////////////////////////////////////////
369 /// Callback for change in high number-entry.
370 
372 {
373  if(GetMax() < GetMin())
376  ValueSet();
377 }
378 
379 ////////////////////////////////////////////////////////////////////////////////
380 /// Callback for change in slider position / width.
381 
383 {
384  Float_t minp, maxp;
385  fSlider->GetPosition(minp, maxp);
386  fMinEntry->SetNumber(minp);
387  fMaxEntry->SetNumber(maxp);
388  ValueSet();
389 }
390 
391 ////////////////////////////////////////////////////////////////////////////////
392 /// Set min/max values, optionally emit signal.
393 
395 {
396  fMinEntry->SetNumber(min);
397  fMaxEntry->SetNumber(max);
398 
399  if(fSlider) fSlider->SetPosition(min, max);
400  if(emit) ValueSet();
401 }
402 
403 ////////////////////////////////////////////////////////////////////////////////
404 /// Emit "ValueSet()" signal.
405 
407 {
408  Emit("ValueSet()");
409 }
410 
411 /** \class TEveGTriVecValuator
412 \ingroup TEve
413 Composite GUI element for setting three numerical values (label,
414 three number-entries). All three values have the same number-format
415 and value-range.
416 */
417 
419 
420 ////////////////////////////////////////////////////////////////////////////////
421 /// Constructor.
422 
424  UInt_t w, UInt_t h, Int_t widgetId) :
425  TGCompositeFrame(p, w, h), TGWidget(widgetId),
426 
427  fLabelWidth (0),
428  fNELength (5),
429  fNEHeight (20)
430 {
431  SetName(name);
432 }
433 
434 ////////////////////////////////////////////////////////////////////////////////
435 /// Create sub-components (label, number entries).
436 
437 void TEveGTriVecValuator::Build(Bool_t vertical, const char* lab0, const char* lab1, const char* lab2)
438 {
439  if (vertical) SetLayoutManager(new TGVerticalLayout(this));
440  else SetLayoutManager(new TGHorizontalLayout(this));
441 
442  const char *labs[3] = { lab0, lab1, lab2 };
443  TGLayoutHints* lh;
444  for (Int_t i=0; i<3; ++i) {
445  fVal[i] = new TEveGValuator(this, labs[i], 10, 0);
450  fVal[i]->Build();
451  fVal[i]->Connect
452  ("ValueSet(Double_t)", "TEveGTriVecValuator", this, "ValueSet()");
453  if (vertical) lh = new TGLayoutHints(kLHintsTop, 1, 1, 1, 1);
454  else lh = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 1, 1);
455  AddFrame(fVal[i], lh);
456  }
457 }
458 
459 ////////////////////////////////////////////////////////////////////////////////
460 /// Emit "ValueSet()" signal.
461 
463 {
464  Emit("ValueSet()");
465 }
466 
467 ////////////////////////////////////////////////////////////////////////////////
468 /// Set limits for all three number-entries, integer values.
469 
471 {
472  for (Int_t i=0; i<3; ++i)
473  fVal[i]->SetLimits(min, max);
474 }
475 
476 ////////////////////////////////////////////////////////////////////////////////
477 /// Set limits for all three number-entries.
478 
481 {
482  for (Int_t i=0; i<3; ++i)
483  fVal[i]->SetLimits(min, max, 0, nef);
484 }
485 
Composite GUI element for setting three numerical values (label, three number-entries).
void MaxEntryCallback()
Callback for change in high number-entry.
void SetLimits(Int_t min, Int_t max)
Set limits for all three number-entries, integer values.
void ValueSet()
Emit "ValueSet()" signal.
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
float Float_t
Definition: RtypesCore.h:53
virtual void SetValue(Float_t v, Bool_t emit=kFALSE)
Set value, optionally emit signal.
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
void SliderCallback()
Callback for change in slider position.
TH1 * h
Definition: legend2.C:5
virtual void SetNumber(Double_t val)
void SetLimits(Int_t min, Int_t max)
Set limits of the represented range for integer values.
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:982
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
void SetToolTip(const char *tip)
Set the tooltip of the number-entry.
virtual void SetRange(Float_t min, Float_t max)
UInt_t GetWidth() const
Definition: TGFrame.h:271
TGNumberEntry * fEntry
TGButton * GetButtonDown() const
TGNumberEntry * fMinEntry
Composite GUI element for single value selection (supports label, number-entry and slider)...
virtual void GetPosition(Float_t &min, Float_t &max) const
TEveGValuator * fVal[3]
void SliderCallback()
Callback for change in slider position / width.
Float_t GetMax() const
virtual void SetName(const char *name)
Definition: TGWindow.h:121
void Build(Bool_t vertical, const char *lab0, const char *lab1, const char *lab2)
Create sub-components (label, number entries).
void SetNEHeight(Int_t h)
TEveGValuator(const TEveGValuator &)
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
void SetShowSlider(Bool_t s=kTRUE)
void ValueSet(Double_t)
Emit "ValueSet(Double_t)" signal.
SVector< double, 2 > v
Definition: Dict.h:5
void SetNELength(Int_t l)
PyObject * fValue
TGNumberEntry * fMaxEntry
void ValueSet()
Emit "ValueSet()" signal.
Base class for composite GUI elements for setting of numeric values.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
void SetEnabled(Bool_t state)
Set enabled state of the whole widget.
TString fName
Definition: TGWindow.h:39
TGButton * GetButtonUp() const
TEveGValuatorBase(const TEveGValuatorBase &)
const Bool_t kFALSE
Definition: RtypesCore.h:92
void SetValues(Float_t min, Float_t max, Bool_t emit=kFALSE)
Set min/max values, optionally emit signal.
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
virtual void Build(Bool_t connect=kTRUE)
Create sub-components (label, number entry, slider).
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:164
#define ClassImp(name)
Definition: Rtypes.h:336
virtual void Build(Bool_t connect=kTRUE)
Create sub-components (label, number entries, double-slider).
double Double_t
Definition: RtypesCore.h:55
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
virtual Double_t GetNumber() const
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
Float_t GetMin() const
virtual void UnmapWindow()
Definition: TGFrame.h:253
virtual void SetHeight(UInt_t h)
Definition: TGFrame.h:294
TGNumberEntryField * GetNumberEntry() const
virtual void MapWindow()
Definition: TGFrame.h:251
Int_t CalcSliderPos(Float_t v)
Return slider position for given value.
void EntryCallback()
Callback for change in number-entry.
TGHSlider * fSlider
void SetLabelWidth(Int_t w)
virtual void SetPosition(Float_t min, Float_t max)
TEveGDoubleValuator(const TEveGDoubleValuator &)
TGDoubleHSlider * fSlider
TEveGTriVecValuator(const TEveGTriVecValuator &)
Composite GUI element for selection of range (label, two number-entries and double-slider).
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
void SetLimits(Int_t min, Int_t max)
Set limits of the represented value for integer values.
Bool_t fSliderNewLine
const Bool_t kTRUE
Definition: RtypesCore.h:91
Int_t Nint(T x)
Definition: TMath.h:607
void MinEntryCallback()
Callback for change in low number-entry.