|
From: Tapio V. <aa...@us...> - 2011-02-24 17:43:50
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 24 19:42:37 2011 +0200
Further NoteLabel creation optimization: now really defer the pixmap creation.
---
editorapp.cc | 4 ++--
notegraphwidget.cc | 2 +-
notelabel.cc | 11 ++++++-----
notelabel.hh | 13 ++++++++-----
notelabelmanager.cc | 1 -
5 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index eb42c71..3bed318 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -182,7 +182,7 @@ void EditorApp::doOpStack()
noteGraph->clearNotes();
QString newMusic = "";
OperationStack::iterator opit = opStack.begin();
-
+QElapsedTimer t; t.start();
// Re-apply all operations in the stack
while (opit != opStack.end()) {
//std::cout << "Doing op: " << opit->dump() << std::endl;
@@ -219,7 +219,7 @@ void EditorApp::doOpStack()
erased = false;
}
}
-
+ std::cout << t.elapsed() << std::endl;
noteGraph->updateNotes();
if (!newMusic.isEmpty()) setMusic(newMusic);
updateMenuStates();
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 47cc182..68dba06 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -374,7 +374,7 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
m_selectedAction = MOVE;
child->startDragging(hotSpot);
}
- child->createPixmap();
+ child->updatePixmap();
// Middle Click
} else if (event->button() == Qt::MiddleButton) {
diff --git a/notelabel.cc b/notelabel.cc
index 207b6bc..36484e7 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -21,13 +21,13 @@ NoteLabel::NoteLabel(const Note ¬e, QWidget *parent, bool floating)
{
updateLabel();
setMouseTracking(true);
- setAttribute(Qt::WA_DeleteOnClose);
// Deferred graphics generation (to make creation quick as object might also be deleted quickly)
- QTimer::singleShot(2000, this, SLOT(createPixmap()));
+ QTimer::singleShot(500, this, SLOT(createPixmap()));
}
-void NoteLabel::createPixmap()
+void NoteLabel::updatePixmap()
{
+ if (isHidden()) return;
QFont font;
font.setStyleStrategy(QFont::ForceOutline);
QFontMetrics metric(font);
@@ -82,7 +82,8 @@ void NoteLabel::createPixmap()
void NoteLabel::setSelected(bool state) {
if (m_selected != state) {
- m_selected = state; createPixmap();
+ m_selected = state;
+ updatePixmap();
if (!m_selected) {
startResizing(0); // Reset
startDragging(QPoint()); // Reset
@@ -90,7 +91,7 @@ void NoteLabel::setSelected(bool state) {
}
}
-void NoteLabel::resizeEvent(QResizeEvent *) { createPixmap(); }
+void NoteLabel::resizeEvent(QResizeEvent *) { updatePixmap(); }
void NoteLabel::moveEvent(QMoveEvent *) { updateTips(); }
diff --git a/notelabel.hh b/notelabel.hh
index 94602d2..c054705 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -1,6 +1,7 @@
#pragma once
#include <QLabel>
+#include <QCloseEvent>
#include "notes.hh"
#include "operation.hh"
@@ -16,7 +17,7 @@ public:
NoteLabel(const Note ¬e, QWidget *parent, bool floating = true);
QString lyric() const { return m_note.syllable; }
- void setLyric(const QString &text) { m_note.syllable = text; createPixmap(); }
+ void setLyric(const QString &text) { m_note.syllable = text; updatePixmap(); }
QString description(bool multiline) const;
bool isSelected() const { return m_selected; }
@@ -28,10 +29,10 @@ public:
void updateTips();
bool isFloating() const { return m_floating; }
- void setFloating(bool state) { m_floating = state; createPixmap(); }
+ void setFloating(bool state) { m_floating = state; updatePixmap(); }
bool isLineBreak() const { return m_note.lineBreak; }
- void setLineBreak(bool state) { m_note.lineBreak = state; createPixmap(); }
- void setType(int newtype) { m_note.type = Note::types[newtype]; createPixmap(); }
+ void setLineBreak(bool state) { m_note.lineBreak = state; updatePixmap(); }
+ void setType(int newtype) { m_note.type = Note::types[newtype]; updatePixmap(); }
void startResizing(int dir);
void startDragging(const QPoint& point);
@@ -42,12 +43,14 @@ public:
bool operator<(const NoteLabel &rhs) const { return m_note.begin < rhs.note().begin; }
public slots:
- void createPixmap();
+ void createPixmap() { show(); updatePixmap(); }
+ void updatePixmap();
protected:
void resizeEvent(QResizeEvent *event);
void moveEvent(QMoveEvent *event);
void mouseMoveEvent(QMouseEvent *event);
+ void closeEvent(QCloseEvent *event) { deleteLater(); event->accept(); }
private:
Note m_note;
diff --git a/notelabelmanager.cc b/notelabelmanager.cc
index 5d3f95f..d675786 100644
--- a/notelabelmanager.cc
+++ b/notelabelmanager.cc
@@ -375,7 +375,6 @@ void NoteLabelManager::doOperation(const Operation& op, int flags)
} else {
std::cerr << "Error: Unkown operation type " << action.toStdString() << std::endl;
}
- n->createPixmap();
}
}
} catch (std::runtime_error&) {
|