|
From: Tapio V. <aa...@us...> - 2011-01-11 14:46:41
|
Module: editor
Branch: master
Commit: 49311348634858803c622536888e77926d12f50a
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 11 16:13:25 2011 +0200
NoteLabel now contains Note instead of inheriting.
---
editorapp.cc | 4 ++--
notegraphwidget.cc | 10 +++++-----
notelabel.cc | 26 ++++++++------------------
notelabel.hh | 11 +++++++----
notes.cc | 2 +-
notes.hh | 2 +-
6 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index b0ac4c2..69e9ca7 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -39,7 +39,7 @@ void EditorApp::updateNoteInfo(NoteLabel *note)
ui.valNoteDuration->setText(QString::number(note->width()));
ui.valNote->setText(QString::number(note->y() / NoteGraphWidget::noteYStep));
ui.cmbNoteType->setEnabled(true);
- ui.cmbNoteType->setCurrentIndex(note->type);
+ ui.cmbNoteType->setCurrentIndex(note->note().type);
ui.chkFloating->setEnabled(true);
ui.chkFloating->setChecked(note->isFloating());
} else {
@@ -160,7 +160,7 @@ void EditorApp::on_actionAbout_triggered()
void EditorApp::on_cmbNoteType_currentIndexChanged(int index)
{
if (ui.noteGraph->selectedNote())
- ui.noteGraph->selectedNote()->type = Note::Type(index);
+ ui.noteGraph->selectedNote()->note().type = Note::Type(index);
}
void EditorApp::on_chkFloating_stateChanged(int state)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index f0ff738..bb595c5 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -196,9 +196,9 @@ void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
// Cut the text in a position proportional to the click point
float relRatio = float(hotSpot.x()) / child->width();
- int cutpos = int(std::ceil(child->getText().length() * relRatio));
- QString firstst = child->getText().left(cutpos);
- QString secondst = child->getText().right(child->getText().length() - cutpos);
+ int cutpos = int(std::ceil(child->lyric().length() * relRatio));
+ QString firstst = child->lyric().left(cutpos);
+ QString secondst = child->lyric().right(child->lyric().length() - cutpos);
int w1 = relRatio * child->width();
// Create new labels
@@ -251,9 +251,9 @@ void NoteGraphWidget::mouseDoubleClickEvent(QMouseEvent *event)
bool ok;
QString text = QInputDialog::getText(this, tr("Edit lyric"),
tr("Lyric:"), QLineEdit::Normal,
- child->getText(), &ok);
+ child->lyric(), &ok);
if (ok && !text.isEmpty()) {
- child->setText(text);
+ child->setLyric(text);
child->createPixmap();
}
diff --git a/notelabel.cc b/notelabel.cc
index fd0094d..58169cd 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -11,7 +11,7 @@ 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_labelText(text), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
+ : QLabel(parent), m_note(text.toStdString()), m_selected(false), m_floating(floating), m_resizing(0), m_hotspot()
{
createPixmap(size);
if (!position.isNull())
@@ -30,7 +30,7 @@ void NoteLabel::createPixmap(QSize size)
size.rwidth() = default_size;
}
if (size.height() <= 0) {
- size.rheight() = metric.size(Qt::TextSingleLine, m_labelText).height() + text_margin;
+ size.rheight() = metric.size(Qt::TextSingleLine, lyric()).height() + text_margin;
}
QImage image(size.width(), size.height(),
@@ -47,15 +47,15 @@ void NoteLabel::createPixmap(QSize size)
gradient.setColorAt(0.2, QColor(180, 100, 100));
gradient.setColorAt(0.8, QColor(180, 100, 100));
gradient.setColorAt(1.0, QColor(120, 100, 100));
- } else if (type == NORMAL) {
+ } else if (m_note.type == Note::NORMAL) {
gradient.setColorAt(0.2, QColor(100 * ff, 100 * ff, 255 * ff));
gradient.setColorAt(0.8, QColor(100 * ff, 100 * ff, 255 * ff));
gradient.setColorAt(1.0, QColor(100 * ff, 100 * ff, 200 * ff));
- } else if (type == GOLDEN) {
+ } else if (m_note.type == Note::GOLDEN) {
gradient.setColorAt(0.2, QColor(255 * ff, 255 * ff, 100 * ff));
gradient.setColorAt(0.8, QColor(255 * ff, 255 * ff, 100 * ff));
gradient.setColorAt(1.0, QColor(160 * ff, 160 * ff, 100 * ff));
- } else if (type == FREESTYLE) {
+ } else if (m_note.type == Note::FREESTYLE) {
gradient.setColorAt(0.2, QColor(100 * ff, 180 * ff, 100 * ff));
gradient.setColorAt(0.8, QColor(100 * ff, 180 * ff, 100 * ff));
gradient.setColorAt(1.0, QColor(100 * ff, 120 * ff, 100 * ff));
@@ -70,23 +70,13 @@ void NoteLabel::createPixmap(QSize size)
painter.setFont(font);
painter.setBrush(Qt::black);
- painter.drawText(QRect(QPoint(6, 6), QSize(size.width()-text_margin, size.height()-text_margin)), Qt::AlignCenter, m_labelText);
+ painter.drawText(QRect(QPoint(6, 6), QSize(size.width()-text_margin, size.height()-text_margin)), Qt::AlignCenter, lyric());
painter.end();
setPixmap(QPixmap::fromImage(image));
- setToolTip(QString("\"%1\"\n%2").arg(m_labelText).arg(QString::fromStdString(typeString())));
- setStatusTip(QString("Lyric: ") + m_labelText);
-}
-
-QString NoteLabel::getText() const
-{
- return m_labelText;
-}
-
-void NoteLabel::setText(const QString &text)
-{
- m_labelText = text;
+ setToolTip(QString("\"%1\"\n%2").arg(lyric()).arg(QString::fromStdString(m_note.typeString())));
+ setStatusTip(QString("Lyric: ") + lyric());
}
void NoteLabel::resizeEvent(QResizeEvent *event)
diff --git a/notelabel.hh b/notelabel.hh
index a30aeb8..096a523 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -3,7 +3,7 @@
#include <QLabel>
#include "notes.hh"
-class NoteLabel: public QLabel, public Note
+class NoteLabel: public QLabel
{
public:
static const int resize_margin;
@@ -13,11 +13,14 @@ public:
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;
- void setText(const QString &text);
+ QString lyric() const { return QString::fromStdString(m_note.syllable); }
+ void setLyric(const QString &text) { m_note.syllable = text.toStdString(); }
void setSelected(bool state = true) { m_selected = state; createPixmap(size()); }
+ Note& note() { return m_note; }
+ Note note() const { return m_note; }
+
bool isFloating() const { return m_floating; }
void setFloating(bool state) { m_floating = state; createPixmap(size()); }
@@ -30,7 +33,7 @@ public:
bool operator<(const NoteLabel &rhs) const { return x() < rhs.x(); }
private:
- QString m_labelText;
+ Note m_note;
bool m_selected;
bool m_floating;
int m_resizing;
diff --git a/notes.cc b/notes.cc
index 366a9b9..09e1071 100644
--- a/notes.cc
+++ b/notes.cc
@@ -54,7 +54,7 @@ double MusicalScale::getNoteOffset(double freq) const {
Duration::Duration(): begin(getNaN()), end(getNaN()) {}
-Note::Note(): duration(getNaN(), getNaN()), phase(getNaN()), type(NORMAL), note(), notePrev() {}
+Note::Note(std::string lyric): syllable(lyric), duration(getNaN(), getNaN()), phase(getNaN()), type(NORMAL), note(), notePrev() {}
double Note::diff(double note, double n) { return remainder(n - note, 12.0); }
diff --git a/notes.hh b/notes.hh
index ff7fee7..4b29864 100644
--- a/notes.hh
+++ b/notes.hh
@@ -47,7 +47,7 @@ typedef std::map<int, Durations> NoteMap;
/// note read from songfile
struct Note {
- Note();
+ Note(std::string lyric = "");
Duration duration; ///< note begin/end
double phase; ///< position within a measure, [0, 1)
/// note type
|