1 /********************************************************************************************** 2 Copyright (C) 2014 Oliver Eichler <oliver.eichler@gmx.de> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program 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 more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 **********************************************************************************************/ 18 19 #ifndef IPLOT_H 20 #define IPLOT_H 21 22 #include "gis/trk/CGisItemTrk.h" 23 #include "mouse/CMouseDummy.h" 24 #include "plot/CPlotData.h" 25 #include <QWidget> 26 27 class QMenu; 28 class CScrOptRangeTrk; 29 30 class IPlot : public QWidget, public INotifyTrk 31 { 32 Q_OBJECT 33 public: 34 enum mode_e {eModeNormal, eModeIcon, eModeWindow, eModeSimple}; 35 enum mouse_click_state_e 36 { 37 eMouseClickIdle 38 , eMouseClick1st 39 , eMouseClick2nd 40 }; 41 42 IPlot(CGisItemTrk* trk, CPlotData::axistype_e type, mode_e mode, QWidget* parent); 43 virtual ~IPlot(); 44 45 void setMouseRangeFocus(const CTrackData::trkpt_t* ptRange1, const CTrackData::trkpt_t* ptRange2) override; setMouseClickFocus(const CTrackData::trkpt_t * pt)46 void setMouseClickFocus(const CTrackData::trkpt_t* pt) override {} 47 48 void save(QImage& image, const CTrackData::trkpt_t* pTrkpt); setSolid(bool yes)49 void setSolid(bool yes) 50 { 51 solid = yes; 52 } 53 54 bool isZoomed() const; 55 56 void clear(); 57 58 using INotifyTrk::setMouseFocus; 59 60 signals: 61 void sigMouseClickState(int); 62 63 private slots: 64 void slotContextMenu(const QPoint& point); 65 void slotSave(); 66 void slotHidePoints(); 67 void slotShowPoints(); 68 void slotActivity(); 69 void slotCopy(); 70 void slotStopRange(); 71 void slotResetZoom(); 72 void slotAddWpt(); 73 void slotCutTrk(); 74 void slotAddTrkPtInfo(); 75 76 77 protected: 78 void setXTicScale(qreal scale); 79 void setYLabel(const QString& str); 80 void setXLabel(const QString& str); 81 void newLine(const QPolygonF& line, const QString& label); 82 void addLine(const QPolygonF& line, const QString& label); 83 void setLimits(); 84 void resetZoom(); 85 86 void paintEvent(QPaintEvent* e) override; 87 void resizeEvent(QResizeEvent* e) override; 88 void leaveEvent(QEvent* e) override; 89 void enterEvent(QEvent* e) override; 90 void keyPressEvent(QKeyEvent* e) override; 91 void mouseMoveEvent(QMouseEvent* e) override; 92 void mousePressEvent(QMouseEvent* e) override; 93 void mouseReleaseEvent(QMouseEvent* e) override; 94 void wheelEvent(QWheelEvent* e) override; 95 96 97 bool mouseReleaseEventSimple(QMouseEvent* e); 98 bool mouseReleaseEventNormal(QMouseEvent* e); 99 100 void setSizes(); 101 void setLRTB(); 102 void setSizeIconArea(); 103 void setSizeXLabel(); 104 void setSizeYLabel(); 105 void setSizeTrackInfo(); 106 void setSizeDrawArea(); 107 108 QPointF getBasePoint(int ptx) const; 109 110 void draw(QPainter& p); 111 void draw(); 112 void drawData(QPainter& p); 113 void drawLabels(QPainter& p); 114 void drawXScale(QPainter& p); 115 void drawYScale(QPainter& p); 116 void drawGridX(QPainter& p); 117 void drawGridY(QPainter& p); 118 void drawXTic(QPainter& p); 119 void drawYTic(QPainter& p); 120 void drawLegend(QPainter& p); 121 void drawDecoration(QPainter& p); 122 void drawTags(QPainter& p); 123 void drawTagLabels(QPainter& p); 124 void drawActivities(QPainter& p); 125 126 bool graphAreaContainsMousePos(QPoint& pos); 127 128 static int cnt; 129 130 // different draw modes 131 mode_e mode; 132 // buffer needs update 133 bool needsRedraw = true; 134 135 bool showWptLabels = false; 136 bool showScale = true; 137 bool thinLine = false; 138 bool solid = false; 139 140 bool mouseDidMove = false; 141 142 QImage buffer; 143 QPoint posMouse1 = NOPOINT; ///< pixel coordinate of mouse in graph area while in focus 144 QPoint posMouse2 = NOPOINT; ///< pixel coordinate of mouse in graph area while in context menu function 145 146 QPoint posLast = NOPOINT; 147 148 /** 149 @brief The track this plot is attached to 150 151 @note It is save to store the pointer to the track item because 152 the plot objects registers/unregisters with the track during 153 construction and destruction. 154 155 See CGisItem::registeredPlots for details. 156 */ 157 CGisItemTrk* trk; 158 CPlotData* data; 159 160 QFontMetrics fm; 161 162 int left = 0; 163 int right = 0; 164 int top = 0; 165 int bottom = 0; 166 167 int deadAreaX = 0; 168 int deadAreaY = 0; 169 170 int fontWidth = 0; 171 int fontHeight = 0; 172 int scaleWidthX1 = 0; 173 int scaleWidthY1 = 0; 174 175 int iconBarHeight = 0; 176 177 QRect rectX1Label; 178 QRect rectY1Label; 179 QRect rectGraphArea; 180 QRect rectIconArea; 181 QRect rectTrackInfo; 182 183 static const QPen pens[]; 184 static const QPen pensThin[]; 185 static const QColor colors[]; 186 187 QMenu* menu; 188 QAction* actionResetZoom; 189 QAction* actionPrint; 190 QAction* actionStopRange; 191 QAction* actionAddWpt; 192 QAction* actionCutTrk; 193 QAction* actionAddTrkPtInfo; 194 195 qint32 idxSel1 = NOIDX; 196 qint32 idxSel2 = NOIDX; 197 198 mouse_click_state_e mouseClickState = eMouseClickIdle; 199 200 QPointer<CScrOptRangeTrk> scrOptRange; 201 202 private: 203 bool setMouseFocus(qreal pos, enum CGisItemTrk::focusmode_e fm); 204 QPolygonF getVisiblePolygon(const QPolygonF& polyline, QPolygonF& line) const; 205 }; 206 207 #endif //IPLOT_H 208 209