1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 04:02:50 +01:00

Remove QApplication in favor of QGuiApplication

This commit is contained in:
Elias Steurer 2023-02-03 16:17:47 +01:00
parent d2919576d8
commit 4bce0a2cab
28 changed files with 90 additions and 75 deletions

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QFile>

View File

@ -3,7 +3,7 @@
#pragma once
#include <QAbstractListModel>
#include <QApplication>
#include <QDebug>
#include <QRect>
#include <QScreen>

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QObject>
#include <QPoint>
#include <QProcess>

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QGuiApplication>
#include <QDebug>
#include <QDir>
#include <QFile>

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QClipboard>
#include <QCoreApplication>
#include <QDateTime>

View File

@ -10,6 +10,7 @@
#include <QProcessEnvironment>
#include <QQuickStyle>
#include <QVersionNumber>
#include <QGuiApplication>
namespace ScreenPlay {
@ -132,7 +133,7 @@ App::App()
/*!
\brief Used for initialization after the constructor. The sole purpose is to check if
another ScreenPlay instance is running and then quit early. This is also because we cannot
call QApplication::quit(); in the SDKConnector before the app.exec(); ( the Qt main event
call QGuiApplication::quit(); in the SDKConnector before the app.exec(); ( the Qt main event
loop ) has started.
*/
void App::init()
@ -189,25 +190,25 @@ void App::init()
// Init after we have the paths from settings
m_installedListModel->init();
auto* guiApplication = QGuiApplication::instance();
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
// Set visible if the -silent parameter was not set
if (guiApplication->arguments().contains("-silent")) {
if (guiAppInst->arguments().contains("-silent")) {
qInfo() << "Starting in silent mode.";
settings()->setSilentStart(true);
}
qmlRegisterSingletonInstance("ScreenPlay", 1, 0, "App", this);
m_mainWindowEngine->addImportPath(guiApplication->applicationDirPath() + "/qml");
m_mainWindowEngine->addImportPath(guiAppInst->applicationDirPath() + "/qml");
#if defined(Q_OS_OSX)
QDir workingDir(guiApplication->applicationDirPath());
QDir workingDir(guiAppInst->applicationDirPath());
workingDir.cdUp();
workingDir.cdUp();
workingDir.cdUp();
// OSX Development workaround:
m_mainWindowEngine->addImportPath(workingDir.path() + "/qml");
#endif
guiApplication->addLibraryPath(guiApplication->applicationDirPath() + "/qml");
guiAppInst->addLibraryPath(guiAppInst->applicationDirPath() + "/qml");
if (m_settings->desktopEnvironment() == Settings::DesktopEnvironment::KDE) {
setupKDE();
@ -227,14 +228,15 @@ QString App::version() const
}
/*!
\brief Calls QApplication quit() and can be used to do additional
\brief Calls QGuiApplication quit() and can be used to do additional
tasks before exiting.
*/
void App::exit()
{
m_screenPlayManager->removeAllWallpapers();
m_screenPlayManager->removeAllWidgets();
QApplication::instance()->quit();
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
guiAppInst->quit();
}
bool App::isKDEInstalled()

View File

@ -2,6 +2,7 @@
#include "ScreenPlay/createimportvideo.h"
#include "ScreenPlayUtil/util.h"
#include <QGuiApplication>
namespace ScreenPlay {
@ -61,8 +62,8 @@ void CreateImportVideo::setupFFMPEG()
m_ffprobeExecutable = "ffprobe";
m_ffmpegExecutable = "ffmpeg";
#else
m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + ScreenPlayUtil::executableBinEnding();
m_ffmpegExecutable = QApplication::applicationDirPath() + "/ffmpeg" + ScreenPlayUtil::executableBinEnding();
m_ffprobeExecutable = QGuiApplication::applicationDirPath() + "/ffprobe" + ScreenPlayUtil::executableBinEnding();
m_ffmpegExecutable = QGuiApplication::applicationDirPath() + "/ffmpeg" + ScreenPlayUtil::executableBinEnding();
#endif
if (!QFileInfo::exists(m_ffprobeExecutable)) {
@ -732,7 +733,7 @@ QString CreateImportVideo::waitForFinished(
m_process->setProcessChannelMode(processChannelMode);
m_process->setArguments(args);
m_process->setWorkingDirectory(QApplication::applicationDirPath());
m_process->setWorkingDirectory(QGuiApplication::applicationDirPath());
m_process->start();
qInfo() << m_process->workingDirectory() << m_process->program() << m_process->arguments();

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "ScreenPlay/monitorlistmodel.h"
#include <QGuiApplication>
namespace ScreenPlay {
/*!
@ -27,9 +27,9 @@ MonitorListModel::MonitorListModel(QObject* parent)
{
loadMonitors();
auto* guiAppInst = dynamic_cast<QApplication*>(QApplication::instance());
connect(guiAppInst, &QApplication::screenAdded, this, &MonitorListModel::screenAdded);
connect(guiAppInst, &QApplication::screenRemoved, this, &MonitorListModel::screenRemoved);
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
connect(guiAppInst, &QGuiApplication::screenAdded, this, &MonitorListModel::screenAdded);
connect(guiAppInst, &QGuiApplication::screenRemoved, this, &MonitorListModel::screenRemoved);
}
/*!
@ -148,8 +148,8 @@ void MonitorListModel::loadMonitors()
int offsetX = 0;
int offsetY = 0;
for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i);
for (int i = 0; i < QGuiApplication::screens().count(); i++) {
QScreen* screen = QGuiApplication::screens().at(i);
if (screen->availableGeometry().x() < 0) {
offsetX += (screen->availableGeometry().x() * -1);
}
@ -158,8 +158,8 @@ void MonitorListModel::loadMonitors()
}
}
for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i);
for (int i = 0; i < QGuiApplication::screens().count(); i++) {
QScreen* screen = QGuiApplication::screens().at(i);
// Sometimes we get invalid monitors on Windows. I don't know why...
if (screen->geometry().width() == 0 || screen->geometry().height() == 0)
@ -222,8 +222,8 @@ void MonitorListModel::closeWallpaper(const QString& appID)
*/
QRect MonitorListModel::absoluteDesktopSize() const
{
auto* app = static_cast<QApplication*>(QGuiApplication::instance());
return app->screens().at(0)->availableVirtualGeometry();
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
return guiAppInst->screens().at(0)->availableVirtualGeometry();
}
/*!

View File

@ -1,10 +1,9 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "ScreenPlay/screenplaymanager.h"
#include "ScreenPlay/util.h"
#include <QScopeGuard>
#include "util.h"
namespace ScreenPlay {
/*!

View File

@ -241,7 +241,7 @@ void Settings::initInstalledPath()
*/
void Settings::initSteamInstalledPath()
{
QString appBasePath = QApplication::instance()->applicationDirPath();
QString appBasePath = QGuiApplication::instance()->applicationDirPath();
if (desktopEnvironment() == DesktopEnvironment::OSX) {
appBasePath += "/../../..";
}
@ -293,14 +293,14 @@ bool Settings::retranslateUI()
QString langCode = fixLanguageCode(QVariant::fromValue(language()).toString());
QFile tsFile;
const QString qmPath = QApplication::applicationDirPath() + "/translations/ScreenPlay_" + langCode + ".qm";
const QString qmPath = QGuiApplication::applicationDirPath() + "/translations/ScreenPlay_" + langCode + ".qm";
if (tsFile.exists(qmPath)) {
if (!m_translator.load(qmPath)) {
qWarning() << "Unable to load translation file: " << qmPath;
return false;
}
auto* app = static_cast<QApplication*>(QApplication::instance());
app->installTranslator(&m_translator);
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
guiAppInst->installTranslator(&m_translator);
emit requestRetranslation();
if (language() == Settings::Language::Ko_KR) {

View File

@ -4,7 +4,9 @@
#include "qarchive_enums.hpp"
#include "qarchivediskcompressor.hpp"
#include "qarchivediskextractor.hpp"
#include <QDesktopServices>
#include <QGuiApplication>
#if defined(Q_OS_WIN)
#include <sentry.h>
@ -26,7 +28,8 @@ Util::Util()
{
// Fix log access vilation on quit
utilPointer = this;
QObject::connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, this, []() { utilPointer = nullptr; });
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
QObject::connect(guiAppInst, &QGuiApplication::aboutToQuit, this, []() { utilPointer = nullptr; });
m_extractor = std::make_unique<QArchive::DiskExtractor>();
m_compressor = std::make_unique<QArchive::DiskCompressor>();
@ -58,7 +61,7 @@ Util::~Util() { }
*/
void Util::copyToClipboard(const QString& text) const
{
auto* clipboard = QApplication::clipboard();
auto* clipboard = QGuiApplication::clipboard();
clipboard->setText(text);
}

View File

@ -2,7 +2,7 @@
#include "ScreenPlay/app.h"
#include "ScreenPlay/create.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QDebug>

View File

@ -1,9 +1,10 @@
#include <QApplication>
#include <QObject>
#include <QStringList>
#include <QVector>
#include <QtGlobal>
#include <QtWebEngineQuick>
#include <QGuiApplication>
#include "ScreenPlayUtil/exitcodes.h"
#include "ScreenPlayUtil/util.h"
@ -23,13 +24,13 @@ int main(int argc, char* argv[])
{
#if !defined(Q_OS_LINUX)
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
qputenv("QT_MEDIA_BACKEND", "windows");
#endif
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QtWebEngineQuick::initialize();
QApplication app(argc, argv);
QGuiApplication app(argc, argv);
#if defined(Q_OS_WIN)
WinWindow window;
@ -46,8 +47,8 @@ int main(int argc, char* argv[])
// For testing purposes when starting the ScreenPlayWallpaper directly.
if (argumentList.length() == 1) {
window.setActiveScreensList({ 0 });
window.setProjectPath("test");
// window.setProjectPath("C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/19112022140605-Horde 1980");
//window.setProjectPath("test");
window.setProjectPath("C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/particles");
window.setAppID("test");
window.setVolume(1);
window.setFillMode("fill");

View File

@ -2,7 +2,7 @@
#include "macbridge.h"
#import <Cocoa/Cocoa.h>
#include <QApplication>
#include <QWindow>
#import <objc/runtime.h>

View File

@ -4,6 +4,9 @@
#include "ScreenPlayUtil/projectfile.h"
#include "ScreenPlayUtil/util.h"
#include <QGuiApplication>
/*!
\module ScreenPlayWallpaper
\title ScreenPlayWallpaper
@ -18,7 +21,7 @@
BaseWindow::BaseWindow()
{
QApplication::instance()->installEventFilter(this);
QGuiApplication::instance()->installEventFilter(this);
qRegisterMetaType<ScreenPlay::InstalledType::InstalledType>();
qmlRegisterUncreatableMetaObject(ScreenPlay::InstalledType::staticMetaObject,
@ -196,7 +199,7 @@ QString BaseWindow::loadFromFile(const QString& filename)
*/
QString BaseWindow::getApplicationPath()
{
return QApplication::applicationDirPath();
return QGuiApplication::applicationDirPath();
}
/*!

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QFileSystemWatcher>

View File

@ -16,6 +16,8 @@
#include <sys/wait.h>
#include <unistd.h>
#include <QGuiApplication>
#define WIDTH 512
#define HEIGHT 384
#define OPAQUE 0xffffffff

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QObject>
#include <QQmlContext>

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
class MacBridge : public QObject {
Q_OBJECT

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
class MacIntegration : public QObject {
Q_OBJECT

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "macwindow.h"
#include <QGuiApplication>
ScreenPlay::WallpaperExitCode MacWindow::start()
{
auto* screen = QGuiApplication::screens().at(activeScreensList().at(0));

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QObject>
#include <QQmlContext>

View File

@ -1,7 +1,8 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "winwindow.h"
#include "ScreenPlayUtil/projectfile.h"
#include "qqml.h"
#include "winwindow.h"
#include <QtQml>
#include <QGuiApplication>
#include <algorithm>
#include <iostream>
#include <vector>
@ -77,15 +78,15 @@ LRESULT __stdcall MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam)
auto event = QMouseEvent(type, g_LastMousePosition, mouseButton, mouseButtons, keyboardModifier);
QApplication::sendEvent(g_winGlobalHook, &event);
QGuiApplication::sendEvent(g_winGlobalHook, &event);
if (type == QMouseEvent::Type::MouseButtonPress) {
}
QTimer::singleShot(100, [&]() {
// auto eventPress = QMouseEvent(QMouseEvent::Type::MouseButtonPress, g_LastMousePosition, mouseButton, mouseButtons, {});
// qInfo() << mouseButton << QApplication::sendEvent(g_winGlobalHook, &eventPress) << g_globalOffset.x() << g_globalOffset.y();
// qInfo() << mouseButton << QGuiApplication::sendEvent(g_winGlobalHook, &eventPress) << g_globalOffset.x() << g_globalOffset.y();
auto eventRelease = QMouseEvent(QMouseEvent::Type::MouseButtonRelease, g_LastMousePosition, mouseButton, mouseButtons, {});
QApplication::sendEvent(g_winGlobalHook, &eventRelease);
QGuiApplication::sendEvent(g_winGlobalHook, &eventRelease);
});
return CallNextHookEx(g_mouseHook, nCode, wParam, lParam);
@ -120,17 +121,17 @@ ScreenPlay::WallpaperExitCode WinWindow::start()
}
},
Qt::QueuedConnection);
auto* guiAppInst = dynamic_cast<QApplication*>(QApplication::instance());
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
if (!debugMode()) {
connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, &WinWindow::destroyThis);
}
connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QGuiApplication::screenAdded, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QGuiApplication::screenRemoved, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QGuiApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry);
connect(this, &BaseWindow::reloadQML, this, &WinWindow::clearComponentCache);
connect(&m_checkForFullScreenWindowTimer, &QTimer::timeout, this, &WinWindow::checkForFullScreenWindow);
const auto screens = QApplication::screens();
const auto screens = QGuiApplication::screens();
for (const auto& screen : screens) {
connect(screen, &QScreen::geometryChanged, this, &WinWindow::configureWindowGeometry);
}
@ -209,7 +210,7 @@ BOOL CALLBACK GetMonitorByIndex(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMo
void WinWindow::setupWallpaperForOneScreen(int activeScreen)
{
const QRect screenRect = QApplication::screens().at(activeScreen)->geometry();
const QRect screenRect = QGuiApplication::screens().at(activeScreen)->geometry();
const int boderWidth = 2;
const float scaling = getScaling(activeScreen);
const int borderOffset = -1;
@ -291,7 +292,7 @@ void WinWindow::setupWallpaperForMultipleScreens(const QVector<int>& activeScree
QScreen* upperLeftScreen { nullptr };
// Check for the upper left screen first so we get x and y positions
for (const int screen : activeScreensList) {
QScreen* screenTmp = QApplication::screens().at(screen);
QScreen* screenTmp = QGuiApplication::screens().at(screen);
if (upperLeftScreen != nullptr) {
if (screenTmp->geometry().x() < upperLeftScreen->geometry().x() || screenTmp->geometry().y() < upperLeftScreen->geometry().y()) {
upperLeftScreen = screenTmp;
@ -338,7 +339,7 @@ bool WinWindow::searchWorkerWindowToParentTo()
*/
float WinWindow::getScaling(const int monitorIndex)
{
QScreen* screen = QApplication::screens().at(monitorIndex);
QScreen* screen = QGuiApplication::screens().at(monitorIndex);
const int factor = screen->physicalDotsPerInch();
switch (factor) {
case 72:
@ -359,7 +360,7 @@ float WinWindow::getScaling(const int monitorIndex)
*/
bool WinWindow::hasWindowScaling()
{
const auto screens = QApplication::screens();
const auto screens = QGuiApplication::screens();
for (int i = 0; i < screens.count(); i++) {
if (getScaling(i) != 1) {
return true;
@ -394,7 +395,7 @@ void WinWindow::configureWindowGeometry()
SetWindowLongPtr(m_windowHandle, GWL_STYLE, WS_POPUPWINDOW);
// Ether for one Screen or for all
if ((QApplication::screens().length() == activeScreensList().length()) && (activeScreensList().length() != 1)) {
if ((QGuiApplication::screens().length() == activeScreensList().length()) && (activeScreensList().length() != 1)) {
setupWallpaperForAllScreens();
} else if (activeScreensList().length() == 1) {
setupWallpaperForOneScreen(activeScreensList().at(0));
@ -494,7 +495,7 @@ void WinWindow::terminate()
ShowWindow(m_windowHandleWorker, SW_HIDE);
ShowWindow(m_windowHandleWorker, SW_SHOW);
QApplication::quit();
QGuiApplication::quit();
}
/*!

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QObject>
#include <QQmlContext>

View File

@ -1,8 +1,9 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QStringList>
#include <QtWebEngineQuick>
#include <QGuiApplication>
#include "src/widgetwindow.h"
@ -20,9 +21,9 @@ int main(int argc, char* argv[])
#endif
QtWebEngineQuick::initialize();
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QApplication app(argc, argv);
QGuiApplication app(argc, argv);
const QStringList argumentList = app.arguments();

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "widgetwindow.h"
#include <QCoreApplication>
#include <QGuiApplication>
#include <QSysInfo>
#include "ScreenPlayUtil/contenttypes.h"
@ -76,8 +76,8 @@ WidgetWindow::WidgetWindow(
qWarning() << "Cannot parse Wallpaper type from value" << m_project.value("type");
}
}
m_window.engine()->addImportPath(qGuiApp->applicationDirPath() + "/qml");
auto* guiAppInst = dynamic_cast<QGuiApplication*>(QGuiApplication::instance());
m_window.engine()->addImportPath(guiAppInst->applicationDirPath() + "/qml");
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setResizeMode(QQuickView::ResizeMode::SizeViewToRootObject);
m_window.setSource(QUrl("qrc:/qml/ScreenPlayWidget/qml/Widget.qml"));

View File

@ -2,7 +2,7 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QFileSystemWatcher>