#include "TQtRConfig.h"
#include "TQtMarker.h"
#include "TAttMarker.h"
#include "TGQt.h"
#include <QtGui/QPolygon>
#include <QtGui/QPainter>
#include <QtCore/QDebug>
ClassImp(TQtMarker)
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)
{
SetMarkerAttributes(markerAttributes);
return *this;
}
TQtMarker::TQtMarker(const TAttMarker &markerAttributes)
{
SetMarkerAttributes(markerAttributes);
}
void TQtMarker::SetMarkerAttributes(const TAttMarker& markerAttributes)
{
fCindex = markerAttributes.GetMarkerColor();
SetPenAttributes(markerAttributes.GetMarkerStyle());
fNumNode = Int_t(markerAttributes.GetMarkerSize());
}
void TQtMarker::SetPenAttributes(int type)
{
static const int packFactor = 1000;
static const int lineFactor = 10000;
fMarkerType = type%packFactor;
fLineWidth = (type - fMarkerType)/packFactor;
if (type >= lineFactor) {
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)
{
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)
{
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:
case 1:
p.drawEllipse(xy[m].fX-r, xy[m].fY-r, 2*r, 2*r);
break;
case 2:
case 3:
{
QPolygon mxy = this->GetNodes();
mxy.translate(xy[m].fX,xy[m].fY);
p.drawPolygon(mxy);
break;
}
case 4:
{
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();
}