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 ctrlQ READ ctrlQ WRITE setCtrlQ); 75 Q_PROPERTY(bool replotOnResize READ replotOnResize WRITE setReplotOnResize); 76 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor); 77 Q_PROPERTY(bool statusLabelActive READ statusLabelActive WRITE setStatusLabelActive); 78 79 public: 80 bool isActive() const; 81 void setStatusText(const QString& status); 82 QSize plotAreaSize() const; 83 virtual QSize sizeHint() const; 84 85 signals: 86 void plotDone(); 87 void statusTextChanged(const QString& status); 88 89 public: 90 void processEvent(QtGnuplotEventType type, QDataStream& in); 91 antialias()92 bool antialias() const { return m_antialias; } rounded()93 bool rounded() const { return m_rounded; } ctrlQ()94 bool ctrlQ() const { return m_ctrlQ; } replotOnResize()95 bool replotOnResize() const { return m_replotOnResize; } backgroundColor()96 const QColor& backgroundColor() const { return m_backgroundColor; } statusLabelActive()97 bool statusLabelActive() const { return m_statusLabelActive; } 98 99 void setAntialias(bool value); 100 void setRounded(bool value); 101 void setCtrlQ(bool value); 102 void setReplotOnResize(bool value); 103 void setBackgroundColor(const QColor& color); 104 void setStatusLabelActive(bool active); 105 106 void loadSettings(const QSettings& settings); 107 void saveSettings(QSettings& settings) const; 108 109 public slots: 110 void copyToClipboard(); 111 void print(QPrinter& printer); 112 void exportToPdf(const QString& fileName); 113 void exportToEps(); 114 void exportToImage(const QString& fileName); 115 void exportToSvg(const QString& fileName); 116 117 // Qt functions 118 protected: 119 virtual void resizeEvent(QResizeEvent* event); 120 121 private: 122 void init(); 123 void setViewMatrix(); 124 QPixmap createPixmap(); 125 QPainter::RenderHints renderHints() const; 126 127 private: 128 int m_id; 129 bool m_active; 130 QtGnuplotScene* m_scene; 131 QGraphicsView* m_view; 132 QLabel* m_statusLabel; 133 QSize m_lastSizeRequest; 134 QSize m_sizeHint; 135 // these can be set from the tool widget or from the command line 136 bool m_rounded; 137 bool m_ctrlQ; 138 QColor m_backgroundColor; 139 // Settings 140 bool m_antialias; 141 bool m_replotOnResize; 142 bool m_statusLabelActive; 143 144 static int m_widgetUid; 145 bool m_skipResize; 146 }; 147 148 #endif // QTGNUPLOTWIDGET_H 149