Skip to content

Commit

Permalink
utils: add donate-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jan 7, 2025
1 parent 6997fe3 commit 6cc1cf5
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

36 changes: 36 additions & 0 deletions utils/donate-screen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
19 changes: 19 additions & 0 deletions utils/donate-screen/DonateScreen.cpp
Original file line number Diff line number Diff line change
@@ -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"));
}
20 changes: 20 additions & 0 deletions utils/donate-screen/DonateScreen.hpp
Original file line number Diff line number Diff line change
@@ -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 = "");
};
30 changes: 30 additions & 0 deletions utils/donate-screen/main.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
98 changes: 98 additions & 0 deletions utils/donate-screen/main.qml
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
}
}

0 comments on commit 6cc1cf5

Please sign in to comment.