Browse Source

fix dialogs close messages and quick closing

pull/2/head
Skycoder42 7 years ago
parent
commit
bb5cdb7829
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 83
      src/imports/mvvmquick/MsgBoxBase.qml
  2. 10
      src/imports/mvvmquick/ProgressDialog.qml
  3. 5
      src/mvvmwidgets/widgetspresenter.cpp

83
src/imports/mvvmquick/MsgBoxBase.qml

@ -46,49 +46,56 @@ AlertDialog {
} }
} }
footer: DialogButtonBox { footer: Item {
id: _btnBox
visible: msgConfig.buttons !== MessageConfig.NoButton visible: msgConfig.buttons !== MessageConfig.NoButton
implicitWidth: _btnBox.implicitWidth
implicitHeight: _btnBox.implicitHeight
readonly property var _allBtns: [ DialogButtonBox {
DialogButtonBox.NoButton, id: _btnBox
DialogButtonBox.Ok, anchors.fill: parent
DialogButtonBox.Save,
DialogButtonBox.SaveAll, readonly property var _allBtns: [
DialogButtonBox.Open, DialogButtonBox.NoButton,
DialogButtonBox.Yes, DialogButtonBox.Ok,
DialogButtonBox.YesToAll, DialogButtonBox.Save,
DialogButtonBox.No, DialogButtonBox.SaveAll,
DialogButtonBox.NoToAll, DialogButtonBox.Open,
DialogButtonBox.Abort, DialogButtonBox.Yes,
DialogButtonBox.Retry, DialogButtonBox.YesToAll,
DialogButtonBox.Ignore, DialogButtonBox.No,
DialogButtonBox.Close, DialogButtonBox.NoToAll,
DialogButtonBox.Cancel, DialogButtonBox.Abort,
DialogButtonBox.Discard, DialogButtonBox.Retry,
DialogButtonBox.Help, DialogButtonBox.Ignore,
DialogButtonBox.Apply, DialogButtonBox.Close,
DialogButtonBox.Reset, DialogButtonBox.Cancel,
DialogButtonBox.RestoreDefaults, DialogButtonBox.Discard,
] DialogButtonBox.Help,
DialogButtonBox.Apply,
standardButtons: msgConfig.buttons DialogButtonBox.Reset,
onStandardButtonsChanged: { DialogButtonBox.RestoreDefaults,
Object.keys(msgConfig.buttonTexts).forEach(function(key) { ]
standardButton(key).text = msgConfig.buttonTexts[key]
});
}
onClicked: { standardButtons: msgConfig.buttons
_msgBoxBase.buttonClicked(button); onStandardButtonsChanged: {
if(msgResult && autoHandleBtns) { Object.keys(msgConfig.buttonTexts).forEach(function(key) {
_allBtns.forEach(function(sBtn) { standardButton(key).text = msgConfig.buttonTexts[key]
if(button === standardButton(sBtn)) {
msgResult.complete(sBtn);
msgResult = null;
}
}); });
} }
onClicked: {
_msgBoxBase.buttonClicked(button);
if(msgResult && autoHandleBtns) {
_allBtns.forEach(function(sBtn) {
if(button === standardButton(sBtn)) {
msgResult.complete(sBtn);
msgResult = null;
_msgBoxBase.done(sBtn);
}
});
}
}
} }
} }

10
src/imports/mvvmquick/ProgressDialog.qml

@ -17,16 +17,6 @@ MsgBoxBase {
readonly property bool _allowClose: !progressControl || !msgResult readonly property bool _allowClose: !progressControl || !msgResult
onButtonClicked: tryCancel(button) 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: { Component.onCompleted: {
if(msgResult) if(msgResult)

5
src/mvvmwidgets/widgetspresenter.cpp

@ -302,6 +302,7 @@ void WidgetsPresenter::presentMessageBox(const MessageConfig &config, QPointer<M
//create and show the msgbox //create and show the msgbox
auto msgBox = DialogMaster::createMessageBox(info); auto msgBox = DialogMaster::createMessageBox(info);
msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->setAttribute(Qt::WA_DeleteOnClose);
result->setCloseTarget(msgBox, QStringLiteral("reject()"));
connect(msgBox, &QMessageBox::finished, connect(msgBox, &QMessageBox::finished,
result, [msgBox, qtHelp, checked, result](){ result, [msgBox, qtHelp, checked, result](){
int sBtn = msgBox->standardButton(msgBox->clickedButton()); int sBtn = msgBox->standardButton(msgBox->clickedButton());
@ -324,6 +325,7 @@ void WidgetsPresenter::presentInputDialog(const MessageConfig &config, QPointer<
parent = QApplication::activeWindow(); parent = QApplication::activeWindow();
auto dialog = new QDialog(parent); auto dialog = new QDialog(parent);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
result->setCloseTarget(dialog, QStringLiteral("reject()"));
auto layout = new QVBoxLayout(dialog); auto layout = new QVBoxLayout(dialog);
dialog->setLayout(layout); dialog->setLayout(layout);
@ -383,6 +385,7 @@ void WidgetsPresenter::presentFileDialog(const MessageConfig &config, QPointer<M
parent = QApplication::activeWindow(); parent = QApplication::activeWindow();
auto dialog = new QFileDialog(parent); auto dialog = new QFileDialog(parent);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
result->setCloseTarget(dialog, QStringLiteral("reject()"));
//prepare the dialog //prepare the dialog
auto title = config.title(); auto title = config.title();
@ -443,6 +446,7 @@ void WidgetsPresenter::presentColorDialog(const MessageConfig &config, const QPo
parent = QApplication::activeWindow(); parent = QApplication::activeWindow();
auto dialog = new QColorDialog{parent}; auto dialog = new QColorDialog{parent};
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
result->setCloseTarget(dialog, QStringLiteral("reject()"));
//prepare the dialog //prepare the dialog
auto title = config.title(); auto title = config.title();
@ -494,6 +498,7 @@ void WidgetsPresenter::presentProgressDialog(const MessageConfig &config, const
parent = QApplication::activeWindow(); parent = QApplication::activeWindow();
auto dialog = new ProgressDialog{config, result, control, parent}; auto dialog = new ProgressDialog{config, result, control, parent};
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
result->setCloseTarget(dialog, QStringLiteral("reject()"));
dialog->open(); dialog->open();
} }

Loading…
Cancel
Save