Advertisement
neochapay

Untitled

Jan 27th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. /****************************************************************************************
  2. **
  3. ** Copyright (C) 2019-2021 Chupligin Sergey <neochapay@gmail.com>
  4. ** All rights reserved.
  5. **
  6. ** You may use this file under the terms of BSD license as follows:
  7. **
  8. ** Redistribution and use in source and binary forms, with or without
  9. ** modification, are permitted provided that the following conditions are met:
  10. ** * Redistributions of source code must retain the above copyright
  11. ** notice, this list of conditions and the following disclaimer.
  12. ** * Redistributions in binary form must reproduce the above copyright
  13. ** notice, this list of conditions and the following disclaimer in the
  14. ** documentation and/or other materials provided with the distribution.
  15. ** * Neither the name of the author nor the
  16. ** names of its contributors may be used to endorse or promote products
  17. ** derived from this software without specific prior written permission.
  18. **
  19. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
  23. ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. **
  30. ****************************************************************************************/
  31.  
  32.  
  33. import QtQuick 2.6
  34. import Nemo.Mce 1.0
  35.  
  36. import Nemo.Configuration 1.0
  37.  
  38. StatusbarItem {
  39. id: batteryIndicator
  40. property int chargeValue: 0
  41.  
  42. width: statusbarRight.height*2
  43. iconSize: statusbarRight.height*2
  44. iconSizeHeight: statusbarRight.height
  45.  
  46. MceBatteryLevel {
  47. id: batteryChargePercentage
  48.  
  49. onPercentChanged: {
  50. chargeIcon();
  51. }
  52. }
  53.  
  54. MceBatteryState {
  55. id: batteryChargeState
  56.  
  57. onStateChanged: {
  58. if(state === MceBatteryState.Charging) {
  59. chargingTimer.start()
  60. pluginIndicator.visible = true
  61. } else {
  62. chargingTimer.stop()
  63. pluginIndicator.visible = false
  64. chargeIcon();
  65. }
  66. }
  67. }
  68.  
  69. MceBatteryStatus{
  70. id: batteryStatus
  71. }
  72.  
  73. source: "/usr/share/lipstick-glacier-home-qt5/qml/theme/battery"+chargeValue+".png"
  74.  
  75. Image {
  76. width: parent.width
  77. height: parent.height
  78. anchors.centerIn: parent
  79. source: "/usr/share/lipstick-glacier-home-qt5/qml/theme/battery_grid.png"
  80. layer.effect: ColoredIconEffect{
  81. color: if(batteryStatus.status === MceBatteryStatus.Ok) {
  82. Theme.textColor
  83. } else if (batteryStatus.status === MceBatteryStatus.Full) {
  84. Theme.accentColor
  85. } else {
  86. "red"
  87. }
  88. }
  89.  
  90. layer.enabled: true
  91. layer.samplerName: "source"
  92. }
  93.  
  94. Image {
  95. id: pluginIndicator
  96. width: parent.width
  97. height: parent.height
  98. anchors.centerIn: parent
  99.  
  100. source: "image://theme/plug"
  101. fillMode: Image.PreserveAspectFit
  102.  
  103. visible: false //cableState.connected
  104. }
  105.  
  106. Timer{
  107. id: chargingTimer
  108. interval: 500
  109. repeat: true
  110. running: false
  111. onTriggered: {
  112. if(batteryIndicator.chargeValue == 6)
  113. {
  114. batteryIndicator.chargeValue = 0
  115. }
  116. else
  117. {
  118. batteryIndicator.chargeValue++
  119. }
  120. }
  121. }
  122.  
  123. Component.onCompleted: {
  124. chargeIcon();
  125. }
  126.  
  127. function chargeIcon()
  128. {
  129. if(batteryChargePercentage.percent > 85) {
  130. batteryIndicator.chargeValue = 6
  131. } else if (batteryChargePercentage.percent <= 5) {
  132. batteryIndicator.chargeValue = 0
  133. } else if (batteryChargePercentage.percent <= 10) {
  134. batteryIndicator.chargeValue = 1
  135. } else if (batteryChargePercentage.percent <= 25) {
  136. batteryIndicator.chargeValue = 2
  137. } else if (batteryChargePercentage.percent <= 40) {
  138. batteryIndicator.chargeValue = 3
  139. } else if (batteryChargePercentage.percent <= 65) {
  140. batteryIndicator.chargeValue = 4
  141. } else if (batteryChargePercentage.percent <= 80) {
  142. batteryIndicator.chargeValue = 5
  143. } else {
  144. batteryIndicator.chargeValue = 6
  145. }
  146. }
  147.  
  148. }
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement