Changeset View
Changeset View
Standalone View
Standalone View
src/part/canvasedge.cpp
Show All 18 Lines | |||||
19 | /* This file was callgraphview.cpp, part of KCachegrind. | 19 | /* This file was callgraphview.cpp, part of KCachegrind. | ||
20 | Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | 20 | Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | ||
21 | 21 | | |||
22 | KCachegrind is free software; you can redistribute it and/or | 22 | KCachegrind is free software; you can redistribute it and/or | ||
23 | modify it under the terms of the GNU General Public | 23 | modify it under the terms of the GNU General Public | ||
24 | License as published by the Free Software Foundation, version 2. | 24 | License as published by the Free Software Foundation, version 2. | ||
25 | */ | 25 | */ | ||
26 | 26 | | |||
27 | | ||||
28 | #include "canvasedge.h" | 27 | #include "canvasedge.h" | ||
29 | #include "graphedge.h" | 28 | #include "FontsCache.h" | ||
30 | #include "graphnode.h" | | |||
31 | #include "dotdefaults.h" | | |||
32 | #include "dot2qtconsts.h" | 29 | #include "dot2qtconsts.h" | ||
30 | #include "dotdefaults.h" | ||||
33 | #include "dotgraphview.h" | 31 | #include "dotgraphview.h" | ||
34 | #include "FontsCache.h" | 32 | #include "graphedge.h" | ||
33 | #include "graphnode.h" | ||||
35 | #include "kgraphviewerlib_debug.h" | 34 | #include "kgraphviewerlib_debug.h" | ||
36 | 35 | | |||
37 | #include <QAction> | 36 | #include <QAction> | ||
38 | 37 | | |||
39 | #include <QPainter> | | |||
40 | #include <QGraphicsSceneMouseEvent> | 38 | #include <QGraphicsSceneMouseEvent> | ||
41 | #include <QMenu> | 39 | #include <QMenu> | ||
40 | #include <QPainter> | ||||
42 | 41 | | |||
43 | #include <klocalizedstring.h> | 42 | #include <klocalizedstring.h> | ||
44 | 43 | | |||
45 | #include <iostream> | 44 | #include <iostream> | ||
46 | 45 | | |||
47 | // | 46 | // | ||
48 | // CanvasEdge | 47 | // CanvasEdge | ||
49 | // | 48 | // | ||
50 | 49 | | |||
51 | namespace KGraphViewer | 50 | namespace KGraphViewer { | ||
52 | { | | |||
53 | 51 | | |||
54 | CanvasEdge::CanvasEdge(DotGraphView* view, GraphEdge* e, | 52 | CanvasEdge::CanvasEdge(DotGraphView *view, GraphEdge *e, qreal scaleX, | ||
55 | qreal scaleX, qreal scaleY, | 53 | qreal scaleY, qreal xMargin, qreal yMargin, qreal gh, | ||
56 | qreal xMargin, qreal yMargin, qreal gh, | 54 | qreal wdhcf, qreal hdvcf, QGraphicsItem *parent) | ||
57 | qreal wdhcf, qreal hdvcf, | 55 | : QAbstractGraphicsShapeItem(parent), m_scaleX(scaleX), m_scaleY(scaleY), | ||
58 | QGraphicsItem* parent) | 56 | m_xMargin(xMargin), m_yMargin(yMargin), m_gh(/*gh*/ 0), m_wdhcf(wdhcf), | ||
59 | : QAbstractGraphicsShapeItem(parent), | 57 | m_hdvcf(hdvcf), m_edge(e), m_font(nullptr), m_view(view), | ||
60 | m_scaleX(scaleX), m_scaleY(scaleY), | 58 | m_popup(new QMenu()) { | ||
61 | m_xMargin(xMargin), m_yMargin(yMargin), | | |||
62 | m_gh(/*gh*/0), m_wdhcf(wdhcf), m_hdvcf(hdvcf), m_edge(e), | | |||
63 | m_font(nullptr), m_view(view), m_popup(new QMenu()) | | |||
64 | { | | |||
65 | Q_UNUSED(gh); | 59 | Q_UNUSED(gh); | ||
66 | qCDebug(KGRAPHVIEWERLIB_LOG) << "edge " << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << m_gh; | 60 | qCDebug(KGRAPHVIEWERLIB_LOG) << "edge " << edge()->fromNode()->id() << "->" | ||
61 | << edge()->toNode()->id() << m_gh; | ||||
67 | setBoundingRegionGranularity(0.9); | 62 | setBoundingRegionGranularity(0.9); | ||
68 | m_font = FontsCache::changeable().fromName(e->fontName()); | 63 | m_font = FontsCache::changeable().fromName(e->fontName()); | ||
69 | 64 | | |||
70 | computeBoundingRect(); | 65 | computeBoundingRect(); | ||
71 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "boundingRect computed: " << m_boundingRect; | 66 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "boundingRect computed: " << | ||
67 | // m_boundingRect; | ||||
72 | 68 | | |||
73 | QString tipStr = i18n("%1 -> %2\nlabel='%3'", | 69 | QString tipStr = i18n("%1 -> %2\nlabel='%3'", edge()->fromNode()->id(), | ||
74 | edge()->fromNode()->id(),edge()->toNode()->id(),e->label()); | 70 | edge()->toNode()->id(), e->label()); | ||
75 | setToolTip(tipStr); | 71 | setToolTip(tipStr); | ||
76 | 72 | | |||
77 | // the message should be given (or possible to be given) by the part user | 73 | // the message should be given (or possible to be given) by the part user | ||
78 | QAction* removeEdgeAction = new QAction(i18n("Remove selected edge(s)"), this); | 74 | QAction *removeEdgeAction = | ||
75 | new QAction(i18n("Remove selected edge(s)"), this); | ||||
79 | m_popup->addAction(removeEdgeAction); | 76 | m_popup->addAction(removeEdgeAction); | ||
80 | connect(removeEdgeAction, &QAction::triggered, | 77 | connect(removeEdgeAction, &QAction::triggered, this, | ||
81 | this, &CanvasEdge::slotRemoveEdge); | 78 | &CanvasEdge::slotRemoveEdge); | ||
82 | | ||||
83 | 79 | | |||
84 | connect(e, &GraphEdge::changed, | 80 | connect(e, &GraphEdge::changed, this, &CanvasEdge::modelChanged); | ||
85 | this, &CanvasEdge::modelChanged); | 81 | connect(this, &CanvasEdge::selected, view, &DotGraphView::slotEdgeSelected); | ||
86 | connect(this, &CanvasEdge::selected, | | |||
87 | view, &DotGraphView::slotEdgeSelected); | | |||
88 | 82 | | |||
89 | connect(this, &CanvasEdge::edgeContextMenuEvent, | 83 | connect(this, &CanvasEdge::edgeContextMenuEvent, view, | ||
90 | view, &DotGraphView::slotContextMenuEvent); | 84 | &DotGraphView::slotContextMenuEvent); | ||
91 | 85 | | |||
92 | setAcceptHoverEvents ( true ); | 86 | setAcceptHoverEvents(true); | ||
93 | 87 | | |||
94 | qCDebug(KGRAPHVIEWERLIB_LOG) << "connect slotElementHoverEnter"; | 88 | qCDebug(KGRAPHVIEWERLIB_LOG) << "connect slotElementHoverEnter"; | ||
95 | connect(this, &CanvasEdge::hoverEnter, | 89 | connect(this, &CanvasEdge::hoverEnter, view, | ||
96 | view, static_cast<void(DotGraphView::*)(CanvasEdge*)>(&DotGraphView::slotElementHoverEnter)); | 90 | static_cast<void (DotGraphView::*)(CanvasEdge *)>( | ||
97 | connect(this, &CanvasEdge::hoverLeave, | 91 | &DotGraphView::slotElementHoverEnter)); | ||
98 | view, static_cast<void(DotGraphView::*)(CanvasEdge*)>(&DotGraphView::slotElementHoverLeave)); | 92 | connect(this, &CanvasEdge::hoverLeave, view, | ||
93 | static_cast<void (DotGraphView::*)(CanvasEdge *)>( | ||||
94 | &DotGraphView::slotElementHoverLeave)); | ||||
99 | } | 95 | } | ||
100 | 96 | | |||
101 | CanvasEdge::~CanvasEdge() | 97 | CanvasEdge::~CanvasEdge() { delete m_popup; } | ||
102 | { | | |||
103 | delete m_popup; | | |||
104 | } | | |||
105 | 98 | | |||
99 | QRectF CanvasEdge::boundingRect() const { return m_boundingRect; } | ||||
106 | 100 | | |||
107 | QRectF CanvasEdge::boundingRect() const | 101 | QPainterPath CanvasEdge::shape() const { | ||
108 | { | 102 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << | ||
109 | return m_boundingRect; | 103 | // edge()->toNode()->id(); | ||
110 | } | | |||
111 | | ||||
112 | QPainterPath CanvasEdge::shape () const | | |||
113 | { | | |||
114 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id(); | | |||
115 | 104 | | |||
116 | if (!m_shape.isEmpty()) { | 105 | if (!m_shape.isEmpty()) { | ||
117 | return m_shape; | 106 | return m_shape; | ||
118 | } | 107 | } | ||
119 | 108 | | |||
120 | foreach (const DotRenderOp& dro, edge()->renderOperations()) | 109 | foreach (const DotRenderOp &dro, edge()->renderOperations()) { | ||
121 | { | 110 | if (dro.renderop == "B") { | ||
122 | if ( dro.renderop == "B" ) | 111 | for (int splineNum = 0; | ||
123 | { | 112 | splineNum < edge()->colors().count() || | ||
124 | for (int splineNum = 0; splineNum < edge()->colors().count() || (splineNum==0 && edge()->colors().count()==0); splineNum++) | 113 | (splineNum == 0 && edge()->colors().count() == 0); | ||
125 | { | 114 | splineNum++) { | ||
126 | m_shape.addPath(pathForSpline(splineNum, dro)); | 115 | m_shape.addPath(pathForSpline(splineNum, dro)); | ||
127 | } | 116 | } | ||
128 | } | 117 | } | ||
129 | } | 118 | } | ||
130 | return m_shape; | 119 | return m_shape; | ||
131 | } | 120 | } | ||
132 | 121 | | |||
133 | QPainterPath CanvasEdge::pathForSpline(int splineNum, const DotRenderOp& dro) const | 122 | QPainterPath CanvasEdge::pathForSpline(int splineNum, | ||
134 | { | 123 | const DotRenderOp &dro) const { | ||
135 | QPolygonF points(dro.integers[0]); | 124 | QPolygonF points(dro.integers[0]); | ||
136 | for (int i = 0; i < dro.integers[0]; i++) | 125 | for (int i = 0; i < dro.integers[0]; i++) { | ||
137 | { | | |||
138 | // computing of diffX and diffY to draw parallel edges | 126 | // computing of diffX and diffY to draw parallel edges | ||
139 | // when asked through the corresponding Graphviz feature | 127 | // when asked through the corresponding Graphviz feature | ||
140 | qreal nom = (dro.integers[2*dro.integers[0]]-dro.integers[2]); | 128 | qreal nom = (dro.integers[2 * dro.integers[0]] - dro.integers[2]); | ||
141 | qreal denom = (dro.integers[2*dro.integers[0]-1]-dro.integers[1]); | 129 | qreal denom = (dro.integers[2 * dro.integers[0] - 1] - dro.integers[1]); | ||
142 | qreal diffX, diffY; | 130 | qreal diffX, diffY; | ||
143 | if (nom == 0) | 131 | if (nom == 0) { | ||
144 | { | | |||
145 | diffX = 0; | 132 | diffX = 0; | ||
146 | diffY = 2*(edge()->colors().count()/2 - splineNum); | 133 | diffY = 2 * (edge()->colors().count() / 2 - splineNum); | ||
147 | } | 134 | } else if (denom == 0) { | ||
148 | else if (denom ==0) | | |||
149 | { | | |||
150 | diffX = 2*(edge()->colors().count()/2 - splineNum); | 135 | diffX = 2 * (edge()->colors().count() / 2 - splineNum); | ||
151 | diffY = 0; | 136 | diffY = 0; | ||
152 | } | 137 | } else { | ||
153 | else | | |||
154 | { | | |||
155 | double pente = nom/denom; | 138 | double pente = nom / denom; | ||
156 | if (pente < 0) | 139 | if (pente < 0) { | ||
157 | { | | |||
158 | diffX = 2*(edge()->colors().count()/2 - splineNum); | 140 | diffX = 2 * (edge()->colors().count() / 2 - splineNum); | ||
159 | diffY = edge()->colors().count()/2 + splineNum; | 141 | diffY = edge()->colors().count() / 2 + splineNum; | ||
160 | } | 142 | } else { | ||
161 | else | | |||
162 | { | | |||
163 | diffX = 2*(edge()->colors().count()/2 - splineNum); | 143 | diffX = 2 * (edge()->colors().count() / 2 - splineNum); | ||
164 | diffY = 2*(edge()->colors().count()/2 - splineNum); | 144 | diffY = 2 * (edge()->colors().count() / 2 - splineNum); | ||
165 | } | 145 | } | ||
166 | } | 146 | } | ||
167 | QPointF p( | 147 | QPointF p((dro.integers[2 * i + 1] /*%m_wdhcf*/ * m_scaleX) + | ||
168 | (dro.integers[2*i+1]/*%m_wdhcf*/*m_scaleX) +m_xMargin + diffX, | 148 | m_xMargin + diffX, | ||
169 | (m_gh-dro.integers[2*i+2]/*%m_hdvcf*/)*m_scaleY + m_yMargin + diffY | 149 | (m_gh - dro.integers[2 * i + 2] /*%m_hdvcf*/) * m_scaleY + | ||
170 | ); | 150 | m_yMargin + diffY); | ||
171 | points[i] = p; | 151 | points[i] = p; | ||
172 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << p; | 152 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" | ||
153 | // << edge()->toNode()->id() << p; | ||||
173 | } | 154 | } | ||
174 | 155 | | |||
175 | QPainterPath path; | 156 | QPainterPath path; | ||
176 | path.moveTo(points[0]); | 157 | path.moveTo(points[0]); | ||
177 | for (int j = 0; j < (points.size()-1)/3; j++) | 158 | for (int j = 0; j < (points.size() - 1) / 3; j++) { | ||
178 | { | 159 | path.cubicTo(points[3 * j + 1], points[3 * j + 1 + 1], | ||
179 | path.cubicTo(points[3*j + 1],points[3*j+1 + 1], points[3*j+2 + 1]); | 160 | points[3 * j + 2 + 1]); | ||
180 | } | 161 | } | ||
181 | return path; | 162 | return path; | ||
182 | } | 163 | } | ||
183 | 164 | | |||
184 | | ||||
185 | void CanvasEdge::paint(QPainter* p, const QStyleOptionGraphicsItem* option, | 165 | void CanvasEdge::paint(QPainter *p, const QStyleOptionGraphicsItem *option, | ||
186 | QWidget* widget) | 166 | QWidget *widget) { | ||
187 | { | | |||
188 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 167 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
189 | Q_UNUSED(option) | 168 | Q_UNUSED(option) | ||
190 | Q_UNUSED(widget) | 169 | Q_UNUSED(widget) | ||
191 | if (m_boundingRect == QRectF()) | 170 | if (m_boundingRect == QRectF()) { | ||
192 | { | | |||
193 | return; | 171 | return; | ||
194 | } | 172 | } | ||
195 | /// computes the scaling of line width | 173 | /// computes the scaling of line width | ||
196 | qreal widthScaleFactor = (m_scaleX+m_scaleY)/2; | 174 | qreal widthScaleFactor = (m_scaleX + m_scaleY) / 2; | ||
197 | if (widthScaleFactor < 1) | 175 | if (widthScaleFactor < 1) { | ||
198 | { | | |||
199 | widthScaleFactor = 1; | 176 | widthScaleFactor = 1; | ||
200 | } | 177 | } | ||
201 | 178 | | |||
202 | if (edge()->style()=="invis") | 179 | if (edge()->style() == "invis") { | ||
203 | { | | |||
204 | return; | 180 | return; | ||
205 | } | 181 | } | ||
206 | if (edge()->renderOperations().isEmpty()) | 182 | if (edge()->renderOperations().isEmpty()) { | ||
207 | { | 183 | if ((edge()->fromNode()->canvasElement()) && | ||
208 | if ((edge()->fromNode()->canvasElement()) | 184 | (edge()->toNode()->canvasElement())) { | ||
209 | && (edge()->toNode()->canvasElement())) | | |||
210 | { | | |||
211 | p->drawLine( | 185 | p->drawLine( | ||
212 | edge()->fromNode()->canvasElement()->boundingRect().center()+edge()->fromNode()->canvasElement()->pos(), | 186 | edge()->fromNode()->canvasElement()->boundingRect().center() + | ||
213 | edge()->toNode()->canvasElement()->boundingRect().center()+edge()->toNode()->canvasElement()->pos()); | 187 | edge()->fromNode()->canvasElement()->pos(), | ||
188 | edge()->toNode()->canvasElement()->boundingRect().center() + | ||||
189 | edge()->toNode()->canvasElement()->pos()); | ||||
214 | } | 190 | } | ||
215 | return; | 191 | return; | ||
216 | } | 192 | } | ||
217 | 193 | | |||
218 | QColor lineColor = Dot2QtConsts::componentData().qtColor(edge()->color(0)); | 194 | QColor lineColor = Dot2QtConsts::componentData().qtColor(edge()->color(0)); | ||
219 | QColor backColor; | 195 | QColor backColor; | ||
220 | 196 | | |||
221 | QList<QPointF> allPoints; | 197 | QList<QPointF> allPoints; | ||
222 | 198 | | |||
223 | const QFont oldFont = p->font(); | 199 | const QFont oldFont = p->font(); | ||
224 | const QPen oldPen = p->pen(); | 200 | const QPen oldPen = p->pen(); | ||
225 | const QBrush oldBrush = p->brush(); | 201 | const QBrush oldBrush = p->brush(); | ||
226 | 202 | | |||
227 | foreach (const DotRenderOp& dro, edge()->renderOperations()) | 203 | foreach (const DotRenderOp &dro, edge()->renderOperations()) { | ||
228 | { | 204 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" | ||
229 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "renderop" << dro.renderop << "; selected:" << edge()->isSelected(); | 205 | // << edge()->toNode()->id() << "renderop" << dro.renderop << "; | ||
230 | if (dro.renderop == "c") | 206 | // selected:" | ||
231 | { | 207 | // << edge()->isSelected(); | ||
208 | if (dro.renderop == "c") { | ||||
232 | QColor c(dro.str.mid(0,7)); | 209 | QColor c(dro.str.mid(0, 7)); | ||
233 | bool ok; | 210 | bool ok; | ||
234 | c.setAlpha(255-dro.str.mid(8).toInt(&ok,16)); | 211 | c.setAlpha(255 - dro.str.mid(8).toInt(&ok, 16)); | ||
235 | lineColor = c; | 212 | lineColor = c; | ||
236 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "c" << dro.str.mid(0,7) << lineColor; | 213 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "c" << dro.str.mid(0,7) << | ||
237 | } | 214 | // lineColor; | ||
238 | else if (dro.renderop == "C") | 215 | } else if (dro.renderop == "C") { | ||
239 | { | | |||
240 | QColor c(dro.str.mid(0,7)); | 216 | QColor c(dro.str.mid(0, 7)); | ||
241 | bool ok; | 217 | bool ok; | ||
242 | c.setAlpha(255-dro.str.mid(8).toInt(&ok,16)); | 218 | c.setAlpha(255 - dro.str.mid(8).toInt(&ok, 16)); | ||
243 | /* if (m_hovered && m_view->highlighting()) | 219 | /* if (m_hovered && m_view->highlighting()) | ||
244 | { | 220 | { | ||
245 | c = c.lighter(); | 221 | c = c.lighter(); | ||
246 | }*/ | 222 | }*/ | ||
247 | backColor = c; | 223 | backColor = c; | ||
248 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "C" << dro.str.mid(0,7) << backColor; | 224 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "C" << dro.str.mid(0,7) << | ||
249 | } | 225 | // backColor; | ||
250 | else if ( dro.renderop == "T" ) | 226 | } else if (dro.renderop == "T") { | ||
251 | { | | |||
252 | const QString& str = dro.str; | 227 | const QString &str = dro.str; | ||
253 | 228 | | |||
254 | qreal stringWidthGoal = dro.integers[3] * m_scaleX; | 229 | qreal stringWidthGoal = dro.integers[3] * m_scaleX; | ||
255 | int fontSize = edge()->fontSize(); | 230 | int fontSize = edge()->fontSize(); | ||
256 | m_font->setPointSize(fontSize); | 231 | m_font->setPointSize(fontSize); | ||
257 | QFontMetrics fm(*m_font); | 232 | QFontMetrics fm(*m_font); | ||
258 | while (fm.width(str) > stringWidthGoal && fontSize > 1) | 233 | while (fm.width(str) > stringWidthGoal && fontSize > 1) { | ||
259 | { | | |||
260 | fontSize--; | 234 | fontSize--; | ||
261 | m_font->setPointSize(fontSize); | 235 | m_font->setPointSize(fontSize); | ||
262 | fm = QFontMetrics(*m_font); | 236 | fm = QFontMetrics(*m_font); | ||
263 | } | 237 | } | ||
264 | 238 | | |||
265 | p->setFont(*m_font); | 239 | p->setFont(*m_font); | ||
266 | 240 | | |||
267 | p->setPen(Dot2QtConsts::componentData().qtColor(edge()->fontColor())); | 241 | p->setPen( | ||
242 | Dot2QtConsts::componentData().qtColor(edge()->fontColor())); | ||||
268 | 243 | | |||
269 | qreal x = (m_scaleX * | 244 | qreal x = | ||
270 | ( | 245 | (m_scaleX * ((dro.integers[0]) + | ||
271 | (dro.integers[0]) | 246 | (((-dro.integers[2]) * (fm.width(dro.str))) / 2) - | ||
272 | + (((-dro.integers[2])*(fm.width(dro.str)))/2) | 247 | ((fm.width(dro.str)) / 2))) + | ||
273 | - ( (fm.width(dro.str))/2 ) | 248 | m_xMargin; | ||
274 | ) | | |||
275 | ) | | |||
276 | + m_xMargin; | | |||
277 | qreal y = ((m_gh - (dro.integers[1]))*m_scaleY)+ m_yMargin; | 249 | qreal y = ((m_gh - (dro.integers[1])) * m_scaleY) + m_yMargin; | ||
278 | QPointF point(x,y); | 250 | QPointF point(x, y); | ||
279 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "drawText" << edge()->fontColor() << point; | 251 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << | ||
252 | // "->" | ||||
253 | // << edge()->toNode()->id() << "drawText" << | ||||
254 | // edge()->fontColor() << point; | ||||
280 | 255 | | |||
281 | p->drawText(point,str); | 256 | p->drawText(point, str); | ||
282 | 257 | | |||
283 | p->setFont(oldFont); | 258 | p->setFont(oldFont); | ||
284 | p->setPen(oldPen); | 259 | p->setPen(oldPen); | ||
285 | } | 260 | } else if ((dro.renderop == "p") || (dro.renderop == "P")) { | ||
286 | else if (( dro.renderop == "p" ) || (dro.renderop == "P" )) | | |||
287 | { | | |||
288 | QPolygonF polygon(dro.integers[0]); | 261 | QPolygonF polygon(dro.integers[0]); | ||
289 | for (int i = 0; i < dro.integers[0]; i++) | 262 | for (int i = 0; i < dro.integers[0]; i++) { | ||
290 | { | | |||
291 | QPointF point( | 263 | QPointF point( | ||
292 | (int(dro.integers[2*i+1])/*%m_wdhcf*/)*m_scaleX +m_xMargin, | 264 | (int(dro.integers[2 * i + 1]) /*%m_wdhcf*/) * m_scaleX + | ||
293 | (int(m_gh-dro.integers[2*i+2])/*%m_hdvcf*/)*m_scaleY + m_yMargin | 265 | m_xMargin, | ||
294 | ); | 266 | (int(m_gh - dro.integers[2 * i + 2]) /*%m_hdvcf*/) * | ||
267 | m_scaleY + | ||||
268 | m_yMargin); | ||||
295 | polygon[i] = point; | 269 | polygon[i] = point; | ||
296 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << point; | 270 | // qCDebug(KGRAPHVIEWERLIB_LOG) << | ||
271 | // edge()->fromNode()->id() << | ||||
272 | // "->" << edge()->toNode()->id() << point; | ||||
297 | allPoints.append(point); | 273 | allPoints.append(point); | ||
298 | } | 274 | } | ||
299 | if (dro.renderop == "P" ) | 275 | if (dro.renderop == "P") { | ||
300 | { | | |||
301 | p->setBrush(lineColor); | 276 | p->setBrush(lineColor); | ||
302 | p->drawPolygon(polygon); | 277 | p->drawPolygon(polygon); | ||
303 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "drawPolygon" << edge()->color(0) << polygon; | 278 | // qCDebug(KGRAPHVIEWERLIB_LOG) << | ||
279 | // edge()->fromNode()->id() << | ||||
280 | // "->" << edge()->toNode()->id() << "drawPolygon" << | ||||
281 | // edge()->color(0) << polygon; | ||||
304 | p->setBrush(oldBrush); | 282 | p->setBrush(oldBrush); | ||
305 | } | 283 | } else { | ||
306 | else | | |||
307 | { | | |||
308 | p->setBrush(Dot2QtConsts::componentData().qtColor("white")); | 284 | p->setBrush(Dot2QtConsts::componentData().qtColor("white")); | ||
309 | } | 285 | } | ||
310 | QPen pen(lineColor); | 286 | QPen pen(lineColor); | ||
311 | if (edge()->style() == "bold") | 287 | if (edge()->style() == "bold") { | ||
312 | { | | |||
313 | pen.setStyle(Qt::SolidLine); | 288 | pen.setStyle(Qt::SolidLine); | ||
314 | pen.setWidth((int)(2 * widthScaleFactor)); | 289 | pen.setWidth((int)(2 * widthScaleFactor)); | ||
315 | } | 290 | } else { | ||
316 | else | | |||
317 | { | | |||
318 | pen.setWidth((int)(1 * widthScaleFactor)); | 291 | pen.setWidth((int)(1 * widthScaleFactor)); | ||
319 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(edge()->style())); | 292 | pen.setStyle( | ||
293 | Dot2QtConsts::componentData().qtPenStyle(edge()->style())); | ||||
320 | } | 294 | } | ||
321 | p->setPen(pen); | 295 | p->setPen(pen); | ||
322 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "drawPolyline" << edge()->color(0) << polygon; | 296 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << | ||
297 | // "->" | ||||
298 | // << edge()->toNode()->id() << "drawPolyline" << | ||||
299 | // edge()->color(0) | ||||
300 | // << polygon; | ||||
323 | polygon << polygon[0]; | 301 | polygon << polygon[0]; | ||
324 | p->drawPolyline(polygon); | 302 | p->drawPolyline(polygon); | ||
325 | p->setPen(oldPen); | 303 | p->setPen(oldPen); | ||
326 | p->setBrush(oldBrush); | 304 | p->setBrush(oldBrush); | ||
327 | } | 305 | } else if ((dro.renderop == "e") || (dro.renderop == "E")) { | ||
328 | else if (( dro.renderop == "e" ) || (dro.renderop == "E" )) | | |||
329 | { | | |||
330 | qreal w = m_scaleX * dro.integers[2] * 2; | 306 | qreal w = m_scaleX * dro.integers[2] * 2; | ||
331 | qreal h = m_scaleY * dro.integers[3] * 2; | 307 | qreal h = m_scaleY * dro.integers[3] * 2; | ||
332 | qreal x = (m_xMargin + (dro.integers[0]/*%m_wdhcf*/)*m_scaleX) - w/2; | 308 | qreal x = | ||
333 | qreal y = ((m_gh - dro.integers[1]/*%m_hdvcf*/)*m_scaleY + m_yMargin) - h/2; | 309 | (m_xMargin + (dro.integers[0] /*%m_wdhcf*/) * m_scaleX) - w / 2; | ||
334 | if (dro.renderop == "E" ) | 310 | qreal y = | ||
335 | { | 311 | ((m_gh - dro.integers[1] /*%m_hdvcf*/) * m_scaleY + m_yMargin) - | ||
312 | h / 2; | ||||
313 | if (dro.renderop == "E") { | ||||
336 | p->setBrush(lineColor); | 314 | p->setBrush(lineColor); | ||
337 | } | 315 | } else { | ||
338 | else | | |||
339 | { | | |||
340 | p->setBrush(Dot2QtConsts::componentData().qtColor("white")); | 316 | p->setBrush(Dot2QtConsts::componentData().qtColor("white")); | ||
341 | } | 317 | } | ||
342 | QPen pen(lineColor); | 318 | QPen pen(lineColor); | ||
343 | if (edge()->style() == "bold") | 319 | if (edge()->style() == "bold") { | ||
344 | { | | |||
345 | pen.setStyle(Qt::SolidLine); | 320 | pen.setStyle(Qt::SolidLine); | ||
346 | pen.setWidth(int(2 * widthScaleFactor)); | 321 | pen.setWidth(int(2 * widthScaleFactor)); | ||
347 | } | 322 | } else { | ||
348 | else | | |||
349 | { | | |||
350 | pen.setWidth(int(1 * widthScaleFactor)); | 323 | pen.setWidth(int(1 * widthScaleFactor)); | ||
351 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(edge()->style())); | 324 | pen.setStyle( | ||
325 | Dot2QtConsts::componentData().qtPenStyle(edge()->style())); | ||||
352 | } | 326 | } | ||
353 | p->setPen(pen); | 327 | p->setPen(pen); | ||
354 | QRectF rect(x,y,w,h); | 328 | QRectF rect(x, y, w, h); | ||
355 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "drawEllipse" << edge()->color(0) << rect; | 329 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << | ||
330 | // "->" | ||||
331 | // << edge()->toNode()->id() << "drawEllipse" << | ||||
332 | // edge()->color(0) << rect; | ||||
356 | p->drawEllipse(rect); | 333 | p->drawEllipse(rect); | ||
357 | p->setPen(oldPen); | 334 | p->setPen(oldPen); | ||
358 | p->setBrush(oldBrush); | 335 | p->setBrush(oldBrush); | ||
359 | } | 336 | } else if (dro.renderop == "B") { | ||
360 | else if ( dro.renderop == "B" ) | | |||
361 | { | | |||
362 | uint lineWidth = 1; | 337 | uint lineWidth = 1; | ||
363 | QPen pen; | 338 | QPen pen; | ||
364 | if (edge()->style() == "bold") | 339 | if (edge()->style() == "bold") { | ||
365 | { | | |||
366 | pen.setStyle(Qt::SolidLine); | 340 | pen.setStyle(Qt::SolidLine); | ||
367 | pen.setWidth(int(2 * widthScaleFactor)); | 341 | pen.setWidth(int(2 * widthScaleFactor)); | ||
342 | } else if (edge()->style() != "filled") { | ||||
343 | pen.setStyle( | ||||
344 | Dot2QtConsts::componentData().qtPenStyle(edge()->style())); | ||||
368 | } | 345 | } | ||
369 | else if (edge()->style() != "filled") | 346 | if (edge()->style().left(12) == "setlinewidth") { | ||
370 | { | | |||
371 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(edge()->style())); | | |||
372 | } | | |||
373 | if (edge()->style().left(12) == "setlinewidth") | | |||
374 | { | | |||
375 | bool ok; | 347 | bool ok; | ||
376 | lineWidth = edge()->style().mid(12, edge()->style().length()-1-12).toInt(&ok); | 348 | lineWidth = edge() | ||
349 | ->style() | ||||
350 | .mid(12, edge()->style().length() - 1 - 12) | ||||
351 | .toInt(&ok); | ||||
377 | pen.setWidth(int(lineWidth * widthScaleFactor)); | 352 | pen.setWidth(int(lineWidth * widthScaleFactor)); | ||
378 | } | 353 | } | ||
379 | if (edge()->attributes().contains("penwidth")) | 354 | if (edge()->attributes().contains("penwidth")) { | ||
380 | { | | |||
381 | bool ok; | 355 | bool ok; | ||
382 | lineWidth = edge()->attributes()["penwidth"].toInt(&ok); | 356 | lineWidth = edge()->attributes()["penwidth"].toInt(&ok); | ||
383 | pen.setWidth(int(lineWidth * widthScaleFactor)); | 357 | pen.setWidth(int(lineWidth * widthScaleFactor)); | ||
384 | } | 358 | } | ||
385 | if (edge()->attributes().contains("color")) | 359 | if (edge()->attributes().contains("color")) { | ||
386 | { | 360 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
387 | qCDebug(KGRAPHVIEWERLIB_LOG) << "set edge color to " << QColor(edge()->attributes()["color"]).name(); | 361 | << "set edge color to " | ||
362 | << QColor(edge()->attributes()["color"]).name(); | ||||
388 | lineColor = QColor(edge()->attributes()["color"]); | 363 | lineColor = QColor(edge()->attributes()["color"]); | ||
389 | } | 364 | } | ||
390 | for (int splineNum = 0; splineNum < edge()->colors().count() || (splineNum==0 && edge()->colors().count()==0); splineNum++) | 365 | for (int splineNum = 0; | ||
391 | { | 366 | splineNum < edge()->colors().count() || | ||
367 | (splineNum == 0 && edge()->colors().count() == 0); | ||||
368 | splineNum++) { | ||||
392 | if (splineNum != 0) | 369 | if (splineNum != 0) | ||
393 | lineColor = Dot2QtConsts::componentData().qtColor(edge()->color(splineNum)); | 370 | lineColor = Dot2QtConsts::componentData().qtColor( | ||
371 | edge()->color(splineNum)); | ||||
394 | pen.setColor(lineColor); | 372 | pen.setColor(lineColor); | ||
395 | // p->setBrush(Dot2QtConsts::componentData().qtColor(edge()->color(0))); | 373 | // p->setBrush(Dot2QtConsts::componentData().qtColor(edge()->color(0))); | ||
396 | p->setBrush(Qt::NoBrush); | 374 | p->setBrush(Qt::NoBrush); | ||
397 | p->setPen(pen); | 375 | p->setPen(pen); | ||
398 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "drawPath" << edge()->color(splineNum) << points.first() << points.last(); | 376 | // qCDebug(KGRAPHVIEWERLIB_LOG) << | ||
377 | // edge()->fromNode()->id() << | ||||
378 | // "->" << edge()->toNode()->id() << "drawPath" << | ||||
379 | // edge()->color(splineNum) << points.first() << | ||||
380 | // points.last(); | ||||
399 | p->drawPath(pathForSpline(splineNum, dro)); | 381 | p->drawPath(pathForSpline(splineNum, dro)); | ||
400 | p->setPen(oldPen); | 382 | p->setPen(oldPen); | ||
401 | p->setBrush(oldBrush); | 383 | p->setBrush(oldBrush); | ||
402 | } | 384 | } | ||
403 | } | 385 | } | ||
404 | } | 386 | } | ||
405 | if (edge()->isSelected()) | 387 | if (edge()->isSelected()) { | ||
406 | { | | |||
407 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "draw square"; | 388 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "draw square"; | ||
408 | // p->drawRect(m_boundingRect); | 389 | // p->drawRect(m_boundingRect); | ||
409 | qreal maxDist = 0; | 390 | qreal maxDist = 0; | ||
410 | QPair<QPointF,QPointF> pointsPair; | 391 | QPair<QPointF, QPointF> pointsPair; | ||
411 | foreach(const QPointF& point1, allPoints) | 392 | foreach (const QPointF &point1, allPoints) { | ||
412 | { | 393 | foreach (const QPointF &point2, allPoints) { | ||
413 | foreach(const QPointF& point2, allPoints) | 394 | if (distance(point1, point2) > maxDist) { | ||
414 | { | | |||
415 | if (distance(point1, point2) > maxDist) | | |||
416 | { | | |||
417 | maxDist = distance(point1, point2); | 395 | maxDist = distance(point1, point2); | ||
418 | pointsPair = qMakePair(point1, point2); | 396 | pointsPair = qMakePair(point1, point2); | ||
419 | } | 397 | } | ||
420 | } | 398 | } | ||
421 | } | 399 | } | ||
422 | if (maxDist>0) | 400 | if (maxDist > 0) { | ||
423 | { | | |||
424 | // p->setBrush(Dot2QtConsts::componentData().qtColor(edge()->color(0))); | 401 | // p->setBrush(Dot2QtConsts::componentData().qtColor(edge()->color(0))); | ||
425 | p->setBrush(Qt::black); | 402 | p->setBrush(Qt::black); | ||
426 | p->setPen(Qt::black); | 403 | p->setPen(Qt::black); | ||
427 | p->drawRect(QRectF(pointsPair.first-QPointF(3,3),QSizeF(6,6))); | 404 | p->drawRect(QRectF(pointsPair.first - QPointF(3, 3), QSizeF(6, 6))); | ||
428 | p->drawRect(QRectF(pointsPair.second-QPointF(3,3),QSizeF(6,6))); | 405 | p->drawRect( | ||
406 | QRectF(pointsPair.second - QPointF(3, 3), QSizeF(6, 6))); | ||||
429 | p->setBrush(oldBrush); | 407 | p->setBrush(oldBrush); | ||
430 | p->setPen(oldPen); | 408 | p->setPen(oldPen); | ||
431 | } | 409 | } | ||
432 | } | 410 | } | ||
433 | } | 411 | } | ||
434 | 412 | | |||
435 | void CanvasEdge::modelChanged() | 413 | void CanvasEdge::modelChanged() { | ||
436 | { | 414 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << | ||
437 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id(); | 415 | // edge()->toNode()->id(); | ||
438 | prepareGeometryChange(); | 416 | prepareGeometryChange(); | ||
439 | computeBoundingRect(); | 417 | computeBoundingRect(); | ||
440 | } | 418 | } | ||
441 | 419 | | |||
442 | void CanvasEdge::computeBoundingRect() | 420 | void CanvasEdge::computeBoundingRect() { | ||
443 | { | | |||
444 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 421 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
445 | //invalidate bounding region cache | 422 | // invalidate bounding region cache | ||
446 | m_shape = QPainterPath(); | 423 | m_shape = QPainterPath(); | ||
447 | if (edge()->renderOperations().isEmpty()) | 424 | if (edge()->renderOperations().isEmpty()) { | ||
448 | { | 425 | if ((edge()->fromNode()->canvasElement() == nullptr) || | ||
449 | if ((edge()->fromNode()->canvasElement() == nullptr) | 426 | (edge()->toNode()->canvasElement() == nullptr) || | ||
450 | || (edge()->toNode()->canvasElement() == nullptr) | 427 | edge()->style() == "invis") { | ||
451 | || edge()->style()=="invis") | | |||
452 | { | | |||
453 | m_boundingRect = QRectF(); | 428 | m_boundingRect = QRectF(); | ||
454 | } | 429 | } else { | ||
455 | else | | |||
456 | { | | |||
457 | QRectF br( | 430 | QRectF br( | ||
458 | edge()->fromNode()->canvasElement()->boundingRect().center()+edge()->fromNode()->canvasElement()->pos(), | 431 | edge()->fromNode()->canvasElement()->boundingRect().center() + | ||
459 | edge()->toNode()->canvasElement()->boundingRect().center()+edge()->toNode()->canvasElement()->pos()); | 432 | edge()->fromNode()->canvasElement()->pos(), | ||
460 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() <<br; | 433 | edge()->toNode()->canvasElement()->boundingRect().center() + | ||
434 | edge()->toNode()->canvasElement()->pos()); | ||||
435 | // qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << | ||||
436 | // "->" | ||||
437 | // << edge()->toNode()->id() <<br; | ||||
461 | m_boundingRect = br; | 438 | m_boundingRect = br; | ||
462 | } | 439 | } | ||
463 | } | 440 | } else { | ||
464 | else | | |||
465 | { | | |||
466 | QPolygonF points; | 441 | QPolygonF points; | ||
467 | foreach (const DotRenderOp& dro, edge()->renderOperations()) | 442 | foreach (const DotRenderOp &dro, edge()->renderOperations()) { | ||
468 | { | | |||
469 | // qCDebug(KGRAPHVIEWERLIB_LOG) << dro.renderop << ", "; | 443 | // qCDebug(KGRAPHVIEWERLIB_LOG) << dro.renderop << ", "; | ||
470 | if ( (dro.renderop != "B") && (dro.renderop != "p") && (dro.renderop != "P") ) continue; | 444 | if ((dro.renderop != "B") && (dro.renderop != "p") && | ||
445 | (dro.renderop != "P")) | ||||
446 | continue; | ||||
471 | uint previousSize = points.size(); | 447 | uint previousSize = points.size(); | ||
472 | points.resize(previousSize+dro.integers[0]); | 448 | points.resize(previousSize + dro.integers[0]); | ||
473 | for (int i = 0; i < dro.integers[0]; i++) | 449 | for (int i = 0; i < dro.integers[0]; i++) { | ||
474 | { | | |||
475 | QPointF p( | 450 | QPointF p( | ||
476 | ((dro.integers[2*i+1]/*%m_wdhcf*/)*m_scaleX) +m_xMargin, | 451 | ((dro.integers[2 * i + 1] /*%m_wdhcf*/) * m_scaleX) + | ||
477 | ((m_gh-dro.integers[2*i+2]/*%m_hdvcf*/)*m_scaleY) + m_yMargin | 452 | m_xMargin, | ||
478 | ); | 453 | ((m_gh - dro.integers[2 * i + 2] /*%m_hdvcf*/) * m_scaleY) + | ||
454 | m_yMargin); | ||||
479 | points[previousSize+i] = p; | 455 | points[previousSize + i] = p; | ||
480 | } | 456 | } | ||
481 | } | 457 | } | ||
482 | // qCDebug(KGRAPHVIEWERLIB_LOG) << points.size() << "points"; | 458 | // qCDebug(KGRAPHVIEWERLIB_LOG) << points.size() << "points"; | ||
483 | if (points.size() == 0) return; | 459 | if (points.size() == 0) | ||
460 | return; | ||||
484 | 461 | | |||
485 | int len = points.count(); | 462 | int len = points.count(); | ||
486 | QPolygonF a = points, b = points; | 463 | QPolygonF a = points, b = points; | ||
487 | a.translate(-1, -1); | 464 | a.translate(-1, -1); | ||
488 | b.translate(1, 1); | 465 | b.translate(1, 1); | ||
489 | a.resize(2*len); | 466 | a.resize(2 * len); | ||
490 | for (int i=0;i<len;i++) | 467 | for (int i = 0; i < len; i++) { | ||
491 | { | | |||
492 | a[len+i] = b[i]; | 468 | a[len + i] = b[i]; | ||
493 | } | 469 | } | ||
494 | // qCDebug(KGRAPHVIEWERLIB_LOG) << a.size() << "points"; | 470 | // qCDebug(KGRAPHVIEWERLIB_LOG) << a.size() << "points"; | ||
495 | 471 | | |||
496 | m_boundingRect = a.boundingRect(); | 472 | m_boundingRect = a.boundingRect(); | ||
497 | } | 473 | } | ||
498 | qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->fromNode()->id() << "->" << edge()->toNode()->id() << "New bounding rect is:" << m_boundingRect; | 474 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
475 | << edge()->fromNode()->id() << "->" << edge()->toNode()->id() | ||||
476 | << "New bounding rect is:" << m_boundingRect; | ||||
499 | } | 477 | } | ||
500 | 478 | | |||
501 | void CanvasEdge::mousePressEvent(QGraphicsSceneMouseEvent * event) | 479 | void CanvasEdge::mousePressEvent(QGraphicsSceneMouseEvent *event) { | ||
502 | { | | |||
503 | qCDebug(KGRAPHVIEWERLIB_LOG) << event; | 480 | qCDebug(KGRAPHVIEWERLIB_LOG) << event; | ||
504 | if (m_view->isReadOnly()) | 481 | if (m_view->isReadOnly()) { | ||
505 | { | | |||
506 | return; | 482 | return; | ||
507 | } | 483 | } | ||
508 | if (event->button() == Qt::LeftButton) | 484 | if (event->button() == Qt::LeftButton) { | ||
509 | { | | |||
510 | edge()->setSelected(!edge()->isSelected()); | 485 | edge()->setSelected(!edge()->isSelected()); | ||
511 | if (edge()->isSelected()) | 486 | if (edge()->isSelected()) { | ||
512 | { | | |||
513 | emit(selected(this,event->modifiers())); | 487 | emit(selected(this, event->modifiers())); | ||
514 | } | 488 | } | ||
515 | update(); | 489 | update(); | ||
516 | } | 490 | } else if (event->button() == Qt::RightButton) { | ||
517 | else if (event->button() == Qt::RightButton) | 491 | if (!edge()->isSelected()) { | ||
518 | { | | |||
519 | if (!edge()->isSelected()) | | |||
520 | { | | |||
521 | edge()->setSelected(true); | 492 | edge()->setSelected(true); | ||
522 | emit(selected(this,event->modifiers())); | 493 | emit(selected(this, event->modifiers())); | ||
523 | update(); | 494 | update(); | ||
524 | } | 495 | } | ||
525 | qCDebug(KGRAPHVIEWERLIB_LOG) << "emiting edgeContextMenuEvent("<<m_edge->id()<<","<<event->screenPos()<<")"; | 496 | qCDebug(KGRAPHVIEWERLIB_LOG) | ||
497 | << "emiting edgeContextMenuEvent(" << m_edge->id() << "," | ||||
498 | << event->screenPos() << ")"; | ||||
526 | emit(edgeContextMenuEvent(m_edge->id(), event->screenPos() )); | 499 | emit(edgeContextMenuEvent(m_edge->id(), event->screenPos())); | ||
527 | // opens the selected edge contextual menu and if necessary select the edge | 500 | // opens the selected edge contextual menu and if necessary select the | ||
501 | // edge | ||||
528 | /* qCDebug(KGRAPHVIEWERLIB_LOG) << "opens the contextual menu"; | 502 | /* qCDebug(KGRAPHVIEWERLIB_LOG) << "opens the contextual menu"; | ||
529 | m_popup->exec(event->screenPos());*/ | 503 | m_popup->exec(event->screenPos());*/ | ||
530 | } | 504 | } | ||
531 | } | 505 | } | ||
532 | 506 | | |||
533 | qreal CanvasEdge::distance(const QPointF& point1, const QPointF& point2) | 507 | qreal CanvasEdge::distance(const QPointF &point1, const QPointF &point2) { | ||
534 | { | 508 | return sqrt(pow(point1.x() - point2.x(), 2) + | ||
535 | return sqrt(pow(point1.x()-point2.x(),2)+pow(point1.y()-point2.y(),2)); | 509 | pow(point1.y() - point2.y(), 2)); | ||
536 | } | 510 | } | ||
537 | 511 | | |||
538 | void CanvasEdge::slotRemoveEdge() | 512 | void CanvasEdge::slotRemoveEdge() { m_view->removeSelectedElements(); } | ||
539 | { | | |||
540 | m_view->removeSelectedElements(); | | |||
541 | } | | |||
542 | 513 | | |||
543 | void CanvasEdge::hoverEnterEvent( QGraphicsSceneHoverEvent * event ) | 514 | void CanvasEdge::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { | ||
544 | { | | |||
545 | Q_UNUSED(event) | 515 | Q_UNUSED(event) | ||
546 | qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->id(); | 516 | qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->id(); | ||
547 | emit hoverEnter(this); | 517 | emit hoverEnter(this); | ||
548 | } | 518 | } | ||
549 | 519 | | |||
550 | void CanvasEdge::hoverLeaveEvent( QGraphicsSceneHoverEvent * event ) | 520 | void CanvasEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { | ||
551 | { | | |||
552 | Q_UNUSED(event) | 521 | Q_UNUSED(event) | ||
553 | qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->id(); | 522 | qCDebug(KGRAPHVIEWERLIB_LOG) << edge()->id(); | ||
554 | emit hoverLeave(this); | 523 | emit hoverLeave(this); | ||
555 | } | 524 | } | ||
556 | 525 | | |||
557 | } | 526 | } // namespace KGraphViewer |