~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/kst/kstviewbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                               kstviewbox.cpp
 
3
                             -------------------
 
4
    begin                : Jun 14, 2005
 
5
    copyright            : (C) 2005 The University of Toronto
 
6
    email                :
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
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.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "editviewobjectdialog.h" 
 
19
#include "kstgfxrectanglemousehandler.h"
 
20
#include "kst.h"
 
21
#include "kstviewbox.h"
 
22
#include "kstviewobjectfactory.h"
 
23
 
 
24
#include <kglobal.h>
 
25
#include <klocale.h>
 
26
 
 
27
#include <qmetaobject.h>
 
28
#include <qpainter.h>
 
29
#include <qmap.h>
 
30
#include <qpair.h>
 
31
 
 
32
KstViewBox::KstViewBox()
 
33
: KstViewObject("Box"), _borderColor(QColor(0, 0, 0)), _borderWidth(0) {
 
34
  _xRound = 0;
 
35
  _yRound = 0;
 
36
  _cornerStyle = Qt::MiterJoin;
 
37
  _fallThroughTransparency = false;
 
38
  setTransparent(true);
 
39
  _transparentFill = false;
 
40
  setFollowsFlow(true);
 
41
}
 
42
 
 
43
 
 
44
KstViewBox::KstViewBox(const QDomElement& e)
 
45
: KstViewObject(e), _borderColor(QColor(0, 0, 0)), _borderWidth(0) {
 
46
  
 
47
  QDomNode n = e.firstChild();
 
48
  while (!n.isNull()) {
 
49
    QDomElement el = n.toElement(); 
 
50
    if (!el.isNull()) {
 
51
      if (metaObject()->findProperty(el.tagName().latin1(), true) > -1) {
 
52
        setProperty(el.tagName().latin1(), QVariant(el.text()));  
 
53
      }  
 
54
    }
 
55
    n = n.nextSibling();      
 
56
  }
 
57
  
 
58
  // these always have these values
 
59
  _type = "Box";
 
60
  _layoutActions |= Delete | Raise | Lower | RaiseToTop | LowerToBottom | Rename | MoveTo | Copy | CopyTo;
 
61
  _fallThroughTransparency = false;
 
62
  setTransparent(true);
 
63
  setFollowsFlow(true);
 
64
}
 
65
 
 
66
 
 
67
KstViewBox::~KstViewBox() {
 
68
}
 
69
 
 
70
 
 
71
void KstViewBox::paintSelf(KstPainter& p, const QRegion& bounds) {
 
72
  p.save();
 
73
  if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
 
74
    if (p.makingMask()) {
 
75
      p.setRasterOp(Qt::SetROP);
 
76
    } else {
 
77
      const QRegion clip(clipRegion());
 
78
      KstViewObject::paintSelf(p, bounds - clip);
 
79
      p.setClipRegion(bounds & clip);
 
80
    }
 
81
  }
 
82
 
 
83
  const int bw(borderWidth() * p.lineWidthAdjustmentFactor());
 
84
  QPen pen(borderColor(), bw);
 
85
  pen.setJoinStyle(_cornerStyle);
 
86
  if (bw == 0) {
 
87
    pen.setStyle(Qt::NoPen);
 
88
  }
 
89
  p.setPen(pen);
 
90
  if (_transparentFill) {
 
91
    p.setBrush(Qt::NoBrush);  
 
92
  } else {
 
93
    p.setBrush(_foregroundColor);
 
94
  }
 
95
  QRect r;
 
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);
 
100
 
 
101
  p.drawRoundRect(r, _xRound, _yRound);
 
102
  p.restore();
 
103
}
 
104
 
 
105
 
 
106
void KstViewBox::save(QTextStream& ts, const QString& indent) {
 
107
  ts << indent << "<" << type() << ">" << endl;
 
108
  KstViewObject::save(ts, indent + "  ");
 
109
  ts << indent << "</" << type() << ">" << endl;
 
110
}
 
111
 
 
112
 
 
113
void KstViewBox::setXRound(int rnd) {
 
114
  int crnd;
 
115
  if (rnd < 0) {
 
116
    crnd = 0;  
 
117
  } else if (rnd > 99) {
 
118
    crnd = 99;  
 
119
  } else {
 
120
    crnd = rnd;  
 
121
  }
 
122
  if (_xRound != crnd) {
 
123
    setDirty();
 
124
    _xRound = crnd;
 
125
  }
 
126
}
 
