ROOT  6.06/09
Reference Guide
TLineEditor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 24/04/06
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 // TLineEditor //
15 // //
16 // Implements GUI for editing line attributes: shape, size, angle. // //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 //Begin_Html
20 /*
21 <img src="gif/TLineEditor.gif">
22 */
23 //End_Html
24 
25 
26 #include "TLineEditor.h"
27 #include "TGLabel.h"
28 #include "TGNumberEntry.h"
29 #include "TLine.h"
30 #include "TVirtualPad.h"
31 
33 
34 enum ELineWid {
35  kLine_STAX,
36  kLine_STAY,
37  kLine_ENDX,
38  kLine_ENDY,
39  kLine_VERTICAL,
40  kLine_HORIZONTAL
41 };
42 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor of line GUI.
46 
48  Int_t height, UInt_t options, Pixel_t back)
49  : TGedFrame(p, width, height, options | kVerticalFrame, back)
50 {
51  fLine = 0;
52 
53  MakeTitle("Points");
54 
55  TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
56  AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 3, 0));
57 
58  TGCompositeFrame *f3a = new TGCompositeFrame(f3, 80, 20);
59  f3->AddFrame(f3a, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
60 
61  TGLabel *fStartPointXLabel = new TGLabel(f3a, "Start X:");
62  f3a->AddFrame(fStartPointXLabel, new TGLayoutHints(kLHintsNormal, 8, 0, 5, 5));
63 
64  TGLabel *fStartPointYLabel = new TGLabel(f3a, "Y:");
65  f3a->AddFrame(fStartPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));
66 
67  TGLabel *fEndPointXLabel = new TGLabel(f3a, "End X:");
68  f3a->AddFrame(fEndPointXLabel, new TGLayoutHints(kLHintsNormal, 10, 0, 5, 5));
69 
70  TGLabel *fEndPointYLabel = new TGLabel(f3a, "Y:");
71  f3a->AddFrame(fEndPointYLabel, new TGLayoutHints(kLHintsNormal, 37, 0, 5, 5));
72 
73  TGCompositeFrame *f3b = new TGCompositeFrame(f3, 80, 20, kFixedWidth);
74  f3->AddFrame(f3b, new TGLayoutHints(kLHintsNormal, 8, 0, 0, 0));
75 
76  fStartPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_STAX,
80  fStartPointX->GetNumberEntry()->SetToolTipText("Set start point X coordinate of Line.");
81  f3b->AddFrame(fStartPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
82 
83  fStartPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_STAY,
87  fStartPointY->GetNumberEntry()->SetToolTipText("Set start point Y coordinate of Line.");
88  f3b->AddFrame(fStartPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
89 
90  fEndPointX = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDX,
94  fEndPointX->GetNumberEntry()->SetToolTipText("Set end point X xoordinate of Line.");
95  f3b->AddFrame(fEndPointX, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
96 
97  fEndPointY = new TGNumberEntry(f3b, 0.0, 8, kLine_ENDY,
101  fEndPointY->GetNumberEntry()->SetToolTipText("Set end point Y coordinate of Line.");
102  f3b->AddFrame(fEndPointY, new TGLayoutHints(kLHintsExpandX, 1, 1, 3, 1));
103 
104  fVertical = new TGCheckButton(this,"Vertical",kLine_VERTICAL);
105  fVertical->SetToolTipText("Set vertical");
106  AddFrame(fVertical, new TGLayoutHints(kLHintsTop, 8, 1, 5, 0));
107 
108  fHorizontal = new TGCheckButton(this,"Horizontal",kLine_HORIZONTAL);
109  fHorizontal->SetToolTipText("Set horizontal");
110  AddFrame(fHorizontal, new TGLayoutHints(kLHintsTop, 8, 1, 3, 0));
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Destructor of line editor.
115 
117 {
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Connect signals to slots.
122 
124 {
125  fStartPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
126  (fStartPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
127  fStartPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoStartPoint()");
128  (fStartPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoStartPoint()");
129  fEndPointX->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
130  (fEndPointX->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
131  fEndPointY->Connect("ValueSet(Long_t)", "TLineEditor", this, "DoEndPoint()");
132  (fEndPointY->GetNumberEntry())->Connect("ReturnPressed()", "TLineEditor", this, "DoEndPoint()");
133  fVertical->Connect("Clicked()","TLineEditor",this,"DoLineVertical()");
134  fHorizontal->Connect("Clicked()","TLineEditor",this,"DoLineHorizontal()");
135 
136  fInit = kFALSE;
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Pick up the used line attributes.
141 
143 {
144  fLine = (TLine *)obj;
146 
147  Float_t val = fLine->GetX1();
148  fStartPointX->SetNumber(val);
149 
150  val = fLine->GetX2();
151  fEndPointX->SetNumber(val);
152 
153  val = fLine->GetY1();
154  fStartPointY->SetNumber(val);
155 
156  val = fLine->GetY2();
157  fEndPointY->SetNumber(val);
158 
161 
164 
166 
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Slot connected to the line start point.
172 
174 {
175  if (fAvoidSignal) return;
179  Update();
180 }
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Slot connected to the line EndPoint.
183 
185 {
186  if (fAvoidSignal) return;
190  Update();
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Slot so set the line vertical
195 
197 {
198  if (fAvoidSignal) return;
199  if (fVertical->GetState() == kButtonDown) {
200  fLine->SetVertical();
202  } else {
204  }
205  Update();
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Slot so set the line horizontal
210 
212 {
213  if (fAvoidSignal) return;
214  if (fHorizontal->GetState() == kButtonDown) {
215  fLine->SetHorizontal();
217  } else {
219  }
220  Update();
221 }
virtual void SetY2(Double_t y2)
Definition: TLine.h:85
virtual void ConnectSignals2Slots()
Connect signals to slots.
ClassImp(TLineEditor) enum ELineWid
Definition: TLineEditor.cxx:32
virtual void DoLineVertical()
Slot so set the line vertical.
float Float_t
Definition: RtypesCore.h:53
Double_t GetX1() const
Definition: TLine.h:67
virtual ~TLineEditor()
Destructor of line editor.
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetNumber(Double_t val)
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetHorizontal(Bool_t set=kTRUE)
Force the line to be drawn horizontally.
Definition: TLine.cxx:455
Bool_t IsVertical()
Check whether this line is to be drawn vertically.
Definition: TLine.cxx:436
virtual void SetModel(TObject *obj)
Pick up the used line attributes.
Bool_t IsHorizontal()
Check whether this line is to be drawn horizontally.
Definition: TLine.cxx:428
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
TGNumberEntryField * GetNumberEntry() const
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:399
Double_t GetY2() const
Definition: TLine.h:70
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGCompositeFrame(const TGCompositeFrame &)
virtual void Paint(Option_t *option="")
Paint this line with its current attributes.
Definition: TLine.cxx:371
virtual void DoLineHorizontal()
Slot so set the line horizontal.
TGNumberEntry * fEndPointX
Definition: TLineEditor.h:37
TGNumberEntry * fStartPointX
Definition: TLineEditor.h:35
virtual void SetX2(Double_t x2)
Definition: TLine.h:83
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:1135
TGCheckButton * fVertical
Definition: TLineEditor.h:39
TGCheckButton * fHorizontal
Definition: TLineEditor.h:40
virtual void SetY1(Double_t y1)
Definition: TLine.h:84
virtual EButtonState GetState() const
Definition: TGButton.h:116
unsigned int UInt_t
Definition: RtypesCore.h:42
A simple line.
Definition: TLine.h:41
Double_t GetX2() const
Definition: TLine.h:68
TGNumberEntry * fEndPointY
Definition: TLineEditor.h:38
virtual void SetX1(Double_t x1)
Definition: TLine.h:82
double Double_t
Definition: RtypesCore.h:55
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
void SetVertical(Bool_t set=kTRUE)
Force the line to be drawn vertically.
Definition: TLine.cxx:476
TLineEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of line GUI.
Definition: TLineEditor.cxx:47
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void DoEndPoint()
Slot connected to the line EndPoint.
Bool_t fInit
Definition: TGedFrame.h:55
Double_t GetY1() const
Definition: TLine.h:69
virtual Double_t GetNumber() const
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1200
virtual void DoStartPoint()
Slot connected to the line start point.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
TGNumberEntry * fStartPointY
Definition: TLineEditor.h:36
TLine * fLine
Definition: TLineEditor.h:34