KReport

KReportDesignerItemCheckBox.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2009-2010 by Adam Pigg (adam@piggz.co.uk)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "KReportDesignerItemCheckBox.h"
19#include "KReportDesignerItemRectBase.h"
20#include "KReportDesigner.h"
21#include "KReportLineStyle.h"
22
23#include <QDomDocument>
24#include <QPainter>
25#include <QGraphicsScene>
26#include <QGraphicsSceneMouseEvent>
27
28//
29// class ReportEntityCheck
30//
31
32void KReportDesignerItemCheckBox::init(QGraphicsScene *scene)
33{
34 if (scene)
35 scene->addItem(this);
36
37 connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
38 this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
39
40 setZValue(z());
41}
42
43// methods (constructors)
44KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos)
46{
47 Q_UNUSED(pos);
48 init(scene);
49 setSceneRect(properRect(*d, KREPORT_ITEM_CHECK_DEFAULT_WIDTH, KREPORT_ITEM_CHECK_DEFAULT_HEIGHT));
50 nameProperty()->setValue(designer()->suggestEntityName(typeName()));
51}
52
53KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s)
54 : KReportItemCheckBox(element), KReportDesignerItemRectBase(d, this)
55{
56 init(s);
57 setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
58}
59
60KReportDesignerItemCheckBox* KReportDesignerItemCheckBox::clone()
61{
64 QDomNode n;
65 buildXML(&d, &e);
66 n = e.firstChild();
67 return new KReportDesignerItemCheckBox(n, designer(), nullptr);
68}
69
70// methods (deconstructor)
71KReportDesignerItemCheckBox::~KReportDesignerItemCheckBox()
72{}
73
74void KReportDesignerItemCheckBox::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
75{
76 Q_UNUSED(option);
77 Q_UNUSED(widget);
78
79 // store any values we plan on changing so we can restore them
80 QFont f = painter->font();
81 QPen p = painter->pen();
82 QBrush b = painter->brush();
83
86
87 painter->setPen(m_foregroundColor->value().value<QColor>());
88
89 if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
90 painter->setPen(QPen(Qt::lightGray));
91 } else {
92 painter->setPen(QPen(m_lineColor->value().value<QColor>(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
93 }
94
95 QSizeF sceneSize = this->sceneSize(size());
96 qreal ox = sceneSize.width() / 5;
97 qreal oy = sceneSize.height() / 5;
98
99 //Checkbox Style
100 if (m_checkStyle->value().toString() == QLatin1String("Cross")) {
102
103 QPen lp;
104 lp.setColor(m_foregroundColor->value().value<QColor>());
105 lp.setWidth(ox > oy ? oy : ox);
106 painter->setPen(lp);
107 painter->drawLine(ox, oy, sceneSize.width() - ox, sceneSize.height() - oy);
108 painter->drawLine(ox, sceneSize.height() - oy, sceneSize.width() - ox, oy);
109 } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) {
110 //Radio Style
112
113 QBrush lb(m_foregroundColor->value().value<QColor>());
114 painter->setBrush(lb);
115 painter->setPen(Qt::NoPen);
116 painter->drawEllipse(rect().center(), sceneSize.width() / 2 - ox, sceneSize.height() / 2 - oy);
117 } else {
118 //Tickbox Style
120
121 QPen lp;
122 lp.setColor(m_foregroundColor->value().value<QColor>());
123 lp.setWidth(ox > oy ? oy : ox);
124 painter->setPen(lp);
125 painter->drawLine(ox, sceneSize.height() / 2, sceneSize.width() / 2, sceneSize.height() - oy);
126 painter->drawLine(sceneSize.width() / 2, sceneSize.height() - oy, sceneSize.width() - ox, oy);
127
128 }
129
131 painter->setPen(m_foregroundColor->value().value<QColor>());
132
133 // restore an values before we started just in case
134 painter->setFont(f);
135 painter->setPen(p);
136 painter->setBrush(b);
137
138 drawHandles(painter);
139}
140
141void KReportDesignerItemCheckBox::buildXML(QDomDocument *doc, QDomElement *parent)
142{
143 //kreportpluginDebug();
144 QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
145
146 //properties
147 addPropertyAsAttribute(&entity, nameProperty());
148 addPropertyAsAttribute(&entity, dataSourceProperty());
149 entity.setAttribute(QLatin1String("fo:foreground-color"), m_foregroundColor->value().toString());
150 addPropertyAsAttribute(&entity, m_checkStyle);
151 addPropertyAsAttribute(&entity, m_staticValue);
152
153 // bounding rect
154 buildXMLRect(doc, &entity, this);
155
156 //Line Style
157 buildXMLLineStyle(doc, &entity, lineStyle());
158
159 parent->appendChild(entity);
160}
161
162void KReportDesignerItemCheckBox::slotPropertyChanged(KPropertySet &s, KProperty &p)
163{
164 Q_UNUSED(s)
165
166 if (p.name() == "name") {
167 //For some reason p.oldValue returns an empty string
168 if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
169 p.setValue(oldName());
170 } else {
171 setOldName(p.value().toString());
172 }
173 }
174
175 KReportDesignerItemRectBase::propertyChanged(s, p);
176 if (designer()) designer()->setModified(true);
177}
QVariant value() const
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
QByteArray name() const
Base class for rectangular report items used within the designer GUI.
The ReportDesigner is the main widget for designing a report.
void setModified(bool modified)
Sets the modified status, defaulting to true for modified.
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
qreal z() const
Return the z-value in points.
QSizeF size() const
Return the size in points.
KOSM_EXPORT const char * typeName(Type type)
QCA_EXPORT void init()
QDomElement createElement(const QString &tagName)
void setAttribute(const QString &name, const QString &value)
QDomNode firstChild() const const
QGraphicsScene * scene() const const
void setZValue(qreal z)
QRectF rect() const const
void addItem(QGraphicsItem *item)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
const QBrush & brush() const const
void drawEllipse(const QPoint &center, int rx, int ry)
void drawLine(const QLine &line)
void drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
const QFont & font() const const
const QPen & pen() const const
void setBackgroundMode(Qt::BGMode mode)
void setBrush(Qt::BrushStyle style)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
void setColor(const QColor &color)
void setWidth(int width)
qreal height() const const
qreal width() const const
OpaqueMode
lightGray
PenStyle
QTextStream & center(QTextStream &stream)
int toInt(bool *ok) const const
QString toString() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.