From abe0327e676cdae42443ec4cee5fbb3bbd902e56 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sat, 14 Sep 2024 03:10:44 -0700 Subject: [PATCH] widgets: add IconImage widget Docs currently cannot be generated due to lack of qml parsing support in typegen. --- src/CMakeLists.txt | 1 + src/widgets/CMakeLists.txt | 13 ++++++++ src/widgets/IconImage.qml | 67 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/widgets/CMakeLists.txt create mode 100644 src/widgets/IconImage.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42954775..33554832 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ install(TARGETS quickshell RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) add_subdirectory(core) add_subdirectory(io) +add_subdirectory(widgets) if (CRASH_REPORTER) add_subdirectory(crash) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt new file mode 100644 index 00000000..ac3682fa --- /dev/null +++ b/src/widgets/CMakeLists.txt @@ -0,0 +1,13 @@ +qt_add_library(quickshell-widgets STATIC) + +qt_add_qml_module(quickshell-widgets + URI Quickshell.Widgets + VERSION 0.1 + QML_FILES + IconImage.qml +) + +qs_pch(quickshell-widgets) +qs_pch(quickshell-widgetsplugin) + +target_link_libraries(quickshell PRIVATE quickshell-widgetsplugin) diff --git a/src/widgets/IconImage.qml b/src/widgets/IconImage.qml new file mode 100644 index 00000000..1cfd7969 --- /dev/null +++ b/src/widgets/IconImage.qml @@ -0,0 +1,67 @@ +import QtQuick + +///! Image component for displaying widget/icon style images. +/// This is a specialization of @@QtQuick.Image configured for icon-style images, +/// designed to make it easier to use correctly. If you need more control, use +/// @@QtQuick.Image directly. +/// +/// The image's aspect raito is assumed to be 1:1. If it is not 1:1, padding +/// will be added to make it 1:1. This is currently applied before the actual +/// aspect ratio of the image is taken into account, and may change in a future +/// release. +/// +/// You should use it for: +/// - Icons for custom buttons +/// - Status indicator icons +/// - System tray icons +/// - Things similar to the above. +/// +/// Do not use it for: +/// - Big images +/// - Images that change size frequently +/// - Anything that doesn't feel like an icon. +/// +/// > [!INFO] More information about many of these properties can be found in +/// > the documentation for @@QtQuick.Image. +Item { + id: root + + /// URL of the image. Defaults to an empty string. + /// See @@QtQuick.Image.source. + property alias source: image.source + /// If the image should be loaded asynchronously. Defaults to false. + /// See @@QtQuick.Image.asynchronous. + property alias asynchronous: image.asynchronous + /// The load status of the image. See @@QtQuick.Image.status. + property alias status: image.status + /// If the image should be mipmap filtered. Defaults to false. + /// See @@QtQuick.Image.mipmap. + /// + /// Try enabling this if your image is significantly scaled down + /// and looks bad because of it. + property alias mipmap: image.mipmap + /// The @@QtQuick.Image backing this object. + /// + /// This is useful if you need to access more functionality than + /// exposed by IconImage. + property alias backer: image + + /// The suggested size of the image. This is used as a defualt + /// for @@QtQuick.Item.implicitWidth and @@QtQuick.Item.implicitHeight. + property real implicitSize: 0 + + /// The actual size the image will be displayed at. + readonly property real actualSize: Math.min(root.width, root.height) + + implicitWidth: root.implicitSize + implicitHeight: root.implicitSize + + Image { + id: image + anchors.fill: parent + fillMode: Image.PreserveAspectFit + + sourceSize.width: root.actualSize + sourceSize.height: root.actualSize + } +}