mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-30 00:35:05 +00:00
introduce bitcoin amount field with split amount/decimals, to protect against mistakes (https://forum.bitcoin.org/index.php?topic=19168.0)
This commit is contained in:
parent
18b99e3f69
commit
f193c57a63
@ -68,7 +68,8 @@ HEADERS += src/qt/bitcoingui.h \
|
|||||||
src/qt/monitoreddatamapper.h \
|
src/qt/monitoreddatamapper.h \
|
||||||
src/externui.h \
|
src/externui.h \
|
||||||
src/qt/transactiondesc.h \
|
src/qt/transactiondesc.h \
|
||||||
src/qt/transactiondescdialog.h
|
src/qt/transactiondescdialog.h \
|
||||||
|
src/qt/bitcoinamountfield.h
|
||||||
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
||||||
src/qt/transactiontablemodel.cpp \
|
src/qt/transactiontablemodel.cpp \
|
||||||
src/qt/addresstablemodel.cpp \
|
src/qt/addresstablemodel.cpp \
|
||||||
@ -98,7 +99,8 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
|
|||||||
src/qt/monitoreddatamapper.cpp \
|
src/qt/monitoreddatamapper.cpp \
|
||||||
src/qt/transactiondesc.cpp \
|
src/qt/transactiondesc.cpp \
|
||||||
src/qt/transactiondescdialog.cpp \
|
src/qt/transactiondescdialog.cpp \
|
||||||
src/qt/bitcoinstrings.cpp
|
src/qt/bitcoinstrings.cpp \
|
||||||
|
src/qt/bitcoinamountfield.cpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
src/qt/bitcoin.qrc
|
src/qt/bitcoin.qrc
|
||||||
|
67
src/qt/bitcoinamountfield.cpp
Normal file
67
src/qt/bitcoinamountfield.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "bitcoinamountfield.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QRegExpValidator>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
|
BitcoinAmountField::BitcoinAmountField(QWidget *parent):
|
||||||
|
QWidget(parent), amount(0), decimals(0)
|
||||||
|
{
|
||||||
|
amount = new QLineEdit(this);
|
||||||
|
amount->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this));
|
||||||
|
amount->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||||
|
amount->installEventFilter(this);
|
||||||
|
amount->setMaximumWidth(80);
|
||||||
|
decimals = new QLineEdit(this);
|
||||||
|
decimals->setValidator(new QRegExpValidator(QRegExp("[0-9]+"), this));
|
||||||
|
decimals->setMaxLength(8);
|
||||||
|
decimals->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
|
||||||
|
decimals->setMaximumWidth(75);
|
||||||
|
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
layout->addWidget(amount);
|
||||||
|
layout->addWidget(new QLabel(QString(".")));
|
||||||
|
layout->addWidget(decimals);
|
||||||
|
layout->addStretch(1);
|
||||||
|
|
||||||
|
setFocusPolicy(Qt::TabFocus);
|
||||||
|
setLayout(layout);
|
||||||
|
setFocusProxy(amount);
|
||||||
|
|
||||||
|
// If one if the widgets changes, the combined content changes as well
|
||||||
|
connect(amount, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged()));
|
||||||
|
connect(decimals, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BitcoinAmountField::setText(const QString &text)
|
||||||
|
{
|
||||||
|
const QStringList parts = text.split(QString("."));
|
||||||
|
if(parts.size() == 2)
|
||||||
|
{
|
||||||
|
amount->setText(parts[0]);
|
||||||
|
decimals->setText(parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BitcoinAmountField::text() const
|
||||||
|
{
|
||||||
|
return amount->text() + QString(".") + decimals->text();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept '.' and ',' keys, if pressed focus a specified widget
|
||||||
|
bool BitcoinAmountField::eventFilter(QObject *object, QEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(object);
|
||||||
|
if(event->type() == QEvent::KeyPress)
|
||||||
|
{
|
||||||
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||||
|
if(keyEvent->key() == Qt::Key_Period || keyEvent->key() == Qt::Key_Comma)
|
||||||
|
{
|
||||||
|
decimals->setFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
33
src/qt/bitcoinamountfield.h
Normal file
33
src/qt/bitcoinamountfield.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef BITCOINFIELD_H
|
||||||
|
#define BITCOINFIELD_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QLineEdit;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class BitcoinAmountField: public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true);
|
||||||
|
public:
|
||||||
|
explicit BitcoinAmountField(QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setText(const QString &text);
|
||||||
|
QString text() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void textChanged();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Intercept '.' and ',' keys, if pressed focus a specified widget
|
||||||
|
bool eventFilter(QObject *object, QEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLineEdit *amount;
|
||||||
|
QLineEdit *decimals;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BITCOINFIELD_H
|
@ -52,22 +52,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QLineEdit" name="payAmount">
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>145</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Amount of bitcoins to send (e.g. 0.05)</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QPushButton" name="pasteButton">
|
<widget class="QPushButton" name="pasteButton">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
@ -106,6 +90,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="BitcoinAmountField" name="payAmount" native="true">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::TabFocus</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -173,6 +164,22 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>BitcoinAmountField</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>bitcoinamountfield.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>payTo</tabstop>
|
||||||
|
<tabstop>payAmount</tabstop>
|
||||||
|
<tabstop>pasteButton</tabstop>
|
||||||
|
<tabstop>addressBookButton</tabstop>
|
||||||
|
<tabstop>sendButton</tabstop>
|
||||||
|
<tabstop>buttonBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../bitcoin.qrc"/>
|
<include location="../bitcoin.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "optionsdialog.h"
|
#include "optionsdialog.h"
|
||||||
#include "optionsmodel.h"
|
#include "optionsmodel.h"
|
||||||
|
#include "bitcoinamountfield.h"
|
||||||
#include "monitoreddatamapper.h"
|
#include "monitoreddatamapper.h"
|
||||||
#include "guiutil.h"
|
#include "guiutil.h"
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ private:
|
|||||||
QCheckBox *connect_socks4;
|
QCheckBox *connect_socks4;
|
||||||
QLineEdit *proxy_ip;
|
QLineEdit *proxy_ip;
|
||||||
QLineEdit *proxy_port;
|
QLineEdit *proxy_port;
|
||||||
QLineEdit *fee_edit;
|
BitcoinAmountField *fee_edit;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@ -195,12 +196,9 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
|
|||||||
fee_hbox->addSpacing(18);
|
fee_hbox->addSpacing(18);
|
||||||
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
|
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
|
||||||
fee_hbox->addWidget(fee_label);
|
fee_hbox->addWidget(fee_label);
|
||||||
fee_edit = new QLineEdit();
|
fee_edit = new BitcoinAmountField();
|
||||||
fee_edit->setMaximumWidth(100);
|
|
||||||
fee_edit->setToolTip(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
|
fee_edit->setToolTip(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
|
||||||
|
|
||||||
GUIUtil::setupAmountWidget(fee_edit, this);
|
|
||||||
|
|
||||||
fee_label->setBuddy(fee_edit);
|
fee_label->setBuddy(fee_edit);
|
||||||
fee_hbox->addWidget(fee_edit);
|
fee_hbox->addWidget(fee_edit);
|
||||||
fee_hbox->addStretch(1);
|
fee_hbox->addStretch(1);
|
||||||
|
@ -23,7 +23,6 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
GUIUtil::setupAddressWidget(ui->payTo, this);
|
GUIUtil::setupAddressWidget(ui->payTo, this);
|
||||||
GUIUtil::setupAmountWidget(ui->payAmount, this);
|
|
||||||
|
|
||||||
// Set initial send-to address if provided
|
// Set initial send-to address if provided
|
||||||
if(!address.isEmpty())
|
if(!address.isEmpty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user