Make status column narrow (icon only, details on tooltip)
[novacoin.git] / src / qt / transactiontablemodel.cpp
index 8fe1839..47cab1b 100644 (file)
@@ -51,8 +51,9 @@ struct TransactionTablePriv
 
     void refreshWallet()
     {
+#ifdef WALLET_UPDATE_DEBUG
         qDebug() << "refreshWallet";
-
+#endif
         /* Query entire wallet from core.
          */
         cachedWallet.clear();
@@ -72,8 +73,9 @@ struct TransactionTablePriv
     {
         /* Walk through updated transactions, update model as needed.
          */
+#ifdef WALLET_UPDATE_DEBUG
         qDebug() << "updateWallet";
-
+#endif
         /* Sort update list, and iterate through it in reverse, so that model updates
            can be emitted from end to beginning (so that earlier updates will not influence
            the indices of latter ones).
@@ -103,8 +105,10 @@ struct TransactionTablePriv
                     inModel = true;
                 }
 
+#ifdef WALLET_UPDATE_DEBUG
                 qDebug() << "  " << QString::fromStdString(hash.ToString()) << inWallet << " " << inModel
                         << lowerIndex << "-" << upperIndex;
+#endif
 
                 if(inWallet && !inModel)
                 {
@@ -270,13 +274,13 @@ QVariant TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) con
         status = tr("Open until ") + GUIUtil::DateTimeStr(wtx->status.open_for);
         break;
     case TransactionStatus::Offline:
-        status = tr("%1/offline").arg(wtx->status.depth);
+        status = tr("Offline (%1)").arg(wtx->status.depth);
         break;
     case TransactionStatus::Unconfirmed:
-        status = tr("%1/unconfirmed").arg(wtx->status.depth);
+        status = tr("Unconfirmed (%1)").arg(wtx->status.depth);
         break;
     case TransactionStatus::HaveConfirmations:
-        status = tr("%1 confirmations").arg(wtx->status.depth);
+        status = tr("Confirmed (%1)").arg(wtx->status.depth);
         break;
     }
 
@@ -396,19 +400,51 @@ QVariant TransactionTableModel::formatTxCredit(const TransactionRecord *wtx) con
     }
 }
 
+QVariant TransactionTableModel::formatTxDecoration(const TransactionRecord *wtx) const
+{
+    switch(wtx->status.status)
+    {
+    case TransactionStatus::OpenUntilBlock:
+    case TransactionStatus::OpenUntilDate:
+        return QColor(64,64,255);
+        break;
+    case TransactionStatus::Offline:
+        return QColor(192,192,192);
+    case TransactionStatus::Unconfirmed:
+        if(wtx->status.depth)
+        {
+            return QColor(255,0,0);
+        }
+        else
+        {
+            return QColor(192,192,192);
+        }
+    case TransactionStatus::HaveConfirmations:
+        return QColor(0,255,0);
+    }
+    return QColor(0,0,0);
+}
+
 QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
 {
     if(!index.isValid())
         return QVariant();
     TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
 
-    if(role == Qt::DisplayRole)
+    if(role == Qt::DecorationRole)
+    {
+        if(index.column() == Status)
+        {
+            return formatTxDecoration(rec);
+        }
+    }
+    else if(role == Qt::DisplayRole)
     {
         /* Delegate to specific column handlers */
         switch(index.column())
         {
-        case Status:
-            return formatTxStatus(rec);
+        //case Status:
+        //    return formatTxStatus(rec);
         case Date:
             return formatTxDate(rec);
         case Description:
@@ -436,6 +472,13 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
             return rec->credit;
         }
     }
+    else if (role == Qt::ToolTipRole)
+    {
+        if(index.column() == Status)
+        {
+            return formatTxStatus(rec);
+        }
+    }
     else if (role == Qt::TextAlignmentRole)
     {
         return column_alignments[index.column()];
@@ -486,6 +529,21 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
         else if (role == Qt::TextAlignmentRole)
         {
             return column_alignments[section];
+        } else if (role == Qt::ToolTipRole)
+        {
+            switch(section)
+            {
+            case Status:
+                return tr("Transaction status. Hover over this field to show number of transactions.");
+            case Date:
+                return tr("Date and time that the transaction was received.");
+            case Description:
+                return tr("Short description of the transaction.");
+            case Debit:
+                return tr("Amount removed from balance.");
+            case Credit:
+                return tr("Amount added to balance.");
+            }
         }
     }
     return QVariant();