From a0a43ebf263e2fcb5c74c6a83258fc0105a4516f Mon Sep 17 00:00:00 2001 From: beholder Date: Tue, 29 Aug 2017 23:23:16 +0300 Subject: [PATCH] show checkbox or radiobutton dependently on exclusiveGroup presence --- interface/resources/qml/desktop/Desktop.qml | 2 - .../qml/hifi/tablet/TabletMenuItem.qml | 46 ++++++++++++++----- .../qml/hifi/tablet/TabletMenuStack.qml | 3 -- libraries/ui/src/VrMenu.cpp | 2 +- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index ec0bb7245b..579b4e7fd6 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -58,14 +58,12 @@ FocusScope { function addExclusionGroup(menuItem, exclusionGroup) { - console.debug('entering Desktop::addExclusionGroup: menuItem = ', menuItem, 'exclusionGroup = ', exclusionGroup); exclusionGroupsByMenuItem.append( { 'menuItem' : menuItem.toString(), 'exclusionGroup' : exclusionGroup.toString() } ); - console.debug('Desktop::addExclusionGroup: ', exclusionGroup, 'rootMenu: ', this); } } diff --git a/interface/resources/qml/hifi/tablet/TabletMenuItem.qml b/interface/resources/qml/hifi/tablet/TabletMenuItem.qml index 25f672e7a9..71e59e0d01 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenuItem.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenuItem.qml @@ -26,24 +26,48 @@ Item { visible: source.visible width: parent.width - CheckBox { + Item { id: check - // FIXME: Should use radio buttons if source.exclusiveGroup. + anchors { left: parent.left leftMargin: hifi.dimensions.menuPadding.x + 15 verticalCenter: label.verticalCenter } - width: 20 - visible: source.visible && source.type === 1 && source.checkable - checked: setChecked() - function setChecked() { - if (!source || source.type !== 1 || !source.checkable) { - return false; + + width: checkbox.visible ? checkbox.width : radiobutton.width + height: checkbox.visible ? checkbox.height : radiobutton.height + + CheckBox { + id: checkbox + // FIXME: Should use radio buttons if source.exclusiveGroup. + width: 20 + visible: source.visible && source.type === 1 && source.checkable && !source.exclusiveGroup + checked: setChecked() + function setChecked() { + if (!source || source.type !== 1 || !source.checkable) { + return false; + } + // FIXME this works for native QML menus but I don't think it will + // for proxied QML menus + return source.checked; + } + } + + RadioButton { + id: radiobutton + // FIXME: Should use radio buttons if source.exclusiveGroup. + width: 20 + visible: source.visible && source.type === 1 && source.checkable && source.exclusiveGroup + checked: setChecked() + function setChecked() { + if (!source || source.type !== 1 || !source.checkable) { + return false; + } + // FIXME this works for native QML menus but I don't think it will + // for proxied QML menus + return source.checked; } - // FIXME this works for native QML menus but I don't think it will - // for proxied QML menus - return source.checked; } } diff --git a/interface/resources/qml/hifi/tablet/TabletMenuStack.qml b/interface/resources/qml/hifi/tablet/TabletMenuStack.qml index c088088a1c..e7eefbc5e7 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenuStack.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenuStack.qml @@ -159,9 +159,6 @@ Item { property Component exclusiveGroupMaker: Component { ExclusiveGroup { - Component.onDestruction: { - console.debug('ExclusionGroup destroyed: ', this) - } } } diff --git a/libraries/ui/src/VrMenu.cpp b/libraries/ui/src/VrMenu.cpp index b81f259b66..70daff944a 100644 --- a/libraries/ui/src/VrMenu.cpp +++ b/libraries/ui/src/VrMenu.cpp @@ -56,7 +56,7 @@ public: _from->removeEventFilter(this); } protected: - bool eventFilter(QObject* o, QEvent* e) { + virtual bool eventFilter(QObject* o, QEvent* e) override { if (e->type() == QEvent::DynamicPropertyChange) { QDynamicPropertyChangeEvent* dpc = static_cast(e); if (dpc->propertyName() == "exclusionGroup")