/* Copyright (c) 2008-2019 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #include "jkqtplottertools/jkqtpdrawingtools.h" #include "jkqtplottertools/jkqtpenhancedpainter.h" const double JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH= 0.02; void JKQTPPlotSymbol(QPaintDevice& paintDevice, double x, double y, JKQTPGraphSymbols symbol, double size, double symbolLineWidth, QColor color, QColor fillColor) { JKQTPEnhancedPainter p(&paintDevice); JKQTPPlotSymbol(p, x, y, symbol, size, symbolLineWidth, color, fillColor); } void JKQTPPlotSymbol(JKQTPEnhancedPainter& painter, double x, double y, JKQTPGraphSymbols symbol, double symbolSize, double symbolLineWidth, QColor color, QColor fillColor) { painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); QPen p=painter.pen(); p.setColor(color); p.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH, symbolLineWidth)); p.setStyle(Qt::SolidLine); p.setCapStyle(Qt::FlatCap); painter.setPen(p); QBrush b=painter.brush(); b.setColor(fillColor); b.setStyle(Qt::SolidPattern); const double w=symbolSize; const double w2=w/2.0; const double w45=fabs(w*cos(45.0/180.0*M_PI)); const double w3=w/3.0; // calculate star cordinates as static values static int star5_items=0; static double star5cordsx[10]; static double star5cordsy[10]; if (star5_items==0) { star5_items=5; double angle=360.0/double(star5_items)/180.0*M_PI; for (int i=0; i(i)+0.5)*angle; star5cordsx[i*2]=sin(a); star5cordsx[i*2+1]=0.5*sin(a+angle/2.0); star5cordsy[i*2]=cos(a); star5cordsy[i*2+1]=0.5*cos(a+angle/2.0); } } static int star6_items=0; static double star6cordsx[12]; static double star6cordsy[12]; if (star6_items==0) { star6_items=6; double angle=360.0/double(star6_items)/180.0*M_PI; for (int i=0; i(i)+0.5)*angle; star6cordsx[i*2]=sin(a); star6cordsx[i*2+1]=0.5*sin(a+angle/2.0); star6cordsy[i*2]=cos(a); star6cordsy[i*2+1]=0.5*cos(a+angle/2.0); } } static int star8_items=0; static double star8cordsx[16]; static double star8cordsy[16]; if (star8_items==0) { star8_items=8; double angle=360.0/double(star8_items)/180.0*M_PI; for (int i=0; i(i)+0.5)*angle; star8cordsx[i*2]=sin(a); star8cordsx[i*2+1]=0.5*sin(a+angle/2.0); star8cordsy[i*2]=cos(a); star8cordsy[i*2+1]=0.5*cos(a+angle/2.0); } } switch(symbol) { case JKQTPDot: painter.drawPoint(QPointF(x,y)); break; case JKQTPCross:{ QPainterPath path; path.moveTo(x-w2,y-w2); path.lineTo(x+w2,y+w2); path.moveTo(x-w2,y+w2); path.lineTo(x+w2,y-w2); painter.drawPath(path); } break; case JKQTPPlus:{ QVector lines; lines< lines; lines< lines; lines< lines; lines< lines; lines< lines; lines< lines; lines< lines; lines< lines; lines< lines; lines< JKQTPDrawEllipse(double x, double y, double a, double b, double angle_start, double angle_end, double alpha, int controlPoints, QPointF* x_start, QPointF* x_end) { QVector result; double start=angle_start*M_PI/180.0; double stop=angle_end*M_PI/180.0; double step=(stop-start)/static_cast(controlPoints); while (fabs(stop-start)/step<10) step=step/2.0; double sina=sin(1.0*alpha/180.0*M_PI); double cosa=cos(1.0*alpha/180.0*M_PI); QPointF xp(x+a*cos(start)*cosa-b*sin(start)*sina, y+a*cos(start)*sina+b*sin(start)*cosa); result.append(xp); if (x_start) *x_start = xp; double t=start+step; for (int i=1; irect.bottom()) { poly<rect.left()) { poly<