Skip to content

Commit ca24f70

Browse files
committed
Add search bar to UI
1 parent 458ba6d commit ca24f70

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

CuraOnshapePlugin.pyproject

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"resources/qml/SettingsDialog.qml",
3838
"i18n/onshape.pot",
3939
"i18n/fr_FR/onshape.po",
40-
"resources/qml/DocumentsActions.qml"
40+
"resources/qml/DocumentsActions.qml",
41+
"resources/qml/SearchBar.qml"
4142
]
4243
}

resources/qml/MainDialog.qml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Window
1818
height: 768 * screenScaleFactor
1919
minimumWidth: 800 * screenScaleFactor
2020
minimumHeight: 600 * screenScaleFactor
21+
color: UM.Theme.getColor("main_background")
2122

2223
UM.I18nCatalog{id: catalog; name:"onshape"}
2324

@@ -26,7 +27,6 @@ Window
2627
sequence: "Esc"
2728
onActivated: root.close()
2829
}
29-
color: UM.Theme.getColor("main_background")
3030

3131
ConnectionItem
3232
{
@@ -51,6 +51,11 @@ Window
5151
documentsModel: documentsListStack.currentItem.documentsModel
5252
}
5353

54+
SearchBar
55+
{
56+
Layout.fillWidth: true
57+
}
58+
5459
StackView
5560
{
5661
id: documentsListStack

resources/qml/SearchBar.qml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2025 Erwan MATHIEU
2+
3+
import QtQuick 2.15
4+
import QtQuick.Window 2.2
5+
import QtQuick.Controls 2.3
6+
import QtQuick.Layouts 1.15
7+
8+
import Cura 1.5 as Cura
9+
import UM 1.5 as UM
10+
11+
12+
Item
13+
{
14+
id: root
15+
implicitHeight: filter.implicitHeight + 2 * UM.Theme.getSize("default_margin").width
16+
17+
UM.I18nCatalog{id: catalog; name:"onshape"}
18+
19+
Timer
20+
{
21+
id: settingsSearchTimer
22+
onTriggered: root.doSearch()
23+
interval: 500
24+
running: false
25+
repeat: false
26+
}
27+
28+
Cura.TextField
29+
{
30+
id: filter
31+
implicitWidth: UM.Theme.getSize("print_setup_big_item").width
32+
implicitHeight: UM.Theme.getSize("print_setup_big_item").height
33+
anchors.left: parent.left
34+
anchors.top: parent.top
35+
anchors.margins: UM.Theme.getSize("default_margin").width
36+
leftPadding: searchIcon.width + UM.Theme.getSize("default_margin").width * 2
37+
placeholderText: catalog.i18nc("@textfield:placeholder", "Search")
38+
font: UM.Theme.getFont("default_italic")
39+
40+
UM.ColorImage
41+
{
42+
id: searchIcon
43+
44+
anchors
45+
{
46+
verticalCenter: parent.verticalCenter
47+
left: parent.left
48+
leftMargin: UM.Theme.getSize("default_margin").width
49+
}
50+
source: UM.Theme.getIcon("Magnifier")
51+
height: UM.Theme.getSize("small_button_icon").height
52+
width: height
53+
color: UM.Theme.getColor("text")
54+
}
55+
56+
onTextChanged: settingsSearchTimer.restart()
57+
58+
onEditingFinished: root.doSearch()
59+
60+
Keys.onEscapePressed: filter.text = ""
61+
}
62+
63+
UM.SimpleButton
64+
{
65+
id: clearFilterButton
66+
iconSource: UM.Theme.getIcon("Cancel")
67+
visible: filter.text !== ""
68+
69+
height: Math.round(filter.height * 0.4)
70+
width: height
71+
72+
anchors.verticalCenter: filter.verticalCenter
73+
anchors.right: filter.right
74+
anchors.rightMargin: UM.Theme.getSize("default_margin").width
75+
76+
color: UM.Theme.getColor("setting_control_button")
77+
hoverColor: UM.Theme.getColor("setting_control_button_hover")
78+
79+
onClicked:
80+
{
81+
filter.text = ""
82+
filter.forceActiveFocus()
83+
root.doSearch()
84+
}
85+
}
86+
87+
function doSearch()
88+
{
89+
console.debug("Search " + filter.text)
90+
}
91+
}

0 commit comments

Comments
 (0)