mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 00:12:50 -05:00
update workspace indicators and qmlformat
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import "../Common/fuzzysort.js" as FuzzySort
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
import qs.Widgets
|
||||
import "../Common/fuzzysort.js" as FuzzySort
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
@@ -14,7 +14,7 @@ Rectangle {
|
||||
property var optionIcons: [] // Array of icon names corresponding to options
|
||||
property bool forceRecreate: false
|
||||
property bool enableFuzzySearch: false
|
||||
property int popupWidthOffset: 0 // How much wider the popup should be than the button
|
||||
property int popupWidthOffset: 0 // How much wider the popup should be than the button
|
||||
property int maxPopupHeight: 400
|
||||
|
||||
signal valueChanged(string value)
|
||||
@@ -23,35 +23,32 @@ Rectangle {
|
||||
height: 60
|
||||
radius: Theme.cornerRadius
|
||||
color: Theme.surfaceHover
|
||||
|
||||
Component.onCompleted: {
|
||||
// Force a small delay to ensure proper initialization
|
||||
forceRecreateTimer.start();
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: forceRecreateTimer
|
||||
interval: 50
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
root.forceRecreate = !root.forceRecreate;
|
||||
}
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
var popup = popupLoader.item;
|
||||
if (popup && popup.visible) {
|
||||
if (popup && popup.visible)
|
||||
popup.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
var popup = popupLoader.item;
|
||||
if (!visible && popup && popup.visible)
|
||||
popup.close();
|
||||
else if (visible) {
|
||||
else if (visible)
|
||||
// Force recreate popup when component becomes visible
|
||||
forceRecreateTimer.start();
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: forceRecreateTimer
|
||||
|
||||
interval: 50
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
root.forceRecreate = !root.forceRecreate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,14 +157,16 @@ Rectangle {
|
||||
|
||||
Loader {
|
||||
id: popupLoader
|
||||
active: true
|
||||
|
||||
property bool recreateFlag: root.forceRecreate
|
||||
|
||||
active: true
|
||||
onRecreateFlagChanged: {
|
||||
// Force recreation by toggling active
|
||||
active = false;
|
||||
active = true;
|
||||
}
|
||||
|
||||
|
||||
sourceComponent: Component {
|
||||
Popup {
|
||||
id: dropdownMenu
|
||||
@@ -176,194 +175,201 @@ Rectangle {
|
||||
property var filteredOptions: []
|
||||
property int selectedIndex: -1
|
||||
|
||||
parent: Overlay.overlay
|
||||
width: dropdown.width + root.popupWidthOffset
|
||||
height: Math.min(root.maxPopupHeight,
|
||||
(root.enableFuzzySearch ? 48 : 0) +
|
||||
Math.min(filteredOptions.length, 10) * 36 + 16)
|
||||
padding: 0
|
||||
modal: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
onOpened: {
|
||||
searchQuery = ""
|
||||
updateFilteredOptions()
|
||||
if (root.enableFuzzySearch && searchField.visible) {
|
||||
searchField.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
|
||||
function updateFilteredOptions() {
|
||||
if (!root.enableFuzzySearch || searchQuery.length === 0) {
|
||||
filteredOptions = root.options
|
||||
filteredOptions = root.options;
|
||||
} else {
|
||||
var results = FuzzySort.go(searchQuery, root.options, {
|
||||
limit: 50,
|
||||
threshold: -10000
|
||||
})
|
||||
"limit": 50,
|
||||
"threshold": -10000
|
||||
});
|
||||
filteredOptions = results.map(function(result) {
|
||||
return result.target
|
||||
})
|
||||
return result.target;
|
||||
});
|
||||
}
|
||||
selectedIndex = -1
|
||||
selectedIndex = -1;
|
||||
}
|
||||
|
||||
function selectNext() {
|
||||
if (filteredOptions.length > 0) {
|
||||
selectedIndex = (selectedIndex + 1) % filteredOptions.length
|
||||
listView.positionViewAtIndex(selectedIndex, ListView.Contain)
|
||||
selectedIndex = (selectedIndex + 1) % filteredOptions.length;
|
||||
listView.positionViewAtIndex(selectedIndex, ListView.Contain);
|
||||
}
|
||||
}
|
||||
|
||||
function selectPrevious() {
|
||||
if (filteredOptions.length > 0) {
|
||||
selectedIndex = selectedIndex <= 0 ? filteredOptions.length - 1 : selectedIndex - 1
|
||||
listView.positionViewAtIndex(selectedIndex, ListView.Contain)
|
||||
selectedIndex = selectedIndex <= 0 ? filteredOptions.length - 1 : selectedIndex - 1;
|
||||
listView.positionViewAtIndex(selectedIndex, ListView.Contain);
|
||||
}
|
||||
}
|
||||
|
||||
function selectCurrent() {
|
||||
if (selectedIndex >= 0 && selectedIndex < filteredOptions.length) {
|
||||
root.currentValue = filteredOptions[selectedIndex]
|
||||
root.valueChanged(filteredOptions[selectedIndex])
|
||||
dropdownMenu.close()
|
||||
root.currentValue = filteredOptions[selectedIndex];
|
||||
root.valueChanged(filteredOptions[selectedIndex]);
|
||||
dropdownMenu.close();
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: "transparent"
|
||||
}
|
||||
parent: Overlay.overlay
|
||||
width: dropdown.width + root.popupWidthOffset
|
||||
height: Math.min(root.maxPopupHeight, (root.enableFuzzySearch ? 48 : 0) + Math.min(filteredOptions.length, 10) * 36 + 16)
|
||||
padding: 0
|
||||
modal: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
onOpened: {
|
||||
searchQuery = "";
|
||||
updateFilteredOptions();
|
||||
if (root.enableFuzzySearch && searchField.visible)
|
||||
searchField.forceActiveFocus();
|
||||
|
||||
contentItem: Rectangle {
|
||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 1)
|
||||
border.color: Theme.primarySelected
|
||||
border.width: 1
|
||||
radius: Theme.cornerRadiusSmall
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingS
|
||||
background: Rectangle {
|
||||
color: "transparent"
|
||||
}
|
||||
|
||||
// Search field
|
||||
Rectangle {
|
||||
id: searchContainer
|
||||
width: parent.width
|
||||
height: 36
|
||||
visible: root.enableFuzzySearch
|
||||
contentItem: Rectangle {
|
||||
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g, Theme.surfaceContainer.b, 1)
|
||||
border.color: Theme.primarySelected
|
||||
border.width: 1
|
||||
radius: Theme.cornerRadiusSmall
|
||||
color: Theme.surfaceVariantAlpha
|
||||
|
||||
DankTextField {
|
||||
id: searchField
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 1
|
||||
placeholderText: "Search..."
|
||||
text: dropdownMenu.searchQuery
|
||||
topPadding: Theme.spacingS
|
||||
bottomPadding: Theme.spacingS
|
||||
onTextChanged: {
|
||||
dropdownMenu.searchQuery = text
|
||||
dropdownMenu.updateFilteredOptions()
|
||||
anchors.margins: Theme.spacingS
|
||||
|
||||
// Search field
|
||||
Rectangle {
|
||||
id: searchContainer
|
||||
|
||||
width: parent.width
|
||||
height: 36
|
||||
visible: root.enableFuzzySearch
|
||||
radius: Theme.cornerRadiusSmall
|
||||
color: Theme.surfaceVariantAlpha
|
||||
|
||||
DankTextField {
|
||||
id: searchField
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.margins: 1
|
||||
placeholderText: "Search..."
|
||||
text: dropdownMenu.searchQuery
|
||||
topPadding: Theme.spacingS
|
||||
bottomPadding: Theme.spacingS
|
||||
onTextChanged: {
|
||||
dropdownMenu.searchQuery = text;
|
||||
dropdownMenu.updateFilteredOptions();
|
||||
}
|
||||
Keys.onDownPressed: dropdownMenu.selectNext()
|
||||
Keys.onUpPressed: dropdownMenu.selectPrevious()
|
||||
Keys.onReturnPressed: dropdownMenu.selectCurrent()
|
||||
Keys.onEnterPressed: dropdownMenu.selectCurrent()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Item {
|
||||
width: 1
|
||||
height: Theme.spacingXS
|
||||
visible: root.enableFuzzySearch
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
|
||||
property real wheelMultiplier: 1.8
|
||||
property int wheelBaseStep: 160
|
||||
|
||||
width: parent.width
|
||||
height: parent.height - (root.enableFuzzySearch ? searchContainer.height + Theme.spacingXS : 0)
|
||||
clip: true
|
||||
model: dropdownMenu.filteredOptions
|
||||
spacing: 2
|
||||
|
||||
WheelHandler {
|
||||
target: null
|
||||
onWheel: (ev) => {
|
||||
let dy = ev.pixelDelta.y !== 0 ? ev.pixelDelta.y : (ev.angleDelta.y / 120) * parent.wheelBaseStep;
|
||||
if (ev.inverted)
|
||||
dy = -dy;
|
||||
|
||||
const maxY = Math.max(0, parent.contentHeight - parent.height);
|
||||
parent.contentY = Math.max(0, Math.min(maxY, parent.contentY - dy * parent.wheelMultiplier));
|
||||
ev.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
property bool isSelected: dropdownMenu.selectedIndex === index
|
||||
property bool isCurrentValue: root.currentValue === modelData
|
||||
property int optionIndex: root.options.indexOf(modelData)
|
||||
|
||||
width: ListView.view.width
|
||||
height: 32
|
||||
radius: Theme.cornerRadiusSmall
|
||||
color: isSelected ? Theme.primaryHover : optionArea.containsMouse ? Theme.primaryHoverLight : "transparent"
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Theme.spacingS
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: optionIndex >= 0 && root.optionIcons.length > optionIndex ? root.optionIcons[optionIndex] : ""
|
||||
size: 18
|
||||
color: isCurrentValue ? Theme.primary : Theme.surfaceVariantText
|
||||
visible: name !== ""
|
||||
}
|
||||
|
||||
StyledText {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: modelData
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: isCurrentValue ? Theme.primary : Theme.surfaceText
|
||||
font.weight: isCurrentValue ? Font.Medium : Font.Normal
|
||||
width: parent.parent.width - parent.x - Theme.spacingS
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: optionArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.currentValue = modelData;
|
||||
root.valueChanged(modelData);
|
||||
dropdownMenu.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Keys.onDownPressed: dropdownMenu.selectNext()
|
||||
Keys.onUpPressed: dropdownMenu.selectPrevious()
|
||||
Keys.onReturnPressed: dropdownMenu.selectCurrent()
|
||||
Keys.onEnterPressed: dropdownMenu.selectCurrent()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Item {
|
||||
width: 1
|
||||
height: Theme.spacingXS
|
||||
visible: root.enableFuzzySearch
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
width: parent.width
|
||||
height: parent.height - (root.enableFuzzySearch ? searchContainer.height + Theme.spacingXS : 0)
|
||||
clip: true
|
||||
model: dropdownMenu.filteredOptions
|
||||
spacing: 2
|
||||
|
||||
ScrollBar.vertical: ScrollBar { policy: ScrollBar.AsNeeded }
|
||||
ScrollBar.horizontal: ScrollBar { policy: ScrollBar.AlwaysOff }
|
||||
|
||||
property real wheelMultiplier: 1.8
|
||||
property int wheelBaseStep: 160
|
||||
|
||||
WheelHandler {
|
||||
target: null
|
||||
onWheel: (ev) => {
|
||||
let dy = ev.pixelDelta.y !== 0
|
||||
? ev.pixelDelta.y
|
||||
: (ev.angleDelta.y / 120) * parent.wheelBaseStep;
|
||||
if (ev.inverted) dy = -dy;
|
||||
|
||||
const maxY = Math.max(0, parent.contentHeight - parent.height);
|
||||
parent.contentY = Math.max(0, Math.min(maxY,
|
||||
parent.contentY - dy * parent.wheelMultiplier));
|
||||
|
||||
ev.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
property bool isSelected: dropdownMenu.selectedIndex === index
|
||||
property bool isCurrentValue: root.currentValue === modelData
|
||||
property int optionIndex: root.options.indexOf(modelData)
|
||||
|
||||
width: ListView.view.width
|
||||
height: 32
|
||||
radius: Theme.cornerRadiusSmall
|
||||
color: isSelected ? Theme.primaryHover :
|
||||
optionArea.containsMouse ? Theme.primaryHoverLight : "transparent"
|
||||
|
||||
Row {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Theme.spacingS
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: optionIndex >= 0 && root.optionIcons.length > optionIndex ?
|
||||
root.optionIcons[optionIndex] : ""
|
||||
size: 18
|
||||
color: isCurrentValue ? Theme.primary : Theme.surfaceVariantText
|
||||
visible: name !== ""
|
||||
}
|
||||
|
||||
StyledText {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: modelData
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: isCurrentValue ? Theme.primary : Theme.surfaceText
|
||||
font.weight: isCurrentValue ? Font.Medium : Font.Normal
|
||||
width: parent.parent.width - parent.x - Theme.spacingS
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: optionArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.currentValue = modelData
|
||||
root.valueChanged(modelData)
|
||||
dropdownMenu.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import qs.Common
|
||||
|
||||
GridView {
|
||||
id: gridView
|
||||
|
||||
property int currentIndex: 0
|
||||
property int columns: 4
|
||||
property bool adaptiveColumns: false
|
||||
@@ -17,6 +18,12 @@ GridView {
|
||||
property int minIconSize: 32
|
||||
property bool hoverUpdatesSelection: true
|
||||
property bool keyboardNavigationActive: false
|
||||
property real wheelMultiplier: 1.8
|
||||
property int wheelBaseStep: 160
|
||||
property int baseCellWidth: adaptiveColumns ? Math.max(minCellWidth, Math.min(maxCellWidth, width / columns)) : (width - Theme.spacingS * 2) / columns
|
||||
property int baseCellHeight: baseCellWidth + 20
|
||||
property int actualColumns: adaptiveColumns ? Math.floor(width / cellWidth) : columns
|
||||
property int remainingSpace: width - (actualColumns * cellWidth)
|
||||
|
||||
signal keyboardNavigationReset()
|
||||
signal itemClicked(int index, var modelData)
|
||||
@@ -41,34 +48,6 @@ GridView {
|
||||
|
||||
}
|
||||
clip: true
|
||||
|
||||
ScrollBar.vertical: ScrollBar { policy: ScrollBar.AsNeeded }
|
||||
ScrollBar.horizontal: ScrollBar { policy: ScrollBar.AlwaysOff }
|
||||
|
||||
property real wheelMultiplier: 1.8
|
||||
property int wheelBaseStep: 160
|
||||
|
||||
WheelHandler {
|
||||
target: null
|
||||
onWheel: (ev) => {
|
||||
let dy = ev.pixelDelta.y !== 0
|
||||
? ev.pixelDelta.y
|
||||
: (ev.angleDelta.y / 120) * gridView.wheelBaseStep;
|
||||
if (ev.inverted) dy = -dy;
|
||||
|
||||
const maxY = Math.max(0, gridView.contentHeight - gridView.height);
|
||||
gridView.contentY = Math.max(0, Math.min(maxY,
|
||||
gridView.contentY - dy * gridView.wheelMultiplier));
|
||||
|
||||
ev.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
property int baseCellWidth: adaptiveColumns ? Math.max(minCellWidth, Math.min(maxCellWidth, width / columns)) : (width - Theme.spacingS * 2) / columns
|
||||
property int baseCellHeight: baseCellWidth + 20
|
||||
property int actualColumns: adaptiveColumns ? Math.floor(width / cellWidth) : columns
|
||||
property int remainingSpace: width - (actualColumns * cellWidth)
|
||||
|
||||
anchors.margins: Theme.spacingS
|
||||
cellWidth: baseCellWidth
|
||||
cellHeight: baseCellHeight
|
||||
@@ -79,92 +58,113 @@ GridView {
|
||||
flickDeceleration: 300
|
||||
maximumFlickVelocity: 30000
|
||||
|
||||
WheelHandler {
|
||||
target: null
|
||||
onWheel: (ev) => {
|
||||
let dy = ev.pixelDelta.y !== 0 ? ev.pixelDelta.y : (ev.angleDelta.y / 120) * gridView.wheelBaseStep;
|
||||
if (ev.inverted)
|
||||
dy = -dy;
|
||||
|
||||
const maxY = Math.max(0, gridView.contentHeight - gridView.height);
|
||||
gridView.contentY = Math.max(0, Math.min(maxY, gridView.contentY - dy * gridView.wheelMultiplier));
|
||||
ev.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AsNeeded
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: gridView.cellWidth - cellPadding
|
||||
height: gridView.cellHeight - cellPadding
|
||||
radius: Theme.cornerRadiusLarge
|
||||
color: currentIndex === index ? Theme.primaryPressed : mouseArea.containsMouse ? Theme.primaryHoverLight : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.03)
|
||||
border.color: currentIndex === index ? Theme.primarySelected : Theme.outlineMedium
|
||||
border.width: currentIndex === index ? 2 : 1
|
||||
radius: Theme.cornerRadiusLarge
|
||||
color: currentIndex === index ? Theme.primaryPressed : mouseArea.containsMouse ? Theme.primaryHoverLight : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.03)
|
||||
border.color: currentIndex === index ? Theme.primarySelected : Theme.outlineMedium
|
||||
border.width: currentIndex === index ? 2 : 1
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.spacingS
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.spacingS
|
||||
|
||||
Item {
|
||||
property int iconSize: Math.min(maxIconSize, Math.max(minIconSize, gridView.cellWidth * iconSizeRatio))
|
||||
Item {
|
||||
property int iconSize: Math.min(maxIconSize, Math.max(minIconSize, gridView.cellWidth * iconSizeRatio))
|
||||
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
IconImage {
|
||||
id: iconImg
|
||||
|
||||
anchors.fill: parent
|
||||
source: (model.icon) ? Quickshell.iconPath(model.icon, "") : ""
|
||||
smooth: true
|
||||
asynchronous: true
|
||||
visible: status === Image.Ready
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: !iconImg.visible
|
||||
color: Theme.surfaceLight
|
||||
radius: Theme.cornerRadiusLarge
|
||||
border.width: 1
|
||||
border.color: Theme.primarySelected
|
||||
|
||||
StyledText {
|
||||
anchors.centerIn: parent
|
||||
text: (model.name && model.name.length > 0) ? model.name.charAt(0).toUpperCase() : "A"
|
||||
font.pixelSize: Math.min(28, parent.width * 0.5)
|
||||
color: Theme.primary
|
||||
font.weight: Font.Bold
|
||||
}
|
||||
|
||||
}
|
||||
IconImage {
|
||||
id: iconImg
|
||||
|
||||
anchors.fill: parent
|
||||
source: (model.icon) ? Quickshell.iconPath(model.icon, "") : ""
|
||||
smooth: true
|
||||
asynchronous: true
|
||||
visible: status === Image.Ready
|
||||
}
|
||||
|
||||
StyledText {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: gridView.cellWidth - 12
|
||||
text: model.name || ""
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
elide: Text.ElideRight
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
maximumLineCount: 2
|
||||
wrapMode: Text.WordWrap
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: !iconImg.visible
|
||||
color: Theme.surfaceLight
|
||||
radius: Theme.cornerRadiusLarge
|
||||
border.width: 1
|
||||
border.color: Theme.primarySelected
|
||||
|
||||
StyledText {
|
||||
anchors.centerIn: parent
|
||||
text: (model.name && model.name.length > 0) ? model.name.charAt(0).toUpperCase() : "A"
|
||||
font.pixelSize: Math.min(28, parent.width * 0.5)
|
||||
color: Theme.primary
|
||||
font.weight: Font.Bold
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
z: 10
|
||||
onEntered: {
|
||||
if (hoverUpdatesSelection && !keyboardNavigationActive)
|
||||
currentIndex = index;
|
||||
|
||||
itemHovered(index);
|
||||
}
|
||||
onPositionChanged: {
|
||||
// Signal parent to reset keyboard navigation flag when mouse moves
|
||||
keyboardNavigationReset();
|
||||
}
|
||||
onClicked: {
|
||||
itemClicked(index, model);
|
||||
}
|
||||
StyledText {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: gridView.cellWidth - 12
|
||||
text: model.name || ""
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
elide: Text.ElideRight
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
maximumLineCount: 2
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
z: 10
|
||||
onEntered: {
|
||||
if (hoverUpdatesSelection && !keyboardNavigationActive)
|
||||
currentIndex = index;
|
||||
|
||||
itemHovered(index);
|
||||
}
|
||||
onPositionChanged: {
|
||||
// Signal parent to reset keyboard navigation flag when mouse moves
|
||||
keyboardNavigationReset();
|
||||
}
|
||||
onClicked: {
|
||||
itemClicked(index, model);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import qs.Common
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
|
||||
property int currentIndex: 0
|
||||
property int itemHeight: 72
|
||||
property int iconSize: 56
|
||||
@@ -13,6 +14,8 @@ ListView {
|
||||
property int itemSpacing: Theme.spacingS
|
||||
property bool hoverUpdatesSelection: true
|
||||
property bool keyboardNavigationActive: false
|
||||
property real wheelMultiplier: 1.8
|
||||
property int wheelBaseStep: 160
|
||||
|
||||
signal keyboardNavigationReset()
|
||||
signal itemClicked(int index, var modelData)
|
||||
@@ -37,29 +40,6 @@ ListView {
|
||||
|
||||
}
|
||||
clip: true
|
||||
|
||||
ScrollBar.vertical: ScrollBar { policy: ScrollBar.AlwaysOn }
|
||||
ScrollBar.horizontal: ScrollBar { policy: ScrollBar.AlwaysOff }
|
||||
|
||||
property real wheelMultiplier: 1.8
|
||||
property int wheelBaseStep: 160
|
||||
|
||||
WheelHandler {
|
||||
target: null
|
||||
onWheel: (ev) => {
|
||||
let dy = ev.pixelDelta.y !== 0
|
||||
? ev.pixelDelta.y
|
||||
: (ev.angleDelta.y / 120) * listView.wheelBaseStep;
|
||||
if (ev.inverted) dy = -dy;
|
||||
|
||||
const maxY = Math.max(0, listView.contentHeight - listView.height);
|
||||
listView.contentY = Math.max(0, Math.min(maxY,
|
||||
listView.contentY - dy * listView.wheelMultiplier));
|
||||
|
||||
ev.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
anchors.margins: itemSpacing
|
||||
spacing: itemSpacing
|
||||
focus: true
|
||||
@@ -67,103 +47,124 @@ ListView {
|
||||
flickDeceleration: 600
|
||||
maximumFlickVelocity: 30000
|
||||
|
||||
WheelHandler {
|
||||
target: null
|
||||
onWheel: (ev) => {
|
||||
let dy = ev.pixelDelta.y !== 0 ? ev.pixelDelta.y : (ev.angleDelta.y / 120) * listView.wheelBaseStep;
|
||||
if (ev.inverted)
|
||||
dy = -dy;
|
||||
|
||||
const maxY = Math.max(0, listView.contentHeight - listView.height);
|
||||
listView.contentY = Math.max(0, Math.min(maxY, listView.contentY - dy * listView.wheelMultiplier));
|
||||
ev.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOn
|
||||
}
|
||||
|
||||
ScrollBar.horizontal: ScrollBar {
|
||||
policy: ScrollBar.AlwaysOff
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
width: listView.width
|
||||
height: itemHeight
|
||||
radius: Theme.cornerRadiusLarge
|
||||
color: ListView.isCurrentItem ? Theme.primaryPressed : mouseArea.containsMouse ? Theme.primaryHoverLight : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.03)
|
||||
border.color: ListView.isCurrentItem ? Theme.primarySelected : Theme.outlineMedium
|
||||
border.width: ListView.isCurrentItem ? 2 : 1
|
||||
radius: Theme.cornerRadiusLarge
|
||||
color: ListView.isCurrentItem ? Theme.primaryPressed : mouseArea.containsMouse ? Theme.primaryHoverLight : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.03)
|
||||
border.color: ListView.isCurrentItem ? Theme.primarySelected : Theme.outlineMedium
|
||||
border.width: ListView.isCurrentItem ? 2 : 1
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingM
|
||||
spacing: Theme.spacingL
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.spacingM
|
||||
spacing: Theme.spacingL
|
||||
|
||||
Item {
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
Item {
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
IconImage {
|
||||
id: iconImg
|
||||
|
||||
anchors.fill: parent
|
||||
source: (model.icon) ? Quickshell.iconPath(model.icon, "") : ""
|
||||
smooth: true
|
||||
asynchronous: true
|
||||
visible: status === Image.Ready
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: !iconImg.visible
|
||||
color: Theme.surfaceLight
|
||||
radius: Theme.cornerRadiusLarge
|
||||
border.width: 1
|
||||
border.color: Theme.primarySelected
|
||||
|
||||
StyledText {
|
||||
anchors.centerIn: parent
|
||||
text: (model.name && model.name.length > 0) ? model.name.charAt(0).toUpperCase() : "A"
|
||||
font.pixelSize: iconSize * 0.4
|
||||
color: Theme.primary
|
||||
font.weight: Font.Bold
|
||||
}
|
||||
|
||||
}
|
||||
IconImage {
|
||||
id: iconImg
|
||||
|
||||
anchors.fill: parent
|
||||
source: (model.icon) ? Quickshell.iconPath(model.icon, "") : ""
|
||||
smooth: true
|
||||
asynchronous: true
|
||||
visible: status === Image.Ready
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: parent.width - iconSize - Theme.spacingL
|
||||
spacing: Theme.spacingXS
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: !iconImg.visible
|
||||
color: Theme.surfaceLight
|
||||
radius: Theme.cornerRadiusLarge
|
||||
border.width: 1
|
||||
border.color: Theme.primarySelected
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: model.name || ""
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: model.comment || "Application"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceVariantText
|
||||
elide: Text.ElideRight
|
||||
visible: showDescription && model.comment && model.comment.length > 0
|
||||
anchors.centerIn: parent
|
||||
text: (model.name && model.name.length > 0) ? model.name.charAt(0).toUpperCase() : "A"
|
||||
font.pixelSize: iconSize * 0.4
|
||||
color: Theme.primary
|
||||
font.weight: Font.Bold
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
Column {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: parent.width - iconSize - Theme.spacingL
|
||||
spacing: Theme.spacingXS
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
z: 10
|
||||
onEntered: {
|
||||
if (hoverUpdatesSelection && !keyboardNavigationActive)
|
||||
listView.currentIndex = index;
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: model.name || ""
|
||||
font.pixelSize: Theme.fontSizeLarge
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
itemHovered(index);
|
||||
}
|
||||
onPositionChanged: {
|
||||
// Signal parent to reset keyboard navigation flag when mouse moves
|
||||
keyboardNavigationReset();
|
||||
}
|
||||
onClicked: {
|
||||
itemClicked(index, model);
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: model.comment || "Application"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceVariantText
|
||||
elide: Text.ElideRight
|
||||
visible: showDescription && model.comment && model.comment.length > 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
z: 10
|
||||
onEntered: {
|
||||
if (hoverUpdatesSelection && !keyboardNavigationActive)
|
||||
listView.currentIndex = index;
|
||||
|
||||
itemHovered(index);
|
||||
}
|
||||
onPositionChanged: {
|
||||
// Signal parent to reset keyboard navigation flag when mouse moves
|
||||
keyboardNavigationReset();
|
||||
}
|
||||
onClicked: {
|
||||
itemClicked(index, model);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,26 +4,24 @@ import qs.Services
|
||||
|
||||
Text {
|
||||
id: root
|
||||
|
||||
|
||||
property bool isMonospace: false
|
||||
|
||||
color: Theme.surfaceText
|
||||
font.pixelSize: Appearance.fontSize.normal
|
||||
font.family: {
|
||||
var requestedFont = isMonospace ? Prefs.monoFontFamily : Prefs.fontFamily
|
||||
var defaultFont = isMonospace ? Prefs.defaultMonoFontFamily : Prefs.defaultFontFamily
|
||||
|
||||
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)) {
|
||||
var availableFonts = Qt.fontFamilies();
|
||||
if (!availableFonts.includes(requestedFont))
|
||||
// Use system default
|
||||
return isMonospace ? "Monospace" : "DejaVu Sans"
|
||||
}
|
||||
return isMonospace ? "Monospace" : "DejaVu Sans";
|
||||
|
||||
}
|
||||
|
||||
// Either user overrode it, or default font is available
|
||||
return requestedFont
|
||||
return requestedFont;
|
||||
}
|
||||
font.weight: Prefs.fontWeight
|
||||
wrapMode: Text.WordWrap
|
||||
|
||||
Reference in New Issue
Block a user