Kstars

TopMenuButton.qml
1 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
2 // SPDX-License-Identifier: GPL-2.0-or-later
3 
4 import QtQuick 2.6
5 import QtQuick.Controls 2.0
6 import QtGraphicalEffects 1.0
7 import "../../constants/" 1.0
8 
9 AbstractButton {
10  id: button
11  property string iconSrc: ""
12  width: icon.width + 5
13  height: icon.height + 5
14  property bool toggled: false
15  opacity: toggled ? 1 : 0.3
16 
17  property string title: " "
18  property bool titlePlural: true
19 
20  onClicked: {
21  toggled = !toggled
22  }
23 
24  onToggledChanged: {
25  if(isLoaded) { //Disable while loading
26  if(toggled) {
27  if(titlePlural) {
28  skyMapLite.notification.showNotification(xi18n("%1 are toggled on", title))
29  } else {
30  skyMapLite.notification.showNotification(xi18n("%1 is toggled on", title))
31  }
32  } else {
33  if(titlePlural) {
34  skyMapLite.notification.showNotification(xi18n("%1 are toggled off", title))
35  } else {
36  skyMapLite.notification.showNotification(xi18n("%1 is toggled off", title))
37  }
38  }
39  }
40  }
41 
42  DropShadow {
43  anchors.fill: iconRect
44  radius: 8.0
45  samples: 16
46  horizontalOffset: 0
47  verticalOffset: 0
48  color: "#000000"
49  source: iconRect
50  opacity: pressed ? 1 : 0
51 
52  Behavior on opacity {
53  OpacityAnimator { duration: 100 }
54  }
55  }
56 
57  Image {
58  id: icon
59  source: iconSrc
60  width: sourceSize.width/Num.pixelRatio //FIX /Num.pixelRatio we don't need it here!
61  height: sourceSize.height/Num.pixelRatio
62  anchors.centerIn: iconRect
63  }
64 
65  background: Rectangle {
66  id: iconRect
67  radius: 5
68  anchors {
69  fill: parent
70  }
71  color: "black"
72  border {
73  color: toggled ? Num.sysPalette.highlight : "grey"
74  width: 1
75  }
76  }
77 
78  onDownChanged: {
79  /*if(down) opacity = 0.6
80  else opacity = 1*/
81  }
82 
83  onPressed: {
84  //opacity = 0.6
85  }
86 
87  onReleased: {
88  //opacity = 1
89  }
90 
91  Behavior on opacity {
92  OpacityAnimator { duration: 100 }
93  }
94 }
QString xi18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.