Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportDesignerItemRectBase.cpp
Show All 22 Lines | |||||
23 | #include "KReportSize.h" | 23 | #include "KReportSize.h" | ||
24 | #include "KReportDesignerSectionScene.h" | 24 | #include "KReportDesignerSectionScene.h" | ||
25 | #include "KReportDpi.h" | 25 | #include "KReportDpi.h" | ||
26 | 26 | | |||
27 | #include <KPropertySet> | 27 | #include <KPropertySet> | ||
28 | #include <QGraphicsSceneMouseEvent> | 28 | #include <QGraphicsSceneMouseEvent> | ||
29 | #include <QApplication> | 29 | #include <QApplication> | ||
30 | 30 | | |||
31 | KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r) | 31 | KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b) | ||
32 | : QGraphicsRectItem(), KReportDesignerItemBase(r) | 32 | : QGraphicsRectItem(), KReportDesignerItemBase(r, b) | ||
33 | { | 33 | { | ||
34 | m_dpiX = KReportDpi::dpiX(); | 34 | m_dpiX = KReportDpi::dpiX(); | ||
35 | m_dpiY = KReportDpi::dpiY(); | 35 | m_dpiY = KReportDpi::dpiY(); | ||
36 | 36 | | |||
37 | m_ppos = 0; | | |||
38 | m_psize = 0; | | |||
39 | m_grabAction = 0; | 37 | m_grabAction = 0; | ||
40 | setAcceptHoverEvents(true); | 38 | setAcceptHoverEvents(true); | ||
41 | 39 | | |||
42 | #if QT_VERSION >= 0x040600 | | |||
43 | setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); | 40 | setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); | ||
44 | #else | | |||
45 | setFlags(ItemIsSelectable | ItemIsMovable); | | |||
46 | #endif | | |||
47 | } | | |||
48 | | ||||
49 | void KReportDesignerItemRectBase::init(KReportPosition* p, KReportSize* s, KPropertySet* se, KReportDesigner *d) | | |||
50 | { | | |||
51 | Q_UNUSED(d); | | |||
52 | m_ppos = p; | | |||
53 | m_psize = s; | | |||
54 | m_pset = se; | | |||
55 | } | 41 | } | ||
staniek: what about this? | |||||
piggz: Will remove , no longer required | |||||
56 | 42 | | |||
57 | KReportDesignerItemRectBase::~KReportDesignerItemRectBase() | 43 | KReportDesignerItemRectBase::~KReportDesignerItemRectBase() | ||
58 | { | 44 | { | ||
59 | } | 45 | } | ||
60 | 46 | | |||
61 | QRectF KReportDesignerItemRectBase::sceneRect() | 47 | QRectF KReportDesignerItemRectBase::sceneRect() | ||
62 | { | 48 | { | ||
63 | return QRectF(m_ppos->toScene(), m_psize->toScene()); | 49 | return QRectF(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); | ||
64 | } | 50 | } | ||
65 | 51 | | |||
66 | QRectF KReportDesignerItemRectBase::pointRect() const | 52 | QRectF KReportDesignerItemRectBase::pointRect() const | ||
67 | { | 53 | { | ||
68 | if (m_ppos && m_psize) | 54 | return QRectF(item()->position(), item()->size()); | ||
69 | return QRectF(m_ppos->toPoint(), m_psize->toPoint()); | | |||
70 | else | | |||
71 | return QRectF(0, 0, 0, 0); | | |||
72 | } | 55 | } | ||
73 | 56 | | |||
74 | void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update) | 57 | void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update) | ||
75 | { | 58 | { | ||
76 | setSceneRect(QRectF(topLeft, size), update); | 59 | setSceneRect(QRectF(topLeft, size), update); | ||
77 | } | 60 | } | ||
78 | 61 | | |||
79 | void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, UpdatePropertyFlag update) | 62 | void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, UpdatePropertyFlag update) | ||
80 | { | 63 | { | ||
81 | QGraphicsRectItem::setPos(rect.x(), rect.y()); | 64 | QGraphicsRectItem::setPos(rect.x(), rect.y()); | ||
82 | setRect(0, 0, rect.width(), rect.height()); | 65 | setRect(0, 0, rect.width(), rect.height()); | ||
83 | if (update == UpdateProperty) { | 66 | if (update == UpdateProperty) { | ||
84 | m_ppos->setScenePos(QPointF(rect.x(), rect.y())); | 67 | item()->setPosition(KReportItemBase::positionFromScene(QPointF(rect.x(), rect.y()))); | ||
85 | m_psize->setSceneSize(QSizeF(rect.width(), rect.height())); | 68 | item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect.width(), rect.height()))); | ||
86 | } | 69 | } | ||
87 | this->update(); | 70 | this->update(); | ||
88 | } | 71 | } | ||
89 | 72 | | |||
90 | void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) | 73 | void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) | ||
91 | { | 74 | { | ||
92 | //Update and show properties | 75 | //Update and show properties | ||
93 | m_ppos->setScenePos(QPointF(sceneRect().x(), sceneRect().y())); | 76 | item()->setPosition(KReportItemBase::positionFromScene(QPointF(sceneRect().x(), sceneRect().y()))); | ||
94 | m_reportDesigner->changeSet(m_pset); | 77 | designer()->changeSet(item()->propertySet()); | ||
95 | setSelected(true); | 78 | setSelected(true); | ||
96 | scene()->update(); | 79 | scene()->update(); | ||
97 | 80 | | |||
98 | QGraphicsItem::mousePressEvent(event); | 81 | QGraphicsItem::mousePressEvent(event); | ||
99 | } | 82 | } | ||
100 | 83 | | |||
101 | void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) | 84 | void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) | ||
102 | { | 85 | { | ||
103 | //Keep the size and position in sync | 86 | //Keep the size and position in sync | ||
104 | m_ppos->setScenePos(pos()); | 87 | item()->setPosition(KReportItemBase::positionFromScene(pos())); | ||
105 | m_psize->setSceneSize(QSizeF(rect().width(), rect().height())); | 88 | // m_ppos->setScenePos(pos()); | ||
staniek: 8X | |||||
89 | item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect().width(), rect().height()))); | ||||
90 | | ||||
91 | // m_psize->setSceneSize(QSizeF(rect().width(), rect().height())); | ||||
staniek: 8X | |||||
106 | 92 | | |||
107 | QGraphicsItem::mouseReleaseEvent(event); | 93 | QGraphicsItem::mouseReleaseEvent(event); | ||
108 | } | 94 | } | ||
109 | 95 | | |||
110 | void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) | 96 | void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) | ||
111 | { | 97 | { | ||
112 | //kreportDebug() << m_grabAction; | 98 | //kreportDebug() << m_grabAction; | ||
113 | 99 | | |||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | 256 | if (change == ItemPositionChange && scene()) { | |||
278 | 264 | | |||
279 | if (newPos.y() < 0) | 265 | if (newPos.y() < 0) | ||
280 | newPos.setY(0); | 266 | newPos.setY(0); | ||
281 | else if (newPos.y() > (scene()->height() - rect().height())) | 267 | else if (newPos.y() > (scene()->height() - rect().height())) | ||
282 | newPos.setY(scene()->height() - rect().height()); | 268 | newPos.setY(scene()->height() - rect().height()); | ||
283 | 269 | | |||
284 | return newPos; | 270 | return newPos; | ||
285 | } else if (change == ItemPositionHasChanged && scene()) { | 271 | } else if (change == ItemPositionHasChanged && scene()) { | ||
286 | m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); | 272 | item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); | ||
287 | } else if (change == ItemSceneHasChanged && scene() && m_psize) { | 273 | //TODO dont update property | ||
274 | //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); | ||||
275 | } else if (change == ItemSceneHasChanged && scene() && item()) { | ||||
288 | QPointF newPos = pos(); | 276 | QPointF newPos = pos(); | ||
289 | 277 | | |||
290 | newPos = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(newPos); | 278 | newPos = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(newPos); | ||
291 | if (newPos.x() < 0) | 279 | if (newPos.x() < 0) | ||
292 | newPos.setX(0); | 280 | newPos.setX(0); | ||
293 | else if (newPos.x() > (scene()->width() - rect().width())) | 281 | else if (newPos.x() > (scene()->width() - rect().width())) | ||
294 | newPos.setX(scene()->width() - rect().width()); | 282 | newPos.setX(scene()->width() - rect().width()); | ||
295 | 283 | | |||
296 | if (newPos.y() < 0) | 284 | if (newPos.y() < 0) | ||
297 | newPos.setY(0); | 285 | newPos.setY(0); | ||
298 | else if (newPos.y() > (scene()->height() - rect().height())) | 286 | else if (newPos.y() > (scene()->height() - rect().height())) | ||
299 | newPos.setY(scene()->height() - rect().height()); | 287 | newPos.setY(scene()->height() - rect().height()); | ||
300 | 288 | | |||
301 | setSceneRect(newPos, m_psize->toScene(), KReportDesignerItemRectBase::DontUpdateProperty); | 289 | setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); | ||
302 | } | 290 | } | ||
303 | 291 | | |||
304 | return QGraphicsItem::itemChange(change, value); | 292 | return QGraphicsItem::itemChange(change, value); | ||
305 | } | 293 | } | ||
306 | 294 | | |||
307 | void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) | 295 | void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) | ||
308 | { | 296 | { | ||
309 | Q_UNUSED(s) | 297 | Q_UNUSED(s) | ||
310 | 298 | | |||
311 | if (p.name() == "position") { | 299 | if (p.name() == "position") { | ||
312 | m_ppos->setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); | 300 | item()->setPosition(p.value().toPointF()); //TODO dont update property | ||
313 | } else if (p.name() == "size") { | 301 | } else if (p.name() == "size") { | ||
314 | m_psize->setUnitSize(p.value().toSizeF(), KReportSize::DontUpdateProperty); | 302 | item()->setSize(p.value().toSizeF()); //TODO dont update property | ||
315 | } | 303 | } | ||
316 | 304 | | |||
317 | setSceneRect(m_ppos->toScene(), m_psize->toScene(), DontUpdateProperty); | 305 | setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()), DontUpdateProperty); | ||
318 | } | 306 | } | ||
319 | 307 | | |||
320 | void KReportDesignerItemRectBase::move(const QPointF& /*m*/) | 308 | void KReportDesignerItemRectBase::move(const QPointF& /*m*/) | ||
321 | { | 309 | { | ||
322 | //! @todo | 310 | //! @todo | ||
323 | } | 311 | } | ||
324 | 312 | | |||
325 | QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const | 313 | QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
what about this?