[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Fri Dec 2 19:25:26 CET 2005
SVN commit 485051 by staikos:
clip the lines to the view so we don't crash. However this isn't a full
solution because it allows the user to create lines greater than the view on
the bottom or left sides. the line stuff needs a bounding box
M +12 -14 kstgfxlinemousehandler.cpp
M +19 -10 kstgfxmousehandlerutils.cpp
--- trunk/extragear/graphics/kst/kst/kstgfxlinemousehandler.cpp #485050:485051
@@ -23,19 +23,17 @@
#include "kstgfxmousehandlerutils.h"
#include "kst.h"
#include "kstdoc.h"
-#include "kstviewarrow.h"
+#include "kstviewline.h"
#include "kstviewwidget.h"
KstGfxLineMouseHandler::KstGfxLineMouseHandler(KstViewObjectPtr top)
: KstGfxMouseHandler(top) {
// initial default settings before any sticky settings
- KstViewArrowPtr defaultArrow = new KstViewArrow;
- defaultArrow->setHasToArrow(false);
- defaultArrow->setHasFromArrow(false);
- defaultArrow->setWidth(2);
- defaultArrow->setPenStyle(Qt::SolidLine);
- defaultArrow->setForegroundColor(Qt::black);
- _defaultObject = KstViewObjectPtr(defaultArrow);
+ KstViewLinePtr defaultLine = new KstViewLine;
+ defaultLine->setWidth(2);
+ defaultLine->setPenStyle(Qt::SolidLine);
+ defaultLine->setForegroundColor(Qt::black);
+ _defaultObject = KstViewObjectPtr(defaultLine);
}
@@ -78,12 +76,12 @@
_mouseDown = false;
if (!_cancelled && _mouseOrigin != pos) {
- // make a new arrow
- KstViewArrowPtr arrow = new KstViewArrow;
- copyDefaults(KstViewObjectPtr(arrow));
- arrow->setFrom(_prevBand.topLeft());
- arrow->setTo(_prevBand.bottomRight());
- _top->appendChild(KstViewObjectPtr(arrow));
+ // make a new line
+ KstViewLinePtr line = new KstViewLine;
+ copyDefaults(KstViewObjectPtr(line));
+ line->setFrom(_prevBand.topLeft());
+ line->setTo(_prevBand.bottomRight());
+ _top->appendChild(KstViewObjectPtr(line));
KstApp::inst()->document()->setModified();
view->paint(KstPainter::P_PAINT);
}
--- trunk/extragear/graphics/kst/kst/kstgfxmousehandlerutils.cpp #485050:485051
@@ -20,6 +20,8 @@
#include <qrect.h>
#include <qpoint.h>
+#include <kglobal.h>
+
#include "kstgfxmousehandlerutils.h"
QRect KstGfxMouseHandlerUtils::newRect(const QPoint& pos, const QPoint& mouseOrigin, bool shift) {
@@ -27,14 +29,14 @@
QPoint fakePos = pos;
if (shift) {
int negOne = negativeOne(pos, mouseOrigin);
-
+
if (abs(pos.x() - mouseOrigin.x()) < abs(pos.y() - mouseOrigin.y())) {
fakePos.setX(mouseOrigin.x() + negOne*(pos.y() - mouseOrigin.y()));
} else {
- fakePos.setY(mouseOrigin.y() + negOne*(pos.x() - mouseOrigin.x()));
+ fakePos.setY(mouseOrigin.y() + negOne*(pos.x() - mouseOrigin.x()));
}
- }
-
+ }
+
QPoint newTopLeft;
if (mouseOrigin.x() < fakePos.x()) {
newTopLeft.setX(mouseOrigin.x());
@@ -44,15 +46,15 @@
if (mouseOrigin.y() < fakePos.y()) {
newTopLeft.setY(mouseOrigin.y());
} else {
- newTopLeft.setY(fakePos.y());
+ newTopLeft.setY(fakePos.y());
}
QSize newSize(abs(fakePos.x() - mouseOrigin.x()),
abs(fakePos.y() - mouseOrigin.y()));
return QRect(newTopLeft, newSize);
}
-
+
QRect KstGfxMouseHandlerUtils::newLine(const QPoint& pos, const QPoint& mouseOrigin, bool shift) {
QPoint fakePos = pos;
if (shift) {
@@ -67,18 +69,25 @@
if (abs(pos.y() - mouseOrigin.y()) < abs(pos.x() - mouseOrigin.x())/2) {
fakePos.setY(mouseOrigin.y());
} else {
- fakePos.setY(mouseOrigin.y() + negOne*(pos.x() - mouseOrigin.x()));
+ fakePos.setY(mouseOrigin.y() + negOne*(pos.x() - mouseOrigin.x()));
}
}
- }
- return QRect(mouseOrigin, fakePos);
+ }
+ bool topLeft = (mouseOrigin.x() <= fakePos.x() && mouseOrigin.y() <= fakePos.y()) || (mouseOrigin.x() >= fakePos.x() && mouseOrigin.y() >= fakePos.y());
+ QRect lineRect(mouseOrigin, fakePos);
+ QRect boundingRect(0, 0, kMax(mouseOrigin.x(), fakePos.x()), kMax(mouseOrigin.y(), fakePos.y()));
+ QRect reduced = lineRect.normalize().intersect(boundingRect);
+ if (topLeft) {
+ return reduced;
+ }
+ return QRect(reduced.bottomLeft(), reduced.topRight());
}
int KstGfxMouseHandlerUtils::negativeOne(const QPoint& pos, const QPoint& mouseOrigin) {
if ((pos.y() < mouseOrigin.y() && pos.x() > mouseOrigin.x()) ||
(pos.y() > mouseOrigin.y() && pos.x() < mouseOrigin.x())) {
- return -1;
+ return -1;
} else {
return 1;
}
More information about the Kst
mailing list