1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 15:32:50 -05:00

General code cleanups

This commit is contained in:
bbedward
2025-08-02 16:18:12 -04:00
parent 2cf7497324
commit 599118c63e
68 changed files with 102 additions and 1241 deletions

View File

@@ -29,7 +29,6 @@ Image {
}
onCachePathChanged: {
if (imageHash && cachePath) {
// Ensure cache directory exists before trying to load from cache
Paths.mkdir(Paths.imagecache);
source = cachePath;
}

View File

@@ -5,8 +5,6 @@ import qs.Common
import qs.Widgets
Rectangle {
// Force recreate popup when component becomes visible
id: root
property string text: ""
@@ -26,7 +24,6 @@ Rectangle {
radius: Theme.cornerRadius
color: Theme.surfaceHover
Component.onCompleted: {
// Force a small delay to ensure proper initialization
forceRecreateTimer.start();
}
Component.onDestruction: {
@@ -104,7 +101,6 @@ Rectangle {
popup.close();
} else if (popup) {
var pos = dropdown.mapToItem(Overlay.overlay, 0, dropdown.height + 4);
// Center the wider popup over the dropdown button
popup.x = pos.x - (root.popupWidthOffset / 2);
popup.y = pos.y;
popup.open();
@@ -112,7 +108,6 @@ Rectangle {
}
}
// Use a Row for the left-aligned content (icon + text)
Row {
id: contentRow
@@ -135,14 +130,12 @@ Rectangle {
text: root.currentValue
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
// Constrain width for proper eliding
width: dropdown.width - contentRow.x - expandIcon.width - Theme.spacingM - Theme.spacingS
elide: Text.ElideRight
}
}
// Anchor the expand icon to the right, outside of the Row
DankIcon {
id: expandIcon
@@ -163,7 +156,6 @@ Rectangle {
active: true
onRecreateFlagChanged: {
// Force recreation by toggling active
active = false;
active = true;
}
@@ -241,7 +233,6 @@ Rectangle {
anchors.fill: parent
anchors.margins: Theme.spacingS
// Search field
Rectangle {
id: searchContainer

View File

@@ -29,7 +29,6 @@ GridView {
signal itemClicked(int index, var modelData)
signal itemHovered(int index)
// Ensure the current item is visible
function ensureVisible(index) {
if (index < 0 || index >= gridView.count)
return ;
@@ -157,7 +156,6 @@ GridView {
itemHovered(index);
}
onPositionChanged: {
// Signal parent to reset keyboard navigation flag when mouse moves
keyboardNavigationReset();
}
onClicked: {

View File

@@ -18,7 +18,6 @@ StyledText {
color: Theme.surfaceText
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
// Material Icons variable font axes support
font.variableAxes: ({
"FILL": fill.toFixed(1),
"GRAD": grade,
@@ -26,7 +25,6 @@ StyledText {
"wght": weight
})
// Smooth transitions for variable axes
Behavior on fill {
NumberAnimation {
duration: Appearance.anim.durations.quick

View File

@@ -20,7 +20,6 @@ ListView {
signal itemClicked(int index, var modelData)
signal itemHovered(int index)
// Ensure the current item is visible
function ensureVisible(index) {
if (index < 0 || index >= count)
return ;
@@ -156,7 +155,6 @@ ListView {
itemHovered(index);
}
onPositionChanged: {
// Signal parent to reset keyboard navigation flag when mouse moves
keyboardNavigationReset();
}
onClicked: {

View File

@@ -21,7 +21,6 @@ Column {
width: parent.width
spacing: Theme.spacingM
// Header
Row {
width: parent.width
spacing: Theme.spacingM
@@ -48,7 +47,6 @@ Column {
}
// Widget Items
Column {
id: itemsList
@@ -252,7 +250,6 @@ Column {
}
// Add Widget Control
Rectangle {
width: 200
height: 40

View File

@@ -1,277 +0,0 @@
import QtQuick
import QtQuick.Controls
import qs.Common
import qs.Widgets
Column {
id: root
property var items: []
property var allWidgets: []
property string title: ""
property string titleIcon: "widgets"
property string sectionId: ""
signal itemEnabledChanged(string itemId, bool enabled)
signal itemOrderChanged(var newOrder)
signal addWidget(string sectionId)
signal removeLastWidget(string sectionId)
width: parent.width
spacing: Theme.spacingM
// Header
Row {
width: parent.width
spacing: Theme.spacingM
DankIcon {
name: root.titleIcon
size: Theme.iconSize
color: Theme.primary
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: root.title
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Medium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
Item {
width: parent.width - 60
height: 1
}
}
// Widget Items
Column {
id: itemsList
width: parent.width
spacing: Theme.spacingS
Repeater {
model: root.items
delegate: Item {
id: delegateItem
property int visualIndex: index
property bool held: dragArea.pressed
property string itemId: modelData.id
width: itemsList.width
height: 70
z: held ? 2 : 1
Rectangle {
id: itemBackground
anchors.fill: parent
anchors.margins: 2
radius: Theme.cornerRadius
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 0.8)
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
border.width: 1
Row {
anchors.fill: parent
anchors.margins: Theme.spacingM
spacing: Theme.spacingM
// Drag handle
Rectangle {
width: 40
height: parent.height
color: "transparent"
anchors.verticalCenter: parent.verticalCenter
DankIcon {
name: "drag_indicator"
size: Theme.iconSize - 4
color: Theme.outline
anchors.centerIn: parent
opacity: 0.8
}
}
// Widget icon
DankIcon {
name: modelData.icon
size: Theme.iconSize
color: modelData.enabled ? Theme.primary : Theme.outline
anchors.verticalCenter: parent.verticalCenter
}
// Widget info
Column {
anchors.verticalCenter: parent.verticalCenter
spacing: 2
width: parent.width - 200 // Leave space for toggle
StyledText {
text: modelData.text
font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Medium
color: modelData.enabled ? Theme.surfaceText : Theme.outline
elide: Text.ElideRight
width: parent.width
}
StyledText {
text: modelData.description
font.pixelSize: Theme.fontSizeSmall
color: modelData.enabled ? Theme.outline : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.6)
elide: Text.ElideRight
width: parent.width
wrapMode: Text.WordWrap
}
}
// Spacer to push toggle to right
Item {
width: parent.width - 280 // Dynamic width
height: 1
}
// Toggle - positioned at right edge
DankToggle {
anchors.verticalCenter: parent.verticalCenter
width: 48
height: 24
hideText: true
checked: modelData.enabled
onToggled: (checked) => {
root.itemEnabledChanged(modelData.id, checked);
}
}
}
// Drag functionality
MouseArea {
id: dragArea
property bool validDragStart: false
anchors.fill: parent
hoverEnabled: true
drag.target: held && validDragStart ? delegateItem : undefined
drag.axis: Drag.YAxis
drag.minimumY: -delegateItem.height
drag.maximumY: itemsList.height
onPressed: (mouse) => {
// Only allow dragging from the drag handle area (first 60px)
if (mouse.x <= 60) {
validDragStart = true;
delegateItem.z = 2;
} else {
validDragStart = false;
mouse.accepted = false;
}
}
onReleased: {
delegateItem.z = 1;
if (drag.active && validDragStart) {
// Calculate new index based on position
var newIndex = Math.round(delegateItem.y / (delegateItem.height + itemsList.spacing));
newIndex = Math.max(0, Math.min(newIndex, root.items.length - 1));
if (newIndex !== index) {
var newItems = root.items.slice();
var draggedItem = newItems.splice(index, 1)[0];
newItems.splice(newIndex, 0, draggedItem);
root.itemOrderChanged(newItems.map((item) => {
return item.id;
}));
}
}
// Reset position
delegateItem.x = 0;
delegateItem.y = 0;
validDragStart = false;
}
}
// Animations for drag
Behavior on y {
enabled: !dragArea.held && !dragArea.drag.active
NumberAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
}
}
}
}
// Add/Remove Controls
Rectangle {
width: parent.width * 0.5
height: 40
radius: Theme.cornerRadius
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
border.width: 1
anchors.horizontalCenter: parent.horizontalCenter
Row {
anchors.centerIn: parent
spacing: Theme.spacingL
StyledText {
text: "Add or remove widgets"
font.pixelSize: Theme.fontSizeSmall
color: Theme.outline
anchors.verticalCenter: parent.verticalCenter
}
Row {
spacing: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
// Add button
DankActionButton {
iconName: "add"
iconSize: Theme.iconSize - 4
iconColor: Theme.primary
hoverColor: Theme.primaryContainer
onClicked: {
root.addWidget(root.sectionId);
}
}
// Remove button
DankActionButton {
iconName: "remove"
iconSize: Theme.iconSize - 4
iconColor: Theme.error
hoverColor: Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.1)
enabled: root.items.length > 0
opacity: root.items.length > 0 ? 1 : 0.5
onClicked: {
if (root.items.length > 0)
root.removeLastWidget(root.sectionId);
}
}
}
}
}
}

View File

@@ -19,13 +19,11 @@ StyledRect {
property alias validator: textInput.validator
property alias inputMethodHints: textInput.inputMethodHints
property alias maximumLength: textInput.maximumLength
// Icon properties
property string leftIconName: ""
property int leftIconSize: Theme.iconSize
property color leftIconColor: Theme.surfaceVariantText
property color leftIconFocusedColor: Theme.primary
property bool showClearButton: false
// Custom properties
property color backgroundColor: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 0.9)
property color focusedBorderColor: Theme.primary
property color normalBorderColor: Theme.outlineStrong
@@ -33,22 +31,18 @@ StyledRect {
property int borderWidth: 1
property int focusedBorderWidth: 2
property real cornerRadius: Theme.cornerRadius
// Internal padding calculations
readonly property real leftPadding: Theme.spacingM + (leftIconName ? leftIconSize + Theme.spacingM : 0)
readonly property real rightPadding: Theme.spacingM + (showClearButton && text.length > 0 ? 24 + Theme.spacingM : 0)
property real topPadding: Theme.spacingM
property real bottomPadding: Theme.spacingM
// Behavior control
property bool ignoreLeftRightKeys: false
property var keyForwardTargets: []
// Signals
signal textEdited()
signal editingFinished()
signal accepted()
signal focusStateChanged(bool hasFocus)
// Access to inner TextInput properties via functions
function getActiveFocus() {
return textInput.activeFocus;
}
@@ -61,7 +55,6 @@ StyledRect {
textInput.focus = value;
}
// Functions
function forceActiveFocus() {
textInput.forceActiveFocus();
}
@@ -94,7 +87,6 @@ StyledRect {
textInput.focus = false;
}
// Default styling
width: 200
height: 48
radius: cornerRadius
@@ -102,7 +94,6 @@ StyledRect {
border.color: textInput.activeFocus ? focusedBorderColor : normalBorderColor
border.width: textInput.activeFocus ? focusedBorderWidth : borderWidth
// Left icon
DankIcon {
id: leftIcon
@@ -153,7 +144,6 @@ StyledRect {
}
// Clear button
StyledRect {
id: clearButton

View File

@@ -12,7 +12,6 @@ Popup {
signal widgetSelected(string widgetId, string targetSection)
// Prevent multiple openings
function safeOpen() {
if (!isOpening && !visible) {
isOpening = true;
@@ -29,7 +28,6 @@ Popup {
}
onClosed: {
isOpening = false;
// Clear references to prevent memory leaks
allWidgets = [];
targetSection = "";
}
@@ -44,7 +42,6 @@ Popup {
contentItem: Item {
anchors.fill: parent
// Close button in top-right
DankActionButton {
iconName: "close"
iconSize: Theme.iconSize - 2
@@ -65,7 +62,6 @@ Popup {
anchors.margins: Theme.spacingL
anchors.topMargin: Theme.spacingL + 30 // Space for close button
// Header
Row {
width: parent.width
spacing: Theme.spacingM
@@ -95,7 +91,6 @@ Popup {
wrapMode: Text.WordWrap
}
// Widget List
ScrollView {
width: parent.width
height: parent.height - 120 // Leave space for header and description
@@ -120,7 +115,6 @@ Popup {
anchors.margins: Theme.spacingM
spacing: Theme.spacingM
// Widget icon
DankIcon {
name: modelData.icon
size: Theme.iconSize
@@ -128,7 +122,6 @@ Popup {
anchors.verticalCenter: parent.verticalCenter
}
// Widget info
Column {
anchors.verticalCenter: parent.verticalCenter
spacing: 2
@@ -154,7 +147,6 @@ Popup {
}
// Add icon
DankIcon {
name: "add"
size: Theme.iconSize - 4

View File

@@ -10,18 +10,14 @@ Text {
color: Theme.surfaceText
font.pixelSize: Appearance.fontSize.normal
font.family: {
// Use system default
var requestedFont = isMonospace ? Prefs.monoFontFamily : Prefs.fontFamily;
var defaultFont = isMonospace ? Prefs.defaultMonoFontFamily : Prefs.defaultFontFamily;
// If user hasn't overridden the font and we're using the default
if (requestedFont === defaultFont) {
var availableFonts = Qt.fontFamilies();
if (!availableFonts.includes(requestedFont))
return isMonospace ? "Monospace" : "DejaVu Sans";
}
// Either user overrode it, or default font is available
return requestedFont;
}
font.weight: Prefs.fontWeight