Warning, /education/kstars/kstars/kstarslite/qml/modules/TopMenu.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick 2.7
0005 import QtQuick.Layouts 1.1
0006 import QtQuick.Controls 2.0
0007 import QtQuick.Controls.Material 2.0
0008 import QtQuick.Controls.Universal 2.0
0009 
0010 import QtQuick.Window 2.2
0011 import "../constants" 1.0
0012 import "helpers"
0013 import KStarsLiteEnums 1.0
0014 
0015 ColumnLayout {
0016     id: topMenu
0017     objectName: "topMenu"
0018     property int padding: 10
0019     property double openOffset: -topBar.background.radius //Hide top round corners
0020     property double closedOffset: -topBar.height // Hide top bar when closed
0021     property string prevState
0022 
0023     Connections {
0024         target: SkyMapLite
0025         onSlewingChanged: {
0026             if(SkyMapLite.slewing || skyMapLite.automaticMode) {
0027                 prevState = state
0028                 state = "hidden"
0029             } else {
0030                 state = prevState
0031             }
0032         }
0033     }
0034 
0035     state: "closed"
0036     property alias state : topMenu.state
0037     spacing: padding
0038 
0039     x: (parent.width - width)/2
0040 
0041     Layout.fillHeight: true
0042     width: parent.width < menuFlow.childrenWidth  ? parent.width : menuFlow.childrenWidth
0043 
0044     states: [
0045         State {
0046             name: "open"
0047             PropertyChanges {
0048                 target: topMenu
0049                 y: openOffset
0050             }
0051         },
0052         State {
0053             name: "closed"
0054             PropertyChanges {
0055                 target: topMenu
0056                 y: closedOffset
0057             }
0058         },
0059         State {
0060             name: "hidden"
0061             PropertyChanges {
0062                 target: topMenu
0063                 y: -topMenu.height
0064             }
0065         }
0066     ]
0067 
0068     transitions: [
0069         Transition {
0070             to: "open"
0071             PropertyAnimation { target: topMenu
0072                 properties: "y"; duration: 300 }
0073         },
0074         Transition {
0075             to: "closed"
0076             PropertyAnimation { target: topMenu
0077                 properties: "y"; duration: 300 }
0078         },
0079         Transition {
0080             to: "hidden"
0081             PropertyAnimation { target: topMenu
0082                 properties: "y"; duration: 200 }
0083         }
0084     ]
0085 
0086     Pane {
0087         id: topBar
0088         anchors.horizontalCenter: parent.horizontalCenter
0089         implicitWidth: parent.width
0090         Layout.fillHeight: true
0091 
0092         background: Rectangle {
0093             id: menuRect
0094             color: Num.sysPalette.base
0095             border {
0096                 width: 2
0097                 color: Num.sysPalette.light
0098             }
0099             radius: 10
0100         }
0101 
0102         Flow {
0103             id: menuFlow
0104             spacing: 5
0105             width: parent.width
0106             property double childrenWidth: 0
0107 
0108             Component.onCompleted: {
0109                 if(Qt.platform.os == "android") {
0110                     //Automatic mode is available only for Android
0111                     var columnForTab = Qt.createQmlObject('import QtQuick 2.7
0112                                                             import "helpers"
0113                 TopMenuButton {
0114                     id: autoModeButton
0115                     iconSrc: "../../images/kstars_automode.png"
0116                     title: xi18n("Automatic mode")
0117                     titlePlural: false
0118                     visible: Qt.platform.os == "android"
0119 
0120                     toggled: SkyMapLite.automaticMode
0121                     onClicked: {
0122                         SkyMapLite.automaticMode = !SkyMapLite.automaticMode
0123                     }
0124                 }', menuFlow)
0125                     }
0126 
0127                 for(var i = 0; i < children.length; ++i) {
0128                     childrenWidth += children[i].width + spacing
0129                 }
0130                 childrenWidth += topBar.padding*2 //Account for topBar padding to have enough space for all elements
0131             }
0132 
0133             anchors {
0134                 top: parent.top
0135                 topMargin: menuRect.radius/2 // Center vertically menuGrid in background rectangle
0136             }
0137             Layout.fillHeight: true
0138 
0139             TopMenuButton {
0140                 iconSrc: "../../images/kstars_stars.png"
0141                 title: xi18n("Stars")
0142 
0143                 toggled: KStarsLite.isToggled(ObjectsToToggle.Stars)
0144                 onClicked: {
0145                     KStarsLite.toggleObjects(ObjectsToToggle.Stars, toggled)
0146                 }
0147             }
0148             TopMenuButton {
0149                 iconSrc: "../../images/kstars_deepsky.png"
0150                 title: xi18n("DeepSky Objects")
0151 
0152                 toggled: KStarsLite.isToggled(ObjectsToToggle.DeepSky)
0153                 onClicked: {
0154                     KStarsLite.toggleObjects(ObjectsToToggle.DeepSky, toggled)
0155                 }
0156             }
0157             TopMenuButton {
0158                 iconSrc: "../../images/kstars_planets.png"
0159                 title: xi18n("Solar System")
0160                 titlePlural: false
0161 
0162                 toggled: KStarsLite.isToggled(ObjectsToToggle.Planets)
0163                 onClicked: {
0164                     KStarsLite.toggleObjects(ObjectsToToggle.Planets, toggled)
0165                 }
0166             }
0167             TopMenuButton {
0168                 iconSrc: "../../images/kstars_supernovae.png"
0169                 title: xi18n("Supernovae")
0170 
0171                 toggled: KStarsLite.isToggled(ObjectsToToggle.Supernovae)
0172                 onClicked: {
0173                     KStarsLite.toggleObjects(ObjectsToToggle.Supernovae, toggled)
0174                 }
0175             }
0176             TopMenuButton {
0177                 iconSrc: "../../images/kstars_satellites.png"
0178                 title: xi18n("Satellites")
0179 
0180                 toggled: KStarsLite.isToggled(ObjectsToToggle.Satellites)
0181                 onClicked: {
0182                     KStarsLite.toggleObjects(ObjectsToToggle.Satellites, toggled)
0183                 }
0184             }
0185             TopMenuButton {
0186                 iconSrc: "../../images/kstars_clines.png"
0187                 title: xi18n("Constellation Lines")
0188 
0189                 toggled: KStarsLite.isToggled(ObjectsToToggle.CLines)
0190                 onClicked: {
0191                     KStarsLite.toggleObjects(ObjectsToToggle.CLines, toggled)
0192                 }
0193             }
0194             TopMenuButton {
0195                 iconSrc: "../../images/kstars_cnames.png"
0196                 title: xi18n("Constellation Names")
0197 
0198                 toggled: KStarsLite.isToggled(ObjectsToToggle.CNames)
0199                 onClicked: {
0200                     KStarsLite.toggleObjects(ObjectsToToggle.CNames, toggled)
0201                 }
0202             }
0203 
0204             TopMenuButton {
0205                 iconSrc: "../../images/kstars_constellationart.png"
0206                 title: xi18n("Constellation Art")
0207                 titlePlural: false
0208 
0209                 toggled: KStarsLite.isToggled(ObjectsToToggle.ConstellationArt)
0210                 onClicked: {
0211                     KStarsLite.toggleObjects(ObjectsToToggle.ConstellationArt, toggled)
0212                 }
0213             }
0214 
0215             TopMenuButton {
0216                 iconSrc: "../../images/kstars_cbound.png"
0217                 title: xi18n("Constellation Bounds")
0218 
0219                 toggled: KStarsLite.isToggled(ObjectsToToggle.CBounds)
0220                 onClicked: {
0221                     KStarsLite.toggleObjects(ObjectsToToggle.CBounds, toggled)
0222                 }
0223             }
0224             TopMenuButton {
0225                 iconSrc: "../../images/kstars_mw.png"
0226                 title: xi18n("Milky Way")
0227                 titlePlural: false
0228 
0229                 toggled: KStarsLite.isToggled(ObjectsToToggle.MilkyWay)
0230                 onClicked: {
0231                     KStarsLite.toggleObjects(ObjectsToToggle.MilkyWay, toggled)
0232                 }
0233             }
0234             TopMenuButton {
0235                 iconSrc: "../../images/kstars_grid.png"
0236                 title: xi18n("Equatorial Grid")
0237                 titlePlural: false
0238 
0239                 toggled: KStarsLite.isToggled(ObjectsToToggle.EquatorialGrid)
0240                 onClicked: {
0241                     KStarsLite.toggleObjects(ObjectsToToggle.EquatorialGrid, toggled)
0242                 }
0243             }
0244             TopMenuButton {
0245                 iconSrc: "../../images/kstars_hgrid.png"
0246                 title: xi18n("Horizontal Grid")
0247                 titlePlural: false
0248 
0249                 toggled: KStarsLite.isToggled(ObjectsToToggle.HorizontalGrid)
0250                 onClicked: {
0251                     KStarsLite.toggleObjects(ObjectsToToggle.HorizontalGrid, toggled)
0252                 }
0253             }
0254             TopMenuButton {
0255                 iconSrc: "../../images/kstars_horizon.png"
0256                 title: xi18n("Horizon")
0257                 titlePlural: false
0258 
0259                 toggled: KStarsLite.isToggled(ObjectsToToggle.Ground)
0260                 onClicked: {
0261                     KStarsLite.toggleObjects(ObjectsToToggle.Ground, toggled)
0262                 }
0263             }
0264         }
0265     }
0266 
0267     Image {
0268         id: arrowDown
0269         anchors {
0270             horizontalCenter: parent.horizontalCenter
0271         }
0272         state: "open"
0273         source: "../images/arrow.png"
0274         rotation: {
0275             if(topMenu.state == "closed")
0276                 return 180
0277             else if(topMenu.state == "open")
0278                 return 0
0279             return rotation //If it state is "hidden" return current rotation
0280         }
0281 
0282         MouseArea {
0283             objectName: "arrowDownMouseArea"
0284             anchors.fill: parent
0285             onPressed: {
0286                 topMenu.state = topMenu.state == "closed" ? "open" : "closed"
0287             }
0288             function manualPress() {
0289                 onPressed(1);
0290             }
0291         }
0292 
0293         Behavior on rotation {
0294             RotationAnimation {
0295                 duration: 200; direction: RotationAnimation.Counterclockwise
0296             }
0297         }
0298     }
0299 }