mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 02:37:49 -06:00
Implement printer search feature in local printer selection
Added a search field in the 'Add Local Printer' section which allows users to search for their desired printer. A timer has been set to trigger the search function as the user types into the search field. A clear button is visible for easy removal of the search text. Adjusted the ListModel.py to correctly emit dataChanged signal when there are changes in the list. CURA-11003
This commit is contained in:
parent
b5f56dfb97
commit
2249e298ca
1 changed files with 95 additions and 3 deletions
|
@ -15,7 +15,7 @@ import Cura 1.1 as Cura
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: base
|
id: base
|
||||||
|
property bool findingPrinter: false
|
||||||
// The currently selected machine item in the local machine list.
|
// The currently selected machine item in the local machine list.
|
||||||
property var currentItem: machineList.currentIndex >= 0 ? machineList.model.getItem(machineList.currentIndex) : null
|
property var currentItem: machineList.currentIndex >= 0 ? machineList.model.getItem(machineList.currentIndex) : null
|
||||||
// The currently active (expanded) section/category, where section/category is the grouping of local machine items.
|
// The currently active (expanded) section/category, where section/category is the grouping of local machine items.
|
||||||
|
@ -63,6 +63,14 @@ Item
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
Timer
|
||||||
|
{
|
||||||
|
id: printerSearchTimer
|
||||||
|
onTriggered: filter.editingFinished()
|
||||||
|
interval: 500
|
||||||
|
running: false
|
||||||
|
repeat: false
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted:
|
Component.onCompleted:
|
||||||
{
|
{
|
||||||
|
@ -73,6 +81,90 @@ Item
|
||||||
base.currentSections = base.currentSections;
|
base.currentSections = base.currentSections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cura.TextField
|
||||||
|
{
|
||||||
|
id: filter
|
||||||
|
width: Math.floor(parent.width * 0.48)
|
||||||
|
implicitHeight: parent.height
|
||||||
|
placeholderText: catalog.i18nc("@label:textbox", "Search Printer")
|
||||||
|
font: UM.Theme.getFont("default_italic")
|
||||||
|
leftPadding: searchIcon.width + UM.Theme.getSize("default_margin").width * 2
|
||||||
|
property var expandedCategories
|
||||||
|
property bool lastFindingPrinters: false
|
||||||
|
|
||||||
|
UM.ColorImage
|
||||||
|
{
|
||||||
|
id: searchIcon
|
||||||
|
source: UM.Theme.getIcon("Magnifier")
|
||||||
|
anchors
|
||||||
|
{
|
||||||
|
verticalCenter: parent.verticalCenter
|
||||||
|
left: parent.left
|
||||||
|
leftMargin: UM.Theme.getSize("default_margin").width
|
||||||
|
}
|
||||||
|
height: UM.Theme.getSize("small_button_icon").height
|
||||||
|
width: height
|
||||||
|
color: UM.Theme.getColor("text")
|
||||||
|
}
|
||||||
|
|
||||||
|
onTextChanged: printerSearchTimer.restart()
|
||||||
|
onEditingFinished:
|
||||||
|
{
|
||||||
|
console.log("here")
|
||||||
|
machineDefinitionsModel.filter = {"id" : "*" + text.toLowerCase() + "*", "visible": true}
|
||||||
|
findingPrinters = (text.length > 0)
|
||||||
|
if (findingPrinters != lastFindingPrinters)
|
||||||
|
{
|
||||||
|
updateDefinitionModel()
|
||||||
|
lastFindingPrinters = findingPrinters
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.onEscapePressed: filter.text = ""
|
||||||
|
function updateDefinitionModel()
|
||||||
|
{
|
||||||
|
if (findingPrinters)
|
||||||
|
{
|
||||||
|
expandedCategories = machineDefinitionsModel.expanded.slice()
|
||||||
|
machineDefinitionsModel.expanded = [""] // keep categories closed while to prevent render while making settings visible one by one
|
||||||
|
machineDefinitionsModel.showAncestors = true
|
||||||
|
machineDefinitionsModel.showAll = true
|
||||||
|
machineDefinitionsModel.expanded = ["*"]
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (expandedCategories)
|
||||||
|
{
|
||||||
|
machineDefinitionsModel.expanded = expandedCategories
|
||||||
|
}
|
||||||
|
machineDefinitionsModel.showAncestors = false
|
||||||
|
machineDefinitionsModel.showAll = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UM.SimpleButton
|
||||||
|
{
|
||||||
|
id: clearFilterButton
|
||||||
|
iconSource: UM.Theme.getIcon("Cancel")
|
||||||
|
visible: findingPrinters
|
||||||
|
|
||||||
|
height: Math.round(filter.height * 0.4)
|
||||||
|
width: visible ? height : 0
|
||||||
|
|
||||||
|
anchors.verticalCenter: filter.verticalCenter
|
||||||
|
anchors.right: filter.right
|
||||||
|
anchors.rightMargin: UM.Theme.getSize("default_margin").width
|
||||||
|
|
||||||
|
color: UM.Theme.getColor("setting_control_button")
|
||||||
|
hoverColor: UM.Theme.getColor("setting_control_button_hover")
|
||||||
|
|
||||||
|
onClicked:
|
||||||
|
{
|
||||||
|
filter.text = ""
|
||||||
|
filter.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Row
|
Row
|
||||||
{
|
{
|
||||||
id: localPrinterSelectionItem
|
id: localPrinterSelectionItem
|
||||||
|
@ -83,8 +175,8 @@ Item
|
||||||
{
|
{
|
||||||
id: machineList
|
id: machineList
|
||||||
width: Math.floor(parent.width * 0.48)
|
width: Math.floor(parent.width * 0.48)
|
||||||
height: parent.height
|
height: parent.height - filter.height
|
||||||
|
y: filter.height
|
||||||
clip: true
|
clip: true
|
||||||
ScrollBar.vertical: UM.ScrollBar {}
|
ScrollBar.vertical: UM.ScrollBar {}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue