Use a messagebox to display the error when -server is provided without providing...
[novacoin.git] / src / qt / sendcoinsentry.cpp
index abdbc81..caffaae 100644 (file)
@@ -7,10 +7,8 @@
 #include "optionsmodel.h"
 #include "addresstablemodel.h"
 
-#include "qapplication.h"
-#include "qclipboard.h"
-
-#include <QDebug>
+#include <QApplication>
+#include <QClipboard>
 
 SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
     QFrame(parent),
@@ -19,6 +17,10 @@ SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
 {
     ui->setupUi(this);
 
+#ifdef Q_WS_MAC
+    ui->payToLayout->setSpacing(4);
+#endif
+
 #if QT_VERSION >= 0x040700
     ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
     ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
@@ -42,6 +44,8 @@ void SendCoinsEntry::on_pasteButton_clicked()
 
 void SendCoinsEntry::on_addressBookButton_clicked()
 {
+    if(!model)
+        return;
     AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
     dlg.setModel(model->getAddressTableModel());
     if(dlg.exec())
@@ -53,12 +57,16 @@ void SendCoinsEntry::on_addressBookButton_clicked()
 
 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
 {
-    ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
-}
+    if(!model)
+        return;
+    // Fill in label from address book, if no label is filled in yet
+    if(ui->addAsLabel->text().isEmpty())
+        ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));}
 
 void SendCoinsEntry::setModel(WalletModel *model)
 {
     this->model = model;
+    clear();
 }
 
 void SendCoinsEntry::setRemoveEnabled(bool enabled)
@@ -72,7 +80,7 @@ void SendCoinsEntry::clear()
     ui->addAsLabel->clear();
     ui->payAmount->clear();
     ui->payTo->setFocus();
-    if(model)
+    if(model && model->getOptionsModel())
     {
         ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
     }
@@ -102,7 +110,6 @@ bool SendCoinsEntry::validate()
         }
     }
 
-
     if(!ui->payTo->hasAcceptableInput() ||
        (model && !model->validateAddress(ui->payTo->text())))
     {
@@ -133,3 +140,21 @@ QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
     QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
     return ui->payAmount->setupTabChain(ui->addAsLabel);
 }
+
+void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
+{
+    ui->payTo->setText(value.address);
+    ui->addAsLabel->setText(value.label);
+    ui->payAmount->setValue(value.amount);
+}
+
+bool SendCoinsEntry::isClear()
+{
+    return ui->payTo->text().isEmpty();
+}
+
+void SendCoinsEntry::setFocus()
+{
+    ui->payTo->setFocus();
+}
+