chore(CommunityPermissions): Setting icon/default values for 'In' section depending on chosen permission

This commit is contained in:
Michał Cieślak 2023-01-20 12:15:05 +01:00 committed by Michał
parent ecf999eb37
commit 5c3b9881c5
2 changed files with 52 additions and 17 deletions

View File

@ -117,6 +117,13 @@ Rectangle {
*/ */
property bool useLetterIdenticons: false property bool useLetterIdenticons: false
/*!
\qmlproperty bool StatusItemSelector::itemsClickable
This property determines if items in the selector are clickable (cursor
is changed on hover and itemClicked emitted when clicked)
*/
property bool itemsClickable: true
/*! /*!
\qmlsignal StatusItemSelector::itemClicked \qmlsignal StatusItemSelector::itemClicked
This signal is emitted when the item is clicked. This signal is emitted when the item is clicked.
@ -217,7 +224,8 @@ Rectangle {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.PointingHandCursor enabled: root.itemsClickable
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: root.itemClicked(parent, model.index, mouse) onClicked: root.itemClicked(parent, model.index, mouse)
} }

View File

@ -76,6 +76,23 @@ StatusScrollView {
readonly property int dropdownVerticalOffset: 1 readonly property int dropdownVerticalOffset: 1
property int permissionType: PermissionTypes.Type.None property int permissionType: PermissionTypes.Type.None
readonly property bool isCommunityPermission:
permissionType === PermissionTypes.Type.Admin ||
permissionType === PermissionTypes.Type.Member
onIsCommunityPermissionChanged: {
if (isCommunityPermission) {
inModelChannels.clear()
inSelector.wholeCommunitySelected = true
inSelector.itemsModel = inModelCommunity
} else {
inSelector.itemsModel = 0
inSelector.wholeCommunitySelected = false
inSelector.itemsModel = inModelChannels
}
}
property bool triggerDirtyTool: false // Trick: Used to force the reevaluation of dirty when an item of the list is updated property bool triggerDirtyTool: false // Trick: Used to force the reevaluation of dirty when an item of the list is updated
property QtObject dirtyValues: QtObject { property QtObject dirtyValues: QtObject {
@ -417,6 +434,11 @@ StatusScrollView {
disableAdminPermission: !root.store.isOwner disableAdminPermission: !root.store.isOwner
onDone: { onDone: {
if (d.permissionType === permissionType) {
permissionsDropdown.close()
return
}
d.permissionType = permissionType d.permissionType = permissionType
d.dirtyValues.permissionObject.key = permissionType d.dirtyValues.permissionObject.key = permissionType
d.dirtyValues.permissionObject.text = title d.dirtyValues.permissionObject.text = title
@ -454,8 +476,13 @@ StatusScrollView {
StatusItemSelector { StatusItemSelector {
id: inSelector id: inSelector
readonly property bool editable: !d.isCommunityPermission
addButton.visible: editable
itemsClickable: editable
Layout.fillWidth: true Layout.fillWidth: true
icon: Style.svg("create-category") icon: d.isCommunityPermission ? Style.svg("communities") : Style.svg("create-category")
iconSize: 24 iconSize: 24
title: qsTr("In") title: qsTr("In")
defaultItemText: qsTr("Example: `#general` channel") defaultItemText: qsTr("Example: `#general` channel")
@ -464,6 +491,21 @@ StatusScrollView {
property bool wholeCommunitySelected: false property bool wholeCommunitySelected: false
function openInDropdown(parent, x, y) {
inDropdown.parent = parent
inDropdown.x = x
inDropdown.y = y
const selectedChannels = []
if (!inSelector.wholeCommunitySelected)
for (let i = 0; i < inModelChannels.count; i++)
selectedChannels.push(inModelChannels.get(i).itemId)
inDropdown.setSelectedChannels(selectedChannels)
inDropdown.open()
}
ListModel { ListModel {
id: inModelCommunity id: inModelCommunity
@ -522,21 +564,6 @@ StatusScrollView {
} }
} }
function openInDropdown(parent, x, y) {
inDropdown.parent = parent
inDropdown.x = x
inDropdown.y = y
const selectedChannels = []
if (!inSelector.wholeCommunitySelected)
for (let i = 0; i < inModelChannels.count; i++)
selectedChannels.push(inModelChannels.get(i).itemId)
inDropdown.setSelectedChannels(selectedChannels)
inDropdown.open()
}
addButton.onClicked: { addButton.onClicked: {
inDropdown.acceptMode = InDropdown.AcceptMode.Add inDropdown.acceptMode = InDropdown.AcceptMode.Add
openInDropdown(inSelector.addButton, openInDropdown(inSelector.addButton,