From 51b823641502dde57b1495d9225ff0abde14b99b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 25 Oct 2016 17:01:04 +0200 Subject: [PATCH] feat(Menu): add `ActionMenu` --- tests/languages/en.ts | 16 +++++- tests/languages/fr.ts | 16 +++++- tests/resources.qrc | 6 ++- .../Animations/CaterpillarAnimation.qml | 2 +- tests/ui/modules/Common/Menu/ActionMenu.qml | 52 +++++++++++++++++++ tests/ui/modules/Common/{ => Menu}/Menu.qml | 19 ++----- .../ui/modules/Common/Popup/DropDownMenu.qml | 2 +- .../Common/Styles/Menu/ActionMenuStyle.qml | 23 ++++++++ .../Common/Styles/{ => Menu}/MenuStyle.qml | 0 tests/ui/modules/Common/Styles/qmldir | 15 ++++-- tests/ui/modules/Common/qmldir | 3 +- .../ui/modules/Linphone/Call/CallControls.qml | 31 ++++------- 12 files changed, 138 insertions(+), 47 deletions(-) create mode 100644 tests/ui/modules/Common/Menu/ActionMenu.qml rename tests/ui/modules/Common/{ => Menu}/Menu.qml (79%) create mode 100644 tests/ui/modules/Common/Styles/Menu/ActionMenuStyle.qml rename tests/ui/modules/Common/Styles/{ => Menu}/MenuStyle.qml (100%) diff --git a/tests/languages/en.ts b/tests/languages/en.ts index 02b29d811..d605ebc9c 100644 --- a/tests/languages/en.ts +++ b/tests/languages/en.ts @@ -5,11 +5,23 @@ CallControls homeEntry - Home + Home contactsEntry - Contacts + Contacts + + + acceptAudioCall + + + + acceptVideoCall + + + + hangup + End call diff --git a/tests/languages/fr.ts b/tests/languages/fr.ts index 135e5d37d..e251cf9f4 100644 --- a/tests/languages/fr.ts +++ b/tests/languages/fr.ts @@ -5,11 +5,23 @@ CallControls homeEntry - Accueil + Accueil contactsEntry - Contacts + Contacts + + + acceptAudioCall + + + + acceptVideoCall + + + + hangup + Fin d'appel diff --git a/tests/resources.qrc b/tests/resources.qrc index 4fbf73e79..e437e30f6 100644 --- a/tests/resources.qrc +++ b/tests/resources.qrc @@ -49,7 +49,8 @@ ui/modules/Common/Image/Icon.qml ui/modules/Common/Image/RoundedImage.qml ui/modules/Common/InvertedMouseArea.qml - ui/modules/Common/Menu.qml + ui/modules/Common/Menu/ActionMenu.qml + ui/modules/Common/Menu/Menu.qml ui/modules/Common/Paned.qml ui/modules/Common/Popup/AbstractDropDownMenu.qml ui/modules/Common/Popup/DropDownDynamicMenu.qml @@ -71,7 +72,8 @@ ui/modules/Common/Styles/Form/TextButtonAStyle.qml ui/modules/Common/Styles/Form/TextButtonBStyle.qml ui/modules/Common/Styles/Form/TransparentComboBoxStyle.qml - ui/modules/Common/Styles/MenuStyle.qml + ui/modules/Common/Styles/Menu/ActionMenuStyle.qml + ui/modules/Common/Styles/Menu/MenuStyle.qml ui/modules/Common/Styles/PanedStyle.qml ui/modules/Common/Styles/PopupStyle.qml ui/modules/Common/Styles/qmldir diff --git a/tests/ui/modules/Common/Animations/CaterpillarAnimation.qml b/tests/ui/modules/Common/Animations/CaterpillarAnimation.qml index aafca2c5f..8a63e85b8 100644 --- a/tests/ui/modules/Common/Animations/CaterpillarAnimation.qml +++ b/tests/ui/modules/Common/Animations/CaterpillarAnimation.qml @@ -9,9 +9,9 @@ Row { property color sphereColor: CaterpillarAnimationStyle.sphere.color property int animationDuration: CaterpillarAnimationStyle.animation.duration - property int animationSpace: CaterpillarAnimationStyle.animation.space property int nSpheres: CaterpillarAnimationStyle.nSpheres property int sphereSize: CaterpillarAnimationStyle.sphere.size + property int animationSpace: CaterpillarAnimationStyle.animation.space spacing: CaterpillarAnimationStyle.spacing diff --git a/tests/ui/modules/Common/Menu/ActionMenu.qml b/tests/ui/modules/Common/Menu/ActionMenu.qml new file mode 100644 index 000000000..0f1f3a721 --- /dev/null +++ b/tests/ui/modules/Common/Menu/ActionMenu.qml @@ -0,0 +1,52 @@ +import QtQuick 2.7 +import QtQuick.Layouts 1.3 + +import Common.Styles 1.0 + +// =================================================================== +// Basic actions menu. +// =================================================================== + +ColumnLayout { + id: menu + + signal clicked (int entry) + + spacing: ActionMenuStyle.spacing + + property int entryHeight + property int entryWidth + property var entries + + Repeater { + model: entries + + Rectangle { + color: ActionMenuStyle.entry.color + height: menu.entryHeight + width: menu.entryWidth + + Text { + anchors { + left: parent.left + leftMargin: ActionMenuStyle.entry.leftMargin + right: parent.right + rightMargin: ActionMenuStyle.entry.rightMargin + } + + color: ActionMenuStyle.entry.text.color + font.pointSize: ActionMenuStyle.entry.text.fontSize + height: parent.height + text: modelData + verticalAlignment: Text.AlignVCenter + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + + onClicked: menu.clicked(index) + } + } + } +} diff --git a/tests/ui/modules/Common/Menu.qml b/tests/ui/modules/Common/Menu/Menu.qml similarity index 79% rename from tests/ui/modules/Common/Menu.qml rename to tests/ui/modules/Common/Menu/Menu.qml index 4022f113f..6cbb1ff7a 100644 --- a/tests/ui/modules/Common/Menu.qml +++ b/tests/ui/modules/Common/Menu/Menu.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Layouts 1.3 +import Common 1.0 import Common.Styles 1.0 // =================================================================== @@ -14,8 +15,6 @@ ColumnLayout { property int entryWidth property var entries - property int fontSize: MenuStyle.entry.text.fontSize - property int _selectedEntry: 0 signal entrySelected (int entry) @@ -50,23 +49,15 @@ ColumnLayout { spacing: MenuStyle.entry.spacing Icon { - Layout.preferredHeight: modelData.icon - ? (modelData.iconSize != null - ? modelData.iconSize - : MenuStyle.entry.iconSize - ) : 0 - Layout.preferredWidth: modelData.icon - ? (modelData.iconSize != null - ? modelData.iconSize - : MenuStyle.entry.iconSize - ) : 0 - icon: modelData.icon || '' + Layout.preferredHeight: MenuStyle.entry.iconSize + Layout.preferredWidth: MenuStyle.entry.iconSize + icon: modelData.icon } Text { Layout.fillWidth: true color: MenuStyle.entry.text.color - font.pointSize: menu.fontSize + font.pointSize: MenuStyle.entry.text.fontSize height: parent.height text: modelData.entryName verticalAlignment: Text.AlignVCenter diff --git a/tests/ui/modules/Common/Popup/DropDownMenu.qml b/tests/ui/modules/Common/Popup/DropDownMenu.qml index 7bc57f005..d059c2722 100644 --- a/tests/ui/modules/Common/Popup/DropDownMenu.qml +++ b/tests/ui/modules/Common/Popup/DropDownMenu.qml @@ -1,5 +1,5 @@ AbstractDropDownMenu { function _computeHeight () { - return content.height + return _content[0].height } } diff --git a/tests/ui/modules/Common/Styles/Menu/ActionMenuStyle.qml b/tests/ui/modules/Common/Styles/Menu/ActionMenuStyle.qml new file mode 100644 index 000000000..0b7c3c38d --- /dev/null +++ b/tests/ui/modules/Common/Styles/Menu/ActionMenuStyle.qml @@ -0,0 +1,23 @@ +pragma Singleton +import QtQuick 2.7 + +import Common 1.0 + +// =================================================================== + +QtObject { + property int spacing: 1 + + property QtObject entry: QtObject { + property int leftMargin: 4 + property int rightMargin: 4 + + property color color: Colors.i + + property QtObject text: QtObject { + property color color: Colors.k + + property int fontSize: 8 + } + } +} diff --git a/tests/ui/modules/Common/Styles/MenuStyle.qml b/tests/ui/modules/Common/Styles/Menu/MenuStyle.qml similarity index 100% rename from tests/ui/modules/Common/Styles/MenuStyle.qml rename to tests/ui/modules/Common/Styles/Menu/MenuStyle.qml diff --git a/tests/ui/modules/Common/Styles/qmldir b/tests/ui/modules/Common/Styles/qmldir index 1ec0f21be..6ffce45fb 100644 --- a/tests/ui/modules/Common/Styles/qmldir +++ b/tests/ui/modules/Common/Styles/qmldir @@ -6,14 +6,12 @@ module Common.Styles singleton CaterpillarAnimationStyle 1.0 Animations/CaterpillarAnimationStyle.qml singleton CollapseStyle 1.0 CollapseStyle.qml + singleton DialogStyle 1.0 DialogStyle.qml + singleton DroppableTextAreaStyle 1.0 DroppableTextAreaStyle.qml singleton ForceScrollBarStyle 1.0 ForceScrollBarStyle.qml -singleton MenuStyle 1.0 MenuStyle.qml -singleton PanedStyle 1.0 PanedStyle.qml -singleton PopupStyle 1.0 PopupStyle.qml -singleton SearchBoxStyle 1.0 SearchBoxStyle.qml singleton AbstractTextButtonStyle 1.0 Form/AbstractTextButtonStyle.qml singleton ActionBarStyle 1.0 Form/ActionBarStyle.qml @@ -24,3 +22,12 @@ singleton SmallButtonStyle 1.0 Form/SmallButtonStyle.qml singleton TextButtonAStyle 1.0 Form/TextButtonAStyle.qml singleton TextButtonBStyle 1.0 Form/TextButtonBStyle.qml singleton TransparentComboBoxStyle 1.0 Form/TransparentComboBoxStyle.qml + +singleton ActionMenuStyle 1.0 Menu/ActionMenuStyle.qml +singleton MenuStyle 1.0 Menu/MenuStyle.qml + +singleton PanedStyle 1.0 PanedStyle.qml + +singleton PopupStyle 1.0 PopupStyle.qml + +singleton SearchBoxStyle 1.0 SearchBoxStyle.qml diff --git a/tests/ui/modules/Common/qmldir b/tests/ui/modules/Common/qmldir index 1749fe81e..13f6e1eb1 100644 --- a/tests/ui/modules/Common/qmldir +++ b/tests/ui/modules/Common/qmldir @@ -49,7 +49,8 @@ RoundedImage 1.0 Image/RoundedImage.qml InvertedMouseArea 1.0 InvertedMouseArea.qml # Menu -Menu 1.0 Menu.qml +ActionMenu 1.0 Menu/ActionMenu.qml +Menu 1.0 Menu/Menu.qml # Paned Paned 1.0 Paned.qml diff --git a/tests/ui/modules/Linphone/Call/CallControls.qml b/tests/ui/modules/Linphone/Call/CallControls.qml index 0ef35568a..16cbc0e28 100644 --- a/tests/ui/modules/Linphone/Call/CallControls.qml +++ b/tests/ui/modules/Linphone/Call/CallControls.qml @@ -52,32 +52,23 @@ RowLayout { DropDownMenu { id: menu - implicitHeight: toto.height launcher: button relativeTo: button relativeX: button.width + 1 - width: 120 + implicitWidth: actionMenu.width + + ActionMenu { + id: actionMenu - Menu { - id: toto entryHeight: 22 - entryWidth: 98 - fontSize: 11 - entries: [{ - entryName: qsTr('homeEntry') - }, { - entryName: qsTr('contactsEntry') - }] + entryWidth: 120 + entries: [ + qsTr('acceptAudioCall'), + qsTr('acceptVideoCall'), + qsTr('hangup') + ] - onEntrySelected: { - console.log('entry', entry) - - if (entry === 0) { - setView('Home') - } else if (entry === 1) { - setView('Contacts') - } - } + onClicked: console.log('entry', entry) } } }