mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Qt: Delay user confirmation of send
I made a subclass of QMessageBox that disables the send button in exec() and starts a timer that calls a slot to re-enable it after a configurable delay. It also has a countdown in the send/yes button while it is disabled to hint to the user why the send button is disabled (and that it is actually supposed to be disabled).
This commit is contained in:
parent
42a6753382
commit
3902a291ab
@ -26,6 +26,9 @@
|
|||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#define SEND_CONFIRM_DELAY 3
|
||||||
|
|
||||||
SendCoinsDialog::SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent) :
|
SendCoinsDialog::SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@ -311,10 +314,10 @@ void SendCoinsDialog::on_sendButton_clicked()
|
|||||||
questionString.append(QString("<span style='font-size:10pt;font-weight:normal;'><br />(=%2)</span>")
|
questionString.append(QString("<span style='font-size:10pt;font-weight:normal;'><br />(=%2)</span>")
|
||||||
.arg(alternativeUnits.join(" " + tr("or") + "<br />")));
|
.arg(alternativeUnits.join(" " + tr("or") + "<br />")));
|
||||||
|
|
||||||
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
|
SendConfirmationDialog confirmationDialog(tr("Confirm send coins"),
|
||||||
questionString.arg(formatted.join("<br />")),
|
questionString.arg(formatted.join("<br />")), SEND_CONFIRM_DELAY, this);
|
||||||
QMessageBox::Yes | QMessageBox::Cancel,
|
confirmationDialog.exec();
|
||||||
QMessageBox::Cancel);
|
QMessageBox::StandardButton retval = (QMessageBox::StandardButton)confirmationDialog.result();
|
||||||
|
|
||||||
if(retval != QMessageBox::Yes)
|
if(retval != QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
@ -828,3 +831,45 @@ void SendCoinsDialog::coinControlUpdateLabels()
|
|||||||
ui->labelCoinControlInsuffFunds->hide();
|
ui->labelCoinControlInsuffFunds->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendConfirmationDialog::SendConfirmationDialog(const QString &title, const QString &text, int secDelay,
|
||||||
|
QWidget *parent) :
|
||||||
|
QMessageBox(QMessageBox::Question, title, text, QMessageBox::Yes | QMessageBox::Cancel, parent), secDelay(secDelay)
|
||||||
|
{
|
||||||
|
setDefaultButton(QMessageBox::Cancel);
|
||||||
|
yesButton = button(QMessageBox::Yes);
|
||||||
|
updateYesButton();
|
||||||
|
connect(&countDownTimer, SIGNAL(timeout()), this, SLOT(countDown()));
|
||||||
|
}
|
||||||
|
|
||||||
|
int SendConfirmationDialog::exec()
|
||||||
|
{
|
||||||
|
updateYesButton();
|
||||||
|
countDownTimer.start(1000);
|
||||||
|
return QMessageBox::exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendConfirmationDialog::countDown()
|
||||||
|
{
|
||||||
|
secDelay--;
|
||||||
|
updateYesButton();
|
||||||
|
|
||||||
|
if(secDelay <= 0)
|
||||||
|
{
|
||||||
|
countDownTimer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendConfirmationDialog::updateYesButton()
|
||||||
|
{
|
||||||
|
if(secDelay > 0)
|
||||||
|
{
|
||||||
|
yesButton->setEnabled(false);
|
||||||
|
yesButton->setText(tr("Yes") + " (" + QString::number(secDelay) + ")");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yesButton->setEnabled(true);
|
||||||
|
yesButton->setText(tr("Yes"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
#include "walletmodel.h"
|
#include "walletmodel.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class ClientModel;
|
class ClientModel;
|
||||||
class OptionsModel;
|
class OptionsModel;
|
||||||
@ -100,4 +102,24 @@ Q_SIGNALS:
|
|||||||
void message(const QString &title, const QString &message, unsigned int style);
|
void message(const QString &title, const QString &message, unsigned int style);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SendConfirmationDialog : public QMessageBox
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SendConfirmationDialog(const QString &title, const QString &text, int secDelay = 0, QWidget *parent = 0);
|
||||||
|
int exec();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void countDown();
|
||||||
|
void updateYesButton();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QAbstractButton *yesButton;
|
||||||
|
QTimer countDownTimer;
|
||||||
|
int secDelay;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_QT_SENDCOINSDIALOG_H
|
#endif // BITCOIN_QT_SENDCOINSDIALOG_H
|
||||||
|
Loading…
Reference in New Issue
Block a user