Browse Source

allow any btn

pull/2/head
Skycoder42 7 years ago
parent
commit
b84bfb3907
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 10
      src/imports/mvvmcore/plugins.qmltypes
  2. 4
      src/mvvmcore/message.cpp
  3. 4
      src/mvvmcore/message.h
  4. 41
      src/mvvmwidgets/progressdialog.cpp
  5. 7
      src/mvvmwidgets/progressdialog_p.h
  6. 2
      src/mvvmwidgets/widgetspresenter.cpp

10
src/imports/mvvmcore/plugins.qmltypes

@ -126,7 +126,10 @@ Module {
Parameter { name: "text"; type: "string" } Parameter { name: "text"; type: "string" }
} }
Signal { name: "closeRequested" } Signal { name: "closeRequested" }
Signal { name: "canceled" } Signal {
name: "canceled"
Parameter { name: "btn"; type: "MessageConfig::StandardButton" }
}
Signal { name: "closed" } Signal { name: "closed" }
Method { name: "close" } Method { name: "close" }
Method { Method {
@ -157,7 +160,10 @@ Module {
name: "setProgress" name: "setProgress"
Parameter { name: "progressPercent"; type: "double" } Parameter { name: "progressPercent"; type: "double" }
} }
Method { name: "requestCancel" } Method {
name: "requestCancel"
Parameter { name: "btn"; type: "MessageConfig::StandardButton" }
}
Method { name: "notifyClosed" } Method { name: "notifyClosed" }
} }
Component { Component {

4
src/mvvmcore/message.cpp

@ -329,9 +329,9 @@ int ProgressControl::progress() const
return d->progress; return d->progress;
} }
void ProgressControl::requestCancel() void ProgressControl::requestCancel(MessageConfig::StandardButton btn)
{ {
emit canceled({}); emit canceled(btn, {});
} }
void ProgressControl::notifyClosed() void ProgressControl::notifyClosed()

4
src/mvvmcore/message.h

@ -263,7 +263,7 @@ public:
int maximum() const; int maximum() const;
int progress() const; int progress() const;
Q_INVOKABLE void requestCancel(); Q_INVOKABLE void requestCancel(MessageConfig::StandardButton btn);
Q_INVOKABLE void notifyClosed(); Q_INVOKABLE void notifyClosed();
public Q_SLOTS: public Q_SLOTS:
@ -287,7 +287,7 @@ Q_SIGNALS:
void changeLabel(const QString &text, QPrivateSignal); void changeLabel(const QString &text, QPrivateSignal);
void closeRequested(QPrivateSignal); void closeRequested(QPrivateSignal);
void canceled(QPrivateSignal); void canceled(MessageConfig::StandardButton btn, QPrivateSignal);
void closed(QPrivateSignal); void closed(QPrivateSignal);
private: private:

41
src/mvvmwidgets/progressdialog.cpp

