status-desktop/ui/shared/views/SearchResults.qml

163 lines
4.9 KiB
QML
Raw Normal View History

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import utils 1.0
import StatusQ.Controls 0.1
import "../"
import "../status"
import "../panels"
// TODO move Contact into shared to get rid of that import
import "../../app/AppLayouts/Chat/controls"
import "./"
import StatusQ.Components 0.1
Item {
id: root
height: 64
property bool hasExistingContacts: false
property bool showProfileNotFoundMessage: false
property bool loading: false
property string username: ""
property string userAlias: ""
property string pubKey: ""
property string address: ""
property bool resultClickable: true
property bool addContactEnabled: true
property bool isAddedContact: pubKey != "" ? chatsModel.messageView.isAddedContact(pubKey) : false
2021-05-18 15:07:18 +00:00
signal resultClicked(string pubKey)
signal addToContactsButtonClicked(string pubKey)
function reset() {
hasExistingContacts = false
showProfileNotFoundMessage = false
username = ""
userAlias = ""
pubKey = ""
}
width: parent.width
StyledText {
id: nonContactsLabel
2021-02-18 16:36:05 +00:00
//% "Non contacts"
text: qsTrId("non-contacts")
anchors.top: parent.top
color: Style.current.secondaryText
font.pixelSize: 15
visible: root.hasExistingContacts && (root.loading || root.pubKey !== "" || root.showProfileNotFoundMessage)
}
Loader {
active: root.loading
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
sourceComponent: Component {
LoadingAnimation {
width: 18
height: 18
}
}
}
Rectangle {
id: foundContact
property bool hovered: false
anchors.top: nonContactsLabel.visible ? nonContactsLabel.bottom : parent.top
color: hovered ? Style.current.backgroundHover : Style.current.background
radius: Style.current.radius
width: parent.width
height: 64
visible: root.pubKey !== "" && !root.loading
StatusSmartIdenticon {
id: contactIdenticon
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: Style.current.padding
image.source: utilsModel.generateIdenticon(root.pubKey)
image.isIdenticon: true
}
StyledText {
id: ensUsername
font.pixelSize: 17
color: Style.current.textColor
anchors.top: contactIdenticon.top
anchors.left: contactIdenticon.right
anchors.leftMargin: Style.current.padding
text: root.username
}
StyledText {
id: contactAlias
font.pixelSize: 15
color: Style.current.secondaryText
anchors.top: ensUsername.bottom
anchors.topMargin: 2
anchors.left: ensUsername.left
text: root.userAlias
}
MouseArea {
cursorShape: root.resultClickable ? Qt.PointingHandCursor : Qt.ArrowCursor
anchors.fill: parent
hoverEnabled: true
onEntered: foundContact.hovered = true
onExited: foundContact.hovered = false
onClicked: {
if (root.resultClickable) {
root.resultClicked(root.pubKey)
}
}
}
StatusFlatRoundButton {
id: addContactBtn
width: 32
height: 32
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
anchors.verticalCenter: parent.verticalCenter
icon.width: 24
icon.height: 24
icon.name: "add-contact"
backgroundHoverColor: Utils.setColorAlpha(Style.current.buttonHoveredBackgroundColor, 0.2)
visible: addContactEnabled && !isAddedContact && !checkIcon.visible
onClicked: {
root.addToContactsButtonClicked(root.pubKey)
mouse.accepted = false
}
onHoveredChanged: foundContact.hovered = addContactBtn.hovered
}
SVGImage {
id: checkIcon
source: Style.svg("check-2")
width: 19
height: 19
anchors.right: parent.right
anchors.rightMargin: Style.current.smallPadding * 2
anchors.verticalCenter: parent.verticalCenter
2021-05-18 15:07:18 +00:00
visible: foundContact.hovered && isAddedContact
}
}
StyledText {
id: profileNotFoundMessage
color: Style.current.secondaryText
visible: root.showProfileNotFoundMessage
font.pixelSize: 15
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
2021-02-18 16:36:05 +00:00
//% "No profile found"
text: qsTrId("no-profile-found")
}
}