diff --git a/src/imports/mvvmquick/MsgBoxBase.qml b/src/imports/mvvmquick/MsgBoxBase.qml index 0c62fd2..ae62d18 100644 --- a/src/imports/mvvmquick/MsgBoxBase.qml +++ b/src/imports/mvvmquick/MsgBoxBase.qml @@ -46,49 +46,56 @@ AlertDialog { } } - footer: DialogButtonBox { - id: _btnBox + footer: Item { visible: msgConfig.buttons !== MessageConfig.NoButton + implicitWidth: _btnBox.implicitWidth + implicitHeight: _btnBox.implicitHeight - readonly property var _allBtns: [ - DialogButtonBox.NoButton, - DialogButtonBox.Ok, - DialogButtonBox.Save, - DialogButtonBox.SaveAll, - DialogButtonBox.Open, - DialogButtonBox.Yes, - DialogButtonBox.YesToAll, - DialogButtonBox.No, - DialogButtonBox.NoToAll, - DialogButtonBox.Abort, - DialogButtonBox.Retry, - DialogButtonBox.Ignore, - DialogButtonBox.Close, - DialogButtonBox.Cancel, - DialogButtonBox.Discard, - DialogButtonBox.Help, - DialogButtonBox.Apply, - DialogButtonBox.Reset, - DialogButtonBox.RestoreDefaults, - ] - - standardButtons: msgConfig.buttons - onStandardButtonsChanged: { - Object.keys(msgConfig.buttonTexts).forEach(function(key) { - standardButton(key).text = msgConfig.buttonTexts[key] - }); - } + DialogButtonBox { + id: _btnBox + anchors.fill: parent + + readonly property var _allBtns: [ + DialogButtonBox.NoButton, + DialogButtonBox.Ok, + DialogButtonBox.Save, + DialogButtonBox.SaveAll, + DialogButtonBox.Open, + DialogButtonBox.Yes, + DialogButtonBox.YesToAll, + DialogButtonBox.No, + DialogButtonBox.NoToAll, + DialogButtonBox.Abort, + DialogButtonBox.Retry, + DialogButtonBox.Ignore, + DialogButtonBox.Close, + DialogButtonBox.Cancel, + DialogButtonBox.Discard, + DialogButtonBox.Help, + DialogButtonBox.Apply, + DialogButtonBox.Reset, + DialogButtonBox.RestoreDefaults, + ] - onClicked: { - _msgBoxBase.buttonClicked(button); - if(msgResult && autoHandleBtns) { - _allBtns.forEach(function(sBtn) { - if(button === standardButton(sBtn)) { - msgResult.complete(sBtn); - msgResult = null; - } + standardButtons: msgConfig.buttons + onStandardButtonsChanged: { + Object.keys(msgConfig.buttonTexts).forEach(function(key) { + standardButton(key).text = msgConfig.buttonTexts[key] }); } + + onClicked: { + _msgBoxBase.buttonClicked(button); + if(msgResult && autoHandleBtns) { + _allBtns.forEach(function(sBtn) { + if(button === standardButton(sBtn)) { + msgResult.complete(sBtn); + msgResult = null; + _msgBoxBase.done(sBtn); + } + }); + } + } } } diff --git a/src/imports/mvvmquick/ProgressDialog.qml b/src/imports/mvvmquick/ProgressDialog.qml index dd0aa64..4d651d1 100644 --- a/src/imports/mvvmquick/ProgressDialog.qml +++ b/src/imports/mvvmquick/ProgressDialog.qml @@ -17,16 +17,6 @@ MsgBoxBase { readonly property bool _allowClose: !progressControl || !msgResult onButtonClicked: tryCancel(button) - onAboutToHide: { //TODO find a way to NOT auto react on button presses... better that this solution - var closeFn = function(){ - if(!_allowClose) - _progressDialog.visible = true; - }; - if(QuickPresenter.currentStyle == "Material") - Qt.callLater(closeFn); - else - closeFn(); - } Component.onCompleted: { if(msgResult) diff --git a/src/mvvmwidgets/widgetspresenter.cpp b/src/mvvmwidgets/widgetspresenter.cpp index 1c09655..bf1ca68 100644 --- a/src/mvvmwidgets/widgetspresenter.cpp +++ b/src/mvvmwidgets/widgetspresenter.cpp @@ -302,6 +302,7 @@ void WidgetsPresenter::presentMessageBox(const MessageConfig &config, QPointersetAttribute(Qt::WA_DeleteOnClose); + result->setCloseTarget(msgBox, QStringLiteral("reject()")); connect(msgBox, &QMessageBox::finished, result, [msgBox, qtHelp, checked, result](){ int sBtn = msgBox->standardButton(msgBox->clickedButton()); @@ -324,6 +325,7 @@ void WidgetsPresenter::presentInputDialog(const MessageConfig &config, QPointer< parent = QApplication::activeWindow(); auto dialog = new QDialog(parent); dialog->setAttribute(Qt::WA_DeleteOnClose); + result->setCloseTarget(dialog, QStringLiteral("reject()")); auto layout = new QVBoxLayout(dialog); dialog->setLayout(layout); @@ -383,6 +385,7 @@ void WidgetsPresenter::presentFileDialog(const MessageConfig &config, QPointersetAttribute(Qt::WA_DeleteOnClose); + result->setCloseTarget(dialog, QStringLiteral("reject()")); //prepare the dialog auto title = config.title(); @@ -443,6 +446,7 @@ void WidgetsPresenter::presentColorDialog(const MessageConfig &config, const QPo parent = QApplication::activeWindow(); auto dialog = new QColorDialog{parent}; dialog->setAttribute(Qt::WA_DeleteOnClose); + result->setCloseTarget(dialog, QStringLiteral("reject()")); //prepare the dialog auto title = config.title(); @@ -494,6 +498,7 @@ void WidgetsPresenter::presentProgressDialog(const MessageConfig &config, const parent = QApplication::activeWindow(); auto dialog = new ProgressDialog{config, result, control, parent}; dialog->setAttribute(Qt::WA_DeleteOnClose); + result->setCloseTarget(dialog, QStringLiteral("reject()")); dialog->open(); }