1 /* Copyright (c) 2015 Gerald Knizia 2 * 3 * This file is part of the IboView program (see: http://www.iboview.org) 4 * 5 * IboView is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, version 3. 8 * 9 * IboView is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/ 16 * 17 * Please see IboView documentation in README.txt for: 18 * -- A list of included external software and their licenses. The included 19 * external software's copyright is not touched by this agreement. 20 * -- Notes on re-distribution and contributions to/further development of 21 * the IboView software 22 */ 23 24 #ifndef IV_CURVEVIEW_H 25 #define IV_CURVEVIEW_H 26 27 #include "Iv.h" 28 #include <QGraphicsView> 29 #include "CxPodArray.h" 30 #include <vector> 31 32 33 enum FCurveFlags { 34 CURVE_Visible = 0x01, 35 CURVE_Fill = 0x02, 36 CURVE_Outline = 0x04, 37 CURVE_Bold = 0x08, 38 CURVE_Ellipses = 0x10 39 }; 40 41 struct FCurveData { FCurveDataFCurveData42 FCurveData() {} 43 explicit FCurveData(TArray<float> const &Data_, uint32_t Flags_, int zOrder, QPen Stroke_, QBrush Fill_); 44 TArray<float> 45 Data; 46 float GetMin(); 47 float GetMax(); 48 49 QString Title; 50 51 uint32_t Flags; 52 QPen Stroke; 53 QBrush Fill; 54 int zOrder; 55 isVisibleFCurveData56 bool isVisible() const { return 0 != (Flags & CURVE_Visible); } isFilledFCurveData57 bool isFilled() const { return 0 != (Flags & CURVE_Fill); } isOutlinedFCurveData58 bool isOutlined() const { return 0 != (Flags & CURVE_Outline); } isBoldFCurveData59 bool isBold() const { return 0 != (Flags & CURVE_Bold); } 60 }; 61 62 enum FHvLineDataType { 63 HVCURVE_Hline = 0x00, 64 HVCURVE_Vline = 0x01, 65 HVCURVE_TypeMask = 0x01, 66 HVCURVE_StartArrow = 0x02, 67 HVCURVE_EndArrow = 0x04 68 }; 69 70 struct FHvLineData { 71 float 72 fPos; 73 uint32_t 74 Flags; 75 QPen 76 Pen; FHvLineDataFHvLineData77 FHvLineData(float fPos_, uint32_t Flags_, QPen const &Pen_) : fPos(fPos_), Flags(Flags_), Pen(Pen_) {} 78 }; 79 80 class FCurveView : public QGraphicsView 81 { 82 Q_OBJECT 83 84 public: 85 FCurveView(QWidget *parent = 0); 86 ~FCurveView(); 87 typedef QGraphicsView FBase; 88 89 void clearCurves(); 90 void setCurve(unsigned iCurveId, TArray<float> const &Data, QString Title, uint32_t Flags = CURVE_Outline, int zOrder = 0, QPen const &Stroke = QPen(QColor(0xffffffff)), QBrush const &Fill = QBrush()); getNumCurves()91 int getNumCurves() { return (int)m_Curves.size(); } 92 void getCurve(TArray<float> &Data, QString &Title, uint32_t &Flags, QColor &Color, unsigned iCurveId); 93 void addHline(float fPos, QPen const &Pen, uint32_t Flags = 0); 94 void addVline(float fPos, QPen const &Pen, uint32_t Flags = 0); 95 protected: 96 void keyPressEvent(QKeyEvent *event); // override 97 void wheelEvent(QWheelEvent *event); // override 98 void drawBackground(QPainter *painter, const QRectF &rect); // override? 99 void resizeEvent(QResizeEvent *event); 100 101 void mousePressEvent(QMouseEvent *event); 102 void mouseReleaseEvent(QMouseEvent *event); 103 void mouseMoveEvent(QMouseEvent *event); 104 105 void scaleView(qreal scaleFactor); 106 107 std::vector<FCurveData> 108 m_Curves; 109 std::vector<FHvLineData> 110 m_HvLines; 111 QTransform 112 // transform from data space to window space 113 m_TrafoData; 114 115 QRectF getCurveBounds(); 116 void RebuildScene(); 117 private: 118 unsigned LastX, LastY; 119 }; 120 121 122 #endif 123