1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 10:42:29 +01:00

Fix scene value set from screenplay to screenplaywindow

Add mouse hook for input
This commit is contained in:
Elias 2019-06-09 12:21:03 +02:00
parent aed40a3633
commit 55b3d0f3f3
9 changed files with 170 additions and 6 deletions

View File

@ -14,11 +14,11 @@ void redirectMessageOutputToMainWindow(QtMsgType type, const QMessageLogContext&
//QByteArray function = "function " + QByteArray(context.function) + ", Message: ";
//localMsg = file + line + localMsg;
global_sdkPtr->redirectMessage(localMsg);
switch (type) {
case QtDebugMsg:
//localMsg = " SDK START: " /*+ QByteArray::fromStdString(global_sdkPtr->contentType().toStdString()) + " "*/ + localMsg;
global_sdkPtr->redirectMessage(localMsg);
break;
case QtInfoMsg:
//fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);

View File

@ -2,5 +2,6 @@
<qresource prefix="/">
<file>mainWindow.qml</file>
<file>test.qml</file>
<file>dot.png</file>
</qresource>
</RCC>

BIN
ScreenPlayWindow/dot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -3,6 +3,7 @@ import QtWebEngine 1.8
import net.aimber.wallpaper 1.0
Rectangle {
id: root
anchors.fill: parent
color: {
if (desktopProperties.color === null) {
@ -12,6 +13,7 @@ Rectangle {
}
}
property bool canFadeIn: true
Component.onCompleted: {
@ -56,6 +58,7 @@ Rectangle {
Loader {
id: loader
anchors.fill: parent
onLoaded: loader.z = 999
}
WebEngineView {
@ -135,8 +138,9 @@ Rectangle {
}
onQmlSceneValueReceived: {
var obj2 = 'import QtQuick 2.12; Item {Component.onCompleted: loader.item.'
var obj2 = 'import QtQuick 2.0; Item {Component.onCompleted: loader.item.'
+ key + ' = ' + value + '; }'
print(key, value)
var newObject = Qt.createQmlObject(obj2.toString(), root, "err")
newObject.destroy(10000)
}
@ -174,4 +178,5 @@ Rectangle {
}
}
}
}

View File

@ -3,11 +3,13 @@
BaseWindow::BaseWindow(QObject* parent)
: QObject(parent)
{
}
BaseWindow::BaseWindow(QString projectFilePath, QObject* parent)
: QObject(parent)
{
QApplication::instance()->installEventFilter(this);
qRegisterMetaType<BaseWindow::WallpaperType>();
qmlRegisterType<BaseWindow>("net.aimber.wallpaper", 1, 0, "Wallpaper");
@ -76,3 +78,4 @@ BaseWindow::BaseWindow(QString projectFilePath, QObject* parent)
return;
}
}

View File

@ -8,7 +8,7 @@
#include <QJsonParseError>
#include <QObject>
#include <QString>
#include <qqml.h>
#include <QtQml>
class BaseWindow : public QObject {
Q_OBJECT

View File

@ -13,6 +13,53 @@ BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam)
return TRUE;
}
HHOOK mouseHook;
QQuickView* winGlobalHook = nullptr;
LRESULT __stdcall MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
Qt::MouseButton mouseButton {};
Qt::MouseButtons mouseButtons {};
Qt::KeyboardModifier keyboardModifier {};
QMouseEvent::Type type { QMouseEvent::Type::MouseMove };
if (nCode >= 0) {
switch (wParam) {
case WM_LBUTTONDOWN:
mouseButton = Qt::MouseButton::LeftButton;
mouseButtons.setFlag(Qt::LeftButton);
type = QMouseEvent::Type::MouseButtonPress;
break;
case WM_LBUTTONUP:
mouseButton = Qt::MouseButton::LeftButton;
mouseButtons.setFlag(Qt::LeftButton);
type = QMouseEvent::Type::MouseButtonRelease;
break;
case WM_RBUTTONDOWN:
mouseButton = Qt::MouseButton::RightButton;
mouseButtons.setFlag(Qt::RightButton);
type = QMouseEvent::Type::MouseButtonPress;
break;
}
}
POINT p {};
QPoint point { 0, 0 };
if (GetCursorPos(&p)) {
point.setX(p.x);
point.setY(p.y);
}
auto event = QMouseEvent(type, point, mouseButton, mouseButtons, keyboardModifier);
auto* app = QApplication::instance();
app->sendEvent(winGlobalHook, &event);
return CallNextHookEx(mouseHook, nCode, wParam, lParam);
}
WinWindow::WinWindow(QVector<int>& activeScreensList, QString projectPath, QString id, QString volume)
: BaseWindow(projectPath)
{
@ -59,11 +106,17 @@ WinWindow::WinWindow(QVector<int>& activeScreensList, QString projectPath, QStri
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setSource(QUrl("qrc:/mainWindow.qml"));
// MUST be called before setting hook for events!
winGlobalHook = &m_window;
if (!(mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, nullptr, 0))) {
qDebug() << "Faild to install mouse hook!";
}
// FIXME WORKAROUND:
// There is a strange bug when we open the ScreenPlayWindow project on its one
// that if we set ShowWindow(m_windowHandle, SW_HIDE); we can no longer set
// the window visible via set Visible.
if(projectPath != "test"){
if (projectPath != "test") {
// Let QML decide when were are read to show the window
ShowWindow(m_windowHandle, SW_HIDE);
}
@ -72,10 +125,14 @@ WinWindow::WinWindow(QVector<int>& activeScreensList, QString projectPath, QStri
void WinWindow::setVisible(bool show)
{
if (show) {
ShowWindow(m_windowHandle, SW_SHOW);
if (!ShowWindow(m_windowHandle, SW_SHOW)) {
qDebug() << "Cannot set window handle visible";
}
m_window.show();
} else {
ShowWindow(m_windowHandle, SW_HIDE);
if (!ShowWindow(m_windowHandle, SW_HIDE)) {
qDebug() << "Cannot set window handle hidden";
}
}
}
@ -93,6 +150,7 @@ void WinWindow::destroyThis()
void WinWindow::messageReceived(QString key, QString value)
{
emit qmlSceneValueReceived(key, value);
}
void WinWindow::calcOffsets()

View File

@ -34,6 +34,10 @@ private:
void setupWallpaperForAllScreens();
bool searchWorkerWindowToParentTo();
signals:
void qmlSceneValueReceived(const QString key, const QString value);
private:
int m_windowOffsetX = 0;
int m_windowOffsetY = 0;

View File

@ -1,10 +1,103 @@
import QtQuick 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Particles 2.12
import QtQuick.Shapes 1.12
Rectangle {
id: root
anchors.fill: parent
color: Material.color(Material.Grey, Material.Shade800)
property int attStrength: 8000000
//Emitter
property bool isEnabled: true
property int emitRate: 25
property int lifeSpan: 5000
property int size: 4
property int endSize: 8
property int sizeVariation: 4
//Image
property real imgOpacity: .75
MouseArea {
id: ma
anchors.fill: parent
hoverEnabled: true
Component.onCompleted: {
attractor.pointX = parent.width * .5
attractor.pointY = 0
}
onPositionChanged: {
if (ma.pressed) {
setPosition()
}
}
onClicked: {
setPosition()
}
function setPosition() {
attractor.pointX = mouseX - 25
attractor.pointY = mouseY - 25
mouseDot.x = mouseX - mouseDot.center
mouseDot.y = mouseY - mouseDot.center
}
}
Rectangle {
id: mouseDot
property int center: mouseDot.width * .5
width: 10
height: width
radius: width
color: "orange"
}
Attractor {
id: attractor
system: particleSystem
affectedParameter: Attractor.Acceleration
strength: root.attStrength
proportionalToDistance: Attractor.InverseQuadratic
}
ParticleSystem {
id: particleSystem
}
Emitter {
id: emitter
enabled: root.isEnabled
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
}
width: parent.width
height: parent.height * .5
system: particleSystem
emitRate: root.emitRate
lifeSpan: root.lifeSpan
lifeSpanVariation: 1000
size: root.size
endSize: root.endSize
sizeVariation: root.sizeVariation
velocity: AngleDirection {
angle: -90
magnitude: 50
magnitudeVariation: 25
angleVariation: 10
}
}
ImageParticle {
height: 16
width: 16
source: "dot.png"
system: particleSystem
opacity: root.imgOpacity
}
Text {
id: name
text: qsTr("This is a empty test window. You can change the source in test.qml")