fix(StatusListItem): add propagateTitleClicks property to StatusListItem

Makes it possible disable the propagation of the mouse event when it's not wanted, for example in the search popup, where if the user clicks the title, we want to show the profile popup, but not navigate to the channel
This commit is contained in:
Jonathan Rainville 2022-02-22 09:54:26 -05:00 committed by Michał Cieślak
parent c5635bb36a
commit ee18ab89dd
3 changed files with 12 additions and 4 deletions

View File

@ -20,6 +20,7 @@ Rectangle {
property real rightPadding: 16 property real rightPadding: 16
property bool enabled: true property bool enabled: true
property bool highlighted: false property bool highlighted: false
property bool propagateTitleClicks: true
property int type: StatusListItem.Type.Primary property int type: StatusListItem.Type.Primary
property list<Item> components property list<Item> components
@ -175,7 +176,7 @@ Rectangle {
anchors.fill: parent anchors.fill: parent
cursorShape: containsMouse? Qt.PointingHandCursor : Qt.ArrowCursor cursorShape: containsMouse? Qt.PointingHandCursor : Qt.ArrowCursor
hoverEnabled: true hoverEnabled: true
propagateComposedEvents: true propagateComposedEvents: statusListItem.propagateTitleClicks
onClicked: { onClicked: {
statusListItem.titleClicked(statusListItem.titleId) statusListItem.titleClicked(statusListItem.titleId)
mouse.accepted = false mouse.accepted = false

View File

@ -10,6 +10,7 @@ StatusPopupMenu {
property var searchPopup property var searchPopup
property var locationModel property var locationModel
readonly property int numDefaultItems: 2
signal itemClicked(string firstLevelItemValue, string secondLevelItemValue) signal itemClicked(string firstLevelItemValue, string secondLevelItemValue)
@ -43,7 +44,7 @@ StatusPopupMenu {
color: model.iconColor, color: model.iconColor,
isLetterIdenticon: !model.imageSource && !model.iconName isLetterIdenticon: !model.imageSource && !model.iconName
}); });
root.insertMenu(index+2, item); root.insertMenu(index + numDefaultItems, item);
} else { } else {
item.value = model.value item.value = model.value
item.text = model.title; item.text = model.title;
@ -52,7 +53,7 @@ StatusPopupMenu {
item.iconSettings.isLetterIdenticon = !model.imageSource && !model.iconName item.iconSettings.isLetterIdenticon = !model.imageSource && !model.iconName
item.image.source = model.imageSource; item.image.source = model.imageSource;
item.image.isIdenticon = model.isIdenticon; item.image.isIdenticon = model.isIdenticon;
root.insertItem(index+2, item); root.insertItem(index + numDefaultItems, item);
} }
} }
} }

View File

@ -24,6 +24,9 @@ StatusModal {
property Menu searchOptionsPopupMenu: Menu { } property Menu searchOptionsPopupMenu: Menu { }
property var searchResults: [ ] property var searchResults: [ ]
property var searchSelectionButton property var searchSelectionButton
// This function is called to know if the popup accepts clicks in the title
// If it does not, the clicks on the titles mousearea will be propagated to the main body instead
property var acceptsTitleClick: function(titleId) {return true}
signal resultItemClicked(string itemId) signal resultItemClicked(string itemId)
signal resultItemTitleClicked(string titleId) signal resultItemTitleClicked(string titleId)
@ -275,10 +278,13 @@ StatusModal {
root.resultItemClicked(itemId) root.resultItemClicked(itemId)
} }
propagateTitleClicks: !root.acceptsTitleClick(titleId)
onTitleClicked: { onTitleClicked: {
if (root.acceptsTitleClick(titleId)) {
root.resultItemTitleClicked(titleId) root.resultItemTitleClicked(titleId)
} }
} }
}
section.property: "sectionName" section.property: "sectionName"
section.criteria: ViewSection.FullString section.criteria: ViewSection.FullString
section.delegate: Item { section.delegate: Item {