File indexing completed on 2024-05-19 15:27:45
0001 /* This file is part of KGraphViewer. 0002 Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KGraphViewer is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; if not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0016 02110-1301, USA 0017 */ 0018 0019 /* This file was callgraphview.h, part of KCachegrind. 0020 Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0021 0022 KCachegrind is free software; you can redistribute it and/or 0023 modify it under the terms of the GNU General Public 0024 License as published by the Free Software Foundation, version 2. 0025 */ 0026 0027 #ifndef CANVAS_EDGE_H 0028 #define CANVAS_EDGE_H 0029 0030 #include <QAbstractGraphicsShapeItem> 0031 #include <QFont> 0032 #include <QGraphicsPathItem> 0033 #include <QGraphicsScene> 0034 #include <QMap> 0035 #include <QWidget> 0036 0037 #include "graphexporter.h" 0038 0039 class QMenu; 0040 0041 struct DotRenderOp; 0042 0043 /* 0044 * Canvas Items: 0045 * - CanvasNode (Rectangular Area) 0046 * - CanvasEdge (Spline curve) 0047 * - CanvasEdgeLabel (Label for edges) 0048 * - CanvasEdgeArrow (Arrows at the end of the edge spline) 0049 */ 0050 namespace KGraphViewer 0051 { 0052 class CanvasNode; 0053 class CanvasEdge; 0054 class GraphEdge; 0055 class DotGraphView; 0056 0057 class CanvasEdge : public QObject, public QAbstractGraphicsShapeItem 0058 { 0059 Q_OBJECT 0060 public: 0061 explicit CanvasEdge(DotGraphView *v, GraphEdge *, qreal scaleX, qreal scaleY, qreal xMargin, qreal yMargin, qreal gh, qreal wdhcf, qreal hdvcf, QGraphicsItem *parent = nullptr); 0062 0063 ~CanvasEdge() override; 0064 0065 QRectF boundingRect() const override; 0066 0067 QPainterPath shape() const override; 0068 0069 void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 0070 0071 inline GraphEdge *edge() 0072 { 0073 return m_edge; 0074 } 0075 inline const GraphEdge *edge() const 0076 { 0077 return m_edge; 0078 } 0079 0080 inline void setGh(qreal gh) 0081 { 0082 m_gh = gh; 0083 } 0084 0085 void computeBoundingRect(); 0086 0087 Q_SIGNALS: 0088 void selected(CanvasEdge *, Qt::KeyboardModifiers); 0089 void edgeContextMenuEvent(const QString &, const QPoint &); 0090 void hoverEnter(CanvasEdge *); 0091 void hoverLeave(CanvasEdge *); 0092 0093 public Q_SLOTS: 0094 void modelChanged(); 0095 void slotRemoveEdge(); 0096 0097 protected: 0098 void mousePressEvent(QGraphicsSceneMouseEvent *event) override; 0099 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; 0100 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; 0101 0102 private: 0103 QPainterPath pathForSpline(int splineNum, const DotRenderOp &dro) const; 0104 qreal distance(const QPointF &point1, const QPointF &point2); 0105 0106 qreal m_scaleX, m_scaleY; 0107 qreal m_xMargin, m_yMargin, m_gh, m_wdhcf, m_hdvcf; 0108 GraphEdge *m_edge; 0109 QRectF m_boundingRect; 0110 QFont *m_font; 0111 DotGraphView *m_view; 0112 QMenu *m_popup; 0113 mutable QPainterPath m_shape; 0114 }; 0115 0116 } 0117 0118 #endif