KOSMIndoorMap

RoomSearchDialog.qml
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6import QtQuick
7import QtQuick.Controls as QQC2
8import org.kde.kirigami as Kirigami
9import org.kde.kosmindoormap
10
11/** Search dialogs for buildings/rooms. */
12Kirigami.SearchDialog {
13 id: root
14
15 /** Room model instance providing the content for this dialog. */
16 property RoomModel roomModel
17
18 /** Emitted when an entry of this dialog as been selected. */
19 signal roomSelected(room: var)
20
21 width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
22 height: Math.min(applicationWindow().height, Kirigami.Units.gridUnit * 32)
23
24 searchFieldPlaceholderText: i18nd("kosmindoormap", "Search room…")
25 model: RoomSortFilterProxyModel {
26 id: roomSortModel
27 sourceModel: root.visible ? root.roomModel : null
28 filterCaseSensitivity: Qt.CaseInsensitive
29 }
30
31 delegate: QQC2.ItemDelegate {
32 id: item
33 required property string name
34 required property string number
35 required property string typeName
36 required property string levelLongName
37 required property int level
38 required property osmElement element
39
40 width: ListView.view.width
41 contentItem: Kirigami.TitleSubtitle {
42 title: {
43 if (item.name === "")
44 return item.number;
45 if (item.number === "")
46 return item.name;
47 return i18nd("kosmindoormap", "%1 (%2)", item.name, item.number);
48 }
49 subtitle: {
50 if (root.roomModel.buildingCount === 1)
51 return item.typeName;
52 if (item.typeName === "")
53 return item.levelLongName;
54 return i18nd("kosmindoormap", "%1 (%2)", item.typeName, item.levelLongName);
55 }
56 }
57 onClicked: {
58 root.roomSelected({ element: item.element, level: item.level });
59 root.accept();
60 }
61
62 Keys.onPressed: (event) => {
63 if (event.key === Qt.Key_Enter || event.key == Qt.Key_Return) {
64 event.accepted = true;
65 root.roomSelected({ element: item.element, level: item.level });
66 root.accept();
67 }
68 }
69 }
70
71 section.property: root.roomModel.buildingCount !== 1 ? "buildingName" : "levelLongName"
72 section.delegate: Kirigami.ListSectionHeader {
73 text: section
74 width: ListView.view.width
75 }
76
77 onTextChanged: roomSortModel.filterString = root.text
78}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QString typeName(const QJsonObject &obj)
QStringView level(QStringView ifopt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.