Toggle visibility of filter field when pressing the "search" icon

This commit is contained in:
fieldOfView 2016-11-22 13:44:41 +01:00
parent 7e4f1dce7b
commit 933ed5177f
2 changed files with 25 additions and 7 deletions

View file

@ -18,9 +18,23 @@ Item
signal showTooltip(Item item, point location, string text);
signal hideTooltip();
function toggleFilterField()
{
filterContainer.visible = !filterContainer.visible
if(filterContainer.visible)
{
filter.forceActiveFocus();
}
else
{
filter.text = "";
}
}
Rectangle
{
id: filterContainer
visible: false
border.width: UM.Theme.getSize("default_lining").width
border.color:
@ -45,7 +59,8 @@ Item
right: parent.right
rightMargin: UM.Theme.getSize("default_margin").width
}
height: UM.Theme.getSize("setting_control").height
height: visible ? UM.Theme.getSize("setting_control").height : 0
Behavior on height { NumberAnimation { duration: 100 } }
TextField
{
@ -125,7 +140,7 @@ Item
onClicked:
{
filter.text = "";
filter.setActiveFocus();
filter.forceActiveFocus();
}
}
}
@ -136,7 +151,8 @@ Item
anchors.bottom: parent.bottom;
anchors.right: parent.right;
anchors.left: parent.left;
anchors.topMargin: UM.Theme.getSize("default_margin").width
anchors.topMargin: filterContainer.visible ? UM.Theme.getSize("default_margin").width : 0
Behavior on anchors.topMargin { NumberAnimation { duration: 100 } }
style: UM.Theme.styles.scrollview;
flickableItem.flickableDirection: Flickable.VerticalFlick;

View file

@ -214,7 +214,7 @@ Rectangle
anchors.left: parent.left
anchors.leftMargin: model.index * (settingsModeSelection.width / 2)
anchors.verticalCenter: parent.verticalCenter
width: 0.5 * parent.width - (index == 1 ? toggleFilterButton.width : 0)
width: 0.5 * parent.width - (modesListModel.get(index).showFilterButton ? toggleFilterButton.width : 0)
text: model.text
exclusiveGroup: modeMenuGroup;
checkable: true;
@ -268,9 +268,11 @@ Rectangle
height: settingsModeSelection.height
width: visible ? height : 0
visible: !monitoringPrint && base.currentModeIndex == 1
visible: !monitoringPrint && modesListModel.get(base.currentModeIndex).showFilterButton
opacity: visible ? 1 : 0
onClicked: sidebarContents.currentItem.toggleFilterField()
style: ButtonStyle
{
background: Rectangle
@ -415,8 +417,8 @@ Rectangle
Component.onCompleted:
{
modesListModel.append({ text: catalog.i18nc("@title:tab", "Recommended"), item: sidebarSimple })
modesListModel.append({ text: catalog.i18nc("@title:tab", "Custom"), item: sidebarAdvanced })
modesListModel.append({ text: catalog.i18nc("@title:tab", "Recommended"), item: sidebarSimple, showFilterButton: false })
modesListModel.append({ text: catalog.i18nc("@title:tab", "Custom"), item: sidebarAdvanced, showFilterButton: true })
sidebarContents.push({ "item": modesListModel.get(base.currentModeIndex).item, "immediate": true });
}