main.qml 3.62 KB
Newer Older
1 2 3
/*
 * Copyright 2013  Heena Mahour <heena393@gmail.com>
 * Copyright 2013 Sebastian Kügler <sebas@kde.org>
4
 * Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de>
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
19 20
import QtQuick 2.12
import QtQuick.Layouts 1.12
21

22 23
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
24
import org.kde.plasma.components 3.0 as PlasmaComponents3
25

26
import org.kde.plasma.calendar 2.0
27 28

Item {
29 30
    Plasmoid.switchWidth: units.gridUnit * 12
    Plasmoid.switchHeight: units.gridUnit * 12
31

32 33 34 35 36 37 38 39 40 41 42 43
    Plasmoid.toolTipMainText: Qt.formatDate(dataSource.data.Local.DateTime, "dddd")
    Plasmoid.toolTipSubText: {
        // this logic is taken from digital-clock:
        // remove "dddd" from the locale format string
        // /all/ locales in LongFormat have "dddd" either
        // at the beginning or at the end. so we just
        // remove it + the delimiter and space
        var format = Qt.locale().dateFormat(Locale.LongFormat);
        format = format.replace(/(^dddd.?\s)|(,?\sdddd$)/, "");
        return Qt.formatDate(dataSource.data.Local.DateTime, format)
    }

44 45 46
    Layout.minimumWidth: units.iconSizes.large
    Layout.minimumHeight: units.iconSizes.large

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    PlasmaCore.DataSource {
        id: dataSource
        engine: "time"
        connectedSources: ["Local"]
        interval: 60000
        intervalAlignment: PlasmaCore.Types.AlignToMinute
    }

    Plasmoid.compactRepresentation: MouseArea {
        onClicked: plasmoid.expanded = !plasmoid.expanded

        PlasmaCore.IconItem {
            anchors.fill: parent
            source: Qt.resolvedUrl("../images/mini-calendar.svgz")

62
            PlasmaComponents3.Label {
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
                anchors {
                    fill: parent
                    margins: Math.round(parent.width * 0.1)
                }
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 1000
                minimumPointSize: theme.smallestFont.pointSize
                text: {
                    var d = new Date(dataSource.data.Local.DateTime)
                    var format = plasmoid.configuration.compactDisplay

                    if (format === "w") {
                        return plasmoid.nativeInterface.weekNumber(d)
                    }

                    return Qt.formatDate(d, format)
                }
                fontSizeMode: Text.Fit
            }
        }
    }

86 87
    Plasmoid.fullRepresentation: Item {

88
        // sizing taken from digital clock
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
89
        readonly property int _minimumWidth: calendar.showWeekNumbers ? Math.round(_minimumHeight * 1.75) : Math.round(_minimumHeight * 1.5)
90 91 92 93
        readonly property int _minimumHeight: units.gridUnit * 14

        Layout.preferredWidth: _minimumWidth
        Layout.preferredHeight: Math.round(_minimumHeight * 1.5)
94 95 96

        MonthView {
            id: calendar
97
            today: dataSource.data["Local"]["DateTime"]
98
            showWeekNumbers: plasmoid.configuration.showWeekNumbers
99

Martin Klapetek's avatar
Martin Klapetek committed
100
            anchors.fill: parent
101
        }
102 103
    }
}