@ -42,18 +42,20 @@ ProgressDialog::ProgressDialog(const MessageConfig &config, QPointer<MessageResu
layout->addWidget(_progress); layout->addWidget(_progress);
//add the cancel button, in case it was requested //add the cancel button, in case it was requested
if(config.buttons().testFlag(MessageConfig::Cancel)) { if(config.buttons() != MessageConfig::NoButton) {
_btnBox = new QDialogButtonBox{this}; _btnBox = new QDialogButtonBox{this};
_btnBox->setStandardButtons(QDialogButtonBox::Cancel); //is ok, as the buttons are the same _btnBox->setStandardButtons(static_cast<QDialogButtonBox::StandardButtons>(static_cast<int>(config.buttons()))); //is ok, as the buttons are the same
auto btnTexts = config.buttonTexts(); auto btns = config.buttonTexts();
if(btnTexts.contains(MessageConfig::Cancel)) for(auto it = btns.constBegin(); it != btns.constEnd(); it++){
_btnBox->button(QDialogButtonBox::Cancel)->setText(btnTexts.value(MessageConfig::Cancel)); auto sBtn = static_cast<QDialogButtonBox::StandardButton>(it.key());
Q_ASSERT(_btnBox->standardButtons().testFlag(sBtn)); //Must be the case now because of the change in MessageConfig
_btnBox->button(sBtn)->setText(it.value());
}
layout->addWidget(_btnBox); layout->addWidget(_btnBox);
// connect the box // connect the box
connect(_btnBox, &QDialogButtonBox::clicked, connect(_btnBox, &QDialogButtonBox::clicked,
this, [this](QAbstractButton *btn) { this, [this](QAbstractButton *btn) {
if(_btnBox->standardButton(btn) == QDialogButtonBox::Cancel) tryCancel(_btnBox->standardButton(btn));
tryCancel();
}); });
} }
@ -75,9 +77,6 @@ ProgressDialog::ProgressDialog(const MessageConfig &config, QPointer<MessageResu
this, &ProgressDialog::setIndetem); this, &ProgressDialog::setIndetem);
} }
connect(this, &ProgressDialog::canceled,
_control, &ProgressControl::requestCancel);
adjustSize(); adjustSize();
DialogMaster::masterDialog(this, true, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); DialogMaster::masterDialog(this, true, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
} }
@ -87,29 +86,25 @@ void ProgressDialog::done(int code)
QDialog::done(code); QDialog::done(code);
if(_control) if(_control)
_control->notifyClosed(); _control->notifyClosed();
if(_result) { if(_result)
if(_wasCanceled) _result->complete(_cancelAction);
_result->complete(MessageConfig::Cancel);
else
_result->complete(MessageConfig::Close);
}
} }
void ProgressDialog::closeEvent(QCloseEvent *event) void ProgressDialog::closeEvent(QCloseEvent *event)
{ {
event->ignore(); event->ignore();
tryCancel(); tryCancel(QDialogButtonBox::Cancel);
} }
void ProgressDialog::tryCancel() void ProgressDialog::tryCancel(QDialogButtonBox::StandardButton btn)
{ {
if(!_wasCanceled && _btnBox) { if(_cancelAction == MessageConfig::NoButton && _btnBox) {
_wasCanceled = true; _cancelAction = static_cast<MessageConfig::StandardButton>(btn);
_btnBox->button(QDialogButtonBox::Cancel)->setEnabled(false); _btnBox->setEnabled(false);
if(_control) if(_control)
_control->requestCancel(); _control->requestCancel(_cancelAction);
else else
done(QDialogButtonBox::Cancel); done(btn);
} }
} }

7
src/mvvmwidgets/progressdialog_p.h

@ -27,14 +27,11 @@ public:
public Q_SLOTS: public Q_SLOTS:
void done(int code) override; void done(int code) override;
Q_SIGNALS:
void canceled();
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
private Q_SLOTS: private Q_SLOTS:
void tryCancel(); void tryCancel(QDialogButtonBox::StandardButton btn);
void updateLabel(const QString &text); void updateLabel(const QString &text);
void setIndetem(bool indetem); void setIndetem(bool indetem);
@ -49,7 +46,7 @@ private:
QLabel *_label; QLabel *_label;
QProgressBar *_progress; QProgressBar *_progress;
QDialogButtonBox *_btnBox = nullptr; QDialogButtonBox *_btnBox = nullptr;
bool _wasCanceled = false; MessageConfig::StandardButton _cancelAction = MessageConfig::NoButton;
}; };
} }

2
src/mvvmwidgets/widgetspresenter.cpp

@ -357,7 +357,7 @@ void WidgetsPresenter::presentInputDialog(const MessageConfig &config, QPointer<
//connect stuff //connect stuff
connect(btnBox, &QDialogButtonBox::clicked, connect(btnBox, &QDialogButtonBox::clicked,
dialog, [dialog, btnBox](QAbstractButton *btn){ dialog, [dialog, btnBox](QAbstractButton *btn){
dialog->done(btnBox->standardButton(btn)); dialog->done(btnBox->standardButton(btn));
}); });
connect(dialog, &QDialog::finished, connect(dialog, &QDialog::finished,

Loading…
Cancel
Save