Verified Commit 12b6b085 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applet: use less `MouseArea` in details area

There are too many MouseAreas, and each will consume a little memory.
This uses childAt to reduce the number of MouseArea.
parent 8c7446a0
......@@ -134,18 +134,16 @@ PlasmaExtras.ExpandableListItem {
}
}
FocusScope {
anchors {
left: parent.left
leftMargin: PlasmaCore.Units.iconSizes.smallMedium
right: parent.right
}
height: detailsTextColumn.implicitHeight
DetailsText {
id: detailsTextColumn
width: parent.width
visible: detailsTabBar.currentIndex == 1
activeFocusOnTab: true
details: ConnectionDetails
Accessible.description: ConnectionDetails.join(" ")
Accessible.description: details.join(" ")
Loader {
anchors.fill: parent
......@@ -157,12 +155,6 @@ PlasmaExtras.ExpandableListItem {
hovered: true
}
}
DetailsText {
id: detailsTextColumn
width: parent.width
details: ConnectionDetails
}
}
FocusScope {
......
......@@ -5,14 +5,28 @@
*/
import QtQuick 2.2
import QtQuick.Layouts 1.15
import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // for ContextMenu+MenuItem
import org.kde.plasma.components 3.0 as PlasmaComponents3
Column {
MouseArea {
height: detailsGrid.implicitHeight
property var details: []
acceptedButtons: Qt.RightButton
onPressed: {
const item = detailsGrid.childAt(mouse.x, mouse.y);
if (!item) {
return;
}
contextMenu.show(this, item.text, mouse.x, mouse.y);
}
KQuickControlsAddons.Clipboard {
id: clipboard
}
......@@ -35,58 +49,28 @@ Column {
}
}
Repeater {
id: repeater
GridLayout {
id: detailsGrid
width: parent.width
columns: 2
rowSpacing: PlasmaCore.Units.smallSpacing / 4
property int contentHeight: 0
property int longestString: 0
Repeater {
id: repeater
model: details.length / 2
Item {
anchors {
left: parent.left
right: parent.right
}
height: Math.max(detailNameLabel.height, detailValueLabel.height)
model: details.length
PlasmaComponents3.Label {
id: detailNameLabel
Layout.fillWidth: true
anchors {
left: parent.left
leftMargin: repeater.longestString - paintedWidth + Math.round(PlasmaCore.Units.gridUnit / 2)
}
font: PlasmaCore.Theme.smallestFont
horizontalAlignment: Text.AlignRight
text: details[index*2] + ": "
opacity: 0.6
Component.onCompleted: {
if (paintedWidth > repeater.longestString) {
repeater.longestString = paintedWidth
}
}
}
readonly property bool isContent: index % 2
PlasmaComponents3.Label {
id: detailValueLabel
anchors {
left: parent.left
right: parent.right
leftMargin: repeater.longestString + Math.round(PlasmaCore.Units.gridUnit / 2)
}
elide: Text.ElideRight
elide: isContent ? Text.ElideRight : Text.ElideNone
font: PlasmaCore.Theme.smallestFont
text: details[(index*2)+1]
horizontalAlignment: isContent ? Text.AlignLeft : Text.AlignRight
text: isContent ? details[index] : `${details[index]}:`
textFormat: Text.PlainText
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y)
}
opacity: isContent ? 1 : 0.6
}
}
}
......
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