|
From: Tapio V. <aa...@us...> - 2011-02-24 21:24:06
|
Author: Tapio Vierros <tap...@gm...>
Date: Thu Feb 24 23:23:10 2011 +0200
Display also mouse position on piano keys.
---
editorapp.cc | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 6ebedd9..27a81ba 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -991,8 +991,10 @@ void Piano::updatePixmap(NoteGraphWidget *ngw)
if (!ngw) return;
const int notes = 12 * 4; // Four octaves
const QColor borderColor = QColor("#c0c0c0");
- const QColor selectionColor = QColor("#090");
+ const QColor selectionColor = QColor("#a00");
+ const QColor mouseColor = QColor("#090");
int noteHeight = ngw->n2px(0) - ngw->n2px(1);
+ int mousen = int(round(ngw->px2n(mapFromGlobal(QCursor::pos()).y())));
QImage image(50, notes * noteHeight, QImage::Format_ARGB32_Premultiplied);
image.fill(qRgba(0, 0, 0, 0));
@@ -1009,7 +1011,8 @@ void Piano::updatePixmap(NoteGraphWidget *ngw)
int y2 = image.height() - i * noteHeight; // Note center y
y2 -= (scale.isSharp(i + 1) ? 1.0 : 0.5) * noteHeight; // Key top y
// Pick border color according to selection status
- if (selectionMatches(i, ngw)) pen.setColor(selectionColor);
+ if (i == mousen) pen.setColor(mouseColor);
+ else if (selectionMatches(i, ngw)) pen.setColor(selectionColor);
else pen.setColor(borderColor);
painter.setPen(pen);
// Skip the first key because y hasn't been calculated yet
@@ -1025,7 +1028,8 @@ void Piano::updatePixmap(NoteGraphWidget *ngw)
if (!scale.isSharp(i)) continue;
y = image.height() - i*noteHeight - noteHeight / 2;
// Pick border color according to selection status
- if (selectionMatches(i, ngw)) pen.setColor(selectionColor);
+ if (i == mousen) pen.setColor(mouseColor);
+ else if (selectionMatches(i, ngw)) pen.setColor(selectionColor);
else pen.setColor(borderColor);
painter.setPen(pen);
painter.fillRect(0, y, w, noteHeight, QColor("#000000"));
|