Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportItemBase.cpp
Show All 24 Lines | |||||
25 | #include <QDomElement> | 25 | #include <QDomElement> | ||
26 | 26 | | |||
27 | class Q_DECL_HIDDEN KReportItemBase::Private | 27 | class Q_DECL_HIDDEN KReportItemBase::Private | ||
28 | { | 28 | { | ||
29 | public: | 29 | public: | ||
30 | Private(); | 30 | Private(); | ||
31 | ~Private(); | 31 | ~Private(); | ||
32 | 32 | | |||
33 | void setUnit(const KReportUnit& u, bool force) | ||||
34 | { | ||||
35 | if (!force && unit == u) { | ||||
36 | return; | ||||
37 | } | ||||
38 | // convert values | ||||
39 | positionProperty->setValue( | ||||
40 | KReportUnit::convertFromUnitToUnit(positionProperty->value().toPointF(), unit, u), | ||||
41 | KProperty::DefaultValueOptions | ||||
42 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
43 | sizeProperty->setValue( | ||||
44 | KReportUnit::convertFromUnitToUnit(sizeProperty->value().toSizeF(), unit, u), | ||||
45 | KProperty::DefaultValueOptions | ||||
46 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
47 | | ||||
48 | // qDebug() << "Setting page unit to: " << u.symbol(); | ||||
49 | unit = u; | ||||
50 | positionProperty->setOption("suffix", u.symbol()); | ||||
51 | sizeProperty->setOption("suffix", u.symbol()); | ||||
52 | } | ||||
53 | | ||||
33 | KPropertySet *set; | 54 | KPropertySet *set; | ||
34 | KProperty *nameProperty; | 55 | KProperty *nameProperty; | ||
35 | KProperty *sizeProperty; | 56 | KProperty *sizeProperty; | ||
36 | KProperty *positionProperty; | 57 | KProperty *positionProperty; | ||
37 | QString oldName; | 58 | QString oldName; | ||
38 | qreal z = 0; | 59 | qreal z = 0; | ||
60 | KReportUnit unit; | ||||
39 | }; | 61 | }; | ||
40 | 62 | | |||
41 | KReportItemBase::Private::Private() | 63 | KReportItemBase::Private::Private() | ||
42 | { | 64 | { | ||
43 | set = new KPropertySet(); | 65 | set = new KPropertySet(); | ||
44 | nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); | 66 | nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name")); | ||
45 | nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut); | 67 | nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut); | ||
46 | 68 | | |||
47 | positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); | 69 | positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position")); | ||
48 | sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); | 70 | sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size")); | ||
71 | setUnit(DEFAULT_UNIT, true); | ||||
49 | 72 | | |||
50 | set->addProperty(nameProperty); | 73 | set->addProperty(nameProperty); | ||
51 | set->addProperty(positionProperty); | 74 | set->addProperty(positionProperty); | ||
52 | set->addProperty(sizeProperty); | 75 | set->addProperty(sizeProperty); | ||
53 | } | 76 | } | ||
54 | 77 | | |||
55 | KReportItemBase::Private::~Private() | 78 | KReportItemBase::Private::~Private() | ||
56 | { | 79 | { | ||
Show All 20 Lines | |||||
77 | bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) | 100 | bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls) | ||
78 | { | 101 | { | ||
79 | return KReportUtils::parseReportLineStyleData(elemSource, ls); | 102 | return KReportUtils::parseReportLineStyleData(elemSource, ls); | ||
80 | } | 103 | } | ||
81 | 104 | | |||
82 | 105 | | |||
83 | bool KReportItemBase::parseReportRect(const QDomElement & elemSource) | 106 | bool KReportItemBase::parseReportRect(const QDomElement & elemSource) | ||
84 | { | 107 | { | ||
85 | QPointF pos; | 108 | const QRectF r(KReportUtils::readRectAttributes(elemSource, DEFAULT_ELEMENT_RECT_PT)); | ||
86 | QSizeF size; | 109 | setPosition(r.topLeft()); | ||
87 | 110 | setSize(r.size()); | |||
88 | pos.setX(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:x"), QLatin1String("1cm")))); | | |||
89 | pos.setY(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:y"), QLatin1String("1cm")))); | | |||
90 | size.setWidth(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:width"), QLatin1String("1cm")))); | | |||
91 | size.setHeight(KReportUnit::parseValue(elemSource.attribute(QLatin1String("svg:height"), QLatin1String("1cm")))); | | |||
92 | | ||||
93 | setPosition(pos); | | |||
94 | setSize(size); | | |||
95 | | ||||
96 | return true; | 111 | return true; | ||
112 | } | ||||
97 | 113 | | |||
114 | KReportUnit KReportItemBase::unit() const | ||||
115 | { | ||||
116 | return d->unit; | ||||
98 | } | 117 | } | ||
99 | 118 | | |||
100 | void KReportItemBase::setUnit(const KReportUnit& u) | 119 | void KReportItemBase::setUnit(const KReportUnit& u) | ||
101 | { | 120 | { | ||
102 | qDebug() << "Setting page unit to: " << u.symbol(); | 121 | d->setUnit(u, false); | ||
103 | d->positionProperty->setOption("unit", u.symbol()); | | |||
104 | d->sizeProperty->setOption("unit", u.symbol()); | | |||
105 | } | 122 | } | ||
106 | 123 | | |||
107 | int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | 124 | int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, | ||
108 | const QVariant &data, KReportScriptHandler* script) | 125 | const QVariant &data, KReportScriptHandler* script) | ||
109 | { | 126 | { | ||
110 | Q_UNUSED(page) | 127 | Q_UNUSED(page) | ||
111 | Q_UNUSED(section) | 128 | Q_UNUSED(section) | ||
112 | Q_UNUSED(offset) | 129 | Q_UNUSED(offset) | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
163 | 180 | | |||
164 | void KReportItemBase::setOldName(const QString& old) | 181 | void KReportItemBase::setOldName(const QString& old) | ||
165 | { | 182 | { | ||
166 | d->oldName = old; | 183 | d->oldName = old; | ||
167 | } | 184 | } | ||
168 | 185 | | |||
169 | QPointF KReportItemBase::position() const | 186 | QPointF KReportItemBase::position() const | ||
170 | { | 187 | { | ||
171 | return d->positionProperty->value().toPointF(); | 188 | return d->unit.convertToPoint(d->positionProperty->value().toPointF()); | ||
172 | } | 189 | } | ||
173 | 190 | | |||
174 | QSizeF KReportItemBase::size() const | 191 | QSizeF KReportItemBase::size() const | ||
175 | { | 192 | { | ||
176 | return d->sizeProperty->value().toSizeF(); | 193 | return d->unit.convertToPoint(d->sizeProperty->value().toSizeF()); | ||
177 | } | 194 | } | ||
178 | 195 | | |||
179 | const KPropertySet * KReportItemBase::propertySet() const | 196 | const KPropertySet * KReportItemBase::propertySet() const | ||
180 | { | 197 | { | ||
181 | return d->set; | 198 | return d->set; | ||
182 | } | 199 | } | ||
183 | 200 | | |||
184 | QPointF KReportItemBase::scenePosition(const QPointF &pos) | 201 | QPointF KReportItemBase::scenePosition(const QPointF &ptPos) | ||
185 | { | 202 | { | ||
186 | const qreal x = POINT_TO_INCH(pos.x()) * KReportPrivate::dpiX(); | 203 | const qreal x = POINT_TO_INCH(ptPos.x()) * KReportPrivate::dpiX(); | ||
187 | const qreal y = POINT_TO_INCH(pos.y()) * KReportPrivate::dpiY(); | 204 | const qreal y = POINT_TO_INCH(ptPos.y()) * KReportPrivate::dpiY(); | ||
188 | return QPointF(x, y); | 205 | return QPointF(x, y); | ||
189 | } | 206 | } | ||
190 | 207 | | |||
191 | QSizeF KReportItemBase::sceneSize(const QSizeF &size) | 208 | QSizeF KReportItemBase::sceneSize(const QSizeF &ptSize) | ||
192 | { | 209 | { | ||
193 | const qreal w = POINT_TO_INCH(size.width()) * KReportPrivate::dpiX(); | 210 | const qreal w = POINT_TO_INCH(ptSize.width()) * KReportPrivate::dpiX(); | ||
194 | const qreal h = POINT_TO_INCH(size.height()) * KReportPrivate::dpiY(); | 211 | const qreal h = POINT_TO_INCH(ptSize.height()) * KReportPrivate::dpiY(); | ||
195 | return QSizeF(w, h); | 212 | return QSizeF(w, h); | ||
196 | } | 213 | } | ||
197 | 214 | | |||
198 | qreal KReportItemBase::z() const | 215 | qreal KReportItemBase::z() const | ||
199 | { | 216 | { | ||
200 | return d->z; | 217 | return d->z; | ||
201 | } | 218 | } | ||
202 | 219 | | |||
203 | void KReportItemBase::setZ(qreal z) | 220 | void KReportItemBase::setZ(qreal z) | ||
204 | { | 221 | { | ||
205 | d->z = z; | 222 | d->z = z; | ||
206 | } | 223 | } | ||
207 | 224 | | |||
208 | void KReportItemBase::setPosition(const QPointF& pos) | 225 | void KReportItemBase::setPosition(const QPointF& ptPos) | ||
209 | { | 226 | { | ||
210 | d->positionProperty->setValue(pos); | 227 | d->positionProperty->setValue(d->unit.convertFromPoint(ptPos)); | ||
211 | } | 228 | } | ||
212 | 229 | | |||
213 | void KReportItemBase::setSize(const QSizeF& size) | 230 | void KReportItemBase::setSize(const QSizeF &ptSize) | ||
214 | { | 231 | { | ||
215 | d->sizeProperty->setValue(size); | 232 | d->sizeProperty->setValue(d->unit.convertFromPoint(ptSize)); | ||
216 | } | 233 | } | ||
217 | 234 | | |||
218 | QPointF KReportItemBase::positionFromScene(const QPointF& pos) | 235 | QPointF KReportItemBase::positionFromScene(const QPointF& pos) | ||
219 | { | 236 | { | ||
220 | const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX()); | 237 | const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX()); | ||
221 | const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY()); | 238 | const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY()); | ||
222 | return QPointF(x, y); | 239 | return QPointF(x, y); | ||
223 | } | 240 | } | ||
224 | 241 | | |||
225 | QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) | 242 | QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) | ||
226 | { | 243 | { | ||
227 | qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX()); | 244 | qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX()); | ||
228 | qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY()); | 245 | qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY()); | ||
229 | return QSizeF(w, h); | 246 | return QSizeF(w, h); | ||
230 | } | 247 | } | ||
231 | 248 | | |||
232 | void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) | 249 | void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p) | ||
233 | { | 250 | { | ||
234 | Q_UNUSED(s) | 251 | Q_UNUSED(s) | ||
235 | Q_UNUSED(p) | 252 | Q_UNUSED(p) | ||
236 | } | 253 | } | ||
237 | 254 | | |||
238 | 255 | | |||
staniek: Minor
Move { to new line | |||||
239 | 256 | |
Minor
Move { to new line