|
From: Tapio V. <aa...@us...> - 2011-01-07 18:50:30
|
Module: editor
Branch: master
Commit: 040c809e5dfcc68195485f547421781ab59379db
Author: Tapio Vierros <tap...@gm...>
Date: Fri Jan 7 20:22:25 2011 +0200
Different mouse cursors for note moving, resizing and hovering.
---
notegraphwidget.cc | 5 ++---
notelabel.cc | 31 +++++++++++++++++++++++++++++++
notelabel.hh | 6 ++++--
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index aa87b97..f458cb4 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -106,11 +106,10 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) {
// Determine if it is drag or resize
- const int resizeHandleSize = 5;
- if (hotSpot.x() < resizeHandleSize || hotSpot.x() > child->width() - resizeHandleSize) {
+ if (hotSpot.x() < NoteLabel::resize_margin || hotSpot.x() > child->width() - NoteLabel::resize_margin) {
// Start a resize
m_resizingNote = child;
- child->startResizing( (hotSpot.x() < resizeHandleSize) ? -1 : 1 );
+ child->startResizing( (hotSpot.x() < NoteLabel::resize_margin) ? -1 : 1 );
child->disableFloating();
} else {
diff --git a/notelabel.cc b/notelabel.cc
index df1b958..7deb3cc 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -6,6 +6,8 @@ namespace {
static const int text_margin = 12; // Margin of the label texts
}
+const int NoteLabel::resize_margin = 5; // How many pixels is the resize area
+
NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &position, const QSize &size, bool floating)
: QLabel(parent), m_labelText(text), m_floating(floating), m_resizing(0), m_hotspot()
{
@@ -87,13 +89,42 @@ void NoteLabel::mouseMoveEvent(QMouseEvent *event)
NoteGraphWidget* ngw = dynamic_cast<NoteGraphWidget*>(parent());
if (m_resizing != 0) {
+ // Resizing
if (m_resizing < 0)
setGeometry(x() + event->pos().x(), y(), width() - event->pos().x(), height());
else
resize(event->pos().x(), height());
if (ngw) ngw->updateNotes();
+
} else if (!m_hotspot.isNull()) {
+ // Moving
move(pos() + event->pos() - m_hotspot);
if (ngw) ngw->updateNotes();
+
+ } else {
+ // Hover cursors
+ if (event->pos().x() < NoteLabel::resize_margin || event->pos().x() > width() - NoteLabel::resize_margin) {
+ setCursor(QCursor(Qt::SizeHorCursor));
+ } else {
+ setCursor(QCursor(Qt::OpenHandCursor));
+ }
}
}
+
+void NoteLabel::startResizing(int dir)
+{
+ m_resizing = dir;
+ m_hotspot = QPoint(); // Reset
+ if (dir != 0) setCursor(QCursor(Qt::SizeHorCursor));
+ else setCursor(QCursor());
+}
+
+void NoteLabel::startDragging(const QPoint& point)
+{
+ m_hotspot = point;
+ m_resizing = 0;
+
+ if (!point.isNull()) setCursor(QCursor(Qt::ClosedHandCursor));
+ else setCursor(QCursor());
+}
+
diff --git a/notelabel.hh b/notelabel.hh
index a677ac0..2a0f3a8 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -5,6 +5,8 @@
class NoteLabel: public QLabel
{
public:
+ static const int resize_margin;
+
NoteLabel(const QString &text, QWidget *parent, const QPoint &position = QPoint(), const QSize &size = QSize(), bool floating = true);
void createPixmap(QSize size = QSize());
@@ -14,8 +16,8 @@ public:
bool isFloating() const { return m_floating; }
void disableFloating() { m_floating = false; }
- void startResizing(int dir) { m_resizing = dir; m_hotspot = QPoint(); }
- void startDragging(const QPoint& point) { m_hotspot = point; m_resizing = 0; }
+ void startResizing(int dir);
+ void startDragging(const QPoint& point);
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
|