From 6f77a1fe9defeab40d90df82df238ef7dd2f906c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 31 Dec 2021 00:47:14 +0100 Subject: [PATCH] Use the styles default delay for tooltips This makes them less annoying when scrolling or accessing the popup menu. See also #860 --- resources/qml/CommunitiesList.qml | 2 ++ resources/qml/MatrixText.qml | 4 +++- resources/qml/MessageView.qml | 6 ++++++ resources/qml/RoomList.qml | 7 +++++++ resources/qml/TimelineRow.qml | 2 ++ src/ui/NhekoGlobalObject.cpp | 8 ++++++++ src/ui/NhekoGlobalObject.h | 4 ++++ 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/resources/qml/CommunitiesList.qml b/resources/qml/CommunitiesList.qml index 46e24566..0131de89 100644 --- a/resources/qml/CommunitiesList.qml +++ b/resources/qml/CommunitiesList.qml @@ -62,6 +62,7 @@ Page { state: "normal" ToolTip.visible: hovered && collapsed ToolTip.text: model.tooltip + ToolTip.delay: Nheko.tooltipDelay onClicked: Communities.setCurrentTagId(model.id) onPressAndHold: communityContextMenu.show(model.id) states: [ @@ -123,6 +124,7 @@ Page { width: fontMetrics.lineSpacing image: model.collapsed ? ":/icons/icons/ui/collapsed.svg" : ":/icons/icons/ui/expanded.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: model.collapsed ? qsTr("Expand") : qsTr("Collapse") hoverEnabled: true diff --git a/resources/qml/MatrixText.qml b/resources/qml/MatrixText.qml index 7253cbe6..8cad3b5a 100644 --- a/resources/qml/MatrixText.qml +++ b/resources/qml/MatrixText.qml @@ -19,7 +19,9 @@ TextEdit { color: Nheko.colors.text onLinkActivated: Nheko.openLink(link) ToolTip.visible: hoveredLink || false - ToolTip.text: hoveredLink || "" + ToolTip.text: hoveredLink + // Setting a tooltip delay makes the hover text empty .-. + //ToolTip.delay: Nheko.tooltipDelay Component.onCompleted: { TimelineManager.fixImageRendering(r.textDocument, r); } diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index adbc9d70..4e0c56c3 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -105,6 +105,7 @@ ScrollView { hoverEnabled: true image: ":/icons/icons/ui/edit.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Edit") onClicked: { if (row.model.isEditable) @@ -121,6 +122,7 @@ ScrollView { hoverEnabled: true image: ":/icons/icons/ui/smile.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("React") onClicked: emojiPopup.visible ? emojiPopup.close() : emojiPopup.show(reactButton, function(emoji) { var event_id = row.model ? row.model.eventId : ""; @@ -137,6 +139,7 @@ ScrollView { hoverEnabled: true image: ":/icons/icons/ui/reply.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Reply") onClicked: chat.model.replyAction(row.model.eventId) } @@ -148,6 +151,7 @@ ScrollView { hoverEnabled: true image: ":/icons/icons/ui/options.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Options") onClicked: messageContextMenu.show(row.model.eventId, row.model.type, row.model.isSender, row.model.isEncrypted, row.model.isEditable, "", row.model.body, optionsButton) } @@ -284,6 +288,7 @@ ScrollView { userid: userId onClicked: room.openUserProfile(userId) ToolTip.visible: avatarHover.hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: userid HoverHandler { @@ -311,6 +316,7 @@ ScrollView { color: TimelineManager.userColor(userId, Nheko.colors.base) textFormat: Text.RichText ToolTip.visible: displayNameHover.hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: userId TapHandler { diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index 3bb9da86..b00ba985 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -140,6 +140,7 @@ Page { width: ListView.view.width state: "normal" ToolTip.visible: hovered && collapsed + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: roomName onClicked: { console.log("tapped " + roomId); @@ -325,6 +326,7 @@ Page { radius: height / 2 color: hasLoudNotification ? Nheko.theme.red : roomItem.bubbleBackground ToolTip.text: notificationCount + ToolTip.delay: Nheko.tooltipDelay ToolTip.visible: notificationBubbleHover.hovered && (notificationCount > 9999) Label { @@ -495,6 +497,7 @@ Page { Layout.preferredHeight: fontMetrics.lineSpacing * 2 image: ":/icons/icons/ui/power-off.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Logout") onClicked: Nheko.openLogoutDialog() } @@ -560,6 +563,7 @@ Page { height: fontMetrics.font.pixelSize image: ":/icons/icons/ui/dismiss.svg" ToolTip.visible: closeUnverifiedBubble.hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Close") onClicked: unverifiedStuffBubble.visible = false } @@ -625,6 +629,7 @@ Page { height: 22 image: ":/icons/icons/ui/add-square-button.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Start a new chat") Layout.margins: Nheko.paddingMedium onClicked: roomJoinCreateMenu.open(parent) @@ -654,6 +659,7 @@ Page { height: 22 image: ":/icons/icons/ui/speech-bubbles.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Room directory") Layout.margins: Nheko.paddingMedium onClicked: { @@ -670,6 +676,7 @@ Page { height: 22 image: ":/icons/icons/ui/settings.svg" ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("User settings") Layout.margins: Nheko.paddingMedium onClicked: Nheko.showUserSettingsPage() diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index 5abc15de..0449981e 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -171,6 +171,7 @@ Item { sourceSize.height: 16 * Screen.devicePixelRatio source: "image://colorimage/:/icons/icons/ui/edit.svg?" + ((eventId == chat.model.edit) ? Nheko.colors.highlight : Nheko.colors.buttonText) ToolTip.visible: editHovered.hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Edited") HoverHandler { @@ -194,6 +195,7 @@ Item { width: Math.max(implicitWidth, text.length * fontMetrics.maximumCharacterWidth) color: Nheko.inactiveColors.text ToolTip.visible: ma.hovered + ToolTip.delay: Nheko.tooltipDelay ToolTip.text: Qt.formatDateTime(timestamp, Qt.DefaultLocaleLongDate) HoverHandler { diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp index bc578476..e6869639 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp @@ -4,7 +4,9 @@ #include "NhekoGlobalObject.h" +#include #include +#include #include #include @@ -75,6 +77,12 @@ Nheko::theme() const return Theme(UserSettings::instance()->theme()); } +int +Nheko::tooltipDelay() const +{ + return QApplication::style()->styleHint(QStyle::StyleHint::SH_ToolTip_WakeUpDelay); +} + void Nheko::openLink(QString link) const { diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index c70813c5..9e3d463a 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -24,6 +24,7 @@ class Nheko : public QObject Q_PROPERTY(int paddingSmall READ paddingSmall CONSTANT) Q_PROPERTY(int paddingMedium READ paddingMedium CONSTANT) Q_PROPERTY(int paddingLarge READ paddingLarge CONSTANT) + Q_PROPERTY(int tooltipDelay READ tooltipDelay CONSTANT) Q_PROPERTY(UserProfile *currentUser READ currentUser NOTIFY profileChanged) @@ -39,6 +40,9 @@ public: int paddingSmall() const { return 4; } int paddingMedium() const { return 8; } int paddingLarge() const { return 20; } + + int tooltipDelay() const; + UserProfile *currentUser() const; Q_INVOKABLE QFont monospaceFont() const