From 22e6ff814f9323f4d6b5568f261bb33a88c43f3e Mon Sep 17 00:00:00 2001 From: herrMirto Date: Thu, 26 Jun 2025 09:01:36 +0200 Subject: [PATCH] Add initial Qt skeleton --- PinVolQt/.gitignore | 1 + PinVolQt/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ PinVolQt/qml/main.qml | 26 ++++++++++++++++++++++++++ PinVolQt/src/main.cpp | 20 ++++++++++++++++++++ PinVolQt/src/volumemanager.cpp | 26 ++++++++++++++++++++++++++ PinVolQt/src/volumemanager.h | 24 ++++++++++++++++++++++++ README.md | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 158 insertions(+) create mode 100644 PinVolQt/.gitignore create mode 100644 PinVolQt/CMakeLists.txt create mode 100644 PinVolQt/qml/main.qml create mode 100644 PinVolQt/src/main.cpp create mode 100644 PinVolQt/src/volumemanager.cpp create mode 100644 PinVolQt/src/volumemanager.h diff --git a/PinVolQt/.gitignore b/PinVolQt/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/PinVolQt/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/PinVolQt/CMakeLists.txt b/PinVolQt/CMakeLists.txt new file mode 100644 index 0000000..9d0326b --- /dev/null +++ b/PinVolQt/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.14) +project(PinVolQt LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +find_package(Qt6 REQUIRED COMPONENTS Core Quick Multimedia Widgets) + +qt_standard_project_setup() + +qt_add_executable(PinVolQt + src/main.cpp + src/volumemanager.cpp src/volumemanager.h +) + +qt_add_qml_module(PinVolQt + URI PinVolQt + VERSION 1.0 + QML_FILES + qml/main.qml +) + +target_link_libraries(PinVolQt PRIVATE Qt6::Core Qt6::Quick Qt6::Multimedia Qt6::Widgets) + +install(TARGETS PinVolQt + BUNDLE DESTINATION . + RUNTIME DESTINATION bin +) diff --git a/PinVolQt/qml/main.qml b/PinVolQt/qml/main.qml new file mode 100644 index 0000000..0cd7862 --- /dev/null +++ b/PinVolQt/qml/main.qml @@ -0,0 +1,26 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import PinVolQt 1.0 + +ApplicationWindow { + width: 400 + height: 300 + visible: true + title: qsTr("PinVolQt") + + Column { + anchors.centerIn: parent + spacing: 20 + Slider { + id: volumeSlider + from: 0 + to: 100 + value: VolumeManager.volume + onValueChanged: VolumeManager.volume = value + } + Text { + text: qsTr("Volume: %1").arg(Math.round(VolumeManager.volume)) + font.pointSize: 20 + } + } +} diff --git a/PinVolQt/src/main.cpp b/PinVolQt/src/main.cpp new file mode 100644 index 0000000..b655a37 --- /dev/null +++ b/PinVolQt/src/main.cpp @@ -0,0 +1,20 @@ +#include +#include +#include "volumemanager.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + qmlRegisterSingletonInstance("PinVolQt", 1, 0, "VolumeManager", &VolumeManager::instance()); + + QQmlApplicationEngine engine; + const QUrl url(u"qrc:/qml/main.qml"_qs); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/PinVolQt/src/volumemanager.cpp b/PinVolQt/src/volumemanager.cpp new file mode 100644 index 0000000..ea044b1 --- /dev/null +++ b/PinVolQt/src/volumemanager.cpp @@ -0,0 +1,26 @@ +#include "volumemanager.h" +#include +#ifdef Q_OS_WIN +#include +#endif + +VolumeManager &VolumeManager::instance() +{ + static VolumeManager mgr; + return mgr; +} + +VolumeManager::VolumeManager(QObject *parent) + : QObject(parent) +{ +} + +void VolumeManager::setVolume(int vol) +{ + vol = qBound(0, vol, 100); + if (m_volume == vol) + return; + m_volume = vol; + // TODO: integrate with platform-specific volume APIs or Qt Multimedia + emit volumeChanged(m_volume); +} diff --git a/PinVolQt/src/volumemanager.h b/PinVolQt/src/volumemanager.h new file mode 100644 index 0000000..3b1cb90 --- /dev/null +++ b/PinVolQt/src/volumemanager.h @@ -0,0 +1,24 @@ +#ifndef VOLUMEMANAGER_H +#define VOLUMEMANAGER_H + +#include + +class VolumeManager : public QObject +{ + Q_OBJECT + Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) +public: + static VolumeManager &instance(); + + int volume() const { return m_volume; } + void setVolume(int vol); + +signals: + void volumeChanged(int volume); + +private: + explicit VolumeManager(QObject *parent = nullptr); + int m_volume = 50; +}; + +#endif // VOLUMEMANAGER_H diff --git a/README.md b/README.md index 7e19e7c..0b0dc9c 100644 --- a/README.md +++ b/README.md @@ -69,3 +69,35 @@ that are useful in a pin cab environment: title of each game it launches, which lets PinVol display the friendly game title instead of just the filename. + +## Cross-platform Qt version + +The repository now contains an experimental Qt/QML port in the `PinVolQt` +subdirectory. This version aims to run on Windows, macOS and Linux. + +### Build instructions + +1. Install Qt 6 and CMake 3.14 or newer. +2. Create a build directory and run CMake: + + ```bash + cd PinVolQt + cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build + ``` +3. The resulting binary will be placed in `build` (or `build/bin` on + Windows). + +### Running + +Execute the `PinVolQt` binary. The application displays a simple window +with a volume slider. Background operation is provided via the system +tray when supported by the platform. On macOS and Linux you may need to +explicitly allow the application to show the tray icon. + +### Background mode + +To run in the background, minimize the main window. On platforms that +support a system tray, the application will remain accessible from the +tray icon. Ensure your desktop environment allows tray icons for the app +so volume hotkeys remain active.