TQtPen.cxx

Go to the documentation of this file.
00001 // Author: Valeri Fine   21/01/2002
00002 /****************************************************************************
00003 ** $Id: TQtPen.cxx 30386 2009-09-23 19:06:28Z brun $
00004 **
00005 ** Copyright (C) 2002 by Valeri Fine. Brookhaven National Laboratory.
00006 **                                    All rights reserved.
00007 **
00008 ** This file may be distributed under the terms of the Q Public License
00009 ** as defined by Trolltech AS of Norway and appearing in the file
00010 ** LICENSE.QPL included in the packaging of this file.
00011 **
00012 *****************************************************************************/
00013 
00014 
00015 /////////////////////////////////////////////////////////////////////////////////
00016 //
00017 // TQtPen class is Qt QPen with ROOT TAttLine interface 
00018 //
00019 /////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include "TQtPen.h"
00022 #include "TGQt.h"
00023 #include "TSystem.h"
00024 #include "TMath.h"
00025 #include "TStyle.h"
00026 #include "TObjString.h"
00027 #include "TObjArray.h"
00028 #include "TAttLine.h"
00029 
00030 #include <QtGui/QFontMetrics>
00031 #include <QDebug>
00032 
00033 //______________________________________________________________________________
00034 TQtPen::TQtPen(): QPen(),TAttLine()
00035 {
00036         // TQtPen default ctor
00037 }
00038 //______________________________________________________________________________
00039 TQtPen::TQtPen(const TAttLine &line) : QPen() 
00040 {
00041         // Copy ctor to copy ROOT TAttLine object
00042    SetLineAttributes(line);
00043 }
00044 
00045 //______________________________________________________________________________
00046 TQtPen &TQtPen::operator=(const TAttLine &line)
00047 {
00048         // Assigns the  Qt pen attributes from ROOT TAttLine object
00049    SetLineAttributes(line);
00050         return *this;
00051 }
00052 
00053 //______________________________________________________________________________
00054 void  TQtPen::SetLineAttributes(const TAttLine &lineAttributes)
00055 {
00056         // Maps the ROOT TAttLine attributes to QPen attributes
00057         SetLineColor(lineAttributes.GetLineColor());
00058         SetLineStyle(lineAttributes.GetLineStyle());
00059         SetLineWidth(lineAttributes.GetLineWidth());
00060 }
00061 
00062 //______________________________________________________________________________
00063 void  TQtPen::SetLineColor(Color_t cindex)
00064 {
00065 //*-*-*-*-*-*-*-*-*-*-*Set color index for lines*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00066 //*-*                  =========================
00067 //*-*  cindex    : color index
00068 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00069 
00070   if (fLineColor != cindex) {
00071     fLineColor = cindex;
00072     if (fLineColor >= 0)  setColor(gQt->ColorIndex(gQt->UpdateColor(fLineColor)));
00073   }
00074 }
00075 //______________________________________________________________________________
00076 void  TQtPen::SetLineType(int n, int*dash)
00077 {
00078 //*-*-*-*-*-*-*-*-*-*-*Set line style-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00079 //*-*                  ==============
00080 //*-*    Set line style:
00081 //*-*    if n < 0 use pre-defined Windows style:
00082 //*-*         0 - solid lines
00083 //*-*        -1 - solid lines
00084 //*-*        -2 - dash line
00085 //*-*        -3 - dot  line
00086 //*-*        -4 - dash-dot line
00087 //*-*        -5 - dash-dot-dot line
00088 //*-*     < -6 - solid line
00089 //*-*
00090 //*-*    if n > 0 use dashed lines described by DASH(N)
00091 //*-*    e.g. n=4,DASH=(6,3,1,3) gives a dashed-dotted line with dash length 6
00092 //*-*    and a gap of 7 between dashes
00093 //*-*
00094 /*
00095    SetLineStyleString(1," ");
00096    SetLineStyleString(2,"12 12");
00097    SetLineStyleString(3,"4 8");
00098    SetLineStyleString(4,"12 16 4 16");
00099    SetLineStyleString(5,"20 12 4 12");
00100    SetLineStyleString(6,"20 12 4 12 4 12 4 12");
00101    SetLineStyleString(7,"20 20");
00102    SetLineStyleString(8,"20 12 4 12 4 12");
00103    SetLineStyleString(9,"80 20");
00104    SetLineStyleString(10,"80 40 4 40");
00105 */
00106   static  Qt::PenStyle styles[] = {
00107       Qt::NoPen          // - no line at all.
00108      ,Qt::SolidLine      // - a simple line.
00109      ,Qt::DashLine       // - dashes separated by a few pixels.
00110      ,Qt::DotLine        // - dots separated by a few pixels.
00111      ,Qt::DashDotLine    // - alternate dots and dashes.
00112      ,Qt::DashDotDotLine // - one dash, two dots, one dash, two dotsQt::NoPen
00113     };
00114 
00115   if (n == 0 ) n = -1; // solid lines
00116   if (n < 0) {
00117     int l = -n;
00118     if (l >= int(sizeof(styles)/sizeof(Qt::PenStyle)) ) l = 1; // Solid line "by default"
00119     setStyle(styles[l]);
00120   }
00121   else if (dash) {
00122      // - A custom pattern defined using QPainterPathStroker::setDashPattern().
00123      QVector<qreal> dashes;
00124      int i;
00125      for (i=0;i<n;i++) dashes << dash[i];
00126      setDashPattern(dashes);
00127   }
00128 }
00129 //______________________________________________________________________________
00130 void  TQtPen::SetLineStyle(Style_t linestyle)
00131 {
00132 //*-*-*-*-*-*-*-*-*-*-*Set line style-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00133 //*-*                  ==============
00134 //*-*    Use pre-defined Windows style:
00135 //*-*    linestyle =
00136 //*-*         0 - solid lines
00137 //*-*        -1 - solid lines
00138 //*-*        -2 - dash line
00139 //*-*        -3 - dot  line
00140 //*-*        -4 - dash-dot line
00141 //*-*        -5 - dash-dot-dot line
00142 //*-*      < -6 - solid line
00143 //*-*
00144 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00145    // Copy/Paste from TGX11::SetLineStyle (it is called "subclassing" ;-)
00146    // Set line style.
00147 
00148    if (fLineStyle != linestyle) { //set style index only if different
00149       fLineStyle = linestyle;
00150       if (linestyle > 0 && linestyle <= 5 ) {
00151          SetLineType(-linestyle,NULL);
00152       } else {
00153          TString st = (TString)gStyle->GetLineStyleString(linestyle);
00154          TObjArray *tokens = st.Tokenize(" ");
00155          Int_t nt;
00156          nt = tokens->GetEntries();
00157          Int_t *lstyle = new Int_t[nt];
00158          for (Int_t j = 0; j<nt; j++) {
00159             Int_t it;
00160             sscanf(((TObjString*)tokens->At(j))->GetName(), "%d", &it);
00161             lstyle[j] = (Int_t)(it/4);
00162          }
00163          SetLineType(nt,lstyle);
00164          delete [] lstyle;
00165          delete tokens;
00166       }
00167    }
00168 }
00169 
00170 //______________________________________________________________________________
00171 void  TQtPen::SetLineWidth(Width_t w)
00172 {
00173    //*-*-*-*-*-*-*-*-*-*-*Set line width*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00174    //*-*                  ==============
00175    //*-*  w   : line width in pixels
00176    //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00177    if (w==1) w =0;
00178    if (fLineWidth != w) {
00179       fLineWidth = w;
00180       if (fLineWidth >= 0 )  setWidth(fLineWidth);
00181    }
00182 }

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