|
From: Tapio V. <aa...@us...> - 2011-02-22 17:37:13
|
Author: Tapio Vierros <tap...@gm...>
Date: Tue Feb 22 19:37:18 2011 +0200
Refactoring piano, still broken.
---
editorapp.cc | 47 ++++++++++++++++++++++++++---------------------
editorapp.hh | 5 ++++-
2 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 77e117c..82061d9 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -99,18 +99,21 @@ EditorApp::EditorApp(QWidget *parent)
connect(player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(playerStateChanged(Phonon::State,Phonon::State)));
connect(player, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
- // NoteGraph setup down here so that the objects we setup signals are already created
- setupNoteGraph();
- updateNoteInfo(NULL);
-
- song.reset(new Song);
-
// The piano keys
- piano = new Piano(noteGraph, ui.topFrame);
+ piano = new Piano(ui.topFrame);
QHBoxLayout *hl = new QHBoxLayout(ui.topFrame);
hl->addWidget(piano);
hl->addWidget(ui.noteGraphScroller);
ui.topFrame->setLayout(hl);
+ connect(ui.noteGraphScroller->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updatePiano(int)));
+
+ // NoteGraph setup down here so that the objects we setup signals are already created
+ setupNoteGraph();
+ updateNoteInfo(NULL);
+
+ piano->updatePixmap(noteGraph->n2px(0) - noteGraph->n2px(1));
+
+ song.reset(new Song);
// Set status tips to tool tips
handleTips(ui.tabNote);
@@ -882,6 +885,7 @@ void EditorApp::writeSettings()
}
+
AboutDialog::AboutDialog(QWidget* parent)
: QDialog(parent)
{
@@ -914,27 +918,28 @@ AboutDialog::AboutDialog(QWidget* parent)
-Piano::Piano(NoteGraphWidget *ngw, QWidget *parent)
- : QLabel(parent)
+void EditorApp::updatePiano(int y)
+{
+ if (!piano) return;
+ piano->move(piano->x(), ui.noteGraphScroller->y() - y);
+}
+
+Piano::Piano(QWidget *parent): QLabel(parent) {}
+
+void Piano::updatePixmap(int noteHeight)
{
- QImage image(50, 768, QImage::Format_ARGB32_Premultiplied);
+ const int notes = 12*6;
+ QImage image(50, notes * noteHeight, QImage::Format_ARGB32_Premultiplied);
image.fill(qRgba(0, 0, 0, 0));
{
QPainter painter(&image);
- // Piano
MusicalScale scale;
- QColor background;
- int note_height = ngw->n2px(0) - ngw->n2px(1);
QPen pen; pen.setWidth(2); pen.setColor(QColor("#c0c0c0"));
painter.setPen(pen);
- for (int i = 1; i < 12*4; ++i) {
- if(scale.isSharp(i)) {
- background = QColor("#000000");
- } else {
- background = QColor("#ffffff");
- }
- painter.fillRect(0, ngw->n2px(i)-note_height/2, image.width(), note_height, background);
- painter.drawRect(0, ngw->n2px(i)-note_height/2, image.width(), note_height);
+ for (int i = 0; i < notes; ++i) {
+ QColor background(scale.isSharp(i) ? "#000000" : "#ffffff");
+ painter.fillRect(0, image.height() - i*noteHeight - noteHeight/2, image.width(), noteHeight, background);
+ painter.drawRect(0, image.height() - i*noteHeight - noteHeight/2, image.width(), noteHeight);
}
}
setPixmap(QPixmap::fromImage(image));
diff --git a/editorapp.hh b/editorapp.hh
index 7a2bde5..aa01cd9 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -31,7 +31,9 @@ class Piano: public QLabel
{
Q_OBJECT
public:
- Piano(NoteGraphWidget *ngw, QWidget *parent = 0);
+ Piano(QWidget *parent = 0);
+public slots:
+ void updatePixmap(int noteHeight);
};
@@ -68,6 +70,7 @@ public slots:
void audioTick(qint64 time);
void playerStateChanged(Phonon::State newstate, Phonon::State olstate);
void statusBarMessage(const QString& message);
+ void updatePiano(int y);
// Automatic slots
|