Full support for other units, add configuration option for default unit (used when...
[novacoin.git] / src / qt / transactionview.cpp
index 8aa4339..12fdc94 100644 (file)
@@ -5,10 +5,11 @@
 #include "walletmodel.h"
 #include "addresstablemodel.h"
 #include "transactiontablemodel.h"
-#include "guiutil.h"
+#include "bitcoinunits.h"
 #include "csvmodelwriter.h"
 #include "transactiondescdialog.h"
 #include "editaddressdialog.h"
+#include "optionsmodel.h"
 
 #include <QScrollBar>
 #include <QComboBox>
@@ -25,6 +26,8 @@
 #include <QMenu>
 #include <QApplication>
 #include <QClipboard>
+#include <QLabel>
+#include <QDateTimeEdit>
 
 #include <QDebug>
 
@@ -90,6 +93,7 @@ TransactionView::TransactionView(QWidget *parent) :
 
     QTableView *view = new QTableView(this);
     vlayout->addLayout(hlayout);
+    vlayout->addWidget(createDateRangeWidget());
     vlayout->addWidget(view);
     vlayout->setSpacing(0);
     int width = view->verticalScrollBar()->sizeHint().width();
@@ -117,15 +121,15 @@ TransactionView::TransactionView(QWidget *parent) :
     // Connect actions
     connect(dateWidget, SIGNAL(activated(int)), this, SLOT(chooseDate(int)));
     connect(typeWidget, SIGNAL(activated(int)), this, SLOT(chooseType(int)));
-    connect(addressWidget, SIGNAL(textChanged(const QString&)), this, SLOT(changedPrefix(const QString&)));
-    connect(amountWidget, SIGNAL(textChanged(const QString&)), this, SLOT(changedAmount(const QString&)));
+    connect(addressWidget, SIGNAL(textChanged(QString)), this, SLOT(changedPrefix(QString)));
+    connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString)));
 
-    connect(view, SIGNAL(doubleClicked(const QModelIndex&)), this, SIGNAL(doubleClicked(const QModelIndex&)));
+    connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex)));
 
     connect(view,
-            SIGNAL(customContextMenuRequested(const QPoint &)),
+            SIGNAL(customContextMenuRequested(QPoint)),
             this,
-            SLOT(contextualMenu(const QPoint &)));
+            SLOT(contextualMenu(QPoint)));
 
     connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress()));
     connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
@@ -167,6 +171,7 @@ void TransactionView::setModel(WalletModel *model)
 void TransactionView::chooseDate(int idx)
 {
     QDate current = QDate::currentDate();
+    dateRangeWidget->setVisible(false);
     switch(dateWidget->itemData(idx).toInt())
     {
     case All:
@@ -203,10 +208,10 @@ void TransactionView::chooseDate(int idx)
                 TransactionFilterProxy::MAX_DATE);
         break;
     case Range:
-        // TODO ask specific range
+        dateRangeWidget->setVisible(true);
+        dateRangeChanged();
         break;
     }
-
 }
 
 void TransactionView::chooseType(int idx)
@@ -223,7 +228,7 @@ void TransactionView::changedPrefix(const QString &prefix)
 void TransactionView::changedAmount(const QString &amount)
 {
     qint64 amount_parsed = 0;
-    if(GUIUtil::parseMoney(amount, &amount_parsed))
+    if(BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, &amount_parsed))
     {
         transactionProxyModel->setMinAmount(amount_parsed);
     }
@@ -337,3 +342,46 @@ void TransactionView::showDetails()
         dlg.exec();
     }
 }
+
+QWidget *TransactionView::createDateRangeWidget()
+{
+    dateRangeWidget = new QFrame();
+    dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
+    dateRangeWidget->setContentsMargins(1,1,1,1);
+    QHBoxLayout *layout = new QHBoxLayout(dateRangeWidget);
+    layout->setContentsMargins(0,0,0,0);
+    layout->addSpacing(23);
+    layout->addWidget(new QLabel("Range:"));
+
+    dateFrom = new QDateTimeEdit(this);
+    dateFrom->setDisplayFormat("dd/MM/yy");
+    dateFrom->setCalendarPopup(true);
+    dateFrom->setMinimumWidth(100);
+    dateFrom->setDate(QDate::currentDate().addDays(-7));
+    layout->addWidget(dateFrom);
+    layout->addWidget(new QLabel("to"));
+
+    dateTo = new QDateTimeEdit(this);
+    dateTo->setDisplayFormat("dd/MM/yy");
+    dateTo->setCalendarPopup(true);
+    dateTo->setMinimumWidth(100);
+    dateTo->setDate(QDate::currentDate());
+    layout->addWidget(dateTo);
+    layout->addStretch();
+
+    // Hide by default
+    dateRangeWidget->setVisible(false);
+
+    // Notify on change
+    connect(dateFrom, SIGNAL(dateChanged(QDate)), this, SLOT(dateRangeChanged()));
+    connect(dateTo, SIGNAL(dateChanged(QDate)), this, SLOT(dateRangeChanged()));
+
+    return dateRangeWidget;
+}
+
+void TransactionView::dateRangeChanged()
+{
+    transactionProxyModel->setDateRange(
+            QDateTime(dateFrom->date()),
+            QDateTime(dateTo->date()).addDays(1));
+}