[Kst] extragear/graphics/kst/src/libkstapp
George Staikos
staikos at kde.org
Wed Aug 2 00:57:10 CEST 2006
SVN commit 568686 by staikos:
overwrite the previous two commits with a fix that avoids an off-by-one, which
seems to be the real culprit
M +36 -50 kstgfxmousehandlerutils.cpp
--- trunk/extragear/graphics/kst/src/libkstapp/kstgfxmousehandlerutils.cpp #568685:568686
@@ -16,7 +16,6 @@
***************************************************************************/
#include <stdlib.h>
-#include <stdio.h>
#include <math.h>
#include <qrect.h>
@@ -24,6 +23,7 @@
#include <kglobal.h>
+#include "ksdebug.h"
#include "kstgfxmousehandlerutils.h"
QPoint KstGfxMouseHandlerUtils::findNearestPtOnLine(const QPoint& fromPoint, const QPoint& toPoint, const QPoint& pos, const QRect &bounds) {
@@ -106,68 +106,55 @@
QRect KstGfxMouseHandlerUtils::resizeRectFromEdge(const QRect& originalSize, const QPoint& anchorPoint, const QPoint& movePoint, const QPoint& pos, const QRect &bounds, bool maintainAspect) {
- QRect newSize;
+ QRect newSize(originalSize);
- if (movePoint.y() == anchorPoint.y() ) {
- int newWidth = pos.x() - anchorPoint.x() + 1; // +1 for the way widths are defined in QRect.
- double newHalfHeight = originalSize.height()/2.0;
+ if (movePoint.y() == anchorPoint.y()) {
+ int newWidth = pos.x() - anchorPoint.x() + 1; // +1 for the way widths are defined in QRect.
- if (maintainAspect) {
- newHalfHeight = originalSize.height()*abs(newWidth)/originalSize.width()/2.0;
+ if (maintainAspect) {
+ double newHalfHeight = originalSize.height() * abs(newWidth) / originalSize.width() / 2.0;
- newHalfHeight = kMin(double(movePoint.y() - bounds.top()), newHalfHeight); // ensure we are still within the bounds.
- newHalfHeight = kMin(double(bounds.bottom() - movePoint.y()), newHalfHeight);
+ newHalfHeight = kMin(double(movePoint.y() - bounds.top()), newHalfHeight); // ensure we are still within the bounds.
+ newHalfHeight = kMin(double(bounds.bottom() - movePoint.y()), newHalfHeight);
- if (newWidth == 0) {
- newWidth = 1;
- } // anything better to be done?
+ if (newWidth == 0) { // anything better to be done?
+ newWidth = 1;
+ }
- newWidth = int(originalSize.width()*newHalfHeight*2.0/originalSize.height()*newWidth/abs(newWidth)); // consistency of width w/ the newly calculated height.
- }
+ newWidth = int(originalSize.width() * newHalfHeight * 2.0 / originalSize.height() * newWidth / abs(newWidth)); // consistency of width w/ the newly calculated height.
+ newSize.setTop(anchorPoint.y() + int(newHalfHeight));
+ newSize.setBottom(anchorPoint.y() - int(newHalfHeight));
+ }
- newSize.setLeft(anchorPoint.x());
- newSize.setWidth(newWidth);
- newSize.setTop(anchorPoint.y() + int(newHalfHeight));
- newSize.setBottom(anchorPoint.y() - int(newHalfHeight));
+ newSize.setLeft(anchorPoint.x());
+ newSize.setWidth(newWidth);
- } else if (movePoint.x() == anchorPoint.x() ) {
- // mimic the case for (movePoint.y() == anchorPoint.y()). comments are there.
- int newHeight = pos.y() - anchorPoint.y() + 1;
- double newHalfWidth = originalSize.width()/2.0;
+ } else if (movePoint.x() == anchorPoint.x()) {
+ // mimic the case for (movePoint.y() == anchorPoint.y()). comments are there.
+ int newHeight = pos.y() - anchorPoint.y() + 1;
- if (maintainAspect) {
- newHalfWidth = originalSize.width()*abs(newHeight)/originalSize.height()/2.0;
+ if (maintainAspect) {
+ double newHalfWidth = originalSize.width() * abs(newHeight) / originalSize.height() / 2.0;
- newHalfWidth = kMin(double(movePoint.x() - bounds.left()), newHalfWidth);
- newHalfWidth = kMin(double(bounds.right() - movePoint.x()), newHalfWidth);
+ newHalfWidth = kMin(double(movePoint.x() - bounds.left()), newHalfWidth);
+ newHalfWidth = kMin(double(bounds.right() - movePoint.x()), newHalfWidth);
- if (newHeight == 0) {
- newHeight = 1;
+ if (newHeight == 0) {
+ newHeight = 1;
+ }
+
+ newHeight = int(originalSize.height() * newHalfWidth * 2.0 / originalSize.width() * newHeight / abs(newHeight));
+ newSize.setLeft(anchorPoint.x() + int(newHalfWidth));
+ newSize.setRight(anchorPoint.x() - int(newHalfWidth));
}
- newHeight = int(originalSize.height()*newHalfWidth*2.0/originalSize.width()*newHeight/abs(newHeight));
+ newSize.setTop(anchorPoint.y());
+ newSize.setHeight(newHeight);
}
- newSize.setTop(anchorPoint.y());
- newSize.setHeight(newHeight);
- newSize.setLeft(anchorPoint.x() + int(newHalfWidth));
- newSize.setRight(anchorPoint.x() - int(newHalfWidth));
- }
+ newSize = newSize.normalize();
- if (newSize.width() < 0) {
- int width = newSize.width();
- newSize.setLeft(newSize.left() + width);
- newSize.setRight(newSize.left() + (width * -1));
- }
- if (newSize.height() < 0) {
- int height = newSize.height();
- newSize.setTop(newSize.top() + height);
- newSize.setBottom(newSize.top() + (height * -1));
- }
-
- newSize = newSize.normalize();
-
- return newSize;
+ return newSize;
}
@@ -188,8 +175,7 @@
QRect KstGfxMouseHandlerUtils::newLine(const QPoint& pos, const QPoint& mouseOrigin, bool specialAspect, const QRect& bounds) {
if (KDE_ISLIKELY(!specialAspect)) {
- QPoint npos = KstGfxMouseHandlerUtils::findNearestPtOnLine(mouseOrigin, pos, pos, bounds);
- return QRect(mouseOrigin, npos);
+ return QRect(mouseOrigin,pos);
} else { //want special 45deg, or vertical, or horizontal line.
QPoint npos;
QPoint mouseDisplacement(pos - mouseOrigin); // for picking type of line..
More information about the Kst
mailing list