[Kst] extragear/graphics/kst/kst
Barth Netterfield
netterfield at astro.utoronto.ca
Sat Feb 4 20:23:25 CET 2006
SVN commit 505754 by netterfield:
BUG: 1121108
George's patch + Barth's tweaks.
Reviewed = barth + george (confirmed by phone)
M +47 -10 ksttoplevelview.cpp
M +30 -8 kstviewline.cpp
M +2 -0 kstviewline.h
--- trunk/extragear/graphics/kst/kst/ksttoplevelview.cpp #505753:505754
@@ -780,9 +780,18 @@
}
-void KstTopLevelView::pressMoveLayoutModeEndPoint(const QPoint& pos, bool shift) {
+void KstTopLevelView::pressMoveLayoutModeEndPoint(const QPoint& pos_in, bool shift) {
// FIXME: remove this!! Should not know about any specific type
// for now we only know how to deal with lines
+
+ QPoint pos = pos_in;
+
+ //pos must be inside the tlv
+ pos.setX(QMAX(pos.x(), geometry().left()));
+ pos.setX(QMIN(pos.x(), geometry().right()));
+ pos.setY(QMIN(pos.y(), geometry().bottom()));
+ pos.setY(QMAX(pos.y(), geometry().top()));
+
if (KstViewLinePtr line = kst_cast<KstViewLine>(_pressTarget)) {
const QRect old(_prevBand);
double aspect;
@@ -975,26 +984,54 @@
void KstTopLevelView::releasePressLayoutModeEndPoint(const QPoint& pos, bool shift) {
- Q_UNUSED(pos)
Q_UNUSED(shift)
-
+
if (KstViewLinePtr line = kst_cast<KstViewLine>(_pressTarget)) {
if (_prevBand.left() != -1 && _prevBand.top() != -1) {
- QPoint toPoint, fromPoint;
if (_pressDirection & UP) {
// UP means we are on the start endpoint
- toPoint = _prevBand.bottomRight();
- fromPoint = _prevBand.topLeft();
+ const QPoint toPoint(line->to());
+ QRect band(pos, toPoint);
+ band = band.normalize().intersect(geometry());
+ if (toPoint == band.topLeft()) {
+ line->setFrom(band.bottomRight());
+ } else if (toPoint == band.bottomLeft()) {
+ line->setFrom(band.topRight());
+ } else if (toPoint == band.topRight()) {
+ line->setFrom(band.bottomLeft());
+ } else {
+ line->setFrom(band.topLeft());
+ }
} else if (_pressDirection & DOWN) {
// DOWN means we are on the end endpoint
- fromPoint = _prevBand.topLeft();
- toPoint = _prevBand.bottomRight();
+ const QPoint fromPoint(line->from());
+ QRect band(fromPoint, pos);
+ band = band.normalize().intersect(geometry());
+ if (fromPoint == band.topLeft()) {
+ line->setTo(band.bottomRight());
+ } else if (fromPoint == band.bottomLeft()) {
+ line->setTo(band.topRight());
+ } else if (fromPoint == band.topRight()) {
+ line->setTo(band.bottomLeft());
+ } else {
+ line->setTo(band.topLeft());
+ }
} else {
abort();
}
- line->setFrom(fromPoint);
- line->setTo(toPoint);
_onGrid = false;
+
+ // reparent
+ QRect obj(_pressTarget->geometry());
+ KstViewObjectPtr container = findDeepestChild(obj);
+
+ if (!container) {
+ container = this;
+ }
+ if (container != _pressTarget && !container->children().contains(_pressTarget)) {
+ _pressTarget->detach();
+ container->appendChild(_pressTarget);
+ }
}
}
}
--- trunk/extragear/graphics/kst/kst/kstviewline.cpp #505753:505754
@@ -233,26 +233,48 @@
}
+void KstViewLine::move(const QPoint& pos) {
+ KstViewObject::move(pos);
+ if (_from.x() < _to.x()) {
+ if (_from.y() < _to.y()) {
+ _from = _geom.topLeft();
+ _to = _geom.bottomRight();
+ } else {
+ _from = _geom.bottomLeft();
+ _to = _geom.topRight();
+ }
+ } else {
+ if (_from.y() < _to.y()) {
+ _from = _geom.topRight();
+ _to = _geom.bottomLeft();
+ } else {
+ _from = _geom.bottomRight();
+ _to = _geom.topLeft();
+ }
+ }
+}
+
+
void KstViewLine::updateOrientation() {
if (_from.x() < _to.x()) {
if (_from.y() < _to.y()) {
_orientation = DownRight;
- move(_from);
- resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
+ KstViewObject::move(_from);
+ KstViewObject::resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
} else {
_orientation = UpRight;
- move(QPoint(_from.x(), _to.y()));
- resize(QSize(kMax(_width, _to.x() - _from.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
+ KstViewObject::move(QPoint(_from.x(), _to.y()));
+ 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;
- move(QPoint(_to.x(), _from.y()));
- resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
+ KstViewObject::move(QPoint(_to.x(), _from.y()));
+ KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _to.y() - _from.y() + 1)));
} else {
_orientation = UpLeft;
- move(_to);
- resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
+ KstViewObject::move(_to);
+ KstViewObject::resize(QSize(kMax(_width, _from.x() - _to.x() + 1), kMax(_width, _from.y() - _to.y() + 1)));
}
}
}
--- trunk/extragear/graphics/kst/kst/kstviewline.h #505753:505754
@@ -52,6 +52,8 @@
void setForegroundColor(const QColor& color);
QColor foregroundColor() const;
+ void move(const QPoint& pos);
+
virtual void setCapStyle(Qt::PenCapStyle style);
virtual Qt::PenCapStyle capStyle() const;
virtual void setPenStyle(Qt::PenStyle style);
More information about the Kst
mailing list