Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cura 11003 add searchbar for offlineprinter #18804

Merged
merged 20 commits into from
Apr 17, 2024
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2249e29
Implement printer search feature in local printer selection
saumyaj3 Apr 3, 2024
56d6325
expanding found machines inside sections
saumyaj3 Apr 3, 2024
b810e63
Merge branch 'main' into CURA-11003-add-searchbar-for-offlineprinter
saumyaj3 Apr 3, 2024
4c42ed7
Refactor code in AddLocalPrinterScrollView.qml
saumyaj3 Apr 3, 2024
a6e91fe
Merge branch 'main' into CURA-11003-add-searchbar-for-offlineprinter
saumyaj3 Apr 3, 2024
2ed0377
added column for removing the magic number
saumyaj3 Apr 4, 2024
f35865e
property name hasSearchFilter changed
saumyaj3 Apr 4, 2024
7a6f195
changed filter from "id" to "name" as both are different
saumyaj3 Apr 4, 2024
0049271
Merge branch 'main' into CURA-11003-add-searchbar-for-offlineprinter
saumyaj3 Apr 5, 2024
66754d8
Remove redundant printerSearchTimer
saumyaj3 Apr 5, 2024
7231c27
Refactor textChanged event
saumyaj3 Apr 5, 2024
78b7793
Merge branch 'main' into CURA-11003-add-searchbar-for-offlineprinter
saumyaj3 Apr 8, 2024
d017f0e
increased size of clear icon
saumyaj3 Apr 8, 2024
8f09d35
Merge branch 'main' into CURA-11003-add-searchbar-for-offlineprinter
saumyaj3 Apr 10, 2024
3908db7
Update search bar style and theme alteration
saumyaj3 Apr 10, 2024
1457569
Fix handling of undefined printer items in AddLocalPrinterScrollView
saumyaj3 Apr 10, 2024
a3911bd
PR comments
saumyaj3 Apr 12, 2024
1737206
Update resources/qml/WelcomePages/AddLocalPrinterScrollView.qml
saumyaj3 Apr 12, 2024
fd01684
Update resources/qml/WelcomePages/AddLocalPrinterScrollView.qml
saumyaj3 Apr 12, 2024
597a871
Merge branch 'main' into CURA-11003-add-searchbar-for-offlineprinter
saumyaj3 Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 174 additions & 79 deletions resources/qml/WelcomePages/AddLocalPrinterScrollView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Cura 1.1 as Cura
Item
{
id: base

property bool hasSearchFilter: false
// The currently selected machine item in the local machine list.
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.
Expand Down Expand Up @@ -43,25 +43,22 @@ Item
const item = machineList.model.getItem(i);
if (item.section == section)
{
machineList.currentIndex = i;
updateCurrentItem(i)
break;
}
}
}

function getMachineName()
{
return machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).name : "";
}

function getMachineMetaDataEntry(key)
function updateCurrentItem(index)
{
var metadata = machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).metadata : undefined;
if (metadata)
machineList.currentIndex = index;
currentItem = machineList.model.getItem(index);
if (currentItem != undefined)
{
return metadata[key];
machineName.text = currentItem.name
manufacturer.text = currentItem.metadata["manufacturer"]
author.text = currentItem.metadata["author"]
}
return undefined;
}

Component.onCompleted:
Expand All @@ -78,98 +75,196 @@ Item
id: localPrinterSelectionItem
anchors.fill: parent

//Selecting a local printer to add from this list.
ListView
Column
{
id: machineList
id: root
width: Math.floor(parent.width * 0.48)
height: parent.height
Item
{
width: root.width
height: filter.height
Cura.TextField
{
id: filter
width:parent.width
saumyaj3 marked this conversation as resolved.
Show resolved Hide resolved
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

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")
}

clip: true
ScrollBar.vertical: UM.ScrollBar {}
onTextChanged: editingFinished()
onEditingFinished:
{
machineDefinitionsModel.filter = {"name" : "*" + text.toLowerCase() + "*", "visible": true}
base.hasSearchFilter = (text.length > 0)
updateDefinitionModel()
}

model: UM.DefinitionContainersModel
{
id: machineDefinitionsModel
filter: { "visible": true }
sectionProperty: "manufacturer"
preferredSections: preferredCategories
Keys.onEscapePressed: filter.text = ""
function updateDefinitionModel()
{
if (base.hasSearchFilter)
{
base.currentSections.clear()
for (var i = 0; i < machineDefinitionsModel.count; i++)
{
var sectionexpanded = machineDefinitionsModel.getItem(i)["section"]
if (!base.currentSections.has(sectionexpanded))
{
base.currentSections.add(sectionexpanded);
}
}
base.updateCurrentItem(0)

// Trigger update on base.currentSections
base.currentSections = base.currentSections;
}
else
{
const initialSection = "Ultimaker B.V.";
base.currentSections.clear();
base.currentSections.add(initialSection);
updateCurrentItemUponSectionChange(initialSection);
updateCurrentItem(0)
// Trigger update on base.currentSections
base.currentSections = base.currentSections;
}

}
}

UM.SimpleButton
{
id: clearFilterButton
iconSource: UM.Theme.getIcon("Cancel")
visible: base.hasSearchFilter

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()
}
}
}

