From 9b606a79bc0143e2703a9db8da4cd34e578c9071 Mon Sep 17 00:00:00 2001 From: Elias Date: Sun, 24 Mar 2019 16:52:07 +0100 Subject: [PATCH] Cleanup widgets and Window. When a developer now opens the widget or window project it opens a instance without screenplay sdk. This makes debugging way easier --- ScreenPlayWidget/ScreenPlayWidget.pro | 6 ++--- .../{SPWidgetmain.cpp => main.cpp} | 19 +++++++++----- ...pwidgetmainwindow.cpp => widgetwindow.cpp} | 26 +++++++++---------- .../{spwidgetmainwindow.h => widgetwindow.h} | 17 ++++++------ ScreenPlayWindow/ScreenPlayWindow.pro | 2 +- ScreenPlayWindow/{SPWmain.cpp => main.cpp} | 11 ++++---- 6 files changed, 43 insertions(+), 38 deletions(-) rename ScreenPlayWidget/{SPWidgetmain.cpp => main.cpp} (56%) rename ScreenPlayWidget/src/{spwidgetmainwindow.cpp => widgetwindow.cpp} (80%) rename ScreenPlayWidget/src/{spwidgetmainwindow.h => widgetwindow.h} (91%) rename ScreenPlayWindow/{SPWmain.cpp => main.cpp} (90%) diff --git a/ScreenPlayWidget/ScreenPlayWidget.pro b/ScreenPlayWidget/ScreenPlayWidget.pro index 8225caa2..3c519690 100644 --- a/ScreenPlayWidget/ScreenPlayWidget.pro +++ b/ScreenPlayWidget/ScreenPlayWidget.pro @@ -13,8 +13,8 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - SPWidgetmain.cpp \ - src/spwidgetmainwindow.cpp + main.cpp \ + src/widgetwindow.cpp RESOURCES += \ SPWidgetResources.qrc @@ -57,4 +57,4 @@ QML_DESIGNER_IMPORT_PATH = HEADERS += \ - src/spwidgetmainwindow.h + src/widgetwindow.h diff --git a/ScreenPlayWidget/SPWidgetmain.cpp b/ScreenPlayWidget/main.cpp similarity index 56% rename from ScreenPlayWidget/SPWidgetmain.cpp rename to ScreenPlayWidget/main.cpp index 54e09bc7..f98b190a 100644 --- a/ScreenPlayWidget/SPWidgetmain.cpp +++ b/ScreenPlayWidget/main.cpp @@ -2,7 +2,7 @@ #include #include -#include "src/spwidgetmainwindow.h" +#include "src/widgetwindow.h" #include "../ScreenPlaySDK/screenplaysdk.h" int main(int argc, char* argv[]) @@ -12,18 +12,25 @@ int main(int argc, char* argv[]) ScreenPlaySDK sdk; QGuiApplication app(argc, argv); - QStringList argumentList = app.arguments(); + // If we start with only one argument (app path) + // It means we want to test a single widget + if (argumentList.length() == 1) { + // Todo generic widget + WidgetWindow spwmw("D:/672870/xkcd","appid" ); + + return app.exec(); + } + if (argumentList.length() != 3) { return -3; } - SPWidgetmainwindow spwmw(argumentList.at(1), argumentList.at(2)); - //SPWidgetmainwindow spwmw("D:/672870/xkcd","asasasasd" ); + WidgetWindow spwmw(argumentList.at(1), argumentList.at(2)); - QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &spwmw, &SPWidgetmainwindow::destroyThis); - QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &spwmw, &SPWidgetmainwindow::messageReceived); + QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &spwmw, &WidgetWindow::destroyThis); + QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &spwmw, &WidgetWindow::messageReceived); return app.exec(); } diff --git a/ScreenPlayWidget/src/spwidgetmainwindow.cpp b/ScreenPlayWidget/src/widgetwindow.cpp similarity index 80% rename from ScreenPlayWidget/src/spwidgetmainwindow.cpp rename to ScreenPlayWidget/src/widgetwindow.cpp index 39b95954..1e391ee6 100644 --- a/ScreenPlayWidget/src/spwidgetmainwindow.cpp +++ b/ScreenPlayWidget/src/widgetwindow.cpp @@ -1,8 +1,8 @@ -#include "spwidgetmainwindow.h" +#include "widgetwindow.h" #include -SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QObject* parent) +WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent) : QObject(parent) { @@ -10,7 +10,7 @@ SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QObje m_hwnd = reinterpret_cast(m_window.winId()); Qt::WindowFlags flags = m_window.flags(); - m_window.setWidth(500); + m_window.setWidth(300); m_window.setHeight(300); m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen); @@ -31,7 +31,6 @@ SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QObje m_window.rootContext()->setContextProperty("backend", this); m_window.setColor(Qt::transparent); - m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); m_window.setSource(QUrl("qrc:/main.qml")); #ifdef Q_OS_WIN @@ -42,23 +41,23 @@ SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QObje emit setWidgetSource(fullPath); } -void SPWidgetmainwindow::setSize(QSize size) +void WidgetWindow::setSize(QSize size) { m_window.setWidth(size.width()); m_window.setHeight(size.height()); } -void SPWidgetmainwindow::destroyThis() +void WidgetWindow::destroyThis() { QCoreApplication::quit(); } -void SPWidgetmainwindow::messageReceived(QString key, QString value) +void WidgetWindow::messageReceived(QString key, QString value) { emit qmlSceneValueReceived(key, value); } -void SPWidgetmainwindow::setPos(int xPos, int yPos) +void WidgetWindow::setPos(int xPos, int yPos) { QPoint delta((xPos - m_clickPos.x()), (yPos - m_clickPos.y())); @@ -68,14 +67,14 @@ void SPWidgetmainwindow::setPos(int xPos, int yPos) m_window.setPosition(QPoint(new_x, new_y)); } -void SPWidgetmainwindow::setClickPos(const QPoint& clickPos) +void WidgetWindow::setClickPos(const QPoint& clickPos) { m_clickPos = clickPos; } -void SPWidgetmainwindow::SetWindowBlur(HWND hWnd) -{ #ifdef Q_OS_WIN +void WidgetWindow::SetWindowBlur(HWND hWnd) +{ const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll")); if (hModule) { @@ -101,12 +100,11 @@ void SPWidgetmainwindow::SetWindowBlur(HWND hWnd) typedef BOOL(WINAPI * pSetWindowCompositionAttribute)(HWND, WINCOMPATTRDATA*); const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute)GetProcAddress(hModule, "SetWindowCompositionAttribute"); if (SetWindowCompositionAttribute) { - ACCENTPOLICY policy = { (int)Accent::BLURBEHIND, 0, 0, 0 }; // ACCENT_ENABLE_BLURBEHIND=3... + ACCENTPOLICY policy = { static_cast(Accent::BLURBEHIND), 0, 0, 0 }; // ACCENT_ENABLE_BLURBEHIND=3... WINCOMPATTRDATA data = { 19, &policy, sizeof(ACCENTPOLICY) }; // WCA_ACCENT_POLICY=19 SetWindowCompositionAttribute(hWnd, &data); } FreeLibrary(hModule); } - -#endif } +#endif diff --git a/ScreenPlayWidget/src/spwidgetmainwindow.h b/ScreenPlayWidget/src/widgetwindow.h similarity index 91% rename from ScreenPlayWidget/src/spwidgetmainwindow.h rename to ScreenPlayWidget/src/widgetwindow.h index 95350d6f..c2458af8 100644 --- a/ScreenPlayWidget/src/spwidgetmainwindow.h +++ b/ScreenPlayWidget/src/widgetwindow.h @@ -8,23 +8,22 @@ #include #include #include -#include -#include #include #include #include #include +#include +#include + #ifdef Q_OS_WIN #include -#else -typedef long HWND; #endif -class SPWidgetmainwindow : public QObject { +class WidgetWindow : public QObject { Q_OBJECT public: - explicit SPWidgetmainwindow(QString projectPath, QString appid, QObject* parent = nullptr); + explicit WidgetWindow(QString projectPath, QString appid, QObject* parent = nullptr); Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) @@ -83,16 +82,18 @@ public slots: void setPos(int xPos, int yPos); void setClickPos(const QPoint& clickPos); +#ifdef Q_OS_WIN void SetWindowBlur(HWND hWnd); - +#endif private: QString m_appID; QString m_type = "qmlWidget"; QString m_projectConfig; QJsonObject m_project; + #ifdef Q_OS_WIN HWND m_hwnd; + #endif QPoint m_clickPos = { 0, 0 }; QQuickView m_window; - }; diff --git a/ScreenPlayWindow/ScreenPlayWindow.pro b/ScreenPlayWindow/ScreenPlayWindow.pro index 4c877a7f..462b1d1b 100644 --- a/ScreenPlayWindow/ScreenPlayWindow.pro +++ b/ScreenPlayWindow/ScreenPlayWindow.pro @@ -6,8 +6,8 @@ msvc: LIBS += -luser32 TARGETPATH = ScreenPlayWindow SOURCES += \ - SPWmain.cpp \ #src/SPWmainwindow.cpp \ + main.cpp \ src/basewindow.cpp \ src/windowsdesktopproperties.cpp \ src/winwindow.cpp diff --git a/ScreenPlayWindow/SPWmain.cpp b/ScreenPlayWindow/main.cpp similarity index 90% rename from ScreenPlayWindow/SPWmain.cpp rename to ScreenPlayWindow/main.cpp index 55324e90..768246c9 100644 --- a/ScreenPlayWindow/SPWmain.cpp +++ b/ScreenPlayWindow/main.cpp @@ -15,20 +15,19 @@ int main(int argc, char* argv[]) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); - + QStringList argumentList = app.arguments(); QtWebEngine::initialize(); - bool debug = false; - if (debug) { + // If we start with only one argument (app path) + // It means we want to test a single wallpaper + if (argumentList.length() == 1) { QVector list; list.append(0); - WinWindow window(list, "D:/672870/_tmp_135011", "argumentList.at(3)", "1"); + WinWindow window(list, "D:/672870/_tmp_135011", "appid", "1"); return app.exec(); } // 6 parameter + 1 OS working directory default paramter - QStringList argumentList = app.arguments(); - qDebug() << argumentList; if (argumentList.length() != 7) { return -3; }