show checkbox or radiobutton dependently on exclusiveGroup presence

This commit is contained in:
beholder 2017-08-29 23:23:16 +03:00
parent cbbe03cee7
commit a0a43ebf26
4 changed files with 36 additions and 17 deletions

View file

@ -58,14 +58,12 @@ FocusScope {
function addExclusionGroup(menuItem, exclusionGroup) function addExclusionGroup(menuItem, exclusionGroup)
{ {
console.debug('entering Desktop::addExclusionGroup: menuItem = ', menuItem, 'exclusionGroup = ', exclusionGroup);
exclusionGroupsByMenuItem.append( exclusionGroupsByMenuItem.append(
{ {
'menuItem' : menuItem.toString(), 'menuItem' : menuItem.toString(),
'exclusionGroup' : exclusionGroup.toString() 'exclusionGroup' : exclusionGroup.toString()
} }
); );
console.debug('Desktop::addExclusionGroup: ', exclusionGroup, 'rootMenu: ', this);
} }
} }

View file

@ -26,24 +26,48 @@ Item {
visible: source.visible visible: source.visible
width: parent.width width: parent.width
CheckBox { Item {
id: check id: check
// FIXME: Should use radio buttons if source.exclusiveGroup.
anchors { anchors {
left: parent.left left: parent.left
leftMargin: hifi.dimensions.menuPadding.x + 15 leftMargin: hifi.dimensions.menuPadding.x + 15
verticalCenter: label.verticalCenter verticalCenter: label.verticalCenter
} }
width: 20
visible: source.visible && source.type === 1 && source.checkable width: checkbox.visible ? checkbox.width : radiobutton.width
checked: setChecked() height: checkbox.visible ? checkbox.height : radiobutton.height
function setChecked() {
if (!source || source.type !== 1 || !source.checkable) { CheckBox {
return false; 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;
} }
} }

View file

@ -159,9 +159,6 @@ Item {
property Component exclusiveGroupMaker: Component { property Component exclusiveGroupMaker: Component {
ExclusiveGroup { ExclusiveGroup {
Component.onDestruction: {
console.debug('ExclusionGroup destroyed: ', this)
}
} }
} }

View file

@ -56,7 +56,7 @@ public:
_from->removeEventFilter(this); _from->removeEventFilter(this);
} }
protected: protected:
bool eventFilter(QObject* o, QEvent* e) { virtual bool eventFilter(QObject* o, QEvent* e) override {
if (e->type() == QEvent::DynamicPropertyChange) { if (e->type() == QEvent::DynamicPropertyChange) {
QDynamicPropertyChangeEvent* dpc = static_cast<QDynamicPropertyChangeEvent*>(e); QDynamicPropertyChangeEvent* dpc = static_cast<QDynamicPropertyChangeEvent*>(e);
if (dpc->propertyName() == "exclusionGroup") if (dpc->propertyName() == "exclusionGroup")