Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/DetailsText.qml
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.2 | 21 | import QtQuick 2.2 | ||
22 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | 22 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | ||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | 23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
24 | 24 | | |||
25 | Item { | 25 | Column { | ||
26 | property var details: [] | 26 | property var details: [] | ||
27 | 27 | | |||
28 | height: repeater.contentHeight | | |||
29 | | ||||
30 | KQuickControlsAddons.Clipboard { | 28 | KQuickControlsAddons.Clipboard { | ||
31 | id: clipboard | 29 | id: clipboard | ||
32 | } | 30 | } | ||
33 | 31 | | |||
34 | PlasmaComponents.ContextMenu { | 32 | PlasmaComponents.ContextMenu { | ||
35 | id: contextMenu | 33 | id: contextMenu | ||
36 | property string text | 34 | property string text | ||
37 | 35 | | |||
38 | function show(item, text, x, y) { | 36 | function show(item, text, x, y) { | ||
39 | contextMenu.text = text | 37 | contextMenu.text = text | ||
40 | visualParent = item | 38 | visualParent = item | ||
41 | open(x, y) | 39 | open(x, y) | ||
42 | } | 40 | } | ||
43 | 41 | | |||
44 | PlasmaComponents.MenuItem { | 42 | PlasmaComponents.MenuItem { | ||
45 | text: i18n("Copy") | 43 | text: i18n("Copy") | ||
46 | icon: "edit-copy" | 44 | icon: "edit-copy" | ||
47 | enabled: contextMenu.text !== "" | 45 | enabled: contextMenu.text !== "" | ||
48 | onClicked: clipboard.content = contextMenu.text | 46 | onClicked: clipboard.content = contextMenu.text | ||
49 | } | 47 | } | ||
50 | } | 48 | } | ||
51 | 49 | | |||
52 | Column { | | |||
53 | anchors.fill: parent | | |||
54 | | ||||
55 | Repeater { | 50 | Repeater { | ||
56 | id: repeater | 51 | id: repeater | ||
57 | 52 | | |||
58 | property int contentHeight: 0 | 53 | property int contentHeight: 0 | ||
59 | property int longestString: 0 | 54 | property int longestString: 0 | ||
60 | 55 | | |||
61 | model: details.length / 2 | 56 | model: details.length / 2 | ||
62 | 57 | | |||
63 | Item { | 58 | Item { | ||
64 | anchors { | 59 | anchors { | ||
65 | left: parent.left | 60 | left: parent.left | ||
66 | right: parent.right | 61 | right: parent.right | ||
67 | topMargin: Math.round(units.gridUnit / 3) | | |||
68 | } | 62 | } | ||
69 | height: Math.max(detailNameLabel.height, detailValueLabel.height) | 63 | height: Math.max(detailNameLabel.height, detailValueLabel.height) | ||
70 | 64 | | |||
71 | PlasmaComponents.Label { | 65 | PlasmaComponents.Label { | ||
72 | id: detailNameLabel | 66 | id: detailNameLabel | ||
73 | 67 | | |||
74 | anchors { | 68 | anchors { | ||
75 | left: parent.left | 69 | left: parent.left | ||
76 | leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2) | 70 | leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2) | ||
77 | verticalCenter: parent.verticalCenter | | |||
78 | } | 71 | } | ||
79 | height: paintedHeight | 72 | height: paintedHeight | ||
80 | font.pointSize: theme.smallestFont.pointSize | 73 | font.pointSize: theme.smallestFont.pointSize | ||
81 | horizontalAlignment: Text.AlignRight | 74 | horizontalAlignment: Text.AlignRight | ||
82 | text: details[index*2] + ": " | 75 | text: details[index*2] + ": " | ||
83 | 76 | | |||
84 | Component.onCompleted: { | 77 | Component.onCompleted: { | ||
85 | if (paintedWidth > repeater.longestString) { | 78 | if (paintedWidth > repeater.longestString) { | ||
86 | repeater.longestString = paintedWidth | 79 | repeater.longestString = paintedWidth | ||
87 | } | 80 | } | ||
88 | } | 81 | } | ||
89 | } | 82 | } | ||
90 | 83 | | |||
91 | PlasmaComponents.Label { | 84 | PlasmaComponents.Label { | ||
92 | id: detailValueLabel | 85 | id: detailValueLabel | ||
93 | 86 | | |||
94 | anchors { | 87 | anchors { | ||
95 | left: detailNameLabel.right | 88 | left: parent.left | ||
96 | right: parent.right | 89 | right: parent.right | ||
97 | verticalCenter: parent.verticalCenter | 90 | leftMargin: repeater.longestString + Math.round(units.gridUnit / 2) | ||
98 | } | 91 | } | ||
99 | height: paintedHeight | 92 | height: paintedHeight | ||
100 | elide: Text.ElideRight | 93 | elide: Text.ElideRight | ||
101 | font.pointSize: theme.smallestFont.pointSize | 94 | font.pointSize: theme.smallestFont.pointSize | ||
102 | text: details[(index*2)+1] | 95 | text: details[(index*2)+1] | ||
103 | textFormat: Text.PlainText | 96 | textFormat: Text.PlainText | ||
104 | 97 | | |||
105 | MouseArea { | 98 | MouseArea { | ||
106 | anchors.fill: parent | 99 | anchors.fill: parent | ||
107 | acceptedButtons: Qt.RightButton | 100 | acceptedButtons: Qt.RightButton | ||
108 | onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y) | 101 | onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y) | ||
109 | } | 102 | } | ||
110 | } | 103 | } | ||
111 | } | 104 | } | ||
112 | | ||||
113 | // Count total height from added items, somehow contentRect.height doesn't work | | |||
114 | onItemAdded: { | | |||
115 | contentHeight = contentHeight + item.height | | |||
116 | } | | |||
117 | } | | |||
118 | } | 105 | } | ||
119 | } | 106 | } |