Replace tons of hardcoded stuff
This commit is contained in:
commit
c075b89dd2
2 changed files with 59 additions and 91 deletions
|
|
@ -27,82 +27,11 @@ ColumnLayout {
|
||||||
// Cache for scheme colors
|
// Cache for scheme colors
|
||||||
property var schemeColorsCache: ({})
|
property var schemeColorsCache: ({})
|
||||||
|
|
||||||
// Array to hold FileView objects
|
|
||||||
property var fileViews: []
|
|
||||||
|
|
||||||
// Scale properties for card animations
|
// Scale properties for card animations
|
||||||
property real cardScaleLow: 0.95
|
property real cardScaleLow: 0.95
|
||||||
property real cardScaleHigh: 1.0
|
property real cardScaleHigh: 1.0
|
||||||
|
|
||||||
// Load color scheme data when schemes are available
|
// This function is called by the FileView Repeater when a scheme file is loaded
|
||||||
Connections {
|
|
||||||
target: ColorSchemes
|
|
||||||
function onSchemesChanged() {
|
|
||||||
loadSchemeColors()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadSchemeColors() {
|
|
||||||
// Clear existing cache
|
|
||||||
schemeColorsCache = {}
|
|
||||||
|
|
||||||
// Destroy existing FileViews
|
|
||||||
for (var i = 0; i < fileViews.length; i++) {
|
|
||||||
if (fileViews[i]) {
|
|
||||||
fileViews[i].destroy()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fileViews = []
|
|
||||||
|
|
||||||
// Create FileViews for each scheme
|
|
||||||
for (var i = 0; i < ColorSchemes.schemes.length; i++) {
|
|
||||||
var schemePath = ColorSchemes.schemes[i]
|
|
||||||
var schemeName = schemePath.split("/").pop().replace(".json", "")
|
|
||||||
|
|
||||||
// Create FileView component
|
|
||||||
var component = Qt.createComponent("SchemeFileView.qml")
|
|
||||||
if (component.status === Component.Ready) {
|
|
||||||
var fileView = component.createObject(root, {
|
|
||||||
"path": schemePath,
|
|
||||||
"schemeName": schemeName
|
|
||||||
})
|
|
||||||
fileViews.push(fileView)
|
|
||||||
} else {
|
|
||||||
// Fallback: create inline FileView
|
|
||||||
createInlineFileView(schemePath, schemeName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createInlineFileView(schemePath, schemeName) {
|
|
||||||
var fileViewQml = `
|
|
||||||
import QtQuick
|
|
||||||
import Quickshell.Io
|
|
||||||
|
|
||||||
FileView {
|
|
||||||
property string schemeName: "${schemeName}"
|
|
||||||
path: "${schemePath}"
|
|
||||||
blockLoading: true
|
|
||||||
|
|
||||||
onLoaded: {
|
|
||||||
try {
|
|
||||||
var jsonData = JSON.parse(text())
|
|
||||||
root.schemeLoaded(schemeName, jsonData)
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Failed to parse JSON for scheme:", schemeName, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
try {
|
|
||||||
var fileView = Qt.createQmlObject(fileViewQml, root, "dynamicFileView_" + schemeName)
|
|
||||||
fileViews.push(fileView)
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Failed to create FileView for scheme:", schemeName, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function schemeLoaded(schemeName, jsonData) {
|
function schemeLoaded(schemeName, jsonData) {
|
||||||
var colors = {}
|
var colors = {}
|
||||||
|
|
||||||
|
|
@ -116,7 +45,7 @@ ColumnLayout {
|
||||||
colors.mOnSurface = jsonData.mOnSurface || jsonData.onSurface || "#000000"
|
colors.mOnSurface = jsonData.mOnSurface || jsonData.onSurface || "#000000"
|
||||||
colors.mOutline = jsonData.mOutline || jsonData.outline || "#666666"
|
colors.mOutline = jsonData.mOutline || jsonData.outline || "#666666"
|
||||||
} else {
|
} else {
|
||||||
// Default colors
|
// Default colors on failure
|
||||||
colors = {
|
colors = {
|
||||||
"mPrimary": "#000000",
|
"mPrimary": "#000000",
|
||||||
"mSecondary": "#000000",
|
"mSecondary": "#000000",
|
||||||
|
|
@ -128,12 +57,50 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cache
|
// Update the cache. This must be done by re-assigning the whole object to trigger updates.
|
||||||
var newCache = schemeColorsCache
|
var newCache = schemeColorsCache
|
||||||
newCache[schemeName] = colors
|
newCache[schemeName] = colors
|
||||||
schemeColorsCache = newCache
|
schemeColorsCache = newCache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When the list of available schemes changes, clear the cache.
|
||||||
|
// The Repeater below will automatically re-create the FileViews.
|
||||||
|
Connections {
|
||||||
|
target: ColorSchemes
|
||||||
|
function onSchemesChanged() {
|
||||||
|
schemeColorsCache = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A non-visual Item to host the Repeater that loads the color scheme files.
|
||||||
|
Item {
|
||||||
|
visible: false
|
||||||
|
id: fileLoaders
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: ColorSchemes.schemes
|
||||||
|
|
||||||
|
// The delegate is a Component, which correctly wraps the non-visual FileView
|
||||||
|
delegate: Item {
|
||||||
|
FileView {
|
||||||
|
path: modelData
|
||||||
|
blockLoading: true
|
||||||
|
onLoaded: {
|
||||||
|
var schemeName = path.split("/").pop().replace(".json", "")
|
||||||
|
try {
|
||||||
|
var jsonData = JSON.parse(text())
|
||||||
|
root.schemeLoaded(schemeName, jsonData)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Failed to parse JSON for scheme:", schemeName, e)
|
||||||
|
root.schemeLoaded(schemeName, null) // Load defaults on parse error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI Code
|
||||||
ScrollView {
|
ScrollView {
|
||||||
id: scrollView
|
id: scrollView
|
||||||
|
|
||||||
|
|
@ -214,6 +181,9 @@ ColumnLayout {
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: schemeCard
|
id: schemeCard
|
||||||
|
|
||||||
|
property string schemePath: modelData
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: 120 * scaling
|
Layout.preferredHeight: 120 * scaling
|
||||||
radius: Style.radiusMedium * scaling
|
radius: Style.radiusMedium * scaling
|
||||||
|
|
@ -222,8 +192,6 @@ ColumnLayout {
|
||||||
border.color: Settings.data.colorSchemes.predefinedScheme === modelData ? Colors.mPrimary : Colors.mOutline
|
border.color: Settings.data.colorSchemes.predefinedScheme === modelData ? Colors.mPrimary : Colors.mOutline
|
||||||
scale: root.cardScaleLow
|
scale: root.cardScaleLow
|
||||||
|
|
||||||
property string schemePath: modelData
|
|
||||||
|
|
||||||
// Mouse area for selection
|
// Mouse area for selection
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
@ -260,7 +228,7 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
font.pointSize: Style.fontSizeMedium * scaling
|
font.pointSize: Style.fontSizeMedium * scaling
|
||||||
font.weight: Style.fontWeightBold
|
font.weight: Style.fontWeightBold
|
||||||
color: Colors.mOnSurface
|
color: getSchemeColor(modelData, "mOnSurface")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
|
@ -284,7 +252,7 @@ ColumnLayout {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: 28 * scaling
|
width: 28 * scaling
|
||||||
height: 28 * scaling
|
height: 28 * scaling
|
||||||
radius: Style.radiusSmall * scaling
|
radius: width * 0.5
|
||||||
color: getSchemeColor(modelData, "mSecondary")
|
color: getSchemeColor(modelData, "mSecondary")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue