|
From: Tapio V. <aa...@us...> - 2011-02-24 17:11:52
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 24 18:55:16 2011 +0200
Optimize NoteLabel creation by delaying pixmap generation.
---
notelabel.cc | 6 ++++--
notelabel.hh | 4 +++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/notelabel.cc b/notelabel.cc
index cc5f79e..207b6bc 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -3,6 +3,7 @@
#include <QToolTip>
#include <QPainter>
#include <QMenu>
+#include <QTimer>
#include <iostream>
#include "notelabel.hh"
#include "notegraphwidget.hh"
@@ -18,11 +19,11 @@ const double NoteLabel::min_length = 0.05; // How many seconds minimum
NoteLabel::NoteLabel(const Note ¬e, QWidget *parent, bool floating)
: QLabel(parent), m_note(note), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
{
- createPixmap();
updateLabel();
setMouseTracking(true);
setAttribute(Qt::WA_DeleteOnClose);
- show();
+ // Deferred graphics generation (to make creation quick as object might also be deleted quickly)
+ QTimer::singleShot(2000, this, SLOT(createPixmap()));
}
void NoteLabel::createPixmap()
@@ -76,6 +77,7 @@ void NoteLabel::createPixmap()
setPixmap(QPixmap::fromImage(image));
updateTips();
+ show();
}
void NoteLabel::setSelected(bool state) {
diff --git a/notelabel.hh b/notelabel.hh
index 7f4a139..94602d2 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -15,7 +15,6 @@ public:
NoteLabel(const Note ¬e, QWidget *parent, bool floating = true);
- void createPixmap();
QString lyric() const { return m_note.syllable; }
void setLyric(const QString &text) { m_note.syllable = text; createPixmap(); }
QString description(bool multiline) const;
@@ -42,6 +41,9 @@ public:
bool operator<(const NoteLabel &rhs) const { return m_note.begin < rhs.note().begin; }
+public slots:
+ void createPixmap();
+
protected:
void resizeEvent(QResizeEvent *event);
void moveEvent(QMoveEvent *event);
|