diff options
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/addresstablemodel.cpp | 6 | ||||
-rw-r--r-- | src/qt/addresstablemodel.h | 4 | ||||
-rw-r--r-- | src/qt/editaddressdialog.cpp | 5 | ||||
-rw-r--r-- | src/qt/forms/receivecoinsdialog.ui | 121 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 12 | ||||
-rw-r--r-- | src/qt/guiutil.h | 2 | ||||
-rw-r--r-- | src/qt/receivecoinsdialog.cpp | 17 | ||||
-rw-r--r-- | src/qt/receiverequestdialog.cpp | 8 | ||||
-rw-r--r-- | src/qt/walletmodel.cpp | 5 | ||||
-rw-r--r-- | src/qt/walletmodel.h | 4 |
10 files changed, 143 insertions, 41 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index a2521a1e9e..74f0db3520 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -341,7 +341,7 @@ void AddressTableModel::updateEntry(const QString &address, priv->updateEntry(address, label, isMine, purpose, status); } -QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address) +QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type) { std::string strLabel = label.toStdString(); std::string strAddress = address.toStdString(); @@ -384,8 +384,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con return QString(); } } - wallet->LearnRelatedScripts(newKey, g_address_type); - strAddress = EncodeDestination(GetDestinationForKey(newKey, g_address_type)); + wallet->LearnRelatedScripts(newKey, address_type); + strAddress = EncodeDestination(GetDestinationForKey(newKey, address_type)); } else { diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index d04b95ebae..11439e25d5 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -8,6 +8,8 @@ #include <QAbstractTableModel> #include <QStringList> +enum OutputType : int; + class AddressTablePriv; class WalletModel; @@ -61,7 +63,7 @@ public: /* Add an address to the model. Returns the added address on success, and an empty string otherwise. */ - QString addRow(const QString &type, const QString &label, const QString &address); + QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type); /* Look up label for address in address book, if not found return empty string. */ diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 6b7df2f2b9..a945fc6aa0 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -11,6 +11,8 @@ #include <QDataWidgetMapper> #include <QMessageBox> +extern OutputType g_address_type; + EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) : QDialog(parent), ui(new Ui::EditAddressDialog), @@ -77,7 +79,8 @@ bool EditAddressDialog::saveCurrentRow() address = model->addRow( mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive, ui->labelEdit->text(), - ui->addressEdit->text()); + ui->addressEdit->text(), + g_address_type); break; case EditReceivingAddress: case EditSendingAddress: diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui index 58f030ebf0..09fb435a58 100644 --- a/src/qt/forms/receivecoinsdialog.ui +++ b/src/qt/forms/receivecoinsdialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>776</width> - <height>364</height> + <height>396</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1"> @@ -28,6 +28,22 @@ <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <layout class="QGridLayout" name="gridLayout"> + <item row="5" column="0"> + <widget class="QLabel" name="label"> + <property name="toolTip"> + <string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string> + </property> + <property name="text"> + <string>&Amount:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buddy"> + <cstring>reqAmount</cstring> + </property> + </widget> + </item> <item row="6" column="0"> <widget class="QLabel" name="label_3"> <property name="toolTip"> @@ -51,13 +67,6 @@ </property> </widget> </item> - <item row="6" column="2"> - <widget class="QLineEdit" name="reqMessage"> - <property name="toolTip"> - <string>An optional message to attach to the payment request, which will be displayed when the request is opened. Note: The message will not be sent with the payment over the Bitcoin network.</string> - </property> - </widget> - </item> <item row="2" column="2"> <widget class="QLabel" name="label_5"> <property name="text"> @@ -81,32 +90,10 @@ </property> </widget> </item> - <item row="5" column="0"> - <widget class="QLabel" name="label"> - <property name="toolTip"> - <string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string> - </property> - <property name="text"> - <string>&Amount:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - <property name="buddy"> - <cstring>reqAmount</cstring> - </property> - </widget> - </item> - <item row="5" column="2"> - <widget class="BitcoinAmountField" name="reqAmount"> - <property name="minimumSize"> - <size> - <width>80</width> - <height>0</height> - </size> - </property> + <item row="6" column="2"> + <widget class="QLineEdit" name="reqMessage"> <property name="toolTip"> - <string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string> + <string>An optional message to attach to the payment request, which will be displayed when the request is opened. Note: The message will not be sent with the payment over the Bitcoin network.</string> </property> </widget> </item> @@ -174,6 +161,73 @@ </property> </widget> </item> + <item row="5" column="2"> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="BitcoinAmountField" name="reqAmount"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>80</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>1000</width> + <height>100</height> + </size> + </property> + <property name="toolTip"> + <string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="useBech32"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>1000</width> + <height>16777215</height> + </size> + </property> + <property name="focusPolicy"> + <enum>Qt::StrongFocus</enum> + </property> + <property name="toolTip"> + <string>Bech32 addresses (BIP-173) are cheaper to spend from and offer better protection against typos. When unchecked a P2SH wrapped SegWit address will be created, compatible with older wallets.</string> + </property> + <property name="text"> + <string>Generate Bech32 address</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> </layout> </item> </layout> @@ -306,6 +360,7 @@ <tabstops> <tabstop>reqLabel</tabstop> <tabstop>reqAmount</tabstop> + <tabstop>useBech32</tabstop> <tabstop>reqMessage</tabstop> <tabstop>receiveButton</tabstop> <tabstop>clearButton</tabstop> diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 670d6108db..558d4f108c 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -995,6 +995,18 @@ QString formatBytes(uint64_t bytes) return QString(QObject::tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024); } +qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) { + while(font_size >= minPointSize) { + font.setPointSizeF(font_size); + QFontMetrics fm(font); + if (fm.width(text) < width) { + break; + } + font_size -= 0.5; + } + return font_size; +} + void ClickableLabel::mouseReleaseEvent(QMouseEvent *event) { Q_EMIT clicked(event->pos()); diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index ad0e22ccd6..71a69483f5 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -201,6 +201,8 @@ namespace GUIUtil QString formatBytes(uint64_t bytes); + qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14); + class ClickableLabel : public QLabel { Q_OBJECT diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index e07f2b74ee..7fd5285467 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -2,6 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include <wallet/wallet.h> + #include <qt/receivecoinsdialog.h> #include <qt/forms/ui_receivecoinsdialog.h> @@ -91,6 +93,15 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model) SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection))); // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready. columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this); + + // configure bech32 checkbox, disable if launched with legacy as default: + if (model->getDefaultAddressType() == OUTPUT_TYPE_BECH32) { + ui->useBech32->setCheckState(Qt::Checked); + } else { + ui->useBech32->setCheckState(Qt::Unchecked); + } + + ui->useBech32->setVisible(model->getDefaultAddressType() != OUTPUT_TYPE_LEGACY); } } @@ -133,7 +144,11 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() QString address; QString label = ui->reqLabel->text(); /* Generate new receiving address */ - address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, ""); + OutputType address_type = model->getDefaultAddressType(); + if (address_type != OUTPUT_TYPE_LEGACY) { + address_type = ui->useBech32->isChecked() ? OUTPUT_TYPE_BECH32 : OUTPUT_TYPE_P2SH_SEGWIT; + } + address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type); SendCoinsRecipient info(address, label, ui->reqAmount->value(), ui->reqMessage->text()); ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp index 209397ca0c..d4cb0e5ba2 100644 --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -183,9 +183,13 @@ void ReceiveRequestDialog::update() QPainter painter(&qrAddrImage); painter.drawImage(0, 0, qrImage.scaled(QR_IMAGE_SIZE, QR_IMAGE_SIZE)); QFont font = GUIUtil::fixedPitchFont(); - font.setPixelSize(12); - painter.setFont(font); QRect paddedRect = qrAddrImage.rect(); + + // calculate ideal font size + qreal font_size = GUIUtil::calculateIdealFontSize(paddedRect.width() - 20, info.address, font); + font.setPointSizeF(font_size); + + painter.setFont(font); paddedRect.setHeight(QR_IMAGE_SIZE+12); painter.drawText(paddedRect, Qt::AlignBottom|Qt::AlignCenter, info.address); painter.end(); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 494b46905d..4d7e977fcb 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -733,6 +733,11 @@ bool WalletModel::hdEnabled() const return wallet->IsHDEnabled(); } +OutputType WalletModel::getDefaultAddressType() const +{ + return g_address_type; +} + int WalletModel::getDefaultConfirmTarget() const { return nTxConfirmTarget; diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 7d7e4f160e..9e13de79be 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -15,6 +15,8 @@ #include <QObject> +enum OutputType : int; + class AddressTableModel; class OptionsModel; class PlatformStyle; @@ -214,6 +216,8 @@ public: bool hdEnabled() const; + OutputType getDefaultAddressType() const; + int getDefaultConfirmTarget() const; private: |