From e10be6f3ada28005cad8c19422409f818429c883 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 12 Sep 2016 15:01:27 +0200 Subject: [PATCH] [Notifications] Limit notification size and add scroll bar if needed This limits the size of the notifications in the popup to 10 lines of text. The limit was removed when it was changed to a TextEdit so text could be copied from it. BUG: 361389 FIXED-IN: 5.8.0 --- .../package/contents/ui/NotificationItem.qml | 71 ++++++++++++------- .../package/contents/ui/NotificationPopup.qml | 5 +- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/applets/notifications/package/contents/ui/NotificationItem.qml b/applets/notifications/package/contents/ui/NotificationItem.qml index c318bcd48..25f470f56 100644 --- a/applets/notifications/package/contents/ui/NotificationItem.qml +++ b/applets/notifications/package/contents/ui/NotificationItem.qml @@ -49,6 +49,8 @@ Item { property alias configurable: settingsButton.visible property var created + property int maximumTextHeight: -1 + property ListModel actions: ListModel { } function pressedAction() { @@ -218,7 +220,7 @@ Item { rightMargin: units.smallSpacing * 2 } - implicitHeight: bodyText.paintedHeight + implicitHeight: maximumTextHeight > 0 ? Math.min(maximumTextHeight, bodyText.paintedHeight) : bodyText.paintedHeight acceptedButtons: Qt.RightButton preventStealing: true @@ -240,31 +242,50 @@ Item { } } - TextEdit { - id: bodyText - enabled: !Settings.isMobile + PlasmaExtras.ScrollArea { + id: bodyTextScrollArea anchors.fill: parent - visible: bodyText.length !== 0 - - color: PlasmaCore.ColorScope.textColor - selectedTextColor: theme.viewBackgroundColor - selectionColor: theme.viewFocusColor - font.capitalization: theme.defaultFont.capitalization - font.family: theme.defaultFont.family - font.italic: theme.defaultFont.italic - font.letterSpacing: theme.defaultFont.letterSpacing - font.pointSize: theme.defaultFont.pointSize - font.strikeout: theme.defaultFont.strikeout - font.underline: theme.defaultFont.underline - font.weight: theme.defaultFont.weight - font.wordSpacing: theme.defaultFont.wordSpacing - renderType: Text.NativeRendering - selectByMouse: true - readOnly: true - wrapMode: Text.Wrap - textFormat: TextEdit.RichText - - onLinkActivated: Qt.openUrlExternally(link) + visible: bodyText.length > 0 + + flickableItem.boundsBehavior: Flickable.StopAtBounds + flickableItem.flickableDirection: Flickable.VerticalFlick + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff + + TextEdit { + id: bodyText + width: bodyTextScrollArea.width + enabled: !Settings.isMobile + + color: PlasmaCore.ColorScope.textColor + selectedTextColor: theme.viewBackgroundColor + selectionColor: theme.viewFocusColor + font.capitalization: theme.defaultFont.capitalization + font.family: theme.defaultFont.family + font.italic: theme.defaultFont.italic + font.letterSpacing: theme.defaultFont.letterSpacing + font.pointSize: theme.defaultFont.pointSize + font.strikeout: theme.defaultFont.strikeout + font.underline: theme.defaultFont.underline + font.weight: theme.defaultFont.weight + font.wordSpacing: theme.defaultFont.wordSpacing + renderType: Text.NativeRendering + selectByMouse: true + readOnly: true + wrapMode: Text.Wrap + textFormat: TextEdit.RichText + + onLinkActivated: Qt.openUrlExternally(link) + + // ensure selecting text scrolls the view as needed... + onCursorRectangleChanged: { + var flick = bodyTextScrollArea.flickableItem + if (flick.contentY >= cursorRectangle.y) { + flick.contentY = cursorRectangle.y + } else if (flick.contentY + flick.height <= cursorRectangle.y + cursorRectangle.height) { + flick.contentY = cursorRectangle.y + cursorRectangle.height - flick.height + } + } + } } } diff --git a/applets/notifications/package/contents/ui/NotificationPopup.qml b/applets/notifications/package/contents/ui/NotificationPopup.qml index a7422dec0..8690d1034 100644 --- a/applets/notifications/package/contents/ui/NotificationPopup.qml +++ b/applets/notifications/package/contents/ui/NotificationPopup.qml @@ -72,8 +72,8 @@ PlasmaCore.Dialog { LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft LayoutMirroring.childrenInherit: true - height: notificationItem.implicitHeight + (units.smallSpacing * 2) - width: notificationItem.width + (units.smallSpacing * 2) + width: notificationItem.width + 2 * notificationItem.x + height: notificationItem.implicitHeight + 2 * notificationItem.y hoverEnabled: true @@ -118,6 +118,7 @@ PlasmaCore.Dialog { y: units.smallSpacing width: Math.round(23 * units.gridUnit) + maximumTextHeight: theme.mSize(theme.defaultFont).height * 10 onClose: { closeNotification(notificationProperties.source)