BCESolve
bcevaluesetplot.hpp
1// This file is part of the BCESolve library for games of incomplete
2// information
3// Copyright (C) 2022 Benjamin A. Brooks
4//
5// BCESolve free software: you can redistribute it and/or modify it
6// under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// BCESolve is distributed in the hope that it will be useful, but
11// WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see
17// <http://www.gnu.org/licenses/>.
18//
19// Benjamin A. Brooks
20// ben@benjaminbrooks.net
21// Chicago, IL
22
23#ifndef BCEVALUESETPLOT_HPP
24#define BCEVALUESETPLOT_HPP
25
26#include <QtWidgets>
27#include "qcustomplot.h"
28
30
37class BCEValueSetPlot : public QCustomPlot {
38 Q_OBJECT;
39
40private:
41
43 QAction *savePNGAction;
45 QAction *savePDFAction;
47 QString path;
48
49public:
50
52 BCEValueSetPlot(): QCustomPlot() {
53
54 setContextMenuPolicy(Qt::CustomContextMenu);
55
56 path = QString("../");
57
58 savePDFAction = new QAction(tr("Save &PDF"), this);
59 savePNGAction = new QAction(tr("Save P&NG"), this);
60
61 connect(this,SIGNAL(mouseMove(QMouseEvent*)),
62 this,SLOT(showPointToolTip(QMouseEvent*)));
63 connect(this,SIGNAL(mousePress(QMouseEvent*)),
64 this,SLOT(getClickCoordinates(QMouseEvent*)));
65 connect(savePDFAction,SIGNAL(triggered()),
66 this,SLOT(savePDF()));
67 connect(savePNGAction,SIGNAL(triggered()),
68 this,SLOT(savePNG()));
69 connect(this,SIGNAL(customContextMenuRequested(const QPoint &)),
70 this,SLOT(ShowContextMenu(const QPoint &)));
71 }
72
73signals:
74
76 void newEqmCoordinates(double x,double y);
77
78public slots:
79
81 void showPointToolTip(QMouseEvent *event) {
82
83 double x = this->xAxis->pixelToCoord(event->pos().x());
84 double y = this->yAxis->pixelToCoord(event->pos().y());
85
86 setToolTip(QString("%1 , %2").arg(x).arg(y));
87 }
88
90 void getClickCoordinates (QMouseEvent *event) {
91
92 double x = this->xAxis->pixelToCoord(event->pos().x());
93 double y = this->yAxis->pixelToCoord(event->pos().y());
94
95 emit(newEqmCoordinates(x,y));
96
97 }
98
99private slots:
100
102
104 void ShowContextMenu(const QPoint & pos)
105 {
106
107 QPoint globalPos = this->mapToGlobal(pos);
108
109 QMenu contextMenu;
110 contextMenu.addAction(savePDFAction);
111 contextMenu.addAction(savePNGAction);
112
113 contextMenu.exec(globalPos);
114 }
115
117 void savePDF()
118 {
119 QString newPath = QFileDialog::getSaveFileName(this, tr("Save PDF"),
120 path, tr("PDF files (*.pdf)"));
121
122 if (newPath.isEmpty())
123 return;
124
125 newPath = newPath + ".pdf";
126 QFileInfo fi(newPath);
127 path = fi.canonicalPath();
128
129 savePdf(newPath);
130 }
131
133 void savePNG()
134 {
135 QString newPath = QFileDialog::getSaveFileName(this, tr("Save PNG"),
136 path, tr("PNG files (*.png)"));
137
138 if (newPath.isEmpty())
139 return;
140
141 newPath = newPath+".png";
142 QFileInfo fi(newPath);
143 path = fi.canonicalPath();
144
145 savePng(newPath);
146 }
147
148};
149
150#endif
QCustomPlot with Tool-tip and click functionality.
Definition: bcevaluesetplot.hpp:37
void getClickCoordinates(QMouseEvent *event)
Gets coordinates of the point where a click is made.
Definition: bcevaluesetplot.hpp:90
QString path
Path to screenshots.
Definition: bcevaluesetplot.hpp:47
void newEqmCoordinates(double x, double y)
Signals new coordinates after the user clicks on the plot.
void ShowContextMenu(const QPoint &pos)
Slot for showing context menu.
Definition: bcevaluesetplot.hpp:104
void savePNG()
Saves graph as a PNG.
Definition: bcevaluesetplot.hpp:133
QAction * savePNGAction
Pointer to QAction for saving PNG files.
Definition: bcevaluesetplot.hpp:38
QAction * savePDFAction
Pointer to QAction for saving PDF files.
Definition: bcevaluesetplot.hpp:45
void showPointToolTip(QMouseEvent *event)
Shows coordinates for point the mouse is hovering over.
Definition: bcevaluesetplot.hpp:81
void savePDF()
Saves graph as a PDF.
Definition: bcevaluesetplot.hpp:117
BCEValueSetPlot()
Constructor.
Definition: bcevaluesetplot.hpp:52