feat(StatusSearchPopupMenuItem): New APIs resetSearchSelection and setSearchSelection

New methods added `resetSearchSelection` and `setSearchSelection` for resetting
and setting selected location.
This commit is contained in:
Sale Djenic 2021-08-16 14:06:51 +02:00
parent d5bd64b742
commit bcb1e1cd97
3 changed files with 56 additions and 45 deletions

View File

@ -567,8 +567,9 @@ Rectangle {
chatInfoButton.type: StatusChatInfoButton.Type.CommunityChat
onSearchButtonClicked: {
searchButton.highlighted = !searchButton.highlighted;
searchPopup.searchSelectionButton.primaryText = demoCommunityDetailModal.header.title;
searchPopup.searchSelectionButton.image.source = demoCommunityDetailModal.header.image.source;
searchPopup.setSearchSelection(demoCommunityDetailModal.header.title,
"",
demoCommunityDetailModal.header.image.source);
searchPopup.open();
}
membersButton.onClicked: membersButton.highlighted = !membersButton.highlighted

View File

@ -16,8 +16,7 @@ StatusPopupMenu {
StatusMenuItem {
text: "Anywhere"
onTriggered: {
searchPopup.resetSelectionBadge();
searchPopup.searchSelectionButton.primaryText = text;
searchPopup.resetSearchSelection();
root.itemClicked("", "");
}
}
@ -64,13 +63,13 @@ StatusPopupMenu {
id: subMenuItemComponent
StatusSearchPopupMenuItem {
onClicked: {
searchPopup.resetSelectionBadge()
searchPopup.searchSelectionButton.primaryText = text;
searchPopup.searchSelectionButton.image.source = image.source;
searchPopup.searchSelectionButton.image.isIdenticon = image.isIdenticon;
searchPopup.searchSelectionButton.iconSettings.name = iconSettings.name;
searchPopup.searchSelectionButton.iconSettings.color = !!iconSettings.color ? iconSettings.color : Theme.palette.primaryColor1
searchPopup.searchSelectionButton.iconSettings.isLetterIdenticon = !iconSettings.name && !image.source
searchPopup.resetSearchSelection()
searchPopup.setSearchSelection(text,
"",
image.source,
image.isIdenticon,
iconSettings.name,
iconSettings.color)
root.itemClicked(value, "")
}
}
@ -105,22 +104,21 @@ StatusPopupMenu {
iconSettings.color: model.iconColor
image.isIdenticon: model.isIdenticon
onTriggered: {
searchPopup.resetSelectionBadge();
searchPopup.resetSearchSelection()
if (menuLoader.parentTitleText === "Chat") {
searchPopup.searchSelectionButton.primaryText = model.text;
searchPopup.searchSelectionButton.image.source = model.imageSource;
searchPopup.searchSelectionButton.image.isIdenticon = model.isIdenticon;
searchPopup.searchSelectionButton.iconSettings.name = model.iconName;
searchPopup.searchSelectionButton.iconSettings.color = !!model.iconColor ? model.iconColor : Theme.palette.primaryColor1;
searchPopup.searchSelectionButton.iconSettings.isLetterIdenticon = !model.iconName && !model.imageSource
searchPopup.setSearchSelection(model.text,
"",
model.imageSource,
model.isIdenticon,
model.iconName,
model.iconColor)
} else {
searchPopup.searchSelectionButton.primaryText = menuLoader.parentTitleText;
searchPopup.searchSelectionButton.secondaryText = model.text;
searchPopup.searchSelectionButton.image.source = menuLoader.parentImageSource;
searchPopup.searchSelectionButton.image.isIdenticon = menuLoader.parentIsIdenticon;
searchPopup.searchSelectionButton.iconSettings.name = menuLoader.parentIconName;
searchPopup.searchSelectionButton.iconSettings.color = !!menuLoader.parentIdenticonColor ? menuLoader.parentIdenticonColor : Theme.palette.primaryColor1;
searchPopup.searchSelectionButton.iconSettings.isLetterIdenticon = !menuLoader.parentIconName && !menuLoader.parentImageSource
searchPopup.setSearchSelection(menuLoader.parentTitleText,
model.text,
menuLoader.parentImageSource,
menuLoader.parentIsIdenticon,
menuLoader.parentIconName,
menuLoader.parentIdenticonColor)
}
root.itemClicked(menuLoader.parentValue, value)
root.dismiss()
@ -131,14 +129,14 @@ StatusPopupMenu {
}
}
onMenuItemClicked: {
searchPopup.resetSelectionBadge();
searchPopup.resetSearchSelection()
let menuItem = root.menuAt(root.currentIndex)
searchPopup.searchSelectionButton.primaryText = menuItem.title;
searchPopup.searchSelectionButton.image.source = menuItem.parentImageSource;
searchPopup.searchSelectionButton.image.isIdenticon = menuItem.parentIsIdenticon;
searchPopup.searchSelectionButton.iconSettings.name = menuItem.parentIconName;
searchPopup.searchSelectionButton.iconSettings.color = menuItem.parentIdenticonColor;
searchPopup.searchSelectionButton.iconSettings.isLetterIdenticon = !menuItem.parentIconName && !menuItem.parentImageSource
searchPopup.setSearchSelection(menuItem.title,
"",
menuItem.parentImageSource,
menuItem.parentIsIdenticon,
menuItem.parentIconName,
menuItem.parentIdenticonColor)
root.itemClicked(menuItem.parentValue, "")
//TODO fix error "QML StatusPopupMenu: cannot find any window to open popup in."
root.dismiss()

View File

@ -19,21 +19,32 @@ StatusModal {
property string searchText: contentComponent.searchText
property string noResultsLabel: "No results"
property string defaultSearchLocationText: "Anywhere"
property bool loading
property Menu searchOptionsPopupMenu: Menu { }
property var searchResults: [ ]
property var searchSelectionButton
function resetSelectionBadge() {
searchSelectionButton.iconSettings.name = ""
searchSelectionButton.iconSettings.isLetterIdenticon = false
searchSelectionButton.iconSettings.color = "transparent"
searchSelectionButton.image.source = ""
searchSelectionButton.image.isIdenticon = false
searchSelectionButton.primaryText = qsTr("Anywhere");
searchSelectionButton.secondaryText = "";
signal resultItemClicked(string itemId)
signal resultItemTitleClicked(string titleId)
function setSearchSelection(text = "",
secondaryText = "",
imageSource = "",
isIdenticon = "",
iconName = "",
iconColor = "") {
searchSelectionButton.primaryText = text
searchSelectionButton.secondaryText = secondaryText
searchSelectionButton.image.source = imageSource
searchSelectionButton.image.isIdenticon = isIdenticon
searchSelectionButton.iconSettings.name = iconName
searchSelectionButton.iconSettings.color = iconColor !== ""? iconColor : Theme.palette.primaryColor1
searchSelectionButton.iconSettings.isLetterIdenticon = !iconName && !imageSource
}
function resetSearchSelection() {
setSearchSelection(defaultSearchLocationText, "", "", false, "", "transparent")
}
content: Item {
@ -134,9 +145,10 @@ StatusModal {
Loader {
Layout.preferredWidth: active ? 16 : 0
Layout.preferredHeight: 16
active: searchOptionsMenuButton.iconSettings.name ||
active: searchOptionsMenuButton.primaryText !== defaultSearchLocationText &&
(searchOptionsMenuButton.iconSettings.name ||
searchOptionsMenuButton.iconSettings.isLetterIdenticon ||
!!searchOptionsMenuButton.image.source.toString()
!!searchOptionsMenuButton.image.source.toString())
sourceComponent: {
if (!!searchOptionsMenuButton.image.source.toString()) {
@ -231,14 +243,14 @@ StatusModal {
anchors.left: searchOptionsMenuButton.right
anchors.leftMargin: 4
anchors.verticalCenter: parent.verticalCenter
opacity: (searchOptionsMenuButton.primaryText === qsTr("Anywhere")) ? 0.0 : 1.0
opacity: (searchOptionsMenuButton.primaryText === defaultSearchLocationText) ? 0.0 : 1.0
visible: (opacity > 0.1)
type: StatusFlatRoundButton.Type.Secondary
icon.name: "close"
icon.color: Theme.palette.directColor1
icon.width: 20
icon.height: 20
onClicked: { root.resetSelectionBadge(); }
onClicked: { root.resetSearchSelection(); }
}
}
@ -321,7 +333,7 @@ StatusModal {
}
}
onClosed: {
root.resetSelectionBadge();
root.resetSearchSelection();
root.loading = false;
contentComponent.searchText = "";
}