|
From: Tapio V. <aa...@us...> - 2011-02-24 18:26:33
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 24 20:11:24 2011 +0200
More optimizations.
---
notelabel.cc | 4 ++--
notelabel.hh | 10 ++++++----
notelabelmanager.cc | 24 ++++++++++++++----------
3 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/notelabel.cc b/notelabel.cc
index 36484e7..91c32c6 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -3,7 +3,6 @@
#include <QToolTip>
#include <QPainter>
#include <QMenu>
-#include <QTimer>
#include <iostream>
#include "notelabel.hh"
#include "notegraphwidget.hh"
@@ -12,6 +11,7 @@ namespace {
static const int text_margin = 3; // Margin of the label texts
}
+const int NoteLabel::render_delay = 200; // How many ms to wait before updating pixmap after some action
const int NoteLabel::resize_margin = 5; // How many pixels is the resize area
const double NoteLabel::default_length = 0.5; // The preferred size of notes
const double NoteLabel::min_length = 0.05; // How many seconds minimum
@@ -83,7 +83,7 @@ void NoteLabel::updatePixmap()
void NoteLabel::setSelected(bool state) {
if (m_selected != state) {
m_selected = state;
- updatePixmap();
+ QTimer::singleShot(render_delay, this, SLOT(updatePixmap()));
if (!m_selected) {
startResizing(0); // Reset
startDragging(QPoint()); // Reset
diff --git a/notelabel.hh b/notelabel.hh
index c054705..ab14763 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -2,6 +2,7 @@
#include <QLabel>
#include <QCloseEvent>
+#include <QTimer>
#include "notes.hh"
#include "operation.hh"
@@ -10,6 +11,7 @@ class NoteLabel: public QLabel
Q_OBJECT
public:
+ static const int render_delay;
static const int resize_margin;
static const double default_length;
static const double min_length;
@@ -17,7 +19,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; updatePixmap(); }
+ void setLyric(const QString &text) { m_note.syllable = text; QTimer::singleShot(render_delay, this, SLOT(updatePixmap())); }
QString description(bool multiline) const;
bool isSelected() const { return m_selected; }
@@ -29,10 +31,10 @@ public:
void updateTips();
bool isFloating() const { return m_floating; }
- void setFloating(bool state) { m_floating = state; updatePixmap(); }
+ void setFloating(bool state) { m_floating = state; QTimer::singleShot(render_delay, this, SLOT(updatePixmap())); }
bool isLineBreak() const { return m_note.lineBreak; }
- void setLineBreak(bool state) { m_note.lineBreak = state; updatePixmap(); }
- void setType(int newtype) { m_note.type = Note::types[newtype]; updatePixmap(); }
+ void setLineBreak(bool state) { m_note.lineBreak = state; QTimer::singleShot(render_delay, this, SLOT(updatePixmap())); }
+ void setType(int newtype) { m_note.type = Note::types[newtype]; QTimer::singleShot(render_delay, this, SLOT(updatePixmap())); }
void startResizing(int dir);
void startDragging(const QPoint& point);
diff --git a/notelabelmanager.cc b/notelabelmanager.cc
index d675786..4bf3ed3 100644
--- a/notelabelmanager.cc
+++ b/notelabelmanager.cc
@@ -244,13 +244,15 @@ void NoteLabelManager::move(NoteLabel *note, int value)
op << getNoteLabelId(n)
<< px2s(n->x()) << px2s(n->x() + n->width())
<< int(round(px2n(n->y() + m_noteHalfHeight))) + value;
- doOperation(op);
+ doOperation(op, Operation::NO_UPDATE);
}
// Combine to one undo operation
if (i > 1) {
- doOperation(Operation("COMBINER", i));
+ doOperation(Operation("COMBINER", i), Operation::NO_UPDATE);
}
+
+ updateNotes();
}
void NoteLabelManager::setType(NoteLabel *note, int index)
@@ -261,7 +263,8 @@ void NoteLabelManager::setType(NoteLabel *note, int index)
if (note->note().getTypeInt() == index) return;
Operation op("TYPE");
op << getNoteLabelId(note) << index;
- doOperation(op);
+ doOperation(op, Operation::NO_UPDATE);
+ return;
}
// Multiple notes selected: apply to all
@@ -269,9 +272,9 @@ void NoteLabelManager::setType(NoteLabel *note, int index)
for (; i < m_selectedNotes.size(); ++i) {
Operation op("TYPE");
op << getNoteLabelId(m_selectedNotes[i]) << index;
- doOperation(op);
+ doOperation(op, Operation::NO_UPDATE);
}
- doOperation(Operation("COMBINER", i));
+ doOperation(Operation("COMBINER", i), Operation::NO_UPDATE);
}
void NoteLabelManager::setFloating(NoteLabel *note, bool state)
@@ -281,12 +284,13 @@ void NoteLabelManager::setFloating(NoteLabel *note, bool state)
if (m_selectedNotes.size() == 1 || !note->isSelected()) {
if (note->isFloating() == state) return;
doOperation(Operation("FLOATING", getNoteLabelId(note), state));
+ return;
}
// Multiple notes selected: apply to all
int i = 0;
for (; i < m_selectedNotes.size(); ++i) {
- doOperation(Operation("FLOATING", getNoteLabelId(m_selectedNotes[i]), state));
+ doOperation(Operation("FLOATING", getNoteLabelId(m_selectedNotes[i]), state), Operation::NO_UPDATE);
}
doOperation(Operation("COMBINER", i));
}
@@ -297,15 +301,15 @@ void NoteLabelManager::setLineBreak(NoteLabel *note, bool state)
// Easy case: only one note
if (m_selectedNotes.size() == 1 || !note->isSelected()) {
if (note->isLineBreak() == state) return;
- doOperation(Operation("LINEBREAK", getNoteLabelId(note), state));
+ doOperation(Operation("LINEBREAK", getNoteLabelId(note), state), Operation::NO_UPDATE);
}
// Multiple notes selected: apply to all
int i = 0;
for (; i < m_selectedNotes.size(); ++i) {
- doOperation(Operation("LINEBREAK", getNoteLabelId(m_selectedNotes[i]), state));
+ doOperation(Operation("LINEBREAK", getNoteLabelId(m_selectedNotes[i]), state), Operation::NO_UPDATE);
}
- doOperation(Operation("COMBINER", i));
+ doOperation(Operation("COMBINER", i), Operation::NO_UPDATE);
}
void NoteLabelManager::editLyric(NoteLabel *note) {
@@ -321,7 +325,7 @@ void NoteLabelManager::editLyric(NoteLabel *note) {
// Create undo operation
Operation op("LYRIC");
op << getNoteLabelId(note) << text;
- doOperation(op, Operation::NO_EXEC);
+ doOperation(op, Operation::NO_EXEC | Operation::NO_UPDATE);
}
}
|