Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportDesignerItemLine.cpp
Show All 27 Lines | |||||
28 | #include <QGraphicsScene> | 28 | #include <QGraphicsScene> | ||
29 | #include <QGraphicsSceneMouseEvent> | 29 | #include <QGraphicsSceneMouseEvent> | ||
30 | 30 | | |||
31 | // | 31 | // | ||
32 | // class ReportEntityLine | 32 | // class ReportEntityLine | ||
33 | // | 33 | // | ||
34 | void KReportDesignerItemLine::init(QGraphicsScene* s, KReportDesigner *r) | 34 | void KReportDesignerItemLine::init(QGraphicsScene* s, KReportDesigner *r) | ||
35 | { | 35 | { | ||
36 | m_reportDesigner = r; | | |||
37 | setPos(0, 0); | 36 | setPos(0, 0); | ||
38 | setUnit(r->pageUnit()); | 37 | setUnit(r->pageUnit()); | ||
39 | 38 | | |||
39 | nameProperty()->setValue(r->suggestEntityName(typeName())); | ||||
40 | | ||||
40 | setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); | 41 | setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); | ||
41 | 42 | | |||
42 | setPen(QPen(Qt::black, 5)); | 43 | setPen(QPen(Qt::black, 5)); | ||
43 | setAcceptHoverEvents(true); | 44 | setAcceptHoverEvents(true); | ||
44 | 45 | | |||
45 | if (s) | 46 | if (s) | ||
46 | s->addItem(this); | 47 | s->addItem(this); | ||
47 | 48 | | |||
48 | connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 49 | setZValue(z()); | ||
49 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | | |||
50 | | ||||
51 | setZValue(Z); | | |||
52 | } | 50 | } | ||
53 | 51 | | |||
54 | KReportDesignerItemLine::KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &pos) | 52 | KReportDesignerItemLine::KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &pos) | ||
55 | : KReportDesignerItemBase(d) | 53 | : KReportDesignerItemBase(d, this) | ||
56 | { | 54 | { | ||
57 | init(scene, d); | 55 | init(scene, d); | ||
58 | setLineScene(QLineF(pos, QPointF(20,20)+pos)); | 56 | setLineScene(QLineF(pos, QPointF(20,20)+pos)); | ||
59 | m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); | 57 | | ||
60 | } | 58 | } | ||
61 | 59 | | |||
62 | KReportDesignerItemLine::KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &startPos, const QPointF &endPos) | 60 | KReportDesignerItemLine::KReportDesignerItemLine(KReportDesigner * d, QGraphicsScene * scene, const QPointF &startPos, const QPointF &endPos) | ||
63 | : KReportDesignerItemBase(d) | 61 | : KReportDesignerItemBase(d, this) | ||
64 | { | 62 | { | ||
65 | init(scene, d); | 63 | init(scene, d); | ||
66 | setLineScene(QLineF(startPos, endPos)); | 64 | setLineScene(QLineF(startPos, endPos)); | ||
67 | m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); | | |||
68 | | ||||
69 | } | 65 | } | ||
70 | 66 | | |||
71 | KReportDesignerItemLine::KReportDesignerItemLine(const QDomNode & entity, KReportDesigner * d, QGraphicsScene * scene) | 67 | KReportDesignerItemLine::KReportDesignerItemLine(const QDomNode & entity, KReportDesigner * d, QGraphicsScene * scene) | ||
72 | : KReportItemLine(entity), KReportDesignerItemBase(d) | 68 | : KReportItemLine(entity), KReportDesignerItemBase(d, this) | ||
73 | { | 69 | { | ||
74 | init(scene, d); | 70 | init(scene, d); | ||
75 | setLine ( m_start.toScene().x(), m_start.toScene().y(), m_end.toScene().x(), m_end.toScene().y() ); | 71 | setLine ( m_start.toScene().x(), m_start.toScene().y(), m_end.toScene().x(), m_end.toScene().y() ); | ||
76 | } | 72 | } | ||
77 | 73 | | |||
78 | KReportDesignerItemLine* KReportDesignerItemLine::clone() | 74 | KReportDesignerItemLine* KReportDesignerItemLine::clone() | ||
79 | { | 75 | { | ||
80 | QDomDocument d; | 76 | QDomDocument d; | ||
Show All 27 Lines | 86 | { | |||
108 | } | 104 | } | ||
109 | } | 105 | } | ||
110 | 106 | | |||
111 | void KReportDesignerItemLine::buildXML(QDomDocument *doc, QDomElement *parent) | 107 | void KReportDesignerItemLine::buildXML(QDomDocument *doc, QDomElement *parent) | ||
112 | { | 108 | { | ||
113 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | 109 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | ||
114 | 110 | | |||
115 | // properties | 111 | // properties | ||
116 | addPropertyAsAttribute(&entity, m_name); | 112 | addPropertyAsAttribute(&entity, nameProperty()); | ||
117 | entity.setAttribute(QLatin1String("report:z-index"), zValue()); | 113 | entity.setAttribute(QLatin1String("report:z-index"), zValue()); | ||
118 | KReportUtils::setAttribute(&entity, QLatin1String("svg:x1"), m_start.toPoint().x()); | 114 | KReportUtils::setAttribute(&entity, QLatin1String("svg:x1"), m_start.toPoint().x()); | ||
119 | KReportUtils::setAttribute(&entity, QLatin1String("svg:y1"), m_start.toPoint().y()); | 115 | KReportUtils::setAttribute(&entity, QLatin1String("svg:y1"), m_start.toPoint().y()); | ||
120 | KReportUtils::setAttribute(&entity, QLatin1String("svg:x2"), m_end.toPoint().x()); | 116 | KReportUtils::setAttribute(&entity, QLatin1String("svg:x2"), m_end.toPoint().x()); | ||
121 | KReportUtils::setAttribute(&entity, QLatin1String("svg:y2"), m_end.toPoint().y()); | 117 | KReportUtils::setAttribute(&entity, QLatin1String("svg:y2"), m_end.toPoint().y()); | ||
122 | 118 | | |||
123 | buildXMLLineStyle(doc, &entity, lineStyle()); | 119 | buildXMLLineStyle(doc, &entity, lineStyle()); | ||
124 | 120 | | |||
125 | parent->appendChild(entity); | 121 | parent->appendChild(entity); | ||
126 | } | 122 | } | ||
127 | 123 | | |||
128 | void KReportDesignerItemLine::slotPropertyChanged(KPropertySet &s, KProperty &p) | 124 | void KReportDesignerItemLine::propertyChanged(KPropertySet &s, KProperty &p) | ||
129 | { | 125 | { | ||
130 | Q_UNUSED(s); | 126 | Q_UNUSED(s); | ||
131 | 127 | | |||
132 | if (p.name() == "Start" || p.name() == "End") { | 128 | if (p.name() == "Start" || p.name() == "End") { | ||
133 | if (p.name() == "Start") | 129 | if (p.name() == "Start") | ||
134 | m_start.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); | 130 | m_start.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); | ||
135 | if (p.name() == "End") | 131 | if (p.name() == "End") | ||
136 | m_end.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); | 132 | m_end.setUnitPos(p.value().toPointF(), KReportPosition::DontUpdateProperty); | ||
137 | 133 | | |||
138 | setLine(m_start.toScene().x(), m_start.toScene().y(), m_end.toScene().x(), m_end.toScene().y()); | 134 | setLine(m_start.toScene().x(), m_start.toScene().y(), m_end.toScene().x(), m_end.toScene().y()); | ||
139 | } | 135 | } | ||
140 | else if (p.name() == "name") { | 136 | else if (p.name() == "name") { | ||
141 | //For some reason p.oldValue returns an empty string | 137 | //For some reason p.oldValue returns an empty string | ||
142 | if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { | 138 | if (!designer()->isEntityNameUnique(p.value().toString(), this)) { | ||
143 | p.setValue(m_oldName); | 139 | p.setValue(oldName()); | ||
144 | } else { | 140 | } else { | ||
145 | m_oldName = p.value().toString(); | 141 | setOldName(p.value().toString()); | ||
146 | } | 142 | } | ||
147 | } | 143 | } | ||
148 | if (m_reportDesigner) | 144 | if (designer()) | ||
149 | m_reportDesigner->setModified(true); | 145 | designer()->setModified(true); | ||
150 | 146 | | |||
151 | update(); | 147 | update(); | ||
152 | } | 148 | } | ||
153 | 149 | | |||
154 | void KReportDesignerItemLine::mousePressEvent(QGraphicsSceneMouseEvent * event) | 150 | void KReportDesignerItemLine::mousePressEvent(QGraphicsSceneMouseEvent * event) | ||
155 | { | 151 | { | ||
156 | m_reportDesigner->changeSet(m_set); | 152 | designer()->changeSet(propertySet()); | ||
157 | setSelected(true); | 153 | setSelected(true); | ||
158 | QGraphicsLineItem::mousePressEvent(event); | 154 | QGraphicsLineItem::mousePressEvent(event); | ||
159 | } | 155 | } | ||
160 | 156 | | |||
161 | QVariant KReportDesignerItemLine::itemChange(GraphicsItemChange change, const QVariant &value) | 157 | QVariant KReportDesignerItemLine::itemChange(GraphicsItemChange change, const QVariant &value) | ||
162 | { | 158 | { | ||
163 | return QGraphicsItem::itemChange(change, value); | 159 | return QGraphicsItem::itemChange(change, value); | ||
164 | } | 160 | } | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
240 | void KReportDesignerItemLine::setLineScene(QLineF l) | 236 | void KReportDesignerItemLine::setLineScene(QLineF l) | ||
241 | { | 237 | { | ||
242 | m_start.setScenePos(l.p1(), KReportPosition::DontUpdateProperty); | 238 | m_start.setScenePos(l.p1(), KReportPosition::DontUpdateProperty); | ||
243 | m_end.setScenePos(l.p2()); | 239 | m_end.setScenePos(l.p2()); | ||
244 | } | 240 | } | ||
245 | 241 | | |||
246 | void KReportDesignerItemLine::move(const QPointF& m) | 242 | void KReportDesignerItemLine::move(const QPointF& m) | ||
247 | { | 243 | { | ||
248 | QPointF original = m_pos.toScene(); | 244 | QPointF original = scenePosition(position()); | ||
249 | original += m; | 245 | original += m; | ||
250 | m_pos.setScenePos(original); | 246 | | ||
247 | setPosition(positionFromScene(original)); | ||||
251 | } | 248 | } |