1
/***************************************************************************
5
copyright : (C) 2005 The University of Toronto
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#include "editviewobjectdialog.h"
19
#include "kstgfxrectanglemousehandler.h"
21
#include "kstviewbox.h"
22
#include "kstviewobjectfactory.h"
27
#include <qmetaobject.h>
32
KstViewBox::KstViewBox()
33
: KstViewObject("Box"), _borderColor(QColor(0, 0, 0)), _borderWidth(0) {
36
_cornerStyle = Qt::MiterJoin;
37
_fallThroughTransparency = false;
39
_transparentFill = false;
44
KstViewBox::KstViewBox(const QDomElement& e)
45
: KstViewObject(e), _borderColor(QColor(0, 0, 0)), _borderWidth(0) {
47
QDomNode n = e.firstChild();
49
QDomElement el = n.toElement();
51
if (metaObject()->findProperty(el.tagName().latin1(), true) > -1) {
52
setProperty(el.tagName().latin1(), QVariant(el.text()));
58
// these always have these values
60
_layoutActions |= Delete | Raise | Lower | RaiseToTop | LowerToBottom | Rename | MoveTo | Copy | CopyTo;
61
_fallThroughTransparency = false;
67
KstViewBox::~KstViewBox() {
71
void KstViewBox::paintSelf(KstPainter& p, const QRegion& bounds) {
73
if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
75
p.setRasterOp(Qt::SetROP);
77
const QRegion clip(clipRegion());
78
KstViewObject::paintSelf(p, bounds - clip);
79
p.setClipRegion(bounds & clip);
83
const int bw(borderWidth() * p.lineWidthAdjustmentFactor());
84
QPen pen(borderColor(), bw);
85
pen.setJoinStyle(_cornerStyle);
87
pen.setStyle(Qt::NoPen);
90
if (_transparentFill) {
91
p.setBrush(Qt::NoBrush);
93
p.setBrush(_foregroundColor);
96
r.setX(_geom.left() + bw / 2);
97
r.setY(_geom.top() + bw / 2);
98
r.setWidth(_geom.width() - bw);
99
r.setHeight(_geom.height() - bw);
101
p.drawRoundRect(r, _xRound, _yRound);
106
void KstViewBox::save(QTextStream& ts, const QString& indent) {
107
ts << indent << "<" << type() << ">" << endl;
108
KstViewObject::save(ts, indent + " ");
109
ts << indent << "</" << type() << ">" << endl;
113
void KstViewBox::setXRound(int rnd) {
117
} else if (rnd > 99) {
122
if (_xRound != crnd) {
129
void KstViewBox::setYRound(int rnd) {
133
} else if (rnd > 99) {
138
if (_yRound != crnd) {
145
int KstViewBox::xRound() const {
150
int KstViewBox::yRound() const {
155
void KstViewBox::setCornerStyle(Qt::PenJoinStyle style) {
156
if (_cornerStyle != style) {
158
_cornerStyle = style;
163
Qt::PenJoinStyle KstViewBox::cornerStyle() const {
168
bool KstViewBox::transparentFill() const {
169
return _transparentFill;
173
void KstViewBox::setTransparentFill(bool yes) {
174
if (_transparentFill != yes) {
176
_transparentFill = yes;
181
void KstViewBox::setBorderColor(const QColor& c) {
182
if (_borderColor != c) {
189
const QColor& KstViewBox::borderColor() const {
194
void KstViewBox::setBorderWidth(int w) {
196
if (_borderWidth != mw) {
203
int KstViewBox::borderWidth() const {
208
void KstViewBox::setBackgroundColor(const QColor& color) {
209
KstViewObject::setBackgroundColor(color);
213
QColor KstViewBox::backgroundColor() const {
214
return KstViewObject::backgroundColor();
218
void KstViewBox::setForegroundColor(const QColor& color) {
219
KstViewObject::setForegroundColor(color);
223
QColor KstViewBox::foregroundColor() const {
224
return KstViewObject::foregroundColor();
228
QMap<QString, QVariant > KstViewBox::widgetHints(const QString& propertyName) const {
229
QMap<QString, QVariant> map = KstViewObject::widgetHints(propertyName);
233
if (propertyName == "xRound") {
234
map.insert(QString("_kst_widgetType"), QString("QSpinBox"));
235
map.insert(QString("_kst_label"), i18n("X Roundness"));
236
map.insert(QString("minValue"), 0);
237
} else if (propertyName == "yRound") {
238
map.insert(QString("_kst_widgetType"), QString("QSpinBox"));
239
map.insert(QString("_kst_label"), i18n("Y Roundness"));
240
map.insert(QString("minValue"), 0);
241
} else if (propertyName == "foregroundColor") {
242
map.insert(QString("_kst_widgetType"), QString("KColorButton"));
243
map.insert(QString("_kst_label"), i18n("Fill Color"));
244
} else if (propertyName == "transparentFill") {
245
map.insert(QString("_kst_widgetType"), QString("QCheckBox"));
246
map.insert(QString("_kst_label"), QString::null);
247
map.insert(QString("text"), i18n("Transparent fill"));
248
} if (propertyName == "borderColor") {
249
map.insert(QString("_kst_widgetType"), QString("KColorButton"));
250
map.insert(QString("_kst_label"), i18n("Border color"));
251
} else if (propertyName == "borderWidth") {
252
map.insert(QString("_kst_widgetType"), QString("QSpinBox"));
253
map.insert(QString("_kst_label"), i18n("Border width"));
254
map.insert(QString("minValue"), 0);
261
KstViewObject *create_KstViewBox() {
262
return new KstViewBox;
266
KstGfxMouseHandler *handler_KstViewBox() {
267
return new KstGfxRectangleMouseHandler;
270
KST_REGISTER_VIEW_OBJECT(Box, create_KstViewBox, handler_KstViewBox)
274
#include "kstviewbox.moc"