ROOT logo
// @(#)root/qt:$Id$
// Author: Valeri Fine   21/01/2002

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * Copyright (C) 2002 by Valeri Fine.                                    *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TQtRConfig.h"
#include "TQtMarker.h"
#include "TAttMarker.h"
#include "TGQt.h"
#include <QtGui/QPolygon>
#include <QtGui/QPainter>
#include <QtCore/QDebug>


ClassImp(TQtMarker)

////////////////////////////////////////////////////////////////////////
//
// TQtMarker - class-utility to convert the ROOT TMarker object shape
//             into the Qt QPointArray.
//
////////////////////////////////////////////////////////////////////////

//______________________________________________________________________________
TQtMarker::TQtMarker(int n, TPoint *xy, int type) : fNumNode(n),
fChain(0), fCindex(0), fMarkerType(0),fLineWidth(0),fLineOption(false)
{
   SetPenAttributes(type);
   if (GetType() != kDot) {
      fChain.resize(n);
      TPoint *rootPoint = xy;
      for (int i=0;i<n;i++,rootPoint++)
         fChain.setPoint(i,rootPoint->fX,rootPoint->fY);
   }
}
//______________________________________________________________________________
TQtMarker::~TQtMarker(){}

//______________________________________________________________________________
TQtMarker &TQtMarker::operator=(const TAttMarker&markerAttributes)
{
   // Assign the TQtMarker from ROOT TAttMarker
   SetMarkerAttributes(markerAttributes);
   return *this;
}

//______________________________________________________________________________
TQtMarker::TQtMarker(const TAttMarker &markerAttributes)
{
   // Create the TQtMarker from ROOT TAttMarker
   SetMarkerAttributes(markerAttributes);
}

//______________________________________________________________________________
void TQtMarker::SetMarkerAttributes(const TAttMarker& markerAttributes)
{
   // Map Qt marker  attributes to ROOT TAttMaker parameters
   fCindex     = markerAttributes.GetMarkerColor();
   SetPenAttributes(markerAttributes.GetMarkerStyle());
   fNumNode    = Int_t(markerAttributes.GetMarkerSize());
}

//______________________________________________________________________________
void  TQtMarker::SetPenAttributes(int type)
{
   // Pen attrbutes is 100000*LineFlag + 1000*width + "marker style"
   static const int packFactor = 1000;
   static const int lineFactor = 10000;
   fMarkerType = type%packFactor;
   fLineWidth = (type - fMarkerType)/packFactor;
   if (type >= lineFactor) {
      // Set line style
      fLineWidth -= lineFactor/packFactor;
      fLineOption = true;
   }
}
//______________________________________________________________________________
int   TQtMarker::GetNumber() const {return fNumNode;}
//______________________________________________________________________________
const QPolygon &TQtMarker::GetNodes() const {return fChain;}
//______________________________________________________________________________
int  TQtMarker::GetType()  const {return fMarkerType;}

//______________________________________________________________________________
int  TQtMarker::GetWidth() const { return fLineWidth;}

//______________________________________________________________________________
void TQtMarker::SetMarker(int n, TPoint *xy, int type)
{
   //*-* Did we have a chain ?
   fNumNode = n;
   SetPenAttributes(type);
   if (GetType() != kDot) {
      fChain.resize(n);
      TPoint *rootPoint = xy;
      for (int i=0;i<n;i++,rootPoint++)
         fChain.setPoint(i,rootPoint->fX,rootPoint->fY);
   }
}

