Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. /*
  2. * Copyright 2013 Marco Martin <mart@kde.org>
  3. * Copyright 2014 Sebastian Kügler <sebas@kde.org>
  4. * Copyright 2014 Kai Uwe Broulik <kde@privat.broulik.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
  19. */
  20.  
  21. import QtQuick 2.5
  22. import QtQuick.Controls 2.1 as QQC2
  23. import QtQuick.Window 2.2
  24. import QtGraphicalEffects 1.0
  25. import org.kde.plasma.wallpapers.image 2.0 as Wallpaper
  26. import org.kde.plasma.core 2.0 as PlasmaCore
  27.  
  28. Item {
  29. id: trueroot
  30. QQC2.StackView {
  31. id: root
  32. anchors.fill: parent
  33. readonly property string modelImage: imageWallpaper.wallpaperPath
  34. readonly property string configuredImage: wallpaper.configuration.Image
  35. readonly property int fillMode: wallpaper.configuration.FillMode
  36. readonly property string configColor: wallpaper.configuration.Color
  37. readonly property bool blur: wallpaper.configuration.Blur
  38. readonly property size sourceSize: Qt.size(root.width * Screen.devicePixelRatio, root.height * Screen.devicePixelRatio)
  39.  
  40. //public API, the C++ part will look for those
  41. function setUrl(url) {
  42. wallpaper.configuration.Image = url
  43. imageWallpaper.addUsersWallpaper(url);
  44. }
  45.  
  46. function action_next() {
  47. imageWallpaper.nextSlide();
  48. }
  49.  
  50. function action_open() {
  51. Qt.openUrlExternally(modelImage)
  52. }
  53.  
  54. //private
  55.  
  56. onConfiguredImageChanged: {
  57. if (modelImage != configuredImage && configuredImage != "") {
  58. imageWallpaper.addUrl(configuredImage);
  59. }
  60. }
  61. Component.onCompleted: {
  62. wallpaper.loading = true; // delays ksplash until the wallpaper has been loaded
  63.  
  64. if (wallpaper.pluginName === "org.kde.slideshow") {
  65. wallpaper.setAction("open", i18nd("plasma_wallpaper_org.kde.image", "Open Wallpaper Image"), "document-open");
  66. wallpaper.setAction("next", i18nd("plasma_wallpaper_org.kde.image", "Next Wallpaper Image"), "user-desktop");
  67. }
  68. }
  69.  
  70. Wallpaper.Image {
  71. id: imageWallpaper
  72. //the oneliner of difference between image and slideshow wallpapers
  73. renderingMode: (wallpaper.pluginName === "org.kde.image") ? Wallpaper.Image.SingleImage : Wallpaper.Image.SlideShow
  74. targetSize: root.sourceSize
  75. slidePaths: wallpaper.configuration.SlidePaths
  76. slideTimer: wallpaper.configuration.SlideInterval
  77. slideshowMode: wallpaper.configuration.SlideshowMode
  78. uncheckedSlides: wallpaper.configuration.UncheckedSlides
  79. }
  80.  
  81. onFillModeChanged: Qt.callLater(loadImage);
  82. onModelImageChanged:{
  83. Qt.callLater(loadImage);
  84. wallpaper.configuration.Image = modelImage;
  85. }
  86. onConfigColorChanged: Qt.callLater(loadImage);
  87. onBlurChanged: Qt.callLater(loadImage);
  88. onWidthChanged: Qt.callLater(loadImage);
  89. onHeightChanged: Qt.callLater(loadImage);
  90.  
  91. function loadImage() {
  92. var isFirst = (root.currentItem == undefined);
  93. var pendingImage = baseImage.createObject(root, { "source": root.modelImage,
  94. "fillMode": root.fillMode,
  95. "sourceSize": root.sourceSize,
  96. "color": root.configColor,
  97. "blur": root.blur,
  98. "opacity": isFirst ? 1: 0});
  99.  
  100. function replaceWhenLoaded() {
  101. if (pendingImage.status !== Image.Loading) {
  102. root.replace(pendingImage, {},
  103. isFirst ? QQC2.StackView.Immediate : QQC2.StackView.Transition);//dont' animate first show
  104. pendingImage.statusChanged.disconnect(replaceWhenLoaded);
  105.  
  106. wallpaper.loading = false;
  107. }
  108. }
  109. pendingImage.statusChanged.connect(replaceWhenLoaded);
  110. replaceWhenLoaded();
  111. }
  112.  
  113. Component {
  114. id: baseImage
  115.  
  116. Image {
  117. id: mainImage
  118.  
  119. property alias color: backgroundColor.color
  120. property bool blur: false
  121.  
  122. asynchronous: true
  123. cache: false
  124. autoTransform: true
  125. z: -1
  126.  
  127. QQC2.StackView.onRemoved: destroy()
  128.  
  129. Rectangle {
  130. id: backgroundColor
  131. anchors.fill: parent
  132. visible: mainImage.status === Image.Ready && !blurLoader.active
  133. z: -2
  134. }
  135.  
  136. Loader {
  137. id: blurLoader
  138. anchors.fill: parent
  139. z: -3
  140. active: mainImage.blur && (mainImage.fillMode === Image.PreserveAspectFit || mainImage.fillMode === Image.Pad)
  141. sourceComponent: Item {
  142. Image {
  143. id: blurSource
  144. anchors.fill: parent
  145. asynchronous: true
  146. cache: false
  147. autoTransform: true
  148. fillMode: Image.PreserveAspectCrop
  149. source: mainImage.source
  150. sourceSize: mainImage.sourceSize
  151. visible: false // will be rendered by the blur
  152. }
  153.  
  154. GaussianBlur {
  155. id: blurEffect
  156. anchors.fill: parent
  157. source: blurSource
  158. radius: 32
  159. samples: 65
  160. visible: blurSource.status === Image.Ready
  161. }
  162. }
  163. }
  164. }
  165. }
  166.  
  167. replaceEnter: Transition {
  168. OpacityAnimator {
  169. from: 0
  170. to: 1
  171. duration: wallpaper.configuration.TransitionAnimationDuration
  172. }
  173. }
  174. // Keep the old image around till the new one is fully faded in
  175. // If we fade both at the same time you can see the background behind glimpse through
  176. replaceExit: Transition{
  177. PauseAnimation {
  178. duration: wallpaper.configuration.TransitionAnimationDuration
  179. }
  180. }
  181. }
  182. }
  183.  
  184. FastBlur {
  185. radius: 40
  186. anchors.fill: trueroot
  187. source: trueroot
  188.  
  189. Behavior on radius {
  190. NumberAnimation { duration: 400 }
  191. }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement