[Kst] [Bug 131739] Snap to behaviour does not operate during a resize
Andrew Walker
arwalker at sumusltd.com
Fri May 4 02:58:43 CEST 2007
------- 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=131739
------- Additional Comments From arwalker sumusltd com 2007-05-04 02:58 -------
SVN commit 660878 by arwalker:
CCBUG:131739 still needs further testing
M +11 -2 kstgfxmousehandlerutils.cpp
M +92 -15 ksttoplevelview.cpp
M +3 -0 ksttoplevelview.h
--- branches/work/kst/1.5/kst/src/libkstapp/kstgfxmousehandlerutils.cpp #660877:660878
@ -175,15 +175,24 @
if (vertical) {
newHalfHeight = kMin(newHalfHeight, anchorPoint.y() - bounds.top());
newHalfHeight = kMin(newHalfHeight, bounds.bottom() - anchorPoint.y());
- newSize.scale(originalRect.width(), 2*newHalfHeight, QSize::ScaleMin);
+ if (newHalfHeight > originalRect.height()/2) {
+ newSize.scale(originalRect.width(), 2*newHalfHeight, QSize::ScaleMax);
+ } else {
+ newSize.scale(originalRect.width(), 2*newHalfHeight, QSize::ScaleMin);
+ }
} else {
newHalfWidth = kMin(newHalfWidth, anchorPoint.x() - bounds.left());
newHalfWidth = kMin(newHalfWidth, bounds.right() - anchorPoint.x());
- newSize.scale(2*newHalfWidth, originalRect.height(), QSize::ScaleMin);
+ if (newHalfWidth > originalRect.width()/2) {
+ newSize.scale(2*newHalfWidth, originalRect.height(), QSize::ScaleMax);
+ } else {
+ newSize.scale(2*newHalfWidth, originalRect.height(), QSize::ScaleMin);
+ }
}
newRect.setSize(newSize);
newRect.moveCenter(anchorPoint);
+ newRect = newRect.intersect(bounds);
} else {
if (vertical) {
newRect = QRect(0, 0, originalRect.width(), 2*newHalfHeight);
--- branches/work/kst/1.5/kst/src/libkstapp/ksttoplevelview.cpp #660877:660878
@ -599,6 +599,91 @
}
+void KstTopLevelView::pointSnapToBorders(int *xMin, int *yMin, const KstViewObjectPtr &obj, const QPoint &p) const {
+ for (KstViewObjectList::ConstIterator i = obj->children().begin(); i != obj->children().end(); ++i) {
+ if (_pressTarget != *i) {
+ const QRect rect((*i)->geometry());
+
+ pointSnapToBorders(xMin, yMin, *i, p);
+
+ if (rect.top() <= p.y() && rect.bottom() >= p.y()) {
+ if (labs(p.x() - rect.left()) < labs(*xMin)) {
+ *xMin = p.x() - rect.left();
+ } else if (labs(p.x() - rect.right()) < labs(*xMin)) {
+ *xMin = p.x() - rect.right();
+ }
+ }
+
+ if (rect.left() <= p.x() && rect.right() >= p.x()) {
+ if (labs(p.y() - rect.top()) < labs(*yMin)) {
+ *yMin = p.y() - rect.top();
+ } else if (labs(p.y() - rect.bottom()) < labs(*yMin)) {
+ *yMin = p.y() - rect.bottom();
+ }
+ }
+ }
+ }
+}
+
+
+QPoint KstTopLevelView::pointSnapToObjects(const QPoint& p) {
+ QRect rectNew;
+ QRect r;
+ int xMin = STICKY_THRESHOLD;
+ int yMin = STICKY_THRESHOLD;
+
+ r.setTopLeft(QPoint(0, 0));
+ r.setBottomRight(p);
+
+ pointSnapToBorders(&xMin, &yMin, this, p);
+
+ if (labs(yMin) < STICKY_THRESHOLD) {
+ r.setBottom(r.bottom() - yMin);
+ }
+
+ if (labs(xMin) < STICKY_THRESHOLD) {
+ r.setRight(r.right() - xMin);
+ }
+
+ return r.bottomRight();
+}
+
+
+QRect KstTopLevelView::resizeCenteredSnapToObjects(const QRect& r, const QRect& bounds, int direction) {
+ QRect rectNew = r;
+ int xMin = STICKY_THRESHOLD;
+ int yMin = STICKY_THRESHOLD;
+
+ resizeSnapToBorders(&xMin, &yMin, this, r, direction);
+
+ if (labs(yMin) < STICKY_THRESHOLD) {
+ if (direction & UP) {
+ rectNew.setTop(r.top() - yMin);
+ rectNew.setBottom(r.bottom() + yMin);
+ } else if (direction & DOWN) {
+ rectNew.setBottom(r.bottom() - yMin);
+ rectNew.setTop(r.top() + yMin);
+ }
+ }
+
+ if (labs(xMin) < STICKY_THRESHOLD) {
+ if (direction & LEFT) {
+ rectNew.setLeft(r.left() - xMin);
+ rectNew.setRight(r.right() + xMin);
+ } else if (direction & RIGHT) {
+ rectNew.setRight(r.right() - xMin);
+ rectNew.setLeft(r.left() + xMin);
+ }
+ }
+
+ if (!bounds.contains(rectNew)) {
+ rectNew = r;
+ }
+
+ return rectNew.normalize();
+}
+
+
QRect KstTopLevelView::resizeSnapToObjects(const QRect& r, int direction) {
QRect rectNew = r;
int xMin = STICKY_THRESHOLD;
@ -609,28 +694,16 @
if (labs(yMin) < STICKY_THRESHOLD) {
if (direction & UP) {
rectNew.setTop(r.top() - yMin);
- if (direction & CENTEREDRESIZE) {
- rectNew.setBottom(r.bottom() + yMin);
- }
} else if (direction & DOWN) {
rectNew.setBottom(r.bottom() - yMin);
- if (direction & CENTEREDRESIZE) {
- rectNew.setTop(r.top() + yMin);
- }
}
}
if (labs(xMin) < STICKY_THRESHOLD) {
if (direction & LEFT) {
rectNew.setLeft(r.left() - xMin);
- if (direction & CENTEREDRESIZE) {
- rectNew.setRight(r.right() + xMin);
- }
} else if (direction & RIGHT) {
rectNew.setRight(r.right() - xMin);
- if (direction & CENTEREDRESIZE) {
- rectNew.setLeft(r.left() + xMin);
- }
}
}
@ -851,6 +924,10 @
}
}
+ if (snapToBorder) {
+ movePoint = pointSnapToObjects(movePoint);
+ }
+
const QRect old(_prevBand);
_prevBand.setTopLeft(*fromPoint);
_prevBand.setBottomRight(*toPoint);
@ -873,11 +950,11 @
void KstTopLevelView::pressMoveLayoutModeCenteredResize(const QPoint& pos, bool maintainAspect, bool snapToBorder) {
//centered resize means that the center of the object stays constant
const QRect old(_prevBand);
-
+
_prevBand = newSizeCentered(_pressTarget->geometry(), _pressTarget->_parent->geometry(), _pressDirection, pos, maintainAspect);
if (snapToBorder) {
- _prevBand = resizeSnapToObjects(_prevBand, _pressDirection);
+ _prevBand = resizeCenteredSnapToObjects(_prevBand, _pressTarget->_parent->geometry(), _pressDirection);
}
if (_prevBand != old) {
@ -933,7 +1010,7 @
if (!_selectionList.isEmpty()) {
for (KstViewObjectList::ConstIterator i = _selectionList.begin(); i != _selectionList.end(); ++i) {
obj = obj.unite((*i)->geometry());
- }
+ }
}
const QPoint objOffset(old.topLeft() - obj.topLeft());
--- branches/work/kst/1.5/kst/src/libkstapp/ksttoplevelview.h #660877:660878
@ -131,7 +131,10 @
QRect correctHeightForRatio(const QRect& oldRect, double ratio, int direction, int origRight, int origLeft);
void moveSnapToBorders(int *xMin, int *yMin, const KstViewObjectPtr &obj, const QRect &r) const;
void resizeSnapToBorders(int *xMin, int *yMin, const KstViewObjectPtr& obj, const QRect &r, int direction) const;
+ QRect resizeCenteredSnapToObjects(const QRect& r, const QRect& bounds, int direction);
QRect resizeSnapToObjects(const QRect& r, int direction);
+ void pointSnapToBorders(int *xMin, int *yMin, const KstViewObjectPtr &obj, const QPoint &p) const;
+ QPoint pointSnapToObjects(const QPoint& p);
// Called as a response to drag re-entering widget()
void restartMove();
More information about the Kst
mailing list