1 /* GNUPLOT - QtGnuplotScene.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 QTGNUPLOTSCENE_H 45 #define QTGNUPLOTSCENE_H 46 47 #define EAM_BOXED_TEXT 1 48 49 #include "QtGnuplotEvent.h" 50 #include "QtGnuplotItems.h" 51 52 #include <QGraphicsScene> 53 #include <QGraphicsItemGroup> 54 #include <QTime> 55 56 class QtGnuplotEnhanced; 57 class QtGnuplotWidget; 58 59 class QtGnuplotScene : public QGraphicsScene, public QtGnuplotEventReceiver 60 { 61 Q_OBJECT 62 63 public: 64 QtGnuplotScene(QtGnuplotEventHandler* eventHandler, QObject* parent = 0); 65 ~QtGnuplotScene(); 66 67 public: 68 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event); 69 virtual void mousePressEvent(QGraphicsSceneMouseEvent* event); 70 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); 71 virtual void wheelEvent(QGraphicsSceneWheelEvent* event); 72 virtual void keyPressEvent(QKeyEvent* event); 73 virtual void keyReleaseEvent(QKeyEvent* event); 74 void processEvent(QtGnuplotEventType type, QDataStream& in); 75 76 private: 77 void resetItems(); 78 void updateModifiers(); 79 void positionText(QGraphicsItem* item, const QPoint& point); 80 void setBrushStyle(int style); 81 void updateRuler(const QPoint& point); 82 void flushCurrentPolygon(); 83 void flushCurrentPointsItem(); 84 QPolygonF& clipPolygon(QPolygonF& polygon, bool checkDiag = true) const; 85 QPointF& clipPoint(QPointF& point) const; 86 QRectF& clipRect(QRectF& point) const; 87 double sceneToGraph(int axis, double coord) const; 88 void update_key_box(const QRectF rect); 89 90 private: 91 QtGnuplotWidget* m_widget; 92 93 QList <QGraphicsItemGroup*> m_plot_group; 94 95 // State variables 96 Qt::Alignment m_textAlignment; 97 QPolygonF m_currentPolygon; 98 QPen m_currentPen; 99 QBrush m_currentBrush; 100 QFont m_font; 101 QPointF m_currentPosition; 102 QPointF m_zoomBoxCorner; 103 double m_currentPointSize; 104 double m_textAngle; 105 double m_currentBoxRotation; 106 QPoint m_currentBoxOrigin; 107 QPoint m_textOffset; 108 double m_currentZ; 109 QTime m_watches[4]; 110 int m_currentPlotNumber; 111 bool m_inKeySample; 112 bool m_preserve_visibility; 113 bool m_inTextBox; 114 int m_currentFillStyle; 115 QRectF m_currentTextBox; 116 QPointF m_textMargin; 117 QList<QGraphicsItem*> m_currentGroup; 118 QtGnuplotPoints* m_currentPointsItem; 119 120 // User events data 121 QPointF m_lastMousePos; 122 int m_lastModifierMask; 123 124 // Special items 125 QGraphicsLineItem* m_horizontalRuler; 126 QGraphicsLineItem* m_verticalRuler; 127 QGraphicsLineItem* m_lineTo; // Line from ruler to cursor 128 QGraphicsRectItem* m_zoomRect; 129 QGraphicsTextItem* m_zoomStartText; 130 QGraphicsTextItem* m_zoomStopText; 131 QtGnuplotEnhanced* m_enhanced; // Current enhanced text block 132 QList<QtGnuplotKeybox> m_key_boxes; 133 QString m_currentHypertext; 134 QList<QGraphicsItem*> m_hypertextList; 135 QGraphicsPixmapItem* m_hyperimage; 136 137 // Axis scales 138 bool m_axisValid[5]; // x, y, x2, y2, z (indicates 3D plot) 139 double m_axisMin [4]; 140 double m_axisLower[4]; 141 double m_axisScale[4]; 142 double m_axisLog [4]; 143 }; 144 145 #endif // QTGNUPLOTSCENE_H 146