|
From: Tapio V. <aa...@us...> - 2011-01-07 12:42:56
|
Module: editor
Branch: master
Commit: 26b0632e4218d7508aa671158477dc9792109ccd
Author: Tapio Vierros <tap...@gm...>
Date: Fri Jan 7 14:32:07 2011 +0200
Notes can be resized by dragging from borders.
---
notegraphwidget.cc | 55 +++++++++++++++++++++++++++++++++++-----------------
notegraphwidget.hh | 2 +
notelabel.cc | 12 ++++++++--
notelabel.hh | 3 ++
4 files changed, 51 insertions(+), 21 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 23b1ac8..3ba2375 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -5,7 +5,7 @@
#include "notegraphwidget.hh"
NoteGraphWidget::NoteGraphWidget(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), m_resizing()
{
setAcceptDrops(true);
}
@@ -157,27 +157,39 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
// Left Click
if (event->button() == Qt::LeftButton) {
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << child->getText() << QPoint(hotSpot);
+ // Determine if it is drag or resize
+ const int resizeHandleSize = 5;
+ if (hotSpot.x() < resizeHandleSize || hotSpot.x() > child->width() - resizeHandleSize) {
+ // Start a resize
+ m_resizing = child;
+ child->setResizing( (hotSpot.x() < resizeHandleSize) ? -1 : 1 );
+ std::cout << "resize" << std::endl;
- QMimeData *mimeData = new QMimeData;
- mimeData->setData("application/x-notelabel", itemData);
- mimeData->setText(child->getText());
+ } else {
+ // Initialize Drag
- QDrag *drag = new QDrag(this);
- drag->setMimeData(mimeData);
- drag->setPixmap(*child->pixmap());
- drag->setHotSpot(hotSpot);
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ dataStream << child->getText() << QPoint(hotSpot);
- child->disableFloating();
- child->createPixmap();
- child->hide();
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("application/x-notelabel", itemData);
+ mimeData->setText(child->getText());
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(*child->pixmap());
+ drag->setHotSpot(hotSpot);
+
+ child->disableFloating();
+ child->createPixmap();
+ child->hide();
- if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
- child->close();
- else
- child->show();
+ if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
+ child->close();
+ else
+ child->show();
+ }
// Right Click
} else if (event->button() == Qt::RightButton) {
@@ -197,6 +209,13 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
}
}
+void NoteGraphWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ (void)*event;
+ m_resizing->setResizing(0);
+ m_resizing = NULL;
+}
+
void NoteGraphWidget::wheelEvent(QWheelEvent *event)
{
NoteLabel *child = static_cast<NoteLabel*>(childAt(event->pos()));
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index bd5ebc5..a3587b0 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -22,11 +22,13 @@ protected:
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void mousePressEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
void mouseDoubleClickEvent(QMouseEvent * event);
private:
int m_requiredWidth;
+ NoteLabel* m_resizing;
NoteLabels m_notes;
};
diff --git a/notelabel.cc b/notelabel.cc
index a47ee73..42ac8a1 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -6,7 +6,7 @@ namespace {
}
NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &position, bool floating)
- : QLabel(parent), m_labelText(text), m_floating(floating)
+ : QLabel(parent), m_labelText(text), m_floating(floating), m_resizing(0)
{
createPixmap();
if (!position.isNull())
@@ -24,9 +24,9 @@ void NoteLabel::createPixmap(QSize size)
size = metric.size(Qt::TextSingleLine, m_labelText);
size.rwidth() += text_margin;
size.rheight() += text_margin;
+ // FIXME: Size is fixed
+ size.rwidth() = 50;
}
- // FIXME: Size is fixed
- size.rwidth() = 50;
QImage image(size.width(), size.height(),
QImage::Format_ARGB32_Premultiplied);
@@ -83,4 +83,10 @@ void NoteLabel::resizeEvent(QResizeEvent *event)
void NoteLabel::mouseMoveEvent(QMouseEvent *event)
{
QToolTip::showText(event->globalPos(), getText(), this);
+ if (m_resizing != 0) {
+ if (m_resizing < 0)
+ setGeometry(x() + event->pos().x(), y(), width() - event->pos().x(), height());
+ else
+ resize(event->pos().x(), height());
+ }
}
diff --git a/notelabel.hh b/notelabel.hh
index 5147685..258d5ce 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -14,6 +14,8 @@ public:
bool isFloating() const { return m_floating; }
void disableFloating() { m_floating = false; }
+ void setResizing(int dir) { m_resizing = dir; }
+
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
@@ -22,6 +24,7 @@ public:
private:
QString m_labelText;
bool m_floating;
+ int m_resizing;
};
bool inline cmpNoteLabelPtr(const NoteLabel *lhs, const NoteLabel *rhs)
|