//______________________________________________________________________________
void  TQtMarker::DrawPolyMarker(QPainter &p, int n, TPoint *xy)
{
   // Draw n markers with the current attributes at positions xy.
   // p    : the external QPainter
   // n    : number of markers to draw
   // xy   : x,y coordinates of markers

   /* Set marker Color */
   const QColor &mColor  = gQt->ColorIndex(fCindex);

   p.save();
   if (this->GetWidth()>0) p.setPen(QPen(mColor,this->GetWidth()));
   else                    p.setPen(mColor);

   if( this->GetNumber() <= 0  || fLineOption )
   {
      QPolygon qtPoints(n);
      TPoint *rootPoint = xy;
      for (int i=0;i<n;i++,rootPoint++)
         qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
      if (fLineOption) p.drawPolyline(qtPoints);
      else             p.drawPoints(qtPoints);
   }
   if ( this->GetNumber() >0 ) {
      int r = this->GetNumber()/2;
      switch (this -> GetType())
      {
         case 1:
         case 3:
         default:
            p.setBrush(mColor);
            break;
         case 0:
         case 2:
            p.setBrush(Qt::NoBrush);
            break;
         case 4:
            break;
      }

      for( int m = 0; m < n; m++ )
      {
         int i;
         switch( this->GetType() )
         {
            case 0:        /* hollow circle */
            case 1:        /* filled circle */
               p.drawEllipse(xy[m].fX-r, xy[m].fY-r, 2*r, 2*r);
               break;
            case 2:        /* hollow polygon */
            case 3:        /* filled polygon */
            {
               QPolygon mxy = this->GetNodes();
               mxy.translate(xy[m].fX,xy[m].fY);
               p.drawPolygon(mxy);
               break;
            }
            case 4:        /* segmented line */
            {
               QPolygon mxy = this->GetNodes();
               mxy.translate(xy[m].fX,xy[m].fY);
               QVector<QLine> lines(this->GetNumber());
               for( i = 0; i < this->GetNumber(); i+=2 )
                  lines.push_back(QLine(mxy.point(i),mxy.point(i+1)));
               p.drawLines(lines);
               break;
            }
         }
      }
   }
   p.restore();
}
 TQtMarker.cxx:1
 TQtMarker.cxx:2
 TQtMarker.cxx:3
 TQtMarker.cxx:4
 TQtMarker.cxx:5
 TQtMarker.cxx:6
 TQtMarker.cxx:7
 TQtMarker.cxx:8
 TQtMarker.cxx:9
 TQtMarker.cxx:10
 TQtMarker.cxx:11
 TQtMarker.cxx:12
 TQtMarker.cxx:13
 TQtMarker.cxx:14
 TQtMarker.cxx:15
 TQtMarker.cxx:16
 TQtMarker.cxx:17
 TQtMarker.cxx:18
 TQtMarker.cxx:19
 TQtMarker.cxx:20
 TQtMarker.cxx:21
 TQtMarker.cxx:22
 TQtMarker.cxx:23
 TQtMarker.cxx:24
 TQtMarker.cxx:25
 TQtMarker.cxx:26
 TQtMarker.cxx:27
 TQtMarker.cxx:28
 TQtMarker.cxx:29
 TQtMarker.cxx:30
 TQtMarker.cxx:31
 TQtMarker.cxx:32
 TQtMarker.cxx:33
 TQtMarker.cxx:34
 TQtMarker.cxx:35
 TQtMarker.cxx:36
 TQtMarker.cxx:37
 TQtMarker.cxx:38
 TQtMarker.cxx:39
 TQtMarker.cxx:40
 TQtMarker.cxx:41
 TQtMarker.cxx:42
 TQtMarker.cxx:43
 TQtMarker.cxx:44
 TQtMarker.cxx:45
 TQtMarker.cxx:46
 TQtMarker.cxx:47
 TQtMarker.cxx:48
 TQtMarker.cxx:49
 TQtMarker.cxx:50
 TQtMarker.cxx:51
 TQtMarker.cxx:52
 TQtMarker.cxx:53
 TQtMarker.cxx:54
 TQtMarker.cxx:55
 TQtMarker.cxx:56
 TQtMarker.cxx:57
 TQtMarker.cxx:58
 TQtMarker.cxx:59
 TQtMarker.cxx:60
 TQtMarker.cxx:61
 TQtMarker.cxx:62
 TQtMarker.cxx:63
 TQtMarker.cxx:64
 TQtMarker.cxx:65
 TQtMarker.cxx:66
 TQtMarker.cxx:67
 TQtMarker.cxx:68
 TQtMarker.cxx:69
 TQtMarker.cxx:70
 TQtMarker.cxx:71
 TQtMarker.cxx:72
 TQtMarker.cxx:73
 TQtMarker.cxx:74
 TQtMarker.cxx:75
 TQtMarker.cxx:76
 TQtMarker.cxx:77
 TQtMarker.cxx:78
 TQtMarker.cxx:79
 TQtMarker.cxx:80
 TQtMarker.cxx:81
 TQtMarker.cxx:82
 TQtMarker.cxx:83
 TQtMarker.cxx:84
 TQtMarker.cxx:85
 TQtMarker.cxx:86
 TQtMarker.cxx:87
 TQtMarker.cxx:88
 TQtMarker.cxx:89
 TQtMarker.cxx:90
 TQtMarker.cxx:91
 TQtMarker.cxx:92
 TQtMarker.cxx:93
 TQtMarker.cxx:94
 TQtMarker.cxx:95
 TQtMarker.cxx:96
 TQtMarker.cxx:97
 TQtMarker.cxx:98
 TQtMarker.cxx:99
 TQtMarker.cxx:100
 TQtMarker.cxx:101
 TQtMarker.cxx:102
 TQtMarker.cxx:103
 TQtMarker.cxx:104
 TQtMarker.cxx:105
 TQtMarker.cxx:106
 TQtMarker.cxx:107
 TQtMarker.cxx:108
 TQtMarker.cxx:109
 TQtMarker.cxx:110
 TQtMarker.cxx:111
 TQtMarker.cxx:112
 TQtMarker.cxx:113
 TQtMarker.cxx:114
 TQtMarker.cxx:115
 TQtMarker.cxx:116
 TQtMarker.cxx:117
 TQtMarker.cxx:118
 TQtMarker.cxx:119
 TQtMarker.cxx:120
 TQtMarker.cxx:121
 TQtMarker.cxx:122
 TQtMarker.cxx:123
 TQtMarker.cxx:124
 TQtMarker.cxx:125
 TQtMarker.cxx:126
 TQtMarker.cxx:127
 TQtMarker.cxx:128
 TQtMarker.cxx:129
 TQtMarker.cxx:130
 TQtMarker.cxx:131
 TQtMarker.cxx:132
 TQtMarker.cxx:133
 TQtMarker.cxx:134
 TQtMarker.cxx:135
 TQtMarker.cxx:136
 TQtMarker.cxx:137
 TQtMarker.cxx:138
 TQtMarker.cxx:139
 TQtMarker.cxx:140
 TQtMarker.cxx:141
 TQtMarker.cxx:142
 TQtMarker.cxx:143
 TQtMarker.cxx:144
 TQtMarker.cxx:145
 TQtMarker.cxx:146
 TQtMarker.cxx:147
 TQtMarker.cxx:148
 TQtMarker.cxx:149
 TQtMarker.cxx:150
 TQtMarker.cxx:151
 TQtMarker.cxx:152
 TQtMarker.cxx:153
 TQtMarker.cxx:154
 TQtMarker.cxx:155
 TQtMarker.cxx:156
 TQtMarker.cxx:157
 TQtMarker.cxx:158
 TQtMarker.cxx:159
 TQtMarker.cxx:160
 TQtMarker.cxx:161
 TQtMarker.cxx:162
 TQtMarker.cxx:163
 TQtMarker.cxx:164
 TQtMarker.cxx:165
 TQtMarker.cxx:166
 TQtMarker.cxx:167
 TQtMarker.cxx:168
 TQtMarker.cxx:169
 TQtMarker.cxx:170
 TQtMarker.cxx:171
 TQtMarker.cxx:172
 TQtMarker.cxx:173
 TQtMarker.cxx:174
 TQtMarker.cxx:175
 TQtMarker.cxx:176
 TQtMarker.cxx:177
 TQtMarker.cxx:178
 TQtMarker.cxx:179
 TQtMarker.cxx:180