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 | class Q_DECL_HIDDEN KReportDesignerItemRectBase::Private | ||
32 | : QGraphicsRectItem(), KReportDesignerItemBase(r) | 32 | { | ||
33 | public: | ||||
34 | Private(); | ||||
35 | ~Private(); | ||||
36 | | ||||
37 | int grabAction; | ||||
38 | }; | ||||
39 | | ||||
40 | KReportDesignerItemRectBase::Private::Private() | ||||
41 | { | ||||
42 | } | ||||
43 | | ||||
44 | KReportDesignerItemRectBase::Private::~Private() | ||||
45 | { | ||||
46 | } | ||||
47 | | ||||
48 | KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b) | ||||
49 | : QGraphicsRectItem(), KReportDesignerItemBase(r, b), d(new KReportDesignerItemRectBase::Private) | ||||
33 | { | 50 | { | ||
34 | m_dpiX = KReportDpi::dpiX(); | 51 | m_dpiX = KReportDpi::dpiX(); | ||
35 | m_dpiY = KReportDpi::dpiY(); | 52 | m_dpiY = KReportDpi::dpiY(); | ||
36 | 53 | | |||
37 | m_ppos = 0; | 54 | d->grabAction = 0; | ||
38 | m_psize = 0; | | |||
39 | m_grabAction = 0; | | |||
40 | setAcceptHoverEvents(true); | 55 | setAcceptHoverEvents(true); | ||
41 | 56 | | |||
42 | #if QT_VERSION >= 0x040600 | | |||
43 | setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); | 57 | 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 | } | 58 | } | ||
staniek: what about this? | |||||
piggz: Will remove , no longer required | |||||
56 | 59 | | |||
57 | KReportDesignerItemRectBase::~KReportDesignerItemRectBase() | 60 | KReportDesignerItemRectBase::~KReportDesignerItemRectBase() | ||
58 | { | 61 | { | ||
62 | delete d; | ||||
59 | } | 63 | } | ||
60 | 64 | | |||
61 | QRectF KReportDesignerItemRectBase::sceneRect() | 65 | QRectF KReportDesignerItemRectBase::sceneRect() | ||
62 | { | 66 | { | ||
63 | return QRectF(m_ppos->toScene(), m_psize->toScene()); | 67 | return QRectF(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); | ||
64 | } | 68 | } | ||
65 | 69 | | |||
66 | QRectF KReportDesignerItemRectBase::pointRect() const | 70 | QRectF KReportDesignerItemRectBase::pointRect() const | ||
67 | { | 71 | { | ||
68 | if (m_ppos && m_psize) | 72 | 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 | } | 73 | } | ||
73 | 74 | | |||
74 | void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update) | 75 | void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, UpdatePropertyFlag update) | ||
75 | { | 76 | { | ||
76 | setSceneRect(QRectF(topLeft, size), update); | 77 | setSceneRect(QRectF(topLeft, size), update); | ||
77 | } | 78 | } | ||
78 | 79 | | |||
79 | void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, UpdatePropertyFlag update) | 80 | void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, UpdatePropertyFlag update) | ||
80 | { | 81 | { | ||
81 | QGraphicsRectItem::setPos(rect.x(), rect.y()); | 82 | QGraphicsRectItem::setPos(rect.x(), rect.y()); | ||
82 | setRect(0, 0, rect.width(), rect.height()); | 83 | setRect(0, 0, rect.width(), rect.height()); | ||
83 | if (update == UpdateProperty) { | 84 | if (update == UpdateProperty) { | ||
84 | m_ppos->setScenePos(QPointF(rect.x(), rect.y())); | 85 | item()->setPosition(KReportItemBase::positionFromScene(QPointF(rect.x(), rect.y()))); | ||
85 | m_psize->setSceneSize(QSizeF(rect.width(), rect.height())); | 86 | item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect.width(), rect.height()))); | ||
86 | } | 87 | } | ||
87 | this->update(); | 88 | this->update(); | ||
88 | } | 89 | } | ||
89 | 90 | | |||
90 | void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) | 91 | void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) | ||
91 | { | 92 | { | ||
92 | //Update and show properties | 93 | //Update and show properties | ||
93 | m_ppos->setScenePos(QPointF(sceneRect().x(), sceneRect().y())); | 94 | item()->setPosition(KReportItemBase::positionFromScene(QPointF(sceneRect().x(), sceneRect().y()))); | ||
94 | m_reportDesigner->changeSet(m_pset); | 95 | designer()->changeSet(item()->propertySet()); | ||
95 | setSelected(true); | 96 | setSelected(true); | ||
96 | scene()->update(); | 97 | scene()->update(); | ||
97 | 98 | | |||
98 | QGraphicsItem::mousePressEvent(event); | 99 | QGraphicsItem::mousePressEvent(event); | ||
99 | } | 100 | } | ||
100 | 101 | | |||
101 | void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) | 102 | void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) | ||
102 | { | 103 | { | ||
103 | //Keep the size and position in sync | 104 | //Keep the size and position in sync | ||
104 | m_ppos->setScenePos(pos()); | 105 | item()->setPosition(KReportItemBase::positionFromScene(pos())); | ||
105 | m_psize->setSceneSize(QSizeF(rect().width(), rect().height())); | 106 | item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect().width(), rect().height()))); | ||
staniek: 8X | |||||
106 | 107 | | |||
107 | QGraphicsItem::mouseReleaseEvent(event); | 108 | QGraphicsItem::mouseReleaseEvent(event); | ||
108 | } | 109 | } | ||
staniek: 8X | |||||
109 | 110 | | |||
110 | void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) | 111 | void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) | ||
111 | { | 112 | { | ||
112 | //kreportDebug() << m_grabAction; | 113 | //kreportDebug() << m_grabAction; | ||
113 | 114 | | |||
114 | qreal w, h; | 115 | qreal w, h; | ||
115 | 116 | | |||
116 | QPointF p = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(event->scenePos()); | 117 | QPointF p = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(event->scenePos()); | ||
117 | w = p.x() - scenePos().x(); | 118 | w = p.x() - scenePos().x(); | ||
118 | h = p.y() - scenePos().y(); | 119 | h = p.y() - scenePos().y(); | ||
119 | 120 | | |||
120 | //! @todo use an enum for the directions | 121 | //! @todo use an enum for the directions | ||
121 | 122 | | |||
122 | switch (m_grabAction) { | 123 | switch (d->grabAction) { | ||
123 | case 1: | 124 | case 1: | ||
124 | if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) | 125 | if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) | ||
125 | setSceneRect(QPointF(p.x(), p.y()), QSizeF(sceneRect().x() - p.x() + rect().width(), sceneRect().y() - p.y() + rect().height())); | 126 | setSceneRect(QPointF(p.x(), p.y()), QSizeF(sceneRect().x() - p.x() + rect().width(), sceneRect().y() - p.y() + rect().height())); | ||
126 | break; | 127 | break; | ||
127 | case 2: | 128 | case 2: | ||
128 | if (sceneRect().y() - p.y() + rect().height() >= 0) | 129 | if (sceneRect().y() - p.y() + rect().height() >= 0) | ||
129 | setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(rect().width(), sceneRect().y() - p.y() + rect().height())); | 130 | setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(rect().width(), sceneRect().y() - p.y() + rect().height())); | ||
130 | break; | 131 | break; | ||
Show All 26 Lines | |||||
157 | } | 158 | } | ||
158 | } | 159 | } | ||
159 | 160 | | |||
160 | void KReportDesignerItemRectBase::hoverMoveEvent(QGraphicsSceneHoverEvent * event) | 161 | void KReportDesignerItemRectBase::hoverMoveEvent(QGraphicsSceneHoverEvent * event) | ||
161 | { | 162 | { | ||
162 | //m_grabAction = 0; | 163 | //m_grabAction = 0; | ||
163 | 164 | | |||
164 | if (isSelected()) { | 165 | if (isSelected()) { | ||
165 | m_grabAction = grabHandle(event->pos()); | 166 | d->grabAction = grabHandle(event->pos()); | ||
166 | switch (m_grabAction) { | 167 | switch (d->grabAction) { | ||
167 | case 1: | 168 | case 1: | ||
168 | setCursor(Qt::SizeFDiagCursor); | 169 | setCursor(Qt::SizeFDiagCursor); | ||
169 | break; | 170 | break; | ||
170 | case 2: | 171 | case 2: | ||
171 | setCursor(Qt::SizeVerCursor); | 172 | setCursor(Qt::SizeVerCursor); | ||
172 | break; | 173 | break; | ||
173 | case 3: | 174 | case 3: | ||
174 | setCursor(Qt::SizeBDiagCursor); | 175 | setCursor(Qt::SizeBDiagCursor); | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 271 | if (change == ItemPositionChange && scene()) { | |||
278 | 279 | | |||
279 | if (newPos.y() < 0) | 280 | if (newPos.y() < 0) | ||
280 | newPos.setY(0); | 281 | newPos.setY(0); | ||
281 | else if (newPos.y() > (scene()->height() - rect().height())) | 282 | else if (newPos.y() > (scene()->height() - rect().height())) | ||
282 | newPos.setY(scene()->height() - rect().height()); | 283 | newPos.setY(scene()->height() - rect().height()); | ||
283 | 284 | | |||
284 | return newPos; | 285 | return newPos; | ||
285 | } else if (change == ItemPositionHasChanged && scene()) { | 286 | } else if (change == ItemPositionHasChanged && scene()) { | ||
286 | m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); | 287 | item()->setPosition(KReportItemBase::positionFromScene(value.toPointF())); | ||
287 | } else if (change == ItemSceneHasChanged && scene() && m_psize) { | 288 | //TODO dont update property | ||
289 | //m_ppos->setScenePos(value.toPointF(), KReportPosition::DontUpdateProperty); | ||||
290 | } else if (change == ItemSceneHasChanged && scene() && item()) { | ||||
288 | QPointF newPos = pos(); | 291 | QPointF newPos = pos(); | ||
289 | 292 | | |||
290 | newPos = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(newPos); | 293 | newPos = dynamic_cast<KReportDesignerSectionScene*>(scene())->gridPoint(newPos); | ||
291 | if (newPos.x() < 0) | 294 | if (newPos.x() < 0) | ||
292 | newPos.setX(0); | 295 | newPos.setX(0); | ||
293 | else if (newPos.x() > (scene()->width() - rect().width())) | 296 | else if (newPos.x() > (scene()->width() - rect().width())) | ||
294 | newPos.setX(scene()->width() - rect().width()); | 297 | newPos.setX(scene()->width() - rect().width()); | ||
295 | 298 | | |||
296 | if (newPos.y() < 0) | 299 | if (newPos.y() < 0) | ||
297 | newPos.setY(0); | 300 | newPos.setY(0); | ||
298 | else if (newPos.y() > (scene()->height() - rect().height())) | 301 | else if (newPos.y() > (scene()->height() - rect().height())) | ||
299 | newPos.setY(scene()->height() - rect().height()); | 302 | newPos.setY(scene()->height() - rect().height()); | ||
300 | 303 | | |||
301 | setSceneRect(newPos, m_psize->toScene(), KReportDesignerItemRectBase::DontUpdateProperty); | 304 | setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::DontUpdateProperty); | ||
302 | } | 305 | } | ||
303 | 306 | | |||
304 | return QGraphicsItem::itemChange(change, value); | 307 | return QGraphicsItem::itemChange(change, value); | ||
305 | } | 308 | } | ||
306 | 309 | | |||
307 | void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) | 310 | void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) | ||
308 | { | 311 | { | ||
309 | Q_UNUSED(s) | 312 | Q_UNUSED(s) | ||
310 | 313 | | |||
311 | if (p.name() == "position") { | 314 | if (p.name() == "position") { | ||
312 | m_ppos->setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); | 315 | item()->setPosition(p.value().toPointF()); //TODO dont update property | ||
313 | } else if (p.name() == "size") { | 316 | } else if (p.name() == "size") { | ||
314 | m_psize->setUnitSize(p.value().toSizeF(), KReportSize::DontUpdateProperty); | 317 | item()->setSize(p.value().toSizeF()); //TODO dont update property | ||
315 | } | 318 | } | ||
316 | 319 | | |||
317 | setSceneRect(m_ppos->toScene(), m_psize->toScene(), DontUpdateProperty); | 320 | setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()), DontUpdateProperty); | ||
318 | } | 321 | } | ||
319 | 322 | | |||
320 | void KReportDesignerItemRectBase::move(const QPointF& /*m*/) | 323 | void KReportDesignerItemRectBase::move(const QPointF& /*m*/) | ||
321 | { | 324 | { | ||
322 | //! @todo | 325 | //! @todo | ||
323 | } | 326 | } | ||
324 | 327 | | |||
325 | QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const | 328 | QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
367 | void KReportDesignerItemRectBase::exitInlineEditingMode() | 370 | void KReportDesignerItemRectBase::exitInlineEditingMode() | ||
368 | { | 371 | { | ||
369 | } | 372 | } | ||
370 | 373 | | |||
371 | void KReportDesignerItemBase::updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType) | 374 | void KReportDesignerItemBase::updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType) | ||
372 | { | 375 | { | ||
373 | if (itemDataSource.isEmpty()) { | 376 | if (itemDataSource.isEmpty()) { | ||
374 | if (itemType.isEmpty()) { | 377 | if (itemType.isEmpty()) { | ||
375 | m_renderText = itemStaticValue; | 378 | setRenderText(itemStaticValue); | ||
376 | } else { | 379 | } else { | ||
377 | m_renderText = dataSourceAndObjectTypeName(itemStaticValue, itemType); | 380 | setRenderText(dataSourceAndObjectTypeName(itemStaticValue, itemType)); | ||
378 | } | 381 | } | ||
379 | } else { | 382 | } else { | ||
380 | if (itemType.isEmpty()) { | 383 | if (itemType.isEmpty()) { | ||
381 | m_renderText = itemDataSource; | 384 | setRenderText(itemDataSource); | ||
382 | } else { | 385 | } else { | ||
383 | m_renderText = dataSourceAndObjectTypeName(itemDataSource, itemType); | 386 | setRenderText(dataSourceAndObjectTypeName(itemDataSource, itemType)); | ||
384 | } | 387 | } | ||
385 | } | 388 | } | ||
386 | } | 389 | } |
what about this?