Changeset View
Changeset View
Standalone View
Standalone View
applets/digital-clock/package/contents/ui/DateFormatTable.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Chris Holland <zrenfire@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
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.8 | ||||
22 | import QtQuick.Controls 2.3 as QtControls | ||||
23 | import QtQuick.Layouts 1.0 as QtLayouts | ||||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
25 | | ||||
26 | QtLayouts.GridLayout { | ||||
27 | id: dateFormatTable | ||||
28 | columns: 2 | ||||
29 | | ||||
30 | property var dateTime: new Date(1976, 3, 1, 23, 59, 34) | ||||
31 | property var model: ["ddd"] | ||||
32 | | ||||
33 | signal dateFormatClicked(string dateFormat) | ||||
34 | | ||||
35 | Repeater { | ||||
36 | model: dateFormatTable.model.length * 2 | ||||
37 | | ||||
38 | Item { | ||||
39 | id: cell | ||||
40 | readonly property int modelIndex: Math.floor(index / 2) | ||||
41 | readonly property string dateFormat: dateFormatTable.model[cell.modelIndex] | ||||
42 | readonly property int row: Math.floor(index / dateFormatTable.columns) | ||||
43 | readonly property int column: index % dateFormatTable.columns | ||||
44 | readonly property bool isVariable: index % 2 == 0 | ||||
45 | readonly property bool needsExtraSpacing: !isVariable && column+1 != dateFormatTable.columns | ||||
46 | readonly property int extraSpacing: needsExtraSpacing ? units.smallSpacing : 0 | ||||
47 | QtLayouts.Layout.fillWidth: true | ||||
48 | // QtLayouts.Layout.alignment: cell.isVariable ? Qt.AlignRight : Qt.AlignLeft | ||||
49 | implicitWidth: cellButton.implicitWidth + extraSpacing | ||||
50 | implicitHeight: cellButton.implicitHeight | ||||
51 | | ||||
52 | Item { | ||||
53 | id: cellButton | ||||
54 | anchors.fill: Drag.active ? undefined : parent | ||||
55 | anchors.rightMargin: cell.extraSpacing | ||||
56 | property int padding: units.smallSpacing | ||||
57 | implicitWidth: exampleLabel.implicitWidth + padding*2 | ||||
58 | implicitHeight: exampleLabel.implicitHeight + padding*2 | ||||
59 | | ||||
60 | Drag.active: mouseArea.drag.active | ||||
61 | Drag.mimeData: { "text/plain": cell.dateFormat } | ||||
62 | Drag.proposedAction: Qt.CopyAction | ||||
63 | Drag.dragType: Drag.Automatic | ||||
64 | | ||||
65 | Rectangle { | ||||
66 | anchors.fill: parent | ||||
67 | color: mouseArea.containsMouse ? PlasmaCore.ColorScope.highlightColor : exampleLabel.color | ||||
68 | opacity: cell.isVariable ? 0.2 : 0.1 | ||||
69 | radius: cellButton.padding | ||||
70 | } | ||||
71 | | ||||
72 | QtControls.Label { | ||||
73 | id: exampleLabel | ||||
74 | anchors.fill: parent | ||||
75 | anchors.margins: cellButton.padding | ||||
76 | // horizontalAlignment: Text.AlignHCenter | ||||
77 | textFormat: cell.isVariable ? Text.PlainText : Text.RichText | ||||
78 | text: { | ||||
79 | if (cell.isVariable) { | ||||
80 | return cell.dateFormat; | ||||
81 | } else { | ||||
82 | return Qt.formatDate(dateFormatTable.dateTime, cell.dateFormat); | ||||
83 | } | ||||
84 | } | ||||
85 | } | ||||
86 | | ||||
87 | MouseArea { | ||||
88 | id: mouseArea | ||||
89 | anchors.fill: parent | ||||
90 | hoverEnabled: true | ||||
91 | cursorShape: Qt.PointingHandCursor | ||||
92 | onClicked: dateFormatTable.dateFormatClicked(dateFormat) | ||||
93 | | ||||
94 | drag.target: cellButton | ||||
95 | onPressed: { | ||||
96 | drag.target.grabToImage(function(result) { | ||||
97 | drag.target.Drag.imageSource = result.url; | ||||
98 | }); | ||||
99 | } | ||||
100 | } | ||||
101 | } | ||||
102 | } | ||||
103 | | ||||
104 | } | ||||
105 | } |