PIVX Core  5.6.99
P2P Digital Currency
sendmemodialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "sendmemodialog.h"
6 #include "ui_sendmemodialog.h"
7 
8 #include "qtutils.h"
9 #include "snackbar.h"
10 
11 SendMemoDialog::SendMemoDialog(QWidget* parent, WalletModel* model) :
12  FocusedDialog(parent),
13  walletModel(model),
14  ui(new Ui::SendMemoDialog)
15 {
16  if (!walletModel) {
17  throw std::runtime_error(strprintf("%s: No wallet model set", __func__));
18  }
19  ui->setupUi(this);
20  this->setStyleSheet(parent->styleSheet());
21 
22  // Container
23  ui->frame->setProperty("cssClass", "container-dialog");
24 
25  // Text
26  ui->labelTitle->setProperty("cssClass", "text-title-dialog");
27  ui->labelMessage->setProperty("cssClass", "text-main-grey");
28 
29  setCssProperty(ui->textEdit, "edit-text-dialog");
30 
31  // Buttons
32  ui->btnEsc->setText("");
33  ui->btnEsc->setProperty("cssClass", "ic-close");
34 
35  ui->btnCancel->setProperty("cssClass", "btn-dialog-cancel");
36  setCssBtnPrimary(ui->btnSave);
37 
38  connect(ui->textEdit, &QTextEdit::textChanged, this, &SendMemoDialog::textChanged);
39  connect(ui->btnEsc, &QPushButton::clicked, [this]() {
40  operationResult = false;
41  close();
42  });
43  connect(ui->btnCancel, &QPushButton::clicked, this, &SendMemoDialog::reset);
44  connect(ui->btnSave, &QPushButton::clicked, this, &SendMemoDialog::accept);
45 }
46 
47 void SendMemoDialog::setMemo(QString text)
48 {
49  ui->textEdit->setText(text);
50  ui->btnCancel->setText(tr("RESET"));
51 }
52 
54 {
55  return ui->textEdit->toPlainText();
56 }
57 
59 {
60  if (ui->textEdit->toPlainText().length() > 512) {
61  ui->textEdit->textCursor().deletePreviousChar();
62  }
63 }
64 
65 void SendMemoDialog::showEvent(QShowEvent *event)
66 {
67  if (ui->textEdit) ui->textEdit->setFocus();
68 }
69 
71 {
72  if (!ui->textEdit->toPlainText().isEmpty()) {
73  ui->textEdit->clear();
74  ui->btnCancel->setText(tr("CANCEL"));
75  }
76  // caller reset memo on the recipient
77  operationResult = true;
78  close();
79 }
80 
82 {
83  operationResult = true;
84  if (ui->textEdit->toPlainText().isEmpty()) {
85  QDialog::close();
86  } else {
87  QDialog::accept();
88  }
89 }
90 
91 void SendMemoDialog::inform(const QString& text)
92 {
93  if (!snackBar) snackBar = new SnackBar(nullptr, this);
94  snackBar->setText(text);
95  snackBar->resize(this->width(), snackBar->height());
96  openDialog(snackBar, this);
97 }
98 
100 {
101  delete ui;
102 }
WalletModel * walletModel
void setMemo(QString memo)
void accept() override
void inform(const QString &text)
SnackBar * snackBar
void showEvent(QShowEvent *event) override
SendMemoDialog(QWidget *parent, WalletModel *model)
Ui::SendMemoDialog * ui
void setText(const QString &text)
Definition: snackbar.cpp:51
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109
void setCssProperty(std::initializer_list< QWidget * > args, const QString &value)
Definition: qtutils.cpp:334
void setCssBtnPrimary(QPushButton *btn, bool forceUpdate)
Definition: qtutils.cpp:302
bool openDialog(QDialog *widget, QWidget *gui)
Definition: qtutils.cpp:23
#define strprintf
Definition: tinyformat.h:1056