Skip to content
Snippets Groups Projects
main.qml 4.07 KiB
Newer Older
    Copyright 2016,2017 Bill Binder <dxtwjb@gmail.com>
    Copyright (C) 2011, 2012, 2013 Glad Deschrijver <glad.deschrijver@gmail.com>

    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 3 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/>.

*/

wwjjbb's avatar
wwjjbb committed
import QtQuick 2.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
dxtwjb's avatar
dxtwjb committed
import QtQuick.Layouts 1.2 as QtLayouts
wwjjbb's avatar
wwjjbb committed
import QtQuick.Controls 1.2 as QtControls
import org.kde.plasma.components 2.0 as PlasmaComponents
wwjjbb's avatar
wwjjbb committed
import "../code/phases.js" as Phases
import "../code/lunacalc.js" as LunaCalc
wwjjbb's avatar
wwjjbb committed
    id: main
    property int minimumWidth
    property int minimumHeight
    property int maximumWidth
    property int maximumHeight
    property int preferredWidth
    property int preferredHeight
    property var currentPhase
wwjjbb's avatar
wwjjbb committed
    property bool showBackground: Plasmoid.configuration.showBackground
    property int hemisphere: Plasmoid.configuration.hemisphere
    property int dateFormat: Plasmoid.configuration.dateFormat
    property string dateFormatString: Plasmoid.configuration.dateFormatString
    property int lunarIndex: Plasmoid.configuration.lunarIndex
    property string lunarImage: ''
    property int lunarImageTweak: 0

wwjjbb's avatar
wwjjbb committed
    Plasmoid.backgroundHints: showBackground ? "DefaultBackground" : "NoBackground"
    Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
dxtwjb's avatar
dxtwjb committed
    Plasmoid.icon: ""
    Plasmoid.toolTipMainText: currentPhase.text
    Plasmoid.toolTipSubText: currentPhase.subText
wwjjbb's avatar
wwjjbb committed
    Plasmoid.compactRepresentation: Item {
        id: compact
wwjjbb's avatar
wwjjbb committed
        property int hemisphere: main.hemisphere
        property bool showBackground: main.showBackground
        property int lunarIndex: main.lunarIndex
wwjjbb's avatar
wwjjbb committed

        Component.onCompleted: updateDetails()
wwjjbb's avatar
wwjjbb committed
        onHemisphereChanged: updateDetails()

        onLunarIndexChanged: updateDetails()

wwjjbb's avatar
wwjjbb committed
        function updateDetails() {
            // set the correct image for the moon
            currentPhase = LunaCalc.getCurrentPhase();
            lunaIcon.phaseNumber = 13; //currentPhase.number;
            lunaIcon.theta = currentPhase.terminator;
wwjjbb's avatar
wwjjbb committed
            lunaIcon.hemisphere = hemisphere;

            main.lunarImage = imageChoices.get(main.lunarIndex).filename
            main.lunarImageTweak = imageChoices.get(main.lunarIndex).tweak
        }

        ImageChoices {
          id: imageChoices
wwjjbb's avatar
wwjjbb committed
        }

        Timer {
            id: hourlyTimer
            interval: 60 * 60 * 1000 // 60 minutes
            repeat: true
            running: true
dxtwjb's avatar
dxtwjb committed
            onTriggered: updateDetails()
wwjjbb's avatar
wwjjbb committed
        }

        LunaIcon {
            id: lunaIcon
            hemisphere: hemisphere
            lunarImage: main.lunarImage
            lunarImageTweak: main.lunarImageTweak
wwjjbb's avatar
wwjjbb committed
            anchors.fill: parent
wwjjbb's avatar
wwjjbb committed
            MouseArea {
                anchors.fill: parent
                onClicked: plasmoid.expanded = !plasmoid.expanded
            }
        }

    }
dxtwjb's avatar
dxtwjb committed
    Plasmoid.fullRepresentation: Item {
wwjjbb's avatar
wwjjbb committed
        id: full
        QtLayouts.Layout.preferredWidth: lunaWidget.QtLayouts.Layout.minimumWidth
        QtLayouts.Layout.preferredHeight: lunaWidget.QtLayouts.Layout.minimumHeight
wwjjbb's avatar
wwjjbb committed

        property int dateFormat: main.dateFormat
        property string dateFormatString: main.dateFormatString
wwjjbb's avatar
wwjjbb committed
        onDateFormatChanged: {
            lunaWidget.dateFormat = dateFormat;
        }
wwjjbb's avatar
wwjjbb committed
        onDateFormatStringChanged: {
            lunaWidget.dateFormatString = dateFormatString;
        }
wwjjbb's avatar
wwjjbb committed
        LunaWidget {
            id: lunaWidget
            dateFormat: dateFormat
            dateFormatString: dateFormatString
        }
    }