[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Sat Dec 10 01:33:14 CET 2005
SVN commit 487283 by staikos:
This breaks arrows, and actually isn't fully correct at this time, but it's
close. It forces the line to be completely inside the bounding box even when
the width is greater than 1.
M +24 -4 kstviewline.cpp
--- trunk/extragear/graphics/kst/kst/kstviewline.cpp #487282:487283
@@ -26,8 +26,10 @@
#include <qpainter.h>
#include <qvariant.h>
+#include <math.h>
+
KstViewLine::KstViewLine(const QString& type)
-: KstViewObject(type), _width(1) {
+: KstViewObject(type), _width(0) {
setTransparent(true);
_container = false;
_capStyle = Qt::FlatCap;
@@ -38,7 +40,7 @@
KstViewLine::KstViewLine(const QDomElement& e)
: KstViewObject(e) {
- _width = 1;
+ _width = 0;
_container = false;
_capStyle = Qt::FlatCap;
_penStyle = Qt::SolidLine;
@@ -66,14 +68,30 @@
p.setPen(pen);
const QRect geom(geometry());
+ int u = 0, v = 0;
+
+ // Adjust for large widths. We don't want the line clipped because it goes
+ // out of the bounding box.
+ if (_width > 1) {
+ double theta = atan(geom.width()/geom.height());
+ int w = _width;
+ if (theta >= 0 && theta <= M_PI/4) {
+ u = int(fabs((w / 2.0) * (sin(theta) + cos(theta))));
+ v = int(fabs((w / 2.0) * (1.5*sin(theta) + 0.5*cos(theta))));
+ } else {
+ u = int(fabs((w / 2.0) * (1.5*sin(theta) + 0.5*cos(theta))));
+ v = int(fabs((w / 2.0) * (sin(theta) + cos(theta))));
+ }
+ }
+
switch (_orientation) {
case UpLeft:
case DownRight:
- p.drawLine(geom.bottomRight(), geom.topLeft());
+ p.drawLine(geom.bottomRight() + QPoint(-u, -v), geom.topLeft() + QPoint(u, v));
break;
case UpRight:
case DownLeft:
- p.drawLine(geom.bottomLeft(), geom.topRight());
+ p.drawLine(geom.bottomLeft() + QPoint(u, -v), geom.topRight() + QPoint(-u, v));
break;
}
// paint this last
@@ -96,6 +114,7 @@
_from = from;
// line drawing finished; update size, origin, and orientation
updateOrientation();
+ setDirty();
}
}
@@ -120,6 +139,7 @@
_to = to;
// line drawing finished; update size, origin, and orientation
updateOrientation();
+ setDirty();
}
}
More information about the Kst
mailing list