Advertisement
Guest User

KDE Plasma 5 lock screen with picture slideshow

a guest
May 27th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 KB | None | 0 0
  1. /********************************************************************
  2. This file is part of the KDE project.
  3.  
  4. Copyright (C) 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
  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, see <http://www.gnu.org/licenses/>.
  18. *********************************************************************/
  19.  
  20. import QtQuick 2.5
  21. import QtQuick.Controls 1.1
  22. import org.kde.plasma.core 2.0 as PlasmaCore
  23. import org.kde.plasma.private.sessions 2.0
  24. import "../components"
  25.  
  26. import Qt.labs.folderlistmodel 2.0
  27.  
  28. Image {
  29. id: root
  30.  
  31. property int slide_duration: 7000 //ms
  32. property int fade_duration: 800
  33. property variant current_img: img1
  34.  
  35. property bool viewVisible: false
  36. property bool debug: false
  37. property string notification
  38. property UserSelect userSelect: null
  39. property int interfaceVersion: org_kde_plasma_screenlocker_greeter_interfaceVersion ? org_kde_plasma_screenlocker_greeter_interfaceVersion : 0
  40. signal clearPassword()
  41.  
  42. source: backgroundPath || "../components/artwork/background.png"
  43. fillMode: Image.PreserveAspectCrop
  44. asynchronous: false
  45.  
  46. onStatusChanged: {
  47. if (status == Image.Error) {
  48. source = "../components/artwork/background.png";
  49. }
  50. }
  51.  
  52. Rectangle {
  53. id: show
  54. anchors.fill: parent
  55. color: "black"
  56.  
  57. focus: true
  58.  
  59. //Load 2 slides
  60. Loader {id:img1; transformOrigin: Item.TopLeft; sourceComponent: slide;}
  61. Loader {id:img2; transformOrigin: Item.TopLeft; sourceComponent: slide;}
  62.  
  63.  
  64. //Input images files
  65. FolderListModel{
  66. id: img_files
  67. folder : "file:///media/sda2/Background/Lock"
  68. nameFilters: ["*.jpg", "*.jpeg", "*.png"]
  69. showDirs : false
  70.  
  71. property int index: 0
  72. property variant rlist: []
  73.  
  74. function getNextUrl(){
  75. if(index >= rlist.length)
  76. shuffleList();
  77. return img_files.get(rlist[index++], "fileURL"); //filePath
  78. }
  79.  
  80. //Fisher-Yates shuffle algorithm.
  81. function shuffleArray(array) {
  82. for (var i = array.length - 1; i > 0; i--) {
  83. var j = Math.floor(Math.random() * (i + 1));
  84. var temp = array[i];
  85. array[i] = array[j];
  86. array[j] = temp;
  87. }
  88. return array;
  89. }
  90.  
  91. function shuffleList()
  92. {
  93. console.log("Shuffle...");
  94. var list = [];
  95. for(var i=0; i<img_files.count; i++)
  96. list.push(i);
  97. shuffleArray(list);
  98. rlist = list;
  99. index = 0;
  100. }
  101.  
  102. //Initialisation
  103. onDataChanged: {
  104. console.log(img_files.count+ " images found");
  105. shuffleList();
  106. //Force la lecture de la 1ere image
  107. img1.item.asynchronous = false
  108. img1.item.visible = true;
  109. img1.item.load_next_slide();
  110. img2.item.load_next_slide();
  111.  
  112. img1.item.asynchronous = true;
  113. mtimer.start();
  114. }
  115. }
  116.  
  117. //Main timer
  118. Timer{
  119. id:mtimer
  120. interval: slide_duration-fade_duration
  121. repeat: true
  122. triggeredOnStart : true
  123.  
  124. onTriggered: {
  125. current_img.item.fadein();
  126. current_img = (current_img == img1 ? img2 : img1); //Swap img
  127. current_img.item.fadeout();
  128. }
  129. }
  130.  
  131. //Slide component
  132. Component {
  133. id: slide
  134.  
  135. Image {
  136. id: img
  137. asynchronous : true
  138. cache: false
  139. fillMode: Image.PreserveAspectFit
  140. //visible: true
  141. opacity: 0
  142. width: root.width
  143. height: root.height
  144.  
  145. //Max painted size (RPI limitations)
  146. sourceSize.width: 1920
  147. sourceSize.height: 1600
  148.  
  149. property real from_scale: 1
  150. property real to_scale: 1
  151.  
  152. property real from_x: 0
  153. property real to_x: 0
  154.  
  155. property real from_y: 0
  156. property real to_y: 0
  157.  
  158. function randRange(a, b){return Math.random()*Math.abs(a-b) + Math.min(a,b);}
  159. function randChoice(n){return Math.round(Math.random()*(n-1));}
  160. function randDirection(){return (Math.random() >= 0.5) ? 1 : -1;}
  161.  
  162. function fadein(){
  163. //Check image loading...
  164. if(status != Image.Ready){
  165. console.log("LOAD ERROR", source);
  166. return;
  167. }
  168.  
  169. //Fit in view
  170. var img_ratio = paintedWidth/paintedHeight;
  171. var scale = (height == paintedHeight) ? width/paintedWidth : height/paintedHeight;
  172.  
  173. //Find random directions
  174. if(img_ratio < 1){ //Rotated
  175. from_scale = scale*0.8;//Un-zoom on 16/9 viewer...
  176. to_scale = from_scale;
  177. from_y = 0;
  178. to_y = 0;
  179. from_x = randDirection()*(paintedHeight*from_scale-height)/2;
  180. to_x = 0;
  181. }
  182. else if(img_ratio > 2){ //Panorama
  183. from_scale = scale;
  184. to_scale = from_scale;
  185. from_y = randDirection()*(paintedWidth*from_scale-width)/2;
  186. to_y = -from_y;
  187. from_x = 0;
  188. to_x = 0;
  189. }
  190. else { //Normal
  191. var type = randChoice(3);
  192. switch(type)
  193. {
  194. case 0: //Zoom in
  195. from_scale = scale;
  196. to_scale = scale*1.4;
  197. from_y = 0;
  198. to_y = 0;
  199. from_x = 0;
  200. to_x = 0;
  201. break;
  202. case 1: //Zoom out
  203. from_scale = scale*1.4;
  204. to_scale = scale;
  205. from_y = 0;
  206. to_y = 0;
  207. from_x = 0;
  208. to_x = 0;
  209. break;
  210. default: //Fixed zoom
  211. from_scale = scale*1.2;
  212. to_scale = from_scale;
  213. break;
  214. }
  215. //Random x,y
  216. var from_max_y = (paintedWidth*from_scale-width)/2;
  217. var to_max_y = (paintedWidth*to_scale-width)/2;
  218. from_y = randRange(-from_max_y, from_max_y);
  219. to_y = randRange(-to_max_y, to_max_y);
  220.  
  221. var from_max_x = (paintedHeight*from_scale-height)/2;
  222. var to_max_x = (paintedHeight*to_scale-height)/2;
  223. from_x = randRange(-from_max_x, from_max_x);
  224. to_x = randRange(-to_max_x, to_max_x);
  225. }
  226.  
  227. visible = true;
  228. afadein.start();
  229. }
  230.  
  231. function fadeout(){
  232. afadeout.start();
  233. }
  234.  
  235. function load_next_slide(){
  236. visible = false;
  237. source = img_files.getNextUrl();
  238. console.log(source);
  239. }
  240.  
  241. ParallelAnimation{
  242. id: afadein
  243. NumberAnimation {target: img; property: "opacity"; from: 0; to: 1; duration: fade_duration; easing.type: Easing.InOutQuad;}
  244. NumberAnimation {target: img; property: "y"; from: from_x; to: to_x; duration: slide_duration; }
  245. NumberAnimation {target: img; property: "x"; from: from_y; to: to_y; duration: slide_duration; }
  246. NumberAnimation {target: img; property: "scale"; from: from_scale; to: to_scale; duration: slide_duration; }
  247. }
  248.  
  249. SequentialAnimation {
  250. id: afadeout;
  251. NumberAnimation{ target: img; property: "opacity"; from: 1; to: 0; duration: fade_duration; easing.type: Easing.InOutQuad;}
  252. ScriptAction { script: img.load_next_slide(); }
  253. }
  254. }
  255. }
  256. }
  257.  
  258. LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
  259. LayoutMirroring.childrenInherit: true
  260.  
  261.  
  262. Loader {
  263. id: mainLoader
  264. anchors.fill: parent
  265. opacity: 0
  266. onItemChanged: opacity = 1
  267.  
  268. Behavior on opacity {
  269. OpacityAnimator {
  270. duration: units.longDuration
  271. easing.type: Easing.InCubic
  272. }
  273. }
  274. }
  275. Connections {
  276. id:loaderConnection
  277. target: org_kde_plasma_screenlocker_greeter_view
  278. onFrameSwapped: {
  279. mainLoader.source = "LockScreenUi.qml";
  280. loaderConnection.target = null;
  281. }
  282. }
  283. Component.onCompleted: {
  284. if (root.interfaceVersion < 2) {
  285. mainLoader.source = "LockScreenUi.qml";
  286. }
  287. }
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement