Last active
March 15, 2023 10:01
-
-
Save lgvr123/4f0d753d582f11a411d4e25a3dda90f2 to your computer and use it in GitHub Desktop.
Musescore dialog plugin boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.9 | |
import QtQuick.Controls 2.2 | |
import QtQuick.Layouts 1.3 | |
import QtQuick.Dialogs 1.2 | |
import QtQuick.Window 2.3 | |
import Qt.labs.settings 1.0 | |
import MuseScore 3.0 | |
MuseScore { | |
menuPath: "Plugins." + qsTr("Plugin Name") | |
version: "1.1.0" | |
requiresScore: false | |
description: qsTr("Create a new score based on exsiting template") | |
pluginType: "dialog" | |
id: mainWindow // required for setting MS4 properties and closing Window | |
Component.onCompleted: { | |
// Specific MS4 features | |
if (mscoreMajorVersion >= 4) { | |
mainWindow.title = qsTr("Plugin Name"); | |
mainWindow.thumbnailName = "logo.png"; | |
// mainWindow.categoryCode = "some category"; | |
} | |
} | |
onRun: { | |
// check MuseScore version | |
if (mscoreMajorVersion < 3) { | |
mainWindow.visible = false | |
versionError.open() | |
} | |
} | |
// Compute dimension based on content | |
width: mainRow.implicitWidth + extraLeft + extraRight | |
height: mainRow.implicitHeight + extraTop + extraBottom | |
property int extraMargin: mainRow.anchors.margins ? mainRow.anchors.margins : 0 | |
property int extraTop: mainRow.anchors.topMargin ? mainRow.anchors.topMargin : extraMargin | |
property int extraBottom: mainRow.anchors.bottomMargin ? mainRow.anchors.bottomMargin : extraMargin | |
property int extraLeft: mainRow.anchors.leftMargin ? mainRow.anchors.leftMargin : extraMargin | |
property int extraRight: mainRow.anchors.rightMargin ? mainRow.anchors.rightMargin : extraMargin | |
// Signal onClosing on the main Window. This code is executed when the window closed | |
// Rem: this generates some warnings in the plugin editor log, but this is ok | |
Connections { | |
target: mainWindow.parent.Window.window | |
onClosing: { | |
// do whatever is required to do when the plugin window is closing such as managing the settings | |
console.log("onClosing: Saving some date to stettings"); | |
} | |
} | |
// UI | |
ColumnLayout { | |
id: mainRow // needed for reference in size computing | |
spacing: 2 | |
anchors.margins: 0 | |
// Plugin controls | |
GridLayout { | |
Layout.margins: 20 | |
Layout.minimumWidth: 250 | |
Layout.minimumHeight: 200 | |
columnSpacing: 5 | |
rowSpacing: 5 | |
// debug | |
columns: 1 | |
Rectangle { | |
color: "yellow" | |
width: 400 | |
height: 300 | |
} | |
} // GridLayout | |
// Buttons | |
DialogButtonBox { | |
Layout.fillWidth: true | |
spacing: 5 | |
alignment: Qt.AlignRight | |
background.opacity: 0 // hide default white background | |
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel | |
Button { | |
// some non standard button placed on the left side | |
id: special | |
enabled: true // add real enabling test | |
DialogButtonBox.buttonRole: DialogButtonBox.ResetRole | |
text: qsTr("Special") | |
} | |
onAccepted: { | |
//... do the stuff ... | |
// and close | |
mainWindow.parent.Window.window.close(); | |
} | |
onClicked: { | |
if (button === special) { | |
//... do some other stuff ... | |
} | |
} | |
onRejected: mainWindow.parent.Window.window.close(); | |
} // DialogButtonBox | |
// Status bar (delete if not needed) | |
RowLayout { | |
Layout.fillWidth: true | |
Layout.preferredHeight: txtStatus.height | |
Layout.margins: 5 | |
spacing: 5 | |
Text { | |
id: txtStatus | |
text: "some status" | |
wrapMode: Text.NoWrap | |
elide: Text.ElideRight | |
maximumLineCount: 1 | |
Layout.fillWidth: true | |
} | |
} // status bar | |
} // ColumnLayout | |
// Plugin settings | |
Settings { | |
id: settings | |
category: "MyPlugin" | |
// use alias on whatever UI controls | |
//property alias subtitle: subtitle.text | |
//property alias composer: composer.text | |
//property alias lyricist: lyricist.text | |
//property alias copyright: copyright.text | |
} | |
// Palette for nice color management | |
SystemPalette { | |
id: sysActivePalette; | |
colorGroup: SystemPalette.Active | |
} | |
SystemPalette { | |
id: sysDisabledPalette; | |
colorGroup: SystemPalette.Disabled | |
} | |
// Version mismatch dialog | |
MessageDialog { | |
id: versionError | |
visible: false | |
title: qsTr("Unsupported MuseScore Version") | |
text: qsTr("This plugin requires MuseScore 3.6later.") | |
onAccepted: { | |
mainWindow.parent.Window.window.close(); | |
} | |
} | |
} // MuseScore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment