00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00027
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
00049 SetMarkerAttributes(markerAttributes);
00050 return *this;
00051 }
00052
00053
00054 TQtMarker::TQtMarker(const TAttMarker &markerAttributes)
00055 {
00056
00057 SetMarkerAttributes(markerAttributes);
00058 }
00059
00060
00061 void TQtMarker::SetMarkerAttributes(const TAttMarker& markerAttributes)
00062 {
00063
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
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
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
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
00111
00112
00113
00114
00115
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:
00154 case 1:
00155 p.drawEllipse(xy[m].fX-r, xy[m].fY-r, 2*r, 2*r);
00156 break;
00157 case 2:
00158 case 3:
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:
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 }