[Kst] [Bug 121068] Arrow view objects not always clipped correctly
netterfield at astro.utoronto.ca
netterfield at astro.utoronto.ca
Sat Feb 4 20:29:58 CET 2006
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=121068
------- Additional Comments From netterfield astro utoronto ca 2006-02-04 20:29 -------
SVN commit 505756 by netterfield:
CCBUG: 121068
Apply Andrew's patch as a temporary fix for 1.2.0. Long term, line to/from/drag
points need to be separated from geometry, so this bug will remain open until this is
done.
M +22 -19 kstviewarrow.cpp
M +1 -1 kstviewarrow.h
M +30 -23 kstviewline.cpp
M +1 -0 kstviewline.h
--- trunk/extragear/graphics/kst/kst/kstviewarrow.cpp #505755:505756
@ -64,8 +64,8 @
}
-void KstViewArrow::paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w) {
- double deltax = _toArrowScaling * 2.0 * double(w);
+void KstViewArrow::paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w, double arrowScaling) {
+ double deltax = arrowScaling * 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,28 +87,31 @
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 bm1(_geom.bottomRight().x(), _geom.bottomRight().y(), true);
- if (!bm1.isNull()) {
+ QBitmap bm(rect.size(), true);
+ if (!bm.isNull()) {
KstPainter p;
p.setMakingMask(true);
- p.begin(&bm1);
+ p.begin(&bm);
p.setViewXForm(true);
+
KstViewLine::paintSelf(p, QRegion());
p.flush();
- 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());
+ _clipMask = QRegion(bm);
+
+ p.eraseRect(rect);
+ paintSelf(p, QRegion());
p.flush();
+ _myClipMask = QRegion(bm);
+
p.end();
- _myClipMask = QRegion(bm2);
}
}
@ -127,7 +130,7 @
p.setClipRegion(bounds & clip);
}
} else {
- KstViewLine::paintSelf(p, bounds);
+ KstViewLine::paintSelf(p, bounds);
}
if (hasArrow()) {
@ -141,10 +144,10 @
p.setBrush(_foregroundColor);
if (_hasToArrow) {
- paintArrow(p, to, from, w);
+ paintArrow(p, to, from, w, _toArrowScaling);
}
if (_hasFromArrow) {
- paintArrow(p, from, to, w);
+ paintArrow(p, from, to, w, _fromArrowScaling);
}
}
p.restore();
--- trunk/extragear/graphics/kst/kst/kstviewarrow.h #505755:505756
@ -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);
+ void paintArrow(KstPainter& p, const QPoint& to, const QPoint &from, int w, double arrowScaling);
// true if either end has an arrow
bool hasArrow() const;
--- trunk/extragear/graphics/kst/kst/kstviewline.cpp #505755:505756
@ -22,6 +22,7 @
#include <klocale.h>
+#include <qbitmap.h>
#include <qmetaobject.h>
#include <qpainter.h>
#include <qvariant.h>
@ -84,12 +85,34 @
}
+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);
@ -104,30 +127,14 @
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() + QPoint(-u, -v), geom.topLeft() + QPoint(u, v));
+ p.drawLine(geom.bottomRight(), geom.topLeft());
break;
case UpRight:
case DownLeft:
- p.drawLine(geom.bottomLeft() + QPoint(u, -v), geom.topRight() + QPoint(-u, v));
+ p.drawLine(geom.bottomLeft(), geom.topRight());
break;
}
p.restore();
@ -260,21 +267,21 @
if (_from.y() < _to.y()) {
_orientation = DownRight;
KstViewObject::move(_from);
- KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
+ KstViewObject::resize(QSize(_to.x() - _from.x() + 1, _to.y() - _from.y() + 1));
} else {
_orientation = UpRight;
KstViewObject::move(QPoint(_from.x(), _to.y()));
- KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
+ KstViewObject::resize(QSize(_to.x() - _from.x() + 1, _from.y() - _to.y() + 1));
}
} else {
if (_from.y() < _to.y()) {
_orientation = DownLeft;
KstViewObject::move(QPoint(_to.x(), _from.y()));
- KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
+ KstViewObject::resize(QSize(_from.x() - _to.x() + 1, _to.y() - _from.y() + 1));
} else {
_orientation = UpLeft;
KstViewObject::move(_to);
- KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
+ KstViewObject::resize(QSize(_from.x() - _to.x() + 1, _from.y() - _to.y() + 1));
}
}
}
--- trunk/extragear/graphics/kst/kst/kstviewline.h #505755:505756
@ -52,6 +52,7 @
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