Changeset View
Changeset View
Standalone View
Standalone View
src/items/field/KReportDesignerItemField.cpp
Show All 30 Lines | |||||
31 | // class ReportEntityField | 31 | // class ReportEntityField | ||
32 | // | 32 | // | ||
33 | 33 | | |||
34 | void KReportDesignerItemField::init(QGraphicsScene * scene, KReportDesigner * d) | 34 | void KReportDesignerItemField::init(QGraphicsScene * scene, KReportDesigner * d) | ||
35 | { | 35 | { | ||
36 | if (scene) | 36 | if (scene) | ||
37 | scene->addItem(this); | 37 | scene->addItem(this); | ||
38 | 38 | | |||
39 | KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); | 39 | setZValue(z()); | ||
40 | | ||||
41 | connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | | |||
42 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | | |||
43 | | ||||
44 | setZValue(Z); | | |||
45 | 40 | | |||
46 | updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); | 41 | updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); | ||
47 | } | 42 | } | ||
48 | 43 | | |||
49 | // methods (constructors) | 44 | // methods (constructors) | ||
50 | KReportDesignerItemField::KReportDesignerItemField(KReportDesigner * rw, QGraphicsScene * scene, const QPointF &pos) | 45 | KReportDesignerItemField::KReportDesignerItemField(KReportDesigner * rw, QGraphicsScene * scene, const QPointF &pos) | ||
51 | : KReportDesignerItemRectBase(rw) | 46 | : KReportDesignerItemRectBase(rw, this) | ||
52 | { | 47 | { | ||
53 | Q_UNUSED(pos); | 48 | Q_UNUSED(pos); | ||
54 | init(scene, rw); | 49 | init(scene, rw); | ||
55 | setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height())); | 50 | setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height())); | ||
56 | m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); | 51 | nameProperty()->setValue(designer()->suggestEntityName(typeName())); | ||
57 | } | 52 | } | ||
58 | 53 | | |||
59 | KReportDesignerItemField::KReportDesignerItemField(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) | 54 | KReportDesignerItemField::KReportDesignerItemField(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) | ||
60 | : KReportItemField(element), KReportDesignerItemRectBase(d) | 55 | : KReportItemField(element), KReportDesignerItemRectBase(d, this) | ||
61 | { | 56 | { | ||
62 | init(s, d); | 57 | init(s, d); | ||
63 | setSceneRect(m_pos.toScene(), m_size.toScene()); | 58 | setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); | ||
64 | } | 59 | } | ||
65 | 60 | | |||
66 | KReportDesignerItemField* KReportDesignerItemField::clone() | 61 | KReportDesignerItemField* KReportDesignerItemField::clone() | ||
67 | { | 62 | { | ||
68 | QDomDocument d; | 63 | QDomDocument d; | ||
69 | QDomElement e = d.createElement(QLatin1String("clone")); | 64 | QDomElement e = d.createElement(QLatin1String("clone")); | ||
70 | QDomNode n; | 65 | QDomNode n; | ||
71 | buildXML(&d, &e); | 66 | buildXML(&d, &e); | ||
72 | n = e.firstChild(); | 67 | n = e.firstChild(); | ||
73 | return new KReportDesignerItemField(n, designer(), 0); | 68 | return new KReportDesignerItemField(n, designer(), 0); | ||
74 | } | 69 | } | ||
75 | 70 | | |||
76 | // methods (deconstructor) | 71 | // methods (deconstructor) | ||
77 | KReportDesignerItemField::~KReportDesignerItemField() | 72 | KReportDesignerItemField::~KReportDesignerItemField() | ||
78 | {} | 73 | {} | ||
79 | 74 | | |||
80 | QRect KReportDesignerItemField::getTextRect() const | 75 | QRect KReportDesignerItemField::getTextRect() const | ||
81 | { | 76 | { | ||
82 | return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), m_renderText); | 77 | return QFontMetrics(font()).boundingRect(x(), y(), 0, 0, textFlags(), renderText()); | ||
83 | } | 78 | } | ||
84 | 79 | | |||
85 | 80 | | |||
86 | 81 | | |||
87 | void KReportDesignerItemField::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget) | 82 | void KReportDesignerItemField::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget) | ||
88 | { | 83 | { | ||
89 | Q_UNUSED(option); | 84 | Q_UNUSED(option); | ||
90 | Q_UNUSED(widget); | 85 | Q_UNUSED(widget); | ||
91 | 86 | | |||
92 | // store any values we plan on changing so we can restore them | 87 | // store any values we plan on changing so we can restore them | ||
93 | QFont f = painter->font(); | 88 | QFont f = painter->font(); | ||
94 | QPen p = painter->pen(); | 89 | QPen p = painter->pen(); | ||
95 | 90 | | |||
96 | 91 | | |||
97 | painter->setFont(font()); | 92 | painter->setFont(font()); | ||
98 | painter->setBackgroundMode(Qt::TransparentMode); | 93 | painter->setBackgroundMode(Qt::TransparentMode); | ||
99 | 94 | | |||
100 | QColor bg = m_backgroundColor->value().value<QColor>(); | 95 | QColor bg = m_backgroundColor->value().value<QColor>(); | ||
101 | bg.setAlphaF(m_backgroundOpacity->value().toReal() *0.01); | 96 | bg.setAlphaF(m_backgroundOpacity->value().toReal() *0.01); | ||
102 | 97 | | |||
103 | painter->setPen(m_foregroundColor->value().value<QColor>()); | 98 | painter->setPen(m_foregroundColor->value().value<QColor>()); | ||
104 | 99 | | |||
105 | painter->fillRect(QGraphicsRectItem::rect(), bg); | 100 | painter->fillRect(QGraphicsRectItem::rect(), bg); | ||
106 | painter->drawText(rect(), textFlags(), m_renderText); | 101 | painter->drawText(rect(), textFlags(), renderText()); | ||
107 | 102 | | |||
108 | 103 | | |||
109 | if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { | 104 | if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { | ||
110 | painter->setPen(QPen(Qt::lightGray)); | 105 | painter->setPen(QPen(Qt::lightGray)); | ||
111 | } else { | 106 | } else { | ||
112 | painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); | 107 | painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); | ||
113 | } | 108 | } | ||
114 | 109 | | |||
115 | painter->drawRect(rect()); | 110 | painter->drawRect(rect()); | ||
116 | 111 | | |||
117 | 112 | | |||
118 | drawHandles(painter); | 113 | drawHandles(painter); | ||
119 | 114 | | |||
120 | // restore an values before we started just in case | 115 | // restore an values before we started just in case | ||
121 | painter->setFont(f); | 116 | painter->setFont(f); | ||
122 | painter->setPen(p); | 117 | painter->setPen(p); | ||
123 | } | 118 | } | ||
124 | 119 | | |||
125 | void KReportDesignerItemField::buildXML(QDomDocument *doc, QDomElement *parent) | 120 | void KReportDesignerItemField::buildXML(QDomDocument *doc, QDomElement *parent) | ||
126 | { | 121 | { | ||
127 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | 122 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | ||
128 | 123 | | |||
129 | // properties | 124 | // properties | ||
130 | addPropertyAsAttribute(&entity, m_name); | 125 | addPropertyAsAttribute(&entity, nameProperty()); | ||
131 | addPropertyAsAttribute(&entity, m_controlSource); | 126 | addPropertyAsAttribute(&entity, m_controlSource); | ||
132 | addPropertyAsAttribute(&entity, m_verticalAlignment); | 127 | addPropertyAsAttribute(&entity, m_verticalAlignment); | ||
133 | addPropertyAsAttribute(&entity, m_horizontalAlignment); | 128 | addPropertyAsAttribute(&entity, m_horizontalAlignment); | ||
134 | addPropertyAsAttribute(&entity, m_wordWrap); | 129 | addPropertyAsAttribute(&entity, m_wordWrap); | ||
135 | addPropertyAsAttribute(&entity, m_canGrow); | 130 | addPropertyAsAttribute(&entity, m_canGrow); | ||
136 | addPropertyAsAttribute(&entity, m_itemValue); | 131 | addPropertyAsAttribute(&entity, m_itemValue); | ||
137 | 132 | | |||
138 | entity.setAttribute(QLatin1String("report:z-index"), zValue()); | 133 | entity.setAttribute(QLatin1String("report:z-index"), zValue()); | ||
139 | 134 | | |||
140 | // bounding rect | 135 | // bounding rect | ||
141 | buildXMLRect(doc, &entity, &m_pos, &m_size); | 136 | buildXMLRect(doc, &entity, this); | ||
142 | 137 | | |||
143 | //text style info | 138 | //text style info | ||
144 | buildXMLTextStyle(doc, &entity, textStyle()); | 139 | buildXMLTextStyle(doc, &entity, textStyle()); | ||
145 | 140 | | |||
146 | //Line Style | 141 | //Line Style | ||
147 | buildXMLLineStyle(doc, &entity, lineStyle()); | 142 | buildXMLLineStyle(doc, &entity, lineStyle()); | ||
148 | 143 | | |||
149 | 144 | | |||
Show All 13 Lines | |||||
163 | } | 158 | } | ||
164 | 159 | | |||
165 | void KReportDesignerItemField::slotPropertyChanged(KPropertySet &s, KProperty &p) | 160 | void KReportDesignerItemField::slotPropertyChanged(KPropertySet &s, KProperty &p) | ||
166 | { | 161 | { | ||
167 | Q_UNUSED(s); | 162 | Q_UNUSED(s); | ||
168 | 163 | | |||
169 | if (p.name() == "name") { | 164 | if (p.name() == "name") { | ||
170 | //For some reason p.oldValue returns an empty string | 165 | //For some reason p.oldValue returns an empty string | ||
171 | if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { | 166 | if (!designer()->isEntityNameUnique(p.value().toString(), this)) { | ||
172 | p.setValue(m_oldName); | 167 | p.setValue(oldName()); | ||
173 | } else { | 168 | } else { | ||
174 | m_oldName = p.value().toString(); | 169 | setOldName(p.value().toString()); | ||
175 | } | 170 | } | ||
176 | } | 171 | } | ||
177 | 172 | | |||
178 | updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); | 173 | updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field")); | ||
179 | 174 | | |||
180 | KReportDesignerItemRectBase::propertyChanged(s, p); | 175 | KReportDesignerItemRectBase::propertyChanged(s, p); | ||
181 | if (m_reportDesigner)m_reportDesigner->setModified(true); | 176 | if (designer())designer()->setModified(true); | ||
182 | } | 177 | } | ||
183 | 178 | | |||
184 | void KReportDesignerItemField::mousePressEvent(QGraphicsSceneMouseEvent * event) | 179 | void KReportDesignerItemField::mousePressEvent(QGraphicsSceneMouseEvent * event) | ||
185 | { | 180 | { | ||
186 | //kreportpluginDebug() << m_reportDesigner->fieldKeys() << m_reportDesigner->fieldNames(); | 181 | //kreportpluginDebug() << m_reportDesigner->fieldKeys() << m_reportDesigner->fieldNames(); | ||
187 | m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); | 182 | m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); | ||
188 | KReportDesignerItemRectBase::mousePressEvent(event); | 183 | KReportDesignerItemRectBase::mousePressEvent(event); | ||
189 | } | 184 | } | ||
190 | 185 | | |||
191 | 186 | |