diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cc2a23..c825644 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,5 @@ qt_standard_project_setup(REQUIRES 6.5) add_subdirectory(utils/dialog) add_subdirectory(utils/update-screen) +add_subdirectory(utils/donate-screen) diff --git a/utils/donate-screen/CMakeLists.txt b/utils/donate-screen/CMakeLists.txt new file mode 100644 index 0000000..cad04e6 --- /dev/null +++ b/utils/donate-screen/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.16) + +project(hyprland-donate-screen VERSION ${VER} LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt6 6.5 REQUIRED COMPONENTS Widgets Quick QuickControls2 WaylandClient) +find_package(PkgConfig REQUIRED) + +pkg_check_modules(hyprutils REQUIRED IMPORTED_TARGET hyprutils) + +qt_standard_project_setup(REQUIRES 6.5) + +qt_add_executable(hyprland-donate-screen + main.cpp + DonateScreen.cpp +) + +qt_add_qml_module(hyprland-donate-screen + URI org.hyprland.donate-screen + VERSION 1.0 + QML_FILES main.qml +) + +target_link_libraries(hyprland-donate-screen PRIVATE + Qt6::Widgets Qt6::QuickControls2 Qt6::WaylandClientPrivate PkgConfig::hyprutils +) + + +include(GNUInstallDirs) +install(TARGETS hyprland-donate-screen + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/utils/donate-screen/DonateScreen.cpp b/utils/donate-screen/DonateScreen.cpp new file mode 100644 index 0000000..66c3ac5 --- /dev/null +++ b/utils/donate-screen/DonateScreen.cpp @@ -0,0 +1,19 @@ +#include "DonateScreen.hpp" + +#include +#include + +#include +#include +using namespace Hyprutils::String; + +CDonateScreen::CDonateScreen(QObject* parent) : QObject(parent) { + ; +} + +void CDonateScreen::onButtonPress(QString buttonName) { + if (buttonName == "quit") + exit(0); + if (buttonName == "donate") + QDesktopServices::openUrl(QUrl("https://hyprland.org/support")); +} diff --git a/utils/donate-screen/DonateScreen.hpp b/utils/donate-screen/DonateScreen.hpp new file mode 100644 index 0000000..2d0b720 --- /dev/null +++ b/utils/donate-screen/DonateScreen.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +class CDonateScreen : public QObject { + Q_OBJECT; + QML_NAMED_ELEMENT(DonateScreen); + QML_SINGLETON; + + public: + explicit CDonateScreen(QObject* parent = nullptr); + + Q_INVOKABLE void onButtonPress(QString buttonName = ""); +}; diff --git a/utils/donate-screen/main.cpp b/utils/donate-screen/main.cpp new file mode 100644 index 0000000..cec1812 --- /dev/null +++ b/utils/donate-screen/main.cpp @@ -0,0 +1,30 @@ +#include "DonateScreen.hpp" +#include +#include +#include +#include +#include +#include +#include + +using namespace Hyprutils::String; + +int main(int argc, char* argv[]) { + // disable logs to not trash the stdout + qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false")); + + auto dialog = new CDonateScreen(); + + QApplication app(argc, argv); + app.setApplicationName("Support Hyprland"); + app.setApplicationDisplayName("Support Hyprland"); + + if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) + QQuickStyle::setStyle("org.kde.desktop"); + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("donateScreen", dialog); + engine.load("qrc:/qt/qml/org/hyprland/donate-screen/main.qml"); + + return app.exec(); +} diff --git a/utils/donate-screen/main.qml b/utils/donate-screen/main.qml new file mode 100644 index 0000000..0acbbfe --- /dev/null +++ b/utils/donate-screen/main.qml @@ -0,0 +1,98 @@ +pragma ComponentBehavior: Bound + +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import './' + +ApplicationWindow { + id: window + + FontMetrics { id: fontMetrics } + + property var windowPaddingH: 30 + property var windowPaddingV: 3 + + minimumWidth: Math.max(fontMetrics.height * 9, mainLayout.Layout.minimumWidth) + mainLayout.anchors.margins * 2 + windowPaddingH * 2 + minimumHeight: Math.max(fontMetrics.height * 9, mainLayout.Layout.minimumHeight) + mainLayout.anchors.margins * 2 + windowPaddingV * 2 + maximumWidth: minimumWidth + maximumHeight: minimumHeight + visible: true + + component Separator: Rectangle { + color: Qt.darker(system.windowText, 1.5) + } + + component VSeparator: Separator { + implicitWidth: 1 + Layout.fillHeight: true + Layout.topMargin: fontMetrics.height + Layout.bottomMargin: fontMetrics.height + } + + component HSeparator: Separator { + implicitHeight: 1 + Layout.fillWidth: true + Layout.leftMargin: fontMetrics.height * 8 + Layout.rightMargin: fontMetrics.height * 8 + } + + SystemPalette { + id: system + colorGroup: SystemPalette.Active + } + + ColumnLayout { + id: mainLayout + spacing: fontMetrics.height + + anchors { + fill: parent + margins: 4 + } + + Text { + font.pointSize: fontMetrics.height + color: system.windowText + text: "Support Hyprland" + Layout.alignment: Qt.AlignHCenter + } + + HSeparator {} + + Text { + color: system.windowText + text: "Hyprland is maintained by volunteers, and led by one person in their free time.
Your support is valuable, and helps fund Hyprland's continued existence.

You can donate once, or monthly, and it takes less than 5 minutes." + Layout.alignment: Qt.AlignHCenter + horizontalAlignment: Text.AlignHCenter + textFormat: TextEdit.RichText + onLinkActivated: Qt.openUrlExternally(link) + } + + Rectangle { + color: "transparent" + Layout.minimumHeight: 4 + Layout.fillHeight: true + } + + RowLayout { + spacing: 6 + Layout.leftMargin: 20 + Layout.alignment: Qt.AlignRight + + Button { + text: "Donate" + onClicked: (e) => { + donateScreen.onButtonPress("donate"); + } + } + + Button { + text: "No thanks" + onClicked: (e) => { + donateScreen.onButtonPress("quit"); + } + } + } + } +}