TQtMarker.cxx

Go to the documentation of this file.
00001 // @(#)root/qt:$Id: TQtMarker.cxx 36079 2010-10-05 09:49:55Z brun $
00002 // Author: Valeri Fine   21/01/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * Copyright (C) 2002 by Valeri Fine.                                    *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 #include "TQtRConfig.h"
00014 #include "TQtMarker.h"
00015 #include "TAttMarker.h"
00016 #include "TGQt.h"
00017 #include <QtGui/QPolygon>
00018 #include <QtGui/QPainter>
00019 #include <QtCore/QDebug>
00020 
00021 
00022 ClassImp(TQtMarker)
00023 
00024 ////////////////////////////////////////////////////////////////////////
00025 //
00026 // TQtMarker - class-utility to convert the ROOT TMarker object shape 
00027 //             into the Qt QPointArray.
00028 //
00029 ////////////////////////////////////////////////////////////////////////
00030 
00031 //______________________________________________________________________________
00032 TQtMarker::TQtMarker(int n, TPoint *xy, int type) : fNumNode(n),
00033                fChain(0), fCindex(0), fMarkerType(0),fLineWidth(0),fLineOption(false)
00034 {
00035   SetPenAttributes(type);
00036   if (GetType() != kDot) {
00037      fChain.resize(n);
00038      TPoint *rootPoint = xy;
00039      for (int i=0;i<n;i++,rootPoint++)
00040         fChain.setPoint(i,rootPoint->fX,rootPoint->fY);
00041   }
00042 }
00043 //______________________________________________________________________________
00044 TQtMarker::~TQtMarker(){}
00045 //______________________________________________________________________________
00046 TQtMarker &TQtMarker::operator=(const TAttMarker&markerAttributes)
00047 {
00048    // Assign the TQtMarker from ROOT TAttMarker 
00049         SetMarkerAttributes(markerAttributes);
00050         return *this;
00051 }
00052 
00053 //______________________________________________________________________________
00054 TQtMarker::TQtMarker(const TAttMarker &markerAttributes)
00055 {
00056    // Create the TQtMarker from ROOT TAttMarker 
00057         SetMarkerAttributes(markerAttributes);
00058 }
00059 
00060 //______________________________________________________________________________
00061 void TQtMarker::SetMarkerAttributes(const TAttMarker& markerAttributes)
00062 {
00063    // Map Qt marker  attributes to ROOT TAttMaker parameters
00064    fCindex     = markerAttributes.GetMarkerColor();
00065    SetPenAttributes(markerAttributes.GetMarkerStyle());
00066    fNumNode    = Int_t(markerAttributes.GetMarkerSize());
00067 }
00068 
00069 //______________________________________________________________________________
00070 void  TQtMarker::SetPenAttributes(int type)
00071 {
00072    // Pen attrbutes is 100000*LineFlag + 1000*width + "marker style"
00073    static const int packFactor = 1000;
00074    static const int lineFactor = 10000;
00075    fMarkerType = type%packFactor;
00076    fLineWidth = (type - fMarkerType)/packFactor;
00077    if (type >= lineFactor) {
00078       // Set line style 
00079       fLineWidth -= lineFactor/packFactor;
00080       fLineOption = true;
00081    }
00082 }
00083 //______________________________________________________________________________
00084 int   TQtMarker::GetNumber() const {return fNumNode;}
00085 //______________________________________________________________________________
00086 const QPolygon &TQtMarker::GetNodes() const {return fChain;}
00087 //______________________________________________________________________________
00088 int  TQtMarker::GetType()  const {return fMarkerType;}
00089 
00090 //______________________________________________________________________________
00091 int  TQtMarker::GetWidth() const { return fLineWidth;}
00092 
00093 //______________________________________________________________________________
00094 void TQtMarker::SetMarker(int n, TPoint *xy, int type)
00095 {
00096 //*-* Did we have a chain ?
00097   fNumNode = n;
00098   SetPenAttributes(type);
00099   if (GetType() != kDot) {
00100     fChain.resize(n);
00101     TPoint *rootPoint = xy;
00102     for (int i=0;i<n;i++,rootPoint++)
00103        fChain.setPoint(i,rootPoint->fX,rootPoint->fY);
00104   }
00105 }
00106 
00107 //______________________________________________________________________________
00108 void  TQtMarker::DrawPolyMarker(QPainter &p, int n, TPoint *xy)
00109 {
00110         // Draw n markers with the current attributes at positions xy.
00111         // p    : the external QPainter 
00112    // n    : number of markers to draw
00113         // xy   : x,y coordinates of markers
00114         
00115         /* Set marker Color */
00116         const QColor &mColor  = gQt->ColorIndex(fCindex);
00117 
00118    p.save();
00119    if (this->GetWidth()>0) p.setPen(QPen(mColor,this->GetWidth()));
00120    else                    p.setPen(mColor);
00121 
00122    if( this->GetNumber() <= 0  || fLineOption )
00123    {
00124       QPolygon qtPoints(n);
00125       TPoint *rootPoint = xy;
00126       for (int i=0;i<n;i++,rootPoint++)
00127         qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
00128       if (fLineOption) p.drawPolyline(qtPoints);
00129       else             p.drawPoints(qtPoints);
00130    }
00131    if ( this->GetNumber() >0 ) {
00132       int r = this->GetNumber()/2;
00133       switch (this -> GetType())
00134       {
00135       case 1:
00136       case 3:
00137       default:
00138          p.setBrush(mColor);
00139          break;
00140                 case 0:
00141                 case 2:
00142                         p.setBrush(Qt::NoBrush);
00143                         break;
00144                 case 4:
00145                         break;
00146                 }
00147 
00148                 for( int m = 0; m < n; m++ )
00149                 {
00150                         int i;
00151                         switch( this->GetType() )
00152                         {
00153                         case 0:        /* hollow circle */
00154                         case 1:        /* filled circle */
00155                                 p.drawEllipse(xy[m].fX-r, xy[m].fY-r, 2*r, 2*r);
00156                                 break;
00157                         case 2:        /* hollow polygon */
00158                         case 3:        /* filled polygon */
00159                                 {
00160                                         QPolygon mxy = this->GetNodes();
00161                                         mxy.translate(xy[m].fX,xy[m].fY);
00162                                         p.drawPolygon(mxy);
00163                                         break;
00164                                 }
00165                         case 4:        /* segmented line */
00166                                 {
00167                                         QPolygon mxy = this->GetNodes();
00168                                         mxy.translate(xy[m].fX,xy[m].fY);
00169                                         QVector<QLine> lines(this->GetNumber());
00170                                         for( i = 0; i < this->GetNumber(); i+=2 )
00171                                                 lines.push_back(QLine(mxy.point(i),mxy.point(i+1)));
00172                                         p.drawLines(lines);
00173                                         break;
00174                                 }
00175                         }
00176                 }
00177         }
00178         p.restore();
00179 }

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