Skip to content

Commit

Permalink
Refactor MemoEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Mar 22, 2019
1 parent 3899807 commit 9dd6821
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 28 deletions.
9 changes: 8 additions & 1 deletion src/memodialog.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -70,6 +70,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MemoEdit</class>
<extends>QPlainTextEdit</extends>
<header>memoedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down
44 changes: 44 additions & 0 deletions src/memoedit.cpp
@@ -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 changes: 22 additions & 0 deletions src/memoedit.h
@@ -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
2 changes: 2 additions & 0 deletions src/precompiled.h
Expand Up @@ -32,6 +32,7 @@
#include <QDir>
#include <QMenu>
#include <QCompleter>
#include <QPushButton>
#include <QDateTime>
#include <QTimer>
#include <QSettings>
Expand All @@ -44,6 +45,7 @@
#include <QStandardPaths>
#include <QMainWindow>
#include <QPushButton>
#include <QPlainTextEdit>
#include <QLabel>
#include <QDialog>
#include <QInputDialog>
Expand Down
14 changes: 14 additions & 0 deletions src/requestdialog.cpp
@@ -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 changes: 22 additions & 0 deletions src/requestdialog.h
@@ -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 changes: 124 additions & 0 deletions src/requestdialog.ui
@@ -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>
23 changes: 3 additions & 20 deletions src/sendtab.cpp
Expand Up @@ -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();
Expand All @@ -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
Expand Down
39 changes: 35 additions & 4 deletions src/settings.ui
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 9dd6821

Please sign in to comment.