feat(StatusNavBarTabButton): introduce `popupMenu` property

This enables users to apply a `StatusPopupMenu` to the button which automatically
positions itself and takes care of highlighting the activated button.

Usage:

```qml
StatusNavBarTabButton {
    ...
    popupMenu: StatusPopupMenu {

        StatusMenuItem {
            text: qsTr("Invite People")
            icon.name: "share-ios"
        }

        StatusMenuItem {
            text: qsTr("View Community")
            icon.name: "group"
        }

        StatusMenuItem {
            text: qsTr("Edit Community")
            icon.name: "edit"
        }
    }
}
```

Closes #137
This commit is contained in:
Pascal Precht 2021-06-11 13:08:12 +02:00 committed by Michał Cieślak
parent b81f0ecd41
commit 666908d93a
3 changed files with 66 additions and 4 deletions

View File

@ -57,6 +57,8 @@ Rectangle {
appNavBar: StatusAppNavBar { appNavBar: StatusAppNavBar {
id: navBar
navBarChatButton: StatusNavBarTabButton { navBarChatButton: StatusNavBarTabButton {
icon.name: "chat" icon.name: "chat"
tooltip.text: "Chat" tooltip.text: "Chat"
@ -74,6 +76,7 @@ Rectangle {
} }
navBarCommunityTabButtons.delegate: StatusNavBarTabButton { navBarCommunityTabButtons.delegate: StatusNavBarTabButton {
id: communityBtn
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
name: model.name name: model.name
tooltip.text: model.tooltipText tooltip.text: model.tooltipText
@ -83,6 +86,35 @@ Rectangle {
onClicked: { onClicked: {
appView.sourceComponent = statusAppCommunityView appView.sourceComponent = statusAppCommunityView
} }
popupMenu: StatusPopupMenu {
StatusMenuItem {
text: qsTr("Invite People")
icon.name: "share-ios"
}
StatusMenuItem {
text: qsTr("View Community")
icon.name: "group"
}
StatusMenuItem {
text: qsTr("Edit Community")
icon.name: "edit"
}
StatusMenuSeparator {}
StatusMenuItem {
text: qsTr("Leave Community")
icon.name: "arrow-right"
icon.width: 14
iconRotation: 180
type: StatusMenuItem.Type.Danger
}
}
} }
navBarTabButtons: [ navBarTabButtons: [

View File

@ -9,6 +9,7 @@ TabButton {
id: statusIconTabButton id: statusIconTabButton
property string name: "" property string name: ""
property bool highlighted: false
implicitWidth: 40 implicitWidth: 40
implicitHeight: 40 implicitHeight: 40
@ -34,7 +35,7 @@ TabButton {
icon: statusIconTabButton.icon.name icon: statusIconTabButton.icon.name
height: statusIconTabButton.icon.height height: statusIconTabButton.icon.height
width: statusIconTabButton.icon.width width: statusIconTabButton.icon.width
color: (statusIconTabButton.hovered || statusIconTabButton.checked) ? Theme.palette.primaryColor1 : statusIconTabButton.icon.color color: (statusIconTabButton.hovered || highlighted || statusIconTabButton.checked) ? Theme.palette.primaryColor1 : statusIconTabButton.icon.color
} }
} }
@ -67,13 +68,13 @@ TabButton {
height: 26 height: 26
letterSize: 15 letterSize: 15
name: statusIconTabButton.name name: statusIconTabButton.name
color: (statusIconTabButton.hovered || statusIconTabButton.checked) ? Theme.palette.primaryColor1 : statusIconTabButton.icon.color color: (statusIconTabButton.hovered || highlighted || statusIconTabButton.checked) ? Theme.palette.primaryColor1 : statusIconTabButton.icon.color
} }
} }
} }
background: Rectangle { background: Rectangle {
color: hovered || ((!!icon.source.toString() || !!name) && checked) ? Theme.palette.primaryColor3 : "transparent" color: hovered || highlighted || ((!!icon.source.toString() || !!name) && checked) ? Theme.palette.primaryColor3 : "transparent"
border.color: Theme.palette.primaryColor1 border.color: Theme.palette.primaryColor1
border.width: (!!icon.source.toString() || !!name) && checked ? 1 : 0 border.width: (!!icon.source.toString() || !!name) && checked ? 1 : 0
radius: statusIconTabButton.width / 2 radius: statusIconTabButton.width / 2

View File

@ -1,13 +1,22 @@
import QtQuick 2.13 import QtQuick 2.13
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
StatusIconTabButton { StatusIconTabButton {
id: statusNavBarTabButton id: statusNavBarTabButton
property alias badge: statusBadge property alias badge: statusBadge
property alias tooltip: statusTooltip property alias tooltip: statusTooltip
property Component popupMenu
signal clicked(var mouse) signal clicked(var mouse)
onPopupMenuChanged: {
if (!!popupMenu) {
popupMenuSlot.sourceComponent = popupMenu
}
}
StatusToolTip { StatusToolTip {
id: statusTooltip id: statusTooltip
visible: statusNavBarTabButton.hovered && !!statusTooltip.text visible: statusNavBarTabButton.hovered && !!statusTooltip.text
@ -38,7 +47,27 @@ StatusIconTabButton {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: statusNavBarTabButton.clicked(mouse) onClicked: {
if (mouse.button === Qt.RightButton) {
if (popupMenuSlot.active) {
statusNavBarTabButton.highlighted = true
let btnWidth = statusNavBarTabButton.width
popupMenuSlot.item.popup(parent.x + btnWidth + 4, parent.y - 2)
}
return
}
statusNavBarTabButton.clicked(mouse)
}
}
Loader {
id: popupMenuSlot
active: !!statusNavBarTabButton.popupMenu
onLoaded: {
popupMenuSlot.item.closeHandler = function () {
statusNavBarTabButton.highlighted = false
}
}
} }
} }