1
0
Fork 0

Launcher: keyboard shortcuts

Use The Qt 5.6 Shortcut item, but via a conditional file so
we don’t touch the base Qt requirement. (This means no shortcuts
when using Qt 5.4 or 5.5, oh well)
This commit is contained in:
James Turner 2018-07-03 09:36:30 +01:00
parent abcbbe897f
commit 6dd374408c
5 changed files with 85 additions and 20 deletions

View file

@ -12,6 +12,7 @@
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlError>
#include <QQmlFileSelector>
#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);

View file

@ -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();
}
}
}

View file

@ -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 {},

View file

@ -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();
}
}
}
}

View file

@ -103,6 +103,7 @@
<file>qml/Menu.qml</file>
<file>qml/BaseMenuItem.qml</file>
<file>qml/MenuItem.qml</file>
<file>qml/+qt56/MenuItem.qml</file>
<file>qml/MenuDivider.qml</file>
<file>qml/ToggleBox.qml</file>
<file>qml/LocationAltitudeRow.qml</file>