11import QtQuick
22import QtQuick.Window
3- import QtQuick.Layouts
4- import QtQuick.Controls
53
64/*
75 * Preview.qml - Development harness for the SDDM theme.
86 *
9- * Provides mock objects in place of the SDDM context properties, then loads
10- * the theme layout through a Loader. A file-watcher timer detects changes
11- * (via a signal file touched by entr) and reloads the Loader in-place ,
12- * keeping the window open for a true live-preview experience .
7+ * A thin window shell that loads the theme's Main.qml via a Loader.
8+ * Mock SDDM context properties (sddm, config, userModel, sessionModel,
9+ * keyboard) are injected by preview-host.py as engine context properties ,
10+ * so Main.qml works identically here and under the real SDDM greeter .
1311 *
1412 * Usage: ./scripts/preview.sh [-theme <name>]
1513 */
@@ -21,113 +19,26 @@ Window {
2119 visible: true
2220 title: " KDE Lockscreen Builder — Preview"
2321
24- // ═══════════════════════════════════════════════════════════════
25- // Mock objects
26- // ═══════════════════════════════════════════════════════════════
27-
28- property QtObject mockConfig: QtObject {
29- property string background: Qt .resolvedUrl (" assets/background.jpg" )
30- property string type: " image"
31- property string color: " #1a1a2e"
32- property string primaryColor: " #ffffff"
33- property string accentColor: " #4a9eff"
34- property string backgroundOverlayColor: " #000000"
35- property real backgroundOverlayOpacity: 0.3
36- property string fontFamily: " "
37- property int fontPointSize: 12
38- property string clockVisible: " true"
39- property string clockFormat: " hh:mm"
40- property string dateFormat: " dddd, MMMM d"
41- property int screenWidth: previewWindow .width
42- property int screenHeight: previewWindow .height
43- }
44-
45- property QtObject mockSddm: QtObject {
46- property string hostname: " preview-host"
47- property bool canPowerOff: true
48- property bool canReboot: true
49- property bool canSuspend: true
50- property bool canHibernate: true
51- property bool canHybridSleep: false
52-
53- signal loginFailed ()
54- signal loginSucceeded ()
55-
56- function login (user , password , sessionIndex ) {
57- console .log (" [mock] sddm.login:" , user, " session:" , sessionIndex)
58- if (password === " test" ) {
59- console .log (" [mock] Login succeeded" )
60- loginSucceeded ()
61- } else {
62- console .log (" [mock] Login failed (use 'test' as password)" )
63- loginFailed ()
64- }
65- }
66- function powerOff () { console .log (" [mock] sddm.powerOff()" ) }
67- function reboot () { console .log (" [mock] sddm.reboot()" ) }
68- function suspend () { console .log (" [mock] sddm.suspend()" ) }
69- function hibernate () { console .log (" [mock] sddm.hibernate()" ) }
70- function hybridSleep () { console .log (" [mock] sddm.hybridSleep()" ) }
71- }
72-
73- property ListModel mockUserModel: ListModel {
74- property string lastUser: " user"
75- property int lastIndex: 0
76- property int disableAvatarsThreshold: 7
77- property bool containsAllUsers: true
78-
79- ListElement { name: " user" ; realName: " User" ; icon: " " ; needsPassword: true }
80- ListElement { name: " guest" ; realName: " Guest User" ; icon: " " ; needsPassword: true }
81- }
82-
83- property ListModel mockSessionModel: ListModel {
84- property int lastIndex: 0
85-
86- ListElement { name: " Plasma (Wayland)" ; comment: " " }
87- ListElement { name: " Plasma (X11)" ; comment: " " }
88- ListElement { name: " GNOME" ; comment: " " }
89- }
90-
91- property QtObject mockKeyboard: QtObject {
92- property bool capsLock: false
93- property bool numLock: true
94- }
95-
96- // ═══════════════════════════════════════════════════════════════
97- // Derived properties (mirrors Main.qml logic)
98- // ═══════════════════════════════════════════════════════════════
99-
100- property string notificationMessage: " "
101- property int baseFontSize: mockConfig .fontPointSize || 12
102- property string fontFamily: mockConfig .fontFamily || " "
103- property color primaryColor: mockConfig .primaryColor || " #ffffff"
104- property color accentColor: mockConfig .accentColor || " #4a9eff"
22+ // Keep config.screenWidth/Height in sync with this window's dimensions
23+ onWidthChanged: config .screenWidth = width
24+ onHeightChanged: config .screenHeight = height
10525
10626 // ═══════════════════════════════════════════════════════════════
10727 // Hot-reload Loader
10828 // ═══════════════════════════════════════════════════════════════
10929
110- // Hot-reload: `hotReloader` is a context property injected by
111- // preview-host.py. Reload is a 3-phase process orchestrated by Python:
112- // 1. unloadRequested → QML destroys all component instances
113- // 2. Python clears the now-unreferenced component cache
114- // 3. reloadRequested → QML reloads components from disk
115- //
116- // When hotReloader is not present (e.g. launched via plain qml6),
117- // the theme loads once without hot-reload.
118-
11930 Loader {
12031 id: themeLoader
12132 anchors .fill : parent
12233
12334 onStatusChanged: {
12435 if (status === Loader .Error )
125- console .log (" [hot-reload] Error loading ThemeLayout .qml — check for syntax errors" )
36+ console .log (" [hot-reload] Error loading Main .qml — check for syntax errors" )
12637 }
12738 }
12839
12940 function loadTheme () {
130- themeLoader .setSource (" ThemeLayout .qml" , { " preview " : previewWindow } )
41+ themeLoader .setSource (" Main .qml" )
13142 }
13243
13344 function unloadTheme () {
@@ -140,7 +51,11 @@ Window {
14051 function onReloadRequested () { previewWindow .loadTheme () }
14152 }
14253
143- Component .onCompleted : loadTheme ()
54+ Component .onCompleted : {
55+ config .screenWidth = width
56+ config .screenHeight = height
57+ loadTheme ()
58+ }
14459
14560 // ── Preview overlay ──────────────────────────────────────────
14661 Rectangle {
0 commit comments