Skip to content
Snippets Groups Projects
MainWindow.qml 6.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • /** This file is part of Nootka (http://nootka.sf.net)               *
    
     * Copyright (C) 2017-2021 by Tomasz Bojczuk (seelook@gmail.com)     *
    
     * on the terms of GNU GPLv3 license (http://www.gnu.org/licenses)   */
    
    SeeLook's avatar
    SeeLook committed
    import Nootka 1.0
    
    import QtQuick 2.12
    import QtQuick.Controls 2.12
    
    
    ApplicationWindow {
    
    SeeLook's avatar
    SeeLook committed
        id: nootkaWindow
    
        property bool topToBott: height > width
        property real shortEdge: Math.min(height, width * (GLOB.instrument.isSax ? 0.85 : 1))
        property alias mainMenu: mainMenu
    
    SeeLook's avatar
    SeeLook committed
        // private
        property var noteName: null
        property var examResults: null
        property var executor: null
        property var dialogLoader: null
        property var tip: null
        property var analyzeWindow: null
        property var sndInf: null
        property var notesBarItem: null
    
        function createStatus() {
            Qt.createComponent("qrc:/StatusTip.qml").createObject(NOO.isAndroid() ? nootkaWindow.contentItem : nootkaWindow.contentItem.parent);
    
    SeeLook's avatar
    SeeLook committed
    
        function checkSingleMode() {
            if (GLOB.singleNoteMode) {
                if (!noteName) {
                    var c = Qt.createComponent("qrc:/NoteName.qml");
                    noteName = c.createObject(scoreWrap, {
                        "score": score
                    });
                }
            } else {
                if (noteName)
                    noteName.destroy();
    
            }
    
    SeeLook's avatar
    SeeLook committed
    
        function showDialog(page) {
            if (!dialogLoader)
                dialogLoader = Qt.createComponent("qrc:/DialogLoader.qml").createObject(nootkaWindow);
    
            if (page === Nootka.Charts) {
                // dialogLoader above registers QML types in C++ - keep that order!
                analyzeWindow = Qt.createComponent("qrc:/charts/AnalyzeDialog.qml").createObject(nootkaWindow);
                return ;
            }
            if (page === Nootka.ScoreImport) {
                Qt.createComponent("qrc:/score/MelodyImport.qml").createObject(dialogLoader.page === Nootka.LevelCreator ? dialogLoader : nootkaWindow);
                return ;
            }
            dialogLoader.page = page;
    
    SeeLook's avatar
    SeeLook committed
    
        function askForSupport() {
            Qt.createComponent("qrc:/about/SupportPopup.qml").createObject(contentItem.parent);
        }
    
        function newerVerPop() {
            var p = analyzeWindow ? analyzeWindow : (dialogLoader && dialogLoader.page ? dialogLoader.contentItem : nootkaWindow);
            return Qt.createComponent("qrc:/level/NewerVersionPopup.qml").createObject(p);
    
    SeeLook's avatar
    SeeLook committed
    
        function audioAnalyze() {
            Qt.createComponent("qrc:/nootini/AudioAnalyze.qml").createObject(nootkaWindow);
            nootkaWindow.title = "Nootini - pitch detection analyzer";
        }
    
        visible: true
        title: "Nootka"
        color: activPal.window
        visibility: NOO.isAndroid() && GLOB.fullScreen() ? "FullScreen" : "AutomaticVisibility"
        width: GLOB.geometry.width
        height: GLOB.geometry.height
        x: GLOB.geometry.x
        y: GLOB.geometry.y
        header: mainMenu.toolBar
    
    SeeLook's avatar
    SeeLook committed
        Component.onCompleted: {
            NOO.mainScore = score;
            checkSingleMode();
            if (GLOB.gotIt("soundInfo", true)) {
                sndInf = Qt.createComponent("qrc:/gotit/SoundInfo.qml").createObject(nootkaWindow.contentItem.parent);
                sndInf.remaindChecked = true;
                sndInf.closed.connect(function() {
                    GLOB.setGotIt("soundInfo", sndInf.remaindChecked);
                    sndInf.destroy();
                    createStatus(); // create status tip only after pitch detection info
                });
            } else {
                createStatus();
    
    
        onClosing: close => {
    
    SeeLook's avatar
    SeeLook committed
            if (NOO.isAndroid() && dialogLoader && dialogLoader.visible) {
                close.accepted = false;
                dialogLoader.close();
            }
            if (executor) {
                if (!executor.closeNootka())
                    close.accepted = false;
            }
            if (close.accepted)
                GLOB.geometry = Qt.rect(x, y, width, height);
    
    
    SeeLook's avatar
    SeeLook committed
    
        SystemPalette {
            id: activPal
    
            property color dimText: Qt.tint(activPal.base, NOO.alpha(activPal.text, 150))
            colorGroup: SystemPalette.Active
    
    SeeLook's avatar
    SeeLook committed
        SystemPalette {
            id: disdPal
            colorGroup: SystemPalette.Disabled
    
    SeeLook's avatar
    SeeLook committed
    
        Connections {
            target: NOO
    
            function onScoreActTriggered() : void { mainMenu.open() }
            function onMelodyActTriggered() : void { mainMenu.melodyOpen() }
            function onSettingsActTriggered() : void { showDialog(Nootka.Settings) }
            function onLevelActTriggered() : void { showDialog(Nootka.LevelCreator) }
            function onChartsActTriggered() : void { showDialog(Nootka.Charts) }
            function onExamActTriggered() : void { showDialog(Nootka.ExamStart) }
            function onAboutActTriggered() : void { showDialog(Nootka.About) }
    
    SeeLook's avatar
    SeeLook committed
    
        MainMenu {
            id: mainMenu
        }
    
        Item {
            id: scoreWrap
    
            property real insHi: GLOB.instrument.getItemHeight(shortEdge)
    
            y: examResults ? examResults.height + 2 : 0
            height: nootkaWindow.contentItem.height - (GLOB.instrument.isSax ? (GLOB.singleNoteMode ? insHi / 7 : 0) : insHi) - (examResults ? examResults.height + 2 : 0) - (notesBarItem ? notesBarItem.height : 0)
            width: parent.width * (GLOB.instrument.isSax ? 0.85 : 1)
            z: 5
            transformOrigin: Item.Top
    
            MainScore {
                id: score
    
                z: 5
                height: parent.height / (GLOB.singleNoteMode && topToBott ? 2 : 1)
                width: parent.width / (GLOB.singleNoteMode && !topToBott ? 2 : 1)
            }
        }
    
        Instrument {
            id: instrument
            score: score
        }
    
        Connections {
            target: GLOB
    
            function onSingleNoteModeChanged() : void { checkSingleMode() }
            function onIsExamChanged() : void {
    
    SeeLook's avatar
    SeeLook committed
                if (GLOB.isExam) {
                    if (!executor)
                        executor = Qt.createComponent("qrc:/exam/ExamExecutor.qml").createObject();
                    if (!examResults)
                        examResults = Qt.createComponent("qrc:/exam/ExamResults.qml").createObject(nootkaWindow.contentItem);
                } else {
                    if (examResults)
                        examResults.destroy();
                }
            }
    
            function onWantOpenFile() : void {
    
    SeeLook's avatar
    SeeLook committed
                showDialog(Nootka.NoDialog);
                dialogLoader.openFile(fileName);
            }
    
            function onShowNotesDiffChanged() : void {
    
    SeeLook's avatar
    SeeLook committed
                if (GLOB.showNotesDiff) {
                    if (!notesBarItem)
                        notesBarItem = Qt.createComponent("qrc:/sound/NotesDiffBar.qml").createObject(nootkaWindow.contentItem);
                } else {
                    if (notesBarItem)
                        notesBarItem.destroy();
                }
            }
        }