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 | | |||
55 | Repeater { | 56 | Repeater { | ||
56 | id: repeater | 57 | id: repeater | ||
57 | 58 | | |||
58 | property int contentHeight: 0 | 59 | property int contentHeight: 0 | ||
59 | property int longestString: 0 | 60 | property int longestString: 0 | ||
60 | 61 | | |||
61 | model: details.length / 2 | 62 | model: details.length / 2 | ||
62 | 63 | | |||
63 | Item { | 64 | Item { | ||
64 | anchors { | 65 | anchors { | ||
65 | left: parent.left | 66 | left: parent.left | ||
66 | right: parent.right | 67 | right: parent.right | ||
67 | topMargin: Math.round(units.gridUnit / 3) | | |||
68 | } | 68 | } | ||
69 | height: Math.max(detailNameLabel.height, detailValueLabel.height) | 69 | height: Math.max(detailNameLabel.height, detailValueLabel.height) | ||
70 | 70 | | |||
71 | PlasmaComponents.Label { | 71 | PlasmaComponents.Label { | ||
72 | id: detailNameLabel | 72 | id: detailNameLabel | ||
73 | 73 | | |||
74 | anchors { | 74 | anchors { | ||
75 | left: parent.left | 75 | left: parent.left | ||
76 | leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2) | 76 | leftMargin: repeater.longestString - paintedWidth + Math.round(units.gridUnit / 2) | ||
77 | verticalCenter: parent.verticalCenter | | |||
78 | } | 77 | } | ||
79 | height: paintedHeight | 78 | height: paintedHeight | ||
80 | font.pointSize: theme.smallestFont.pointSize | 79 | font.pointSize: theme.smallestFont.pointSize | ||
81 | horizontalAlignment: Text.AlignRight | 80 | horizontalAlignment: Text.AlignRight | ||
82 | text: details[index*2] + ": " | 81 | text: details[index*2] + ": " | ||
83 | 82 | | |||
84 | Component.onCompleted: { | 83 | Component.onCompleted: { | ||
85 | if (paintedWidth > repeater.longestString) { | 84 | if (paintedWidth > repeater.longestString) { | ||
86 | repeater.longestString = paintedWidth | 85 | repeater.longestString = paintedWidth | ||
87 | } | 86 | } | ||
88 | } | 87 | } | ||
89 | } | 88 | } | ||
90 | 89 | | |||
91 | PlasmaComponents.Label { | 90 | PlasmaComponents.Label { | ||
92 | id: detailValueLabel | 91 | id: detailValueLabel | ||
93 | 92 | | |||
94 | anchors { | 93 | anchors { | ||
95 | left: detailNameLabel.right | 94 | left: parent.left | ||
96 | right: parent.right | 95 | right: parent.right | ||
97 | verticalCenter: parent.verticalCenter | 96 | leftMargin: repeater.longestString + Math.round(units.gridUnit / 2) | ||
98 | } | 97 | } | ||
99 | height: paintedHeight | 98 | height: paintedHeight | ||
100 | elide: Text.ElideRight | 99 | elide: Text.ElideRight | ||
101 | font.pointSize: theme.smallestFont.pointSize | 100 | font.pointSize: theme.smallestFont.pointSize | ||
102 | text: details[(index*2)+1] | 101 | text: details[(index*2)+1] | ||
103 | textFormat: Text.PlainText | 102 | textFormat: Text.PlainText | ||
104 | 103 | | |||
105 | MouseArea { | 104 | MouseArea { | ||
106 | anchors.fill: parent | 105 | anchors.fill: parent | ||
107 | acceptedButtons: Qt.RightButton | 106 | acceptedButtons: Qt.RightButton | ||
108 | onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y) | 107 | onPressed: contextMenu.show(this, detailValueLabel.text, mouse.x, mouse.y) | ||
109 | } | 108 | } | ||
110 | } | 109 | } | ||
111 | } | 110 | } | ||
112 | | ||||
113 | // Count total height from added items, somehow contentRect.height doesn't work | | |||
114 | onItemAdded: { | | |||
115 | contentHeight = contentHeight + item.height | | |||
116 | } | | |||
117 | } | | |||
118 | } | 111 | } | ||
119 | } | 112 | } |