2022-12-20 00:19:46 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
StatusDropdown {
|
|
|
|
id: root
|
|
|
|
|
2023-01-20 11:08:20 +00:00
|
|
|
property bool allowChoosingEntireCommunity: false
|
|
|
|
property bool showAddChannelButton: false
|
|
|
|
|
2022-12-20 00:19:46 +00:00
|
|
|
property string communityName
|
|
|
|
property string communityImage
|
|
|
|
property color communityColor
|
|
|
|
|
|
|
|
property var model
|
|
|
|
|
|
|
|
property int acceptMode: InDropdown.AcceptMode.Add
|
|
|
|
|
|
|
|
enum AcceptMode {
|
|
|
|
Add, Update
|
|
|
|
}
|
|
|
|
|
|
|
|
width: 289
|
|
|
|
padding: 8
|
|
|
|
|
|
|
|
// force keeping within the bounds of the enclosing window
|
|
|
|
margins: 0
|
|
|
|
|
|
|
|
signal addChannelClicked
|
|
|
|
signal communitySelected
|
|
|
|
signal channelsSelected(var channels)
|
|
|
|
|
|
|
|
function setSelectedChannels(channels) {
|
|
|
|
d.setSelectedChannels(channels)
|
|
|
|
}
|
|
|
|
|
|
|
|
onAboutToHide: searcher.text = ""
|
|
|
|
onAboutToShow: scrollView.Layout.preferredHeight = Math.min(
|
|
|
|
scrollView.implicitHeight, 420)
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2023-02-10 14:46:18 +00:00
|
|
|
readonly property int defaultVMargin: 9
|
|
|
|
readonly property int maxHeightCountNo: 5
|
|
|
|
readonly property int itemStandardHeight: 44
|
2022-12-20 00:19:46 +00:00
|
|
|
readonly property var selectedChannels: new Map()
|
|
|
|
|
|
|
|
signal setSelectedChannels(var channels)
|
|
|
|
|
|
|
|
function search(text, searcherText) {
|
|
|
|
return text.toLowerCase().includes(searcherText.toLowerCase())
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolveEmoji(emoji) {
|
|
|
|
return !!emoji ? emoji : ""
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolveColor(color, colorId) {
|
|
|
|
return !!color ? color : Theme.palette.userCustomizationColors[colorId]
|
|
|
|
}
|
|
|
|
|
|
|
|
function addToSelectedChannels(model) {
|
|
|
|
selectedChannels.set(model.itemId, {
|
|
|
|
itemId: model.itemId,
|
|
|
|
name: model.name,
|
|
|
|
color: d.resolveColor(model.color, model.colorId),
|
|
|
|
emoji: d.resolveEmoji(model.emoji)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeFromSelectedChannels(model) {
|
|
|
|
selectedChannels.delete(model.itemId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-10 14:46:18 +00:00
|
|
|
contentItem: ColumnLayout {
|
2022-12-20 00:19:46 +00:00
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
SearchBox {
|
|
|
|
id: searcher
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
minimumHeight: 36
|
|
|
|
maximumHeight: 36
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusListItem {
|
|
|
|
Layout.fillWidth: true
|
2023-02-10 14:46:18 +00:00
|
|
|
Layout.topMargin: d.defaultVMargin
|
|
|
|
Layout.preferredHeight: d.itemStandardHeight
|
2022-12-20 00:19:46 +00:00
|
|
|
|
2023-01-20 11:08:20 +00:00
|
|
|
visible: root.allowChoosingEntireCommunity
|
2022-12-20 00:19:46 +00:00
|
|
|
title: root.communityName
|
|
|
|
subTitle: qsTr("Community")
|
|
|
|
|
|
|
|
asset.name: root.communityImage
|
|
|
|
asset.color: root.communityColor
|
|
|
|
asset.isImage: true
|
|
|
|
asset.width: 32
|
|
|
|
asset.height: 32
|
|
|
|
asset.isLetterIdenticon: !asset.name
|
|
|
|
asset.charactersLen: 2
|
|
|
|
asset.letterSize: 15
|
|
|
|
|
|
|
|
leftPadding: 8
|
|
|
|
rightPadding: 6
|
|
|
|
|
|
|
|
statusListItemTitleArea.anchors.leftMargin: 8
|
|
|
|
statusListItemTitle.font.pixelSize: 13
|
|
|
|
statusListItemTitle.font.weight: Font.Medium
|
|
|
|
|
|
|
|
statusListItemSubTitle.font.pixelSize: 12
|
|
|
|
|
|
|
|
components: [
|
|
|
|
StatusRadioButton {
|
|
|
|
id: radioButton
|
|
|
|
|
|
|
|
size: StatusRadioButton.Size.Small
|
|
|
|
rightPadding: 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// using MouseArea instead of build-in 'clicked' signal to avoid
|
|
|
|
// intercepting event by the StatusRadioButton
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
radioButton.toggle()
|
|
|
|
radioButton.toggled()
|
|
|
|
}
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusMenuSeparator {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: 4 - implicitHeight / 2
|
|
|
|
Layout.bottomMargin: 4 - implicitHeight / 2
|
2023-01-20 11:08:20 +00:00
|
|
|
|
|
|
|
visible: root.allowChoosingEntireCommunity
|
2022-12-20 00:19:46 +00:00
|
|
|
}
|
|
|
|
StatusScrollView {
|
|
|
|
id: scrollView
|
|
|
|
Layout.fillWidth: true
|
2023-02-10 14:46:18 +00:00
|
|
|
Layout.minimumHeight: Math.min(d.maxHeightCountNo, topRepeater.count) * d.itemStandardHeight
|
|
|
|
Layout.maximumHeight: Layout.minimumHeight
|
|
|
|
contentHeight: scrollableColumn.implicitHeight
|
|
|
|
Layout.bottomMargin: d.defaultVMargin
|
2023-01-20 11:08:20 +00:00
|
|
|
Layout.topMargin:
|
2023-02-10 14:46:18 +00:00
|
|
|
!root.allowChoosingEntireCommunity && !root.allowChoosingEntireCommunity ? d.defaultVMargin : 0
|
2022-12-20 00:19:46 +00:00
|
|
|
|
|
|
|
padding: 0
|
|
|
|
|
|
|
|
ColumnLayout {
|
2023-02-10 14:46:18 +00:00
|
|
|
id: scrollableColumn
|
2022-12-20 00:19:46 +00:00
|
|
|
width: scrollView.width
|
2023-02-10 14:46:18 +00:00
|
|
|
spacing: 0
|
2022-12-20 00:19:46 +00:00
|
|
|
|
|
|
|
StatusIconTextButton {
|
|
|
|
Layout.preferredHeight: 36
|
2023-01-20 11:08:20 +00:00
|
|
|
visible: root.showAddChannelButton
|
2022-12-20 00:19:46 +00:00
|
|
|
leftPadding: 8
|
|
|
|
spacing: 8
|
|
|
|
statusIcon: "add"
|
|
|
|
icon.width: 16
|
|
|
|
icon.height: 16
|
|
|
|
iconRotation: 0
|
|
|
|
text: qsTr("Add channel")
|
|
|
|
onClicked: root.addChannelClicked()
|
|
|
|
}
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: topRepeater
|
|
|
|
model: SortFilterProxyModel {
|
|
|
|
id: topLevelModel
|
|
|
|
|
|
|
|
sourceModel: root.model
|
|
|
|
|
2023-02-27 11:38:05 +00:00
|
|
|
filters: AnyOf {
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "categoryId"
|
|
|
|
value: ""
|
|
|
|
}
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "isCategory"
|
|
|
|
value: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 00:19:46 +00:00
|
|
|
sorters: [
|
2023-02-27 11:38:05 +00:00
|
|
|
RoleSorter {
|
|
|
|
roleName: "categoryPosition"
|
|
|
|
priority: 2 // Higher number === higher priority
|
|
|
|
},
|
|
|
|
RoleSorter {
|
|
|
|
roleName: "position"
|
|
|
|
priority: 1
|
|
|
|
}
|
2022-12-20 00:19:46 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: column
|
2023-02-27 11:38:05 +00:00
|
|
|
|
2022-12-20 00:19:46 +00:00
|
|
|
readonly property var topModel: model
|
|
|
|
readonly property alias checkBox: loader.item
|
|
|
|
property int checkedCount: 0
|
|
|
|
|
2023-02-27 11:38:05 +00:00
|
|
|
readonly property bool isCategory: model.isCategory
|
|
|
|
readonly property string categoryId: model.categoryId
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
spacing: 0
|
|
|
|
|
2022-12-20 00:19:46 +00:00
|
|
|
visible: {
|
2023-02-27 11:38:05 +00:00
|
|
|
if (!isCategory)
|
2022-12-20 00:19:46 +00:00
|
|
|
return d.search(model.name, searcher.text)
|
|
|
|
|| checkBox.checked
|
|
|
|
|
|
|
|
if (checkedCount > 0)
|
|
|
|
return true
|
|
|
|
|
|
|
|
const subItemsCount = subItemsRepeater.count
|
|
|
|
|
|
|
|
for (let i = 0; i < subItemsCount; i++)
|
|
|
|
if (subItemsRepeater.itemAt(i).show)
|
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: loader
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2023-02-10 14:46:18 +00:00
|
|
|
Layout.preferredHeight: d.itemStandardHeight
|
2023-02-27 11:38:05 +00:00
|
|
|
Layout.topMargin: isCategory ? d.defaultVMargin : 0
|
|
|
|
sourceComponent: isCategory
|
2022-12-20 00:19:46 +00:00
|
|
|
? communityCategoryDelegate
|
|
|
|
: communityDelegate
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: radioButton
|
|
|
|
|
|
|
|
function onToggled() {
|
|
|
|
const checkBox = loader.item.checkBox
|
|
|
|
checkBox.checked = false
|
|
|
|
checkBox.onToggled()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: communityDelegate
|
|
|
|
|
|
|
|
CommunityListItem {
|
|
|
|
id: communityItem
|
|
|
|
|
|
|
|
title: "#" + model.name
|
|
|
|
|
2023-02-27 11:38:05 +00:00
|
|
|
asset.name: model.icon ?? ""
|
2022-12-20 00:19:46 +00:00
|
|
|
asset.emoji: d.resolveEmoji(model.emoji)
|
|
|
|
asset.color: d.resolveColor(model.color,
|
|
|
|
model.colorId)
|
|
|
|
|
|
|
|
checkBox.onToggled: {
|
|
|
|
if (checked)
|
|
|
|
radioButton.checked = false
|
|
|
|
}
|
|
|
|
|
|
|
|
checkBox.onCheckedChanged: {
|
|
|
|
if (checkBox.checked)
|
|
|
|
d.addToSelectedChannels(model)
|
|
|
|
else
|
|
|
|
d.removeFromSelectedChannels(model)
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onSetSelectedChannels(channels) {
|
|
|
|
communityItem.checked = channels.includes(
|
|
|
|
model.itemId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: communityCategoryDelegate
|
|
|
|
|
|
|
|
CommunityCategoryListItem {
|
|
|
|
title: model.name
|
|
|
|
|
|
|
|
checkState: {
|
2023-02-27 11:38:05 +00:00
|
|
|
if (checkedCount === subItems.count)
|
2022-12-20 00:19:46 +00:00
|
|
|
return Qt.Checked
|
|
|
|
else if (checkedCount === 0)
|
|
|
|
return Qt.Unchecked
|
|
|
|
|
|
|
|
return Qt.PartiallyChecked
|
|
|
|
}
|
|
|
|
|
|
|
|
checkBox.onToggled: {
|
|
|
|
if (checked)
|
|
|
|
radioButton.checked = false
|
|
|
|
|
|
|
|
subItemsRepeater.setAll(checkState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-27 11:38:05 +00:00
|
|
|
SortFilterProxyModel {
|
|
|
|
id: subItems
|
|
|
|
|
|
|
|
sourceModel: isCategory ? root.model : null
|
|
|
|
|
|
|
|
filters: AllOf {
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "categoryId"
|
|
|
|
value: column.categoryId
|
|
|
|
}
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "isCategory"
|
|
|
|
value: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sorters: RoleSorter {
|
|
|
|
roleName: "position"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 00:19:46 +00:00
|
|
|
Repeater {
|
|
|
|
id: subItemsRepeater
|
2023-02-27 11:38:05 +00:00
|
|
|
|
|
|
|
model: subItems
|
2022-12-20 00:19:46 +00:00
|
|
|
|
|
|
|
function setAll(checkState) {
|
|
|
|
const subItemsCount = count
|
|
|
|
|
|
|
|
for (let i = 0; i < subItemsCount; i++) {
|
|
|
|
itemAt(i).checkState = checkState
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CommunityListItem {
|
|
|
|
id: communitySubItem
|
|
|
|
|
2023-02-27 11:38:05 +00:00
|
|
|
readonly property bool show:
|
|
|
|
d.search(model.name, searcher.text) || checked
|
|
|
|
|
2022-12-20 00:19:46 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
visible: show
|
|
|
|
|
|
|
|
title: "#" + model.name
|
|
|
|
|
2023-02-27 11:38:05 +00:00
|
|
|
asset.name: model.icon ?? ""
|
2022-12-20 00:19:46 +00:00
|
|
|
asset.emoji: d.resolveEmoji(model.emoji)
|
|
|
|
asset.color: d.resolveColor(model.color,
|
|
|
|
model.colorId)
|
|
|
|
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (checked) {
|
|
|
|
radioButton.checked = false
|
|
|
|
d.addToSelectedChannels(model)
|
|
|
|
} else {
|
|
|
|
d.removeFromSelectedChannels(model)
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt.callLater(() => checkedCount += checked ? 1 : -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onSetSelectedChannels(channels) {
|
|
|
|
communitySubItem.checked = channels.includes(
|
|
|
|
model.itemId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: root.acceptMode === InDropdown.AcceptMode.Add
|
|
|
|
? qsTr("Add") : qsTr("Update")
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (radioButton.checked) {
|
|
|
|
root.communitySelected()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root.channelsSelected(Array.from(d.selectedChannels.values()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|