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
|
|
|
|
the Free Software Foundation, either version 2 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \file jkqtplotter.cpp
|
2019-01-19 16:40:52 +08:00
|
|
|
* \ingroup jkqtpplotterclasses
|
2015-07-11 18:56:02 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QtWidgets>
|
|
|
|
#else
|
|
|
|
#include <QtGui>
|
|
|
|
#endif
|
2018-11-26 03:25:44 +08:00
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
2018-12-28 05:52:00 +08:00
|
|
|
#include "jkqtplotter/jkqtpgraphs.h"
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
#define jkqtp_RESIZE_DELAY 100
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************************************
|
2019-01-20 23:15:10 +08:00
|
|
|
* JKQTPlotter
|
2015-07-11 18:56:02 +08:00
|
|
|
**************************************************************************************************************************/
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter::JKQTPlotter(bool datastore_internal, QWidget* parent, JKQTPDatastore* datast):
|
2015-07-11 18:56:02 +08:00
|
|
|
QWidget(parent, Qt::Widget)
|
2018-12-03 01:30:12 +08:00
|
|
|
{
|
2019-01-20 23:15:10 +08:00
|
|
|
initJKQTPlotterResources();
|
2015-07-11 18:56:02 +08:00
|
|
|
init(datastore_internal, parent, datast);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter::JKQTPlotter(QWidget *parent):
|
2015-07-11 18:56:02 +08:00
|
|
|
QWidget(parent, Qt::Widget)
|
|
|
|
{
|
2019-01-20 23:15:10 +08:00
|
|
|
initJKQTPlotterResources();
|
2018-11-18 18:59:30 +08:00
|
|
|
init(true, parent, nullptr);
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::init(bool datastore_internal, QWidget* parent, JKQTPDatastore* datast)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
2015-10-12 23:05:15 +08:00
|
|
|
leftDoubleClickAction=LeftDoubleClickDefault;
|
2018-11-18 18:59:30 +08:00
|
|
|
menuSpecialContextMenu=nullptr;
|
2015-10-10 18:42:55 +08:00
|
|
|
mouseContextX=0;
|
|
|
|
mouseContextY=0;
|
2015-07-11 18:56:02 +08:00
|
|
|
setParent(parent);
|
|
|
|
connect(&resizeTimer, SIGNAL(timeout()), this, SLOT(delayedResizeEvent()));
|
|
|
|
doDrawing=false;
|
|
|
|
magnification=1;
|
2019-01-20 17:49:29 +08:00
|
|
|
plotter=new JKQTBasePlotter(datastore_internal, this, datast);
|
2015-07-11 18:56:02 +08:00
|
|
|
plotter->set_emitSignals(false);
|
|
|
|
plotter->set_backgroundColor(palette().color(QPalette::Window));//QPalette::Window
|
|
|
|
plotter->set_def_backgroundColor(palette().color(QPalette::Window));//QPalette::Window
|
|
|
|
//plotter->set_plotBackgroundColor(palette().color(QPalette::Base));
|
|
|
|
//plotter->set_def_plotBackgroundColor((palette().color(QPalette::Base));
|
|
|
|
|
|
|
|
mousePosX=0;
|
|
|
|
mousePosY=0;
|
2019-01-20 23:15:10 +08:00
|
|
|
rightMouseButtonAction=JKQTPlotter::RightMouseButtonContextMenu;
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
connect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
connect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
connect(plotter, SIGNAL(beforePlotScalingRecalculate()), this, SLOT(intBeforePlotScalingRecalculate()));
|
2019-01-20 17:49:29 +08:00
|
|
|
connect(plotter, SIGNAL(zoomChangedLocally(double, double, double, double, JKQTBasePlotter*)), this, SLOT(pzoomChangedLocally(double, double, double, double, JKQTBasePlotter*)));
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
image=QImage(width(), height(), QImage::Format_ARGB32);
|
|
|
|
oldImage=image;
|
|
|
|
imageNoOverlays=image;
|
|
|
|
toolbarIconSize=16;
|
|
|
|
mouseDragingRectangle=false;
|
|
|
|
|
|
|
|
def_userActionColor=QColor("steelblue"); userActionColor=def_userActionColor;
|
|
|
|
def_userActionCompositionMode=QPainter::CompositionMode_SourceOver; userActionCompositionMode=def_userActionCompositionMode;
|
|
|
|
def_mousePositionTemplate=QString("(%1; %2)"); mousePositionTemplate=def_mousePositionTemplate;
|
|
|
|
|
|
|
|
displayMousePosition=true;
|
|
|
|
displayCustomMousePosition=false;
|
|
|
|
customMousePositiontext="";
|
|
|
|
displayToolbar=true;
|
|
|
|
toolbarAlwaysOn=false;
|
2019-01-20 23:15:10 +08:00
|
|
|
mouseActionMode=JKQTPlotter::ZoomRectangle;
|
2015-07-11 18:56:02 +08:00
|
|
|
//zoomByDoubleAndRightMouseClick=true;
|
|
|
|
zoomByMouseWheel=true;
|
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
|
|
toolbar=new JKVanishQToolBar(this);
|
|
|
|
toolbar->clear();
|
|
|
|
toolbar->move(1,1);
|
|
|
|
toolbar->hide();
|
|
|
|
toolbar->setAutoFillBackground(true);
|
|
|
|
toolbar->addSeparator();
|
|
|
|
toolbar->addSeparator();
|
|
|
|
populateToolbar(toolbar);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contextMenu=new QMenu(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QSize s=QSize(toolbarIconSize, toolbarIconSize);
|
|
|
|
toolbar->setIconSize(s);
|
|
|
|
|
|
|
|
//move(32,32);
|
|
|
|
resize(400,300);
|
|
|
|
doDrawing=true;
|
|
|
|
plotter->set_emitSignals(true);
|
|
|
|
update_plot();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter::~JKQTPlotter() {
|
2015-07-11 18:56:02 +08:00
|
|
|
disconnect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
disconnect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
disconnect(plotter, SIGNAL(beforePlotScalingRecalculate()), this, SLOT(intBeforePlotScalingRecalculate()));
|
2019-01-20 17:49:29 +08:00
|
|
|
disconnect(plotter, SIGNAL(zoomChangedLocally(double, double, double, double, JKQTBasePlotter*)), this, SLOT(pzoomChangedLocally(double, double, double, double, JKQTBasePlotter*)));
|
2015-07-11 18:56:02 +08:00
|
|
|
delete plotter;
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::updateToolbarActions()
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
toolbar->clear();
|
|
|
|
toolbar->setAutoFillBackground(true);
|
|
|
|
toolbar->addSeparator();
|
|
|
|
toolbar->addSeparator();
|
|
|
|
populateToolbar(toolbar);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::loadSettings(QSettings& settings, QString group) {
|
2015-07-11 18:56:02 +08:00
|
|
|
plotter->loadSettings(settings, group);
|
|
|
|
|
|
|
|
|
|
|
|
set_toolbarIconSize(settings.value(group+"toolbar_icon_size", toolbarIconSize).toInt());
|
|
|
|
mousePositionTemplate=settings.value(group+"mouse_position_template", mousePositionTemplate).toString();
|
2019-01-20 17:49:29 +08:00
|
|
|
userActionColor=QColor(settings.value(group+"zoomrect_color", jkqtp_QColor2String(userActionColor)).toString());
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
update_plot();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::saveSettings(QSettings& settings, QString group) {
|
2015-07-11 18:56:02 +08:00
|
|
|
plotter->saveSettings(settings, group);
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
if (userActionColor!=def_userActionColor) settings.setValue(group+"zoomrect_color", jkqtp_QColor2String(userActionColor));
|
2015-07-11 18:56:02 +08:00
|
|
|
if (toolbarIconSize!=def_toolbarIconSize) settings.setValue(group+"toolbar_icon_size", toolbarIconSize);
|
|
|
|
if (mousePositionTemplate!=def_mousePositionTemplate) settings.setValue(group+"mouse_position_template", mousePositionTemplate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::paintUserAction() {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (mouseDragingRectangle) {
|
|
|
|
image=oldImage;
|
|
|
|
if (image.width()>0 && image.height()>0 && !image.isNull()) {
|
|
|
|
JKQTPEnhancedPainter painter(&image);
|
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setWidthF(1);
|
|
|
|
p.setColor(QColor("black"));
|
|
|
|
p.setStyle(Qt::DashLine);
|
|
|
|
painter.setPen(p);
|
|
|
|
QPainter::CompositionMode oldCMode=painter.compositionMode();
|
|
|
|
painter.setCompositionMode(userActionCompositionMode);
|
|
|
|
if ((mouseDragRectXEnd!=mouseDragRectXStart) && (mouseDragRectYEnd!=mouseDragRectYStart)) {
|
|
|
|
double x1=plotter->x2p(mouseDragRectXStart)*magnification;
|
|
|
|
double y1=plotter->y2p(mouseDragRectYStart)*magnification;
|
|
|
|
double x2=plotter->x2p(mouseDragRectXEnd)*magnification;
|
|
|
|
double y2=plotter->y2p(mouseDragRectYEnd)*magnification;
|
|
|
|
double dx=x2-x1;
|
|
|
|
double dy=y2-y1;
|
2019-01-20 23:15:10 +08:00
|
|
|
if ((mouseActionMode==JKQTPlotter::ZoomRectangle) || (mouseActionMode==JKQTPlotter::RectangleEvents)) {
|
2015-07-11 18:56:02 +08:00
|
|
|
painter.setOpacity(0.2);
|
|
|
|
painter.fillRect(QRectF(x1, y1, x2-x1, y2-y1), QBrush(userActionColor));
|
|
|
|
painter.setOpacity(1.0);
|
|
|
|
painter.drawRect(QRectF(x1, y1, x2-x1, y2-y1));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::CircleEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QColor zc=userActionColor;
|
|
|
|
zc.setAlphaF(0.2);
|
|
|
|
painter.setBrush(QBrush(zc));
|
|
|
|
painter.drawEllipse(QPointF(x1, y1), qMin(fabs(dx), fabs(dy)), qMin(fabs(dx), fabs(dy)));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::EllipseEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QColor zc=userActionColor;
|
|
|
|
zc.setAlphaF(0.2);
|
|
|
|
painter.setBrush(QBrush(zc));
|
|
|
|
painter.drawEllipse(QPointF(x1, y1), fabs(dx), fabs(dy));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::LineEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QPen pp=p;
|
|
|
|
pp.setColor(userActionColor);
|
|
|
|
painter.setPen(pp);
|
|
|
|
painter.drawLine(QPointF(x1,y1), QPointF(x2,y2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
painter.setCompositionMode(oldCMode);
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::mouseMoveEvent ( QMouseEvent * event ) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (displayMousePosition) {
|
|
|
|
mousePosX=plotter->p2x(event->x()/magnification);
|
|
|
|
mousePosY=plotter->p2y((event->y()-getPlotYOffset())/magnification);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayToolbar && (!toolbarAlwaysOn) && (!toolbar->isVisible())) { // decide whether to display toolbar
|
|
|
|
int y1=10;
|
|
|
|
if (event->y()/magnification>=0 && event->y()/magnification<=y1) {
|
|
|
|
toolbar->show();
|
|
|
|
toolbar->move(1,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!displayToolbar) {
|
|
|
|
toolbar->hide();
|
|
|
|
}
|
2019-01-20 23:15:10 +08:00
|
|
|
if (( (mouseActionMode==JKQTPlotter::ZoomRectangle) ||
|
|
|
|
(mouseActionMode==JKQTPlotter::RectangleEvents) ||
|
|
|
|
(mouseActionMode==JKQTPlotter::CircleEvents) ||
|
|
|
|
(mouseActionMode==JKQTPlotter::EllipseEvents) ||
|
|
|
|
(mouseActionMode==JKQTPlotter::ScribbleEvents) ||
|
|
|
|
(mouseActionMode==JKQTPlotter::LineEvents) ) &&
|
2015-07-11 18:56:02 +08:00
|
|
|
mouseDragingRectangle && (event->buttons() & Qt::LeftButton))
|
|
|
|
{
|
2019-01-20 23:15:10 +08:00
|
|
|
if (mouseActionMode==JKQTPlotter::ScribbleEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
mouseDragRectXStart=mouseDragRectXEnd;
|
|
|
|
mouseDragRectYStart=mouseDragRectYEnd;
|
|
|
|
}
|
|
|
|
mouseDragRectXEnd=plotter->p2x(event->x()/magnification);
|
|
|
|
mouseDragRectYEnd=plotter->p2y((event->y()-getPlotYOffset())/magnification);
|
|
|
|
paintUserAction();
|
|
|
|
event->accept();
|
|
|
|
//std::cout<<mouseZoomingTStart<<" -- "<<mouseZoomingTEnd<<std::endl;
|
2019-01-20 23:15:10 +08:00
|
|
|
if (mouseActionMode==JKQTPlotter::ZoomRectangle) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit plotNewZoomRectangle(mouseDragRectXStart, mouseDragRectXEnd, mouseDragRectYStart, mouseDragRectYEnd);
|
|
|
|
}
|
2019-01-20 23:15:10 +08:00
|
|
|
if ((mouseActionMode==JKQTPlotter::ScribbleEvents) && ((mouseDragRectXStart!=mouseDragRectXEnd) || (mouseDragRectYStart!=mouseDragRectYEnd)) ) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit userScribbleClick(mouseDragRectXEnd, mouseDragRectYEnd, event->modifiers(), false, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event->accept();
|
|
|
|
/*if (emitSignals)*/ //emit plotMouseMove(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// emit clicked signal, if event occured inside plot only
|
|
|
|
if ( (event->x()/magnification>=plotter->get_iplotBorderLeft()) && (event->x()/magnification<=plotter->get_plotWidth()+plotter->get_iplotBorderLeft()) &&
|
|
|
|
((event->y()-getPlotYOffset())/magnification>=plotter->get_iplotBorderTop()) && ((event->y()-getPlotYOffset())/magnification<=plotter->get_plotHeight()+plotter->get_iplotBorderTop()) ) {
|
|
|
|
emit plotMouseMove(plotter->p2x(event->x()/magnification), plotter->p2y((event->y()-getPlotYOffset())/magnification));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::mousePressEvent ( QMouseEvent * event ){
|
2015-07-11 18:56:02 +08:00
|
|
|
if (event->button()==Qt::LeftButton) {
|
2015-10-12 23:05:15 +08:00
|
|
|
mouseLastClickX=event->x();
|
|
|
|
mouseLastClickY=event->y();
|
2019-01-20 23:15:10 +08:00
|
|
|
if ( (mouseActionMode!=JKQTPlotter::NoMouseAction))
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
mouseDragRectXStart=plotter->p2x(event->x()/magnification);
|
|
|
|
mouseDragRectYStart=plotter->p2y((event->y()-getPlotYOffset())/magnification);
|
|
|
|
mouseDragingRectangle=true;
|
|
|
|
oldImage=image;
|
|
|
|
event->accept();
|
2019-01-20 23:15:10 +08:00
|
|
|
if (mouseActionMode==JKQTPlotter::ScribbleEvents) emit userScribbleClick(mouseDragRectXStart, mouseDragRectYStart, event->modifiers(), true, false);
|
|
|
|
if (mouseActionMode==JKQTPlotter::ClickEvents) emit userClickFinished(mouseDragRectXStart, mouseDragRectYStart, event->modifiers());
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
} else if (event->button()==Qt::RightButton) {
|
2015-10-12 23:05:15 +08:00
|
|
|
mouseLastClickX=event->x();
|
|
|
|
mouseLastClickY=event->y();
|
2019-01-20 23:15:10 +08:00
|
|
|
if (rightMouseButtonAction==JKQTPlotter::RightMouseButtonZoom) {
|
2015-07-11 18:56:02 +08:00
|
|
|
double xmin=plotter->p2x((long)round((double)plotter->get_iplotBorderLeft()-(double)plotter->get_plotWidth()/2.0));
|
|
|
|
double xmax=plotter->p2x((long)round((double)plotter->get_iplotBorderLeft()+1.5*(double)plotter->get_plotWidth()));
|
|
|
|
double ymin=plotter->p2y((long)round((double)plotter->get_iplotBorderTop()+1.5*(double)plotter->get_plotHeight()));
|
|
|
|
double ymax=plotter->p2y((long)round((double)plotter->get_iplotBorderTop()-(double)plotter->get_plotHeight()/2.0));
|
|
|
|
if (plotter->get_xAxis()->isLogAxis()) {
|
|
|
|
if (xmin<=0) xmin=1;
|
|
|
|
if (xmax<=0) xmax=10;
|
|
|
|
}
|
|
|
|
if (plotter->get_yAxis()->isLogAxis()) {
|
|
|
|
if (ymin<=0) ymin=1;
|
|
|
|
if (ymax<=0) ymax=10;
|
|
|
|
}
|
|
|
|
/*plotter->get_xAxis->setRange(xmin, xmax);
|
|
|
|
plotter->get_yAxis->setRange(ymin, ymax);*/
|
|
|
|
//update_plot();
|
|
|
|
/*if (plotter->get_emitSignals())*/ emit zoomChangedLocally(xmin, xmax, ymin, ymax, this);
|
|
|
|
plotter->setXY(xmin, xmax, ymin, ymax);
|
|
|
|
//update();
|
|
|
|
event->accept();
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (rightMouseButtonAction==JKQTPlotter::RightMouseButtonContextMenu) {
|
2015-10-12 23:05:15 +08:00
|
|
|
openContextMenu(event->x(), event->y());
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// emit clicked signal, if event occured inside plot only
|
|
|
|
if ( (event->x()/magnification>=plotter->get_iplotBorderLeft()) && (event->x()/magnification<=plotter->get_plotWidth()+plotter->get_iplotBorderLeft()) &&
|
|
|
|
((event->y()-getPlotYOffset())/magnification>=plotter->get_iplotBorderTop()) && ((event->y()-getPlotYOffset())/magnification<=plotter->get_plotHeight()+plotter->get_iplotBorderTop()) ) {
|
|
|
|
emit plotMouseClicked(plotter->p2x(event->x()/magnification), plotter->p2y((event->y()-getPlotYOffset())/magnification), event->modifiers(), event->button());
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::mouseReleaseEvent ( QMouseEvent * event ){
|
2015-10-12 23:05:15 +08:00
|
|
|
if ((event->flags()&Qt::MouseEventCreatedDoubleClick)==Qt::MouseEventCreatedDoubleClick) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-11 18:56:02 +08:00
|
|
|
if (mouseDragingRectangle && event->button()==Qt::LeftButton) {
|
|
|
|
mouseDragRectXEnd=plotter->p2x(event->x()/magnification);
|
|
|
|
mouseDragRectYEnd=plotter->p2y((event->y()-getPlotYOffset())/magnification);
|
|
|
|
image=oldImage;
|
|
|
|
//update();
|
|
|
|
mouseDragingRectangle=false;
|
|
|
|
|
|
|
|
|
|
|
|
double x1=mouseDragRectXStart;
|
|
|
|
double y1=mouseDragRectYStart;
|
|
|
|
double x2=mouseDragRectXEnd;
|
|
|
|
double y2=mouseDragRectYEnd;
|
|
|
|
|
|
|
|
if ((mouseDragRectXStart!=mouseDragRectXEnd) && (mouseDragRectYStart!=mouseDragRectYEnd)) {
|
2019-01-20 23:15:10 +08:00
|
|
|
if (mouseActionMode==JKQTPlotter::ZoomRectangle) {
|
2015-07-11 18:56:02 +08:00
|
|
|
double xmin=mouseDragRectXStart;
|
|
|
|
double xmax=mouseDragRectXEnd;
|
|
|
|
|
|
|
|
double ymin=mouseDragRectYStart;
|
|
|
|
double ymax=mouseDragRectYEnd;
|
|
|
|
|
|
|
|
emit zoomChangedLocally(xmin, xmax, ymin, ymax, this);
|
|
|
|
plotter->setXY(xmin, xmax, ymin, ymax);
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::RectangleEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit userRectangleFinished(x1, y1, x2-x1, y2-y1, event->modifiers());
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::CircleEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit userCircleFinished(x1, y1, qMin(fabs(x2-x1), fabs(y2-y1)), event->modifiers());
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::EllipseEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit userEllipseFinished(x1, y1, fabs(x2-x1), fabs(y2-y1), event->modifiers());
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::LineEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit userLineFinished(x1, y1, x2, y2, event->modifiers());
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::ScribbleEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit userScribbleClick(x1, y1, event->modifiers(), false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-01-20 23:15:10 +08:00
|
|
|
if (mouseActionMode!=JKQTPlotter::ZoomRectangle) update();
|
2015-07-11 18:56:02 +08:00
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::mouseDoubleClickEvent ( QMouseEvent * event ){
|
2015-07-11 18:56:02 +08:00
|
|
|
// only react on double clicks inside the widget
|
|
|
|
if ( (event->x()/magnification>=plotter->get_iplotBorderLeft()) && (event->x()/magnification<=plotter->get_plotWidth()+plotter->get_iplotBorderLeft()) &&
|
|
|
|
((event->y()-getPlotYOffset())/magnification>=plotter->get_iplotBorderTop()) && ((event->y()-getPlotYOffset())/magnification<=plotter->get_plotHeight()+plotter->get_iplotBorderTop()) ) {
|
|
|
|
|
2015-10-12 23:05:15 +08:00
|
|
|
mouseLastClickX=event->x();
|
|
|
|
mouseLastClickY=event->y();
|
|
|
|
if (event->button()==Qt::LeftButton) {
|
|
|
|
if (leftDoubleClickAction==LeftDoubleClickContextMenu) {
|
|
|
|
openContextMenu(event->x(), event->y());
|
|
|
|
event->accept();
|
|
|
|
} else if (leftDoubleClickAction==LeftDoubleClickSpecialContextMenu) {
|
|
|
|
openSpecialContextMenu(event->x(), event->y());
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
if (rightMouseButtonAction==JKQTPlotter::RightMouseButtonZoom && event->button()==Qt::RightButton) {
|
2015-07-11 18:56:02 +08:00
|
|
|
double factor=4.0;
|
|
|
|
if (event->button()==Qt::RightButton) factor=1;
|
|
|
|
double xmin=plotter->p2x((long)round((double)event->x()/magnification-(double)plotter->get_plotWidth()/factor));
|
|
|
|
double xmax=plotter->p2x((long)round((double)event->x()/magnification+(double)plotter->get_plotWidth()/factor));
|
|
|
|
double ymin=plotter->p2y((long)round((double)event->y()/magnification-(double)getPlotYOffset()+(double)plotter->get_plotHeight()/factor));
|
|
|
|
double ymax=plotter->p2y((long)round((double)event->y()/magnification-(double)getPlotYOffset()-(double)plotter->get_plotHeight()/factor));
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
//xAxis->setRange(xmin, xmax);
|
|
|
|
//yAxis->setRange(ymin, ymax);
|
|
|
|
//update_plot();
|
|
|
|
/*if (plotter->get_emitSignals())*/ emit zoomChangedLocally(xmin, xmax, ymin, ymax, this);
|
|
|
|
plotter->setXY(xmin, xmax, ymin, ymax);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
emit plotMouseDoubleClicked(plotter->p2x(event->x()/magnification), plotter->p2y((event->y()-getPlotYOffset())/magnification), event->modifiers(), event->button());
|
|
|
|
|
|
|
|
} else { event->ignore(); }
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::keyReleaseEvent(QKeyEvent *event) {
|
2015-07-11 18:56:02 +08:00
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
if (event->key()==Qt::Key_Escape && event->modifiers()==Qt::NoModifier) {
|
|
|
|
if (mouseDragingRectangle) {
|
|
|
|
mouseDragingRectangle=false;
|
|
|
|
image=oldImage;
|
|
|
|
update();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::wheelEvent ( QWheelEvent * event ) {
|
2015-07-11 18:56:02 +08:00
|
|
|
// only react on wheel turns inside the widget, turning forward will zoom out and turning backwards will zoom in by a factor of 2
|
|
|
|
if ( (event->x()/magnification>=plotter->get_iplotBorderLeft()) && (event->x()/magnification<=plotter->get_plotWidth()+plotter->get_iplotBorderLeft()) &&
|
|
|
|
((event->y()-getPlotYOffset())/magnification>=plotter->get_iplotBorderTop()) && ((event->y()-getPlotYOffset())/magnification<=plotter->get_plotHeight()+plotter->get_iplotBorderTop()) ) {
|
|
|
|
double factor=pow(2.0, 1.0*(double)event->delta()/120.0)*2.0;
|
|
|
|
//std::cout<<(double)event->delta()/120.0<<": "<<factor<<std::endl;
|
|
|
|
double xmin=plotter->p2x((long)round((double)event->x()/magnification-(double)plotter->get_plotWidth()/factor));
|
|
|
|
double xmax=plotter->p2x((long)round((double)event->x()/magnification+(double)plotter->get_plotWidth()/factor));
|
|
|
|
double ymin=plotter->p2y((long)round((double)event->y()/magnification-(double)getPlotYOffset()+(double)plotter->get_plotHeight()/factor));
|
|
|
|
double ymax=plotter->p2y((long)round((double)event->y()/magnification-(double)getPlotYOffset()-(double)plotter->get_plotHeight()/factor));
|
|
|
|
|
|
|
|
//std::cout<<"t="<<t<<", w="<<w<<" => "<<tmin<<" -- "<<tmax<<std::endl;
|
|
|
|
event->accept();
|
|
|
|
/*if (plotter->get_emitSignals())*/ emit zoomChangedLocally(xmin, xmax, ymin, ymax, this);
|
|
|
|
plotter->setXY(xmin, xmax, ymin, ymax);
|
|
|
|
//update();
|
|
|
|
/*xAxis->setRange(xmin, xmax);
|
|
|
|
yAxis->setRange(ymin, ymax);
|
|
|
|
//update_plot();
|
|
|
|
if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this);*/
|
|
|
|
} else { event->ignore(); }
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
int JKQTPlotter::getPlotYOffset() {
|
2015-07-11 18:56:02 +08:00
|
|
|
int plotYOffset=0;
|
|
|
|
if (displayMousePosition) {
|
|
|
|
plotYOffset=plotYOffset+QFontMetrics(font()).height()+2;
|
|
|
|
}
|
|
|
|
if (displayToolbar && toolbarAlwaysOn) {
|
|
|
|
plotYOffset=plotYOffset+toolbar->height();
|
|
|
|
}
|
|
|
|
return plotYOffset;
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::initContextMenu()
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
contextMenu->clear();
|
|
|
|
qDeleteAll(contextSubMenus);
|
|
|
|
contextSubMenus.clear();
|
|
|
|
|
|
|
|
contextMenu->addAction(plotter->get_actSaveData());
|
|
|
|
contextMenu->addAction(plotter->get_actSavePlot());
|
|
|
|
contextMenu->addAction(plotter->get_actPrint());
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(plotter->get_actCopyPixelImage());
|
|
|
|
contextMenu->addAction(plotter->get_actCopyData());
|
|
|
|
contextMenu->addAction(plotter->get_actCopyMatlab());
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(plotter->get_actShowPlotData());
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(plotter->get_actZoomAll());
|
|
|
|
contextMenu->addAction(plotter->get_actZoomIn());
|
|
|
|
contextMenu->addAction(plotter->get_actZoomOut());
|
2018-08-20 00:17:18 +08:00
|
|
|
contextMenu->addSeparator();
|
|
|
|
QMenu* menVisibleGroup=new QMenu(tr("Graph Visibility"), contextMenu);
|
|
|
|
for (size_t i=0; i<get_plotter()->getGraphCount(); i++) {
|
|
|
|
QString tit=get_plotter()->getGraph(i)->get_title();
|
|
|
|
if (tit.isEmpty()) tit=tr("Graph %1").arg(static_cast<int>(i));
|
|
|
|
QAction* act=new QAction(tit, menVisibleGroup);
|
|
|
|
act->setCheckable(true);
|
|
|
|
act->setChecked(get_plotter()->getGraph(i)->get_visible());
|
|
|
|
act->setIcon(QIcon(QPixmap::fromImage(get_plotter()->getGraph(i)->generateKeyMarker(QSize(16,16)))));
|
|
|
|
act->setData(static_cast<int>(i));
|
|
|
|
connect(act, SIGNAL(toggled(bool)), this, SLOT(reactGraphVisible(bool)));
|
|
|
|
menVisibleGroup->addAction(act);
|
|
|
|
}
|
|
|
|
contextMenu->addMenu(menVisibleGroup);
|
2015-07-11 18:56:02 +08:00
|
|
|
|
|
|
|
if (actions().size()>0) {
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addActions(actions());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSep=false;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTBasePlotter::AdditionalActionsMap lst=get_plotter()->get_lstAdditionalPlotterActions();
|
|
|
|
JKQTBasePlotter::AdditionalActionsMapIterator it(lst);
|
2015-07-11 18:56:02 +08:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (it.value().size()>0) {
|
|
|
|
bool hasMenu=false;
|
|
|
|
for (int i=0; i<it.value().size(); i++) {
|
|
|
|
if (it.value().at(i)) {
|
|
|
|
if (!hasMenu) {
|
|
|
|
contextSubMenus.append(new QMenu(it.key(), this));
|
|
|
|
if (!hasSep) {
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
hasSep=true;
|
|
|
|
}
|
|
|
|
hasMenu=true;
|
|
|
|
}
|
|
|
|
contextSubMenus.last()->addAction(it.value().at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasMenu) {
|
|
|
|
contextMenu->addMenu(contextSubMenus.last());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
modifyContextMenu(contextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::updateCursor() {
|
|
|
|
if (mouseActionMode==JKQTPlotter::ZoomRectangle) {
|
|
|
|
QBitmap cursor(":/JKQTPlotter/jkqtp_cursor_zoom.png");
|
|
|
|
QBitmap mask(":/JKQTPlotter/jkqtp_cursor_zoom_mask.png");
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(cursor, mask, 9, 14));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::RectangleEvents) {
|
|
|
|
QBitmap cursor(":/JKQTPlotter/jkqtp_cursor_rectangle.png");
|
|
|
|
QBitmap mask(":/JKQTPlotter/jkqtp_cursor_rectangle_mask.png");
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(cursor, mask, 9, 14));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::CircleEvents) {
|
|
|
|
QBitmap cursor(":/JKQTPlotter/jkqtp_cursor_circle.png");
|
|
|
|
QBitmap mask(":/JKQTPlotter/jkqtp_cursor_circle_mask.png");
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(cursor, mask, 9, 14));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::EllipseEvents) {
|
|
|
|
QBitmap cursor(":/JKQTPlotter/jkqtp_cursor_ellipse.png");
|
|
|
|
QBitmap mask(":/JKQTPlotter/jkqtp_cursor_ellipse_mask.png");
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(cursor, mask, 9, 14));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::LineEvents) {
|
|
|
|
QBitmap cursor(":/JKQTPlotter/jkqtp_cursor_line.png");
|
|
|
|
QBitmap mask(":/JKQTPlotter/jkqtp_cursor_line_mask.png");
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(cursor, mask, 9, 14));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::ClickEvents) {
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(Qt::CrossCursor));
|
2019-01-20 23:15:10 +08:00
|
|
|
} else if (mouseActionMode==JKQTPlotter::ScribbleEvents) {
|
|
|
|
QBitmap cursor(":/JKQTPlotter/jkqtp_cursor_scribble.png");
|
|
|
|
QBitmap mask(":/JKQTPlotter/jkqtp_cursor_scribble_mask.png");
|
2015-07-11 18:56:02 +08:00
|
|
|
setCursor(QCursor(cursor, mask, 9, 14));
|
|
|
|
} else {
|
|
|
|
setCursor(QCursor(Qt::ArrowCursor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::update_overlays() {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!doDrawing) return;
|
|
|
|
disconnect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
disconnect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
image=imageNoOverlays;
|
|
|
|
JKQTPEnhancedPainter painter(&image);
|
|
|
|
if (painter.isActive()) {
|
|
|
|
painter.scale(magnification, magnification);
|
|
|
|
plotter->drawNonGridOverlays(painter);
|
|
|
|
}
|
|
|
|
oldImage=image;
|
|
|
|
connect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
connect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::synchronizeXAxis(double newxmin, double newxmax, double /*newymin*/, double /*newymax*/, JKQTPlotter * /*sender*/) {
|
2015-07-11 18:56:02 +08:00
|
|
|
setX(newxmin, newxmax);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::synchronizeYAxis(double /*newxmin*/, double /*newxmax*/, double newymin, double newymax, JKQTPlotter * /*sender*/) {
|
2015-07-11 18:56:02 +08:00
|
|
|
setY(newymin, newymax);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::synchronizeXYAxis(double newxmin, double newxmax, double newymin, double newymax, JKQTPlotter * /*sender*/) {
|
2015-07-11 18:56:02 +08:00
|
|
|
setXY(newxmin, newxmax, newymin, newymax);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::replot_overlays() {
|
2015-07-11 18:56:02 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot(QString("JKQTPlotter::replot_overlays()"));
|
2015-07-11 18:56:02 +08:00
|
|
|
#endif
|
|
|
|
if (!doDrawing) return;
|
|
|
|
disconnect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
disconnect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
image=imageNoOverlays;
|
|
|
|
JKQTPEnhancedPainter painter(&image);
|
|
|
|
if (painter.isActive()) {
|
|
|
|
painter.scale(magnification, magnification);
|
|
|
|
plotter->drawNonGridOverlays(painter);
|
|
|
|
}
|
|
|
|
oldImage=image;
|
|
|
|
connect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
connect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::update_plot() {
|
2015-07-11 18:56:02 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot(QString("JKQTPlotter::update_plot()"));
|
2015-07-11 18:56:02 +08:00
|
|
|
#endif
|
|
|
|
if (!doDrawing) return;
|
|
|
|
disconnect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
disconnect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
plotter->resize(width()/magnification, height()/magnification-getPlotYOffset());
|
|
|
|
JKQTPEnhancedPainter painter(&image);
|
|
|
|
if (painter.isActive()) {
|
|
|
|
painter.scale(magnification, magnification);
|
|
|
|
//QTime t;
|
|
|
|
//t.start();
|
|
|
|
plotter->drawNonGrid(painter, QPoint(0,0), false);//, QRect(QPoint(0,0), QSize(plotter->get_plotWidth(), plotter->get_plotHeight())));
|
|
|
|
//qDebug()<<"drawNonGrid"<<objectName()<<": "<<t.elapsed()<<"ms";
|
|
|
|
imageNoOverlays=image;
|
|
|
|
plotter->drawNonGridOverlays(painter);
|
|
|
|
}
|
|
|
|
oldImage=image;
|
|
|
|
connect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
connect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::replot_plot() {
|
2015-07-11 18:56:02 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot(QString("JKQTPlotter::replot_plot()"));
|
2015-07-11 18:56:02 +08:00
|
|
|
#endif
|
|
|
|
if (!doDrawing) return;
|
|
|
|
disconnect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
disconnect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
|
|
|
|
plotter->resize(width()/magnification, height()/magnification-getPlotYOffset());
|
|
|
|
JKQTPEnhancedPainter painter(&image);
|
|
|
|
if (painter.isActive()) {
|
|
|
|
painter.scale(magnification, magnification);
|
|
|
|
plotter->drawNonGrid(painter);//, QRect(QPoint(0,0), QSize(plotter->get_plotWidth(), plotter->get_plotHeight())));
|
|
|
|
}
|
|
|
|
oldImage=image;
|
|
|
|
connect(plotter, SIGNAL(plotUpdated()), this, SLOT(update_plot()));
|
|
|
|
connect(plotter, SIGNAL(overlaysUpdated()), this, SLOT(replot_overlays()));
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::paintEvent(QPaintEvent *event){
|
2015-07-11 18:56:02 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot(QString("JKQTPlotter::paintEvent()"));
|
2015-07-11 18:56:02 +08:00
|
|
|
#endif
|
|
|
|
// draw the saved image of the plot
|
|
|
|
JKQTPEnhancedPainter* p = new JKQTPEnhancedPainter(this);
|
|
|
|
|
|
|
|
if (p->isActive()) {
|
|
|
|
|
|
|
|
//std::cout<<"getPlotYOffset()="<<getPlotYOffset()<<std::endl;
|
|
|
|
p->save();
|
|
|
|
p->setBrush(palette().brush(QPalette::Window));
|
|
|
|
p->setPen(palette().color(QPalette::Window));
|
|
|
|
p->drawRect(geometry());
|
|
|
|
p->restore();
|
|
|
|
if (displayMousePosition ) {
|
|
|
|
if (displayCustomMousePosition) {
|
|
|
|
p->drawText(plotter->get_iplotBorderLeft(), getPlotYOffset()-1, customMousePositiontext);
|
|
|
|
} else {
|
|
|
|
p->drawText(plotter->get_iplotBorderLeft(), getPlotYOffset()-1, mousePositionTemplate.arg(mousePosX).arg(mousePosY));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int plotImageWidth=width();
|
|
|
|
int plotImageHeight=height();
|
|
|
|
|
|
|
|
plotImageHeight=plotImageHeight-getPlotYOffset();
|
|
|
|
if (image.width()!=plotImageWidth || image.height()!=plotImageHeight) {
|
|
|
|
p->drawImage(QRectF(0, getPlotYOffset(), plotImageWidth, plotImageHeight), image);
|
|
|
|
} else {
|
|
|
|
p->drawImage(QPoint(0, getPlotYOffset()), image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete p;
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::resizeEvent(QResizeEvent *event) {
|
2015-07-11 18:56:02 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot(QString("JKQTPlotter::resizeEvent()"));
|
2015-07-11 18:56:02 +08:00
|
|
|
#endif
|
|
|
|
//qDebug()<<"resizeEvent old="<<size()<<" new="<<event->size();
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
event->accept();
|
|
|
|
bool sizeChanged=false;
|
|
|
|
int plotImageWidth=width();
|
|
|
|
int plotImageHeight=height();
|
|
|
|
|
|
|
|
plotImageHeight=plotImageHeight-getPlotYOffset();
|
|
|
|
if (plotImageWidth != image.width() || plotImageHeight != image.height()) {
|
|
|
|
sizeChanged=true;
|
|
|
|
}
|
|
|
|
if (sizeChanged) {
|
|
|
|
resizeTimer.setSingleShot(true);
|
2019-01-20 17:49:29 +08:00
|
|
|
resizeTimer.start(jkqtp_RESIZE_DELAY);
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//updateGeometry();
|
|
|
|
//std::cout<<"resize DONE\n";
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::delayedResizeEvent()
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
int plotImageWidth=width();
|
|
|
|
int plotImageHeight=height();
|
|
|
|
|
|
|
|
plotImageHeight=plotImageHeight-getPlotYOffset();
|
|
|
|
//std::cout<<"resize: "<<plotImageWidth<<" x "<<plotImageHeight<<std::endl;
|
|
|
|
bool sizeChanged=false;
|
|
|
|
if (plotImageWidth != image.width() || plotImageHeight != image.height()) {
|
|
|
|
|
|
|
|
QImage newImage(QSize(plotImageWidth, plotImageHeight), QImage::Format_ARGB32);
|
|
|
|
image=newImage;
|
|
|
|
sizeChanged=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizeChanged) update_plot();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::leaveEvent(QEvent * /*event*/) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!toolbarAlwaysOn) toolbar->hide();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::updateToolbar()
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
if (displayToolbar) {
|
|
|
|
if (toolbarAlwaysOn) {
|
|
|
|
toolbar->set_toolbarVanishes(false);
|
|
|
|
toolbar->show();
|
|
|
|
toolbar->move(1,1);
|
|
|
|
} else {
|
|
|
|
toolbar->set_toolbarVanishes(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toolbar->hide();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
QSize JKQTPlotter::minimumSizeHint() const {
|
2015-07-11 18:56:02 +08:00
|
|
|
QSize m=QWidget::minimumSizeHint();
|
|
|
|
|
|
|
|
if (minSize.width()>m.width()) m.setWidth(minSize.width());
|
|
|
|
if (minSize.height()>m.height()) m.setHeight(minSize.height());
|
|
|
|
return m;//QSize((int)round((plotter->get_iplotBorderLeft()+plotter->get_iplotBorderRight())*1.5), (int)round((plotter->get_iplotBorderTop()+plotter->get_iplotBorderBottom())*1.5));
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
QSize JKQTPlotter::sizeHint() const {
|
2015-07-11 18:56:02 +08:00
|
|
|
return QWidget::sizeHint(); //minimumSizeHint()+QSize(200,100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::masterPlotScalingRecalculated() {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (masterPlotter) {
|
|
|
|
if (plotter->get_masterSynchronizeHeight()||plotter->get_masterSynchronizeWidth()) {
|
|
|
|
update_plot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::synchronizeToMaster(JKQTPlotter* master, bool synchronizeWidth, bool synchronizeHeight) {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (!master) {
|
|
|
|
resetMasterSynchronization();
|
|
|
|
}
|
|
|
|
plotter->synchronizeToMaster(master->get_plotter(), synchronizeWidth, synchronizeHeight);
|
|
|
|
masterPlotter=master;
|
|
|
|
if (masterPlotter) connect(masterPlotter->get_plotter(), SIGNAL(plotScalingRecalculated()), this, SLOT(masterPlotScalingRecalculated()));
|
|
|
|
update_plot();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::resetMasterSynchronization() {
|
2015-07-11 18:56:02 +08:00
|
|
|
if (masterPlotter) disconnect(masterPlotter->get_plotter(), SIGNAL(plotScalingRecalculated()), this, SLOT(masterPlotScalingRecalculated()));
|
|
|
|
plotter->resetMasterSynchronization();
|
|
|
|
update_plot();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::pzoomChangedLocally(double newxmin, double newxmax, double newymin, double newymax, JKQTBasePlotter* /*sender*/) {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit zoomChangedLocally(newxmin, newxmax, newymin, newymax, this);
|
|
|
|
minSize=QSize(plotter->get_iplotBorderLeft()+plotter->get_iplotBorderRight()+10, plotter->get_iplotBorderTop()+plotter->get_iplotBorderBottom()+10);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::intBeforePlotScalingRecalculate() {
|
2015-07-11 18:56:02 +08:00
|
|
|
emit beforePlotScalingRecalculate();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::reactGraphVisible(bool visible)
|
2018-08-20 00:17:18 +08:00
|
|
|
{
|
|
|
|
QAction* act=dynamic_cast<QAction*>(sender());
|
|
|
|
if (act) {
|
|
|
|
get_plotter()->setGraphVisible(act->data().toInt(), visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::set_zoomByMouseRectangle(bool zomByrectangle) {
|
|
|
|
if (zomByrectangle) mouseActionMode=JKQTPlotter::ZoomRectangle;
|
|
|
|
else mouseActionMode=JKQTPlotter::NoMouseAction;
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::set_menuSpecialContextMenu(QMenu *menu)
|
2015-10-12 23:05:15 +08:00
|
|
|
{
|
|
|
|
menuSpecialContextMenu=menu;
|
|
|
|
if (menuSpecialContextMenu) {
|
|
|
|
menuSpecialContextMenu->setParent(this);
|
|
|
|
menuSpecialContextMenu->close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::setMagnification(double m)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
magnification=m;
|
|
|
|
update_plot();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
bool JKQTPlotter::get_zoomByMouseRectangle() const {
|
|
|
|
return (mouseActionMode==JKQTPlotter::ZoomRectangle);
|
2015-07-11 18:56:02 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::modifyContextMenu(QMenu * /*menu*/)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::populateToolbar(QToolBar *toolbar) const
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
toolbar->addAction(plotter->get_actSaveData());
|
|
|
|
toolbar->addAction(plotter->get_actSavePlot());
|
|
|
|
toolbar->addAction(plotter->get_actPrint());
|
|
|
|
toolbar->addSeparator();
|
|
|
|
toolbar->addAction(plotter->get_actCopyPixelImage());
|
|
|
|
toolbar->addAction(plotter->get_actCopyData());
|
|
|
|
toolbar->addAction(plotter->get_actCopyMatlab());
|
|
|
|
toolbar->addSeparator();
|
|
|
|
toolbar->addAction(plotter->get_actShowPlotData());
|
|
|
|
toolbar->addSeparator();
|
|
|
|
toolbar->addAction(plotter->get_actZoomAll());
|
|
|
|
toolbar->addAction(plotter->get_actZoomIn());
|
|
|
|
toolbar->addAction(plotter->get_actZoomOut());
|
|
|
|
|
|
|
|
if (actions().size()>0) {
|
|
|
|
toolbar->addSeparator();
|
|
|
|
toolbar->addActions(actions());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::setMousePositionLabel(const QString &text)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
customMousePositiontext=text;
|
|
|
|
if (displayCustomMousePosition) update();
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::openContextMenu()
|
2015-10-12 23:05:15 +08:00
|
|
|
{
|
|
|
|
openContextMenu(mouseLastClickX, mouseLastClickY);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::openContextMenu(int x, int y)
|
2015-10-12 23:05:15 +08:00
|
|
|
{
|
|
|
|
//qDebug()<<"openContextMenu("<<x<<y<<contextMenu<<")";
|
|
|
|
mouseContextX=plotter->p2x(x/magnification);
|
|
|
|
mouseContextY=plotter->p2y((y-getPlotYOffset())/magnification);
|
|
|
|
contextMenu->close();
|
|
|
|
initContextMenu();
|
|
|
|
contextMenu->popup(mapToGlobal(QPoint(x,y)));
|
2015-10-14 19:24:10 +08:00
|
|
|
//qDebug()<<" -> "<<mapToGlobal(QPoint(x,y))<<contextMenu->size()<<contextMenu->pos()<<contextMenu->parent();
|
2015-10-12 23:05:15 +08:00
|
|
|
emit contextMenuOpened(mouseContextX, mouseContextY, contextMenu);
|
|
|
|
//qDebug()<<"openContextMenu("<<x<<y<<contextMenu<<") ... DONE";
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::openSpecialContextMenu()
|
2015-10-12 23:05:15 +08:00
|
|
|
{
|
|
|
|
openSpecialContextMenu(mouseLastClickX, mouseLastClickY);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::openSpecialContextMenu(int x, int y)
|
2015-10-12 23:05:15 +08:00
|
|
|
{
|
2015-10-14 19:24:10 +08:00
|
|
|
//qDebug()<<"openSpecialContextMenu("<<x<<y<<menuSpecialContextMenu<<")";
|
2015-10-12 23:05:15 +08:00
|
|
|
if (menuSpecialContextMenu) {
|
|
|
|
for (int i=0; i<menuSpecialContextMenu->actions().size(); i++) {
|
2015-10-14 19:24:10 +08:00
|
|
|
//qDebug()<<" - "<<menuSpecialContextMenu->actions().at(i)->text();
|
2015-10-12 23:05:15 +08:00
|
|
|
}
|
|
|
|
mouseContextX=plotter->p2x(x/magnification);
|
|
|
|
mouseContextY=plotter->p2y((y-getPlotYOffset())/magnification);
|
|
|
|
menuSpecialContextMenu->close();
|
|
|
|
menuSpecialContextMenu->popup(mapToGlobal(QPoint(x,y)));
|
|
|
|
menuSpecialContextMenu->resize(menuSpecialContextMenu->sizeHint());
|
2015-10-14 19:24:10 +08:00
|
|
|
//qDebug()<<" -> "<<mapToGlobal(QPoint(x,y))<<menuSpecialContextMenu->size()<<menuSpecialContextMenu->pos()<<menuSpecialContextMenu->parent();
|
2015-10-12 23:05:15 +08:00
|
|
|
emit contextMenuOpened(mouseContextX, mouseContextY, menuSpecialContextMenu);
|
2015-10-14 19:24:10 +08:00
|
|
|
//qDebug()<<"openSpecialContextMenu("<<x<<y<<menuSpecialContextMenu<<") ... DONE";
|
2015-10-12 23:05:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 18:56:02 +08:00
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPlotter::set_doDrawing(bool enable)
|
2015-07-11 18:56:02 +08:00
|
|
|
{
|
|
|
|
doDrawing=enable;
|
|
|
|
plotter->set_emitSignals(enable);
|
|
|
|
//qDebug()<<objectName()<<" doDrawing="<<doDrawing;
|
|
|
|
}
|
|
|
|
|
2018-12-03 01:30:12 +08:00
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void initJKQTPlotterResources()
|
2018-12-03 01:30:12 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
initJKQTBasePlotterResources();
|
2018-12-03 01:30:12 +08:00
|
|
|
}
|