Refactor MemoEdit
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QPlainTextEdit" name="memoTxt"/>
|
||||
<widget class="MemoEdit" name="memoTxt"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
@@ -70,6 +70,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MemoEdit</class>
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header>memoedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
44
src/memoedit.cpp
Normal file
44
src/memoedit.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "memoedit.h"
|
||||
|
||||
MemoEdit::MemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
|
||||
QObject::connect(this, &QPlainTextEdit::textChanged, [=]() {
|
||||
QString txt = this->toPlainText();
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen));
|
||||
|
||||
if (txt.toUtf8().size() <= maxlen) {
|
||||
// Everything is fine
|
||||
acceptButton->setEnabled(true);
|
||||
lenDisplayLabel->setStyleSheet("");
|
||||
}
|
||||
else {
|
||||
// Overweight
|
||||
acceptButton->setEnabled(false);
|
||||
lenDisplayLabel->setStyleSheet("color: red;");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
void MemoEdit::setMaxLen(int len) {
|
||||
this->maxlen = len;
|
||||
}
|
||||
|
||||
void MemoEdit::setLenDisplayLabel(QLabel* label) {
|
||||
this->lenDisplayLabel = label;
|
||||
}
|
||||
|
||||
void MemoEdit::setAcceptButton(QPushButton* button) {
|
||||
this->acceptButton = button;
|
||||
}
|
||||
|
||||
void MemoEdit::includeReplyTo(QString addr) {
|
||||
if (addr.isEmpty())
|
||||
return;
|
||||
|
||||
auto curText = this->toPlainText();
|
||||
if (curText.endsWith(addr))
|
||||
return;
|
||||
|
||||
this->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + addr);
|
||||
}
|
||||
22
src/memoedit.h
Normal file
22
src/memoedit.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef MEMOEDIT_H
|
||||
#define MEMOEDIT_H
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
class MemoEdit : public QPlainTextEdit
|
||||
{
|
||||
public:
|
||||
MemoEdit(QWidget* parent);
|
||||
|
||||
void setMaxLen(int len);
|
||||
void setLenDisplayLabel(QLabel* label);
|
||||
void setAcceptButton(QPushButton* button);
|
||||
void includeReplyTo(QString replyToAddress);
|
||||
|
||||
private:
|
||||
int maxlen = 512;
|
||||
QLabel* lenDisplayLabel = nullptr;
|
||||
QPushButton* acceptButton = nullptr;
|
||||
};
|
||||
|
||||
#endif // MEMOEDIT_H
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <QDir>
|
||||
#include <QMenu>
|
||||
#include <QCompleter>
|
||||
#include <QPushButton>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QSettings>
|
||||
@@ -44,6 +45,7 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QMainWindow>
|
||||
#include <QPushButton>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QLabel>
|
||||
#include <QDialog>
|
||||
#include <QInputDialog>
|
||||
|
||||
14
src/requestdialog.cpp
Normal file
14
src/requestdialog.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "requestdialog.h"
|
||||
#include "ui_requestdialog.h"
|
||||
|
||||
RequestDialog::RequestDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::RequestDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
RequestDialog::~RequestDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
22
src/requestdialog.h
Normal file
22
src/requestdialog.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef REQUESTDIALOG_H
|
||||
#define REQUESTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class RequestDialog;
|
||||
}
|
||||
|
||||
class RequestDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RequestDialog(QWidget *parent = nullptr);
|
||||
~RequestDialog();
|
||||
|
||||
private:
|
||||
Ui::RequestDialog *ui;
|
||||
};
|
||||
|
||||
#endif // REQUESTDIALOG_H
|
||||
124
src/requestdialog.ui
Normal file
124
src/requestdialog.ui
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RequestDialog</class>
|
||||
<widget class="QDialog" name="RequestDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>544</width>
|
||||
<height>450</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="txtAmount">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>amount in ZEC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QLabel" name="txtAmountUSD">
|
||||
<property name="text">
|
||||
<string>Amount USD</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Amount</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="3">
|
||||
<widget class="QTextEdit" name="txtMemo"/>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="txtFrom">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>z address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Memo</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Request From</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>RequestDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>RequestDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -330,22 +330,8 @@ void MainWindow::memoButtonClicked(int number, bool includeReplyTo) {
|
||||
memoDialog.setupUi(&dialog);
|
||||
Settings::saveRestore(&dialog);
|
||||
|
||||
QObject::connect(memoDialog.memoTxt, &QPlainTextEdit::textChanged, [=] () {
|
||||
QString txt = memoDialog.memoTxt->toPlainText();
|
||||
memoDialog.memoSize->setText(QString::number(txt.toUtf8().size()) + "/512");
|
||||
|
||||
if (txt.toUtf8().size() <= 512) {
|
||||
// Everything is fine
|
||||
memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
memoDialog.memoSize->setStyleSheet("");
|
||||
}
|
||||
else {
|
||||
// Overweight
|
||||
memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
memoDialog.memoSize->setStyleSheet("color: red;");
|
||||
}
|
||||
|
||||
});
|
||||
memoDialog.memoTxt->setLenDisplayLabel(memoDialog.memoSize);
|
||||
memoDialog.memoTxt->setAcceptButton(memoDialog.buttonBox->button(QDialogButtonBox::Ok));
|
||||
|
||||
auto fnAddReplyTo = [=, &dialog]() {
|
||||
QString replyTo = ui->inputsCombo->currentText();
|
||||
@@ -354,11 +340,8 @@ void MainWindow::memoButtonClicked(int number, bool includeReplyTo) {
|
||||
if (replyTo.isEmpty())
|
||||
return;
|
||||
}
|
||||
auto curText = memoDialog.memoTxt->toPlainText();
|
||||
if (curText.endsWith(replyTo))
|
||||
return;
|
||||
|
||||
memoDialog.memoTxt->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + replyTo);
|
||||
memoDialog.memoTxt->includeReplyTo(replyTo);
|
||||
|
||||
// MacOS has a really annoying bug where the Plaintext doesn't refresh when the content is
|
||||
// updated. So we do this ugly hack - resize the window slightly to force it to refresh
|
||||
|
||||
@@ -274,7 +274,7 @@
|
||||
<string>Troubleshooting</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="3" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="chkReindex">
|
||||
<property name="text">
|
||||
<string>Reindex</string>
|
||||
@@ -305,7 +305,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<item row="9" column="0">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@@ -318,7 +318,24 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This will take several hours. You need to restart ZecWallet for this to take effect</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Rebuild the entire blockchain from the genesis block, by rescanning all the block files. This may take several hours to days, depending on your hardware. You need to restart ZecWallet for this to take effect</string>
|
||||
@@ -328,13 +345,27 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="chkRescan">
|
||||
<property name="text">
|
||||
<string>Rescan</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="Line" name="line_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
@@ -55,7 +55,9 @@ SOURCES += \
|
||||
src/addresscombo.cpp \
|
||||
src/websockets.cpp \
|
||||
src/mobileappconnector.cpp \
|
||||
src/recurring.cpp
|
||||
src/recurring.cpp \
|
||||
src/requestdialog.cpp \
|
||||
src/memoedit.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/mainwindow.h \
|
||||
@@ -78,7 +80,9 @@ HEADERS += \
|
||||
src/addresscombo.h \
|
||||
src/websockets.h \
|
||||
src/mobileappconnector.h \
|
||||
src/recurring.h
|
||||
src/recurring.h \
|
||||
src/requestdialog.h \
|
||||
src/memoedit.h
|
||||
|
||||
FORMS += \
|
||||
src/mainwindow.ui \
|
||||
@@ -95,7 +99,8 @@ FORMS += \
|
||||
src/mobileappconnector.ui \
|
||||
src/createzcashconfdialog.ui \
|
||||
src/recurringdialog.ui \
|
||||
src/newrecurring.ui
|
||||
src/newrecurring.ui \
|
||||
src/requestdialog.ui
|
||||
|
||||
|
||||
TRANSLATIONS = res/zec_qt_wallet_es.ts \
|
||||
|
||||
Reference in New Issue
Block a user