1 /* GNUPLOT - QtGnuplotWidget.h */
2 
3 /*[
4  * Copyright 2009   Jérôme Lodewyck
5  *
6  * Permission to use, copy, and distribute this software and its
7  * documentation for any purpose with or without fee is hereby granted,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.
11  *
12  * Permission to modify the software is granted, but not the right to
13  * distribute the complete modified source code.  Modifications are to
14  * be distributed as patches to the released version.  Permission to
15  * distribute binaries produced by compiling modified sources is granted,
16  * provided you
17  *   1. distribute the corresponding source modifications from the
18  *    released version in the form of a patch file along with the binaries,
19  *   2. add special version identification to distinguish your version
20  *    in addition to the base release version number,
21  *   3. provide your name and address as the primary contact for the
22  *    support of your modified version, and
23  *   4. retain our contact information in regard to use of the base
24  *    software.
25  * Permission to distribute the released version of the source code along
26  * with corresponding source modifications in the form of a patch file is
27  * granted with same provisions 2 through 4 for binary distributions.
28  *
29  * This software is provided "as is" without express or implied warranty
30  * to the extent permitted by applicable law.
31  *
32  *
33  * Alternatively, the contents of this file may be used under the terms of the
34  * GNU General Public License Version 2 or later (the "GPL"), in which case the
35  * provisions of GPL are applicable instead of those above. If you wish to allow
36  * use of your version of this file only under the terms of the GPL and not
37  * to allow others to use your version of this file under the above gnuplot
38  * license, indicate your decision by deleting the provisions above and replace
39  * them with the notice and other provisions required by the GPL. If you do not
40  * delete the provisions above, a recipient may use your version of this file
41  * under either the GPL or the gnuplot license.
42 ]*/
43 
44 #ifndef QTGNUPLOTWIDGET_H
45 #define QTGNUPLOTWIDGET_H
46 
47 #include "QtGnuplotEvent.h"
48 
49 #include <QWidget>
50 #include <QPainter>
51 
52 /* I had to add these in order to link against qt5 rather than qt4 */
53 #if QT_VERSION >= 0x050000
54 #include <QtWidgets>
55 #include <QtPrintSupport/QPrinter>
56 #include <QtPrintSupport/QPrintDialog>
57 #endif
58 
59 class QtGnuplotScene;
60 class QGraphicsView;
61 class QSettings;
62 class QLabel;
63 
64 class QtGnuplotWidget : public QWidget, public QtGnuplotEventReceiver
65 {
66 Q_OBJECT
67 
68 public:
69 	QtGnuplotWidget(QWidget* parent);
70 	QtGnuplotWidget(int id = 0, QtGnuplotEventHandler* eventHandler = 0, QWidget* parent = 0);
71 
72 	Q_PROPERTY(bool antialias READ antialias WRITE setAntialias);
73 	Q_PROPERTY(bool rounded READ rounded WRITE setRounded);
74 	Q_PROPERTY(bool replotOnResize READ replotOnResize WRITE setReplotOnResize);
75 	Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor);
76 	Q_PROPERTY(bool statusLabelActive READ statusLabelActive WRITE setStatusLabelActive);
77 
78 public:
79 	bool isActive() const;
80 	void setStatusText(const QString& status);
81 	QSize plotAreaSize() const;
82 	virtual QSize sizeHint() const;
83 
84 signals:
85 	void plotDone();
86 	void statusTextChanged(const QString& status);
87 
88 public:
89 	void processEvent(QtGnuplotEventType type, QDataStream& in);
90 
antialias()91 	bool antialias() const { return m_antialias; }
rounded()92 	bool rounded() const { return m_rounded; }
replotOnResize()93 	bool replotOnResize() const { return m_replotOnResize; }
backgroundColor()94 	const QColor& backgroundColor() const { return m_backgroundColor; }
statusLabelActive()95 	bool statusLabelActive() const { return m_statusLabelActive; }
96 
97 	void setAntialias(bool value);
98 	void setRounded(bool value);
99 	void setReplotOnResize(bool value);
100 	void setBackgroundColor(const QColor& color);
101 	void setStatusLabelActive(bool active);
102 
103 	void loadSettings(const QSettings& settings);
104 	void saveSettings(QSettings& settings) const;
105 
106 public slots:
107 	void copyToClipboard();
108 	void print(QPrinter& printer);
109 	void exportToPdf(const QString& fileName);
110 	void exportToEps();
111 	void exportToImage(const QString& fileName);
112 	void exportToSvg(const QString& fileName);
113 
114 // Qt functions
115 protected:
116 	virtual void resizeEvent(QResizeEvent* event);
117 
118 private:
119 	void init();
120 	void setViewMatrix();
121 	QPixmap createPixmap();
122 	QPainter::RenderHints renderHints() const;
123 
124 private:
125 	int m_id;
126 	bool m_active;
127 	QtGnuplotScene* m_scene;
128 	QGraphicsView* m_view;
129 	QLabel* m_statusLabel;
130 	QSize m_lastSizeRequest;
131 	QSize m_sizeHint;
132 	// these can be set from the tool widget or from the command line
133 	bool m_rounded;
134 	QColor m_backgroundColor;
135 	// Settings
136 	bool m_antialias;
137 	bool m_replotOnResize;
138 	bool m_statusLabelActive;
139 
140 	static int m_widgetUid;
141 	bool m_skipResize;
142 };
143 
144 #endif // QTGNUPLOTWIDGET_H
145