diff --git a/src/GUI/LauncherMainWindow.cxx b/src/GUI/LauncherMainWindow.cxx index d8dd9edd4..2c4c890db 100644 --- a/src/GUI/LauncherMainWindow.cxx +++ b/src/GUI/LauncherMainWindow.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include "version.h" @@ -83,6 +84,13 @@ LauncherMainWindow::LauncherMainWindow() : setResizeMode(QQuickView::SizeRootObjectToView); engine()->addImportPath("qrc:///"); + // allow selecting different QML files based on the Qt version we are + // compiled against + auto selector = new QQmlFileSelector(engine(), this); +#if QT_VERSION >= 0x050600 + selector->setExtraSelectors({"qt56"}); +#endif + QQmlContext* ctx = rootContext(); ctx->setContextProperty("_launcher", m_controller); ctx->setContextProperty("_addOns", addOnsCtl); diff --git a/src/GUI/qml/+qt56/MenuItem.qml b/src/GUI/qml/+qt56/MenuItem.qml new file mode 100644 index 000000000..7f5430f12 --- /dev/null +++ b/src/GUI/qml/+qt56/MenuItem.qml @@ -0,0 +1,68 @@ +import QtQuick 2.6 // so we can use Shortcut +import "." +import ".." + +BaseMenuItem { + id: root + + property alias text: itemText.text + property alias shortcut: keyShortcut.sequence + + signal triggered(); + + function minWidth() { + return itemText.width + shortcutText.width + (Style.inset * 2) + } + + Shortcut { + id: keyShortcut + onActivated: root.triggered(); + enabled: root.enabled + } + + Rectangle { + height: parent.height + width: parent.width + visible: mouse.containsMouse + color: "#cfcfcf" + } + + Text { + id: itemText + font.pixelSize: Style.baseFontPixelSize + color: mouse.containsMouse ? Style.themeColor : + (root.enabled ? Style.baseTextColor : Style.disabledTextColor); + + anchors { + left: parent.left + leftMargin: Style.inset + verticalCenter: parent.verticalCenter + } + } + + Text { + id: shortcutText + color: Style.disabledTextColor + font.pixelSize: Style.baseFontPixelSize + width: implicitWidth + Style.inset + horizontalAlignment: Text.AlignRight + text: keyShortcut.nativeText + + anchors { + right: parent.right + rightMargin: Style.inset + verticalCenter: parent.verticalCenter + } + } + + MouseArea { + id: mouse + enabled: root.enabled + anchors.fill: parent + hoverEnabled: root.enabled + onClicked: { + root.closeMenu(); + root.triggered(); + } + } +} diff --git a/src/GUI/qml/Launcher.qml b/src/GUI/qml/Launcher.qml index 3a9f3a530..647bc53e7 100644 --- a/src/GUI/qml/Launcher.qml +++ b/src/GUI/qml/Launcher.qml @@ -136,10 +136,12 @@ Item { z: 100 items: [ - MenuItem { text:qsTr("Open saved configuration..."); onTriggered: _launcher.openConfig(); }, - MenuItem { text:qsTr("Save configuration as..."); onTriggered: _launcher.saveConfigAs(); }, + MenuItem { text:qsTr("Open saved configuration..."); shortcut: "Ctrl+O"; + onTriggered: _launcher.openConfig(); }, + MenuItem { text:qsTr("Save configuration as..."); shortcut: "Ctrl+S"; + onTriggered: _launcher.saveConfigAs(); }, MenuDivider {}, - MenuItem { text:qsTr("View command line"); onTriggered: _launcher.viewCommandLine(); }, + MenuItem { text:qsTr("View command line"); onTriggered: _launcher.viewCommandLine(); shortcut: "Ctrl+L"}, MenuItem { text:qsTr("Select data files location..."); onTriggered: _launcher.requestChangeDataPath(); }, MenuItem { text:qsTr("Restore default settings..."); onTriggered: _launcher.requestRestoreDefaults(); }, MenuDivider {}, diff --git a/src/GUI/qml/MenuItem.qml b/src/GUI/qml/MenuItem.qml index 5b59bd16a..31af765f8 100644 --- a/src/GUI/qml/MenuItem.qml +++ b/src/GUI/qml/MenuItem.qml @@ -5,12 +5,12 @@ BaseMenuItem { id: root property alias text: itemText.text - property alias shortcut: shortcutText.text + property string shortcut: "" // for compatability with Qt 5.6 and up signal triggered(); function minWidth() { - return itemText.width + shortcutText.width + (Style.inset * 2) + return itemText.width + (Style.inset * 2) } Rectangle { @@ -33,20 +33,6 @@ BaseMenuItem { } } - Text { - id: shortcutText - color: Style.disabledTextColor - font.pixelSize: Style.baseFontPixelSize - width: implicitWidth + Style.inset - horizontalAlignment: Text.AlignRight - - anchors { - right: parent.right - rightMargin: Style.inset - verticalCenter: parent.verticalCenter - } - } - MouseArea { id: mouse enabled: root.enabled @@ -57,4 +43,4 @@ BaseMenuItem { root.triggered(); } } -} \ No newline at end of file +} diff --git a/src/GUI/resources.qrc b/src/GUI/resources.qrc index 5fc0f8908..4796da08d 100644 --- a/src/GUI/resources.qrc +++ b/src/GUI/resources.qrc @@ -103,6 +103,7 @@ qml/Menu.qml qml/BaseMenuItem.qml qml/MenuItem.qml + qml/+qt56/MenuItem.qml qml/MenuDivider.qml qml/ToggleBox.qml qml/LocationAltitudeRow.qml