Changeset View
Changeset View
Standalone View
Standalone View
src/items/check/KReportDesignerItemCheckBox.cpp
Show All 28 Lines | |||||
29 | // class ReportEntityCheck | 29 | // class ReportEntityCheck | ||
30 | // | 30 | // | ||
31 | 31 | | |||
32 | void KReportDesignerItemCheckBox::init(QGraphicsScene *scene, KReportDesigner *d) | 32 | void KReportDesignerItemCheckBox::init(QGraphicsScene *scene, KReportDesigner *d) | ||
33 | { | 33 | { | ||
34 | if (scene) | 34 | if (scene) | ||
35 | scene->addItem(this); | 35 | scene->addItem(this); | ||
36 | 36 | | |||
37 | KReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d); | | |||
38 | | ||||
39 | connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 37 | connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | ||
40 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | 38 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | ||
41 | 39 | | |||
42 | setZValue(Z); | 40 | setZValue(z()); | ||
43 | } | 41 | } | ||
44 | 42 | | |||
45 | // methods (constructors) | 43 | // methods (constructors) | ||
46 | KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) | 44 | KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos) | ||
47 | : KReportDesignerItemRectBase(d) | 45 | : KReportDesignerItemRectBase(d, this) | ||
48 | { | 46 | { | ||
49 | Q_UNUSED(pos); | 47 | Q_UNUSED(pos); | ||
50 | init(scene, d); | 48 | init(scene, d); | ||
51 | setSceneRect(properRect(*d, KREPORT_ITEM_CHECK_DEFAULT_WIDTH, KREPORT_ITEM_CHECK_DEFAULT_HEIGHT)); | 49 | setSceneRect(properRect(*d, KREPORT_ITEM_CHECK_DEFAULT_WIDTH, KREPORT_ITEM_CHECK_DEFAULT_HEIGHT)); | ||
52 | m_name->setValue(m_reportDesigner->suggestEntityName(typeName())); | 50 | nameProperty()->setValue(designer()->suggestEntityName(typeName())); | ||
53 | } | 51 | } | ||
54 | 52 | | |||
55 | KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) | 53 | KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s) | ||
56 | : KReportItemCheckBox(element), KReportDesignerItemRectBase(d) | 54 | : KReportItemCheckBox(element), KReportDesignerItemRectBase(d, this) | ||
57 | { | 55 | { | ||
58 | init(s, d); | 56 | init(s, d); | ||
59 | setSceneRect(m_pos.toScene(), m_size.toScene()); | 57 | setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); | ||
60 | } | 58 | } | ||
61 | 59 | | |||
62 | KReportDesignerItemCheckBox* KReportDesignerItemCheckBox::clone() | 60 | KReportDesignerItemCheckBox* KReportDesignerItemCheckBox::clone() | ||
63 | { | 61 | { | ||
64 | QDomDocument d; | 62 | QDomDocument d; | ||
65 | QDomElement e = d.createElement(QLatin1String("clone")); | 63 | QDomElement e = d.createElement(QLatin1String("clone")); | ||
66 | QDomNode n; | 64 | QDomNode n; | ||
67 | buildXML(&d, &e); | 65 | buildXML(&d, &e); | ||
Show All 21 Lines | 75 | { | |||
89 | painter->setPen(m_foregroundColor->value().value<QColor>()); | 87 | painter->setPen(m_foregroundColor->value().value<QColor>()); | ||
90 | 88 | | |||
91 | if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { | 89 | if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) { | ||
92 | painter->setPen(QPen(Qt::lightGray)); | 90 | painter->setPen(QPen(Qt::lightGray)); | ||
93 | } else { | 91 | } else { | ||
94 | painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); | 92 | painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt())); | ||
95 | } | 93 | } | ||
96 | 94 | | |||
97 | qreal ox = m_size.toScene().width() / 5; | 95 | QSizeF sceneSize = this->sceneSize(size()); | ||
98 | qreal oy = m_size.toScene().height() / 5; | 96 | qreal ox = sceneSize.width() / 5; | ||
97 | qreal oy = sceneSize.height() / 5; | ||||
staniek: In such cases I am using
`QSizeF sceneSize = this->sceneSize(size());`
and it works portable | |||||
99 | 98 | | |||
100 | //Checkbox Style | 99 | //Checkbox Style | ||
101 | if (m_checkStyle->value().toString() == QLatin1String("Cross")) { | 100 | if (m_checkStyle->value().toString() == QLatin1String("Cross")) { | ||
102 | painter->drawRoundedRect(QGraphicsRectItem::rect(), m_size.toScene().width() / 10 , m_size.toScene().height() / 10); | 101 | painter->drawRoundedRect(QGraphicsRectItem::rect(), sceneSize.width() / 10 , sceneSize.height() / 10); | ||
103 | 102 | | |||
104 | QPen lp; | 103 | QPen lp; | ||
105 | lp.setColor(m_foregroundColor->value().value<QColor>()); | 104 | lp.setColor(m_foregroundColor->value().value<QColor>()); | ||
106 | lp.setWidth(ox > oy ? oy : ox); | 105 | lp.setWidth(ox > oy ? oy : ox); | ||
107 | painter->setPen(lp); | 106 | painter->setPen(lp); | ||
108 | painter->drawLine(ox, oy, m_size.toScene().width() - ox, m_size.toScene().height() - oy); | 107 | painter->drawLine(ox, oy, sceneSize.width() - ox, sceneSize.height() - oy); | ||
109 | painter->drawLine(ox, m_size.toScene().height() - oy, m_size.toScene().width() - ox, oy); | 108 | painter->drawLine(ox, sceneSize.height() - oy, sceneSize.width() - ox, oy); | ||
110 | } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) { | 109 | } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) { | ||
111 | //Radio Style | 110 | //Radio Style | ||
112 | painter->drawEllipse(QGraphicsRectItem::rect()); | 111 | painter->drawEllipse(QGraphicsRectItem::rect()); | ||
113 | 112 | | |||
114 | QBrush lb(m_foregroundColor->value().value<QColor>()); | 113 | QBrush lb(m_foregroundColor->value().value<QColor>()); | ||
115 | painter->setBrush(lb); | 114 | painter->setBrush(lb); | ||
116 | painter->setPen(Qt::NoPen); | 115 | painter->setPen(Qt::NoPen); | ||
117 | painter->drawEllipse(rect().center(), m_size.toScene().width() / 2 - ox, m_size.toScene().height() / 2 - oy); | 116 | painter->drawEllipse(rect().center(), sceneSize.width() / 2 - ox, sceneSize.height() / 2 - oy); | ||
118 | } else { | 117 | } else { | ||
119 | //Tickbox Style | 118 | //Tickbox Style | ||
120 | painter->drawRoundedRect(QGraphicsRectItem::rect(), m_size.toScene().width() / 10 , m_size.toScene().height() / 10); | 119 | painter->drawRoundedRect(QGraphicsRectItem::rect(), sceneSize.width() / 10 , sceneSize.height() / 10); | ||
121 | 120 | | |||
122 | QPen lp; | 121 | QPen lp; | ||
123 | lp.setColor(m_foregroundColor->value().value<QColor>()); | 122 | lp.setColor(m_foregroundColor->value().value<QColor>()); | ||
124 | lp.setWidth(ox > oy ? oy : ox); | 123 | lp.setWidth(ox > oy ? oy : ox); | ||
125 | painter->setPen(lp); | 124 | painter->setPen(lp); | ||
126 | painter->drawLine(ox, m_size.toScene().height() / 2, m_size.toScene().width() / 2, m_size.toScene().height() - oy); | 125 | painter->drawLine(ox, sceneSize.height() / 2, sceneSize.width() / 2, sceneSize.height() - oy); | ||
127 | painter->drawLine(m_size.toScene().width() / 2, m_size.toScene().height() - oy, m_size.toScene().width() - ox, oy); | 126 | painter->drawLine(sceneSize.width() / 2, sceneSize.height() - oy, sceneSize.width() - ox, oy); | ||
128 | 127 | | |||
129 | } | 128 | } | ||
130 | 129 | | |||
131 | painter->setBackgroundMode(Qt::TransparentMode); | 130 | painter->setBackgroundMode(Qt::TransparentMode); | ||
132 | painter->setPen(m_foregroundColor->value().value<QColor>()); | 131 | painter->setPen(m_foregroundColor->value().value<QColor>()); | ||
133 | 132 | | |||
134 | // restore an values before we started just in case | 133 | // restore an values before we started just in case | ||
135 | painter->setFont(f); | 134 | painter->setFont(f); | ||
136 | painter->setPen(p); | 135 | painter->setPen(p); | ||
137 | painter->setBrush(b); | 136 | painter->setBrush(b); | ||
138 | 137 | | |||
139 | drawHandles(painter); | 138 | drawHandles(painter); | ||
140 | } | 139 | } | ||
141 | 140 | | |||
142 | void KReportDesignerItemCheckBox::buildXML(QDomDocument *doc, QDomElement *parent) | 141 | void KReportDesignerItemCheckBox::buildXML(QDomDocument *doc, QDomElement *parent) | ||
143 | { | 142 | { | ||
144 | //kreportpluginDebug(); | 143 | //kreportpluginDebug(); | ||
145 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | 144 | QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); | ||
146 | 145 | | |||
147 | //properties | 146 | //properties | ||
148 | addPropertyAsAttribute(&entity, m_name); | 147 | addPropertyAsAttribute(&entity, nameProperty()); | ||
149 | addPropertyAsAttribute(&entity, m_controlSource); | 148 | addPropertyAsAttribute(&entity, m_controlSource); | ||
150 | entity.setAttribute(QLatin1String("fo:foreground-color"), m_foregroundColor->value().toString()); | 149 | entity.setAttribute(QLatin1String("fo:foreground-color"), m_foregroundColor->value().toString()); | ||
151 | addPropertyAsAttribute(&entity, m_checkStyle); | 150 | addPropertyAsAttribute(&entity, m_checkStyle); | ||
152 | addPropertyAsAttribute(&entity, m_staticValue); | 151 | addPropertyAsAttribute(&entity, m_staticValue); | ||
153 | 152 | | |||
154 | // bounding rect | 153 | // bounding rect | ||
155 | buildXMLRect(doc, &entity, &m_pos, &m_size); | 154 | buildXMLRect(doc, &entity, this); | ||
156 | 155 | | |||
157 | //Line Style | 156 | //Line Style | ||
158 | buildXMLLineStyle(doc, &entity, lineStyle()); | 157 | buildXMLLineStyle(doc, &entity, lineStyle()); | ||
159 | 158 | | |||
160 | parent->appendChild(entity); | 159 | parent->appendChild(entity); | ||
161 | } | 160 | } | ||
162 | 161 | | |||
163 | void KReportDesignerItemCheckBox::slotPropertyChanged(KPropertySet &s, KProperty &p) | 162 | void KReportDesignerItemCheckBox::slotPropertyChanged(KPropertySet &s, KProperty &p) | ||
164 | { | 163 | { | ||
165 | Q_UNUSED(s) | 164 | Q_UNUSED(s) | ||
166 | 165 | | |||
167 | if (p.name() == "name") { | 166 | if (p.name() == "name") { | ||
168 | //For some reason p.oldValue returns an empty string | 167 | //For some reason p.oldValue returns an empty string | ||
169 | if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) { | 168 | if (!designer()->isEntityNameUnique(p.value().toString(), this)) { | ||
170 | p.setValue(m_oldName); | 169 | p.setValue(oldName()); | ||
171 | } else { | 170 | } else { | ||
172 | m_oldName = p.value().toString(); | 171 | setOldName(p.value().toString()); | ||
173 | } | 172 | } | ||
174 | } | 173 | } | ||
175 | 174 | | |||
176 | KReportDesignerItemRectBase::propertyChanged(s, p); | 175 | KReportDesignerItemRectBase::propertyChanged(s, p); | ||
177 | if (m_reportDesigner) m_reportDesigner->setModified(true); | 176 | if (designer()) designer()->setModified(true); | ||
178 | } | 177 | } | ||
179 | 178 | | |||
180 | void KReportDesignerItemCheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event) | 179 | void KReportDesignerItemCheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event) | ||
181 | { | 180 | { | ||
182 | m_controlSource->setListData(m_reportDesigner->fieldKeys(), m_reportDesigner->fieldNames()); | 181 | m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); | ||
183 | KReportDesignerItemRectBase::mousePressEvent(event); | 182 | KReportDesignerItemRectBase::mousePressEvent(event); | ||
184 | } | 183 | } |
In such cases I am using
QSizeF sceneSize = this->sceneSize(size());
and it works portable