[Kst] kdeextragear-2/kst/kst
George Staikos
staikos at kde.org
Tue Apr 6 19:47:05 CEST 2004
CVS commit by staikos:
set the cursor over objects
M +51 -0 ksttoplevelview.cpp 1.9
M +3 -0 ksttoplevelview.h 1.7
M +4 -0 kstviewobject.cpp 1.11
M +1 -0 kstviewobject.h 1.9
--- kdeextragear-2/kst/kst/ksttoplevelview.cpp #1.8:1.9
@@ -19,4 +19,5 @@
#include <assert.h>
+#include <qapplication.h>
KstTopLevelView::KstTopLevelView(QWidget *parent, const char *name, WFlags w) : KstViewObject(), _w(new KstViewWidget(this, parent, name, w)) {
@@ -80,4 +81,5 @@ void KstTopLevelView::paint(bool erase)
void KstTopLevelView::clearFocus() {
if (_focusOn) {
+ _w->unsetCursor();
_focusOn = false;
recursively<bool>(&KstViewObject::setFocus, false);
@@ -95,5 +97,7 @@ void KstTopLevelView::updateFocus(const
KstViewObjectPtr p = findChild(pos);
if (p) {
+ setCursorFor(pos, p->geometry());
if (p->focused()) {
+ assert(_focusOn);
return;
}
@@ -123,4 +127,51 @@ void KstTopLevelView::setViewMode(ViewMo
+void KstTopLevelView::setCursorFor(const QPoint& pos, const QRect& objGeom) {
+ char direction = 0;
+#define UP 1
+#define DOWN 2
+#define LEFT 4
+#define RIGHT 8
+
+ if (pos.x() < objGeom.left() + 4) {
+ direction |= LEFT;
+ } else if (pos.x() > objGeom.right() - 4) {
+ direction |= RIGHT;
+ }
+
+ if (pos.y() < objGeom.top() + 4) {
+ direction |= UP;
+ } else if (pos.y() > objGeom.bottom() - 4) {
+ direction |= DOWN;
+ }
+
+ switch(direction) {
+ case UP:
+ case DOWN:
+ _cursor.setShape(Qt::SizeVerCursor);
+ break;
+ case LEFT:
+ case RIGHT:
+ _cursor.setShape(Qt::SizeHorCursor);
+ break;
+ case UP|LEFT:
+ case DOWN|LEFT:
+ _cursor.setShape(Qt::SizeFDiagCursor);
+ break;
+ case UP|RIGHT:
+ case DOWN|RIGHT:
+ _cursor.setShape(Qt::SizeBDiagCursor);
+ break;
+ default:
+ _cursor.setShape(Qt::SizeAllCursor);
+ break;
+ }
+
+ if (_cursor.shape() != _w->cursor().shape()) {
+ _w->setCursor(_cursor);
+ }
+}
+
+
#include "ksttoplevelview.moc"
// vim: ts=2 sw=2 et
--- kdeextragear-2/kst/kst/ksttoplevelview.h #1.6:1.7
@@ -21,4 +21,5 @@
#include "kstviewobject.h"
#include "kstviewwidget.h"
+#include <qcursor.h>
#include <qpainter.h>
#include <qwidget.h>
@@ -43,4 +44,5 @@ class KstTopLevelView : public KstViewOb
void clearFocus();
void updateFocus(const QPoint& pos);
+ void setCursorFor(const QPoint& pos, const QRect& objGeom);
enum ViewMode { LayoutMode = 0, DisplayMode, Unknown = 15 };
@@ -58,4 +60,5 @@ class KstTopLevelView : public KstViewOb
bool _focusOn : 1;
ViewMode _mode : 4;
+ QCursor _cursor;
};
--- kdeextragear-2/kst/kst/kstviewobject.cpp #1.10:1.11
@@ -270,4 +270,8 @@ KstViewObjectPtr KstViewObject::findChil
+QRect KstViewObject::geometry() const {
+ return QRect(_pos, _size);
+}
+
#include "kstviewobject.moc"
// vim: ts=2 sw=2 et
--- kdeextragear-2/kst/kst/kstviewobject.h #1.8:1.9
@@ -51,4 +51,5 @@ class KstViewObject : public KstObject {
virtual QSize size() const;
virtual QPoint position() const;
+ virtual QRect geometry() const;
virtual void move(const QPoint& to);
More information about the Kst
mailing list