TAttLineEditor.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TAttLineEditor.cxx 31790 2009-12-10 14:14:17Z bellenot $
00002 // Author: Ilka Antcheva   10/05/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 //  TAttLineEditor                                                      //
00015 //                                                                      //
00016 //  Implements GUI for editing line attributes.                         //                                             //
00017 //           color, line width, line style                              //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 //Begin_Html
00021 /*
00022 <img src="gif/TAttLineEditor.gif">
00023 */
00024 //End_Html
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    // Constructor of line attributes GUI.
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    // Destructor of line editor.
00076 }
00077 
00078 //______________________________________________________________________________
00079 void TAttLineEditor::ConnectSignals2Slots()
00080 {
00081    // Connect signals to slots.
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    // Pick up the used line attributes.
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    // Slot connected to the line color.
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    // Slot connected to the line style.
00133 
00134    if (fAvoidSignal) return;
00135    fAttLine->SetLineStyle(style);
00136    Update();
00137 }
00138 
00139 
00140 //______________________________________________________________________________
00141 void TAttLineEditor::DoLineWidth(Int_t width)
00142 {
00143    // Slot connected to the line width.
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 }

Generated on Tue Jul 5 14:19:45 2011 for ROOT_528-00b_version by  doxygen 1.5.1