From 741511a8e48049bd55b516b453d9cefc620722fb Mon Sep 17 00:00:00 2001 From: SeeLook <945374+SeeLook@users.noreply.github.com> Date: Fri, 14 Apr 2017 13:30:05 +0200 Subject: [PATCH] Drawing octave names on piano, loading instrument depends on settings --- src/libs/core/instruments/tpianobg.cpp | 13 +++++++++++++ src/qml/instruments/Instrument.qml | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libs/core/instruments/tpianobg.cpp b/src/libs/core/instruments/tpianobg.cpp index d1e71e8fe..d170a03ba 100644 --- a/src/libs/core/instruments/tpianobg.cpp +++ b/src/libs/core/instruments/tpianobg.cpp @@ -29,6 +29,10 @@ #include "checktime.h" +const char* const octaveNames[8] = { QT_TR_NOOP("Subcontra"), QT_TR_NOOP("Contra"), QT_TR_NOOP("Great"), QT_TR_NOOP("Small"), + QT_TR_NOOP("One-line"), QT_TR_NOOP("Two-line"), QT_TR_NOOP("Three-line"), QT_TR_NOOP("Four-line") }; + + TpianoBg::TpianoBg(QQuickItem* parent) : QQuickPaintedItem(parent), m_keyWidth(32.0), @@ -95,6 +99,15 @@ CHECKTIME ( painter->drawRect(0, kw, m_margin, height() - kw); painter->drawRect(width() - m_margin, kw, m_margin, height() - kw); } + painter->setPen(Qt::white); + QFont f; + f.setPixelSize(qRound(m_keyWidth * 0.6)); + painter->setFont(f); + for (int k = 0; k < m_keysNumber / 7; ++k) { + painter->drawText(QRect(m_margin + k * 7 * kw, 0, 7 * kw, m_keyWidth), Qt::AlignCenter, octaveNames[m_firstOctave + 2 + k]); + int xx = m_margin + (k + 1) * 7 * kw; + painter->drawLine(xx, qRound(m_keyWidth / 2.0), xx, qRound(m_keyWidth - 1.0)); + } ) } diff --git a/src/qml/instruments/Instrument.qml b/src/qml/instruments/Instrument.qml index 8240452da..24954693f 100644 --- a/src/qml/instruments/Instrument.qml +++ b/src/qml/instruments/Instrument.qml @@ -4,17 +4,21 @@ import QtQuick 2.7 +import Nootka 1.0 + + Item { id: root property Item instrument: null signal note(var n) - height: nootkaWindow.height / 4 //5 for piano + height: nootkaWindow.height / (GLOB.instrument.type === Tinstrument.Piano ? 5 : 4) width: nootkaWindow.width Component.onCompleted: { - var c = Qt.createComponent("qrc:/Guitar.qml") + var i = GLOB.instrument.type === Tinstrument.Piano ? "Piano" : "Guitar" + var c = Qt.createComponent("qrc:/" + i + ".qml") instrument = c.createObject(root, {"anchors.fill": root}) instrument.onNoteChanged.connect(callNote) } -- GitLab