Changeset View
Changeset View
Standalone View
Standalone View
applets/clipboard/contents/ui/TextItemDelegate.qml
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | This file is part of the KDE project. | ||||
3 | | ||||
4 | Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org> | ||||
5 | Copyright 2014 Sebastian Kügler <sebas@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | import QtQuick 2.0 | ||||
22 | | ||||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
24 | | ||||
25 | PlasmaComponents.Label { | ||||
26 | height: undefined // unset PlasmaComponents.Label default height | ||||
27 | maximumLineCount: 3 | ||||
28 | verticalAlignment: Text.AlignVCenter | ||||
29 | | ||||
30 | text: { | ||||
31 | var highlightFontTag = "<font color='" + theme.highlightColor + "'>%1</font>" | ||||
32 | | ||||
33 | var text = DisplayRole | ||||
34 | | ||||
35 | // first escape any HTML characters to prevent privacy issues | ||||
36 | text = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") | ||||
37 | | ||||
38 | // color code leading or trailing whitespace | ||||
39 | // the first regex is basically "trim" | ||||
40 | text = text.replace(/^\s+|\s+$/gm, function(match) { | ||||
41 | // then inside the trimmed characters ("match") we replace each one individually | ||||
42 | match = match.replace(/ /g, "␣") // space | ||||
43 | .replace(/\t/g, "↹") // tab | ||||
44 | .replace(/\n/g, "↵") // return | ||||
45 | return highlightFontTag.arg(match) | ||||
46 | }) | ||||
47 | | ||||
48 | // finally turn line breaks into HTML br tags | ||||
49 | text = text.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "<br>") | ||||
50 | | ||||
51 | return text | ||||
52 | } | ||||
53 | elide: Text.ElideRight | ||||
54 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | ||||
55 | textFormat: Text.StyledText | ||||
56 | } |