1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-15 06:52:34 +02:00

Add widget fadeout

This commit is contained in:
Elias 2019-06-13 18:06:24 +02:00
parent 17fa34e288
commit 8c1b535fad
3 changed files with 81 additions and 46 deletions

View File

@ -1,18 +1,24 @@
import QtQuick 2.12
import QtQuick.Controls 2.3
import ScreenPlay.screenplaysdk 1.0
Item {
id: mainWindow
visible: true
anchors.fill: parent
OpacityAnimator {
id: animFadeOut
from: 1
to: 0
target: parent
duration: 800
easing.type: Easing.InOutQuad
onFinished: window.destroyThis()
}
Rectangle {
id: bgColor
anchors.fill: parent
color: "white"
//color: "#1A1F22"
opacity: .15
}
@ -28,12 +34,14 @@ Item {
anchors.fill: parent
asynchronous: true
source: {
Qt.resolvedUrl(window.sourcePath)
Qt.resolvedUrl(window.sourcePath)
}
onStatusChanged: {
if (loader.status === Loader.Ready) {
Connections {
target: loader.item
onSizeChanged: {
mainWindow.width = size.width
mainWindow.height = size.height
}
}
}
@ -41,37 +49,20 @@ Item {
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onPressed: {
window.setClickPos(Qt.point(mouse.x, mouse.y))
}
onPositionChanged: {
window.setPos(mouse.x, mouse.y)
if (mouseArea.pressed)
window.setPos(mouse.x, mouse.y)
}
onClicked: {
if (mouse.button === Qt.RightButton) {
contextMenu.popup()
}
}
}
Menu {
id: contextMenu
MenuItem {
text: qsTr("Close Widget")
onClicked: {
Qt.quit()
}
}
}
Connections {
target: window
onQmlSceneValueReceived: {
var obj2 = 'import QtQuick 2.12; Item {Component.onCompleted: loader.item.'
+ key + ' = ' + value + '; }'
@ -80,5 +71,45 @@ Item {
}
}
MouseArea {
id: mouseAreaClose
width: 20
height: width
anchors {
top: parent.top
right: parent.right
}
cursorShape: Qt.PointingHandCursor
onClicked: {
window.setWindowBlur(0)
animFadeOut.start()
}
Image {
source: "qrc:/assets/icons/baseline-close-24px.svg"
anchors.centerIn: parent
}
}
MouseArea {
id: mouseAreaResize
width: 20
height: width
anchors {
bottom: parent.bottom
right: parent.right
}
cursorShape: Qt.SizeFDiagCursor
property point clickPosition
onPressed: {
clickPosition = Qt.point(mouseX, mouseY)
}
onPositionChanged: {
if (mouseAreaResize.pressed) {
window.setWidgetSize(clickPosition.x + mouseX,
clickPosition.y + mouseY)
}
}
}
}

View File

@ -4,11 +4,9 @@
WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
: QObject(parent)
, m_appID { appid }
{
m_appID = appid;
Qt::WindowFlags flags = m_window.flags();
m_window.setWidth(300);
m_window.setHeight(300);
@ -18,7 +16,7 @@ WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
#ifdef Q_OS_WIN
m_hwnd = reinterpret_cast<HWND>(m_window.winId());
SetWindowBlur(m_hwnd);
setWindowBlur();
#endif
if (projectPath != "test") {
@ -44,9 +42,9 @@ WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
// Instead of setting "renderType: Text.NativeRendering" every time
// we can set it here once :)
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
// m_window.setResizeMode(QQuickView::ResizeMode::SizeViewToRootObject);
m_window.setSource(QUrl("qrc:/mainWidget.qml"));
m_window.show();
}
void WidgetWindow::setSize(QSize size)
@ -80,8 +78,14 @@ void WidgetWindow::setClickPos(const QPoint& clickPos)
m_clickPos = clickPos;
}
void WidgetWindow::setWidgetSize(const int with, const int height)
{
m_window.setWidth(with);
m_window.setHeight(height);
}
#ifdef Q_OS_WIN
void WidgetWindow::SetWindowBlur(HWND hWnd)
void WidgetWindow::setWindowBlur(unsigned int style)
{
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
@ -108,9 +112,9 @@ void WidgetWindow::SetWindowBlur(HWND hWnd)
typedef BOOL(WINAPI * pSetWindowCompositionAttribute)(HWND, WINCOMPATTRDATA*);
const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute)GetProcAddress(hModule, "SetWindowCompositionAttribute");
if (SetWindowCompositionAttribute) {
ACCENTPOLICY policy = { static_cast<int>(Accent::BLURBEHIND), 0, 0, 0 }; // ACCENT_ENABLE_BLURBEHIND=3...
ACCENTPOLICY policy = { static_cast<int>(style), 0, 0, 0 }; // ACCENT_ENABLE_BLURBEHIND=3...
WINCOMPATTRDATA data = { 19, &policy, sizeof(ACCENTPOLICY) }; // WCA_ACCENT_POLICY=19
SetWindowCompositionAttribute(hWnd, &data);
SetWindowCompositionAttribute(m_hwnd, &data);
}
FreeLibrary(hModule);
}

View File

@ -56,13 +56,18 @@ signals:
void typeChanged(QString type);
void projectConfigChanged(QString projectConfig);
void sourcePathChanged(QString sourcePath);
void qmlSceneValueReceived(QString key, QString value);
public slots:
void setSize(QSize size);
void destroyThis();
void messageReceived(QString key, QString value);
void setPos(int xPos, int yPos);
void setClickPos(const QPoint& clickPos);
void setWidgetSize(const int with, const int height);
#ifdef Q_OS_WIN
void setWindowBlur(unsigned int style = 3);
#endif
void setAppID(QString appID)
{
@ -89,11 +94,6 @@ public slots:
emit projectConfigChanged(m_projectConfig);
}
void setPos(int xPos, int yPos);
void setClickPos(const QPoint& clickPos);
#ifdef Q_OS_WIN
void SetWindowBlur(HWND hWnd);
#endif
void setSourcePath(QString sourcePath)
{
if (m_sourcePath == sourcePath)
@ -104,9 +104,9 @@ public slots:
}
private:
QString m_appID;
QString m_type = "qmlWidget";
QString m_projectConfig;
QString m_appID { "" };
QString m_type { "qmlWidget" };
QString m_projectConfig { "" };
QJsonObject m_project;
#ifdef Q_OS_WIN
HWND m_hwnd;
@ -114,5 +114,5 @@ private:
QPoint m_clickPos = { 0, 0 };
QQuickView m_window;
QString m_sourcePath;
QString m_sourcePath { "" };
};