65 TPieEditor::TPieEditor(
const TGWindow *p, Int_t width,
66 Int_t height, UInt_t options, Pixel_t back)
67 : TGedFrame(p, width, height, options | kVerticalFrame, back)
71 MakeTitle(
"Pie Chart");
73 fTitle =
new TGTextEntry(
this,
new TGTextBuffer(50), kPIE_TITLE);
74 fTitle->Resize(135, fTitle->GetDefaultHeight());
75 fTitle->SetToolTipText(
"Enter the pie title string");
77 AddFrame(fTitle,
new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
80 TGCompositeFrame *f2 =
new TGCompositeFrame(
this, 80, 20, kVerticalFrame);
81 fgr =
new TGButtonGroup(f2,3,1,3,5,
"Label direction");
82 fgr->SetRadioButtonExclusive(kTRUE);
83 fLblDirH =
new TGRadioButton(fgr,
"Horizontal",kPIE_HOR);
84 fLblDirH->SetToolTipText(
"Draw horizontal labels");
85 fLblDirR =
new TGRadioButton(fgr,
"Radial",kPIE_RAD);
86 fLblDirR->SetToolTipText(
"Draw labels radially");
87 fLblDirT =
new TGRadioButton(fgr,
"Tangential",kPIE_TAN);
88 fLblDirT->SetToolTipText(
"Draw labels tangential to the piechart");
90 fgr->SetLayoutHints(fShape1lh=
new TGLayoutHints(kLHintsLeft, 0,3,0,0), fLblDirH);
92 fgr->ChangeOptions(kFitWidth|kChildFrame|kVerticalFrame);
93 f2->AddFrame(fgr,
new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
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));
102 MakeTitle(
"3D options");
103 TGCompositeFrame *f3 =
new TGCompositeFrame(
this, 80, 20, kHorizontalFrame);
104 AddFrame(f3,
new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
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));
110 f3DAngle =
new TGNumberEntry(f3, 0, 2, kPIE_3DANGLE, TGNumberEntry::kNESInteger, TGNumberEntry::kNEANonNegative,TGNumberFormat::kNELLimitMinMax, 0, 90);
112 f3DAngle->Resize(50, 20);
113 f3->AddFrame(f3DAngle,
new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
114 f3DAngle->Associate(f3);
116 f3DHeight =
new TGNumberEntry(f3, 0, 3, kPIE_3DTHICKNESS, TGNumberEntry::kNESReal, TGNumberEntry::kNEANonNegative);
118 f3DHeight->Resize(50, 20);
119 f3->AddFrame(f3DHeight,
new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
120 f3DHeight->Associate(f3);
123 TGCompositeFrame *f4 =
new TGCompositeFrame(
this, 80, 20, kHorizontalFrame);
124 fColorSelect =
new TGColorSelect(f4, 0, kFONT_COLOR);
125 f4->AddFrame(fColorSelect,
new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
126 fColorSelect->Associate(
this);
127 fSizeCombo = BuildFontSizeComboBox(f4, kFONT_SIZE);
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));
132 fTypeCombo =
new TGFontTypeComboBox(
this, kFONT_STYLE);
133 fTypeCombo->Resize(137, 20);
134 AddFrame(fTypeCombo,
new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
141 TPieEditor::~TPieEditor()
149 void TPieEditor::ConnectSignals2Slots()
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()");
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()");
170 void TPieEditor::ActivateBaseClassEditors(TClass* cl)
172 TGedEditor *gedEditor = GetGedEditor();
173 gedEditor->ExcludeClassEditor(TAttText::Class());
174 TGedFrame::ActivateBaseClassEditors(cl);
181 void TPieEditor::SetModel(TObject* obj)
184 fAvoidSignal = kTRUE;
187 const char *text = fPie->GetTitle();
188 fTitle->SetText(text);
190 TString soption = GetDrawOption();
201 if ( (idx=soption.Index(
"same"))>=0 ) {
203 soption.Remove(idx,4);
206 if ( (idx=soption.Index(
"nol"))>=0 ) {
207 fOutlineOnOff->SetState(kButtonUp,kFALSE);
208 soption.Remove(idx,3);
211 fOutlineOnOff->SetState(kButtonDown,kFALSE);
215 if ( (idx=soption.Index(
"3d"))>=0 ) {
216 fIs3D->SetState(kButtonDown, kFALSE);
217 f3DAngle->SetNumber(fPie->GetAngle3D());
218 f3DHeight->SetNumber(fPie->GetHeight());
219 soption.Remove(idx,2);
221 fIs3D->SetState(kButtonUp, kFALSE);
225 if ( (idx=soption.Index(
"t"))>=0 ) {
227 soption.Remove(idx,1);
231 if ( (idx=soption.Index(
"r"))>=0 ) {
233 soption.Remove(idx,1);
238 fLblDirH->SetState(kButtonDown,kTRUE);
241 fLblDirR->SetState(kButtonDown,kTRUE);
244 fLblDirT->SetState(kButtonDown,kTRUE);
249 fTypeCombo->Select(fPie->GetTextFont() / 10);
251 Color_t c = fPie->GetTextColor();
252 Pixel_t p = TColor::Number2Pixel(c);
253 fColorSelect->SetColor(p, kFALSE);
255 Float_t s = fPie->GetTextSize();
258 if (obj->InheritsFrom(TPaveLabel::Class())) {
259 TBox *pl = (TBox*)obj;
260 dy = s * (pl->GetY2() - pl->GetY1());
263 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
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);
270 if (fInit) ConnectSignals2Slots();
271 fAvoidSignal = kFALSE;
278 void TPieEditor::DoTitle(
const char *text)
280 if (fAvoidSignal)
return;
281 fPie->SetTitle(text);
289 void TPieEditor::DoShape()
291 if (fAvoidSignal)
return;
293 TString opt = GetDrawOption();
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);
299 else if (fLblDirR->GetState()==kButtonDown) {
300 if (opt.Contains(
"t")) opt.Remove(opt.First(
"t"),1);
301 if (!opt.Contains(
"r")) opt +=
"r";
303 else if (fLblDirT->GetState()==kButtonDown) {
304 if (!opt.Contains(
"t")) opt +=
"t";
305 if (opt.Contains(
"r")) opt.Remove(opt.First(
"r"),1);
309 if (gPad && gPad->GetVirtCanvas()) gPad->GetVirtCanvas()->SetCursor(kPointer);
310 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
317 void TPieEditor::DoMarkerOnOff(Bool_t)
319 if (fAvoidSignal)
return;
320 TString t = GetDrawOption();
322 if (t.Contains(
"nol") && fOutlineOnOff->GetState() == kButtonDown) {
323 t.Remove(t.First(
"nol"),3);
325 else if (!t.Contains(
"nol") && fOutlineOnOff->GetState() == kButtonUp) {
336 void TPieEditor::DoChange3DAngle()
338 if (fAvoidSignal)
return;
340 fPie->SetAngle3D(static_cast<Int_t>(f3DAngle->GetNumber()));
341 fPie->SetHeight(f3DHeight->GetNumber());
351 void TPieEditor::DoGraphLineWidth()
353 if (fAvoidSignal)
return;
355 TString opt = GetDrawOption();
356 if (!opt.Contains(
"3d") && fIs3D->IsDown())
358 else if (opt.Contains(
"3d") && !fIs3D->IsDown())
359 opt.Remove(opt.First(
"3d"),2);
371 void TPieEditor::DoTextChange()
373 if (fAvoidSignal)
return;
376 fPie->SetTextColor(TColor::GetColor(fColorSelect->GetColor()));
379 Int_t fontPrec = fPie->GetTextFont()%10;
380 Int_t fontType = fTypeCombo->GetSelected();
381 fPie->SetTextFont(fontType*10+fontPrec);
384 TVirtualPad* pad = fGedEditor->GetPad();
386 Float_t val = TString(fSizeCombo->GetSelectedEntry()->GetTitle()).Atoi();
388 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY((Int_t)val);
391 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
392 TBox *pl = (TBox*)fGedEditor->GetModel();
393 textSize = dy/(pl->GetY2() - pl->GetY1());
396 textSize = dy/(pad->GetY2() - pad->GetY1());
398 fPie->SetTextSize(textSize);
408 TGComboBox* TPieEditor::BuildFontSizeComboBox(TGFrame* parent, Int_t
id)
411 TGComboBox *c =
new TGComboBox(parent,
id);
413 c->AddEntry(
"Default", 0);
414 for (
int i = 1; i <= 50; i++) {
415 snprintf(a, 99,
"%d", i);