Skip to content

Commit 12b6878

Browse files
committed
Search in mixer - code review tweaks
1 parent 395432e commit 12b6878

File tree

11 files changed

+108
-83
lines changed

11 files changed

+108
-83
lines changed

src/framework/ui/qml/Muse/Ui/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ qt_add_qml_module(muse_ui_qml
2626
SOURCES
2727
abstractnavigation.cpp
2828
abstractnavigation.h
29-
filteredflyoutmodel.h
30-
filteredflyoutmodel.cpp
3129
foreign.cpp
3230
foreign.h
3331
graphicstestobject.cpp

src/framework/uicomponents/qml/Muse/UiComponents/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ qt_add_qml_module(muse_uicomponents_qml
4040
dropdownview.h
4141
filepickermodel.cpp
4242
filepickermodel.h
43+
filteredflyoutmodel.cpp
44+
filteredflyoutmodel.h
4345
filtervalue.cpp
4446
filtervalue.h
4547
iconview.cpp

src/framework/ui/qml/Muse/Ui/filteredflyoutmodel.cpp renamed to src/framework/uicomponents/qml/Muse/UiComponents/filteredflyoutmodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "filteredflyoutmodel.h"
2424

25-
using namespace muse::ui;
25+
using namespace muse::uicomponents;
2626

2727
// Recursively traverse a flyout tree, collect all "leaves" (items without a sub item)...
2828
static void flattenTreeModel(const QVariant& treeModel, const QString& categoryTitle, QVariantList& result, QVariant& alwaysAppend)
@@ -43,7 +43,7 @@ static void flattenTreeModel(const QVariant& treeModel, const QString& categoryT
4343
// Found parent - if it's a "filter category" all child leaves under this item
4444
// will prepend the title of this item to their titles...
4545
const bool isFilterCategory = menuItem.value("isFilterCategory").toBool();
46-
const QString newCategoryTitle = isFilterCategory ? title : categoryTitle;
46+
const QString& newCategoryTitle = isFilterCategory ? title : categoryTitle;
4747
flattenTreeModel(subItems, newCategoryTitle, result, alwaysAppend); // Recursive call...
4848
continue;
4949
}
@@ -58,7 +58,7 @@ static void flattenTreeModel(const QVariant& treeModel, const QString& categoryT
5858
continue;
5959
}
6060

61-
QString prefix = categoryTitle.isEmpty() ? muse::qtrc("uicomponents", "Unknown") : categoryTitle;
61+
const QString prefix = categoryTitle.isEmpty() ? muse::qtrc("global", "Unknown") : categoryTitle;
6262
menuItem.insert("title", prefix + " - " + title);
6363

6464
result << menuItem;

src/framework/ui/qml/Muse/Ui/filteredflyoutmodel.h renamed to src/framework/uicomponents/qml/Muse/UiComponents/filteredflyoutmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <QObject>
2626
#include <qqmlintegration.h>
2727

28-
namespace muse::ui {
28+
namespace muse::uicomponents {
2929
class FilteredFlyoutModel : public QObject
3030
{
3131
Q_OBJECT

src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenu.qml

Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ MenuView {
4949

5050
function requestFocus() {
5151
if (root.isSearchable) {
52-
searchField.navigation.requestActive()
52+
searchLoader.requestFocus()
5353
return
5454
}
5555
var focused = prv.focusOnSelected()
@@ -122,14 +122,12 @@ MenuView {
122122

123123
desiredHeight: {
124124
const anchorItemHeight = Boolean(root.anchorItem) ? root.anchorItem.height - padding * 2 : Screen.height
125-
const searchHeight = root.isSearchable ? searchColumn.height : 0
125+
const searchHeight = root.isSearchable ? searchLoader.height : 0
126126
return Math.min(listView.actualHeight + searchHeight, anchorItemHeight)
127127
}
128128

129129
desiredWidth: root.menuMetrics?.itemWidth ?? 0
130130

131-
isSearching: searchField.searchText !== ""
132-
133131
onAboutToClose: function(closeEvent) {
134132
closeSubMenu()
135133
}
@@ -146,22 +144,6 @@ MenuView {
146144

147145
readonly property bool isPlacedAbove: root.popupPosition === PopupPosition.Top
148146

149-
property bool searchNeedsRefocus: false
150-
onIsSubMenuOpenChanged: {
151-
// The following prevents a crash when typing while a submenu is open
152-
if (root.isSubMenuOpen) {
153-
if (searchField.inputField.focus) {
154-
searchField.inputField.focus = false
155-
root.searchNeedsRefocus = true
156-
}
157-
return
158-
}
159-
if (root.searchNeedsRefocus) {
160-
searchField.inputField.focus = true
161-
root.searchNeedsRefocus = false
162-
}
163-
}
164-
165147
contentItem: PopupContent {
166148
id: content
167149

@@ -275,53 +257,87 @@ MenuView {
275257
})
276258
}
277259

278-
Column {
279-
id: searchColumn
260+
Loader {
261+
id: searchLoader
280262

281-
visible: root.isSearchable
263+
active: root.isSearchable
282264

283265
width: parent.width
266+
height: item ? item.implicitHeight : 0
284267

285268
// If the window is placed above then the search goes underneath the list
286-
y: root.isPlacedAbove ? parent.height - searchColumn.height : 0
269+
y: root.isPlacedAbove ? parent.height - searchLoader.height : 0
287270

288-
bottomPadding: root.isPlacedAbove ? root.viewMargins : 0
289-
topPadding: root.isPlacedAbove ? 0 : root.viewMargins
290-
spacing: root.viewMargins
271+
signal requestFocus()
291272

292-
SeparatorLine {
293-
visible: root.isPlacedAbove
273+
sourceComponent: Column {
294274
width: parent.width
295-
}
296275

297-
SearchField {
298-
id: searchField
276+
bottomPadding: root.isPlacedAbove ? root.viewMargins : 0
277+
topPadding: root.isPlacedAbove ? 0 : root.viewMargins
278+
spacing: root.viewMargins
299279

300-
navigation.panel: content.navigationPanel
301-
navigation.row: 0
280+
SeparatorLine {
281+
visible: root.isPlacedAbove
282+
width: parent.width
283+
}
302284

303-
inputField.activeFocusOnPress: true
285+
SearchField {
286+
id: searchField
304287

305-
anchors {
306-
left: parent.left
307-
right: parent.right
288+
navigation.panel: content.navigationPanel
289+
navigation.row: 0
308290

309-
leftMargin: root.viewMargins
310-
rightMargin: root.viewMargins
311-
}
291+
inputField.activeFocusOnPress: true
312292

313-
onSearchTextChanged: {
314-
if (root.isSubMenuOpen) {
315-
// This is a failsafe - see onIsSubmenuOpenChanged...
316-
return
293+
anchors {
294+
left: parent.left
295+
right: parent.right
296+
297+
leftMargin: root.viewMargins
298+
rightMargin: root.viewMargins
299+
}
300+
301+
onSearchTextChanged: {
302+
if (root.isSubMenuOpen) {
303+
// This is a failsafe - see onIsSubmenuOpenChanged...
304+
return
305+
}
306+
root.isSearching = searchField.searchText !== ""
307+
filteredModel.setFilterText(searchField.searchText)
308+
}
309+
310+
property bool searchNeedsRefocus: false
311+
312+
Connections {
313+
target: root
314+
315+
function onIsSubMenuOpenChanged() {
316+
// The following prevents a crash when typing while a submenu is open
317+
if (root.isSubMenuOpen) {
318+
if (searchField.inputField.focus) {
319+
searchField.inputField.focus = false
320+
searchField.searchNeedsRefocus = true
321+
}
322+
return
323+
}
324+
if (searchField.searchNeedsRefocus) {
325+
searchField.inputField.focus = true
326+
searchField.searchNeedsRefocus = false
327+
}
328+
}
329+
}
330+
331+
Connections {
332+
target: searchLoader
333+
function onRequestFocus() { searchField.navigation.requestActive() }
317334
}
318-
filteredModel.setFilterText(searchField.searchText)
319335
}
320-
}
321336

322-
SeparatorLine {
323-
visible: !root.isPlacedAbove
324-
width: parent.width
337+
SeparatorLine {
338+
visible: !root.isPlacedAbove
339+
width: parent.width
340+
}
325341
}
326342
}
327343

@@ -377,14 +393,14 @@ MenuView {
377393
if (!root.isSearchable) {
378394
return parent.top
379395
}
380-
return root.isPlacedAbove ? parent.top : searchColumn.bottom
396+
return root.isPlacedAbove ? parent.top : searchLoader.bottom
381397
}
382398

383399
bottom: {
384400
if (!root.isSearchable) {
385401
return parent.bottom
386402
}
387-
return root.isPlacedAbove ? searchColumn.top : parent.bottom
403+
return root.isPlacedAbove ? searchLoader.top : parent.bottom
388404
}
389405

390406
topMargin: root.viewMargins

src/framework/uicomponents/qml/Muse/UiComponents/menuview.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ using namespace muse::uicomponents;
2929

3030
static const QString MENU_VIEW_CONTENT_OBJECT_NAME("_MenuViewContent");
3131

32+
// Padding so that our menus don't "collide" with the top/bottom of our screen...
33+
static const int TOP_BOTTOM_EDGE_PADDING = 16;
34+
3235
MenuView::MenuView(QQuickItem* parent)
3336
: PopupView(parent)
3437
{
@@ -115,7 +118,7 @@ void MenuView::updateGeometry()
115118
m_globalPos = parentTopLeft;
116119
}
117120

118-
const QRectF paddedAnchorRect = anchorGeometry().adjusted(0, 16, 0, -16);
121+
const QRectF paddedAnchorRect = anchorGeometry().adjusted(0, TOP_BOTTOM_EDGE_PADDING, 0, -TOP_BOTTOM_EDGE_PADDING);
119122
QRectF viewRect = viewGeometry();
120123

121124
//! NOTE: should be after resolving anchor geometry

src/framework/uicomponents/qml/Muse/UiComponents/popupview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PopupView : public WindowView
9393

9494
QQuickItem* anchorItem() const;
9595
void setAnchorItem(QQuickItem* anchorItem);
96-
Q_INVOKABLE QRectF anchorGeometry() const;
96+
QRectF anchorGeometry() const;
9797

9898
PlacementPolicies placementPolicies() const;
9999
void setPlacementPolicies(PlacementPolicies placementPolicies);

src/playback/qml/MuseScore/Playback/abstractaudioresourceitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ bool AbstractAudioResourceItem::isActive() const
6060
QVariantMap AbstractAudioResourceItem::buildMenuItem(const QString& itemId,
6161
const QString& title,
6262
const bool checked,
63-
const bool includeInFilteredLists,
6463
const QVariantList& subItems,
64+
const bool includeInFilteredLists,
6565
const bool isFilterCategory) const
6666
{
6767
QVariantMap result;

src/playback/qml/MuseScore/Playback/abstractaudioresourceitem.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ class AbstractAudioResourceItem : public QObject, public muse::async::Asyncable,
7373
void availableResourceListResolved(const QVariantList& resources);
7474

7575
protected:
76-
QVariantMap buildMenuItem(const QString& itemId, const QString& title, const bool checked, const bool includeInFilteredLists = true,
77-
const QVariantList& subItems = QVariantList(), const bool isFilterCategory = false) const;
76+
QVariantMap buildMenuItem(const QString& itemId, const QString& title, const bool checked,
77+
const QVariantList& subItems = QVariantList(), const bool includeInFilteredLists = true,
78+
const bool isFilterCategory = false) const;
7879

7980
QVariantMap buildSeparator() const;
8081

0 commit comments

Comments
 (0)