summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2017-03-22 10:16:07 +0100
committerJan Grulich <[email protected]>2017-03-22 10:16:07 +0100
commit53e9d3e514c52bed0835baff6d874a76f44df2de (patch)
tree3ac1e393388324cdd052cc80aea53349f6acbdbb
parent3040cca95440027c6398563a2c131c35bfb6e65d (diff)
Simplify connection item delegate
Make some components like password field or traffic monitor as separated QML files
-rw-r--r--applet/contents/ui/CompactRepresentation.qml2
-rw-r--r--applet/contents/ui/ConnectionItem.qml216
-rw-r--r--applet/contents/ui/DetailsText.qml121
-rw-r--r--applet/contents/ui/Header.qml2
-rw-r--r--applet/contents/ui/PasswordField.qml39
-rw-r--r--applet/contents/ui/PopupDialog.qml3
-rw-r--r--applet/contents/ui/Separator.qml29
-rw-r--r--applet/contents/ui/SwitchButton.qml2
-rw-r--r--applet/contents/ui/Toolbar.qml2
-rw-r--r--applet/contents/ui/TrafficMonitor.qml93
-rw-r--r--applet/contents/ui/main.qml2
11 files changed, 313 insertions, 198 deletions
diff --git a/applet/contents/ui/CompactRepresentation.qml b/applet/contents/ui/CompactRepresentation.qml
index f196902..02c446c 100644
--- a/applet/contents/ui/CompactRepresentation.qml
+++ b/applet/contents/ui/CompactRepresentation.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2013-2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
diff --git a/applet/contents/ui/ConnectionItem.qml b/applet/contents/ui/ConnectionItem.qml
index 390e439..3fba037 100644
--- a/applet/contents/ui/ConnectionItem.qml
+++ b/applet/contents/ui/ConnectionItem.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2013-2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -167,17 +167,13 @@ PlasmaComponents.ListItem {
Item {
height: childrenRect.height
- PlasmaCore.SvgItem {
+ Separator {
id: detailsSeparator
-
anchors {
left: parent.left
right: parent.right
top: parent.top
}
- height: lineSvg.elementSize("horizontal-line").height; width: parent.width
- elementId: "horizontal-line"
- svg: PlasmaCore.Svg { id: lineSvg; imagePath: "widgets/line" }
}
PlasmaComponents.TabBar {
@@ -209,31 +205,7 @@ PlasmaComponents.ListItem {
}
}
- KQuickControlsAddons.Clipboard {
- id: clipboard
- }
-
- PlasmaComponents.ContextMenu {
- id: contextMenu
- property string text
-
- function show(item, text, x, y) {
- contextMenu.text = text
- visualParent = item
- open(x, y)
- }
-
- PlasmaComponents.MenuItem {
- text: i18n("Copy")
- icon: "edit-copy"
- enabled: contextMenu.text !== ""
- onClicked: clipboard.content = contextMenu.text
- }
- }
-
- Column {
- id: details
-
+ DetailsText {
anchors {
left: parent.left
leftMargin: units.iconSizes.medium
@@ -241,143 +213,20 @@ PlasmaComponents.ListItem {
top: detailsTabBar.visible ? detailsTabBar.bottom : detailsSeparator.bottom
topMargin: Math.round(units.gridUnit / 3)
}
- height: childrenRect.height
- visible: detailsTabBar.currentTab == detailsTabButton;
-
- Repeater {
- id: repeater
-
- property int longestString: 0
-
- model: ConnectionDetails.length / 2
-
- Item {
- anchors {
- left: parent.left
- right: parent.right
- topMargin: Math.round(units.gridUnit / 3)
- }
- height: Math.max(detailNameLabel.height, detailValueLabel.height)
-
- PlasmaComponents.Label {
- id: detailNameLabel
-
- anchors {
- left: parent.left
- leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2)
- verticalCenter: parent.verticalCenter
- }
- height: paintedHeight
- font.pointSize: theme.smallestFont.pointSize
- horizontalAlignment: Text.AlignRight
- opacity: 0.6
- text: "<b>" + ConnectionDetails[index*2] + "</b>: &nbsp"
-
- Component.onCompleted: {
- if (paintedWidth > repeater.longestString) {
- repeater.longestString = paintedWidth
- }
- }
- }
-
- PlasmaComponents.Label {
- id: detailValueLabel
-
- anchors {
- left: detailNameLabel.right
- right: parent.right
- verticalCenter: parent.verticalCenter
- }
- height: paintedHeight
- elide: Text.ElideRight
- font.pointSize: theme.smallestFont.pointSize
- opacity: 0.6
- text: ConnectionDetails[(index*2)+1]
- textFormat: Text.PlainText
-
- MouseArea {
- anchors.fill: parent
- acceptedButtons: Qt.RightButton
- onClicked: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y)
- }
- }
- }
- }
+ details: ConnectionDetails
+ visible: detailsTabBar.currentTab == detailsTabButton
}
- Item {
- id: trafficMonitor
-
+ TrafficMonitor {
anchors {
left: parent.left
right: parent.right
top: detailsTabBar.visible ? detailsTabBar.bottom : detailsSeparator.bottom
topMargin: Math.round(units.gridUnit / 3)
}
- height: visible? plotter.height + Math.round(units.gridUnit / 3) : 0
+ dataEngine: dataSource
+ deviceName: DeviceName
visible: detailsTabBar.currentTab == speedTabButton
-
- Repeater {
- model: 5
-
- PlasmaComponents.Label {
- anchors {
- left: parent.left
- top: parent.top
- topMargin: Math.round(units.gridUnit / 3) + (index * plotter.height / 5)
- }
- height: paintedHeight
- font.pointSize: theme.smallestFont.pointSize
- text: KCoreAddons.Format.formatByteSize((plotter.maxValue * 1024) * (1 - index / 5))
- }
- }
-
- KQuickControlsAddons.Plotter {
- id: plotter
-
- // Joining two QList<foo> in QML/javascript doesn't seem to work so I'm getting maximum from both list separately
- readonly property int maxValue: Math.max(Math.max.apply(null, downloadPlotData.values), Math.max.apply(null, uploadPlotData.values))
- anchors {
- left: parent.left
- leftMargin: units.iconSizes.medium
- right: parent.right
- top: parent.top
- topMargin: Math.round(units.gridUnit / 2)
- }
- width: units.gridUnit * 20
- height: units.gridUnit * 8
- horizontalGridLineCount: 5
-
- dataSets: [
- KQuickControlsAddons.PlotData {
- id: downloadPlotData
- label: i18n("Download")
- color: theme.highlightColor
- },
- KQuickControlsAddons.PlotData {
- id: uploadPlotData
- label: i18n("Upload")
- color: cycle(theme.highlightColor, -180)
- }
- ]
-
- Connections {
- target: dataSource;
- onNewData: {
- if (sourceName.indexOf("network/interfaces/" + DeviceName) != 0) {
- return;
- }
- var rx = dataSource.data[dataSource.downloadSource];
- var tx = dataSource.data[dataSource.uploadSource];
- if (rx === undefined || rx.value === undefined ||
- tx === undefined || tx.value === undefined) {
- return;
- }
-
- plotter.addSample([rx.value, tx.value]);
- }
- }
- }
}
}
}
@@ -386,59 +235,44 @@ PlasmaComponents.ListItem {
id: passwordDialogComponent
Item {
- property alias password: passwordInput.text
- property alias passwordFocus: passwordInput
+ property alias password: passwordField.text
+ property alias passwordInput: passwordField
height: childrenRect.height
- PlasmaCore.SvgItem {
+ Separator {
id: passwordSeparator
-
anchors {
left: parent.left
right: parent.right
top: parent.top
}
- height: lineSvg.elementSize("horizontal-line").height; width: parent.width
- elementId: "horizontal-line"
- svg: PlasmaCore.Svg { id: lineSvg; imagePath: "widgets/line" }
}
- PlasmaComponents.TextField {
- id: passwordInput
-
+ PasswordField {
+ id: passwordField
anchors {
horizontalCenter: parent.horizontalCenter
top: passwordSeparator.bottom
topMargin: Math.round(units.gridUnit / 3)
}
- height: implicitHeight; width: units.gridUnit * 15
- echoMode: TextInput.Password
- revealPasswordButtonShown: true
- placeholderText: i18n("Password...")
- validator: RegExpValidator {
- regExp: if (SecurityType == PlasmaNM.Enums.StaticWep) {
- /^(?:.{5}|[0-9a-fA-F]{10}|.{13}|[0-9a-fA-F]{26}){1}$/
- } else {
- /^(?:.{8,64}){1}$/
- }
- }
+ securityType: SecurityType
onAccepted: {
- stateChangeButton.clicked();
+ stateChangeButton.clicked()
}
onAcceptableInputChanged: {
- stateChangeButton.enabled = acceptableInput;
+ stateChangeButton.enabled = acceptableInput
}
- }
- Component.onCompleted: {
- stateChangeButton.enabled = false;
- }
+ Component.onCompleted: {
+ stateChangeButton.enabled = false
+ }
- Component.onDestruction: {
- stateChangeButton.enabled = true;
+ Component.onDestruction: {
+ stateChangeButton.enabled = true
+ }
}
}
}
@@ -466,10 +300,10 @@ PlasmaComponents.ListItem {
function createContent() {
if (visibleDetails) {
- expandableComponentLoader.sourceComponent = detailsComponent;
+ expandableComponentLoader.sourceComponent = detailsComponent
} else if (visiblePasswordDialog) {
- expandableComponentLoader.sourceComponent = passwordDialogComponent;
- expandableComponentLoader.item.passwordFocus.forceActiveFocus();
+ expandableComponentLoader.sourceComponent = passwordDialogComponent
+ expandableComponentLoader.item.passwordInput.forceActiveFocus()
}
}
diff --git a/applet/contents/ui/DetailsText.qml b/applet/contents/ui/DetailsText.qml
new file mode 100644
index 0000000..27be5d7
--- /dev/null
+++ b/applet/contents/ui/DetailsText.qml
@@ -0,0 +1,121 @@
+/*
+ Copyright 2013-2017 Jan Grulich <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import QtQuick 2.2
+import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons
+import org.kde.plasma.components 2.0 as PlasmaComponents
+
+Item {
+ property var details: []
+
+ height: repeater.contentHeight
+
+ KQuickControlsAddons.Clipboard {
+ id: clipboard
+ }
+
+ PlasmaComponents.ContextMenu {
+ id: contextMenu
+ property string text
+
+ function show(item, text, x, y) {
+ contextMenu.text = text
+ visualParent = item
+ open(x, y)
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Copy")
+ icon: "edit-copy"
+ enabled: contextMenu.text !== ""
+ onClicked: clipboard.content = contextMenu.text
+ }
+ }
+
+ Column {
+ anchors.fill: parent
+
+ Repeater {
+ id: repeater
+
+ property int contentHeight: 0
+ property int longestString: 0
+
+ model: details.length / 2
+
+ Item {
+ anchors {
+ left: parent.left
+ right: parent.right
+ topMargin: Math.round(units.gridUnit / 3)
+ }
+ height: Math.max(detailNameLabel.height, detailValueLabel.height)
+
+ PlasmaComponents.Label {
+ id: detailNameLabel
+
+ anchors {
+ left: parent.left
+ leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2)
+ verticalCenter: parent.verticalCenter
+ }
+ height: paintedHeight
+ font.pointSize: theme.smallestFont.pointSize
+ horizontalAlignment: Text.AlignRight
+ opacity: 0.6
+ text: "<b>" + details[index*2] + "</b>: &nbsp"
+
+ Component.onCompleted: {
+ if (paintedWidth > repeater.longestString) {
+ repeater.longestString = paintedWidth
+ }
+ }
+ }
+
+ PlasmaComponents.Label {
+ id: detailValueLabel
+
+ anchors {
+ left: detailNameLabel.right
+ right: parent.right
+ verticalCenter: parent.verticalCenter
+ }
+ height: paintedHeight
+ elide: Text.ElideRight
+ font.pointSize: theme.smallestFont.pointSize
+ opacity: 0.6
+ text: details[(index*2)+1]
+ textFormat: Text.PlainText
+
+ MouseArea {
+ anchors.fill: parent
+ acceptedButtons: Qt.RightButton
+ onClicked: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y)
+ }
+ }
+ }
+
+ // Count total height from added items, somehow contentRect.height doesn't work
+ onItemAdded: {
+ contentHeight = contentHeight + item.height
+ }
+ }
+ }
+}
diff --git a/applet/contents/ui/Header.qml b/applet/contents/ui/Header.qml
index faf5421..0a426f0 100644
--- a/applet/contents/ui/Header.qml
+++ b/applet/contents/ui/Header.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2013-2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
diff --git a/applet/contents/ui/PasswordField.qml b/applet/contents/ui/PasswordField.qml
new file mode 100644
index 0000000..425da7d
--- /dev/null
+++ b/applet/contents/ui/PasswordField.qml
@@ -0,0 +1,39 @@
+/*
+ Copyright 2013-2017 Jan Grulich <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import QtQuick 2.2
+import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
+
+PlasmaComponents.TextField {
+ property int securityType
+
+ height: implicitHeight; width: units.gridUnit * 15
+ echoMode: TextInput.Password
+ revealPasswordButtonShown: true
+ placeholderText: i18n("Password...")
+ validator: RegExpValidator {
+ regExp: if (securityType == PlasmaNM.Enums.StaticWep) {
+ /^(?:.{5}|[0-9a-fA-F]{10}|.{13}|[0-9a-fA-F]{26}){1}$/
+ } else {
+ /^(?:.{8,64}){1}$/
+ }
+ }
+}
diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml
index 6d376d8..329cfbe 100644
--- a/applet/contents/ui/PopupDialog.qml
+++ b/applet/contents/ui/PopupDialog.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2013-2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -102,5 +102,4 @@ FocusScope {
id: notificationsEngine
engine: "notifications"
}
-
}
diff --git a/applet/contents/ui/Separator.qml b/applet/contents/ui/Separator.qml
new file mode 100644
index 0000000..f28639d
--- /dev/null
+++ b/applet/contents/ui/Separator.qml
@@ -0,0 +1,29 @@
+/*
+ Copyright 2013-2017 Jan Grulich <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import QtQuick 2.2
+import org.kde.plasma.core 2.0 as PlasmaCore
+
+PlasmaCore.SvgItem {
+ height: lineSvg.elementSize("horizontal-line").height; width: parent.width
+ elementId: "horizontal-line"
+ svg: PlasmaCore.Svg { id: lineSvg; imagePath: "widgets/line" }
+}
+
diff --git a/applet/contents/ui/SwitchButton.qml b/applet/contents/ui/SwitchButton.qml
index 708953c..7573d7a 100644
--- a/applet/contents/ui/SwitchButton.qml
+++ b/applet/contents/ui/SwitchButton.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
diff --git a/applet/contents/ui/Toolbar.qml b/applet/contents/ui/Toolbar.qml
index 044fa27..257d03f 100644
--- a/applet/contents/ui/Toolbar.qml
+++ b/applet/contents/ui/Toolbar.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2013-2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
diff --git a/applet/contents/ui/TrafficMonitor.qml b/applet/contents/ui/TrafficMonitor.qml
new file mode 100644
index 0000000..8f03c34
--- /dev/null
+++ b/applet/contents/ui/TrafficMonitor.qml
@@ -0,0 +1,93 @@
+/*
+ Copyright 2013-2017 Jan Grulich <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) version 3, or any
+ later version accepted by the membership of KDE e.V. (or its
+ successor approved by the membership of KDE e.V.), which shall
+ act as a proxy defined in Section 6 of version 3 of the license.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import QtQuick 2.2
+import org.kde.kcoreaddons 1.0 as KCoreAddons
+import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons
+import org.kde.plasma.components 2.0 as PlasmaComponents
+
+Item {
+ property QtObject dataEngine: null
+ property string deviceName
+
+ height: visible ? plotter.height + Math.round(units.gridUnit / 3) : 0
+
+ Repeater {
+ model: 5
+
+ PlasmaComponents.Label {
+ anchors {
+ left: parent.left
+ top: parent.top
+ topMargin: Math.round(units.gridUnit / 3) + (index * plotter.height / 5)
+ }
+ height: paintedHeight
+ font.pointSize: theme.smallestFont.pointSize
+ text: KCoreAddons.Format.formatByteSize((plotter.maxValue * 1024) * (1 - index / 5))
+ }
+ }
+
+ KQuickControlsAddons.Plotter {
+ id: plotter
+
+ // Joining two QList<foo> in QML/javascript doesn't seem to work so I'm getting maximum from both list separately
+ readonly property int maxValue: Math.max(Math.max.apply(null, downloadPlotData.values), Math.max.apply(null, uploadPlotData.values))
+ anchors {
+ left: parent.left
+ leftMargin: units.iconSizes.medium
+ right: parent.right
+ top: parent.top
+ topMargin: Math.round(units.gridUnit / 2)
+ }
+ width: units.gridUnit * 20
+ height: units.gridUnit * 8
+ horizontalGridLineCount: 5
+
+ dataSets: [
+ KQuickControlsAddons.PlotData {
+ id: downloadPlotData
+ label: i18n("Download")
+ color: theme.highlightColor
+ },
+ KQuickControlsAddons.PlotData {
+ id: uploadPlotData
+ label: i18n("Upload")
+ color: cycle(theme.highlightColor, -180)
+ }
+ ]
+
+ Connections {
+ target: dataEngine;
+ onNewData: {
+ if (sourceName.indexOf("network/interfaces/" + deviceName) != 0) {
+ return;
+ }
+ var rx = dataEngine.data[dataEngine.downloadSource];
+ var tx = dataEngine.data[dataEngine.uploadSource];
+ if (rx === undefined || rx.value === undefined ||
+ tx === undefined || tx.value === undefined) {
+ return;
+ }
+
+ plotter.addSample([rx.value, tx.value]);
+ }
+ }
+ }
+}
diff --git a/applet/contents/ui/main.qml b/applet/contents/ui/main.qml
index a81825a..c9c8031 100644
--- a/applet/contents/ui/main.qml
+++ b/applet/contents/ui/main.qml
@@ -1,5 +1,5 @@
/*
- Copyright 2013-2014 Jan Grulich <[email protected]>
+ Copyright 2013-2017 Jan Grulich <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public