More work on menus and some code cleanup

This commit is contained in:
Brad Davis 2015-04-24 12:54:11 -07:00
parent c0d562ed55
commit 1ff8c67576
21 changed files with 438 additions and 513 deletions

View file

@ -2,19 +2,19 @@ import QtQuick 2.4
import QtQuick.Controls 1.3 import QtQuick.Controls 1.3
Action { Action {
property string name property string name
objectName: name + "HifiAction" objectName: name + "HifiAction"
text: qsTr(name) text: qsTr(name)
signal triggeredByName(string name); signal triggeredByName(string name);
signal toggledByName(string name); signal toggledByName(string name);
onTriggered: { onTriggered: {
triggeredByName(name); triggeredByName(name);
} }
onToggled: { onToggled: {
toggledByName(name, checked); toggledByName(name, checked);
} }
} }

View file

@ -6,19 +6,20 @@ import "controls"
import "styles" import "styles"
Hifi.HifiMenu { Hifi.HifiMenu {
id: root id: root
anchors.fill: parent anchors.fill: parent
objectName: "HifiMenu" objectName: "HifiMenu"
enabled: false enabled: false
opacity: 0.0 opacity: 0.0
property int animationDuration: 200 property int animationDuration: 200
HifiPalette { id: hifiPalette } HifiPalette { id: hifiPalette }
z: 10000
onEnabledChanged: { onEnabledChanged: {
if (enabled && columns.length == 0) { if (enabled && columns.length == 0) {
pushColumn(rootMenu.items); pushColumn(rootMenu.items);
} }
opacity = enabled ? 1.0 : 0.0 opacity = enabled ? 1.0 : 0.0
if (enabled) { if (enabled) {
forceActiveFocus() forceActiveFocus()
} }
@ -37,355 +38,235 @@ Hifi.HifiMenu {
} }
onVisibleChanged: { onVisibleChanged: {
if (!visible) reset(); if (!visible) reset();
} }
property var menu: Menu {} property var menu: Menu {}
property var models: [] property var models: []
property var columns: [] property var columns: []
property var itemBuilder: Component { property var itemBuilder: Component {
Text { Text {
SystemPalette { id: sp; colorGroup: SystemPalette.Active } SystemPalette { id: sp; colorGroup: SystemPalette.Active }
id: thisText id: thisText
x: 32 x: 32
property var source property var source
property var root property var root
property var listViewIndex property var listViewIndex
property var listView property var listView
text: typedText() text: typedText()
height: implicitHeight height: implicitHeight
width: implicitWidth width: implicitWidth
color: source.enabled ? "black" : "gray" color: source.enabled ? "black" : "gray"
onImplicitWidthChanged: { onImplicitWidthChanged: {
if (listView) { if (listView) {
listView.minWidth = Math.max(listView.minWidth, implicitWidth + 64); listView.minWidth = Math.max(listView.minWidth, implicitWidth + 64);
listView.recalculateSize(); listView.recalculateSize();
} }
} }
FontAwesome { FontAwesome {
visible: source.type == 1 && source.checkable visible: source.type == 1 && source.checkable
x: -32 x: -32
text: (source.type == 1 && source.checked) ? "\uF05D" : "\uF10C" text: (source.type == 1 && source.checked) ? "\uF05D" : "\uF10C"
} }
FontAwesome { FontAwesome {
visible: source.type == 2 visible: source.type == 2
x: listView.width - 64 x: listView.width - 64
text: "\uF0DA" text: "\uF0DA"
} }
function typedText() { function typedText() {
switch(source.type) { switch(source.type) {
case 2: case 2:
return source.title; return source.title;
case 1: case 1:
return source.text; return source.text;
case 0: case 0:
return "-----" return "-----"
} }
} }
MouseArea { MouseArea {
id: mouseArea id: mouseArea
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 0 anchors.bottomMargin: 0
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 0 anchors.topMargin: 0
width: listView.width width: listView.width
onClicked: { onClicked: {
listView.currentIndex = listViewIndex listView.currentIndex = listViewIndex
parent.root.selectItem(parent.source); parent.root.selectItem(parent.source);
} }
} }
} }
} }
property var menuBuilder: Component { property var menuBuilder: Component {
Border { Border {
SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active } SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }
x: root.models.length * 60; x: root.models.length == 1 ?
(root.width / 2 - width / 2) :
root.columns[root.models.length - 2].x + 60;
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
border.color: hifiPalette.hifiBlue border.color: hifiPalette.hifiBlue
color: sysPalette.window color: sysPalette.window
ListView { ListView {
spacing: 6 spacing: 6
property int outerMargin: 8 property int outerMargin: 8
property real minWidth: 0 property real minWidth: 0
anchors.fill: parent anchors.fill: parent
anchors.margins: outerMargin anchors.margins: outerMargin
id: listView id: listView
height: root.height height: root.height
currentIndex: -1 currentIndex: -1
onCountChanged: { onCountChanged: {
recalculateSize() recalculateSize()
} }
function recalculateSize() { function recalculateSize() {
var newHeight = 0 var newHeight = 0
var newWidth = minWidth; var newWidth = minWidth;
for (var i = 0; i < children.length; ++i) { for (var i = 0; i < children.length; ++i) {
var item = children[i]; var item = children[i];
newHeight += item.height newHeight += item.height
} }
parent.height = newHeight + outerMargin * 2; parent.height = newHeight + outerMargin * 2;
parent.width = newWidth + outerMargin * 2 parent.width = newWidth + outerMargin * 2
} }
highlight: Rectangle { highlight: Rectangle {
width: listView.minWidth; height: 32 width: listView.minWidth; height: 32
color: sysPalette.highlight color: sysPalette.highlight
y: (listView.currentItem) ? listView.currentItem.y : 0; y: (listView.currentItem) ? listView.currentItem.y : 0;
Behavior on y { x: 32
NumberAnimation { Behavior on y {
duration: 100 NumberAnimation {
easing.type: Easing.InOutQuint duration: 100
} easing.type: Easing.InOutQuint
} }
} }
}
property int columnIndex: root.models.length - 1 property int columnIndex: root.models.length - 1
model: root.models[columnIndex] model: root.models[columnIndex]
delegate: Loader { delegate: Loader {
id: loader id: loader
sourceComponent: root.itemBuilder sourceComponent: root.itemBuilder
Binding { Binding {
target: loader.item target: loader.item
property: "root" property: "root"
value: root value: root
when: loader.status == Loader.Ready when: loader.status == Loader.Ready
} }
Binding { Binding {
target: loader.item target: loader.item
property: "source" property: "source"
value: modelData value: modelData
when: loader.status == Loader.Ready when: loader.status == Loader.Ready
} }
Binding { Binding {
target: loader.item target: loader.item
property: "listViewIndex" property: "listViewIndex"
value: index value: index
when: loader.status == Loader.Ready when: loader.status == Loader.Ready
} }
Binding { Binding {
target: loader.item target: loader.item
property: "listView" property: "listView"
value: listView value: listView
when: loader.status == Loader.Ready when: loader.status == Loader.Ready
} }
} }
} }
} }
} }
function lastColumn() { function lastColumn() {
return columns[root.columns.length - 1]; return columns[root.columns.length - 1];
} }
function pushColumn(items) { function pushColumn(items) {
models.push(items) models.push(items)
if (columns.length) { if (columns.length) {
var oldColumn = lastColumn(); var oldColumn = lastColumn();
oldColumn.enabled = false; oldColumn.enabled = false;
oldColumn.opacity = 0.5; oldColumn.opacity = 0.5;
} }
var newColumn = menuBuilder.createObject(root); var newColumn = menuBuilder.createObject(root);
columns.push(newColumn); columns.push(newColumn);
newColumn.forceActiveFocus(); newColumn.forceActiveFocus();
} }
function popColumn() { function popColumn() {
if (columns.length > 0) { if (columns.length > 0) {
var curColumn = columns.pop(); var curColumn = columns.pop();
console.log(curColumn); console.log(curColumn);
curColumn.visible = false; curColumn.visible = false;
curColumn.destroy(); curColumn.destroy();
models.pop(); models.pop();
} }
if (columns.length == 0) { if (columns.length == 0) {
enabled = false; enabled = false;
return; return;
} }
curColumn = lastColumn(); curColumn = lastColumn();
curColumn.enabled = true; curColumn.enabled = true;
curColumn.opacity = 1.0; curColumn.opacity = 1.0;
curColumn.forceActiveFocus(); curColumn.forceActiveFocus();
} }
function selectItem(source) { function selectItem(source) {
switch (source.type) { switch (source.type) {
case 2: case 2:
pushColumn(source.items) pushColumn(source.items)
break; break;
case 1: case 1:
source.trigger() source.trigger()
enabled = false enabled = false
break; break;
case 0: case 0:
break; break;
} }
} }
function reset() { function reset() {
while (columns.length > 0) { while (columns.length > 0) {
popColumn(); popColumn();
} }
} }
/*
HifiMenu {
id: rootMenu
Menu {
id: menu
Menu {
title: "File"
MenuItem {
action: HifiAction {
name: rootMenu.login
}
}
MenuItem {
action: HifiAction {
name: "Test"
checkable: true
}
}
MenuItem {
action: HifiAction {
name: rootMenu.quit
}
}
}
Menu {
title: "Edit"
MenuItem {
action: HifiAction {
text: "Copy"
shortcut: StandardKey.Copy
}
}
MenuItem {
action: HifiAction {
text: "Cut"
shortcut: StandardKey.Cut
}
}
MenuItem {
action: HifiAction {
text: "Paste"
shortcut: StandardKey.Paste
}
}
MenuItem {
action: HifiAction {
text: "Undo"
shortcut: StandardKey.Undo
}
}
MenuItem {
action: HifiAction {
text: "Redo"
shortcut: StandardKey.Redo
}
}
MenuItem {
action: HifiAction {
name: rootMenu.attachments
}
}
MenuItem {
action: HifiAction {
name: rootMenu.animations
}
}
}
Menu {
title: "Scripts"
MenuItem {
action: HifiAction {
name: rootMenu.scriptEditor
}
}
MenuItem {
action: HifiAction {
name: rootMenu.loadScript
}
}
MenuItem {
action: HifiAction {
name: rootMenu.loadScriptURL
}
}
MenuItem {
action: HifiAction {
name: rootMenu.stopAllScripts
}
}
MenuItem {
action: HifiAction {
name: rootMenu.reloadAllScripts
}
}
MenuItem {
action: HifiAction {
name: rootMenu.runningScripts
}
}
}
Menu {
title: "Location"
MenuItem {
action: HifiAction {
name: rootMenu.addressBar
}
}
MenuItem {
action: HifiAction {
name: rootMenu.copyAddress
}
}
MenuItem {
action: HifiAction {
name: rootMenu.copyPath
}
}
}
}
}
*/
Keys.onPressed: { Keys.onPressed: {
switch (event.key) { switch (event.key) {
case Qt.Key_Escape: case Qt.Key_Escape:
root.popColumn() root.popColumn()
event.accepted = true; event.accepted = true;
} }
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
id: mouseArea id: mouseArea
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: { onClicked: {
if (mouse.button == Qt.RightButton) { if (mouse.button == Qt.RightButton) {
root.popColumn(); root.popColumn();
} else { } else {
root.enabled = false; root.enabled = false;
} }
} }
} }
} }

