Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class TPieEditor
14 \ingroup ged
15
16Implements GUI for pie-chart attributes.
17
18'Title': set the title of the graph
19
20*/
21
22
23#include "TGedEditor.h"
24#include "TGComboBox.h"
25#include "TGButtonGroup.h"
26#include "TPieEditor.h"
27#include "TGTextEntry.h"
28#include "TGNumberEntry.h"
29#include "TPie.h"
30#include "TVirtualPad.h"
31#include "TGColorSelect.h"
32#include "TColor.h"
33#include "TBox.h"
34#include "TPaveLabel.h"
35#include "TVirtualX.h"
36#include "snprintf.h"
37
38
54
55////////////////////////////////////////////////////////////////////////////////
56/// Constructor of graph editor.
57
59 Int_t height, UInt_t options, Pixel_t back)
60 : TGedFrame(p, width, height, options | kVerticalFrame, back)
61{
62 fPie = 0;
63 // TextEntry to change the title
64 MakeTitle("Pie Chart");
65
66 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kPIE_TITLE);
68 fTitle->SetToolTipText("Enter the pie title string");
69 // better take kLHintsLeft and Right - Right is not working at the moment
70 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
71
72 // Radio Buttons to change the draw options of the graph
73 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
74 fgr = new TGButtonGroup(f2,3,1,3,5,"Label direction");
76 fLblDirH = new TGRadioButton(fgr,"Horizontal",kPIE_HOR); // no draw option
77 fLblDirH->SetToolTipText("Draw horizontal labels");
78 fLblDirR = new TGRadioButton(fgr,"Radial",kPIE_RAD); // option C
79 fLblDirR->SetToolTipText("Draw labels radially");
80 fLblDirT = new TGRadioButton(fgr,"Tangential",kPIE_TAN); // option L
81 fLblDirT->SetToolTipText("Draw labels tangential to the piechart");
82
84 fgr->Show();
86 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
87
88 // CheckBox to activate/deactivate the drawing of the Marker
89 fOutlineOnOff = new TGCheckButton(f2,"Outline",kPIE_OUTLINE);
90 fOutlineOnOff->SetToolTipText("Draw a line to mark the pie");
91 f2->AddFrame(fOutlineOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
92 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
93
94 // Exclusion zone parameters
95 MakeTitle("3D options");
96 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
97 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
98
99 fIs3D = new TGCheckButton(f3,"3D",kPIE_3D);
100 fIs3D->SetToolTipText("Draw a 3D charts");
101 f3->AddFrame(fIs3D, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
102
104 //f3DAngle->SetToolTipText("3D angle: 0-90")
105 f3DAngle->Resize(50, 20);
106 f3->AddFrame(f3DAngle, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
107 f3DAngle->Associate(f3);
108
110 //f3DHeight->SetToolTipText("3D thick")
111 f3DHeight->Resize(50, 20);
112 f3->AddFrame(f3DHeight, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
113 f3DHeight->Associate(f3);
114
115 MakeTitle("Text");
116 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
118 f4->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
119 fColorSelect->Associate(this);
121 f4->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
122 fSizeCombo->Resize(91, 20);
123 fSizeCombo->Associate(this);
124 AddFrame(f4, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
126 fTypeCombo->Resize(137, 20);
127 AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
128}
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Destructor of pie editor.
133
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// Connect signals to slots.
141
143{
144 fTitle->Connect("TextChanged(const char *)","TPieEditor",this,"DoTitle(const char *)");
145 fgr->Connect("Clicked(Int_t)","TPieEditor",this,"DoShape()");
146 fOutlineOnOff->Connect("Toggled(Bool_t)","TPieEditor",this,"DoMarkerOnOff(Bool_t)");
147 f3DAngle->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
148 f3DHeight->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
149 fIs3D->Connect("Clicked()","TPieEditor",this,"DoGraphLineWidth()");
150
151 // text attributes connection
152 fTypeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
153 fSizeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
154 fColorSelect->Connect("ColorSelected(Pixel_t)","TPieEditor",this,"DoTextChange()");
155
156 fInit = kFALSE; // connect the slots to the signals only once
157}
158
159
160////////////////////////////////////////////////////////////////////////////////
161/// Exclude TAttTextEditor from this interface.
162
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Pick up the used values of graph attributes.
173
175{
176 fPie = (TPie *)obj;
178
179 // set the Title TextEntry
180 const char *text = fPie->GetTitle();
182
184
185 // For the label orientation there are 3 possibilities:
186 // 0: horizontal
187 // 1: radial
188 // 2: tangent
189 Int_t lblor(0);
190
191 // Parse the options
192 Int_t idx;
193 // Paint the TPie in an existing canvas
194 if ( (idx=soption.Index("same"))>=0 ) {
195 // optionSame = kTRUE;
196 soption.Remove(idx,4);
197 }
198
199 if ( (idx=soption.Index("nol"))>=0 ) {
201 soption.Remove(idx,3);
202 }
203 else {
205 }
206
207 // check if is active the pseudo-3d
208 if ( (idx=soption.Index("3d"))>=0 ) {
212 soption.Remove(idx,2);
213 } else {
215 }
216
217 // seek if have to draw the labels around the pie chart
218 if ( (idx=soption.Index("t"))>=0 ) {
219 lblor = 2;
220 soption.Remove(idx,1);
221 }
222
223 // Seek if have to paint the labels along the radii
224 if ( (idx=soption.Index("r"))>=0 ) {
225 lblor = 1;
226 soption.Remove(idx,1);
227 }
228
229 switch(lblor) {
230 case 0:
232 break;
233 case 1:
235 break;
236 case 2:
238 break;
239 }
240
241 // set text attributes
243
247
248 Float_t s = fPie->GetTextSize();
249 Float_t dy;
250
251 if (obj->InheritsFrom(TPaveLabel::Class())) {
252 TBox *pl = (TBox*)obj;
253 dy = s * (pl->GetY2() - pl->GetY1());
254 }
255 else
256 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
257
258 Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
259 if (size > 50) size = 50;
260 if (size < 0) size = 0;
262
265}
266
267
268////////////////////////////////////////////////////////////////////////////////
269/// Slot for setting the graph title.
270
271void TPieEditor::DoTitle(const char *text)
272{
273 if (fAvoidSignal) return;
275 Update();
276}
277
278
279////////////////////////////////////////////////////////////////////////////////
280/// Slot connected to the draw options.
281
283{
284 if (fAvoidSignal) return;
285
286 TString opt = GetDrawOption();
287
288 if (fLblDirH->GetState()==kButtonDown) {
289 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
290 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
291 }
292 else if (fLblDirR->GetState()==kButtonDown) {
293 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
294 if (!opt.Contains("r")) opt += "r";
295 }
296 else if (fLblDirT->GetState()==kButtonDown) {
297 if (!opt.Contains("t")) opt += "t";
298 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
299 }
300
301 SetDrawOption(opt);
302 if (gPad && gPad->GetVirtCanvas()) gPad->GetVirtCanvas()->SetCursor(kPointer);
303 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
304}
305
306
307////////////////////////////////////////////////////////////////////////////////
308/// Slot for setting markers as visible/invisible.
309
311{
312 if (fAvoidSignal) return;
314
315 if (t.Contains("nol") && fOutlineOnOff->GetState() == kButtonDown) {
316 t.Remove(t.First("nol"),3);
317 }
318 else if (!t.Contains("nol") && fOutlineOnOff->GetState() == kButtonUp) {
319 t += "nol";
320 }
321
322 SetDrawOption(t);
323}
324
325
326////////////////////////////////////////////////////////////////////////////////
327/// Slot for setting the 3D angle
328
330{
331 if (fAvoidSignal) return;
332
333 fPie->SetAngle3D(static_cast<Int_t>(f3DAngle->GetNumber()));
335
336 Update();
337
338}
339
340
341////////////////////////////////////////////////////////////////////////////////
342/// Slot connected to the graph line width.
343
345{
346 if (fAvoidSignal) return;
347
348 TString opt = GetDrawOption();
349 if (!opt.Contains("3d") && fIs3D->IsDown())
350 opt += "3d";
351 else if (opt.Contains("3d") && !fIs3D->IsDown())
352 opt.Remove(opt.First("3d"),2);
353
354 SetDrawOption(opt);
355
356 Update();
357}
358
359
360
361////////////////////////////////////////////////////////////////////////////////
362/// Change text.
363
365{
366 if (fAvoidSignal) return;
367
368 // font color
370
371 // font type
375
376 // font size
378
379 Float_t val = TString(fSizeCombo->GetSelectedEntry()->GetTitle()).Atoi();
380
381 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY((Int_t)val);
383
384 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
386 textSize = dy/(pl->GetY2() - pl->GetY1());
387 }
388 else
389 textSize = dy/(pad->GetY2() - pad->GetY1());
390
392
393 Update();
394
395}
396
397
398////////////////////////////////////////////////////////////////////////////////
399/// Create text size combo box.
400
402{
403 char a[100];
404 TGComboBox *c = new TGComboBox(parent, id);
405
406 c->AddEntry("Default", 0);
407 for (int i = 1; i <= 50; i++) {
408 snprintf(a, 99, "%d", i);
409 c->AddEntry(a, i);
410 }
411
412 return c;
413}
@ kPointer
Definition GuiTypes.h:375
@ kChildFrame
Definition GuiTypes.h:379
@ kVerticalFrame
Definition GuiTypes.h:381
@ kFitWidth
Definition GuiTypes.h:386
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kFONT_STYLE
@ kFONT_SIZE
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
EPieWid
@ kPIE_3DTHICKNESS
@ kPie
@ kPIE_RAD
@ kPIE_3D
@ kPIE_FILL
@ kPIE_TAN
@ kFONT_STYLE
@ kFONT_COLOR
@ kFONT_SIZE
@ kPIE_TITLE
@ kPIE_HOR
@ kPIE_OUTLINE
@ kPIE_3DANGLE
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
#define snprintf
Definition civetweb.c:1579
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:38
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:37
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:46
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:48
static TClass * Class()
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:49
Create a Box.
Definition TBox.h:22
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2445
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:1926
Organizes TGButton widgets in a group.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=nullptr)
Set layout hints for the specified button or if button=0 for all buttons.
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 SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:439
virtual EButtonState GetState() const
Definition TGButton.h:112
Selects different options.
Definition TGButton.h:264
Bool_t IsDown() const override
Definition TGButton.h:311
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set check button state.
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Pixel_t GetColor() const
A combobox (also known as a drop down listbox) allows the selection of one item out of a list of item...
Definition TGComboBox.h:47
virtual Int_t GetSelected() const
Definition TGComboBox.h:114
virtual TGLBEntry * GetSelectedEntry() const
Definition TGComboBox.h:115
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...
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
TGCompositeFrame(const TGCompositeFrame &)=delete
void ChangeOptions(UInt_t options) override
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1035
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.
Definition TGComboBox.h:178
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGNumberEntry is a number entry input widget with up/down buttons.
void Associate(const TGWindow *w) override
Make w the window that will receive the generated messages.
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
@ kNEANonNegative
Non-negative number.
@ kNESReal
Real number.
@ kNESInteger
Style of number entry field.
@ kNELLimitMinMax
Both lower and upper limits.
Handle_t GetId() const
Definition TGObject.h:41
Selects different options.
Definition TGButton.h:321
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set radio button state.
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
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:72
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual TVirtualPad * GetPad() const
Definition TGedEditor.h:78
virtual TObject * GetModel() const
Definition TGedEditor.h:79
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
void SetDrawOption(Option_t *option="") override
Set drawing option for object.
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:71
Option_t * GetDrawOption() const override
Get draw options of the selected object.
Definition TGedFrame.cxx:79
TGedEditor * GetGedEditor()
Definition TGedFrame.h:71
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
static TClass * Class()
void ActivateBaseClassEditors(TClass *) override
Exclude TAttTextEditor from this interface.
TGRadioButton * fLblDirH
Draw slice's labels horizontal.
Definition TPieEditor.h:36
TGNumberEntry * f3DAngle
set the pseudo 3D angle
Definition TPieEditor.h:43
virtual void DoTextChange()
Change text.
TPie * fPie
Pie object.
Definition TPieEditor.h:34
TGColorSelect * fColorSelect
font color selector
Definition TPieEditor.h:44
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void DoChange3DAngle()
Slot for setting the 3D angle.
TGNumberEntry * f3DHeight
set the 3D tickness
Definition TPieEditor.h:42
TGCheckButton * fIs3D
set if is enabled the pseudo-3d mode
Definition TPieEditor.h:41
virtual void DoMarkerOnOff(Bool_t on)
Slot for setting markers as visible/invisible.
virtual void DoGraphLineWidth()
Slot connected to the graph line width.
void SetModel(TObject *) override
Pick up the used values of graph attributes.
TGLayoutHints * fShape1lh
layout-hints for fShape1
Definition TPieEditor.h:39
static TGComboBox * BuildFontSizeComboBox(TGFrame *, Int_t)
Create text size combo box.
TGRadioButton * fLblDirT
Draw slice's labels tangential to the piechart's circle.
Definition TPieEditor.h:38
TGRadioButton * fLblDirR
Draw slice's labels radial to the piechart.
Definition TPieEditor.h:37
TGComboBox * fSizeCombo
font size
Definition TPieEditor.h:46
TGButtonGroup * fgr
Group the Radiobuttons:
Definition TPieEditor.h:35
TGTextEntry * fTitle
Contains the title of the graph.
Definition TPieEditor.h:32
TGCheckButton * fOutlineOnOff
set piechart outline visible/unvisible
Definition TPieEditor.h:40
TGFontTypeComboBox * fTypeCombo
font style
Definition TPieEditor.h:45
TPieEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of graph editor.
virtual void DoShape()
Slot connected to the draw options.
virtual void DoTitle(const char *text)
Slot for setting the graph title.
~TPieEditor() override
Destructor of pie editor.
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:1145
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:1265
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:865
Basic string class.
Definition TString.h:138
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1994
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:545
TString & Remove(Ssiz_t pos)
Definition TString.h:693
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51