utils: add donate-screen
Some checks failed
Build / nix (push) Has been cancelled

This commit is contained in:
Vaxry 2025-01-07 14:53:19 +01:00
parent 6997fe382d
commit 6cc1cf51f2
6 changed files with 204 additions and 0 deletions

View file

@ -18,4 +18,5 @@ qt_standard_project_setup(REQUIRES 6.5)
add_subdirectory(utils/dialog) add_subdirectory(utils/dialog)
add_subdirectory(utils/update-screen) add_subdirectory(utils/update-screen)
add_subdirectory(utils/donate-screen)

View file

@ -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}
)

View file

@ -0,0 +1,19 @@
#include "DonateScreen.hpp"
#include <print>
#include <QDesktopServices>
#include <hyprutils/string/String.hpp>
#include <hyprutils/os/Process.hpp>
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"));
}

View file

@ -0,0 +1,20 @@
#pragma once
#include <QObject>
#include <QQmlApplicationEngine>
#include <QPixmap>
#include <QIcon>
#include <qcontainerfwd.h>
#include <qqmlintegration.h>
#include <qtmetamacros.h>
class CDonateScreen : public QObject {
Q_OBJECT;
QML_NAMED_ELEMENT(DonateScreen);
QML_SINGLETON;
public:
explicit CDonateScreen(QObject* parent = nullptr);
Q_INVOKABLE void onButtonPress(QString buttonName = "");
};

View file

@ -0,0 +1,30 @@
#include "DonateScreen.hpp"
#include <hyprutils/string/VarList.hpp>
#include <print>
#include <qapplication.h>
#include <qqmlapplicationengine.h>
#include <qquickstyle.h>
#include <qtenvironmentvariables.h>
#include <QQmlContext>
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();
}

View file

@ -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.<br/>Your support is valuable, and helps fund Hyprland's continued existence.<br/><br/>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");
}
}
}
}
}