Skip to content
Snippets Groups Projects
Commit 851349b8 authored by SeeLook's avatar SeeLook
Browse files

Implemented note name control, QML wrapped by C++ object with the logic,

TipRec has property determining is shadow displayed or not and color exposed
parent 93e3c167
No related branches found
No related tags found
No related merge requests found
......@@ -66,9 +66,11 @@ add_subdirectory( libs/sound ) # libNootkaSound
include_directories( libs/core libs/sound ) # libs/main
# nootka executable
set(NOOTKA_SRC
main.cpp
main/tnameitem.cpp
)
......
......@@ -29,9 +29,10 @@
#include <QtCore/qfile.h>
#include <QtCore/qsettings.h>
#include "tpath.h"
#include "tnootkaqml.h"
#include <tpath.h>
#include <tnootkaqml.h>
#include <tsound.h>
#include "main/tnameitem.h"
#if defined (Q_OS_ANDROID)
#include <Android/tandroid.h>
......@@ -135,6 +136,7 @@ int main(int argc, char *argv[])
e->rootContext()->setContextProperty(QStringLiteral("SOUND"), &sound);
GLOB->isFirstRun = false;
}
qmlRegisterType<TnameItem>("Nootka.name", 1, 0, "TnameItem");
e->load(QUrl(QStringLiteral("qrc:/MainWindow.qml")));
// #if defined (Q_OS_ANDROID)
......
/***************************************************************************
* Copyright (C) 2017 by Tomasz Bojczuk *
* seelook@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "tnameitem.h"
#include <tglobals.h>
static const char* const shortOctaveNames[8] = { QT_TR_NOOP("Sub"), QT_TR_NOOP("Contra"), QT_TR_NOOP("Great"), QT_TR_NOOP("Small"),
QT_TR_NOOP("1-line"), QT_TR_NOOP("2-line"), QT_TR_NOOP("3-line"), QT_TR_NOOP("4-line") };
TnameItem::TnameItem(QQuickItem* parent) :
QQuickItem(parent),
m_nameStyle(Tnote::e_english_Bb)
{
m_note.octave = -4;
}
TnameItem::~TnameItem() {}
void TnameItem::setNote(const Tnote& n) {
if (!m_note.compareNotes(n)) {
bool stepCh = n.note != m_note.note;
bool octaveCh = n.octave != m_note.octave;
bool alterCh = n.alter != m_note.alter;
m_note = n;
emit noteChanged();
if (stepCh)
emit stepChanged();
if (octaveCh)
emit octaveChanged();
if (alterCh)
emit alterChanged();
nameTextChanged();
}
}
void TnameItem::setStep(int st) {
char stepChar = static_cast<char>(st);
if (stepChar != m_note.note) {
if (m_note.octave == -4) // initial octave value is fake, revert it
setOctave(0);
m_note.note = stepChar;
emit stepChanged();
emit nameTextChanged();
emit noteChanged();
}
}
void TnameItem::setAlter(int alt) {
char alterChar = static_cast<char>(alt);
if (alterChar != m_note.alter) {
m_note.alter = alterChar;
emit alterChanged();
emit nameTextChanged();
emit noteChanged();
}
}
void TnameItem::setOctave(int oct) {
char octaveChar = static_cast<char>(oct);
if (octaveChar != m_note.octave) {
m_note.octave = octaveChar;
emit octaveChanged();
emit nameTextChanged();
emit noteChanged();
}
}
void TnameItem::setNameStyle(int nStyle) {
if (static_cast<Tnote::EnameStyle>(nStyle) != m_nameStyle) {
m_nameStyle = static_cast<Tnote::EnameStyle>(nStyle);
emit nameStyleChanged();
emit nameTextChanged();
}
}
QString TnameItem::nameText() const {
QString enharmText;
if (m_note.isValid()) {
TnotesList enharmList = m_note.getTheSameNotes(GLOB->enableDoubleAccids());
TnotesList::iterator it = enharmList.begin();
++it;
if (it != enharmList.end()) {
auto n1 = *(it);
enharmText += QString(" <font color=\"%1\" size=\"1\">(").arg(GLOB->getEnharmNoteColor().name()) + n1.styledName();
}
++it;
if (it != enharmList.end()) {
auto n2 = *(it);
enharmText += QLatin1String(" ") + n2.styledName();
}
if (!enharmText.isEmpty())
enharmText += QLatin1String(")</font>");
}
return m_note.isValid() ? m_note.styledName() + enharmText : QString();
}
QString TnameItem::octaveName(int oNr) const {
return oNr > -4 && oNr < 5 ? shortOctaveNames[oNr + 3] : QString();
}
QString TnameItem::octavesLink() const {
// TODO: here is a status tip, make it available when tips will back
QString l = tr("Click to see what <i>octaves</i> are at \"http://en.wikipedia.org/wiki/Octave\"",
"You can change this link to article in your language. Leave quotation marks around the address!");
return QLatin1String("<a href=") + l.mid(l.indexOf("\"")) + QLatin1String(">") + tr("Octaves") + QLatin1String(":</a>");
}
QString TnameItem::noteButtonText(int noteNr, int nStyle) {
Q_UNUSED(nStyle)
return Tnote(noteNr, 0, 0).toText(m_nameStyle, false);
}
/***************************************************************************
* Copyright (C) 2017 by Tomasz Bojczuk *
* seelook@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef TNAMEOBJECT_H
#define TNAMEOBJECT_H
#include <music/tnote.h>
#include <QtQuick/qquickitem.h>
class TnameItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(Tnote note READ note WRITE setNote NOTIFY noteChanged)
Q_PROPERTY(int step READ step WRITE setStep NOTIFY stepChanged)
Q_PROPERTY(int alter READ alter WRITE setAlter NOTIFY alterChanged)
Q_PROPERTY(int octave READ octave WRITE setOctave NOTIFY octaveChanged)
Q_PROPERTY(QString nameText READ nameText NOTIFY nameTextChanged)
Q_PROPERTY(int nameStyle READ nameStyle WRITE setNameStyle NOTIFY nameStyleChanged)
public:
TnameItem (QQuickItem* parent = nullptr);
~TnameItem() override;
Tnote note() const { return m_note; }
void setNote(const Tnote& n);
int step() const { return static_cast<int>(m_note.note); }
void setStep (int st);
int alter() const { return static_cast<int>(m_note.alter); }
void setAlter(int alt);
int octave() const { return static_cast<int>(m_note.octave); }
void setOctave(int oct);
int nameStyle() const { return static_cast<int>(m_nameStyle); }
void setNameStyle(int nStyle);
QString nameText() const;
Q_INVOKABLE QString octaveName(int oNr) const;
Q_INVOKABLE QString octavesLink() const;
Q_INVOKABLE QString noteButtonText(int noteNr, int nStyle = -1);
signals:
void noteChanged();
void stepChanged();
void alterChanged();
void octaveChanged();
void nameTextChanged();
void nameStyleChanged();
private:
Tnote m_note;
Tnote::EnameStyle m_nameStyle;
};
#endif // TNAMEOBJECT_H
......@@ -22,6 +22,7 @@
<file alias="Transposition.qml">qml/shared/Transposition.qml</file>
<file alias="TlabelText.qml">qml/shared/TlabelText.qml</file>
<file alias="Tflickable.qml">qml/shared/Tflickable.qml</file>
<file alias="TcuteButton.qml">qml/shared/TcuteButton.qml</file>
<!-- <file alias="IntonationBar.qml">qml/sound/IntonationBar.qml</file> -->
<file alias="PitchView.qml">qml/sound/PitchView.qml</file>
......
......@@ -96,13 +96,6 @@ Score {
radius: width / 3.0
}
// NoteName {
// width: mainScore.width / 4
// height: mainScore.scale * 32
// y: mainScore.scale * 0.4
// x: mainScore.width * 0.7
// }
Taction {
id: playAct
text: Noo.TR("QShortcut", "Play")
......
......@@ -5,88 +5,128 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import Nootka.name 1.0
TipRect {
TnameItem {
id: noteName
// private
property int note: 0
property int alter: 0
property int octave: 0
// color: activPal.window
property real buttHeight: height / 12
property real buttWidth: width / 9
Column {
z: 2
Rectangle {
anchors.fill: parent
spacing: (noteName.height - childrenRect.height) / 4
topPadding: spacing
color: Noo.alpha(activPal.window, 230)
}
Rectangle {
y: parent.height / 14
anchors.horizontalCenter: parent.horizontalCenter
width: noteName.width * 0.9
height: noteName.height * 0.2
height: noteName.height / 5
color: Noo.alpha(activPal.base, 230)
Text {
y: -noteName.height * 0.17
text: nameText
width: parent.width
height: parent.height
id: nameLabel
font { pixelSize: height * 0.8; family: "Scorek" }
horizontalAlignment: Text.AlignHCenter
}
}
ButtonGroup { id: stepsGr }
Row {
z: 2
y: parent.height * 0.34
anchors.horizontalCenter: parent.horizontalCenter
spacing: noteName.width / 56
spacing: noteName.width / 54
Repeater {
id: stepRep
model: 7
Button {
width: noteName.width / 8
height: noteName.width * 0.15
contentItem: Text {
font.pixelSize: noteName.height * 0.1
text: Noo.noteName(Noo.note(index + 1, 0, 0), 1, false)
}
onClicked: {
noteName.note = index + 1
buttonPressed()
}
TcuteButton {
width: buttWidth
height: buttHeight
checkable: true
checked: index === step - 1
ButtonGroup.group: stepsGr
font { pixelSize: height * 0.8; family: "Serif"; bold: true }
text: noteButtonText(index + 1, nameStyle)
onClicked: step = index + 1
}
}
}
Row {
z: 2
y: parent.height / 2
anchors.horizontalCenter: parent.horizontalCenter
spacing: noteName.width / 56
Repeater {
model: [ "B", "b", "#", "x" ]
Button {
width: noteName.width / 8
height: noteName.width * 0.15
contentItem: Text {
font { family: "Nootka"; pixelSize: noteName.height * 0.1 }
TcuteButton {
width: buttWidth
height: buttHeight * 1.1
checkable: step > 0
checked: step > 0 && ((index < 2 && alter === index - 2) || (index > 1 && alter === index - 1))
font { family: "Nootka"; pixelSize: height * 0.85 }
text: modelData
onClicked: alter = checked ? (index < 2 ? index - 2 : index - 1) : 0
}
}
onClicked: {
noteName.alter = index - 2
buttonPressed()
}
ButtonGroup { id: octavesGr }
Row {
y: parent.height * 0.65
leftPadding: parent.width / 60
spacing: parent.width / 20
Text {
text: octavesLink()
font { pixelSize: buttHeight * 0.4; family: "Sans"; bold: true }
anchors.verticalCenter: parent.verticalCenter
onLinkActivated: Qt.openUrlExternally(link)
MouseArea { // make hand cursor over link text
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
Repeater {
model: 4
TcuteButton {
width: buttWidth * 1.2
height: buttHeight
checkable: step > 0
checked: index === (octave + 2) / 2
ButtonGroup.group: octavesGr
font { pixelSize: height * 0.5; family: "Sans"; bold: true }
text: octaveName(index * 2 - 2)
onClicked: octave = index * 2 - 2
}
}
}
MouseArea {
z: 1
anchors.fill: parent
hoverEnabled: true
onExited: noteName.visible = false
Row {
y: parent.height * 0.78
leftPadding: spacing
spacing: buttWidth * 0.64
Repeater {
model: 4
TcuteButton {
width: buttWidth * 1.2
height: buttHeight
checkable: step > 0
checked: index === (octave + 3) / 2
ButtonGroup.group: octavesGr
font { pixelSize: height * 0.5; family: "Sans"; bold: true }
text: octaveName(index * 2 - 3)
onClicked: octave = index * 2 - 3
}
}
function buttonPressed() {
nameLabel.text = Noo.noteName(Noo.note(note, octave, alter), 1)
}
}
/** This file is part of Nootka (http://nootka.sf.net) *
* Copyright (C) 2017 by Tomasz Bojczuk (seelook@gmail.com) *
* on the terms of GNU GPLv3 license (http://www.gnu.org/licenses) */
import QtQuick 2.9
import QtQuick.Controls 2.2
/**
* Button used for note name control.
* It is just rectangle with shadow, palette aware
*/
AbstractButton {
id: root
// property alias font: contentItem.font
contentItem: Text {
font: root.font
horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
minimumPixelSize: 8
fontSizeMode: Text.HorizontalFit
color: enabled ? (checked ? activPal.highlightedText : activPal.text) : disdPal.text
text: root.text
}
background: TipRect {
color: enabled ? (checked ? activPal.highlight : activPal.button) : disdPal.button
rised: !checked
}
}
......@@ -7,6 +7,8 @@ import QtGraphicalEffects 1.0
Item {
property alias color: bg.color
property bool rised: true
Rectangle {
id: bg
......@@ -18,8 +20,8 @@ Item {
DropShadow {
anchors.fill: bg
horizontalOffset: nootkaWindow.fontSize / 4
verticalOffset: nootkaWindow.fontSize / 4
horizontalOffset: rised ? nootkaWindow.fontSize / 4 : 0
verticalOffset: rised ? nootkaWindow.fontSize / 4 : 0
radius: 8.0
samples: 17
color: activPal.shadow
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment