00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "TAttLineEditor.h"
00028 #include "TGColorSelect.h"
00029 #include "TGComboBox.h"
00030 #include "TColor.h"
00031 #include "TGraph.h"
00032
00033 ClassImp(TAttLineEditor)
00034
00035 enum ELineWid {
00036 kCOLOR,
00037 kLINE_WIDTH,
00038 kLINE_STYLE
00039 };
00040
00041
00042
00043 TAttLineEditor::TAttLineEditor(const TGWindow *p, Int_t width,
00044 Int_t height, UInt_t options, Pixel_t back)
00045 : TGedFrame(p, width, height, options | kVerticalFrame, back)
00046 {
00047
00048
00049 fPriority = 1;
00050 fAttLine = 0;
00051
00052 MakeTitle("Line");
00053
00054 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00055 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00056
00057 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
00058 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
00059 fColorSelect->Associate(this);
00060
00061 fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
00062 fStyleCombo->Resize(137, 20);
00063 AddFrame(fStyleCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
00064 fStyleCombo->Associate(this);
00065
00066 fWidthCombo = new TGLineWidthComboBox(f2, kLINE_WIDTH);
00067 fWidthCombo->Resize(91, 20);
00068 f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
00069 fWidthCombo->Associate(this);
00070 }
00071
00072
00073 TAttLineEditor::~TAttLineEditor()
00074 {
00075
00076 }
00077
00078
00079 void TAttLineEditor::ConnectSignals2Slots()
00080 {
00081
00082
00083 fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttLineEditor", this, "DoLineColor(Pixel_t)");
00084 fStyleCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineStyle(Int_t)");
00085 fWidthCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineWidth(Int_t)");
00086
00087 fInit = kFALSE;
00088 }
00089
00090
00091 void TAttLineEditor::SetModel(TObject* obj)
00092 {
00093
00094
00095 TAttLine *attline = dynamic_cast<TAttLine*>(obj);
00096 if (!attline) return;
00097
00098 fAttLine = attline;
00099 fAvoidSignal = kTRUE;
00100
00101 fStyleCombo->Select(fAttLine->GetLineStyle());
00102
00103 if (obj->InheritsFrom(TGraph::Class())) {
00104 fWidthCombo->Select(TMath::Abs(fAttLine->GetLineWidth()%100));
00105 } else {
00106 fWidthCombo->Select(fAttLine->GetLineWidth());
00107 }
00108
00109 Color_t c = fAttLine->GetLineColor();
00110 Pixel_t p = TColor::Number2Pixel(c);
00111 fColorSelect->SetColor(p);
00112
00113 if (fInit) ConnectSignals2Slots();
00114
00115 fAvoidSignal = kFALSE;
00116 }
00117
00118
00119 void TAttLineEditor::DoLineColor(Pixel_t color)
00120 {
00121
00122
00123 if (fAvoidSignal) return;
00124 fAttLine->SetLineColor(TColor::GetColor(color));
00125 Update();
00126 }
00127
00128
00129
00130 void TAttLineEditor::DoLineStyle(Int_t style)
00131 {
00132
00133
00134 if (fAvoidSignal) return;
00135 fAttLine->SetLineStyle(style);
00136 Update();
00137 }
00138
00139
00140
00141 void TAttLineEditor::DoLineWidth(Int_t width)
00142 {
00143
00144
00145 if (fAvoidSignal) return;
00146 if (dynamic_cast<TGraph*>(fAttLine)) {
00147 Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
00148 if (graphLineWidth >= 0) {
00149 fAttLine->SetLineWidth(graphLineWidth+width);
00150 } else {
00151 fAttLine->SetLineWidth(-(TMath::Abs(graphLineWidth)+width));
00152 }
00153 } else {
00154 fAttLine->SetLineWidth(width);
00155 }
00156 Update();
00157 }