|
From: Tapio V. <aa...@us...> - 2011-01-07 12:42:58
|
Module: editor
Branch: master
Commit: 02a9224d89a3d712994f0282629b94e94606037e
Author: Tapio Vierros <tap...@gm...>
Date: Fri Jan 7 14:42:33 2011 +0200
Notes now remember their width after dragging.
---
notegraphwidget.cc | 7 ++++---
notelabel.cc | 17 ++++++++---------
notelabel.hh | 2 +-
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 3ba2375..74a7290 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -131,8 +131,9 @@ void NoteGraphWidget::dropEvent(QDropEvent *event)
QString text;
QPoint offset;
- dataStream >> text >> offset;
- new NoteLabel(text, this, event->pos() - offset, false);
+ int w;
+ dataStream >> text >> offset >> w;
+ new NoteLabel(text, this, event->pos() - offset, QSize(w, 0), false);
updateNotes();
if (event->source() == this) {
@@ -170,7 +171,7 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << child->getText() << QPoint(hotSpot);
+ dataStream << child->getText() << QPoint(hotSpot) << child->width();
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/x-notelabel", itemData);
diff --git a/notelabel.cc b/notelabel.cc
index 42ac8a1..3af1271 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -5,10 +5,10 @@ namespace {
static const int text_margin = 12; // Margin of the label texts
}
-NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &position, bool floating)
+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)
{
- createPixmap();
+ createPixmap(size);
if (!position.isNull())
move(position);
@@ -19,13 +19,12 @@ NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &positio
void NoteLabel::createPixmap(QSize size)
{
- if (!size.isValid()) {
- QFontMetrics metric(font());
- size = metric.size(Qt::TextSingleLine, m_labelText);
- size.rwidth() += text_margin;
- size.rheight() += text_margin;
- // FIXME: Size is fixed
- size.rwidth() = 50;
+ QFontMetrics metric(font());
+ if (size.width() <= 0) {
+ size.rwidth() = 50; // FIXME: Size is fixed
+ }
+ if (size.height() <= 0) {
+ size.rheight() = metric.size(Qt::TextSingleLine, m_labelText).height() + text_margin;
}
QImage image(size.width(), size.height(),
diff --git a/notelabel.hh b/notelabel.hh
index 258d5ce..4e1bb7f 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -5,7 +5,7 @@
class NoteLabel: public QLabel
{
public:
- NoteLabel(const QString &text, QWidget *parent, const QPoint &position = QPoint(), bool floating = true);
+ NoteLabel(const QString &text, QWidget *parent, const QPoint &position = QPoint(), const QSize &size = QSize(), bool floating = true);
void createPixmap(QSize size = QSize());
QString getText() const;
|