From b2bcf713a60781cdce8a9db19a054d6abd5e0a19 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 16 Dec 2014 13:17:30 +0100 Subject: [PATCH] - Replace Qt5.3 ModalDialog by custom modal dialog. --- mix/AppContext.cpp | 9 ++++----- mix/Extension.cpp | 5 ++--- mix/qml.qrc | 2 ++ mix/qml/AlertMessageDialog.qml | 27 +++++++++++++++++++++++++++ mix/qml/BasicMessage.qml | 1 + mix/qml/Debugger.qml | 8 -------- mix/qml/ModalDialog.qml | 27 +++++++++++++++++++++++++++ mix/qml/main.qml | 22 +++------------------- 8 files changed, 66 insertions(+), 35 deletions(-) create mode 100644 mix/qml/AlertMessageDialog.qml create mode 100644 mix/qml/ModalDialog.qml diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index 92b3f4c0a..89f2849cd 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -74,14 +74,13 @@ void AppContext::setApplicationContext(QQmlApplicationEngine* _engine) void AppContext::displayMessageDialog(QString _title, QString _message) { - QQmlComponent component(m_applicationEngine.get(), QUrl("qrc:/qml/BasicMessage.qml")); - QObject* dialog = component.create(); - dialog->findChild("messageContent", Qt::FindChildrenRecursively)->setProperty("text", _message); - QObject* dialogWin = AppContext::getInstance()->appEngine()->rootObjects().at(0)->findChild("messageDialog", Qt::FindChildrenRecursively); + QObject* dialogWin = m_applicationEngine.get()->rootObjects().at(0)->findChild("alertMessageDialog", Qt::FindChildrenRecursively); + QObject* dialogWinComponent = m_applicationEngine.get()->rootObjects().at(0)->findChild("alertMessageDialogContent", Qt::FindChildrenRecursively); QMetaObject::invokeMethod(dialogWin, "close"); - dialogWin->setProperty("contentItem", QVariant::fromValue(dialog)); + dialogWinComponent->setProperty("source", QString("qrc:/qml/BasicMessage.qml")); dialogWin->setProperty("title", _title); dialogWin->setProperty("width", "250"); dialogWin->setProperty("height", "100"); + dialogWin->findChild("messageContent", Qt::FindChildrenRecursively)->setProperty("text", _message); QMetaObject::invokeMethod(dialogWin, "open"); } diff --git a/mix/Extension.cpp b/mix/Extension.cpp index f9a8ad94d..e46fc4145 100644 --- a/mix/Extension.cpp +++ b/mix/Extension.cpp @@ -65,11 +65,10 @@ void Extension::addContentOn(QObject* _view) Q_UNUSED(_view); if (m_displayBehavior == ExtensionDisplayBehavior::ModalDialog) { - QQmlComponent component(AppContext::getInstance()->appEngine(), QUrl(contentUrl())); - QObject* dialog = component.create(); QObject* dialogWin = AppContext::getInstance()->appEngine()->rootObjects().at(0)->findChild("dialog", Qt::FindChildrenRecursively); + QObject* dialogWinComponent = AppContext::getInstance()->appEngine()->rootObjects().at(0)->findChild("modalDialogContent", Qt::FindChildrenRecursively); QMetaObject::invokeMethod(dialogWin, "close"); - dialogWin->setProperty("contentItem", QVariant::fromValue(dialog)); + dialogWinComponent->setProperty("source", contentUrl()); dialogWin->setProperty("title", title()); QMetaObject::invokeMethod(dialogWin, "open"); } diff --git a/mix/qml.qrc b/mix/qml.qrc index 2fa92d661..d14aa9974 100644 --- a/mix/qml.qrc +++ b/mix/qml.qrc @@ -7,5 +7,7 @@ qml/Debugger.qml qml/js/Debugger.js qml/BasicMessage.qml + qml/ModalDialog.qml + qml/AlertMessageDialog.qml diff --git a/mix/qml/AlertMessageDialog.qml b/mix/qml/AlertMessageDialog.qml new file mode 100644 index 000000000..f89ade45f --- /dev/null +++ b/mix/qml/AlertMessageDialog.qml @@ -0,0 +1,27 @@ +import QtQuick 2.2 +import QtQuick.Window 2.0 + +Window +{ + id: alertMessageDialog + title: "" + modality: Qt.WindowModal + height: 150 + width: 200 + visible: false + Loader + { + focus: true + id: alertMessageDialogContent + objectName: "alertMessageDialogContent" + anchors.fill: parent + } + function open() + { + visible = true + } + function close() + { + visible = false + } +} diff --git a/mix/qml/BasicMessage.qml b/mix/qml/BasicMessage.qml index 0678c9b54..233717009 100644 --- a/mix/qml/BasicMessage.qml +++ b/mix/qml/BasicMessage.qml @@ -18,3 +18,4 @@ Rectangle { text: "" } } + diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index e895d1ada..fa3e8aba4 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -21,7 +21,6 @@ Rectangle { font.italic: true id: headerInfoLabel } - } Keys.onPressed: { @@ -138,7 +137,6 @@ Rectangle { horizontalAlignment: "AlignHCenter" font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 width: parent.width height: 15 anchors.top : parent.top @@ -149,7 +147,6 @@ Rectangle { width: parent.width font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 height: parent.height - 15 id:debugStackTxt readOnly: true; @@ -166,7 +163,6 @@ Rectangle { horizontalAlignment: "AlignHCenter" font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 width: parent.width height: 15 anchors.top : parent.top @@ -177,7 +173,6 @@ Rectangle { width: parent.width font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 height: parent.height - 15 id: debugMemoryTxt readOnly: true; @@ -194,7 +189,6 @@ Rectangle { horizontalAlignment: "AlignHCenter" font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 width: parent.width height: 15 anchors.top : parent.top @@ -205,7 +199,6 @@ Rectangle { width: parent.width font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 height: parent.height - 15 id:debugStorageTxt readOnly: true; @@ -222,7 +215,6 @@ Rectangle { horizontalAlignment: "AlignHCenter" font.family: "Verdana" font.pointSize: 8 - font.letterSpacing: 2 width: parent.width height: 15 anchors.top : parent.top diff --git a/mix/qml/ModalDialog.qml b/mix/qml/ModalDialog.qml new file mode 100644 index 000000000..983420926 --- /dev/null +++ b/mix/qml/ModalDialog.qml @@ -0,0 +1,27 @@ +import QtQuick 2.2 +import QtQuick.Window 2.0 + +Window +{ + id: modalDialog + title: "" + modality: Qt.WindowModal + height: 400 + width: 700 + visible: false + Loader + { + focus: true + id: modalDialogContent + objectName: "modalDialogContent" + anchors.fill: parent + } + function open() + { + visible = true + } + function close() + { + visible = false + } +} diff --git a/mix/qml/main.qml b/mix/qml/main.qml index 05b29eb62..52c47e063 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -30,29 +30,13 @@ ApplicationWindow { MainContent { } - Dialog { - x: mainApplication.x + (mainApplication.width - width) / 2 - y: mainApplication.y + (mainApplication.height - height) / 2 + ModalDialog { objectName: "dialog" id: dialog - height: 400 - width: 700 - modality: Qt.WindowModal - contentItem: Rectangle { - objectName: "dialogContent" - } } - Dialog { - x: mainApplication.x + (mainApplication.width - width) / 2 - y: mainApplication.y + (mainApplication.height - height) / 2 - objectName: "messageDialog" + AlertMessageDialog { + objectName: "alertMessageDialog" id: messageDialog - height: 150 - width: 200 - modality: Qt.WindowModal - contentItem: Rectangle { - objectName: "messageContent" - } } }