diff --git a/ScreenPlay.pro b/ScreenPlay.pro index d889f70b..82d42e9f 100644 --- a/ScreenPlay.pro +++ b/ScreenPlay.pro @@ -2,4 +2,6 @@ TEMPLATE = subdirs SUBDIRS = \ ScreenPlay/ScreenPlay.pro \ ScreenPlayWindow/ScreenPlayWindow.pro \ + ScreenPlaySDK/Screenplaysdk.pro +ScreenPlayWindow.depends = ScreenPlaySDK diff --git a/ScreenPlay/ScreenPlay.pro b/ScreenPlay/ScreenPlay.pro index 4f833a63..b491794e 100644 --- a/ScreenPlay/ScreenPlay.pro +++ b/ScreenPlay/ScreenPlay.pro @@ -19,7 +19,8 @@ SOURCES += main.cpp \ src/steamworkshoplistmodel.cpp \ src/workshopitem.cpp \ src/widgetbridge.cpp \ - src/installedlistfilter.cpp + src/installedlistfilter.cpp \ + src/sdkconnector.cpp RESOURCES += \ Resources.qrc \ @@ -40,7 +41,8 @@ HEADERS += \ src/steamworkshoplistmodel.h \ src/workshopitem.h \ src/widgetbridge.h \ - src/installedlistfilter.h + src/installedlistfilter.h \ + src/sdkconnector.h INCLUDEPATH += \ $$PWD/ThirdParty/ \ diff --git a/ScreenPlay/main.cpp b/ScreenPlay/main.cpp index 38cbfd6c..caea8f8e 100644 --- a/ScreenPlay/main.cpp +++ b/ScreenPlay/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -11,31 +12,31 @@ #include #include #include +#include #include +#include #include #include #include #include -#include #include -#include -#include +#include "installedlistfilter.h" #include "installedlistmodel.h" #include "monitorlistmodel.h" #include "packagefilehandler.h" #include "profilelistmodel.h" -#include "quazip5/quazip.h" #include "settings.h" #include "steam/steam_api.h" #include "steamworkshop.h" #include "steamworkshoplistmodel.h" #include "widget.h" -#include "widgetbridge.h" -#include "installedlistfilter.h" +#include "sdkconnector.h" int main(int argc, char* argv[]) { + + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseOpenGLES); @@ -45,7 +46,7 @@ int main(int argc, char* argv[]) trsl.load(":/languages/ScreenPlay_de.qm"); app.installTranslator(&trsl); - QObject::connect(&app,&QGuiApplication::screenRemoved,[&]() { qDebug() << "removed"; }); + QObject::connect(&app, &QGuiApplication::screenRemoved, [&]() { qDebug() << "removed"; }); QFontDatabase::addApplicationFont(":/assets/fonts/LibreBaskerville-Italic.ttf"); QFontDatabase::addApplicationFont(":/assets/fonts/Roboto-Light.ttf"); @@ -61,7 +62,6 @@ int main(int argc, char* argv[]) QCoreApplication::setApplicationVersion("0.1.0"); app.setWindowIcon(QIcon(":/assets/icons/favicon.ico")); - bool steamErrorRestart = false; bool steamErrorAPIInit = false; @@ -80,15 +80,19 @@ int main(int argc, char* argv[]) PackageFileHandler packageFileHandler; ProfileListModel profileListModel; SteamWorkshopListModel steamWorkshopListModel; - - WidgetBridge widgetBridge; - + SDKConnector sdkConnector; InstalledListFilter installedListFilter(&installedListModel); // Create settings in the end because for now it depends on // such things as the profile list model to complete // It will also set the m_absoluteStoragePath in profileListModel and installedListModel - Settings settings(&profileListModel, &monitorListModel, &installedListModel, steamID); + Settings settings(&profileListModel, &monitorListModel, &installedListModel, &sdkConnector, steamID); + + #ifdef QT_DEBUG + settings.setScreenPlayWindowPath(QUrl("C:/Users/Eli/Code/Qt/build-ScreenPlay-Desktop-Debug/ScreenPlayWindow/debug/ScreenPlayWindow.exe")); + #elif QT_NO_DEBUG + settings.setScreenPlayWindowPath(QUrl("ScreenPlayWindow.exe")); + #endif SteamWorkshop steamWorkshop(steamID, &steamWorkshopListModel, &settings); // All the list need the default path from the settings @@ -96,7 +100,6 @@ int main(int argc, char* argv[]) profileListModel.loadProfiles(); settings.loadActiveProfiles(); - QQmlApplicationEngine mainWindowEngine; mainWindowEngine.rootContext()->setContextProperty("installedListFilter", &installedListFilter); mainWindowEngine.rootContext()->setContextProperty("workshopListModel", &steamWorkshopListModel); @@ -117,7 +120,7 @@ int main(int argc, char* argv[]) // Set visible if the -silent parameter was not set QStringList argumentList = app.arguments(); - if(!argumentList.contains("-silent")){ + if (!argumentList.contains("-silent")) { settings.setMainWindowVisible(true); } @@ -132,10 +135,8 @@ int main(int argc, char* argv[]) timer.setInterval(100); timer.start(); - QObject::connect(&steamWorkshop,&SteamWorkshop::workshopSearchResult, - &steamWorkshopListModel,&SteamWorkshopListModel::append,Qt::QueuedConnection); - - + QObject::connect(&steamWorkshop, &SteamWorkshop::workshopSearchResult, + &steamWorkshopListModel, &SteamWorkshopListModel::append, Qt::QueuedConnection); int status = app.exec(); diff --git a/ScreenPlay/src/sdkconnector.cpp b/ScreenPlay/src/sdkconnector.cpp new file mode 100644 index 00000000..d564f7cc --- /dev/null +++ b/ScreenPlay/src/sdkconnector.cpp @@ -0,0 +1,40 @@ +#include "sdkconnector.h" + +SDKConnector::SDKConnector(QObject* parent) + : QObject(parent) +{ + m_server = QSharedPointer(new QLocalServer(this)); + connect(m_server.data(), &QLocalServer::newConnection, this, &SDKConnector::newConnection); + + if (!m_server.data()->listen("ScreenPlay")) { + qDebug() << "SERVER: Server could not start"; + } else { + qDebug() << "SERVER: Server started!"; + } +} + +void SDKConnector::newConnection() +{ + QLocalSocket* socket = m_server.data()->nextPendingConnection(); + m_clients.append(socket); + + connect(socket,&QLocalSocket::readyRead, [&]() { + qDebug() << socket->readAll(); + }); + +// connect(socket,&QLocalSocket::stateChanged, [&]() { +// switch (socket->state()) { +// case QLocalSocket::UnconnectedState:; +// break; +// case QLocalSocket::ConnectingState:; +// break; +// case QLocalSocket::ConnectedState:; +// break; +// case QLocalSocket::ClosingState:; +// break; +// } +// }); +} + + + diff --git a/ScreenPlay/src/sdkconnector.h b/ScreenPlay/src/sdkconnector.h new file mode 100644 index 00000000..6570ef87 --- /dev/null +++ b/ScreenPlay/src/sdkconnector.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +class SDKConnector : public QObject +{ + Q_OBJECT +public: + explicit SDKConnector(QObject *parent = nullptr); + +signals: + +public slots: + void newConnection(); + +private: + QSharedPointer m_server; + QVector m_clients; + +}; + diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index 5e0e8427..65468b26 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -1,12 +1,13 @@ #include "settings.h" -Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, AppId_t steamID, QObject* parent) +Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, AppId_t steamID, QObject* parent) : QObject(parent) { m_plm = plm; m_mlm = mlm; m_ilm = ilm; + m_sdkc = sdkc; m_steamID = steamID; QFile configTmp; @@ -105,9 +106,8 @@ void Settings::setWallpaper(int monitorIndex, QUrl absoluteStoragePath) } } increaseActiveWallpaperCounter(); - auto tmpWallpaper = QSharedPointer(new Wallpaper(project, monitor)); - QObject::connect(tmpWallpaper.data(),&Wallpaper::destroyed,this, &Settings::destroyWallpaper); - m_wallpapers.append(tmpWallpaper); + m_windows.append(new QProcess()); + m_windows.last()->start(m_screenPlayWindowPath.toString()); } void Settings::setWidget(QUrl absoluteStoragePath) @@ -155,23 +155,23 @@ void Settings::loadActiveProfiles() QString profileName = activeProfilesTmp.at(i).toObject().value("profile").toString(); QString monitorID = activeProfilesTmp.at(i).toObject().value("monitorID").toString(); Profile profile; -// auto spf = new QSharedPointer(new ProjectFile()); + // auto spf = new QSharedPointer(new ProjectFile()); -// if (!m_plm->getProfileByName(profileName, &profile)) -// continue; + // if (!m_plm->getProfileByName(profileName, &profile)) + // continue; -// if (!m_ilm->getProjectByAbsoluteStoragePath(&profile.m_absolutePath, spf)) -// continue; + // if (!m_ilm->getProjectByAbsoluteStoragePath(&profile.m_absolutePath, spf)) + // continue; -// constructWallpaper(profile, monitorID, spf); + // constructWallpaper(profile, monitorID, spf); } } } -void Settings::destroyWallpaper(QObject *ref) +void Settings::destroyWallpaper(QObject* ref) { for (int i = 0; i < m_wallpapers.count(); ++i) { - if(m_wallpapers.at(i) == ref){ + if (m_wallpapers.at(i) == ref) { m_wallpapers.at(i).data()->deleteLater(); //m_wallpapers.remove(i); return; @@ -202,7 +202,7 @@ void Settings::writeSingleSettingConfig(QString name, QVariant value) QFile configTmp; configTmp.setFileName(m_localSettingsPath.toString() + "/settings.json"); - configTmp.open(QIODevice::ReadOnly| QIODevice::Text); + configTmp.open(QIODevice::ReadOnly | QIODevice::Text); QString config = configTmp.readAll(); configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError); @@ -227,7 +227,9 @@ void Settings::removeAll() for (int i = 0; i < m_wallpapers.size(); ++i) { m_wallpapers.at(i).data()->destroyWallpaper(); } - //m_wallpapers.clear(); + for (int i = 0; i < m_windows.size(); ++i) { + + } setActiveWallpaperCounter(0); } @@ -273,7 +275,6 @@ QString Settings::fixWindowsPath(QString url) return url.replace("/", "\\\\"); } - void Settings::removeWallpaperAt(int pos) { if (pos > 0 && pos > m_wallpapers.size()) @@ -298,6 +299,16 @@ void Settings::createDefaultConfig() defaultSettings.close(); } +QUrl Settings::getScreenPlayWindowPath() const +{ + return m_screenPlayWindowPath; +} + +void Settings::setScreenPlayWindowPath(const QUrl& screenPlayWindowPath) +{ + m_screenPlayWindowPath = screenPlayWindowPath; +} + ActiveProfiles::ActiveProfiles() { } diff --git a/ScreenPlay/src/settings.h b/ScreenPlay/src/settings.h index 93a6f9f2..6865ba19 100644 --- a/ScreenPlay/src/settings.h +++ b/ScreenPlay/src/settings.h @@ -19,7 +19,9 @@ #include #include #include +#include +#include "sdkconnector.h" #include "installedlistmodel.h" #include "monitorlistmodel.h" #include "profile.h" @@ -33,7 +35,7 @@ class Settings : public QObject { Q_OBJECT public: - explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, AppId_t steamID, QObject* parent = nullptr); + explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, AppId_t steamID, QObject* parent = nullptr); ~Settings(); Q_PROPERTY(Version version READ version) @@ -107,6 +109,9 @@ public: return m_activeWallpaperCounter; } + QUrl getScreenPlayWindowPath() const; + void setScreenPlayWindowPath(const QUrl &screenPlayWindowPath); + signals: void autostartChanged(bool autostart); void highPriorityStartChanged(bool highPriorityStart); @@ -264,13 +269,17 @@ private: ProfileListModel* m_plm; InstalledListModel* m_ilm; MonitorListModel* m_mlm; + SDKConnector* m_sdkc; + QThread m_thread; QVector> m_wallpapers; QVector m_widgets; + QVector m_windows; QUrl m_localStoragePath; QUrl m_localSettingsPath; + QUrl m_screenPlayWindowPath; bool m_hasWorkshopBannerSeen = false; QString m_decoder; diff --git a/ScreenPlay/src/widgetbridge.h b/ScreenPlay/src/widgetbridge.h index bb30d9ef..c334cd67 100644 --- a/ScreenPlay/src/widgetbridge.h +++ b/ScreenPlay/src/widgetbridge.h @@ -1,4 +1,4 @@ -#pragma once + #include diff --git a/ScreenPlaySDK/Screenplaysdk.pro b/ScreenPlaySDK/Screenplaysdk.pro new file mode 100644 index 00000000..85f8a263 --- /dev/null +++ b/ScreenPlaySDK/Screenplaysdk.pro @@ -0,0 +1,34 @@ +TEMPLATE = lib +TARGET = ScreenPlaySDK +QT += qml quick +CONFIG += plugin c++11 + +TARGET = $$qtLibraryTarget($$TARGET) +uri = net.aimber.screenplaysdk + +# Input +SOURCES += \ + screenplay-sdk_plugin.cpp \ + screenplaysdk.cpp + +HEADERS += \ + screenplay-sdk_plugin.h \ + screenplaysdk.h + +DISTFILES = qmldir + +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { + copy_qmldir.target = $$OUT_PWD/qmldir + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + QMAKE_EXTRA_TARGETS += copy_qmldir + PRE_TARGETDEPS += $$copy_qmldir.target +} + +qmldir.files = qmldir + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) +qmldir.path = $$installPath +target.path = $$installPath +INSTALLS += target qmldir + diff --git a/ScreenPlaySDK/qmldir b/ScreenPlaySDK/qmldir new file mode 100644 index 00000000..996d828c --- /dev/null +++ b/ScreenPlaySDK/qmldir @@ -0,0 +1,2 @@ +module net.aimber.screenplaysdk +plugin ScreenPlaySDK diff --git a/ScreenPlaySDK/screenplay-sdk_plugin.cpp b/ScreenPlaySDK/screenplay-sdk_plugin.cpp new file mode 100644 index 00000000..510094cb --- /dev/null +++ b/ScreenPlaySDK/screenplay-sdk_plugin.cpp @@ -0,0 +1,11 @@ +#include "screenplay-sdk_plugin.h" +#include "screenplaysdk.h" + +#include + +void ScreenPlay_SDKPlugin::registerTypes(const char *uri) +{ + // @uri net.aimber.screenplaysdk + qmlRegisterType(uri, 1, 0, "ScreenPlaySDK"); +} + diff --git a/ScreenPlaySDK/screenplay-sdk_plugin.h b/ScreenPlaySDK/screenplay-sdk_plugin.h new file mode 100644 index 00000000..b241190a --- /dev/null +++ b/ScreenPlaySDK/screenplay-sdk_plugin.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class ScreenPlay_SDKPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void registerTypes(const char *uri); +}; diff --git a/ScreenPlaySDK/screenplaysdk.cpp b/ScreenPlaySDK/screenplaysdk.cpp new file mode 100644 index 00000000..a8c12992 --- /dev/null +++ b/ScreenPlaySDK/screenplaysdk.cpp @@ -0,0 +1,62 @@ +#include "screenplaysdk.h" + +ScreenPlaySDK::ScreenPlaySDK(QQuickItem *parent): + QQuickItem(parent) +{ + // By default, QQuickItem does not draw anything. If you subclass + // QQuickItem to create a visual item, you will need to uncomment the + // following line and re-implement updatePaintNode() + + // setFlag(ItemHasContents, true); + m_socket = QSharedPointer(new QLocalSocket()); + m_socket.data()->setServerName("ScreenPlay"); + QObject::connect(m_socket.data(), &QLocalSocket::connected, this, &ScreenPlaySDK::connected); + QObject::connect(m_socket.data(), &QLocalSocket::disconnected, this, &ScreenPlaySDK::disconnected); + QObject::connect(m_socket.data(), &QLocalSocket::bytesWritten, this, &ScreenPlaySDK::bytesWritten); + QObject::connect(m_socket.data(), &QLocalSocket::readyRead, this, &ScreenPlaySDK::readyRead); + QObject::connect(m_socket.data(), QOverload::of(&QLocalSocket::error), this, &ScreenPlaySDK::error); + m_socket.data()->connectToServer(); +} + +ScreenPlaySDK::~ScreenPlaySDK() +{ +} + +void ScreenPlaySDK::connected() +{ + setIsConnected(true); + emit sdkConnected(); +} + +void ScreenPlaySDK::disconnected() +{ + setIsConnected(false); + emit sdkDisconnected(); +} + +void ScreenPlaySDK::bytesWritten(qint64 bytes) +{ + +} + +void ScreenPlaySDK::readyRead() +{ + QString tmp = m_socket.data()->readAll(); + QJsonParseError err; + QJsonDocument jdoc = QJsonDocument::fromJson(QByteArray::fromStdString(tmp.toStdString()),&err); + + if (!(err.error == QJsonParseError::NoError)) { + emit incommingMessageError(tmp); + return; + } + emit incommingMessage(tmp); +} + +void ScreenPlaySDK::error(QLocalSocket::LocalSocketError socketError) +{ + emit sdkSocketError("Error"); + + if(socketError == QLocalSocket::LocalSocketError::ConnectionRefusedError){ + //QCoreApplication::quit(); + } +} diff --git a/ScreenPlaySDK/screenplaysdk.h b/ScreenPlaySDK/screenplaysdk.h new file mode 100644 index 00000000..aa927297 --- /dev/null +++ b/ScreenPlaySDK/screenplaysdk.h @@ -0,0 +1,85 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ScreenPlaySDK : public QQuickItem +{ + Q_OBJECT + Q_DISABLE_COPY(ScreenPlaySDK) + +public: + ScreenPlaySDK(QQuickItem *parent = nullptr); + ~ScreenPlaySDK(); + + Q_PROPERTY(QString contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged) + Q_PROPERTY(bool isConnected READ isConnected WRITE setIsConnected NOTIFY isConnectedChanged) + QString contentType() const + { + return m_contentType; + } + + bool isConnected() const + { + return m_isConnected; + } + +public slots: + void connected(); + void disconnected(); + void bytesWritten(qint64 bytes); + void readyRead(); + void error(QLocalSocket::LocalSocketError socketError); + + void setContentType(QString contentType) + { + if (m_contentType == contentType) + return; + + m_contentType = contentType; + + if(isConnected()){ + m_socket.data()->write(QByteArray(m_contentType.toLatin1())); + m_socket.data()->flush(); + m_socket.data()->waitForBytesWritten(); + } + emit contentTypeChanged(m_contentType); + } + + void setIsConnected(bool isConnected) + { + if (m_isConnected == isConnected) + return; + + m_isConnected = isConnected; + emit isConnectedChanged(m_isConnected); + } + +signals: + void incommingMessage(QString msg); + void incommingMessageError(QString msg); + + + void sdkConnected(); + void sdkDisconnected(); + void sdkSocketError(QString type); + + void contentTypeChanged(QString contentType); + + void isConnectedChanged(bool isConnected); + +private: + QSharedPointer m_socket; + + QString m_contentType = "undefined"; + bool m_isConnected = false; +}; + diff --git a/ScreenPlayWindow/ScreenPlayWindow.pro b/ScreenPlayWindow/ScreenPlayWindow.pro index 7fab3fa6..509979d2 100644 --- a/ScreenPlayWindow/ScreenPlayWindow.pro +++ b/ScreenPlayWindow/ScreenPlayWindow.pro @@ -1,5 +1,5 @@ TEMPLATE = app -QT += qml quick av widgets quickcontrols2 +QT += qml quick av widgets quickcontrols2 CONFIG += c++17 @@ -28,17 +28,9 @@ CONFIG(debug, debug|release) { } -install_it.files += assets/templates/config.json \ - assets/icons/favicon.ico \ - steam_appid.txt \ - settings.json \ - -INSTALLS += install_it - - # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH += [QtAVSourceCodeDir]/qml - +QML_IMPORT_PATH += "C:\msys64\mingw64\share\qt5\qml" # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = @@ -59,5 +51,5 @@ win32 { INCLUDEPATH += "C:\msys64\mingw64\include" } - - +win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-ScreenPlay-Desktop-Release/ScreenPlaySDK/release -llibScreenPlaySDK.dll +else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-ScreenPlay-Desktop-Debug/ScreenPlaySDK/debug -llibScreenPlaySDKd.dll diff --git a/ScreenPlayWindow/main.cpp b/ScreenPlayWindow/main.cpp index f37730be..1a377e9d 100644 --- a/ScreenPlayWindow/main.cpp +++ b/ScreenPlayWindow/main.cpp @@ -1,12 +1,12 @@ #include "src/mainwindow.h" #include + int main(int argc, char *argv[]) { + //QCoreApplication::addLibraryPath("C:/msys64/mingw64/bin"); QApplication a(argc, argv); - MainWindow w; - w.show(); - w.close(); + MainWindow w; return a.exec(); } diff --git a/ScreenPlayWindow/main.qml b/ScreenPlayWindow/main.qml index 70556f7a..9cd271df 100644 --- a/ScreenPlayWindow/main.qml +++ b/ScreenPlayWindow/main.qml @@ -1,6 +1,54 @@ import QtQuick 2.9 +import net.aimber.screenplaysdk 1.0 Rectangle { - color: "orange" + color: "gray" anchors.fill: parent + + + ScreenPlaySDK { + contentType: "wallpaper" + + onIncommingMessageError: { + name.text = msg + } + + onSdkConnected: { + name.text = "connected" + } + + onSdkDisconnected: { + name.text = "disconnected" + mainwindow.destroyThis() + } + } + + Text { + id: name + text: qsTr("text") + anchors { + horizontalCenter: parent.horizontalCenter + } + y:-100 + + font.pixelSize: 36 + SequentialAnimation { + loops: SequentialAnimation.Infinite + running: true + NumberAnimation { + target: name + property: "y" + duration: 2000 + easing.type: Easing.InOutQuad + to:500 + } + NumberAnimation { + target: name + property: "y" + duration: 2000 + easing.type: Easing.InOutQuad + to:300 + } + } + } } diff --git a/ScreenPlayWindow/src/mainwindow.cpp b/ScreenPlayWindow/src/mainwindow.cpp index 873c95f2..d2732865 100644 --- a/ScreenPlayWindow/src/mainwindow.cpp +++ b/ScreenPlayWindow/src/mainwindow.cpp @@ -1,6 +1,5 @@ #include "mainwindow.h" - BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam) { // 0xXXXXXXX "" WorkerW @@ -17,13 +16,16 @@ BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam) MainWindow::MainWindow(QScreen* parent) : QWindow(parent) { -// for (int var = 0; var < QApplication::screens().count(); ++var) { -// QScreen* screen = QApplication::screens().at(i); -// } + // for (int var = 0; var < QApplication::screens().count(); ++var) { + // QScreen* screen = QApplication::screens().at(i); + // } + + setOpacity(0); + this->m_hwnd = (HWND)this->winId(); QScreen* screen = QApplication::screens().at(0); - //setGeometry(screen->geometry()); + setScreen(screen); HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager"); @@ -37,13 +39,12 @@ MainWindow::MainWindow(QScreen* parent) 1000, nullptr); EnumWindows(SearchForWorkerWindow, reinterpret_cast(&m_worker_hwnd)); + ShowWindow(m_worker_hwnd, SW_HIDE); + ShowWindow(m_hwnd, SW_HIDE); + SetParent(m_hwnd, m_worker_hwnd); - //SetWindowPos(m_worker_hwnd,HWND_BOTTOM,screen->geometry().x(),screen->geometry().y(),screen->geometry().width(),screen->geometry().height(),SWP_SHOWWINDOW); - SetWindowPos(m_hwnd,HWND_BOTTOM,screen->geometry().x(),screen->geometry().y(),screen->size().width(),screen->size().height(),SWP_SHOWWINDOW); - WINDOWINFO objWinInfo; - GetWindowInfo(m_hwnd, &objWinInfo); - - qDebug() << objWinInfo.rcClient.bottom << objWinInfo.rcWindow.bottom; + SetWindowPos(m_worker_hwnd, HWND_BOTTOM, screen->geometry().x(), screen->geometry().y(), screen->geometry().width(), screen->geometry().height(), SWP_SHOWWINDOW); + SetWindowPos(m_hwnd, HWND_BOTTOM, screen->geometry().x(), screen->geometry().y(), screen->size().width(), screen->size().height(), SWP_SHOWWINDOW); SetWindowLongPtr(m_hwnd, GWL_STYLE, WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU); @@ -54,13 +55,35 @@ MainWindow::MainWindow(QScreen* parent) this->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint); m_quickRenderer = QSharedPointer(new QQuickView(this)); + //m_quickRenderer.data()->engine()->addImportPath("C:/msys64/mingw64/share/qt5/qml"); + //m_quickRenderer.data()->engine()->addImportPath("C:/msys64/mingw64/share/qt5"); + + m_quickRenderer.data()->rootContext()->setContextProperty("mainwindow", this); + m_quickRenderer.data()->setGeometry(screen->geometry()); m_quickRenderer.data()->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); m_quickRenderer.data()->setSource(QUrl("qrc:/main.qml")); + + QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); + animation->setDuration(250); + animation->setEasingCurve(QEasingCurve::OutCubic); + animation->setStartValue(0); + animation->setEndValue(1); + m_quickRenderer.data()->show(); show(); - SetParent(m_hwnd, m_worker_hwnd); + ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT); + ShowWindow(m_hwnd, SW_SHOWDEFAULT); + + animation->start(); +} + +void MainWindow::destroyThis() +{ + ShowWindow(m_worker_hwnd, SW_HIDE); + ShowWindow(m_hwnd, SW_HIDE); + QCoreApplication::quit(); } MainWindow::~MainWindow() diff --git a/ScreenPlayWindow/src/mainwindow.h b/ScreenPlayWindow/src/mainwindow.h index a0d4a377..66d66fa2 100644 --- a/ScreenPlayWindow/src/mainwindow.h +++ b/ScreenPlayWindow/src/mainwindow.h @@ -1,27 +1,30 @@ #pragma once -#include -#include #include +#include +#include +#include +#include +#include #include -#include +#include #include - +#include #include "qt_windows.h" -class MainWindow : public QWindow -{ +class MainWindow : public QWindow { Q_OBJECT public: - explicit MainWindow(QScreen *parent = 0); + explicit MainWindow(QScreen* parent = 0); + void init(); ~MainWindow(); +public slots: + void destroyThis(); private: HWND m_hwnd; HWND m_worker_hwnd; QSharedPointer m_quickRenderer = nullptr; }; - -