Changeset View
Changeset View
Standalone View
Standalone View
src/part/canvaselement.cpp
Show All 10 Lines | 1 | /* This file is part of KGraphViewer. | |||
---|---|---|---|---|---|
11 | General Public License for more details. | 11 | General Public License for more details. | ||
12 | 12 | | |||
13 | You should have received a copy of the GNU General Public License | 13 | You should have received a copy of the GNU General Public License | ||
14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software | ||
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
16 | 02110-1301, USA | 16 | 02110-1301, USA | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | | ||||
20 | #include "canvaselement.h" | 19 | #include "canvaselement.h" | ||
20 | #include "FontsCache.h" | ||||
21 | #include "dot2qtconsts.h" | ||||
22 | #include "dotdefaults.h" | ||||
21 | #include "dotgraphview.h" | 23 | #include "dotgraphview.h" | ||
22 | #include "graphelement.h" | 24 | #include "graphelement.h" | ||
23 | #include "dotdefaults.h" | | |||
24 | #include "dot2qtconsts.h" | | |||
25 | #include "FontsCache.h" | | |||
26 | #include "kgraphviewerlib_debug.h" | 25 | #include "kgraphviewerlib_debug.h" | ||
27 | 26 | | |||
28 | #include <stdlib.h> | | |||
29 | #include <math.h> | | |||
30 | #include <iostream> | 27 | #include <iostream> | ||
28 | #include <math.h> | ||||
29 | #include <stdlib.h> | ||||
31 | 30 | | |||
32 | #include <QPainter> | | |||
33 | #include <QGraphicsScene> | 31 | #include <QGraphicsScene> | ||
34 | #include <QGraphicsSceneMouseEvent> | 32 | #include <QGraphicsSceneMouseEvent> | ||
35 | #include <QMenu> | 33 | #include <QMenu> | ||
34 | #include <QPainter> | ||||
36 | 35 | | |||
37 | #include <QDebug> | | |||
38 | #include <QAction> | 36 | #include <QAction> | ||
37 | #include <QDebug> | ||||
39 | #include <klocalizedstring.h> | 38 | #include <klocalizedstring.h> | ||
40 | 39 | | |||
41 | // comment out to get extended debug output during rendering | 40 | // comment out to get extended debug output during rendering | ||
42 | // #define RENDER_DEBUG 1 | 41 | // #define RENDER_DEBUG 1 | ||
43 | 42 | | |||
44 | #ifndef RENDER_DEBUG | 43 | #ifndef RENDER_DEBUG | ||
45 | #define RENDER_DEBUG 0 | 44 | #define RENDER_DEBUG 0 | ||
46 | #endif | 45 | #endif | ||
47 | 46 | | |||
48 | namespace KGraphViewer | 47 | namespace KGraphViewer { | ||
49 | { | | |||
50 | | ||||
51 | 48 | | |||
52 | CanvasElement::CanvasElement( | 49 | CanvasElement::CanvasElement(DotGraphView *v, GraphElement *gelement, | ||
53 | DotGraphView* v, | 50 | QGraphicsScene *c, QGraphicsItem *parent) | ||
54 | GraphElement* gelement, | 51 | : QObject(), QAbstractGraphicsShapeItem(parent), m_scaleX(0), m_scaleY(0), | ||
55 | QGraphicsScene* c, | 52 | m_xMargin(0), m_yMargin(0), m_gh(0), m_element(gelement), m_view(v), | ||
56 | QGraphicsItem* parent | | |||
57 | ) | | |||
58 | : QObject(), QAbstractGraphicsShapeItem(parent), | | |||
59 | m_scaleX(0), m_scaleY(0), | | |||
60 | m_xMargin(0), m_yMargin(0), m_gh(0), | | |||
61 | m_element(gelement), m_view(v), | | |||
62 | m_font(nullptr), | 53 | m_font(nullptr), | ||
63 | m_pen(Dot2QtConsts::componentData().qtColor(gelement->fontColor())), | 54 | m_pen(Dot2QtConsts::componentData().qtColor(gelement->fontColor())), | ||
64 | m_popup(new QMenu()), | 55 | m_popup(new QMenu()), m_hovered(false), m_lastRenderOpRev(0) { | ||
65 | m_hovered(false), | | |||
66 | m_lastRenderOpRev(0) | | |||
67 | { | | |||
68 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 56 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
69 | m_font = FontsCache::changeable().fromName(gelement->fontName()); | 57 | m_font = FontsCache::changeable().fromName(gelement->fontName()); | ||
70 | 58 | | |||
71 | /* qCDebug(KGRAPHVIEWERLIB_LOG) << "Creating CanvasElement for "<<gelement->id(); | 59 | /* qCDebug(KGRAPHVIEWERLIB_LOG) << "Creating CanvasElement for | ||
72 | qCDebug(KGRAPHVIEWERLIB_LOG) << " data: " << wdhcf << "," << hdvcf << "," << gh << "," | 60 | "<<gelement->id(); qCDebug(KGRAPHVIEWERLIB_LOG) << " data: " << wdhcf | ||
73 | << scaleX << "," << scaleY << "," << xMargin << "," << yMargin << endl;*/ | 61 | << | ||
62 | "," << hdvcf << "," << gh << "," | ||||
63 | << scaleX << "," << scaleY << "," << xMargin << "," << yMargin << | ||||
64 | endl;*/ | ||||
74 | 65 | | |||
75 | if (element()->style() == "bold") | 66 | if (element()->style() == "bold") { | ||
76 | { | | |||
77 | m_pen.setStyle(Qt::SolidLine); | 67 | m_pen.setStyle(Qt::SolidLine); | ||
78 | m_pen.setWidth(int(2*((m_scaleX+m_scaleY)/2))); | 68 | m_pen.setWidth(int(2 * ((m_scaleX + m_scaleY) / 2))); | ||
79 | } | 69 | } else if (element()->style() != "filled") { | ||
80 | else if (element()->style() != "filled") | 70 | m_pen.setStyle( | ||
81 | { | 71 | Dot2QtConsts::componentData().qtPenStyle(m_element->style())); | ||
82 | m_pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(m_element->style())); | | |||
83 | m_pen.setWidth(int((m_scaleX+m_scaleY)/2)); | 72 | m_pen.setWidth(int((m_scaleX + m_scaleY) / 2)); | ||
84 | if (element()->style().left(12) == "setlinewidth") | 73 | if (element()->style().left(12) == "setlinewidth") { | ||
85 | { | | |||
86 | bool ok; | 74 | bool ok; | ||
87 | uint lineWidth = element()->style().mid(13, m_element->style().length()-1-13).toInt(&ok); | 75 | uint lineWidth = element() | ||
76 | ->style() | ||||
77 | .mid(13, m_element->style().length() - 1 - 13) | ||||
78 | .toInt(&ok); | ||||
88 | m_pen.setWidth(lineWidth * int((m_scaleX+m_scaleY)/2)); | 79 | m_pen.setWidth(lineWidth * int((m_scaleX + m_scaleY) / 2)); | ||
89 | } | 80 | } | ||
90 | } | 81 | } | ||
91 | if (m_element->style() == "filled") | 82 | if (m_element->style() == "filled") { | ||
92 | { | | |||
93 | m_brush = Dot2QtConsts::componentData().qtColor(element()->backColor()); | 83 | m_brush = Dot2QtConsts::componentData().qtColor(element()->backColor()); | ||
94 | // QCanvasPolygon::drawShape(p); | 84 | // QCanvasPolygon::drawShape(p); | ||
95 | } | 85 | } else { | ||
96 | else | | |||
97 | { | | |||
98 | m_brush = c->backgroundBrush(); | 86 | m_brush = c->backgroundBrush(); | ||
99 | } | 87 | } | ||
100 | 88 | | |||
101 | // the message should be given (or possible to be given) by the part user | 89 | // the message should be given (or possible to be given) by the part user | ||
102 | QAction* removeElementAction = new QAction(i18n("Remove selected element(s)"), this); | 90 | QAction *removeElementAction = | ||
91 | new QAction(i18n("Remove selected element(s)"), this); | ||||
103 | m_popup->addAction(removeElementAction); | 92 | m_popup->addAction(removeElementAction); | ||
104 | connect(removeElementAction, &QAction::triggered, | 93 | connect(removeElementAction, &QAction::triggered, this, | ||
105 | this, &CanvasElement::slotRemoveElement); | 94 | &CanvasElement::slotRemoveElement); | ||
106 | 95 | | |||
107 | connect(this, &CanvasElement::selected, | 96 | connect(this, &CanvasElement::selected, v, | ||
108 | v, &DotGraphView::slotElementSelected); | 97 | &DotGraphView::slotElementSelected); | ||
109 | 98 | | |||
110 | connect(this, &CanvasElement::elementContextMenuEvent, | 99 | connect(this, &CanvasElement::elementContextMenuEvent, v, | ||
111 | v, &DotGraphView::slotContextMenuEvent); | 100 | &DotGraphView::slotContextMenuEvent); | ||
112 | 101 | | |||
113 | setAcceptHoverEvents ( true ); | 102 | setAcceptHoverEvents(true); | ||
114 | 103 | | |||
115 | connect(this, &CanvasElement::hoverEnter, | 104 | connect(this, &CanvasElement::hoverEnter, v, | ||
116 | v, static_cast<void(DotGraphView::*)(CanvasElement*)>(&DotGraphView::slotElementHoverEnter)); | 105 | static_cast<void (DotGraphView::*)(CanvasElement *)>( | ||
117 | connect(this, &CanvasElement::hoverLeave, | 106 | &DotGraphView::slotElementHoverEnter)); | ||
118 | v, static_cast<void(DotGraphView::*)(CanvasElement*)>(&DotGraphView::slotElementHoverLeave)); | 107 | connect(this, &CanvasElement::hoverLeave, v, | ||
119 | 108 | static_cast<void (DotGraphView::*)(CanvasElement *)>( | |||
109 | &DotGraphView::slotElementHoverLeave)); | ||||
120 | } | 110 | } | ||
121 | 111 | | |||
122 | CanvasElement::~CanvasElement() | 112 | CanvasElement::~CanvasElement() { delete m_popup; } | ||
123 | { | | |||
124 | delete m_popup; | | |||
125 | } | | |||
126 | 113 | | |||
127 | void CanvasElement::modelChanged() | 114 | void CanvasElement::modelChanged() { | ||
128 | { | | |||
129 | qCDebug(KGRAPHVIEWERLIB_LOG) ;//<< id(); | 115 | qCDebug(KGRAPHVIEWERLIB_LOG); //<< id(); | ||
130 | m_pen = QPen(Dot2QtConsts::componentData().qtColor(m_element->fontColor())); | 116 | m_pen = QPen(Dot2QtConsts::componentData().qtColor(m_element->fontColor())); | ||
131 | m_font = FontsCache::changeable().fromName(m_element->fontName()); | 117 | m_font = FontsCache::changeable().fromName(m_element->fontName()); | ||
132 | prepareGeometryChange(); | 118 | prepareGeometryChange(); | ||
133 | computeBoundingRect(); | 119 | computeBoundingRect(); | ||
134 | } | 120 | } | ||
135 | 121 | | |||
136 | void CanvasElement::initialize(qreal scaleX, qreal scaleY, | 122 | void CanvasElement::initialize(qreal scaleX, qreal scaleY, qreal xMargin, | ||
137 | qreal xMargin, qreal yMargin, qreal gh) | 123 | qreal yMargin, qreal gh) { | ||
138 | { | | |||
139 | Q_UNUSED(gh); | 124 | Q_UNUSED(gh); | ||
140 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 125 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
141 | setFlag(QGraphicsItem::ItemIsMovable, true); | 126 | setFlag(QGraphicsItem::ItemIsMovable, true); | ||
142 | setFlag(QGraphicsItem::ItemIsSelectable, true); | 127 | setFlag(QGraphicsItem::ItemIsSelectable, true); | ||
143 | 128 | | |||
144 | m_scaleX = scaleX; m_scaleY = scaleY; | 129 | m_scaleX = scaleX; | ||
145 | m_xMargin = xMargin; m_yMargin = yMargin; | 130 | m_scaleY = scaleY; | ||
131 | m_xMargin = xMargin; | ||||
132 | m_yMargin = yMargin; | ||||
146 | // m_gh = gh; | 133 | // m_gh = gh; | ||
147 | 134 | | |||
148 | setZValue(m_element->z()); | 135 | setZValue(m_element->z()); | ||
149 | 136 | | |||
150 | computeBoundingRect(); | 137 | computeBoundingRect(); | ||
151 | } | 138 | } | ||
152 | 139 | | |||
153 | QRectF CanvasElement::boundingRect () const | 140 | QRectF CanvasElement::boundingRect() const { return m_boundingRect; } | ||
154 | { | | |||
155 | return m_boundingRect; | | |||
156 | } | | |||
157 | 141 | | |||
158 | void CanvasElement::computeBoundingRect() | 142 | void CanvasElement::computeBoundingRect() { | ||
159 | { | | |||
160 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element(); | 143 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element(); | ||
161 | qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << zValue(); | 144 | qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << zValue(); | ||
162 | 145 | | |||
163 | qreal adjust = 0.5; | 146 | qreal adjust = 0.5; | ||
164 | QRectF rect; | 147 | QRectF rect; | ||
165 | if (element()->renderOperations().isEmpty()) | 148 | if (element()->renderOperations().isEmpty()) { | ||
166 | { | | |||
167 | qCDebug(KGRAPHVIEWERLIB_LOG) << "no render operation"; | 149 | qCDebug(KGRAPHVIEWERLIB_LOG) << "no render operation"; | ||
168 | rect = QRectF(0,0,(m_view->defaultNewElementPixmap().size().width())*m_scaleX,(m_view->defaultNewElementPixmap().size().height())*m_scaleY); | 150 | rect = QRectF( | ||
151 | 0, 0, (m_view->defaultNewElementPixmap().size().width()) * m_scaleX, | ||||
152 | (m_view->defaultNewElementPixmap().size().height()) * m_scaleY); | ||||
169 | m_boundingRect = rect; | 153 | m_boundingRect = rect; | ||
170 | } | 154 | } else { | ||
171 | else | | |||
172 | { | | |||
173 | DotRenderOpVec::const_iterator it, it_end; | 155 | DotRenderOpVec::const_iterator it, it_end; | ||
174 | it = element()->renderOperations().constBegin(); it_end = element()->renderOperations().constEnd(); | 156 | it = element()->renderOperations().constBegin(); | ||
175 | for (; it != it_end; it++) | 157 | it_end = element()->renderOperations().constEnd(); | ||
176 | { | 158 | for (; it != it_end; it++) { | ||
177 | #if RENDER_DEBUG | 159 | #if RENDER_DEBUG | ||
178 | QString msg; | 160 | QString msg; | ||
179 | QTextStream dd(&msg); | 161 | QTextStream dd(&msg); | ||
180 | dd << element()->id() << " an op: " << (*it).renderop << " "; | 162 | dd << element()->id() << " an op: " << (*it).renderop << " "; | ||
181 | foreach (int i, (*it).integers) | 163 | foreach (int i, (*it).integers) { dd << i << " "; } | ||
182 | { | | |||
183 | dd << i << " "; | | |||
184 | } | | |||
185 | dd << (*it).str; | 164 | dd << (*it).str; | ||
186 | qCDebug(KGRAPHVIEWERLIB_LOG) << msg; | 165 | qCDebug(KGRAPHVIEWERLIB_LOG) << msg; | ||
187 | #endif | 166 | #endif | ||
188 | 167 | | |||
189 | if ((*it).renderop == "e" || (*it).renderop == "E") | 168 | if ((*it).renderop == "e" || (*it).renderop == "E") { | ||
190 | { | 169 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "integers[0]=" << | ||
191 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "integers[0]=" << (*it).integers[0] << "; | 170 | // (*it).integers[0] << "; | ||
192 | qreal w = m_scaleX * (*it).integers[2] * 2; | 171 | qreal w = m_scaleX * (*it).integers[2] * 2; | ||
193 | qreal h = m_scaleY * (*it).integers[3] * 2; | 172 | qreal h = m_scaleY * (*it).integers[3] * 2; | ||
194 | qreal x = m_xMargin + (((*it).integers[0])*m_scaleX) - w/2; | 173 | qreal x = m_xMargin + (((*it).integers[0]) * m_scaleX) - w / 2; | ||
195 | qreal y = ((m_gh - (*it).integers[1])*m_scaleY) + m_yMargin - h/2; | 174 | qreal y = | ||
196 | m_boundingRect = QRectF(x - adjust,y - adjust, w + adjust, h + adjust); | 175 | ((m_gh - (*it).integers[1]) * m_scaleY) + m_yMargin - h / 2; | ||
197 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "'" << element()->id() << "' set rect for ellipse to " << rect; | 176 | m_boundingRect = | ||
198 | } | 177 | QRectF(x - adjust, y - adjust, w + adjust, h + adjust); | ||
199 | else if ((*it).renderop == "p" || (*it).renderop == "P") | 178 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "'" << | ||
200 | { | 179 | // element()->id() << "' set rect for ellipse to " << | ||
180 | // rect; | ||||
181 | } else if ((*it).renderop == "p" || (*it).renderop == "P") { | ||||
201 | QPolygonF polygon((*it).integers[0]); | 182 | QPolygonF polygon((*it).integers[0]); | ||
202 | for (int i = 0; i < (*it).integers[0]; i++) | 183 | for (int i = 0; i < (*it).integers[0]; i++) { | ||
203 | { | | |||
204 | qreal x,y; | 184 | qreal x, y; | ||
205 | x = (*it).integers[2*i+1]; | 185 | x = (*it).integers[2 * i + 1]; | ||
206 | y = (*it).integers[2*i+2]; | 186 | y = (*it).integers[2 * i + 2]; | ||
207 | { | 187 | {} | ||
208 | 188 | QPointF p(x * m_scaleX + m_xMargin, | |||
209 | } | 189 | (m_gh - y) * m_scaleY + m_yMargin); | ||
210 | QPointF p( | | |||
211 | x*m_scaleX +m_xMargin, | | |||
212 | (m_gh-y)*m_scaleY + m_yMargin | | |||
213 | ); | | |||
214 | polygon[i] = p; | 190 | polygon[i] = p; | ||
215 | } | 191 | } | ||
216 | m_boundingRect = polygon.boundingRect(); | 192 | m_boundingRect = polygon.boundingRect(); | ||
217 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "'" << element()->id() << "' set rect for polygon to " << rect; | 193 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "'" << | ||
194 | // element()->id() << "' set rect for polygon to " << | ||||
195 | // rect; | ||||
218 | } | 196 | } | ||
219 | } | 197 | } | ||
220 | } | 198 | } | ||
221 | setPos(0,0); | 199 | setPos(0, 0); | ||
222 | } | 200 | } | ||
223 | 201 | | |||
224 | ///TODO: optimize more! | 202 | /// TODO: optimize more! | ||
225 | void CanvasElement::paint(QPainter* p, const QStyleOptionGraphicsItem *option, | 203 | void CanvasElement::paint(QPainter *p, const QStyleOptionGraphicsItem *option, | ||
226 | QWidget *widget) | 204 | QWidget *widget) { | ||
227 | { | | |||
228 | if (m_lastRenderOpRev != element()->renderOperationsRevision()) { | 205 | if (m_lastRenderOpRev != element()->renderOperationsRevision()) { | ||
229 | m_fontSizeCache.clear(); | 206 | m_fontSizeCache.clear(); | ||
230 | } | 207 | } | ||
231 | 208 | | |||
232 | Q_UNUSED(option) | 209 | Q_UNUSED(option) | ||
233 | Q_UNUSED(widget) | 210 | Q_UNUSED(widget) | ||
234 | /// computes the scaling of line width | 211 | /// computes the scaling of line width | ||
235 | qreal widthScaleFactor = (m_scaleX+m_scaleY)/2; | 212 | qreal widthScaleFactor = (m_scaleX + m_scaleY) / 2; | ||
236 | if (widthScaleFactor < 1) | 213 | if (widthScaleFactor < 1) { | ||
237 | { | | |||
238 | widthScaleFactor = 1; | 214 | widthScaleFactor = 1; | ||
239 | } | 215 | } | ||
240 | 216 | | |||
241 | #if RENDER_DEBUG | 217 | #if RENDER_DEBUG | ||
242 | QString msg; | 218 | QString msg; | ||
243 | QTextStream dd(&msg); | 219 | QTextStream dd(&msg); | ||
244 | foreach (const DotRenderOp &op, element()->renderOperations()) | 220 | foreach (const DotRenderOp &op, element()->renderOperations()) { | ||
245 | { | | |||
246 | dd << element()->id() << " an op: " << op.renderop << " "; | 221 | dd << element()->id() << " an op: " << op.renderop << " "; | ||
247 | foreach (int i, op.integers) | 222 | foreach (int i, op.integers) { dd << i << " "; } | ||
248 | { | | |||
249 | dd << i << " "; | | |||
250 | } | | |||
251 | dd << op.str << endl; | 223 | dd << op.str << endl; | ||
252 | } | 224 | } | ||
253 | qCDebug(KGRAPHVIEWERLIB_LOG) << msg; | 225 | qCDebug(KGRAPHVIEWERLIB_LOG) << msg; | ||
254 | #endif | 226 | #endif | ||
255 | 227 | | |||
256 | if (element()->renderOperations().isEmpty() && m_view->isReadWrite()) | 228 | if (element()->renderOperations().isEmpty() && m_view->isReadWrite()) { | ||
257 | { | 229 | qCWarning(KGRAPHVIEWERLIB_LOG) | ||
258 | qCWarning(KGRAPHVIEWERLIB_LOG) << element()->id() << ": no render operation. This should not happen."; | 230 | << element()->id() | ||
231 | << ": no render operation. This should not happen."; | ||||
259 | return; | 232 | return; | ||
260 | } | 233 | } | ||
261 | 234 | | |||
262 | QListIterator<DotRenderOp> it(element()->renderOperations()); | 235 | QListIterator<DotRenderOp> it(element()->renderOperations()); | ||
263 | // it.toBack(); | 236 | // it.toBack(); | ||
264 | 237 | | |||
265 | QColor lineColor = Dot2QtConsts::componentData().qtColor(element()->lineColor()); | 238 | QColor lineColor = | ||
266 | QColor backColor = Dot2QtConsts::componentData().qtColor(element()->backColor()); | 239 | Dot2QtConsts::componentData().qtColor(element()->lineColor()); | ||
267 | if (m_hovered && m_view->highlighting()) | 240 | QColor backColor = | ||
268 | { | 241 | Dot2QtConsts::componentData().qtColor(element()->backColor()); | ||
242 | if (m_hovered && m_view->highlighting()) { | ||||
269 | backColor = backColor.lighter(); | 243 | backColor = backColor.lighter(); | ||
270 | } | 244 | } | ||
271 | 245 | | |||
272 | const QPen oldPen = p->pen(); | 246 | const QPen oldPen = p->pen(); | ||
273 | const QBrush oldBrush = p->brush(); | 247 | const QBrush oldBrush = p->brush(); | ||
274 | const QFont oldFont = p->font(); | 248 | const QFont oldFont = p->font(); | ||
275 | 249 | | |||
276 | while (it.hasNext()) | 250 | while (it.hasNext()) { | ||
277 | { | | |||
278 | const DotRenderOp& dro = it.next(); | 251 | const DotRenderOp &dro = it.next(); | ||
279 | if (dro.renderop == "c") | 252 | if (dro.renderop == "c") { | ||
280 | { | | |||
281 | QColor c(dro.str.mid(0,7)); | 253 | QColor c(dro.str.mid(0, 7)); | ||
282 | bool ok; | 254 | bool ok; | ||
283 | c.setAlpha(255-dro.str.mid(8).toInt(&ok,16)); | 255 | c.setAlpha(255 - dro.str.mid(8).toInt(&ok, 16)); | ||
284 | lineColor = c; | 256 | lineColor = c; | ||
285 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "c" << dro.str.mid(0,7) << lineColor; | 257 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "c" << dro.str.mid(0,7) << | ||
286 | } | 258 | // lineColor; | ||
287 | else if (dro.renderop == "C") | 259 | } else if (dro.renderop == "C") { | ||
288 | { | | |||
289 | QColor c(dro.str.mid(0,7)); | 260 | QColor c(dro.str.mid(0, 7)); | ||
290 | bool ok; | 261 | bool ok; | ||
291 | c.setAlpha(255-dro.str.mid(8).toInt(&ok,16)); | 262 | c.setAlpha(255 - dro.str.mid(8).toInt(&ok, 16)); | ||
292 | if (m_hovered && m_view->highlighting()) | 263 | if (m_hovered && m_view->highlighting()) { | ||
293 | { | | |||
294 | c = c.lighter(); | 264 | c = c.lighter(); | ||
295 | } | 265 | } | ||
296 | backColor = c; | 266 | backColor = c; | ||
297 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "C" << dro.str.mid(0,7) << backColor; | 267 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "C" << dro.str.mid(0,7) << | ||
298 | } | 268 | // backColor; | ||
299 | else if (dro.renderop == "e" || dro.renderop == "E") | 269 | } else if (dro.renderop == "e" || dro.renderop == "E") { | ||
300 | { | | |||
301 | QPen pen = oldPen; | 270 | QPen pen = oldPen; | ||
302 | qreal w = m_scaleX * dro.integers[2] * 2; | 271 | qreal w = m_scaleX * dro.integers[2] * 2; | ||
303 | qreal h = m_scaleY * dro.integers[3] * 2; | 272 | qreal h = m_scaleY * dro.integers[3] * 2; | ||
304 | qreal x = m_xMargin + (dro.integers[0]*m_scaleX) - w/2; | 273 | qreal x = m_xMargin + (dro.integers[0] * m_scaleX) - w / 2; | ||
305 | qreal y = ((m_gh - dro.integers[1])*m_scaleY) + m_yMargin - h/2; | 274 | qreal y = ((m_gh - dro.integers[1]) * m_scaleY) + m_yMargin - h / 2; | ||
306 | QRectF rect(x,y,w,h); | 275 | QRectF rect(x, y, w, h); | ||
307 | pen.setColor(lineColor); | 276 | pen.setColor(lineColor); | ||
308 | if (element()->attributes().contains("penwidth")) | 277 | if (element()->attributes().contains("penwidth")) { | ||
309 | { | | |||
310 | bool ok; | 278 | bool ok; | ||
311 | int lineWidth = element()->attributes()["penwidth"].toInt(&ok); | 279 | int lineWidth = element()->attributes()["penwidth"].toInt(&ok); | ||
312 | pen.setWidth(int(lineWidth * widthScaleFactor)); | 280 | pen.setWidth(int(lineWidth * widthScaleFactor)); | ||
313 | } | 281 | } | ||
314 | 282 | | |||
315 | p->setBrush(backColor); | 283 | p->setBrush(backColor); | ||
316 | p->setPen(pen); | 284 | p->setPen(pen); | ||
317 | 285 | | |||
318 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << "drawEllipse" << lineColor << backColor << rect; | 286 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << | ||
319 | // rect = QRectF(0,0,100,100); | 287 | // "drawEllipse" | ||
288 | // << lineColor << backColor << rect; rect = | ||||
289 | // QRectF(0,0,100,100); | ||||
320 | p->drawEllipse(rect); | 290 | p->drawEllipse(rect); | ||
321 | } | 291 | } else if (dro.renderop == "p" || dro.renderop == "P") { | ||
322 | else if(dro.renderop == "p" || dro.renderop == "P") | 292 | // std::cerr << "Drawing polygon for node | ||
323 | { | 293 | // '"<<element()->id()<<"': | ||
324 | // std::cerr << "Drawing polygon for node '"<<element()->id()<<"': "; | 294 | // "; | ||
325 | QPolygonF points(dro.integers[0]); | 295 | QPolygonF points(dro.integers[0]); | ||
326 | for (int i = 0; i < dro.integers[0]; i++) | 296 | for (int i = 0; i < dro.integers[0]; i++) { | ||
327 | { | | |||
328 | qreal x,y; | 297 | qreal x, y; | ||
329 | x = dro.integers[2*i+1]; | 298 | x = dro.integers[2 * i + 1]; | ||
330 | y = dro.integers[2*i+2]; | 299 | y = dro.integers[2 * i + 2]; | ||
331 | QPointF p( | 300 | QPointF p((x * m_scaleX) + m_xMargin, | ||
332 | (x*m_scaleX) + m_xMargin, | 301 | ((m_gh - y) * m_scaleY) + m_yMargin); | ||
333 | ((m_gh-y)*m_scaleY) + m_yMargin | 302 | /* qCDebug(KGRAPHVIEWERLIB_LOG) << " point: (" << | ||
334 | ); | 303 | dro.integers[2*i+1] << "," | ||
335 | /* qCDebug(KGRAPHVIEWERLIB_LOG) << " point: (" << dro.integers[2*i+1] << "," | | |||
336 | << dro.integers[2*i+2] << ") " */ | 304 | << dro.integers[2*i+2] << ") " */ | ||
337 | points[i] = p; | 305 | points[i] = p; | ||
338 | } | 306 | } | ||
339 | 307 | | |||
340 | QPen pen = oldPen; | 308 | QPen pen = oldPen; | ||
341 | pen.setColor(lineColor); | 309 | pen.setColor(lineColor); | ||
342 | if (element()->style() == "bold") | 310 | if (element()->style() == "bold") { | ||
343 | { | | |||
344 | pen.setStyle(Qt::SolidLine); | 311 | pen.setStyle(Qt::SolidLine); | ||
345 | pen.setWidth(2); | 312 | pen.setWidth(2); | ||
346 | } | 313 | } | ||
347 | if (element()->attributes().contains("penwidth")) | 314 | if (element()->attributes().contains("penwidth")) { | ||
348 | { | | |||
349 | bool ok; | 315 | bool ok; | ||
350 | int lineWidth = element()->attributes()["penwidth"].toInt(&ok); | 316 | int lineWidth = element()->attributes()["penwidth"].toInt(&ok); | ||
351 | pen.setWidth(int(lineWidth * widthScaleFactor)); | 317 | pen.setWidth(int(lineWidth * widthScaleFactor)); | ||
318 | } else if (element()->style() != "filled") { | ||||
319 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle( | ||||
320 | element()->style())); | ||||
352 | } | 321 | } | ||
353 | else if (element()->style() != "filled") | 322 | if (element()->style().left(12) == "setlinewidth") { | ||
354 | { | | |||
355 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(element()->style())); | | |||
356 | } | | |||
357 | if (element()->style().left(12) == "setlinewidth") | | |||
358 | { | | |||
359 | bool ok; | 323 | bool ok; | ||
360 | uint lineWidth = element()->style().mid(12, element()->style().length()-1-12).toInt(&ok); | 324 | uint lineWidth = | ||
325 | element() | ||||
326 | ->style() | ||||
327 | .mid(12, element()->style().length() - 1 - 12) | ||||
328 | .toInt(&ok); | ||||
361 | pen.setWidth(lineWidth); | 329 | pen.setWidth(lineWidth); | ||
362 | } | 330 | } | ||
363 | p->setPen(pen); | 331 | p->setPen(pen); | ||
364 | p->setBrush(backColor); | 332 | p->setBrush(backColor); | ||
365 | /* if (element()->style() == "filled") | 333 | /* if (element()->style() == "filled") | ||
366 | { | 334 | { | ||
367 | p->setBrush(Dot2QtConsts::componentData().qtColor(element()->backColor())); | 335 | p->setBrush(Dot2QtConsts::componentData().qtColor(element()->backColor())); | ||
368 | // QCanvasPolygon::paint(p); | 336 | // QCanvasPolygon::paint(p); | ||
369 | } | 337 | } | ||
370 | else | 338 | else | ||
371 | { | 339 | { | ||
372 | p->setBrush(canvas()->backgroundColor()); | 340 | p->setBrush(canvas()->backgroundColor()); | ||
373 | }*/ | 341 | }*/ | ||
374 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << "drawPolygon" << points; | 342 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << | ||
343 | // "drawPolygon" | ||||
344 | // << points; | ||||
375 | p->drawPolygon(points); | 345 | p->drawPolygon(points); | ||
376 | if (!element()->shapeFile().isEmpty()) | 346 | if (!element()->shapeFile().isEmpty()) { | ||
377 | { | | |||
378 | QPixmap pix(element()->shapeFile()); | 347 | QPixmap pix(element()->shapeFile()); | ||
379 | if (!pix.isNull()) | 348 | if (!pix.isNull()) { | ||
380 | { | 349 | p->drawPixmap(int(points.boundingRect().left()), | ||
381 | p->drawPixmap(int(points.boundingRect().left()), int(points.boundingRect().top()), pix); | 350 | int(points.boundingRect().top()), pix); | ||
382 | } | 351 | } | ||
383 | } | 352 | } | ||
384 | } | 353 | } | ||
385 | | ||||
386 | } | 354 | } | ||
387 | 355 | | |||
388 | p->setBrush(oldBrush); | 356 | p->setBrush(oldBrush); | ||
389 | p->setPen(oldPen); | 357 | p->setPen(oldPen); | ||
390 | 358 | | |||
391 | it.toFront(); | 359 | it.toFront(); | ||
392 | while (it.hasNext()) | 360 | while (it.hasNext()) { | ||
393 | { | | |||
394 | const DotRenderOp& dro = it.next(); | 361 | const DotRenderOp &dro = it.next(); | ||
395 | if (dro.renderop == "c") | 362 | if (dro.renderop == "c") { | ||
396 | { | | |||
397 | QColor c(dro.str.mid(0,7)); | 363 | QColor c(dro.str.mid(0, 7)); | ||
398 | bool ok; | 364 | bool ok; | ||
399 | c.setAlpha(255-dro.str.mid(8).toInt(&ok,16)); | 365 | c.setAlpha(255 - dro.str.mid(8).toInt(&ok, 16)); | ||
400 | lineColor = c; | 366 | lineColor = c; | ||
401 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "c" << dro.str.mid(0,7) << lineColor; | 367 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "c" << dro.str.mid(0,7) << | ||
402 | } | 368 | // lineColor; | ||
403 | else if (dro.renderop == "C") | 369 | } else if (dro.renderop == "C") { | ||
404 | { | | |||
405 | QColor c(dro.str.mid(0,7)); | 370 | QColor c(dro.str.mid(0, 7)); | ||
406 | bool ok; | 371 | bool ok; | ||
407 | c.setAlpha(255-dro.str.mid(8).toInt(&ok,16)); | 372 | c.setAlpha(255 - dro.str.mid(8).toInt(&ok, 16)); | ||
408 | if (m_hovered && m_view->highlighting()) | 373 | if (m_hovered && m_view->highlighting()) { | ||
409 | { | | |||
410 | c = c.lighter(); | 374 | c = c.lighter(); | ||
411 | } | 375 | } | ||
412 | backColor = c; | 376 | backColor = c; | ||
413 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "C" << dro.str.mid(0,7) << backColor; | 377 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "C" << dro.str.mid(0,7) << | ||
414 | } | 378 | // backColor; | ||
415 | else if ( dro.renderop == "L" ) | 379 | } else if (dro.renderop == "L") { | ||
416 | { | | |||
417 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Label"; | 380 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Label"; | ||
418 | QPolygonF points(dro.integers[0]); | 381 | QPolygonF points(dro.integers[0]); | ||
419 | for (int i = 0; i < dro.integers[0]; i++) | 382 | for (int i = 0; i < dro.integers[0]; i++) { | ||
420 | { | | |||
421 | qreal x,y; | 383 | qreal x, y; | ||
422 | x = dro.integers[2*i+1]; | 384 | x = dro.integers[2 * i + 1]; | ||
423 | y = dro.integers[2*i+2]; | 385 | y = dro.integers[2 * i + 2]; | ||
424 | QPointF p( | 386 | QPointF p((x * m_scaleX) + m_xMargin, | ||
425 | (x*m_scaleX) +m_xMargin, | 387 | ((m_gh - y) * m_scaleY) + m_yMargin); | ||
426 | ((m_gh-y)*m_scaleY) + m_yMargin | | |||
427 | ); | | |||
428 | points[i] = p; | 388 | points[i] = p; | ||
429 | } | 389 | } | ||
430 | QPen pen(lineColor); | 390 | QPen pen(lineColor); | ||
431 | if (element()->style() == "bold") | 391 | if (element()->style() == "bold") { | ||
432 | { | | |||
433 | pen.setStyle(Qt::SolidLine); | 392 | pen.setStyle(Qt::SolidLine); | ||
434 | pen.setWidth(2); | 393 | pen.setWidth(2); | ||
435 | } | 394 | } else if (element()->style() != "filled") { | ||
436 | else if (element()->style() != "filled") | 395 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle( | ||
437 | { | 396 | element()->style())); | ||
438 | pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(element()->style())); | | |||
439 | } | 397 | } | ||
440 | p->setPen(pen); | 398 | p->setPen(pen); | ||
441 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << "drawPolyline" << points; | 399 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << | ||
400 | // "drawPolyline" | ||||
401 | // << points; | ||||
442 | p->drawPolyline(points); | 402 | p->drawPolyline(points); | ||
443 | } | 403 | } | ||
444 | } | 404 | } | ||
445 | p->setPen(oldPen); | 405 | p->setPen(oldPen); | ||
446 | 406 | | |||
447 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Drawing" << element()->id() << "labels"; | 407 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Drawing" << element()->id() << | ||
408 | // "labels"; | ||||
448 | QString color = lineColor.name(); | 409 | QString color = lineColor.name(); | ||
449 | it.toFront(); | 410 | it.toFront(); | ||
450 | uint num_T = 0; | 411 | uint num_T = 0; | ||
451 | while (it.hasNext()) | 412 | while (it.hasNext()) { | ||
452 | { | | |||
453 | const DotRenderOp& dro = it.next(); | 413 | const DotRenderOp &dro = it.next(); | ||
454 | if (dro.renderop == "c" || dro.renderop == "C") | 414 | if (dro.renderop == "c" || dro.renderop == "C") { | ||
455 | { | | |||
456 | color = dro.str.mid(0,7); | 415 | color = dro.str.mid(0, 7); | ||
457 | // qCDebug(KGRAPHVIEWERLIB_LOG) << dro.renderop << color; | 416 | // qCDebug(KGRAPHVIEWERLIB_LOG) << dro.renderop << color; | ||
458 | } | 417 | } else if (dro.renderop == "F") { | ||
459 | else if (dro.renderop == "F") | | |||
460 | { | | |||
461 | element()->setFontName(dro.str); | 418 | element()->setFontName(dro.str); | ||
462 | element()->setFontSize(dro.integers[0]); | 419 | element()->setFontSize(dro.integers[0]); | ||
463 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "F" << element()->fontName() << element()->fontColor() << element()->fontSize(); | 420 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "F" << | ||
464 | } | 421 | // element()->fontName() << element()->fontColor() << | ||
465 | else if ( dro.renderop == "T" ) | 422 | // element()->fontSize(); | ||
466 | { | 423 | } else if (dro.renderop == "T") { | ||
467 | ++num_T; | 424 | ++num_T; | ||
468 | // we suppose here that the color has been set just before | 425 | // we suppose here that the color has been set just before | ||
469 | element()->setFontColor(color); | 426 | element()->setFontColor(color); | ||
470 | // draw a label | 427 | // draw a label | ||
471 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Drawing a label " << dro.integers[0] | 428 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "Drawing a label " << | ||
429 | // dro.integers[0] | ||||
472 | // << " " << dro.integers[1] << " " << dro.integers[2] | 430 | // << " " << dro.integers[1] << " " << dro.integers[2] | ||
473 | // << " " << dro.integers[3] << " " << dro.str | 431 | // << " " << dro.integers[3] << " " << dro.str | ||
474 | // << " (" << element()->fontName() << ", " << element()->fontSize() | 432 | // << " (" << element()->fontName() << ", " << | ||
433 | // element()->fontSize() | ||||
475 | // << ", " << element()->fontColor() << ")"; | 434 | // << ", " << element()->fontColor() << ")"; | ||
476 | 435 | | |||
477 | int fontWidth = 0; | 436 | int fontWidth = 0; | ||
478 | bool cacheValid = false; | 437 | bool cacheValid = false; | ||
479 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << " initial fontSize " << fontSize; | 438 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << " | ||
439 | // initial fontSize " << fontSize; | ||||
480 | if (m_lastRenderOpRev == element()->renderOperationsRevision()) { | 440 | if (m_lastRenderOpRev == element()->renderOperationsRevision()) { | ||
481 | FontSizeCache::iterator cacheIt = m_fontSizeCache.find(num_T); | 441 | FontSizeCache::iterator cacheIt = m_fontSizeCache.find(num_T); | ||
482 | if (cacheIt != m_fontSizeCache.end()) { | 442 | if (cacheIt != m_fontSizeCache.end()) { | ||
483 | m_font->setPointSize(cacheIt->first); | 443 | m_font->setPointSize(cacheIt->first); | ||
484 | fontWidth = cacheIt->second; | 444 | fontWidth = cacheIt->second; | ||
485 | cacheValid = true; | 445 | cacheValid = true; | ||
486 | } | 446 | } | ||
487 | } | 447 | } | ||
488 | if (!cacheValid) { | 448 | if (!cacheValid) { | ||
489 | int stringWidthGoal = int(dro.integers[3] * m_scaleX); | 449 | int stringWidthGoal = int(dro.integers[3] * m_scaleX); | ||
490 | int fontSize = element()->fontSize(); | 450 | int fontSize = element()->fontSize(); | ||
491 | m_font->setPointSize(fontSize); | 451 | m_font->setPointSize(fontSize); | ||
492 | 452 | | |||
493 | QFontMetrics fm(*m_font); | 453 | QFontMetrics fm(*m_font); | ||
494 | fontWidth = fm.width(dro.str); | 454 | fontWidth = fm.width(dro.str); | ||
495 | while (fontWidth > stringWidthGoal && fontSize > 1) | 455 | while (fontWidth > stringWidthGoal && fontSize > 1) { | ||
496 | { | | |||
497 | // use floor'ed extrapolated font size | 456 | // use floor'ed extrapolated font size | ||
498 | fontSize = double(stringWidthGoal) / fontWidth * fontSize; | 457 | fontSize = double(stringWidthGoal) / fontWidth * fontSize; | ||
499 | m_font->setPointSize(fontSize); | 458 | m_font->setPointSize(fontSize); | ||
500 | fm = QFontMetrics(*m_font); | 459 | fm = QFontMetrics(*m_font); | ||
501 | fontWidth = fm.width(dro.str); | 460 | fontWidth = fm.width(dro.str); | ||
502 | } | 461 | } | ||
503 | m_fontSizeCache[num_T] = qMakePair(fontSize, fontWidth); | 462 | m_fontSizeCache[num_T] = qMakePair(fontSize, fontWidth); | ||
504 | } | 463 | } | ||
505 | 464 | | |||
506 | p->setFont(*m_font); | 465 | p->setFont(*m_font); | ||
507 | QPen pen(m_pen); | 466 | QPen pen(m_pen); | ||
508 | pen.setColor(element()->fontColor()); | 467 | pen.setColor(element()->fontColor()); | ||
509 | p->setPen(pen); | 468 | p->setPen(pen); | ||
510 | qreal x = (m_scaleX * | 469 | qreal x = (m_scaleX * ((dro.integers[0]) + | ||
511 | ( | 470 | (((-dro.integers[2]) * (fontWidth)) / 2) - | ||
512 | (dro.integers[0]) | 471 | ((fontWidth) / 2))) + | ||
513 | + (((-dro.integers[2])*(fontWidth))/2) | 472 | m_xMargin; | ||
514 | - ( (fontWidth)/2 ) | | |||
515 | ) | | |||
516 | ) | | |||
517 | + m_xMargin; | | |||
518 | qreal y = ((m_gh - (dro.integers[1]))*m_scaleY)+ m_yMargin; | 473 | qreal y = ((m_gh - (dro.integers[1])) * m_scaleY) + m_yMargin; | ||
519 | QPointF point(x,y); | 474 | QPointF point(x, y); | ||
520 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << "drawText" << point << " " << fontSize; | 475 | // qCDebug(KGRAPHVIEWERLIB_LOG) << element()->id() << | ||
476 | // "drawText" << point << " " << fontSize; | ||||
521 | p->drawText(point, dro.str); | 477 | p->drawText(point, dro.str); | ||
522 | } | 478 | } | ||
523 | } | 479 | } | ||
524 | 480 | | |||
525 | if (element()->isSelected()) | 481 | if (element()->isSelected()) { | ||
526 | { | 482 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element is selected: draw | ||
527 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "element is selected: draw selection marks"; | 483 | // selection marks"; | ||
528 | p->setBrush(Qt::black); | 484 | p->setBrush(Qt::black); | ||
529 | p->setPen(Qt::black); | 485 | p->setPen(Qt::black); | ||
530 | p->drawRect(QRectF(m_boundingRect.topLeft(),QSizeF(6,6))); | 486 | p->drawRect(QRectF(m_boundingRect.topLeft(), QSizeF(6, 6))); | ||
531 | p->drawRect(QRectF(m_boundingRect.topRight()-QPointF(6,0),QSizeF(6,6))); | 487 | p->drawRect( | ||
532 | p->drawRect(QRectF(m_boundingRect.bottomLeft()-QPointF(0,6),QSizeF(6,6))); | 488 | QRectF(m_boundingRect.topRight() - QPointF(6, 0), QSizeF(6, 6))); | ||
533 | p->drawRect(QRectF(m_boundingRect.bottomRight()-QPointF(6,6),QSizeF(6,6))); | 489 | p->drawRect( | ||
490 | QRectF(m_boundingRect.bottomLeft() - QPointF(0, 6), QSizeF(6, 6))); | ||||
491 | p->drawRect( | ||||
492 | QRectF(m_boundingRect.bottomRight() - QPointF(6, 6), QSizeF(6, 6))); | ||||
534 | } | 493 | } | ||
535 | 494 | | |||
536 | p->setPen(oldPen); | 495 | p->setPen(oldPen); | ||
537 | p->setBrush(oldBrush); | 496 | p->setBrush(oldBrush); | ||
538 | p->setFont(oldFont); | 497 | p->setFont(oldFont); | ||
539 | 498 | | |||
540 | m_lastRenderOpRev = element()->renderOperationsRevision(); | 499 | m_lastRenderOpRev = element()->renderOperationsRevision(); | ||
541 | } | 500 | } | ||
542 | 501 | | |||
543 | void CanvasElement::mousePressEvent(QGraphicsSceneMouseEvent* event) | 502 | void CanvasElement::mousePressEvent(QGraphicsSceneMouseEvent *event) { | ||
544 | { | | |||
545 | qCDebug(KGRAPHVIEWERLIB_LOG) << m_element->id() << boundingRect(); | 503 | qCDebug(KGRAPHVIEWERLIB_LOG) << m_element->id() << boundingRect(); | ||
546 | if (m_view->isReadOnly()) | 504 | if (m_view->isReadOnly()) { | ||
547 | { | | |||
548 | return; | 505 | return; | ||
549 | } | 506 | } | ||
550 | if (m_view->editingMode() == DotGraphView::AddNewEdge) | 507 | if (m_view->editingMode() == DotGraphView::AddNewEdge) { | ||
551 | { | | |||
552 | m_view->createNewEdgeDraftFrom(this); | 508 | m_view->createNewEdgeDraftFrom(this); | ||
553 | return; | 509 | return; | ||
554 | } | 510 | } else if (m_view->editingMode() == DotGraphView::DrawNewEdge) { | ||
555 | else if (m_view->editingMode() == DotGraphView::DrawNewEdge) | | |||
556 | { | | |||
557 | m_view->finishNewEdgeTo(this); | 511 | m_view->finishNewEdgeTo(this); | ||
558 | return; | 512 | return; | ||
559 | } | 513 | } | ||
560 | if (event->button() == Qt::LeftButton) | 514 | if (event->button() == Qt::LeftButton) { | ||
561 | { | | |||
562 | m_element->setSelected(!m_element->isSelected()); | 515 | m_element->setSelected(!m_element->isSelected()); | ||
563 | if (m_element->isSelected()) | 516 | if (m_element->isSelected()) { | ||
564 | { | | |||
565 | emit(selected(this,event->modifiers())); | 517 | emit(selected(this, event->modifiers())); | ||
566 | } | 518 | } | ||
567 | update(); | 519 | update(); | ||
568 | } | 520 | } else if (event->button() == Qt::RightButton) { | ||
569 | else if (event->button() == Qt::RightButton) | 521 | // opens the selected edge contextual menu and if necessary select the | ||
570 | { | 522 | // edge | ||
571 | // opens the selected edge contextual menu and if necessary select the edge | 523 | if (!m_element->isSelected()) { | ||
572 | if (!m_element->isSelected()) | | |||
573 | { | | |||
574 | m_element->setSelected(true); | 524 | m_element->setSelected(true); | ||
575 | emit(selected(this,event->modifiers())); | 525 | emit(selected(this, event->modifiers())); | ||
576 | update(); | 526 | update(); | ||
577 | } | 527 | } | ||
578 | 528 | | |||
579 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "opens the contextual menu"; | 529 | // qCDebug(KGRAPHVIEWERLIB_LOG) << "opens the contextual menu"; | ||
580 | // m_popup->exec(event->screenPos()); | 530 | // m_popup->exec(event->screenPos()); | ||
581 | emit(elementContextMenuEvent(m_element->id(), event->screenPos() )); | 531 | emit(elementContextMenuEvent(m_element->id(), event->screenPos())); | ||
582 | } | 532 | } | ||
583 | } | 533 | } | ||
584 | 534 | | |||
585 | void CanvasElement::mouseMoveEvent(QGraphicsSceneMouseEvent* event) | 535 | void CanvasElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { | ||
586 | { | | |||
587 | Q_UNUSED(event) | 536 | Q_UNUSED(event) | ||
588 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | 537 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | ||
589 | } | 538 | } | ||
590 | 539 | | |||
591 | void CanvasElement::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | 540 | void CanvasElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { | ||
592 | { | | |||
593 | Q_UNUSED(event) | 541 | Q_UNUSED(event) | ||
594 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | 542 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | ||
595 | } | 543 | } | ||
596 | 544 | | |||
597 | void CanvasElement::slotRemoveElement() | 545 | void CanvasElement::slotRemoveElement() { m_view->removeSelectedElements(); } | ||
598 | { | | |||
599 | m_view->removeSelectedElements(); | | |||
600 | } | | |||
601 | 546 | | |||
602 | void CanvasElement::hoverEnterEvent( QGraphicsSceneHoverEvent * event ) | 547 | void CanvasElement::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { | ||
603 | { | | |||
604 | Q_UNUSED(event) | 548 | Q_UNUSED(event) | ||
605 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 549 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
606 | m_hovered = true; | 550 | m_hovered = true; | ||
607 | update(); | 551 | update(); | ||
608 | emit hoverEnter(this); | 552 | emit hoverEnter(this); | ||
609 | } | 553 | } | ||
610 | 554 | | |||
611 | void CanvasElement::hoverLeaveEvent( QGraphicsSceneHoverEvent * event ) | 555 | void CanvasElement::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { | ||
612 | { | | |||
613 | Q_UNUSED(event) | 556 | Q_UNUSED(event) | ||
614 | // qCDebug(KGRAPHVIEWERLIB_LOG); | 557 | // qCDebug(KGRAPHVIEWERLIB_LOG); | ||
615 | m_hovered = false; | 558 | m_hovered = false; | ||
616 | update(); | 559 | update(); | ||
617 | emit hoverLeave(this); | 560 | emit hoverLeave(this); | ||
618 | } | 561 | } | ||
619 | 562 | | |||
620 | } | 563 | } // namespace KGraphViewer |