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 | 28 | anchors { | ||
29 | left: parent.left | ||||
30 | right: parent.right | ||||
31 | } | ||||
29 | 32 | | |||
30 | KQuickControlsAddons.Clipboard { | 33 | KQuickControlsAddons.Clipboard { | ||
31 | id: clipboard | 34 | id: clipboard | ||
32 | } | 35 | } | ||
33 | 36 | | |||
34 | PlasmaComponents.ContextMenu { | 37 | PlasmaComponents.ContextMenu { | ||
35 | id: contextMenu | 38 | id: contextMenu | ||
36 | property string text | 39 | property string text | ||
37 | 40 | | |||
38 | function show(item, text, x, y) { | 41 | function show(item, text, x, y) { | ||
39 | contextMenu.text = text | 42 | contextMenu.text = text | ||
40 | visualParent = item | 43 | visualParent = item | ||
41 | open(x, y) | 44 | open(x, y) | ||
42 | } | 45 | } | ||
43 | 46 | | |||
44 | PlasmaComponents.MenuItem { | 47 | PlasmaComponents.MenuItem { | ||
45 | text: i18n("Copy") | 48 | text: i18n("Copy") | ||
46 | icon: "edit-copy" | 49 | icon: "edit-copy" | ||
47 | enabled: contextMenu.text !== "" | 50 | enabled: contextMenu.text !== "" | ||
48 | onClicked: clipboard.content = contextMenu.text | 51 | onClicked: clipboard.content = contextMenu.text | ||
49 | } | 52 | } | ||
50 | } | 53 | } | ||
51 | 54 | | |||
52 | Column { | | |||
53 | anchors.fill: parent | | |||
54 | | ||||
55 | Repeater { | 55 | Repeater { | ||
56 | id: repeater | 56 | id: repeater | ||
57 | 57 | | |||
58 | property int contentHeight: 0 | 58 | property int contentHeight: 0 | ||
59 | property int longestString: 0 | 59 | property int longestString: 0 | ||
60 | 60 | | |||
61 | model: details.length / 2 | 61 | model: details.length / 2 | ||
62 | 62 | | |||
63 | Item { | 63 | Item { | ||
64 | anchors { | 64 | anchors { | ||
65 | left: parent.left | 65 | left: parent.left | ||
66 | right: parent.right | 66 | right: parent.right | ||
67 | topMargin: Math.round(units.gridUnit / 3) | | |||
68 | } | 67 | } | ||
69 | height: Math.max(detailNameLabel.height, detailValueLabel.height) | 68 | height: Math.max(detailNameLabel.height, detailValueLabel.height) | ||
70 | 69 | | |||
71 | PlasmaComponents.Label { | 70 | PlasmaComponents.Label { | ||
72 | id: detailNameLabel | 71 | id: detailNameLabel | ||
73 | 72 | | |||
74 | anchors { | 73 | anchors { | ||
75 | left: parent.left | 74 | left: parent.left | ||
76 | leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2) | 75 | leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2) | ||
77 | verticalCenter: parent.verticalCenter | | |||
78 | } | 76 | } | ||
79 | height: paintedHeight | 77 | height: paintedHeight | ||
80 | font.pointSize: theme.smallestFont.pointSize | 78 | font.pointSize: theme.smallestFont.pointSize | ||
81 | horizontalAlignment: Text.AlignRight | 79 | horizontalAlignment: Text.AlignRight | ||
82 | text: details[index*2] + ": " | 80 | text: details[index*2] + ": " | ||
83 | 81 | | |||
84 | Component.onCompleted: { | 82 | Component.onCompleted: { | ||
85 | if (paintedWidth > repeater.longestString) { | 83 | if (paintedWidth > repeater.longestString) { | ||
86 | repeater.longestString = paintedWidth | 84 | repeater.longestString = paintedWidth | ||
87 | } | 85 | } | ||
88 | } | 86 | } | ||
89 | } | 87 | } | ||
90 | 88 | | |||
91 | PlasmaComponents.Label { | 89 | PlasmaComponents.Label { | ||
92 | id: detailValueLabel | 90 | id: detailValueLabel | ||
93 | 91 | | |||
94 | anchors { | 92 | anchors { | ||
95 | left: detailNameLabel.right | 93 | left: parent.left | ||
96 | right: parent.right | 94 | right: parent.right | ||
97 | verticalCenter: parent.verticalCenter | 95 | leftMargin: repeater.longestString + Math.round(units.gridUnit / 2) | ||
98 | } | 96 | } | ||
99 | height: paintedHeight | 97 | height: paintedHeight | ||
100 | elide: Text.ElideRight | 98 | elide: Text.ElideRight | ||
101 | font.pointSize: theme.smallestFont.pointSize | 99 | font.pointSize: theme.smallestFont.pointSize | ||
102 | text: details[(index*2)+1] | 100 | text: details[(index*2)+1] | ||
103 | textFormat: Text.PlainText | 101 | textFormat: Text.PlainText | ||
104 | 102 | | |||
105 | MouseArea { | 103 | MouseArea { | ||
106 | anchors.fill: parent | 104 | anchors.fill: parent | ||
107 | acceptedButtons: Qt.RightButton | 105 | acceptedButtons: Qt.RightButton | ||
108 | onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y) | 106 | onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y) | ||
109 | } | 107 | } | ||
110 | } | 108 | } | ||
111 | } | 109 | } | ||
112 | | ||||
113 | // Count total height from added items, somehow contentRect.height doesn't work | | |||
114 | onItemAdded: { | | |||
115 | contentHeight = contentHeight + item.height | | |||
116 | } | | |||
117 | } | | |||
118 | } | 110 | } | ||
119 | } | 111 | } |