Skip to content

Commit 088700c

Browse files
authored
Refactor Menu Implementation with QfMenu Component (#6086)
1 parent 77ea525 commit 088700c

14 files changed

+63
-278
lines changed

src/qml/About.qml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,10 @@ Item {
189189
}
190190
}
191191

192-
Menu {
192+
QfMenu {
193193
id: linksMenu
194194
title: qsTr("Links Menu")
195195

196-
width: {
197-
var result = 0;
198-
var padding = 0;
199-
for (var i = 0; i < count; ++i) {
200-
var item = itemAt(i);
201-
result = Math.max(item.contentItem.implicitWidth, result);
202-
padding = Math.max(item.padding, padding);
203-
}
204-
return result + padding * 2;
205-
}
206-
207196
MenuItem {
208197
text: qsTr('Changelog')
209198

src/qml/LayerTreeItemProperties.qml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,10 @@ Popup {
367367
}
368368
}
369369

370-
Menu {
370+
QfMenu {
371371
id: showFeaturesMenu
372372
title: qsTr("Show Features Menu")
373373

374-
width: {
375-
var result = 0;
376-
var padding = 0;
377-
for (var i = 0; i < count; ++i) {
378-
var item = itemAt(i);
379-
result = Math.max(item.contentItem.implicitWidth, result);
380-
padding = Math.max(item.padding, padding);
381-
}
382-
return result + padding * 2;
383-
}
384-
385374
MenuItem {
386375
text: qsTr('Show visible features list')
387376

src/qml/NavigationBar.qml

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,10 @@ Rectangle {
483483
}
484484
}
485485

486-
Menu {
486+
QfMenu {
487487
id: featureListMenu
488488
title: qsTr("Feature List Menu")
489489

490-
width: {
491-
let result = 50;
492-
let padding = 0;
493-
for (let i = 0; i < count; ++i) {
494-
let item = itemAt(i);
495-
result = Math.max(item.contentItem.implicitWidth, result);
496-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
497-
}
498-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
499-
}
500-
501490
topMargin: mainWindow.sceneTopMargin
502491
bottomMargin: mainWindow.sceneBottomMargin
503492

@@ -613,25 +602,13 @@ Rectangle {
613602
}
614603
}
615604

616-
Menu {
605+
QfMenu {
617606
id: featureMenu
618607
title: qsTr("Feature Menu")
619608

620609
topMargin: mainWindow.sceneTopMargin
621610
bottomMargin: mainWindow.sceneBottomMargin
622611

623-
width: {
624-
const toolbarWidth = featureMenuActionsToolbar.childrenRect.width + 4;
625-
let result = 50;
626-
let padding = 0;
627-
for (let i = 1; i < count; ++i) {
628-
let item = itemAt(i);
629-
result = Math.max(item.contentItem.implicitWidth, result);
630-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
631-
}
632-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
633-
}
634-
635612
Row {
636613
id: featureMenuActionsToolbar
637614
leftPadding: 2
@@ -816,7 +793,7 @@ Rectangle {
816793
}
817794
}
818795

819-
Menu {
796+
QfMenu {
820797
id: atlasMenu
821798

822799
property alias printTimer: timer
@@ -826,17 +803,6 @@ Rectangle {
826803

827804
signal enablePrintItem(int rows)
828805

829-
width: {
830-
let result = 50;
831-
let padding = 0;
832-
for (let i = 0; i < count; ++i) {
833-
let item = itemAt(i);
834-
result = Math.max(item.contentItem.implicitWidth, result);
835-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
836-
}
837-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
838-
}
839-
840806
topMargin: mainWindow.sceneTopMargin
841807
bottomMargin: mainWindow.sceneBottomMargin
842808

src/qml/PluginManagerSettings.qml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,10 @@ Popup {
204204
}
205205
}
206206

207-
Menu {
207+
QfMenu {
208208
id: pluginsManagementMenu
209209
title: qsTr('Plugins management menu')
210210

211-
width: {
212-
let result = 50;
213-
let padding = 0;
214-
for (let i = 0; i < count; ++i) {
215-
let item = itemAt(i);
216-
result = Math.max(item.contentItem.implicitWidth, result);
217-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
218-
}
219-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
220-
}
221-
222211
MenuItem {
223212
text: qsTr('Clear remembered permissions')
224213

src/qml/QFieldCamera.qml

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -645,24 +645,13 @@ Popup {
645645
}
646646
}
647647

648-
Menu {
648+
QfMenu {
649649
id: cameraSelectionMenu
650650

651651
topMargin: sceneTopMargin
652652
bottomMargin: sceneBottomMargin
653653
z: 10000 // 1000s are embedded feature forms, use higher value
654654

655-
width: {
656-
let result = 50;
657-
let padding = 0;
658-
for (let i = 0; i < count; ++i) {
659-
let item = itemAt(i);
660-
result = Math.max(item.contentItem.implicitWidth, result);
661-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
662-
}
663-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : 0;
664-
}
665-
666655
Repeater {
667656
model: mediaDevices.videoInputs
668657

@@ -693,24 +682,13 @@ Popup {
693682
}
694683
}
695684

696-
Menu {
685+
QfMenu {
697686
id: resolutionSelectionMenu
698687

699688
topMargin: sceneTopMargin
700689
bottomMargin: sceneBottomMargin
701690
z: 10000 // 1000s are embedded feature forms, use higher value
702691

703-
width: {
704-
let result = 50;
705-
let padding = 0;
706-
for (let i = 0; i < count; ++i) {
707-
let item = itemAt(i);
708-
result = Math.max(item.contentItem.implicitWidth, result);
709-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
710-
}
711-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : 0;
712-
}
713-
714692
function ratioFromResolution(resolution) {
715693
let smallerValue = Math.min(resolution.width, resolution.height);
716694
let gdc = 0;

src/qml/QFieldCloudScreen.qml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ Page {
482482
}
483483
}
484484

485-
Menu {
485+
QfMenu {
486486
id: projectActions
487487

488488
property string projectId: ''
@@ -492,17 +492,6 @@ Page {
492492

493493
title: qsTr('Project Actions')
494494

495-
width: {
496-
let result = 50;
497-
let padding = 0;
498-
for (let i = 0; i < count; ++i) {
499-
let item = itemAt(i);
500-
result = Math.max(item.contentItem.implicitWidth, result);
501-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
502-
}
503-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
504-
}
505-
506495
topMargin: mainWindow.sceneTopMargin
507496
bottomMargin: mainWindow.sceneBottomMargin
508497

src/qml/QFieldLocalDataPickerScreen.qml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ Page {
5353
}
5454
}
5555

56-
function determineMenuWidth(menu) {
57-
let result = 50;
58-
let padding = 0;
59-
for (let i = 0; i < menu.count; ++i) {
60-
let item = menu.itemAt(i);
61-
result = Math.max(item.contentItem.implicitWidth, result);
62-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
63-
}
64-
return mainWindow.width > 0 ? Math.min(result + padding * 2, mainWindow.width - 20) : result + padding;
65-
}
66-
6756
ColumnLayout {
6857
id: files
6958
anchors.fill: parent
@@ -437,7 +426,7 @@ Page {
437426
}
438427
}
439428

440-
Menu {
429+
QfMenu {
441430
id: itemMenu
442431

443432
property int itemMetaType: 0
@@ -448,10 +437,9 @@ Page {
448437

449438
title: qsTr('Item Actions')
450439

451-
width: determineMenuWidth(itemMenu)
452-
453440
topMargin: sceneTopMargin
454441
bottomMargin: sceneBottomMargin
442+
paddingMultiplier: 2
455443

456444
// File items
457445
MenuItem {
@@ -642,15 +630,14 @@ Page {
642630
}
643631
}
644632

645-
Menu {
633+
QfMenu {
646634
id: importMenu
647635

648636
title: qsTr('Import Actions')
649637

650-
width: determineMenuWidth(importMenu)
651-
652638
topMargin: sceneTopMargin
653639
bottomMargin: sceneBottomMargin
640+
paddingMultiplier: 2
654641

655642
MenuItem {
656643
id: importProjectFromFolder
@@ -756,15 +743,14 @@ Page {
756743
}
757744
}
758745

759-
Menu {
746+
QfMenu {
760747
id: projectMenu
761748

762749
title: qsTr('Project Actions')
763750

764-
width: determineMenuWidth(projectMenu)
765-
766751
topMargin: sceneTopMargin
767752
bottomMargin: sceneBottomMargin
753+
paddingMultiplier: 2
768754

769755
MenuItem {
770756
id: updateProjectFromArchive
@@ -821,10 +807,10 @@ Page {
821807
}
822808
}
823809

824-
Menu {
810+
QfMenu {
825811
id: selectionMenu
826812
x: parent.width - width - 8
827-
width: determineMenuWidth(selectionMenu)
813+
paddingMultiplier: 2
828814

829815
MenuItem {
830816
id: uploadToWebdav

src/qml/WelcomeScreen.qml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,25 +685,14 @@ Page {
685685
}
686686
}
687687

688-
Menu {
688+
QfMenu {
689689
id: recentProjectActions
690690

691691
property string recentProjectPath: ''
692692
property int recentProjectType: 0
693693

694694
title: qsTr('Recent Project Actions')
695695

696-
width: {
697-
let result = 50;
698-
let padding = 0;
699-
for (let i = 0; i < count; ++i) {
700-
let item = itemAt(i);
701-
result = Math.max(item.contentItem.implicitWidth, result);
702-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
703-
}
704-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
705-
}
706-
707696
topMargin: mainWindow.sceneTopMargin
708697
bottomMargin: mainWindow.sceneBottomMargin
709698

src/qml/editorwidgets/EditorWidgetBase.qml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import QtQuick
22
import QtQuick.Controls
3+
import Theme
34

45
Item {
56
/**
@@ -10,22 +11,11 @@ Item {
1011
property bool isLoaded: false
1112
property bool hasMenu: false
1213

13-
property Menu menu: Menu {
14+
property Menu menu: QfMenu {
1415
id: itemMenu
1516
title: qsTr("Item Menu")
1617
z: 10000 // 1000s are embedded feature forms, use a higher value to insure feature form popups always show above embedded feature formes
1718

18-
width: {
19-
let result = 50;
20-
let padding = 0;
21-
for (var i = 0; i < count; ++i) {
22-
let item = itemAt(i);
23-
result = Math.max(item.contentItem.implicitWidth, result);
24-
padding = Math.max(item.leftPadding + item.rightPadding, padding);
25-
}
26-
return mainWindow.width > 0 ? Math.min(result + padding, mainWindow.width - 20) : result + padding;
27-
}
28-
2919
topMargin: mainWindow.sceneTopMargin
3020
bottomMargin: mainWindow.sceneBottomMargin
3121
}

0 commit comments

Comments
 (0)