Logo ROOT  
Reference Guide
TPieEditor.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Guido Volpi 12/10/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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
13//////////////////////////////////////////////////////////////////////////
14// //
15// TPieEditor //
16// //
17// Implements GUI for pie-chart attributes. //
18// //
19// Title': set the title of the graph //
20// //
21//////////////////////////////////////////////////////////////////////////
22//Begin_Html
23/*
24<img src="gif/TPieEditor.gif">
25*/
26//End_Html
27
28#include "TGedEditor.h"
29#include "TGComboBox.h"
30#include "TGButtonGroup.h"
31#include "TPieEditor.h"
32#include "TGTextEntry.h"
33#include "TGNumberEntry.h"
34#include "TGToolTip.h"
35#include "TGLabel.h"
36#include "TPie.h"
37#include "TVirtualPad.h"
38#include "TGColorSelect.h"
39#include "TGComboBox.h"
40#include "TColor.h"
41#include "TBox.h"
42#include "TPaveLabel.h"
43
45
46enum EPieWid {
47 kPie = 0,
60};
61
62////////////////////////////////////////////////////////////////////////////////
63/// Constructor of graph editor.
64
66 Int_t height, UInt_t options, Pixel_t back)
67 : TGedFrame(p, width, height, options | kVerticalFrame, back)
68{
69 fPie = 0;
70 // TextEntry to change the title
71 MakeTitle("Pie Chart");
72
73 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kPIE_TITLE);
75 fTitle->SetToolTipText("Enter the pie title string");
76 // better take kLHintsLeft and Right - Right is not working at the moment
77 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
78
79 // Radio Buttons to change the draw options of the graph
80 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
81 fgr = new TGButtonGroup(f2,3,1,3,5,"Label direction");
83 fLblDirH = new TGRadioButton(fgr,"Horizontal",kPIE_HOR); // no draw option
84 fLblDirH->SetToolTipText("Draw horizontal labels");
85 fLblDirR = new TGRadioButton(fgr,"Radial",kPIE_RAD); // option C
86 fLblDirR->SetToolTipText("Draw labels radially");
87 fLblDirT = new TGRadioButton(fgr,"Tangential",kPIE_TAN); // option L
88 fLblDirT->SetToolTipText("Draw labels tangential to the piechart");
89
91 fgr->Show();
93 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
94
95 // CheckBox to activate/deactivate the drawing of the Marker
96 fOutlineOnOff = new TGCheckButton(f2,"Outline",kPIE_OUTLINE);
97 fOutlineOnOff->SetToolTipText("Draw a line to mark the pie");
98 f2->AddFrame(fOutlineOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
99 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
100
101 // Exclusion zone parameters
102 MakeTitle("3D options");
103 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
104 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
105
106 fIs3D = new TGCheckButton(f3,"3D",kPIE_3D);
107 fIs3D->SetToolTipText("Draw a 3D charts");
108 f3->AddFrame(fIs3D, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
109
111 //f3DAngle->SetToolTipText("3D angle: 0-90")
112 f3DAngle->Resize(50, 20);
113 f3->AddFrame(f3DAngle, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
114 f3DAngle->Associate(f3);
115
117 //f3DHeight->SetToolTipText("3D thick")
118 f3DHeight->Resize(50, 20);
119 f3->AddFrame(f3DHeight, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
120 f3DHeight->Associate(f3);
121
122 MakeTitle("Text");
123 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
125 f4->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
126 fColorSelect->Associate(this);
128 f4->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
129 fSizeCombo->Resize(91, 20);
130 fSizeCombo->Associate(this);
131 AddFrame(f4, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
133 fTypeCombo->Resize(137, 20);
134 AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
135}
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Destructor of pie editor.
140
142{
143}
144
145
146////////////////////////////////////////////////////////////////////////////////
147/// Connect signals to slots.
148
150{
151 fTitle->Connect("TextChanged(const char *)","TPieEditor",this,"DoTitle(const char *)");
152 fgr->Connect("Clicked(Int_t)","TPieEditor",this,"DoShape()");
153 fOutlineOnOff->Connect("Toggled(Bool_t)","TPieEditor",this,"DoMarkerOnOff(Bool_t)");
154 f3DAngle->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
155 f3DHeight->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
156 fIs3D->Connect("Clicked()","TPieEditor",this,"DoGraphLineWidth()");
157
158 // text attributes connection
159 fTypeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
160 fSizeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
161 fColorSelect->Connect("ColorSelected(Pixel_t)","TPieEditor",this,"DoTextChange()");
162
163 fInit = kFALSE; // connect the slots to the signals only once
164}
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Exclude TAttTextEditor from this interface.
169
171{
172 TGedEditor *gedEditor = GetGedEditor();
175}
176
177
178////////////////////////////////////////////////////////////////////////////////
179/// Pick up the used values of graph attributes.
180
182{
183 fPie = (TPie *)obj;
185
186 // set the Title TextEntry
187 const char *text = fPie->GetTitle();
189
190 TString soption = GetDrawOption();
191
192 // For the label orientation there are 3 possibilities:
193 // 0: horizontal
194 // 1: radial
195 // 2: tangent
196 Int_t lblor(0);
197
198 // Parse the options
199 Int_t idx;
200 // Paint the TPie in an existing canvas
201 if ( (idx=soption.Index("same"))>=0 ) {
202 // optionSame = kTRUE;
203 soption.Remove(idx,4);
204 }
205
206 if ( (idx=soption.Index("nol"))>=0 ) {
208 soption.Remove(idx,3);
209 }
210 else {
212 }
213
214 // check if is active the pseudo-3d
215 if ( (idx=soption.Index("3d"))>=0 ) {
219 soption.Remove(idx,2);
220 } else {
222 }
223
224 // seek if have to draw the labels around the pie chart
225 if ( (idx=soption.Index("t"))>=0 ) {
226 lblor = 2;
227 soption.Remove(idx,1);
228 }
229
230 // Seek if have to paint the labels along the radii
231 if ( (idx=soption.Index("r"))>=0 ) {
232 lblor = 1;
233 soption.Remove(idx,1);
234 }
235
236 switch(lblor) {
237 case 0:
239 break;
240 case 1:
242 break;
243 case 2:
245 break;
246 }
247
248 // set text attributes
250
254
256 Float_t dy;
257
258 if (obj->InheritsFrom(TPaveLabel::Class())) {
259 TBox *pl = (TBox*)obj;
260 dy = s * (pl->GetY2() - pl->GetY1());
261 }
262 else
263 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
264
265 Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
266 if (size > 50) size = 50;
267 if (size < 0) size = 0;
268 fSizeCombo->Select(size, kFALSE);
269
272}
273
274
275////////////////////////////////////////////////////////////////////////////////
276/// Slot for setting the graph title.
277
278void TPieEditor::DoTitle(const char *text)
279{
280 if (fAvoidSignal) return;
282 Update();
283}
284
285
286////////////////////////////////////////////////////////////////////////////////
287/// Slot connected to the draw options.
288
290{
291 if (fAvoidSignal) return;
292
293 TString opt = GetDrawOption();
294
295 if (fLblDirH->GetState()==kButtonDown) {
296 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
297 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
298 }
299 else if (fLblDirR->GetState()==kButtonDown) {
300 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
301 if (!opt.Contains("r")) opt += "r";
302 }
303 else if (fLblDirT->GetState()==kButtonDown) {
304 if (!opt.Contains("t")) opt += "t";
305 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
306 }
307
308 SetDrawOption(opt);
309 if (gPad && gPad->GetVirtCanvas()) gPad->GetVirtCanvas()->SetCursor(kPointer);
310 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
311}
312
313
314////////////////////////////////////////////////////////////////////////////////
315/// Slot for setting markers as visible/invisible.
316
318{
319 if (fAvoidSignal) return;
321
322 if (t.Contains("nol") && fOutlineOnOff->GetState() == kButtonDown) {
323 t.Remove(t.First("nol"),3);
324 }
325 else if (!t.Contains("nol") && fOutlineOnOff->GetState() == kButtonUp) {
326 t += "nol";
327 }
328
329 SetDrawOption(t);
330}
331
332
333////////////////////////////////////////////////////////////////////////////////
334/// Slot for setting the 3D angle
335
337{
338 if (fAvoidSignal) return;
339
340 fPie->SetAngle3D(static_cast<Int_t>(f3DAngle->GetNumber()));
342
343 Update();
344
345}
346
347
348////////////////////////////////////////////////////////////////////////////////
349/// Slot connected to the graph line width.
350
352{
353 if (fAvoidSignal) return;
354
355 TString opt = GetDrawOption();
356 if (!opt.Contains("3d") && fIs3D->IsDown())
357 opt += "3d";
358 else if (opt.Contains("3d") && !fIs3D->IsDown())
359 opt.Remove(opt.First("3d"),2);
360
361 SetDrawOption(opt);
362
363 Update();
364}
365
366
367
368////////////////////////////////////////////////////////////////////////////////
369/// Change text.
370
372{
373 if (fAvoidSignal) return;
374
375 // font color
377
378 // font type
379 Int_t fontPrec = fPie->GetTextFont()%10;
380 Int_t fontType = fTypeCombo->GetSelected();
381 fPie->SetTextFont(fontType*10+fontPrec);
382
383 // font size
384 TVirtualPad* pad = fGedEditor->GetPad();
385
387
388 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY((Int_t)val);
389 Float_t textSize;
390
392 TBox *pl = (TBox*)fGedEditor->GetModel();
393 textSize = dy/(pl->GetY2() - pl->GetY1());
394 }
395 else
396 textSize = dy/(pad->GetY2() - pad->GetY1());
397
398 fPie->SetTextSize(textSize);
399
400 Update();
401
402}
403
404
405////////////////////////////////////////////////////////////////////////////////
406/// Create text size combo box.
407
409{
410 char a[100];
411 TGComboBox *c = new TGComboBox(parent, id);
412
413 c->AddEntry("Default", 0);
414 for (int i = 1; i <= 50; i++) {
415 snprintf(a, 99, "%d", i);
416 c->AddEntry(a, i);
417 }
418
419 return c;
420}
void Class()
Definition: Class.C:29
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
short Color_t
Definition: RtypesCore.h:79
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kButtonDown
Definition: TGButton.h:54
@ kButtonUp
Definition: TGButton.h:53
@ kChildFrame
Definition: TGFrame.h:57
@ kVerticalFrame
Definition: TGFrame.h:59
@ kFitWidth
Definition: TGFrame.h:64
@ kHorizontalFrame
Definition: TGFrame.h:60
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsTop
Definition: TGLayout.h:34
EPieWid
Definition: TPieEditor.cxx:46
@ kPIE_3DTHICKNESS
Definition: TPieEditor.cxx:56
@ kPie
Definition: TPieEditor.cxx:47
@ kPIE_RAD
Definition: TPieEditor.cxx:49
@ kPIE_3D
Definition: TPieEditor.cxx:54
@ kPIE_FILL
Definition: TPieEditor.cxx:51
@ kPIE_TAN
Definition: TPieEditor.cxx:50
@ kFONT_STYLE
Definition: TPieEditor.cxx:59
@ kFONT_COLOR
Definition: TPieEditor.cxx:57
@ kFONT_SIZE
Definition: TPieEditor.cxx:58
@ kPIE_TITLE
Definition: TPieEditor.cxx:53
@ kPIE_HOR
Definition: TPieEditor.cxx:48
@ kPIE_OUTLINE
Definition: TPieEditor.cxx:52
@ kPIE_3DANGLE
Definition: TPieEditor.cxx:55
#define gPad
Definition: TVirtualPad.h:286
#define gVirtualX
Definition: TVirtualX.h:345
@ kPointer
Definition: TVirtualX.h:47
#define snprintf
Definition: civetweb.c:1540
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
Create a Box.
Definition: TBox.h:24
Double_t GetY1() const
Definition: TBox.h:54
Double_t GetY2() const
Definition: TBox.h:55
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition: TColor.cxx:2003
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition: TColor.cxx:1764
virtual void SetRadioButtonExclusive(Bool_t flag=kTRUE)
If enable is kTRUE, this button group will treat radio buttons as mutually exclusive,...
virtual void Show()
Show group of buttons.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=0)
Set layout hints for the specified button or if button=0 for all buttons.
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1200
virtual Bool_t IsDown() const
Definition: TGButton.h:312
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Pixel_t GetColor() const
virtual Int_t GetSelected() const
Definition: TGComboBox.h:134
virtual TGLBEntry * GetSelectedEntry() const
Definition: TGComboBox.h:135
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:450
TGCompositeFrame(const TGCompositeFrame &)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1025
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void SetNumber(Double_t val)
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
virtual Double_t GetNumber() const
Handle_t GetId() const
Definition: TGObject.h:47
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set radio button state.
Definition: TGButton.cxx:1563
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line.
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:89
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
Definition: TGedEditor.cxx:578
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition: TGedFrame.cxx:81
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
Definition: TGedFrame.cxx:168
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TGedFrame.cxx:145
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGedEditor * GetGedEditor()
Definition: TGedFrame.h:77
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
TGRadioButton * fLblDirH
Definition: TPieEditor.h:43
TGNumberEntry * f3DAngle
Definition: TPieEditor.h:50
virtual void DoTextChange()
Change text.
Definition: TPieEditor.cxx:371
TPie * fPie
Definition: TPieEditor.h:41
virtual void ActivateBaseClassEditors(TClass *)
Exclude TAttTextEditor from this interface.
Definition: TPieEditor.cxx:170
TGColorSelect * fColorSelect
Definition: TPieEditor.h:51
virtual ~TPieEditor()
Destructor of pie editor.
Definition: TPieEditor.cxx:141
virtual void ConnectSignals2Slots()
Connect signals to slots.
Definition: TPieEditor.cxx:149
virtual void DoChange3DAngle()
Slot for setting the 3D angle.
Definition: TPieEditor.cxx:336
TGNumberEntry * f3DHeight
Definition: TPieEditor.h:49
TGCheckButton * fIs3D
Definition: TPieEditor.h:48
virtual void SetModel(TObject *)
Pick up the used values of graph attributes.
Definition: TPieEditor.cxx:181
virtual void DoMarkerOnOff(Bool_t on)
Slot for setting markers as visible/invisible.
Definition: TPieEditor.cxx:317
virtual void DoGraphLineWidth()
Slot connected to the graph line width.
Definition: TPieEditor.cxx:351
TGLayoutHints * fShape1lh
Definition: TPieEditor.h:46
static TGComboBox * BuildFontSizeComboBox(TGFrame *, Int_t)
Create text size combo box.
Definition: TPieEditor.cxx:408
TGRadioButton * fLblDirT
Definition: TPieEditor.h:45
TGRadioButton * fLblDirR
Definition: TPieEditor.h:44
TGComboBox * fSizeCombo
Definition: TPieEditor.h:53
TPieEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of graph editor.
Definition: TPieEditor.cxx:65
TGButtonGroup * fgr
Definition: TPieEditor.h:42
TGTextEntry * fTitle
Definition: TPieEditor.h:39
TGCheckButton * fOutlineOnOff
Definition: TPieEditor.h:47
TGFontTypeComboBox * fTypeCombo
Definition: TPieEditor.h:52
virtual void DoShape()
Slot connected to the draw options.
Definition: TPieEditor.cxx:289
virtual void DoTitle(const char *text)
Slot for setting the graph title.
Definition: TPieEditor.cxx:278
Draw a Pie Chart,.
Definition: TPie.h:23
void SetAngle3D(Float_t val=30.)
Set the value of for the pseudo 3D view angle, in degree.
Definition: TPie.cxx:1178
Double_t GetHeight()
Definition: TPie.h:72
void SetHeight(Double_t val=.08)
Set the height, in pixel, for the piechart if is drawn using the pseudo-3d mode.
Definition: TPie.cxx:1298
Float_t GetAngle3D()
Definition: TPie.h:61
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
Basic string class.
Definition: TString.h:131
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1921
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:499
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:634
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
virtual Int_t YtoPixel(Double_t y) const =0
virtual Double_t GetY1() const =0
virtual Double_t AbsPixeltoY(Int_t py)=0
virtual Double_t GetY2() const =0
TText * text
static constexpr double s
auto * a
Definition: textangle.C:12