mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-06 19:12:30 +01:00
Add nice blurry background on windows 10
This commit is contained in:
parent
972e7bcad5
commit
92c09aa2bd
@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>assets/image/noisy-texture-3.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -1,5 +1,5 @@
|
||||
QT += quick
|
||||
CONFIG += c++11
|
||||
QT += quick qml quickcontrols2 core charts widgets gui
|
||||
CONFIG += c++17
|
||||
CONFIG += qtquickcompiler
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked deprecated (the exact warnings
|
||||
|
BIN
ScreenPlayWidget/assets/image/noisy-texture-3.png
Normal file
BIN
ScreenPlayWidget/assets/image/noisy-texture-3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
@ -1,14 +1,42 @@
|
||||
import QtQuick 2.9
|
||||
import net.aimber.screenplaysdk 1.0
|
||||
import QtQuick.Window 2.3
|
||||
import QtQuick.Controls 2.3
|
||||
|
||||
Window {
|
||||
Item {
|
||||
id: mainWindow
|
||||
visible: true
|
||||
width: 250
|
||||
height: 250
|
||||
flags: Qt.SplashScreen | Qt.ToolTip | Qt.SplashScreen
|
||||
anchors.fill: parent
|
||||
|
||||
Rectangle {
|
||||
id:bgColor
|
||||
anchors.fill: parent
|
||||
color: "white"
|
||||
//color: "#1A1F22"
|
||||
opacity: .15
|
||||
}
|
||||
|
||||
Image {
|
||||
id: bg
|
||||
source: "qrc:/assets/image/noisy-texture-3.png"
|
||||
anchors.fill: parent
|
||||
opacity: .05
|
||||
fillMode: Image.Tile
|
||||
}
|
||||
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
anchors.fill: parent
|
||||
|
||||
onPressed: {
|
||||
backend.setClickPos(Qt.point(mouse.x, mouse.y))
|
||||
}
|
||||
|
||||
onPositionChanged: {
|
||||
backend.setPos(mouse.x, mouse.y)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ScreenPlaySDK {
|
||||
id: spSDK
|
||||
@ -53,48 +81,4 @@ Window {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections{
|
||||
target: loader.item
|
||||
ignoreUnknownSignals: true
|
||||
onSizeChanged:{
|
||||
print(size)
|
||||
mainWindow.width = size.width
|
||||
mainWindow.height = size.height
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
property point clickPos: "1,1"
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
z:99
|
||||
|
||||
onPressed: {
|
||||
clickPos = Qt.point(mouse.x, mouse.y)
|
||||
}
|
||||
|
||||
onPositionChanged: {
|
||||
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
|
||||
var new_x = mainWindow.x + delta.x
|
||||
var new_y = mainWindow.y + delta.y
|
||||
mainWindow.x = new_x
|
||||
mainWindow.y = new_y
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
if (mouse.button === Qt.RightButton) {
|
||||
contextMenu.popup()
|
||||
}
|
||||
}
|
||||
}
|
||||
Menu {
|
||||
id: contextMenu
|
||||
MenuItem {
|
||||
text: qsTr("Close")
|
||||
onClicked: {
|
||||
Qt.quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,15 @@
|
||||
SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QScreen* parent)
|
||||
: QWindow(parent)
|
||||
{
|
||||
|
||||
m_appID = appid;
|
||||
|
||||
m_hwnd = (HWND)this->winId();
|
||||
Qt::WindowFlags flags = this->flags();
|
||||
this->setWidth(500);
|
||||
this->setHeight(300);
|
||||
this->setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen);
|
||||
|
||||
QFile configTmp;
|
||||
QJsonDocument configJsonDocument;
|
||||
QJsonParseError parseError;
|
||||
@ -20,11 +27,80 @@ SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QScre
|
||||
m_project = configJsonDocument.object();
|
||||
QString fullPath = projectPath + "/" + m_project.value("file").toString();
|
||||
|
||||
m_quickRenderer = QSharedPointer<QQmlApplicationEngine>(new QQmlApplicationEngine());
|
||||
m_quickRenderer = QSharedPointer<QQuickView>(new QQuickView(this));
|
||||
m_quickRenderer.data()->rootContext()->setContextProperty("backend", this);
|
||||
m_quickRenderer.data()->load(QUrl("qrc:/main.qml"));
|
||||
m_quickRenderer.data()->setColor(Qt::transparent);
|
||||
m_quickRenderer.data()->setWidth(this->width());
|
||||
m_quickRenderer.data()->setHeight(this->height());
|
||||
m_quickRenderer.data()->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
|
||||
|
||||
m_quickRenderer.data()->setSource(QUrl("qrc:/main.qml"));
|
||||
#ifdef Q_OS_WIN
|
||||
SetWindowBlur(m_hwnd);
|
||||
#endif
|
||||
show();
|
||||
m_quickRenderer.data()->show();
|
||||
|
||||
emit setWidgetSource(fullPath);
|
||||
|
||||
}
|
||||
|
||||
void SPWidgetmainwindow::setSize(QSize size)
|
||||
{
|
||||
this->setWidth(size.width());
|
||||
this->setHeight(size.height());
|
||||
m_quickRenderer.data()->setWidth(size.width());
|
||||
m_quickRenderer.data()->setHeight(size.height());
|
||||
}
|
||||
|
||||
void SPWidgetmainwindow::setPos(int xPos, int yPos)
|
||||
{
|
||||
|
||||
QPoint delta((xPos - m_clickPos.x()), (yPos - m_clickPos.y()));
|
||||
int new_x = x() + delta.x();
|
||||
int new_y = y() + delta.y();
|
||||
|
||||
setPosition(QPoint(new_x, new_y));
|
||||
}
|
||||
|
||||
void SPWidgetmainwindow::setClickPos(const QPoint &clickPos)
|
||||
{
|
||||
m_clickPos = clickPos;
|
||||
}
|
||||
|
||||
void SPWidgetmainwindow::SetWindowBlur(HWND hWnd)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
|
||||
if (hModule) {
|
||||
struct ACCENTPOLICY {
|
||||
int nAccentState;
|
||||
int nFlags;
|
||||
int nColor;
|
||||
int nAnimationId;
|
||||
};
|
||||
struct WINCOMPATTRDATA {
|
||||
int nAttribute;
|
||||
PVOID pData;
|
||||
ULONG ulDataSize;
|
||||
};
|
||||
enum class Accent {
|
||||
DISABLED = 0,
|
||||
GRADIENT = 1,
|
||||
TRANSPARENTGRADIENT = 2,
|
||||
BLURBEHIND = 3,
|
||||
ACRYLIC = 4,
|
||||
INVALID = 5
|
||||
};
|
||||
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...
|
||||
WINCOMPATTRDATA data = { 19, &policy, sizeof(ACCENTPOLICY) }; // WCA_ACCENT_POLICY=19
|
||||
SetWindowCompositionAttribute(hWnd, &data);
|
||||
}
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -6,12 +6,15 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QPoint>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickView>
|
||||
#include <QtQuick/QQuickView>
|
||||
#include <QtQuick/QQuickWindow>
|
||||
#include <QQuickWindow>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QWindow>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <qt_windows.h>
|
||||
|
||||
class SPWidgetmainwindow : public QWindow {
|
||||
Q_OBJECT
|
||||
@ -45,6 +48,7 @@ signals:
|
||||
void setWidgetSource(QString source);
|
||||
|
||||
public slots:
|
||||
void setSize(QSize size);
|
||||
void setAppID(QString appID)
|
||||
{
|
||||
if (m_appID == appID)
|
||||
@ -70,11 +74,17 @@ public slots:
|
||||
emit projectConfigChanged(m_projectConfig);
|
||||
}
|
||||
|
||||
void setPos(int xPos, int yPos);
|
||||
void setClickPos(const QPoint& clickPos);
|
||||
void SetWindowBlur(HWND hWnd);
|
||||
|
||||
private:
|
||||
QString m_appID;
|
||||
QString m_type = "qmlWidget";
|
||||
QString m_projectConfig;
|
||||
QJsonObject m_project;
|
||||
HWND m_hwnd;
|
||||
QPoint m_clickPos = { 0, 0 };
|
||||
|
||||
QSharedPointer<QQmlApplicationEngine> m_quickRenderer = nullptr;
|
||||
QSharedPointer<QQuickView> m_quickRenderer;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user