Commit 5169dff8 authored by Carl Schwan's avatar Carl Schwan 🚴 Committed by Nate Graham
Browse files

Port away from ScrollArea to ScrollView

In most cases the port is trivial and can even simplify the code like in
the case of the system tray applet. In the case of notifications applet,
this is causing a bigger refactor and it's now also using a TextArea
that provides the automatic scrolling when selecting behavior.

CCBUG: 437155
parent 76b881b8
......@@ -114,7 +114,9 @@ PlasmaComponents3.Page {
}
}
PlasmaExtras.ScrollArea {
PlasmaComponents3.ScrollView {
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
anchors {
horizontalCenter: parent.horizontalCenter
top: settingsColumn.bottom
......
......@@ -8,23 +8,26 @@ import QtQuick 2.0
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.kirigami 2.12 as Kirigami
PlasmaExtras.ScrollArea {
PlasmaComponents3.ScrollView {
id: menu
property alias view: menuListView
property alias model: menuListView.model
property bool supportsBarcodes
frameVisible: false
background: null
signal itemSelected(string uuid)
signal remove(string uuid)
signal edit(string uuid)
signal barcode(string text)
signal action(string uuid)
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
ListView {
id: menuListView
......
......@@ -110,8 +110,10 @@ PlasmaComponents3.Page {
}
}
PlasmaExtras.ScrollArea {
PlasmaComponents3.ScrollView {
anchors.fill: parent
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
ListView {
id: notifierDialog
......
......@@ -233,13 +233,16 @@ PlasmaComponents3.Page {
spacing: PlasmaCore.Units.smallSpacing
// actual notifications
PlasmaExtras.ScrollArea {
PlasmaComponents3.ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.preferredWidth: PlasmaCore.Units.gridUnit * 18
Layout.preferredHeight: PlasmaCore.Units.gridUnit * 24
Layout.leftMargin: PlasmaCore.Units.smallSpacing
frameVisible: false
background: null
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
ListView {
id: list
......
......@@ -10,19 +10,15 @@ import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.kirigami 2.11 as Kirigami
import org.kde.plasma.private.notifications 2.0 as Notifications
// NOTE This wrapper item is needed for QQC ScrollView to work
// In NotificationItem we just do SelectableLabel {} and then it gets confused
// as to which is the "contentItem"
Item {
PlasmaComponents3.ScrollView {
id: bodyTextContainer
property alias text: bodyText.text
property alias font: bodyText.font
property int cursorShape
......@@ -31,93 +27,65 @@ Item {
signal clicked(var mouse)
signal linkActivated(string link)
implicitWidth: bodyText.paintedWidth
implicitHeight: bodyText.paintedHeight
PlasmaExtras.ScrollArea {
id: bodyTextScrollArea
anchors.fill: parent
flickableItem.boundsBehavior: Flickable.StopAtBounds
flickableItem.flickableDirection: Flickable.VerticalFlick
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
TextEdit {
id: bodyText
width: bodyTextScrollArea.width
// TODO check that this doesn't causes infinite loops when it starts adding and removing the scrollbar
//width: bodyTextScrollArea.viewport.width
enabled: !Kirigami.Settings.isMobile
color: PlasmaCore.ColorScope.textColor
selectedTextColor: PlasmaCore.Theme.viewBackgroundColor
selectionColor: PlasmaCore.Theme.viewFocusColor
font.capitalization: PlasmaCore.Theme.defaultFont.capitalization
font.family: PlasmaCore.Theme.defaultFont.family
font.italic: PlasmaCore.Theme.defaultFont.italic
font.letterSpacing: PlasmaCore.Theme.defaultFont.letterSpacing
font.pointSize: PlasmaCore.Theme.defaultFont.pointSize
font.strikeout: PlasmaCore.Theme.defaultFont.strikeout
font.underline: PlasmaCore.Theme.defaultFont.underline
font.weight: PlasmaCore.Theme.defaultFont.weight
font.wordSpacing: PlasmaCore.Theme.defaultFont.wordSpacing
// Work around Qt bug where NativeRendering breaks for non-integer scale factors
// https://bugreports.qt.io/browse/QTBUG-67007
renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
// Selectable only when we are in desktop mode
selectByMouse: !Kirigami.Settings.tabletMode
readOnly: true
wrapMode: Text.Wrap
textFormat: TextEdit.RichText
onLinkActivated: bodyTextContainer.linkActivated(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
}
}
implicitHeight: Math.min(bodyText.implicitHeight, PlasmaCore.Units.gridUnit * 5)
// Handle left-click
Notifications.TextEditClickHandler {
target: bodyText
onClicked: {
bodyTextContainer.clicked(null);
}
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
contentWidth: availableWidth
PlasmaComponents3.TextArea {
id: bodyText
enabled: !Kirigami.Settings.isMobile
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
background: Item {}
// Work around Qt bug where NativeRendering breaks for non-integer scale factors
// https://bugreports.qt.io/browse/QTBUG-67007
renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
// Selectable only when we are in desktop mode
selectByMouse: !Kirigami.Settings.tabletMode
readOnly: true
wrapMode: Text.Wrap
textFormat: TextEdit.RichText
onLinkActivated: bodyTextContainer.linkActivated(link)
// Handle left-click
Notifications.TextEditClickHandler {
target: bodyText
onClicked: {
bodyTextContainer.clicked(null);
}
}
// Handle right-click and cursorShape
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
cursorShape: {
if (bodyText.hoveredLink) {
return Qt.PointingHandCursor;
} else if (bodyText.selectionStart !== bodyText.selectionEnd) {
return Qt.IBeamCursor;
} else {
return bodyTextContainer.cursorShape || Qt.IBeamCursor;
}
// Handle right-click and cursorShape
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
cursorShape: {
if (bodyText.hoveredLink) {
return Qt.PointingHandCursor;
} else if (bodyText.selectionStart !== bodyText.selectionEnd) {
return Qt.IBeamCursor;
} else {
return bodyTextContainer.cursorShape || Qt.IBeamCursor;
}
}
onPressed: {
contextMenu = contextMenuComponent.createObject(bodyText);
contextMenu.link = bodyText.linkAt(mouse.x, mouse.y);
onPressed: {
contextMenu = contextMenuComponent.createObject(bodyText);
contextMenu.link = bodyText.linkAt(mouse.x, mouse.y);
contextMenu.closed.connect(function() {
contextMenu.destroy();
contextMenu = null;
});
contextMenu.open(mouse.x, mouse.y);
}
contextMenu.closed.connect(function() {
contextMenu.destroy();
contextMenu = null;
});
contextMenu.open(mouse.x, mouse.y);
}
}
}
......
......@@ -10,51 +10,49 @@ import QtQuick 2.1
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 3.0 as PlasmaComponents3
import "items"
MouseArea {
PlasmaComponents3.ScrollView {
id: hiddenTasksView
property alias layout: hiddenTasks
hoverEnabled: true
onExited: hiddenTasks.currentIndex = -1
PlasmaExtras.ScrollArea {
width: parent.width
height: parent.height
frameVisible: false
onHoveredChanged: if (!hovered) {
hiddenTasks.currentIndex = -1;
}
background: null
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
verticalScrollBarPolicy: systemTrayState.activeApplet ? Qt.ScrollBarAlwaysOff : Qt.ScrollBarAsNeeded
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
PlasmaComponents3.ScrollBar.vertical.policy: systemTrayState.activeApplet ? PlasmaComponents3.ScrollBar.AlwaysOff : PlasmaComponents3.ScrollBar.AsNeeded
GridView {
id: hiddenTasks
GridView {
id: hiddenTasks
readonly property int rows: 4
readonly property int columns: 4
readonly property int rows: 4
readonly property int columns: 4
cellWidth: Math.floor(hiddenTasks.width / hiddenTasks.columns)
cellHeight: Math.floor(hiddenTasks.height / hiddenTasks.rows)
cellWidth: Math.floor(hiddenTasks.width / hiddenTasks.columns)
cellHeight: Math.floor(hiddenTasks.height / hiddenTasks.rows)
currentIndex: -1
highlight: PlasmaComponents.Highlight {}
highlightMoveDuration: 0
currentIndex: -1
highlight: PlasmaComponents.Highlight {}
highlightMoveDuration: 0
pixelAligned: true
pixelAligned: true
readonly property int itemCount: model.count
readonly property int itemCount: model.count
model: PlasmaCore.SortFilterModel {
sourceModel: plasmoid.nativeInterface.systemTrayModel
filterRole: "effectiveStatus"
filterCallback: function(source_row, value) {
return value === PlasmaCore.Types.PassiveStatus
}
model: PlasmaCore.SortFilterModel {
sourceModel: plasmoid.nativeInterface.systemTrayModel
filterRole: "effectiveStatus"
filterCallback: function(source_row, value) {
return value === PlasmaCore.Types.PassiveStatus
}
delegate: ItemLoader {}
}
delegate: ItemLoader {}
}
}
......@@ -10,7 +10,6 @@ import QtQuick.Window 2.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.milou 0.1 as Milou
ColumnLayout {
......@@ -233,12 +232,14 @@ ColumnLayout {
}
}
PlasmaExtras.ScrollArea {
PlasmaComponents3.ScrollView {
Layout.alignment: Qt.AlignTop
visible: results.count > 0
enabled: visible
Layout.fillWidth: true
Layout.preferredHeight: Math.min(Screen.height, results.contentHeight)
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
Milou.ResultsView {
id: results
......@@ -276,13 +277,15 @@ ColumnLayout {
}
}
PlasmaExtras.ScrollArea {
PlasmaComponents3.ScrollView {
Layout.alignment: Qt.AlignTop
Layout.fillWidth: true
visible: root.query.length === 0 && listView.count > 0
// don't accept keyboard input when not visible so the keys propagate to the other list
enabled: visible
Layout.preferredHeight: Math.min(Screen.height, listView.contentHeight)
// HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
ListView {
id: listView // needs this id so the delegate can access it
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment