Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportDesignerItemRectBase.cpp
Show All 26 Lines | |||||
27 | #include <QApplication> | 27 | #include <QApplication> | ||
28 | 28 | | |||
29 | class Q_DECL_HIDDEN KReportDesignerItemRectBase::Private | 29 | class Q_DECL_HIDDEN KReportDesignerItemRectBase::Private | ||
30 | { | 30 | { | ||
31 | public: | 31 | public: | ||
32 | Private(); | 32 | Private(); | ||
33 | ~Private(); | 33 | ~Private(); | ||
34 | 34 | | |||
35 | int grabAction; | 35 | int grabAction = 0; | ||
36 | }; | 36 | }; | ||
37 | 37 | | |||
38 | KReportDesignerItemRectBase::Private::Private() | 38 | KReportDesignerItemRectBase::Private::Private() | ||
39 | { | 39 | { | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | KReportDesignerItemRectBase::Private::~Private() | 42 | KReportDesignerItemRectBase::Private::~Private() | ||
43 | { | 43 | { | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) | 109 | void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) | ||
110 | { | 110 | { | ||
111 | //kreportDebug() << m_grabAction; | 111 | //kreportDebug() << m_grabAction; | ||
112 | 112 | | |||
113 | qreal w, h; | 113 | qreal w, h; | ||
114 | 114 | | |||
115 | QPointF p = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(event->scenePos()); | 115 | KReportDesignerSectionScene *_section = dynamic_cast<KReportDesignerSectionScene*>(scene()); | ||
staniek: Can we skip the _? | |||||
116 | if (!_section) { | ||||
117 | return; | ||||
118 | } | ||||
119 | | ||||
120 | QPointF p = _section->gridPoint(event->scenePos()); | ||||
staniek: `qobject_cast` | |||||
116 | w = p.x() - scenePos().x(); | 121 | w = p.x() - scenePos().x(); | ||
117 | h = p.y() - scenePos().y(); | 122 | h = p.y() - scenePos().y(); | ||
118 | 123 | | |||
119 | //! @todo use an enum for the directions | 124 | //! @todo use an enum for the directions | ||
120 | 125 | | |||
121 | switch (d->grabAction) { | 126 | switch (d->grabAction) { | ||
122 | case 1: | 127 | case 1: | ||
123 | if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) | 128 | if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | 265 | } else if (QRectF(center.x() - (halfW), center.y() - 2, 5, 5).contains(pos)) { | |||
261 | // middle-right | 266 | // middle-right | ||
262 | return 8; | 267 | return 8; | ||
263 | } | 268 | } | ||
264 | return 0; | 269 | return 0; | ||
265 | } | 270 | } | ||
266 | 271 | | |||
267 | QVariant KReportDesignerItemRectBase::itemChange(GraphicsItemChange change, const QVariant &value) | 272 | QVariant KReportDesignerItemRectBase::itemChange(GraphicsItemChange change, const QVariant &value) | ||
268 | { | 273 | { | ||
269 | if (change == ItemPositionChange && scene()) { | 274 | KReportDesignerSectionScene *_section = dynamic_cast<KReportDesignerSectionScene*>(scene()); | ||
staniek: Same here | |||||
275 | if (_section) { | ||||
276 | | ||||
277 | if (change == ItemPositionChange) { | ||||
270 | QPointF newPos = value.toPointF(); | 278 | QPointF newPos = value.toPointF(); | ||
271 | 279 | | |||
272 | newPos = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(newPos); | 280 | newPos = _section->gridPoint(newPos); | ||
273 | if (newPos.x() < 0) | 281 | if (newPos.x() < 0) | ||
274 | newPos.setX(0); | 282 | newPos.setX(0); | ||
275 | else if (newPos.x() > (scene()->width() - rect().width())) | 283 | else if (newPos.x() > (scene()->width() - rect().width())) | ||
276 | newPos.setX(scene()->width() - rect().width()); | 284 | newPos.setX(scene()->width() - rect().width()); | ||
277 | 285 | | |||
278 | if (newPos.y() < 0) | 286 | if (newPos.y() < 0) | ||
279 | newPos.setY(0); | 287 | newPos.setY(0); | ||
280 | else if (newPos.y() > (scene()->height() - rect().height())) | 288 | else if (newPos.y() > (scene()->height() - rect().height())) | ||
281 | newPos.setY(scene()->height() - rect().height()); | 289 | newPos.setY(scene()->height() - rect().height()); | ||
282 | 290 | | |||
283 | return newPos; | 291 | return newPos; | ||
284 | } else if (change == ItemPositionHasChanged && scene()) { | 292 | } else if (change == ItemPositionHasChanged) { | ||
285 | item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); | 293 | item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); | ||
286 | //TODO dont update property | 294 | //TODO dont update property | ||
287 | //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); | 295 | //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); | ||
288 | } else if (change == ItemSceneHasChanged && scene() && item()) { | 296 | } else if (change == ItemSceneHasChanged && item()) { | ||
289 | QPointF newPos = pos(); | 297 | QPointF newPos = pos(); | ||
290 | 298 | | |||
291 | newPos = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(newPos); | 299 | newPos = _section->gridPoint(newPos); | ||
292 | if (newPos.x() < 0) | 300 | if (newPos.x() < 0) | ||
293 | newPos.setX(0); | 301 | newPos.setX(0); | ||
294 | else if (newPos.x() > (scene()->width() - rect().width())) | 302 | else if (newPos.x() > (scene()->width() - rect().width())) | ||
295 | newPos.setX(scene()->width() - rect().width()); | 303 | newPos.setX(scene()->width() - rect().width()); | ||
296 | 304 | | |||
297 | if (newPos.y() < 0) | 305 | if (newPos.y() < 0) | ||
298 | newPos.setY(0); | 306 | newPos.setY(0); | ||
299 | else if (newPos.y() > (scene()->height() - rect().height())) | 307 | else if (newPos.y() > (scene()->height() - rect().height())) | ||
300 | newPos.setY(scene()->height() - rect().height()); | 308 | newPos.setY(scene()->height() - rect().height()); | ||
301 | 309 | | |||
302 | setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); | 310 | setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); | ||
303 | } | 311 | } | ||
staniek: `qobject_cast` | |||||
304 | 312 | } | |||
305 | return QGraphicsItem::itemChange(change, value); | 313 | return QGraphicsItem::itemChange(change, value); | ||
306 | } | 314 | } | ||
307 | 315 | | |||
308 | void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) | 316 | void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) | ||
309 | { | 317 | { | ||
310 | Q_UNUSED(s) | 318 | Q_UNUSED(s) | ||
311 | 319 | | |||
312 | if (p.name() == "position") { | 320 | if (p.name() == "position") { | ||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |
Can we skip the _?