Browse Source

- Replace Qt5.3 ModalDialog by custom modal dialog.

cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
b2bcf713a6
  1. 9
      mix/AppContext.cpp
  2. 5
      mix/Extension.cpp
  3. 2
      mix/qml.qrc
  4. 27
      mix/qml/AlertMessageDialog.qml
  5. 1
      mix/qml/BasicMessage.qml
  6. 8
      mix/qml/Debugger.qml
  7. 27
      mix/qml/ModalDialog.qml
  8. 22
      mix/qml/main.qml

9
mix/AppContext.cpp

@ -74,14 +74,13 @@ void AppContext::setApplicationContext(QQmlApplicationEngine* _engine)
void AppContext::displayMessageDialog(QString _title, QString _message) void AppContext::displayMessageDialog(QString _title, QString _message)
{ {
QQmlComponent component(m_applicationEngine.get(), QUrl("qrc:/qml/BasicMessage.qml")); QObject* dialogWin = m_applicationEngine.get()->rootObjects().at(0)->findChild<QObject*>("alertMessageDialog", Qt::FindChildrenRecursively);
QObject* dialog = component.create(); QObject* dialogWinComponent = m_applicationEngine.get()->rootObjects().at(0)->findChild<QObject*>("alertMessageDialogContent", Qt::FindChildrenRecursively);
dialog->findChild<QObject*>("messageContent", Qt::FindChildrenRecursively)->setProperty("text", _message);
QObject* dialogWin = AppContext::getInstance()->appEngine()->rootObjects().at(0)->findChild<QObject*>("messageDialog", Qt::FindChildrenRecursively);
QMetaObject::invokeMethod(dialogWin, "close"); QMetaObject::invokeMethod(dialogWin, "close");
dialogWin->setProperty("contentItem", QVariant::fromValue(dialog)); dialogWinComponent->setProperty("source", QString("qrc:/qml/BasicMessage.qml"));
dialogWin->setProperty("title", _title); dialogWin->setProperty("title", _title);
dialogWin->setProperty("width", "250"); dialogWin->setProperty("width", "250");
dialogWin->setProperty("height", "100"); dialogWin->setProperty("height", "100");
dialogWin->findChild<QObject*>("messageContent", Qt::FindChildrenRecursively)->setProperty("text", _message);
QMetaObject::invokeMethod(dialogWin, "open"); QMetaObject::invokeMethod(dialogWin, "open");
} }

5
mix/Extension.cpp

@ -65,11 +65,10 @@ void Extension::addContentOn(QObject* _view)
Q_UNUSED(_view); Q_UNUSED(_view);
if (m_displayBehavior == ExtensionDisplayBehavior::ModalDialog) 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<QObject*>("dialog", Qt::FindChildrenRecursively); QObject* dialogWin = AppContext::getInstance()->appEngine()->rootObjects().at(0)->findChild<QObject*>("dialog", Qt::FindChildrenRecursively);
QObject* dialogWinComponent = AppContext::getInstance()->appEngine()->rootObjects().at(0)->findChild<QObject*>("modalDialogContent", Qt::FindChildrenRecursively);
QMetaObject::invokeMethod(dialogWin, "close"); QMetaObject::invokeMethod(dialogWin, "close");
dialogWin->setProperty("contentItem", QVariant::fromValue(dialog)); dialogWinComponent->setProperty("source", contentUrl());
dialogWin->setProperty("title", title()); dialogWin->setProperty("title", title());
QMetaObject::invokeMethod(dialogWin, "open"); QMetaObject::invokeMethod(dialogWin, "open");
} }

2
mix/qml.qrc

@ -7,5 +7,7 @@
<file>qml/Debugger.qml</file> <file>qml/Debugger.qml</file>
<file>qml/js/Debugger.js</file> <file>qml/js/Debugger.js</file>
<file>qml/BasicMessage.qml</file> <file>qml/BasicMessage.qml</file>
<file>qml/ModalDialog.qml</file>
<file>qml/AlertMessageDialog.qml</file>
</qresource> </qresource>
</RCC> </RCC>

27
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
}
}

1
mix/qml/BasicMessage.qml

@ -18,3 +18,4 @@ Rectangle {
text: "" text: ""
} }
} }

8
mix/qml/Debugger.qml

@ -21,7 +21,6 @@ Rectangle {
font.italic: true font.italic: true
id: headerInfoLabel id: headerInfoLabel
} }
} }
Keys.onPressed: { Keys.onPressed: {
@ -138,7 +137,6 @@ Rectangle {
horizontalAlignment: "AlignHCenter" horizontalAlignment: "AlignHCenter"
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
width: parent.width width: parent.width
height: 15 height: 15
anchors.top : parent.top anchors.top : parent.top
@ -149,7 +147,6 @@ Rectangle {
width: parent.width width: parent.width
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
height: parent.height - 15 height: parent.height - 15
id:debugStackTxt id:debugStackTxt
readOnly: true; readOnly: true;
@ -166,7 +163,6 @@ Rectangle {
horizontalAlignment: "AlignHCenter" horizontalAlignment: "AlignHCenter"
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
width: parent.width width: parent.width
height: 15 height: 15
anchors.top : parent.top anchors.top : parent.top
@ -177,7 +173,6 @@ Rectangle {
width: parent.width width: parent.width
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
height: parent.height - 15 height: parent.height - 15
id: debugMemoryTxt id: debugMemoryTxt
readOnly: true; readOnly: true;
@ -194,7 +189,6 @@ Rectangle {
horizontalAlignment: "AlignHCenter" horizontalAlignment: "AlignHCenter"
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
width: parent.width width: parent.width
height: 15 height: 15
anchors.top : parent.top anchors.top : parent.top
@ -205,7 +199,6 @@ Rectangle {
width: parent.width width: parent.width
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
height: parent.height - 15 height: parent.height - 15
id:debugStorageTxt id:debugStorageTxt
readOnly: true; readOnly: true;
@ -222,7 +215,6 @@ Rectangle {
horizontalAlignment: "AlignHCenter" horizontalAlignment: "AlignHCenter"
font.family: "Verdana" font.family: "Verdana"
font.pointSize: 8 font.pointSize: 8
font.letterSpacing: 2
width: parent.width width: parent.width
height: 15 height: 15
anchors.top : parent.top anchors.top : parent.top

27
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
}
}

22
mix/qml/main.qml

@ -30,29 +30,13 @@ ApplicationWindow {
MainContent { MainContent {
} }
Dialog { ModalDialog {
x: mainApplication.x + (mainApplication.width - width) / 2
y: mainApplication.y + (mainApplication.height - height) / 2
objectName: "dialog" objectName: "dialog"
id: dialog id: dialog
height: 400
width: 700
modality: Qt.WindowModal
contentItem: Rectangle {
objectName: "dialogContent"
}
} }
Dialog { AlertMessageDialog {
x: mainApplication.x + (mainApplication.width - width) / 2 objectName: "alertMessageDialog"
y: mainApplication.y + (mainApplication.height - height) / 2
objectName: "messageDialog"
id: messageDialog id: messageDialog
height: 150
width: 200
modality: Qt.WindowModal
contentItem: Rectangle {
objectName: "messageContent"
}
} }
} }

Loading…
Cancel
Save