Merge branch 'fix-crash-on-close'

This commit is contained in:
ItsLemmy
2025-11-29 09:39:05 -05:00
5 changed files with 597 additions and 75 deletions

View File

@@ -149,93 +149,222 @@ ColumnLayout {
enableDescriptionRichText: true
}
GridView {
id: contributorsGrid
readonly property int columnsCount: 2
// Top 20 contributors with full cards (avoids GridView shader crashes on Qt 6.8)
Flow {
id: topContributorsFlow
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: cellWidth * columnsCount
Layout.preferredHeight: {
if (root.contributors.length === 0)
return 0;
Layout.preferredWidth: Math.round(Style.baseWidgetSize * 14)
spacing: Style.marginM
const rows = Math.ceil(root.contributors.length / columnsCount);
return rows * cellHeight;
}
cellWidth: Math.round(Style.baseWidgetSize * 7)
cellHeight: Math.round(Style.baseWidgetSize * 2.5)
model: root.contributors
Repeater {
model: Math.min(root.contributors.length, 20)
delegate: Rectangle {
width: contributorsGrid.cellWidth - Style.marginM
height: contributorsGrid.cellHeight - Style.marginM
radius: Style.radiusL
color: contributorArea.containsMouse ? Color.mHover : Color.transparent
delegate: Rectangle {
width: Math.round(Style.baseWidgetSize * 6.8)
height: Math.round(Style.baseWidgetSize * 2.3)
radius: Style.radiusM
color: contributorArea.containsMouse ? Color.mHover : Color.transparent
border.width: 1
border.color: contributorArea.containsMouse ? Color.mPrimary : Color.mOutline
Behavior on color {
ColorAnimation {
duration: Style.animationFast
Behavior on color {
ColorAnimation {
duration: Style.animationFast
}
}
}
RowLayout {
anchors.centerIn: parent
width: parent.width - (Style.marginS * 2)
spacing: Style.marginM
Behavior on border.color {
ColorAnimation {
duration: Style.animationFast
}
}
Item {
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: Style.baseWidgetSize * 2 * Style.uiScaleRatio
Layout.preferredHeight: Style.baseWidgetSize * 2 * Style.uiScaleRatio
RowLayout {
anchors.fill: parent
anchors.margins: Style.marginM
spacing: Style.marginM
NImageRounded {
anchors.fill: parent
anchors.margins: Style.marginXS
radius: width * 0.5
imagePath: modelData.avatar_url || ""
fallbackIcon: "person"
borderColor: contributorArea.containsMouse ? Color.mOnHover : Color.mPrimary
borderWidth: Style.borderM
// Avatar container with rectangular design (modern, no shader issues)
Item {
id: wrapper
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: Style.baseWidgetSize * 1.8
Layout.preferredHeight: Style.baseWidgetSize * 1.8
Behavior on borderColor {
ColorAnimation {
property bool isRounded: false
// Background and image container
Item {
anchors.fill: parent
// Simple circular image (pre-rendered, no shaders)
Image {
anchors.fill: parent
source: {
// Try cached circular version first
var username = root.contributors[index].login;
var cached = GitHubService.cachedCircularAvatars[username];
if (cached) {
wrapper.isRounded = true;
return cached;
}
// Fall back to original avatar URL
return root.contributors[index].avatar_url || "";
}
fillMode: Image.PreserveAspectFit // Fit since image is already circular with transparency
mipmap: true
smooth: true
asynchronous: true
visible: root.contributors[index].avatar_url !== undefined && root.contributors[index].avatar_url !== ""
opacity: status === Image.Ready ? 1.0 : 0.0
Behavior on opacity {
NumberAnimation {
duration: Style.animationFast
}
}
}
// Fallback icon
NIcon {
anchors.centerIn: parent
visible: !root.contributors[index].avatar_url || root.contributors[index].avatar_url === ""
icon: "person"
pointSize: Style.fontSizeL
color: Color.mPrimary
}
}
Rectangle {
visible: wrapper.isRounded
anchors.fill: parent
color: Color.transparent
radius: width * 0.5
border.width: Style.borderM
border.color: Color.mPrimary
}
}
// Info column
ColumnLayout {
spacing: 2
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
NText {
text: root.contributors[index].login || "Unknown"
font.weight: Style.fontWeightBold
color: contributorArea.containsMouse ? Color.mOnHover : Color.mOnSurface
elide: Text.ElideRight
Layout.fillWidth: true
pointSize: Style.fontSizeS
}
RowLayout {
spacing: Style.marginXS
Layout.fillWidth: true
NIcon {
icon: "git-commit"
pointSize: Style.fontSizeXS
color: contributorArea.containsMouse ? Color.mOnHover : Color.mOnSurfaceVariant
}
NText {
text: `${(root.contributors[index].contributions || 0).toString()} commits`
pointSize: Style.fontSizeXS
color: contributorArea.containsMouse ? Color.mOnHover : Color.mOnSurfaceVariant
}
}
}
// Hover indicator
NIcon {
Layout.alignment: Qt.AlignVCenter
icon: "arrow-right"
pointSize: Style.fontSizeS
color: Color.mPrimary
opacity: contributorArea.containsMouse ? 1.0 : 0.0
Behavior on opacity {
NumberAnimation {
duration: Style.animationFast
}
}
}
}
ColumnLayout {
spacing: Style.marginXS
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
NText {
text: modelData.login || "Unknown"
font.weight: Style.fontWeightBold
color: contributorArea.containsMouse ? Color.mOnHover : Color.mOnSurface
elide: Text.ElideRight
Layout.fillWidth: true
}
NText {
text: (modelData.contributions || 0) + " " + ((modelData.contributions || 0) === 1 ? "commit" : "commits")
pointSize: Style.fontSizeXS
color: contributorArea.containsMouse ? Color.mOnHover : Color.mOnSurfaceVariant
MouseArea {
id: contributorArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (root.contributors[index].html_url)
Quickshell.execDetached(["xdg-open", root.contributors[index].html_url]);
}
}
}
}
}
MouseArea {
id: contributorArea
// Remaining contributors (simple text links)
Flow {
id: remainingContributorsFlow
visible: root.contributors.length > 20
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: Math.round(Style.baseWidgetSize * 14)
Layout.topMargin: Style.marginL
spacing: Style.marginS
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (modelData.html_url)
Quickshell.execDetached(["xdg-open", modelData.html_url]);
Repeater {
model: Math.max(0, root.contributors.length - 20)
delegate: Rectangle {
width: nameText.implicitWidth + Style.marginM * 2
height: nameText.implicitHeight + Style.marginS * 2
radius: Style.radiusS
color: nameArea.containsMouse ? Qt.alpha(Color.mPrimary, 0.1) : Color.transparent
border.width: 1
border.color: nameArea.containsMouse ? Color.mPrimary : Color.mOutline
Behavior on color {
ColorAnimation {
duration: Style.animationFast
}
}
Behavior on border.color {
ColorAnimation {
duration: Style.animationFast
}
}
NText {
id: nameText
anchors.centerIn: parent
text: root.contributors[index + 20].login || "Unknown"
pointSize: Style.fontSizeXS
color: nameArea.containsMouse ? Color.mPrimary : Color.mOnSurface
font.weight: Style.fontWeightMedium
Behavior on color {
ColorAnimation {
duration: Style.animationFast
}
}
}
MouseArea {
id: nameArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (root.contributors[index + 20].html_url)
Quickshell.execDetached(["xdg-open", root.contributors[index + 20].html_url]);
}
}
}
}

View File

@@ -0,0 +1,96 @@
import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Widgets
import qs.Commons
/**
* CircularAvatarRenderer - Hidden window for rendering circular avatars
*
* This component safely uses ClippingRectangle in a separate hidden window to
* pre-render circular avatar images. The rendered images are saved as PNGs
* with transparent backgrounds, which can then be used in the UI without
* any shader effects (avoiding Qt 6.8 crashes).
*
* Usage:
* var renderer = component.createObject(null, {
* imagePath: "file:///path/to/avatar.png",
* outputPath: "/path/to/output_circular.png",
* username: "ItsLemmy"
* });
* renderer.renderComplete.connect(function(success) {
* if (success) console.log("Rendered!");
* renderer.destroy();
* });
*/
PanelWindow {
id: root
// Input properties
property string imagePath: ""
property string outputPath: ""
property string username: ""
// Hidden window configuration
implicitWidth: 256
implicitHeight: 256
visible: true // Must be visible for grabToImage to work
color: "transparent"
// Wayland configuration - hide it from user view
WlrLayershell.layer: WlrLayer.Bottom // Render below everything
WlrLayershell.exclusionMode: ExclusionMode.Ignore
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
// Position it off-screen or behind everything
anchors {
left: true
top: true
}
margins {
left: -512// Off-screen to the left
top: -512 // Off-screen to the top
}
signal renderComplete(bool success)
// Use ClippingRectangle safely (not in GridView, not visible)
ClippingRectangle {
id: clipper
anchors.fill: parent
radius: width * 0.5 // Make it circular
color: "transparent"
Image {
id: sourceImage
anchors.fill: parent
source: root.imagePath
fillMode: Image.PreserveAspectCrop
smooth: true
mipmap: true
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
// Image loaded successfully, capture it on next frame
Qt.callLater(captureCircular);
} else if (status === Image.Error) {
Logger.e("CircularAvatarRenderer", "Failed to load image for", root.username);
root.renderComplete(false);
}
}
}
}
function captureCircular() {
clipper.grabToImage(function (result) {
if (result.saveToFile(root.outputPath)) {
Logger.d("CircularAvatarRenderer", "Saved circular avatar for", root.username, "to", root.outputPath);
root.renderComplete(true);
} else {
Logger.e("CircularAvatarRenderer", "Failed to save circular avatar for", root.username);
root.renderComplete(false);
}
}, Qt.size(root.width, root.height));
}
}