|
From: Tapio V. <aa...@us...> - 2011-01-11 14:46:43
|
Module: editor
Branch: master
Commit: 70b0cf1e8cea749b10d7abb15b851c69035dc95f
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 11 16:22:49 2011 +0200
Prepare to populate NoteGraphWidget from Notes instead of string.
---
notegraphwidget.cc | 29 ++++++++++++++++++++++++++---
notegraphwidget.hh | 2 ++
notelabel.cc | 4 ++--
notelabel.hh | 2 +-
4 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index bb595c5..a2d131d 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -67,7 +67,7 @@ void NoteGraphWidget::setLyrics(QString lyrics)
QString word;
ts >> word;
if (!word.isEmpty()) {
- NoteLabel *wordLabel = new NoteLabel(word, this, QPoint(x, y));
+ NoteLabel *wordLabel = new NoteLabel(Note(word.toStdString()), this, QPoint(x, y));
last = wordLabel;
x += wordLabel->width() + gap;
if (!first) first = wordLabel;
@@ -83,6 +83,29 @@ void NoteGraphWidget::setLyrics(QString lyrics)
updateWidth();
}
+void NoteGraphWidget::setLyrics(const Notes ¬es)
+{
+ const int gap = 10;
+ int x = gap, y = 2 * noteYStep;
+
+ clear();
+ NoteLabel *first = NULL, *last = NULL;
+ for (Notes::const_iterator it = notes.begin(); it != notes.end(); ++it) {
+ NoteLabel *label = new NoteLabel(*it, this, QPoint(x, y));
+ last = label;
+ x += label->width() + gap;
+ if (!first) first = label;
+ }
+
+ // Set first and last to non-floating
+ if (first) first->setFloating(false);
+ if (last) last->setFloating(false);
+
+ rebuildNoteList();
+ m_requiredWidth = x + gap;
+ updateWidth();
+}
+
void NoteGraphWidget::updateWidth()
{
setFixedWidth(m_requiredWidth);
@@ -202,8 +225,8 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
int w1 = relRatio * child->width();
// Create new labels
- NoteLabel *newLabel1 = new NoteLabel(firstst, this, child->pos(), QSize(w1, 0));
- new NoteLabel(secondst, this, newLabel1->pos() + QPoint(newLabel1->width(), 0), QSize(child->width() - w1, 0));
+ NoteLabel *newLabel1 = new NoteLabel(Note(firstst.toStdString()), this, child->pos(), QSize(w1, 0));
+ new NoteLabel(Note(secondst.toStdString()), this, newLabel1->pos() + QPoint(newLabel1->width(), 0), QSize(child->width() - w1, 0));
// Delete the old one
child->close();
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index 042b531..ed34310 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -1,6 +1,7 @@
#pragma once
#include "pitchvis.hh"
+#include "notes.hh"
#include <QLabel>
#include <list>
@@ -19,6 +20,7 @@ public:
void clear();
void setLyrics(QString lyrics);
+ void setLyrics(const Notes ¬es);
void updateWidth();
void updateNotes();
void rebuildNoteList();
diff --git a/notelabel.cc b/notelabel.cc
index 58169cd..fb18ace 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -10,8 +10,8 @@ const int NoteLabel::resize_margin = 5; // How many pixels is the resize area
const int NoteLabel::min_width = 10; // How many pixels is the resize area
const int NoteLabel::default_size = 50; // The preferred size of notes
-NoteLabel::NoteLabel(const QString &text, QWidget *parent, const QPoint &position, const QSize &size, bool floating)
- : QLabel(parent), m_note(text.toStdString()), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
+NoteLabel::NoteLabel(const Note ¬e, QWidget *parent, const QPoint &position, const QSize &size, bool floating)
+ : QLabel(parent), m_note(note), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
{
createPixmap(size);
if (!position.isNull())
diff --git a/notelabel.hh b/notelabel.hh
index 096a523..0926b9f 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -10,7 +10,7 @@ public:
static const int min_width;
static const int default_size;
- NoteLabel(const QString &text, QWidget *parent, const QPoint &position = QPoint(), const QSize &size = QSize(), bool floating = true);
+ NoteLabel(const Note ¬e, QWidget *parent, const QPoint &position = QPoint(), const QSize &size = QSize(), bool floating = true);
void createPixmap(QSize size = QSize());
QString lyric() const { return QString::fromStdString(m_note.syllable); }
|