Changeset View
Changeset View
Standalone View
Standalone View
src/items/label/KReportDesignerItemLabel.cpp
Show All 29 Lines | |||||
30 | #include <QTextCursor> | 30 | #include <QTextCursor> | ||
31 | #include <QTextDocument> | 31 | #include <QTextDocument> | ||
32 | 32 | | |||
33 | void KReportDesignerItemLabel::init(QGraphicsScene *scene, KReportDesigner *d) | 33 | void KReportDesignerItemLabel::init(QGraphicsScene *scene, KReportDesigner *d) | ||
34 | { | 34 | { | ||
35 | if (scene) | 35 | if (scene) | ||
36 | scene->addItem(this); | 36 | scene->addItem(this); | ||
37 | 37 | | |||
38 | KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); | | |||
39 | | ||||
40 | connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 38 | connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | ||
41 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | 39 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | ||
42 | 40 | | |||
43 | setZValue(Z); | 41 | setZValue(z()); | ||
44 | setFlag(ItemIsFocusable); | 42 | setFlag(ItemIsFocusable); | ||
45 | 43 | | |||
46 | m_inlineEdit = new BoundedTextItem(this); | 44 | m_inlineEdit = new BoundedTextItem(this); | ||
47 | m_inlineEdit->setVisible(false); | 45 | m_inlineEdit->setVisible(false); | ||
48 | m_inlineEdit->setFlag(ItemIsFocusable); | 46 | m_inlineEdit->setFlag(ItemIsFocusable); | ||
49 | m_inlineEdit->setFlag(ItemIsSelectable, false); | 47 | m_inlineEdit->setFlag(ItemIsSelectable, false); | ||
50 | QTextDocument *doc = new QTextDocument; | 48 | QTextDocument *doc = new QTextDocument; | ||
51 | doc->setDocumentMargin(0); | 49 | doc->setDocumentMargin(0); | ||
52 | doc->setPlainText(text()); | 50 | doc->setPlainText(text()); | ||
53 | m_inlineEdit->setDocument(doc); | 51 | m_inlineEdit->setDocument(doc); | ||
54 | 52 | | |||
55 | connect(m_inlineEdit, SIGNAL(exitEditMode()), this, SLOT(exitInlineEditingMode())); | 53 | connect(m_inlineEdit, SIGNAL(exitEditMode()), this, SLOT(exitInlineEditingMode())); | ||
56 | } | 54 | } | ||
57 | 55 | | |||
58 | // methods (constructors) | 56 | // methods (constructors) | ||
59 | KReportDesignerItemLabel::KReportDesignerItemLabel(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) | 57 | KReportDesignerItemLabel::KReportDesignerItemLabel(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) | ||
60 | : KReportDesignerItemRectBase(d) | 58 | : KReportDesignerItemRectBase(d, this) | ||
61 | { | 59 | { | ||
62 | Q_UNUSED(pos); | 60 | Q_UNUSED(pos); | ||
63 | init(scene, d); | 61 | init(scene, d); | ||
64 | setSceneRect(properRect(*d, getTextRect().width(), getTextRect().height())); | 62 | setSceneRect(properRect(*d, getTextRect().width(), getTextRect().height())); | ||
65 | m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); | 63 | nameProperty()->setValue(designer()->suggestEntityName(typeName())); | ||
66 | 64 | | |||
67 | enterInlineEditingMode(); | 65 | enterInlineEditingMode(); | ||
68 | } | 66 | } | ||
69 | 67 | | |||
70 | KReportDesignerItemLabel::KReportDesignerItemLabel(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) | 68 | KReportDesignerItemLabel::KReportDesignerItemLabel(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) | ||
71 | : KReportItemLabel(element), KReportDesignerItemRectBase(d), m_inlineEdit(0) | 69 | : KReportItemLabel(element), KReportDesignerItemRectBase(d, this), m_inlineEdit(0) | ||
72 | { | 70 | { | ||
73 | init(s, d); | 71 | init(s, d); | ||
74 | setSceneRect(m_pos.toScene(), m_size.toScene()); | 72 | setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); | ||
75 | } | 73 | } | ||
76 | 74 | | |||
77 | KReportDesignerItemLabel* KReportDesignerItemLabel::clone() | 75 | KReportDesignerItemLabel* KReportDesignerItemLabel::clone() | ||
78 | { | 76 | { | ||
79 | QDomDocument d; | 77 | QDomDocument d; | ||
80 | QDomElement e = d.createElement(QLatin1String("clone")); | 78 | QDomElement e = d.createElement(QLatin1String("clone")); | ||
81 | QDomNode n; | 79 | QDomNode n; | ||
82 | buildXML(&d, &e); | 80 | buildXML(&d, &e); | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
134 | } | 132 | } | ||
135 | 133 | | |||
136 | void KReportDesignerItemLabel::buildXML(QDomDocument *doc, QDomElement *parent) | 134 | void KReportDesignerItemLabel::buildXML(QDomDocument *doc, QDomElement *parent) | ||
137 | { | 135 | { | ||
138 | //kreportpluginDebug(); | 136 | //kreportpluginDebug(); | ||
139 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | 137 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | ||
140 | 138 | | |||
141 | // properties | 139 | // properties | ||
142 | addPropertyAsAttribute(&entity, m_name); | 140 | addPropertyAsAttribute(&entity, nameProperty()); | ||
143 | addPropertyAsAttribute(&entity, m_text); | 141 | addPropertyAsAttribute(&entity, m_text); | ||
144 | addPropertyAsAttribute(&entity, m_verticalAlignment); | 142 | addPropertyAsAttribute(&entity, m_verticalAlignment); | ||
145 | addPropertyAsAttribute(&entity, m_horizontalAlignment); | 143 | addPropertyAsAttribute(&entity, m_horizontalAlignment); | ||
146 | entity.setAttribute(QLatin1String("report:z-index"), zValue()); | 144 | entity.setAttribute(QLatin1String("report:z-index"), z()); | ||
147 | 145 | | |||
148 | // bounding rect | 146 | // bounding rect | ||
149 | buildXMLRect(doc, &entity, &m_pos, &m_size); | 147 | buildXMLRect(doc, &entity, this); | ||
150 | 148 | | |||
151 | //text style info | 149 | //text style info | ||
152 | buildXMLTextStyle(doc, &entity, textStyle()); | 150 | buildXMLTextStyle(doc, &entity, textStyle()); | ||
153 | 151 | | |||
154 | //Line Style | 152 | //Line Style | ||
155 | buildXMLLineStyle(doc, &entity, lineStyle()); | 153 | buildXMLLineStyle(doc, &entity, lineStyle()); | ||
156 | 154 | | |||
157 | parent->appendChild(entity); | 155 | parent->appendChild(entity); | ||
158 | } | 156 | } | ||
159 | 157 | | |||
160 | void KReportDesignerItemLabel::slotPropertyChanged(KPropertySet &s, KProperty &p) | 158 | void KReportDesignerItemLabel::slotPropertyChanged(KPropertySet &s, KProperty &p) | ||
161 | { | 159 | { | ||
162 | Q_UNUSED(s); | 160 | Q_UNUSED(s); | ||
163 | 161 | | |||
164 | if (p.name() == "name") { | 162 | if (p.name() == "name") { | ||
165 | //For some reason p.oldValue returns an empty string | 163 | //For some reason p.oldValue returns an empty string | ||
166 | if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { | 164 | if (!designer()->isEntityNameUnique(p.value().toString(), this)) { | ||
167 | p.setValue(m_oldName); | 165 | p.setValue(oldName()); | ||
168 | } else { | 166 | } else { | ||
169 | m_oldName = p.value().toString(); | 167 | setOldName(p.value().toString()); | ||
170 | } | 168 | } | ||
171 | } else if (p.name() == "caption") { | 169 | } else if (p.name() == "caption") { | ||
172 | m_inlineEdit->setPlainText(p.value().toString()); | 170 | m_inlineEdit->setPlainText(p.value().toString()); | ||
173 | } | 171 | } | ||
174 | 172 | | |||
175 | KReportDesignerItemRectBase::propertyChanged(s, p); | 173 | KReportDesignerItemRectBase::propertyChanged(s, p); | ||
176 | if (m_reportDesigner) m_reportDesigner->setModified(true); | 174 | if (designer()) designer()->setModified(true); | ||
177 | 175 | | |||
178 | } | 176 | } | ||
179 | 177 | | |||
180 | void KReportDesignerItemLabel::enterInlineEditingMode() | 178 | void KReportDesignerItemLabel::enterInlineEditingMode() | ||
181 | { | 179 | { | ||
182 | if (!m_inlineEdit->isVisible()) { | 180 | if (!m_inlineEdit->isVisible()) { | ||
183 | m_inlineEdit->setVisible(true); | 181 | m_inlineEdit->setVisible(true); | ||
184 | m_inlineEdit->setPlainText(text()); | 182 | m_inlineEdit->setPlainText(text()); | ||
Show All 39 Lines |