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