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)
{
console.debug('entering Desktop::addExclusionGroup: menuItem = ', menuItem, 'exclusionGroup = ', exclusionGroup);
exclusionGroupsByMenuItem.append(
{
'menuItem' : menuItem.toString(),
'exclusionGroup' : exclusionGroup.toString()
}
);
console.debug('Desktop::addExclusionGroup: ', exclusionGroup, 'rootMenu: ', this);
}
}

View file

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

View file

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

View file

@ -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<QDynamicPropertyChangeEvent*>(e);
if (dpc->propertyName() == "exclusionGroup")