2015-07-11 18:56:02 +08:00
|
|
|
/*
|
2019-01-20 23:15:10 +08:00
|
|
|
Copyright (c) 2008-2019 Jan W. Krieger (<jan@jkrieger.de>)
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2015-07-12 22:34:27 +08:00
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
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
|
2019-02-08 00:24:46 +08:00
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
2015-07-11 18:56:02 +08:00
|
|
|
(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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/overlays/jkqtpbasicoverlays.h"
|
2018-11-26 03:25:44 +08:00
|
|
|
#include "jkqtplotter/jkqtpbaseplotter.h"
|
2019-05-30 04:40:02 +08:00
|
|
|
#include "jkqtplotter/jkqtptools.h"
|
|
|
|
#include "jkqtcommon/jkqtpdrawingtools.h"
|
2015-07-11 18:56:02 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPOverlayVerticalLine::JKQTPOverlayVerticalLine(double pos, JKQTBasePlotter *parent):
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPOverlayOneCoordOverlay(pos, parent), JKQTPGraphTextStyleMixin(parent)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
JKQTPOverlayVerticalLine::JKQTPOverlayVerticalLine(double pos, const QString& text, JKQTBasePlotter *parent):
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPOverlayOneCoordOverlay(pos, parent), JKQTPGraphTextStyleMixin(parent)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
setText(text);
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPOverlayVerticalLine::draw(JKQTPEnhancedPainter &painter) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!parent) return;
|
|
|
|
double ymin=parent->getYMin();
|
|
|
|
double ymax=parent->getYMax();
|
|
|
|
QPointF p1=transform(position, ymin);
|
|
|
|
QPointF p2=transform(position, ymax);
|
|
|
|
QPointF p3=p2-QPointF(0, (p2.y()-p1.y())*0.1);
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.setPen(getLinePen(painter, parent));
|
2015-07-11 18:56:02 +08:00
|
|
|
painter.drawLine(p1, p2);
|
|
|
|
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//JKQTMathText mt(this);
|
2019-01-26 03:16:04 +08:00
|
|
|
JKQTMathText* mt=parent->getMathText();
|
2019-04-22 19:27:50 +08:00
|
|
|
mt->setFontSize(getTextFontSize());
|
|
|
|
mt->setFontColor(getTextColor());
|
|
|
|
mt->setFontRomanOrSpecial(getTextFontName());
|
2015-07-11 18:56:02 +08:00
|
|
|
mt->parse(text);
|
|
|
|
mt->draw(painter, p3.x(), p3.y());
|
|
|
|
}
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPOverlayVerticalLine::setColor(QColor c)
|
|
|
|
{
|
|
|
|
setLineColor(c);
|
|
|
|
setTextColor(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPOverlayVerticalLine::setText(const QString &__value)
|
|
|
|
{
|
|
|
|
this->text = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString JKQTPOverlayVerticalLine::getText() const
|
|
|
|
{
|
|
|
|
return this->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPOverlayVerticalRange::JKQTPOverlayVerticalRange(double pos, double pos2, JKQTBasePlotter *parent):
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPOverlayTwoCoordOverlay(pos, pos2, parent), JKQTPGraphTextStyleMixin(parent)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
inverted=false;
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:28:44 +08:00
|
|
|
JKQTPOverlayVerticalRange::JKQTPOverlayVerticalRange(double pos, double pos2, const QString& text, JKQTBasePlotter *parent):
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPOverlayTwoCoordOverlay(pos, pos2, parent), JKQTPGraphTextStyleMixin(parent)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2019-01-26 20:00:40 +08:00
|
|
|
setText(text);
|
2015-07-11 18:56:02 +08:00
|
|
|
inverted=false;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPOverlayVerticalRange::draw(JKQTPEnhancedPainter &painter) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!parent) return;
|
|
|
|
double ymin=parent->getYMin();
|
|
|
|
double ymax=parent->getYMax();
|
|
|
|
double xmin=parent->getXMin();
|
|
|
|
double xmax=parent->getXMax();
|
|
|
|
QPointF p1=transform(position, ymin);
|
|
|
|
QPointF p2=transform(position, ymax);
|
|
|
|
QPointF p3=p2-QPointF(0, (p2.y()-p1.y())*0.1);
|
|
|
|
|
|
|
|
QPointF p21=transform(position2, ymin);
|
|
|
|
QPointF p22=transform(position2, ymax);
|
2015-08-02 19:36:54 +08:00
|
|
|
//QPointF p23=p2-QPointF(0, (p2.y()-p1.y())*0.1);
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
if (getFillColor()!=QColor(Qt::transparent)) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (inverted) {
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.fillRect(QRectF(transform(xmin, ymin), p2), getFillBrush(painter, parent));
|
|
|
|
painter.fillRect(QRectF(p21, transform(xmax, ymax)), getFillBrush(painter, parent));
|
2015-07-11 18:56:02 +08:00
|
|
|
} else {
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.fillRect(QRectF(p2, p21), getFillBrush(painter, parent));
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.setPen(getLinePen(painter, parent));
|
2015-07-11 18:56:02 +08:00
|
|
|
painter.drawLine(p1, p2);
|
|
|
|
painter.drawLine(p21, p22);
|
|
|
|
|
|
|
|
if (!text.isEmpty()) {
|
2019-01-20 17:49:29 +08:00
|
|
|
//JKQTMathText mt(this);
|
2019-01-26 03:16:04 +08:00
|
|
|
JKQTMathText* mt=parent->getMathText();
|
2019-04-22 19:27:50 +08:00
|
|
|
mt->setFontSize(getTextFontSize());
|
|
|
|
mt->setFontColor(getTextColor());
|
|
|
|
mt->setFontRomanOrSpecial(getTextFontName());
|
2015-07-11 18:56:02 +08:00
|
|
|
mt->parse(text);
|
|
|
|
mt->draw(painter, p3.x(), p3.y());
|
|
|
|
}
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPOverlayVerticalRange::setColor(QColor c)
|
|
|
|
{
|
|
|
|
setLineColor(c);
|
|
|
|
setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c));
|
|
|
|
setTextColor(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPOverlayVerticalRange::setInverted(bool __value)
|
|
|
|
{
|
|
|
|
this->inverted = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPOverlayVerticalRange::getInverted() const
|
|
|
|
{
|
|
|
|
return this->inverted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPOverlayVerticalRange::setText(const QString &__value)
|
|
|
|
{
|
|
|
|
text=__value;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString JKQTPOverlayVerticalRange::getText() const
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPOverlayLine::JKQTPOverlayLine(double x1, double y1, double x2, double y2, JKQTBasePlotter *parent):
|
|
|
|
JKQTPOverlayTwoPositionOverlay(x1,y1,x2,y2,parent)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
infinite=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPOverlayLine::draw(JKQTPEnhancedPainter &painter) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!parent) return;
|
|
|
|
double xmin=parent->getXMin();
|
|
|
|
double xmax=parent->getXMax();
|
|
|
|
QPointF p1=transform(x1, y1);
|
|
|
|
QPointF p2=transform(x2, y2);
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.setPen(getLinePen(painter, parent));
|
2015-07-11 18:56:02 +08:00
|
|
|
if (infinite) {
|
|
|
|
double alpha=(p2.y()-p1.y())/(p2.x()-p1.x());
|
|
|
|
double offset=p1.y()-alpha*p1.x();
|
|
|
|
|
|
|
|
double pxmin=transfromX(xmin);
|
|
|
|
double pxmax=transfromX(xmax);
|
|
|
|
|
|
|
|
QPointF pmin=QPointF(pxmin, pxmin*alpha+offset);
|
|
|
|
QPointF pmax=QPointF(pxmax, pxmax*alpha+offset);
|
|
|
|
painter.drawLine(pmin, pmax);
|
|
|
|
} else {
|
|
|
|
painter.drawLine(p1,p2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPOverlayLine::setInfinite(bool __value)
|
|
|
|
{
|
|
|
|
this->infinite = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPOverlayLine::getInfinite() const
|
|
|
|
{
|
|
|
|
return this->infinite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPOverlayLine::setColor(QColor c)
|
|
|
|
{
|
|
|
|
setLineColor(c);
|
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPOverlayRectangle::JKQTPOverlayRectangle(double x1, double y1, double x2, double y2, JKQTBasePlotter *parent):
|
|
|
|
JKQTPOverlayTwoPositionOverlay(x1,y1,x2,y2,parent)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPOverlayRectangle::draw(JKQTPEnhancedPainter &painter)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
if (!parent) return;
|
|
|
|
QPointF p1=transform(x1, y1);
|
|
|
|
QPointF p2=transform(x2, y2);
|
|
|
|
QRectF rect(qMin(p1.x(), p2.x()), qMin(p1.y(), p2.y()), fabs(p1.x()-p2.x()), fabs(p1.y()-p2.y()));
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.setPen(getLinePen(painter, parent));
|
|
|
|
painter.setBrush(getFillBrush(painter, parent));
|
2015-07-11 18:56:02 +08:00
|
|
|
//painter.fillRect(rect);
|
|
|
|
painter.drawRect(rect);
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
|
|
|
void JKQTPOverlayRectangle::setColor(QColor c)
|
|
|
|
{
|
|
|
|
setLineColor(c);
|
|
|
|
setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c));
|
|
|
|
}
|