Skip to content

Commit

Permalink
chore(CommunityPermissions): Setting icon/default values for 'In' sec…
Browse files Browse the repository at this point in the history
…tion depending on chosen permission
  • Loading branch information
micieslak committed Jan 26, 2023
1 parent ecf999e commit 5c3b988
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
10 changes: 9 additions & 1 deletion ui/StatusQ/src/StatusQ/Components/StatusItemSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ Rectangle {
*/
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
This signal is emitted when the item is clicked.
Expand Down Expand Up @@ -217,7 +224,8 @@ Rectangle {

MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
enabled: root.itemsClickable
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: root.itemClicked(parent, model.index, mouse)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ StatusScrollView {
readonly property int dropdownVerticalOffset: 1

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 QtObject dirtyValues: QtObject {
Expand Down Expand Up @@ -417,6 +434,11 @@ StatusScrollView {
disableAdminPermission: !root.store.isOwner

onDone: {
if (d.permissionType === permissionType) {
permissionsDropdown.close()
return
}

d.permissionType = permissionType
d.dirtyValues.permissionObject.key = permissionType
d.dirtyValues.permissionObject.text = title
Expand Down Expand Up @@ -454,8 +476,13 @@ StatusScrollView {
StatusItemSelector {
id: inSelector

readonly property bool editable: !d.isCommunityPermission

addButton.visible: editable
itemsClickable: editable

Layout.fillWidth: true
icon: Style.svg("create-category")
icon: d.isCommunityPermission ? Style.svg("communities") : Style.svg("create-category")
iconSize: 24
title: qsTr("In")
defaultItemText: qsTr("Example: `#general` channel")
Expand All @@ -464,6 +491,21 @@ StatusScrollView {

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 {
id: inModelCommunity

Expand Down Expand Up @@ -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: {
inDropdown.acceptMode = InDropdown.AcceptMode.Add
openInDropdown(inSelector.addButton,
Expand Down

0 comments on commit 5c3b988

Please sign in to comment.