[Kst] [Bug 121108] Kst assertion failure when line or arrow moved outside of window
Andrew Walker
arwalker at sumusltd.com
Wed Feb 1 23:21:40 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=121108
------- Additional Comments From arwalker sumusltd com 2006-02-01 23:21 -------
Propoased patch which keeps the line/arrow within the parent, thus avoiding the assert:
Index: ksttoplevelview.cpp
===================================================================
--- ksttoplevelview.cpp (revision 504684)
+++ ksttoplevelview.cpp (working copy)
@ -37,6 +37,7 @
#include "kstaccessibility.h"
#include "kstdoc.h"
#include "kstgfxmousehandler.h"
+#include "kstmath.h"
#include "kstplotgroup.h"
#include "kstsettings.h"
#include "ksttimers.h"
@ -780,12 +781,80 @
}
+QPoint KstTopLevelView::handlePoint(bool shift, const QPoint& ptFixed, const QPoint& pos, double aspect) {
+ QPoint ptMoved = pos;
+
+ if (shift) {
+ double absAspect = fabs(aspect);
+ if (absAspect < 500.0 && (double(abs((pos.y() - ptFixed.y())/(pos.x() - ptFixed.x()))) < aspect ||
+ absAspect < 0.1)) {
+ ptMoved = QPoint(pos.x(), ptFixed.y() + int(aspect*(pos.x() - ptFixed.x())));
+ } else {
+ ptMoved = QPoint(ptFixed.x() + int((pos.y() - ptFixed.y())/aspect), pos.y());
+ }
+ }
+
+ //
+ // ensure that the point we just moved is contained by its parent...
+ //
+ QRect parentRect = _pressTarget->_parent->_geom;
+ if (parentRect.contains(ptFixed) && !parentRect.contains(ptMoved)) {
+ double gradient;
+ bool found = false;
+ int x;
+ int y;
+
+ if (!found && ptMoved.x() < parentRect.left()) {
+ gradient = double(ptMoved.y() - ptFixed.y())/double(ptMoved.x() - ptFixed.x());
+ x = parentRect.left();
+ y = ptFixed.y() + d2i(double(x - ptFixed.x()) * gradient);
+ if (y >= parentRect.top() && y <= parentRect.bottom()) {
+ found = true;
+ }
+ }
+ if (!found && ptMoved.x() > parentRect.right()) {
+ gradient = double(ptMoved.y() - ptFixed.y())/double(ptMoved.x() - ptFixed.x());
+ x = parentRect.right();
+ y = ptFixed.y() + d2i(double(x - ptFixed.x()) * gradient);
+ if (y >= parentRect.top() && y <= parentRect.bottom()) {
+ found = true;
+ }
+ }
+ if (!found && ptMoved.y() < parentRect.top()) {
+ gradient = double(ptMoved.x() - ptFixed.x())/double(ptMoved.y() - ptFixed.y());
+ y = parentRect.top();
+ x = ptFixed.x() + d2i(double(y - ptFixed.y()) * gradient);
+ if (x >= parentRect.left() && x <= parentRect.right()) {
+ found = true;
+ }
+ }
+ if (!found && ptMoved.y() > parentRect.bottom()) {
+ gradient = double(ptMoved.x() - ptFixed.x())/double(ptMoved.y() - ptFixed.y());
+ y = parentRect.bottom();
+ x = ptFixed.x() + d2i(double(y - ptFixed.y()) * gradient);
+ if (x >= parentRect.left() && x <= parentRect.right()) {
+ found = true;
+ }
+ }
+
+ if (found) {
+ ptMoved.setX(x);
+ ptMoved.setY(y);
+ }
+ }
+
+ return ptMoved;
+}
+
+
void KstTopLevelView::pressMoveLayoutModeEndPoint(const QPoint& pos, bool shift) {
// FIXME: remove this!! Should not know about any specific type
// for now we only know how to deal with lines
if (KstViewLinePtr line = kst_cast<KstViewLine>(_pressTarget)) {
const QRect old(_prevBand);
+ QPoint ptFixed;
double aspect;
+
if (line->to().x() != line->from().x()) {
aspect = double(line->to().y() - line->from().y()) / double(line->to().x() - line->from().x());
} else {
@ -795,40 +864,22 @
aspect = 1.0E300;
}
}
- QPoint fromPoint, toPoint;
+
if (_pressDirection & UP) {
- // UP means we are on the start endpoint
- toPoint = line->to();
- if (shift) {
- double absAspect = fabs(aspect);
- if (absAspect < 500 && (double(abs((pos.y() - toPoint.y())/(pos.x() - toPoint.x()))) < aspect || absAspect < 0.1)) {
- fromPoint = QPoint(pos.x(), toPoint.y() + int(aspect*(pos.x() - toPoint.x())));
- } else {
- fromPoint = QPoint(toPoint.x() + int((pos.y() - toPoint.y())/aspect), pos.y());
- }
- } else {
- fromPoint = pos;
- }
+ // UP means we are on the "from" point
+ ptFixed = line->to();
+ _prevBand.setTopLeft(handlePoint(shift, ptFixed, pos, aspect));
+ _prevBand.setBottomRight(ptFixed);
} else if (_pressDirection & DOWN) {
- // DOWN means we are on the end endpoint
- fromPoint = line->from();
- if (shift) {
- double absAspect = fabs(aspect);
- if (absAspect < 500 && (double(abs((pos.y() - toPoint.y())/(pos.x() - toPoint.x()))) < aspect || absAspect < 0.1)) {
- toPoint = QPoint(pos.x(), fromPoint.y() + int(aspect*(pos.x() - fromPoint.x())));
- } else {
- toPoint = QPoint(fromPoint.x() + int((pos.y() - fromPoint.y())/aspect), pos.y());
- }
- } else {
- toPoint = pos;
- }
+ // DOWN means we are on the "to" point
+ ptFixed = line->from();
+ _prevBand.setTopLeft(ptFixed);
+ _prevBand.setBottomRight(handlePoint(shift, ptFixed, pos, aspect));
} else {
- abort();
+ assert(false);
+ return;
}
- _prevBand.setTopLeft(fromPoint);
- _prevBand.setBottomRight(toPoint);
-
if (old != _prevBand) {
KstPainter p;
p.begin(_w);
Index: ksttoplevelview.h
===================================================================
--- ksttoplevelview.h (revision 504664)
+++ ksttoplevelview.h (working copy)
@ -98,6 +98,7 @
void pressMove(const QPoint& pos, bool shift = false);
void pressMoveLayoutMode(const QPoint& pos, bool shift = false);
// helpers for pressMoveLayoutMode
+ QPoint handlePoint(bool shift, const QPoint& ptFixed, const QPoint& pos, double aspect);
void pressMoveLayoutModeMove(const QPoint& pos, bool shift = false);
void pressMoveLayoutModeResize(const QPoint& pos, bool shift = false);
void pressMoveLayoutModeSelect(const QPoint& pos, bool shift = false);
More information about the Kst
mailing list