[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Tue Feb 7 14:46:49 CET 2006
SVN commit 506682 by staikos:
back out r505756
M +19 -22 kstviewarrow.cpp
M +1 -1 kstviewarrow.h
M +23 -30 kstviewline.cpp
M +0 -1 kstviewline.h
--- trunk/extragear/graphics/kst/kst/kstviewarrow.cpp #506681:506682
@@ -64,8 +64,8 @@
}
-void KstViewArrow::paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w, double arrowScaling) {
- double deltax = arrowScaling * 2.0 * double(w);
+void KstViewArrow::paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w) {
+ double deltax = _toArrowScaling * 2.0 * double(w);
double theta = atan2(double(from.y() - to.y()), double(from.x() - to.x())) - M_PI / 2.0;
double sina = sin(theta);
double cosa = cos(theta);
@@ -87,31 +87,28 @@
QRegion KstViewArrow::clipRegion() {
if (_clipMask.isNull()) {
- double arrowScaling = _toArrowScaling;
- if (_fromArrowScaling > arrowScaling) {
- arrowScaling = _fromArrowScaling;
- }
-
- int w = int(ceil(sqrt(3.0) * arrowScaling * 2.0 * double(width())));
- QRect rect(0, 0, _geom.bottomRight().x() + w + 1, _geom.bottomRight().y() + w + 1 );
_myClipMask = QRegion();
- QBitmap bm(rect.size(), true);
- if (!bm.isNull()) {
+ QBitmap bm1(_geom.bottomRight().x(), _geom.bottomRight().y(), true);
+ if (!bm1.isNull()) {
KstPainter p;
p.setMakingMask(true);
- p.begin(&bm);
+ p.begin(&bm1);
p.setViewXForm(true);
-
KstViewLine::paintSelf(p, QRegion());
p.flush();
- _clipMask = QRegion(bm);
-
- p.eraseRect(rect);
- paintSelf(p, QRegion());
+ p.end();
+ _clipMask = QRegion(bm1);
+ }
+ QBitmap bm2(_geom.bottomRight().x(), _geom.bottomRight().y(), true);
+ if (!bm2.isNull()) {
+ KstPainter p;
+ p.setMakingMask(true);
+ p.begin(&bm2);
+ p.setViewXForm(true);
+ paintSelf(p, QRegion());
p.flush();
- _myClipMask = QRegion(bm);
-
p.end();
+ _myClipMask = QRegion(bm2);
}
}
@@ -130,7 +127,7 @@
p.setClipRegion(bounds & clip);
}
} else {
- KstViewLine::paintSelf(p, bounds);
+ KstViewLine::paintSelf(p, bounds);
}
if (hasArrow()) {
@@ -144,10 +141,10 @@
p.setBrush(_foregroundColor);
if (_hasToArrow) {
- paintArrow(p, to, from, w, _toArrowScaling);
+ paintArrow(p, to, from, w);
}
if (_hasFromArrow) {
- paintArrow(p, from, to, w, _fromArrowScaling);
+ paintArrow(p, from, to, w);
}
}
p.restore();
--- trunk/extragear/graphics/kst/kst/kstviewarrow.h #506681:506682
@@ -39,7 +39,7 @@
QMap<QString, QVariant > widgetHints(const QString& propertyName) const;
void paintSelf(KstPainter& p, const QRegion& bounds);
- void paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w, double arrowScaling);
+ void paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w);
// true if either end has an arrow
bool hasArrow() const;
--- trunk/extragear/graphics/kst/kst/kstviewline.cpp #506681:506682
@@ -22,7 +22,6 @@
#include <klocale.h>
-#include <qbitmap.h>
#include <qmetaobject.h>
#include <qpainter.h>
#include <qvariant.h>
@@ -85,34 +84,12 @@
}
-QRegion KstViewLine::clipRegion() {
- if (_clipMask.isNull()) {
- int w = width();
- QRect rect(0, 0, _geom.bottomRight().x() + w + 1, _geom.bottomRight().y() + w + 1);
- QBitmap bm(rect.size(), true);
- if (!bm.isNull()) {
- KstPainter p;
- p.setMakingMask(true);
- p.begin(&bm);
- p.setViewXForm(true);
- p.eraseRect(rect);
- paintSelf(p, QRegion());
- p.flush();
- p.end();
- _clipMask = QRegion(bm);
- } else {
- _clipMask = QRegion(); // only invalidate our own variable
- }
- }
-
- return _clipMask;
-}
-
void KstViewLine::paintSelf(KstPainter& p, const QRegion& bounds) {
p.save();
if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
if (p.makingMask()) {
p.setRasterOp(Qt::SetROP);
+ KstViewObject::paintSelf(p, geometry());
} else {
const QRegion clip(clipRegion());
KstViewObject::paintSelf(p, bounds - clip);
@@ -127,14 +104,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 && geom.height() > 0) {
+ 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;
}
p.restore();
@@ -267,21 +260,21 @@
if (_from.y() < _to.y()) {
_orientation = DownRight;
KstViewObject::move(_from);
- KstViewObject::resize(QSize(_to.x() - _from.x() + 1, _to.y() - _from.y() + 1));
+ KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
} else {
_orientation = UpRight;
KstViewObject::move(QPoint(_from.x(), _to.y()));
- KstViewObject::resize(QSize(_to.x() - _from.x() + 1, _from.y() - _to.y() + 1));
+ KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
}
} else {
if (_from.y() < _to.y()) {
_orientation = DownLeft;
KstViewObject::move(QPoint(_to.x(), _from.y()));
- KstViewObject::resize(QSize(_from.x() - _to.x() + 1, _to.y() - _from.y() + 1));
+ KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
} else {
_orientation = UpLeft;
KstViewObject::move(_to);
- KstViewObject::resize(QSize(_from.x() - _to.x() + 1, _from.y() - _to.y() + 1));
+ KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
}
}
}
--- trunk/extragear/graphics/kst/kst/kstviewline.h #506681:506682
@@ -52,7 +52,6 @@
void setForegroundColor(const QColor& color);
QColor foregroundColor() const;
- QRegion clipRegion();
void move(const QPoint& pos);
virtual void setCapStyle(Qt::PenCapStyle style);
More information about the Kst
mailing list