View file

@ -14,7 +14,7 @@ Dialog {
resizable: true resizable: true
MarketplaceDialog { MarketplaceDialog {
id: marketplaceDialog id: marketplaceDialog
} }
Item { Item {
@ -33,13 +33,13 @@ Dialog {
url: "https://metaverse.highfidelity.com/marketplace" url: "https://metaverse.highfidelity.com/marketplace"
anchors.fill: parent anchors.fill: parent
onNavigationRequested: { onNavigationRequested: {
console.log(request.url) console.log(request.url)
if (!marketplaceDialog.navigationRequested(request.url)) { if (!marketplaceDialog.navigationRequested(request.url)) {
console.log("Application absorbed the request") console.log("Application absorbed the request")
request.action = WebView.IgnoreRequest; request.action = WebView.IgnoreRequest;
return; return;
} }
console.log("Application passed on the request") console.log("Application passed on the request")
request.action = WebView.AcceptRequest; request.action = WebView.AcceptRequest;
return; return;
} }

View file

@ -71,13 +71,13 @@ Dialog {
onEnabledChanged: { onEnabledChanged: {
if (enabled) { if (enabled) {
content.forceActiveFocus(); content.forceActiveFocus();
} }
} }
Hifi.MessageDialog { Hifi.MessageDialog {
id: content id: content
clip: true clip: true
anchors.fill: parent anchors.fill: parent
anchors.topMargin: parent.topMargin + root.outerSpacing anchors.topMargin: parent.topMargin + root.outerSpacing
anchors.leftMargin: parent.margins + root.outerSpacing anchors.leftMargin: parent.margins + root.outerSpacing
@ -88,16 +88,16 @@ Dialog {
property real buttonsRowImplicitWidth: Screen.pixelDensity * 50 property real buttonsRowImplicitWidth: Screen.pixelDensity * 50
Keys.onPressed: { Keys.onPressed: {
console.log("Key press at content") console.log("Key press at content")
event.accepted = true event.accepted = true
if (event.modifiers === Qt.ControlModifier) if (event.modifiers === Qt.ControlModifier)
switch (event.key) { switch (event.key) {
case Qt.Key_A: case Qt.Key_A:
console.log("Select All") console.log("Select All")
detailedText.selectAll() detailedText.selectAll()
break break
case Qt.Key_C: case Qt.Key_C:
console.log("Copy") console.log("Copy")
detailedText.copy() detailedText.copy()
break break
case Qt.Key_Period: case Qt.Key_Period:
@ -107,12 +107,12 @@ Dialog {
} else switch (event.key) { } else switch (event.key) {
case Qt.Key_Escape: case Qt.Key_Escape:
case Qt.Key_Back: case Qt.Key_Back:
console.log("Rejecting") console.log("Rejecting")
reject() reject()
break break
case Qt.Key_Enter: case Qt.Key_Enter:
case Qt.Key_Return: case Qt.Key_Return:
console.log("Accepting") console.log("Accepting")
accept() accept()
break break
} }
@ -123,18 +123,18 @@ Dialog {
Component.onCompleted: { Component.onCompleted: {
root.title = title root.title = title
} }
onTitleChanged: { onTitleChanged: {
root.title = title root.title = title
} }
Column { Column {
id: contentColumn id: contentColumn
spacing: root.outerSpacing spacing: root.outerSpacing
anchors { anchors {
top: parent.top top: parent.top
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
Item { Item {

View file

@ -2,8 +2,8 @@ import QtQuick 2.4
import QtQuick.Controls 1.3 import QtQuick.Controls 1.3
Item { Item {
Menu { Menu {
id: root id: root
objectName: "rootMenu" objectName: "rootMenu"
} }
} }

View file

@ -10,17 +10,17 @@ Root {
anchors.fill: parent anchors.fill: parent
onWidthChanged: { onWidthChanged: {
console.log("Root width: " + width) console.log("Root width: " + width)
} }
onHeightChanged: { onHeightChanged: {
console.log("Root height: " + height) console.log("Root height: " + height)
} }
Component.onCompleted: { Component.onCompleted: {
console.log("Completed root") console.log("Completed root")
root.forceActiveFocus() root.forceActiveFocus()
} }
Button { Button {
id: messageBox id: messageBox
anchors.right: createDialog.left anchors.right: createDialog.left
@ -48,7 +48,7 @@ Root {
} }
Keys.onPressed: { Keys.onPressed: {
console.log(event.key); console.log(event.key);
} }
} }

View file

@ -16,6 +16,8 @@ Item {
HifiPalette { id: hifiPalette } HifiPalette { id: hifiPalette }
SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active } SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }
x: parent ? parent.width / 2 - width / 2 : 0
y: parent ? parent.height / 2 - height / 2 : 0
property int animationDuration: 400 property int animationDuration: 400
property bool destroyOnInvisible: false property bool destroyOnInvisible: false

View file

@ -7,7 +7,7 @@ Text {
FontLoader { id: iconFont; source: "../../fonts/fontawesome-webfont.ttf"; } FontLoader { id: iconFont; source: "../../fonts/fontawesome-webfont.ttf"; }
property int size: 32 property int size: 32
width: size width: size
height: size height: size
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.family: iconFont.name font.family: iconFont.name

View file

@ -2,15 +2,15 @@ import QtQuick 2.4 as Original
import QtQuick.Controls.Styles 1.3 as OriginalStyles import QtQuick.Controls.Styles 1.3 as OriginalStyles
import "." import "."
import "../controls" import "../controls"
OriginalStyles.ButtonStyle { OriginalStyles.ButtonStyle {
Original.SystemPalette { id: myPalette; colorGroup: Original.SystemPalette.Active } Original.SystemPalette { id: myPalette; colorGroup: Original.SystemPalette.Active }
padding { padding {
top: 8 top: 8
left: 12 left: 12
right: 12 right: 12
bottom: 8 bottom: 8
} }
background: Border { background: Border {
anchors.fill: parent anchors.fill: parent
} }

View file

@ -1,5 +1,5 @@
import QtQuick 2.4 import QtQuick 2.4
QtObject { QtObject {
property string hifiBlue: "#0e7077" property string hifiBlue: "#0e7077"
} }

View file

@ -2,15 +2,15 @@ import QtQuick 2.4
import QtQuick.Controls.Styles 1.3 import QtQuick.Controls.Styles 1.3
import "../controls" import "../controls"
import "." import "."
ButtonStyle { ButtonStyle {
HifiPalette { id: hifiPalette } HifiPalette { id: hifiPalette }
padding { padding {
top: 2 top: 2
left: 4 left: 4
right: 4 right: 4
bottom: 2 bottom: 2
} }
background: Item {} background: Item {}
label: Text { label: Text {
renderType: Text.NativeRendering renderType: Text.NativeRendering

View file

@ -1079,12 +1079,12 @@ bool Application::eventFilter(QObject* object, QEvent* event) {
return false; return false;
} }
static bool _altPressed; static bool altPressed;
static bool _ctrlPressed; static bool ctrlPressed;
void Application::keyPressEvent(QKeyEvent* event) { void Application::keyPressEvent(QKeyEvent* event) {
_altPressed = event->key() == Qt::Key_Alt; altPressed = event->key() == Qt::Key_Alt;
_ctrlPressed = event->key() == Qt::Key_Control; ctrlPressed = event->key() == Qt::Key_Control;
_keysPressed.insert(event->key()); _keysPressed.insert(event->key());
_controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts
@ -1336,15 +1336,13 @@ void Application::keyPressEvent(QKeyEvent* event) {
} }
void Application::keyReleaseEvent(QKeyEvent* event) { void Application::keyReleaseEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Alt && _altPressed) { if (event->key() == Qt::Key_Alt && altPressed && _window->isActiveWindow()) {
Menu::toggle(); Menu::toggle();
} }
if (event->key() == Qt::Key_Control && _ctrlPressed) { if (event->key() == Qt::Key_Control && ctrlPressed && _window->isActiveWindow()) {
auto offscreenUi = DependencyManager::get<OffscreenUi>(); Menu::toggle();
auto rootMenu = offscreenUi->getRootItem()->findChild<QObject*>("rootMenu");
QMetaObject::invokeMethod(rootMenu, "popup");
} }
_ctrlPressed = event->key() == Qt::Key_Control; ctrlPressed = altPressed = false;
_keysPressed.remove(event->key()); _keysPressed.remove(event->key());

View file

@ -94,9 +94,9 @@ void MainWindow::changeEvent(QEvent* event) {
emit windowShown(true); emit windowShown(true);
} }
if (isFullScreen() != Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) { //if (isFullScreen() != Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {
Menu::getInstance()->setIsOptionChecked(MenuOption::Fullscreen, isFullScreen()); // Menu::getInstance()->setIsOptionChecked(MenuOption::Fullscreen, isFullScreen());
} //}
} else if (event->type() == QEvent::ActivationChange) { } else if (event->type() == QEvent::ActivationChange) {
if (isActiveWindow()) { if (isActiveWindow()) {
emit windowShown(true); emit windowShown(true);

View file

@ -45,13 +45,12 @@
#include "Util.h" #include "Util.h"
// Proxy object to simplify porting over // Proxy object to simplify porting over
HifiAction::HifiAction(const QString & menuOption) : _menuOption(menuOption) { HifiAction::HifiAction(const QString& menuOption) : _menuOption(menuOption) {
} }
//void HifiAction::setCheckable(bool) { void HifiAction::setCheckable(bool checkable) {
// Menu::getInstance()->set Menu::getInstance()->setCheckable(_menuOption, checkable);
// qFatal("Not implemented"); }
//}
void HifiAction::setChecked(bool checked) { void HifiAction::setChecked(bool checked) {
Menu::getInstance()->setChecked(_menuOption, checked); Menu::getInstance()->setChecked(_menuOption, checked);
@ -65,7 +64,7 @@ QString HifiAction::shortcut() const {
return Menu::getInstance()->getItemShortcut(_menuOption); return Menu::getInstance()->getItemShortcut(_menuOption);
} }
void HifiAction::setText(const QString & text) { void HifiAction::setText(const QString& text) {
Menu::getInstance()->setItemText(_menuOption, text); Menu::getInstance()->setItemText(_menuOption, text);
} }
@ -101,7 +100,7 @@ Menu* Menu::getInstance() {
return _instance; return _instance;
} }
Menu::Menu(QQuickItem * parent) : HifiMenu(parent) { Menu::Menu(QQuickItem* parent) : HifiMenu(parent) {
} }
void Menu::init() { void Menu::init() {
@ -125,12 +124,15 @@ void Menu::init() {
#endif #endif
{ {
#if 0
static const QString SCRIPTS_MENU{ "Scripts" }; static const QString SCRIPTS_MENU{ "Scripts" };
addMenu(FILE_MENU, SCRIPTS_MENU); addMenu(FILE_MENU, LOCATION_MENU);
#else
static const QString SCRIPTS_MENU{ FILE_MENU };
addSeparator(FILE_MENU, "Scripts");
#endif
//Qt::CTRL | Qt::Key_O //Qt::CTRL | Qt::Key_O
addItem(SCRIPTS_MENU, MenuOption::LoadScript, [=] { addItem(SCRIPTS_MENU, MenuOption::LoadScript, qApp, SLOT(loadDialog()));
qApp->loadDialog();
});
//Qt::CTRL | Qt::SHIFT | Qt::Key_O //Qt::CTRL | Qt::SHIFT | Qt::Key_O
addItem(SCRIPTS_MENU, MenuOption::LoadScriptURL, [=] { addItem(SCRIPTS_MENU, MenuOption::LoadScriptURL, [=] {
qApp->loadScriptURLDialog(); qApp->loadScriptURLDialog();
@ -149,9 +151,15 @@ void Menu::init() {
} }
{ {
#if 0
static const QString LOCATION_MENU{ "Location" }; static const QString LOCATION_MENU{ "Location" };
addMenu(FILE_MENU, LOCATION_MENU); addMenu(FILE_MENU, LOCATION_MENU);
#else
addSeparator(FILE_MENU, "Location");
static const QString LOCATION_MENU{ FILE_MENU };
#endif
qApp->getBookmarks()->setupMenus(LOCATION_MENU); qApp->getBookmarks()->setupMenus(LOCATION_MENU);
//Qt::CTRL | Qt::Key_L //Qt::CTRL | Qt::Key_L
addItem(LOCATION_MENU, MenuOption::AddressBar, [=] { addItem(LOCATION_MENU, MenuOption::AddressBar, [=] {
auto dialogsManager = DependencyManager::get<DialogsManager>(); auto dialogsManager = DependencyManager::get<DialogsManager>();
@ -178,16 +186,15 @@ void Menu::init() {
{ {
static const QString EDIT_MENU{ "Edit" }; static const QString EDIT_MENU{ "Edit" };
addMenu(ROOT_MENU, EDIT_MENU); addMenu(ROOT_MENU, EDIT_MENU);
#if 0
QUndoStack* undoStack = qApp->getUndoStack();
QAction* undoAction = undoStack->createUndoAction(editMenu);
undoAction->setShortcut(Qt::CTRL | Qt::Key_Z);
addActionToQMenuAndActionHash(editMenu, undoAction);
QAction* redoAction = undoStack->createRedoAction(editMenu); QUndoStack* undoStack = qApp->getUndoStack();
redoAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Z); QAction* undoAction = undoStack->createUndoAction(this);
addActionToQMenuAndActionHash(editMenu, redoAction); //undoAction->setShortcut(Qt::CTRL | Qt::Key_Z);
#endif addItem(EDIT_MENU, undoAction->text(), undoAction, SLOT(trigger()));
QAction* redoAction = undoStack->createRedoAction(this);
//redoAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Z);
addItem(EDIT_MENU, redoAction->text(), redoAction, SLOT(trigger()));
// Qt::CTRL | Qt::Key_Comma // Qt::CTRL | Qt::Key_Comma
// QAction::PreferencesRole // QAction::PreferencesRole
@ -231,23 +238,20 @@ void Menu::init() {
// FIXME group // FIXME group
addCheckableItem(VIZ_MENU, MenuOption::VisibleToEveryone, addCheckableItem(VIZ_MENU, MenuOption::VisibleToEveryone,
discoverabilityManager->getDiscoverabilityMode() == Discoverability::All, discoverabilityManager->getDiscoverabilityMode() == Discoverability::All,
[=](bool) { discoverabilityManager->setVisibility(); }); discoverabilityManager.data(), SLOT(setVisibility()));
addCheckableItem(VIZ_MENU, MenuOption::VisibleToFriends, addCheckableItem(VIZ_MENU, MenuOption::VisibleToFriends,
discoverabilityManager->getDiscoverabilityMode() == Discoverability::Friends, discoverabilityManager->getDiscoverabilityMode() == Discoverability::Friends,
[=](bool) { discoverabilityManager->setVisibility(); }); discoverabilityManager.data(), SLOT(setVisibility()));
addCheckableItem(VIZ_MENU, MenuOption::VisibleToNoOne, addCheckableItem(VIZ_MENU, MenuOption::VisibleToNoOne,
discoverabilityManager->getDiscoverabilityMode() == Discoverability::None, discoverabilityManager->getDiscoverabilityMode() == Discoverability::None,
[=](bool) { discoverabilityManager->setVisibility(); }); discoverabilityManager.data(), SLOT(setVisibility()));
connect(discoverabilityManager.data(), &DiscoverabilityManager::discoverabilityModeChanged, connect(discoverabilityManager.data(), &DiscoverabilityManager::discoverabilityModeChanged,
discoverabilityManager.data(), &DiscoverabilityManager::visibilityChanged); discoverabilityManager.data(), &DiscoverabilityManager::visibilityChanged);
} }
//Qt::CTRL | Qt::ALT | Qt::Key_T, //Qt::CTRL | Qt::ALT | Qt::Key_T,
addItem(TOOLS_MENU, MenuOption::ToolWindow, [=] { addItem(TOOLS_MENU, MenuOption::ToolWindow,
// dialogsManager->toggleToolWindow(); dialogsManager.data(), SLOT(toggleToolWindow()));
});
//Qt::CTRL | Qt::ALT | Qt::Key_J, //Qt::CTRL | Qt::ALT | Qt::Key_J,
addItem(TOOLS_MENU, MenuOption::Console, [=] { addItem(TOOLS_MENU, MenuOption::Console, [=] {
@ -297,12 +301,10 @@ void Menu::init() {
addCheckableItem(AVATAR_MENU, MenuOption::NamesAboveHeads, true); addCheckableItem(AVATAR_MENU, MenuOption::NamesAboveHeads, true);
addCheckableItem(AVATAR_MENU, MenuOption::GlowWhenSpeaking, true); addCheckableItem(AVATAR_MENU, MenuOption::GlowWhenSpeaking, true);
addCheckableItem(AVATAR_MENU, MenuOption::BlueSpeechSphere, true); addCheckableItem(AVATAR_MENU, MenuOption::BlueSpeechSphere, true);
addCheckableItem(AVATAR_MENU, MenuOption::EnableCharacterController, true, [=](bool) { addCheckableItem(AVATAR_MENU, MenuOption::EnableCharacterController, true,
avatar->updateMotionBehavior(); avatar, SLOT(updateMotionBehavior()));
}); addCheckableItem(AVATAR_MENU, MenuOption::ShiftHipsForIdleAnimations, false,
addCheckableItem(AVATAR_MENU, MenuOption::ShiftHipsForIdleAnimations, false, [=](bool) { avatar, SLOT(updateMotionBehavior()));
avatar->updateMotionBehavior();
});
} }
{ {
@ -311,32 +313,28 @@ void Menu::init() {
// Mac Qt::CTRL | Qt::META | Qt::Key_F, // Mac Qt::CTRL | Qt::META | Qt::Key_F,
// Win32/Linux Qt::CTRL | Qt::Key_F, // Win32/Linux Qt::CTRL | Qt::Key_F,
addCheckableItem(VIEW_MENU, MenuOption::Fullscreen, false, [=](bool checked) { addCheckableItem(VIEW_MENU, MenuOption::Fullscreen, false);
// qApp->setFullscreen(checked); connectCheckable(MenuOption::Fullscreen, qApp, SLOT(setFullscreen(bool)));
});
// QML Qt::Key_P, // QML Qt::Key_P,
addCheckableItem(VIEW_MENU, MenuOption::FirstPerson, true, [=](bool checked) { addCheckableItem(VIEW_MENU, MenuOption::FirstPerson, true,
// qApp->cameraMenuChanged(); qApp, SLOT(cameraMenuChanged()));
});
//QML Qt::SHIFT | Qt::Key_H, //QML Qt::SHIFT | Qt::Key_H,
addCheckableItem(VIEW_MENU, MenuOption::Mirror, true); addCheckableItem(VIEW_MENU, MenuOption::Mirror, true,
qApp, SLOT(cameraMenuChanged()));
// QML Qt::Key_H, // QML Qt::Key_H,
addCheckableItem(VIEW_MENU, MenuOption::FullscreenMirror, true, [=](bool checked) { addCheckableItem(VIEW_MENU, MenuOption::FullscreenMirror, false,
// qApp->cameraMenuChanged(); qApp, SLOT(cameraMenuChanged()));
});
// Mac Qt::META | Qt::Key_H, // Mac Qt::META | Qt::Key_H,
// Win32/Linux Qt::CTRL | Qt::Key_H, // Win32/Linux Qt::CTRL | Qt::Key_H,
addCheckableItem(VIEW_MENU, MenuOption::HMDTools, false, [=](bool checked) { addCheckableItem(VIEW_MENU, MenuOption::HMDTools, false, [=](bool checked) {
dialogsManager->hmdTools(checked); dialogsManager->hmdTools(checked);
}); });
addCheckableItem(VIEW_MENU, MenuOption::EnableVRMode, false, [=](bool checked) { addCheckableItem(VIEW_MENU, MenuOption::EnableVRMode, false);
// qApp->setEnableVRMode(checked); connectCheckable(MenuOption::EnableVRMode, qApp, SLOT(setEnableVRMode(bool)));
}); addCheckableItem(VIEW_MENU, MenuOption::Enable3DTVMode, false);
addCheckableItem(VIEW_MENU, MenuOption::Enable3DTVMode, false, [=](bool checked) { connectCheckable(MenuOption::Enable3DTVMode, qApp, SLOT(setEnable3DTVMode(bool)));
// qApp->setEnable3DTVMode(checked);
});
{ {
static const QString BORDER_MENU{ "Server Borders" }; static const QString BORDER_MENU{ "Server Borders" };
@ -362,7 +360,6 @@ void Menu::init() {
dialogsManager->octreeStatsDetails(); dialogsManager->octreeStatsDetails();
}); });
} }
{ {
static const QString DEV_MENU{ "Developer" }; static const QString DEV_MENU{ "Developer" };
@ -561,25 +558,19 @@ void Menu::init() {
static const QString AUDIO_MENU{ "Audio" }; static const QString AUDIO_MENU{ "Audio" };
addMenu(DEV_MENU, AUDIO_MENU); addMenu(DEV_MENU, AUDIO_MENU);
auto audioIO = DependencyManager::get<AudioClient>(); auto audioIO = DependencyManager::get<AudioClient>();
addCheckableItem(AUDIO_MENU, MenuOption::AudioNoiseReduction, true, [=](bool checked) { addCheckableItem(AUDIO_MENU, MenuOption::AudioNoiseReduction, true,
audioIO->toggleAudioNoiseReduction(); audioIO.data(), SLOT(toggleAudioNoiseReduction()));
}); addCheckableItem(AUDIO_MENU, MenuOption::EchoServerAudio, false,
addCheckableItem(AUDIO_MENU, MenuOption::EchoServerAudio, false, [=](bool checked) { audioIO.data(), SLOT(toggleServerEcho()));
audioIO->toggleServerEcho(); addCheckableItem(AUDIO_MENU, MenuOption::EchoLocalAudio, false,
}); audioIO.data(), SLOT(toggleLocalEcho()));
addCheckableItem(AUDIO_MENU, MenuOption::EchoLocalAudio, false, [=](bool checked) { addCheckableItem(AUDIO_MENU, MenuOption::StereoAudio, false,
audioIO->toggleLocalEcho(); audioIO.data(), SLOT(toggleStereoInput()));
});
addCheckableItem(AUDIO_MENU, MenuOption::StereoAudio, false, [=](bool checked) {
audioIO->toggleStereoInput();
});
// Qt::CTRL | Qt::Key_M, // Qt::CTRL | Qt::Key_M,
addCheckableItem(AUDIO_MENU, MenuOption::MuteAudio, false, [=](bool checked) { addCheckableItem(AUDIO_MENU, MenuOption::MuteAudio, false,
audioIO->toggleMute(); audioIO.data(), SLOT(toggleMute()));
}); addCheckableItem(AUDIO_MENU, MenuOption::MuteEnvironment, false,
addCheckableItem(AUDIO_MENU, MenuOption::MuteEnvironment, false, [=](bool checked) { audioIO.data(), SLOT(sendMuteEnvironmentPacket()));
audioIO->sendMuteEnvironmentPacket();
});
{ {
static const QString SCOPE_MENU{ "Audio Scope" }; static const QString SCOPE_MENU{ "Audio Scope" };
addMenu(AUDIO_MENU, SCOPE_MENU); addMenu(AUDIO_MENU, SCOPE_MENU);
@ -637,6 +628,37 @@ void Menu::loadSettings() {
void Menu::saveSettings() { void Menu::saveSettings() {
// scanMenuBar(&Menu::saveAction); // scanMenuBar(&Menu::saveAction);
} }
void Menu::addMenuItem(const MenuItemProperties& properties) {
if (QThread::currentThread() != Application::getInstance()->getMainThread()) {
Application::getInstance()->postLambdaEvent([=]{
addMenuItem(properties);
});
return;
}
// Shortcut key items: in order of priority
//QString shortcutKey;
//KeyEvent shortcutKeyEvent;
//QKeySequence shortcutKeySequence; // this is what we actually use, it's set from one of the above
//// location related items: in order of priority
//int position;
//QString beforeItem;
//QString afterItem;
if (properties.isSeparator) {
addSeparator(properties.menuName, properties.menuItemName);
return;
}
addItem(properties.menuName, properties.menuItemName);
if (properties.isCheckable) {
setCheckable(properties.menuItemName);
if (properties.isChecked) {
setChecked(properties.menuItemName);
}
}
}
#if 0 #if 0
void Menu::loadAction(Settings& settings, QAction& action) { void Menu::loadAction(Settings& settings, QAction& action) {
@ -688,4 +710,5 @@ void Menu::addDisabledActionAndSeparator(QMenu* destinationMenu, const QString&
} }
} }
#endif #endif

View file

@ -28,72 +28,50 @@ void MenuScriptingInterface::menuItemTriggered() {
} }
void MenuScriptingInterface::addMenu(const QString& menu) { void MenuScriptingInterface::addMenu(const QString& menu) {
QMetaObject::invokeMethod(Menu::getInstance(), "addMenu", Q_ARG(const QString&, menu)); Menu::getInstance()->addMenu("", menu);
} }
void MenuScriptingInterface::removeMenu(const QString& menu) { void MenuScriptingInterface::removeMenu(const QString& menu) {
QMetaObject::invokeMethod(Menu::getInstance(), "removeMenu", Q_ARG(const QString&, menu)); Menu::getInstance()->removeMenu(menu);
} }
bool MenuScriptingInterface::menuExists(const QString& menu) { bool MenuScriptingInterface::menuExists(const QString& menu) {
bool result; return Menu::getInstance()->menuExists(menu);
QMetaObject::invokeMethod(Menu::getInstance(), "menuExists", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(const QString&, menu));
return result;
} }
void MenuScriptingInterface::addSeparator(const QString& menuName, const QString& separatorName) { void MenuScriptingInterface::addSeparator(const QString& menuName, const QString& separatorName) {
QMetaObject::invokeMethod(Menu::getInstance(), "addSeparator", Menu::getInstance()->addSeparator(menuName, separatorName);
Q_ARG(const QString&, menuName),
Q_ARG(const QString&, separatorName));
} }
void MenuScriptingInterface::removeSeparator(const QString& menuName, const QString& separatorName) { void MenuScriptingInterface::removeSeparator(const QString& menuName, const QString& separatorName) {
QMetaObject::invokeMethod(Menu::getInstance(), "removeSeparator", Menu::getInstance()->removeSeparator(menuName, separatorName);
Q_ARG(const QString&, menuName),
Q_ARG(const QString&, separatorName));
} }
void MenuScriptingInterface::addMenuItem(const MenuItemProperties& properties) { void MenuScriptingInterface::addMenuItem(const MenuItemProperties& properties) {
QMetaObject::invokeMethod(Menu::getInstance(), "addMenuItem", Q_ARG(const MenuItemProperties&, properties)); Menu::getInstance()->addMenuItem(properties);
} }
void MenuScriptingInterface::addMenuItem(const QString& menu, const QString& menuitem, const QString& shortcutKey) { void MenuScriptingInterface::addMenuItem(const QString& menu, const QString& menuitem, const QString& shortcutKey) {
MenuItemProperties properties(menu, menuitem, shortcutKey); Menu::getInstance()->addItem(menu, menuitem);
QMetaObject::invokeMethod(Menu::getInstance(), "addMenuItem", Q_ARG(const MenuItemProperties&, properties)); Menu::getInstance()->setItemShortcut(menuitem, shortcutKey);
} }
void MenuScriptingInterface::addMenuItem(const QString& menu, const QString& menuitem) { void MenuScriptingInterface::addMenuItem(const QString& menu, const QString& menuitem) {
MenuItemProperties properties(menu, menuitem); Menu::getInstance()->addItem(menu, menuitem);
QMetaObject::invokeMethod(Menu::getInstance(), "addMenuItem", Q_ARG(const MenuItemProperties&, properties));
} }
void MenuScriptingInterface::removeMenuItem(const QString& menu, const QString& menuitem) { void MenuScriptingInterface::removeMenuItem(const QString& menu, const QString& menuitem) {
QMetaObject::invokeMethod(Menu::getInstance(), "removeMenuItem", Menu::getInstance()->removeItem(menuitem);
Q_ARG(const QString&, menu),
Q_ARG(const QString&, menuitem));
}; };
bool MenuScriptingInterface::menuItemExists(const QString& menu, const QString& menuitem) { bool MenuScriptingInterface::menuItemExists(const QString& menu, const QString& menuitem) {
bool result; return Menu::getInstance()->itemExists(menu, menuitem);
QMetaObject::invokeMethod(Menu::getInstance(), "menuItemExists", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(const QString&, menu),
Q_ARG(const QString&, menuitem));
return result;
} }
bool MenuScriptingInterface::isOptionChecked(const QString& menuOption) { bool MenuScriptingInterface::isOptionChecked(const QString& menuOption) {
bool result; return Menu::getInstance()->isChecked(menuOption);
QMetaObject::invokeMethod(Menu::getInstance(), "isOptionChecked", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, result),
Q_ARG(const QString&, menuOption));
return result;
} }
void MenuScriptingInterface::setIsOptionChecked(const QString& menuOption, bool isChecked) { void MenuScriptingInterface::setIsOptionChecked(const QString& menuOption, bool isChecked) {
QMetaObject::invokeMethod(Menu::getInstance(), "setIsOptionChecked", Qt::BlockingQueuedConnection, Menu::getInstance()->setChecked(menuOption, isChecked);
Q_ARG(const QString&, menuOption),
Q_ARG(bool, isChecked));
} }

View file

@ -45,13 +45,18 @@ QScriptValue WindowScriptingInterface::hasFocus() {
} }
void WindowScriptingInterface::setFocus() { void WindowScriptingInterface::setFocus() {
auto window = Application::getInstance()->getWindow(); Application::getInstance()->postLambdaEvent([] {
window->activateWindow(); auto window = Application::getInstance()->getWindow();
window->setFocus(); window->activateWindow();
window->setFocus();
});
} }
void WindowScriptingInterface::raiseMainWindow() { void WindowScriptingInterface::raiseMainWindow() {
// Application::getInstance()->getWindow()->raise(); // It's forbidden to call raise() from another thread.
Application::getInstance()->postLambdaEvent([] {
Application::getInstance()->getWindow()->raise();
});
} }
void WindowScriptingInterface::setCursorVisible(bool visible) { void WindowScriptingInterface::setCursorVisible(bool visible) {

View file

@ -323,7 +323,7 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
//Render magnifier, but dont show border for mouse magnifier //Render magnifier, but dont show border for mouse magnifier
glm::vec2 projection = screenToOverlay(glm::vec2(_reticlePosition[MOUSE].x(), glm::vec2 projection = screenToOverlay(glm::vec2(_reticlePosition[MOUSE].x(),
_reticlePosition[MOUSE].y())); _reticlePosition[MOUSE].y()));
with_each_texture(_overlays.getTexture(), _newUiTexture, [&] { with_each_texture(_overlays.getTexture(), 0, [&] {
renderMagnifier(projection, _magSizeMult[i], i != MOUSE); renderMagnifier(projection, _magSizeMult[i], i != MOUSE);
}); });
} }

View file

@ -14,16 +14,26 @@
#include <QVector> #include <QVector>
#include <QDateTime> #include <QDateTime>
#include <QFileInfo> #include <QFileInfo>
#include <QDir>
#include "PathUtils.h" #include "PathUtils.h"
QString& PathUtils::resourcesPath() { QString& PathUtils::resourcesPath() {
#ifdef DEBUG
static QString staticResourcePath;
if (staticResourcePath.isEmpty()) {
QDir path(__FILE__);
path.cdUp();
staticResourcePath = path.cleanPath(path.absoluteFilePath("../../../interface/resources/")) + "/";
}
#else
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/"; static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/";
#else #else
static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/"; static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/";
#endif #endif
#endif
return staticResourcePath; return staticResourcePath;
} }

View file

@ -45,7 +45,7 @@ void HifiMenu::setTriggerAction(const QString & name, std::function<void()> f) {
QObject* addMenu(QObject* parent, const QString & text) { QObject* addMenu(QObject* parent, const QString & text) {
// FIXME add more checking here to ensure no name conflicts // FIXME add more checking here to ensure no name conflicts
QVariant returnedValue; QVariant returnedValue;
QMetaObject::invokeMethod(parent, "addMenu", QMetaObject::invokeMethod(parent, "addMenu", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, returnedValue), Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, text)); Q_ARG(QVariant, text));
QObject* result = returnedValue.value<QObject*>(); QObject* result = returnedValue.value<QObject*>();
@ -59,7 +59,7 @@ class QQuickMenuItem;
QObject* addItem(QObject* parent, const QString& text) { QObject* addItem(QObject* parent, const QString& text) {
// FIXME add more checking here to ensure no name conflicts // FIXME add more checking here to ensure no name conflicts
QQuickMenuItem* returnedValue{ nullptr }; QQuickMenuItem* returnedValue{ nullptr };
bool invokeResult = QMetaObject::invokeMethod(parent, "addItem", bool invokeResult = QMetaObject::invokeMethod(parent, "addItem", Qt::DirectConnection,
Q_RETURN_ARG(QQuickMenuItem*, returnedValue), Q_RETURN_ARG(QQuickMenuItem*, returnedValue),
Q_ARG(QString, text)); Q_ARG(QString, text));
Q_ASSERT(invokeResult); Q_ASSERT(invokeResult);
@ -104,9 +104,11 @@ bool HifiMenu::menuExists(const QString& menuName) const {
} }
void HifiMenu::addSeparator(const QString& parentMenu, const QString& separatorName) { void HifiMenu::addSeparator(const QString& parentMenu, const QString& separatorName) {
// FIXME 'add sep' QObject * parent = findMenuObject(parentMenu);
// addMenu(parentMenu, separatorName); bool invokeResult = QMetaObject::invokeMethod(parent, "addSeparator", Qt::DirectConnection);
// setEnabled() Q_ASSERT(invokeResult);
addItem(parentMenu, separatorName);
enableItem(separatorName, false);
} }
void HifiMenu::removeSeparator(const QString& parentMenu, const QString& separatorName) { void HifiMenu::removeSeparator(const QString& parentMenu, const QString& separatorName) {
@ -132,6 +134,11 @@ void HifiMenu::addItem(const QString & parentMenu, const QString & menuOption, s
addItem(parentMenu, menuOption); addItem(parentMenu, menuOption);
} }
void HifiMenu::addItem(const QString & parentMenu, const QString & menuOption, QObject* receiver, const char* slot) {
addItem(parentMenu, menuOption);
connectItem(menuOption, receiver, slot);
}
void HifiMenu::removeItem(const QString& menuOption) { void HifiMenu::removeItem(const QString& menuOption) {
removeMenu(menuOption); removeMenu(menuOption);
} }
@ -170,8 +177,10 @@ void HifiMenu::setChecked(const QString& menuOption, bool isChecked) {
warn(menuOption); warn(menuOption);
return; return;
} }
menuItem->setProperty("checked", QVariant::fromValue(isChecked)); if (menuItem->property("checked").toBool() != isChecked) {
Q_ASSERT(menuItem->property("checked").toBool() == isChecked); menuItem->setProperty("checked", QVariant::fromValue(isChecked));
Q_ASSERT(menuItem->property("checked").toBool() == isChecked);
}
} }
void HifiMenu::setCheckable(const QString& menuOption, bool checkable) { void HifiMenu::setCheckable(const QString& menuOption, bool checkable) {
@ -185,7 +194,7 @@ void HifiMenu::setCheckable(const QString& menuOption, bool checkable) {
Q_ASSERT(menuItem->property("checkable").toBool() == checkable); Q_ASSERT(menuItem->property("checkable").toBool() == checkable);
} }
void HifiMenu::setItemText(const QString& menuOption, const QString & text) { void HifiMenu::setItemText(const QString& menuOption, const QString& text) {
QObject* menuItem = findMenuObject(menuOption); QObject* menuItem = findMenuObject(menuOption);
if (!menuItem) { if (!menuItem) {
warn(menuOption); warn(menuOption);
@ -253,3 +262,18 @@ QString HifiMenu::getItemShortcut(const QString& menuOption) {
} }
return QString(); return QString();
} }
void HifiMenu::addCheckableItem(const QString& parentMenu, const QString& menuOption, bool checked, QObject* receiver, const char* slot) {
addCheckableItem(parentMenu, menuOption, checked);
connectItem(menuOption, receiver, slot);
}
void HifiMenu::connectCheckable(const QString& menuOption, QObject* receiver, const char* slot) {
QObject* result = findMenuObject(menuOption);
connect(result, SIGNAL(toggled(bool)), receiver, slot);
}
void HifiMenu::connectItem(const QString& menuOption, QObject* receiver, const char* slot) {
QObject* result = findMenuObject(menuOption);
connect(result, SIGNAL(triggered()), receiver, slot);
}

View file

@ -37,9 +37,13 @@ public:
void addItem(const QString& parentMenu, const QString& menuOption); void addItem(const QString& parentMenu, const QString& menuOption);
void addItem(const QString& parentMenu, const QString& menuOption, std::function<void()> f); void addItem(const QString& parentMenu, const QString& menuOption, std::function<void()> f);
void addItem(const QString& parentMenu, const QString& menuOption, QObject* receiver, const char* slot);
void addCheckableItem(const QString& parentMenu, const QString& menuOption, bool checked = false); void addCheckableItem(const QString& parentMenu, const QString& menuOption, bool checked = false);
void addCheckableItem(const QString& parentMenu, const QString& menuOption, bool checked, std::function<void(bool)> f); void addCheckableItem(const QString& parentMenu, const QString& menuOption, bool checked, std::function<void(bool)> f);
void addCheckableItem(const QString& parentMenu, const QString& menuOption, bool checked, QObject* receiver, const char* slot);
void connectCheckable(const QString& menuOption, QObject* receiver, const char* slot);
void connectItem(const QString& menuOption, QObject* receiver, const char* slot);
void removeItem(const QString& menuitem); void removeItem(const QString& menuitem);
bool itemExists(const QString& menuName, const QString& menuitem) const; bool itemExists(const QString& menuName, const QString& menuitem) const;
@ -48,15 +52,15 @@ public:
bool isChecked(const QString& menuOption) const; bool isChecked(const QString& menuOption) const;
void setChecked(const QString& menuOption, bool checked = true); void setChecked(const QString& menuOption, bool checked = true);
void setCheckable(const QString& menuOption, bool checkable = true); void setCheckable(const QString& menuOption, bool checkable = true);
void setExclusiveGroup(const QString& menuOption, const QString & groupName); void setExclusiveGroup(const QString& menuOption, const QString& groupName);
void setItemText(const QString& menuOption, const QString& text); void setItemText(const QString& menuOption, const QString& text);
void setItemVisible(const QString& menuOption, bool visible = true); void setItemVisible(const QString& menuOption, bool visible = true);
bool isItemVisible(const QString& menuOption); bool isItemVisible(const QString& menuOption);
void setItemShortcut(const QString& menuOption, const QString & shortcut); void setItemShortcut(const QString& menuOption, const QString& shortcut);
QString getItemShortcut(const QString& menuOption); QString getItemShortcut(const QString& menuOption);
void setRootMenu(QObject * rootMenu); void setRootMenu(QObject* rootMenu);
private slots: private slots:
void onTriggeredByName(const QString& name); void onTriggeredByName(const QString& name);

View file

@ -47,7 +47,7 @@ import "qml"
//import "/Users/bdavis/Git/hifi/interface/resources/qml" //import "/Users/bdavis/Git/hifi/interface/resources/qml"
Item { Item {
anchors.fill: parent anchors.fill: parent
visible: true visible: true
//title: "Qt Quick Controls Gallery" //title: "Qt Quick Controls Gallery"