127
 
 
128
 
 
129
void KstViewBox::setYRound(int rnd) {
 
130
  int crnd;
 
131
  if (rnd < 0) {
 
132
    crnd = 0;  
 
133
  } else if (rnd > 99) {
 
134
    crnd = 99;  
 
135
  } else {
 
136
    crnd = rnd;  
 
137
  }
 
138
  if (_yRound != crnd) {
 
139
    setDirty();
 
140
    _yRound = crnd;
 
141
  }
 
142
}
 
143
 
 
144
 
 
145
int KstViewBox::xRound() const {
 
146
  return _xRound;
 
147
}
 
148
 
 
149
 
 
150
int KstViewBox::yRound() const {
 
151
  return _yRound;
 
152
}
 
153
 
 
154
 
 
155
void KstViewBox::setCornerStyle(Qt::PenJoinStyle style) {
 
156
  if (_cornerStyle != style) {
 
157
    setDirty();
 
158
    _cornerStyle = style;
 
159
  }
 
160
}
 
161
 
 
162
 
 
163
Qt::PenJoinStyle KstViewBox::cornerStyle() const {
 
164
  return _cornerStyle;
 
165
}
 
166
 
 
167
 
 
168
bool KstViewBox::transparentFill() const {
 
169
  return _transparentFill;
 
170
}
 
171
 
 
172
 
 
173
void KstViewBox::setTransparentFill(bool yes) {
 
174
  if (_transparentFill != yes) {
 
175
    setDirty();
 
176
    _transparentFill = yes;
 
177
  }
 
178
}
 
179
 
 
180
 
 
181
void KstViewBox::setBorderColor(const QColor& c) {
 
182
  if (_borderColor != c) {
 
183
    setDirty();
 
184
    _borderColor = c;
 
185
  }
 
186
}
 
187
 
 
188
 
 
189
const QColor& KstViewBox::borderColor() const {
 
190
  return _borderColor;
 
191
}
 
192
 
 
193
 
 
194
void KstViewBox::setBorderWidth(int w) {
 
195
  int mw = kMax(0, w);
 
196
  if (_borderWidth != mw) {
 
197
    _borderWidth = mw;
 
198
    setDirty();
 
199
  }
 
200
}
 
201
 
 
202
 
 
203
int KstViewBox::borderWidth() const {
 
204
  return _borderWidth;
 
205
}
 
206
 
 
207
 
 
208
void KstViewBox::setBackgroundColor(const QColor& color) {
 
209
  KstViewObject::setBackgroundColor(color);
 
210
}
 
211
 
 
212
 
 
213
QColor KstViewBox::backgroundColor() const {
 
214
  return KstViewObject::backgroundColor();
 
215
}
 
216
 
 
217
 
 
218
void KstViewBox::setForegroundColor(const QColor& color) {
 
219
  KstViewObject::setForegroundColor(color);
 
220
}
 
221
 
 
222
 
 
223
QColor KstViewBox::foregroundColor() const {
 
224
  return KstViewObject::foregroundColor();
 
225
}
 
226
 
 
227
 
 
228
QMap<QString, QVariant > KstViewBox::widgetHints(const QString& propertyName) const {
 
229
  QMap<QString, QVariant> map = KstViewObject::widgetHints(propertyName);
 
230
  if (!map.empty()) {
 
231
    return map;  
 
232
  }
 
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);
 
255
  }
 
256
  return map;
 
257
}
 
258
 
 
259
 
 
260
namespace {
 
261
KstViewObject *create_KstViewBox() {
 
262
  return new KstViewBox;
 
263
}
 
264
 
 
265
 
 
266
KstGfxMouseHandler *handler_KstViewBox() {
 
267
  return new KstGfxRectangleMouseHandler;
 
268
}
 
269
 
 
270
KST_REGISTER_VIEW_OBJECT(Box, create_KstViewBox, handler_KstViewBox)
 
271
}
 
272
 
 
273
 
 
274
#include "kstviewbox.moc"
 
275
// vim: ts=2 sw=2 et