section.property: "section"
section.delegate: Button
//Selecting a local printer to add from this list.
ListView
{
id: button
width: machineList.width
height: UM.Theme.getSize("action_button").height
text: section

property bool isActive: base.currentSections.has(section)
id: machineList
width:root.width
saumyaj3 marked this conversation as resolved.
Show resolved Hide resolved
saumyaj3 marked this conversation as resolved.
Show resolved Hide resolved
height: root.height - filter.height
clip: true
ScrollBar.vertical: UM.ScrollBar {}

background: Rectangle
model: UM.DefinitionContainersModel
{
anchors.fill: parent
color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
id: machineDefinitionsModel
filter: { "visible": true }
sectionProperty: "manufacturer"
preferredSections: preferredCategories
}

contentItem: Item
section.property: "section"
section.delegate: Button
{
width: childrenRect.width
id: button
width: machineList.width
height: UM.Theme.getSize("action_button").height
text: section

UM.ColorImage
{
id: arrow
anchors.left: parent.left
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
color: UM.Theme.getColor("text")
source: isActive ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight")
}
property bool isActive: base.currentSections.has(section)

UM.Label
background: Rectangle
{
id: label
anchors.left: arrow.right
anchors.leftMargin: UM.Theme.getSize("default_margin").width
text: button.text
font: UM.Theme.getFont("default_bold")
anchors.fill: parent
color: isActive ? UM.Theme.getColor("setting_control_highlight") : "transparent"
}
}

onClicked:
{
if (base.currentSections.has(section))
contentItem: Item
{
base.currentSections.delete(section);
width: childrenRect.width
height: UM.Theme.getSize("action_button").height

UM.ColorImage
{
id: arrow
anchors.left: parent.left
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
color: UM.Theme.getColor("text")
source: isActive ? UM.Theme.getIcon("ChevronSingleDown") : UM.Theme.getIcon("ChevronSingleRight")
}

UM.Label
{
id: label
anchors.left: arrow.right
anchors.leftMargin: UM.Theme.getSize("default_margin").width
text: button.text
font: UM.Theme.getFont("default_bold")
}
}
else

onClicked:
{
base.currentSections.add(section);
base.updateCurrentItemUponSectionChange(section);
if (base.currentSections.has(section))
{
base.currentSections.delete(section);
}
else
{
base.currentSections.add(section);
base.updateCurrentItemUponSectionChange(section);
}
// Trigger update on base.currentSections
base.currentSections = base.currentSections;
}
// Trigger update on base.currentSections
base.currentSections = base.currentSections;
}
}

delegate: Cura.RadioButton
{
id: radioButton
anchors
delegate: Cura.RadioButton
{
left: parent !== null ? parent.left : undefined
leftMargin: UM.Theme.getSize("standard_list_lineheight").width
id: radioButton
anchors
{
left: parent !== null ? parent.left : undefined
leftMargin: UM.Theme.getSize("standard_list_lineheight").width

right: parent !== null ? parent.right : undefined
rightMargin: UM.Theme.getSize("default_margin").width
}
height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0 //This causes the scrollbar to vary in length due to QTBUG-76830.
right: parent !== null ? parent.right : undefined
rightMargin: UM.Theme.getSize("default_margin").width
}
height: visible ? UM.Theme.getSize("standard_list_lineheight").height : 0 //This causes the scrollbar to vary in length due to QTBUG-76830.

checked: machineList.currentIndex == index
text: name
visible: base.currentSections.has(section)
onClicked: machineList.currentIndex = index
checked: machineList.currentIndex == index
text: name
visible: base.currentSections.has(section)
onClicked: base.updateCurrentItem(index)
}
}
}

Expand All @@ -193,8 +288,8 @@ Item

UM.Label
{
id: machineName
width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
text: base.getMachineName()
color: UM.Theme.getColor("primary_button")
font: UM.Theme.getFont("huge")
elide: Text.ElideRight
Expand All @@ -215,7 +310,7 @@ Item
}
UM.Label
{
text: base.getMachineMetaDataEntry("manufacturer")
id: manufacturer
width: parent.width - manufacturerLabel.width
wrapMode: Text.WordWrap
}
Expand All @@ -226,7 +321,7 @@ Item
}
UM.Label
{
text: base.getMachineMetaDataEntry("author")
id: author
width: parent.width - profileAuthorLabel.width
wrapMode: Text.WordWrap
}
Expand Down
Loading