From 9b9cb68e14fa32317c66b4b7521023703a514c43 Mon Sep 17 00:00:00 2001
From: "littletux89@gmail.com" <littletux89@gmail.com>
Date: Mon, 8 Jul 2019 19:43:47 +0300
Subject: [PATCH] [*] Improved wallet design

---
 KelvinDashboardGUI/DapChainWalletsModel.cpp   |  10 +-
 KelvinDashboardGUI/DapChainWalletsModel.h     |   3 +-
 .../DapUiQmlScreenDialogSendToken.qml         |   2 +-
 .../DapUiQmlWidgetChainWallet.qml             |  26 +---
 .../DapUiQmlWidgetChainWalletForm.ui.qml      | 135 ++++++++++++++----
 libKelvinDashboardCommon/DapChainWallet.cpp   |   5 +
 libKelvinDashboardCommon/DapChainWallet.h     |   4 +
 7 files changed, 130 insertions(+), 55 deletions(-)

diff --git a/KelvinDashboardGUI/DapChainWalletsModel.cpp b/KelvinDashboardGUI/DapChainWalletsModel.cpp
index 1abadc1e0..8c348c790 100755
--- a/KelvinDashboardGUI/DapChainWalletsModel.cpp
+++ b/KelvinDashboardGUI/DapChainWalletsModel.cpp
@@ -26,6 +26,7 @@ QVariant DapChainWalletsModel::data(const QModelIndex &index, int role) const
             case AddressWalletRole: return m_dapChainWallets.at(index.row())->getAddress();
             case BalanceWalletRole: return m_dapChainWallets.at(index.row())->getBalance();
             case TokensWalletRole: return m_dapChainWallets.at(index.row())->getTokens();
+            case CountWalletRole: return m_dapChainWallets.at(index.row())->getCount();
             default:
                 return QVariant();
         }
@@ -39,7 +40,8 @@ QHash<int, QByteArray> DapChainWalletsModel::roleNames() const
             { NameWalletRole, "name" },
             { AddressWalletRole, "address" },
             { BalanceWalletRole, "balance" },
-            { TokensWalletRole, "tokens" }
+            { TokensWalletRole, "tokens" },
+            { CountWalletRole, "count" }
         };
 
     return roles;
@@ -48,10 +50,10 @@ QHash<int, QByteArray> DapChainWalletsModel::roleNames() const
 QVariantMap DapChainWalletsModel::get(int row) const
 {
     if (m_dapChainWallets.count() == 0) {
-        return { {"iconPath", ""}, {"name", ""}, {"address", ""}, {"balance", ""}, {"tokens", QStringList()} };
+        return { {"iconPath", ""}, {"name", ""}, {"address", ""}, {"balance", ""}, {"tokens", QStringList()}, {"count", 0} };
     }
     const DapChainWallet *wallet = m_dapChainWallets.value(row);
-    return { {"iconPath", wallet->getIconPath()}, {"name", wallet->getName()}, {"address", wallet->getAddress()}, {"balance", wallet->getBalance()}, {"tokens", wallet->getTokens()} };
+    return { {"iconPath", wallet->getIconPath()}, {"name", wallet->getName()}, {"address", wallet->getAddress()}, {"balance", wallet->getBalance()}, {"tokens", wallet->getTokens()}, {"count", wallet->getCount()} };
 }
 
 void DapChainWalletsModel::append(const DapChainWallet &arWallet)
@@ -80,7 +82,7 @@ void DapChainWalletsModel::set(int row, const QString& asIconPath, const QString
         wallet->setAddress(asAddresss);
         wallet->setBalance(aBalance);
         wallet->setTokens(aTokens);
-        dataChanged(index(row, 0), index(row, 0), { IconWalletRole, NameWalletRole, AddressWalletRole, BalanceWalletRole });
+        dataChanged(index(row, 0), index(row, 0), { IconWalletRole, NameWalletRole, AddressWalletRole, BalanceWalletRole, CountWalletRole });
 }
 
 void DapChainWalletsModel::remove(int row)
diff --git a/KelvinDashboardGUI/DapChainWalletsModel.h b/KelvinDashboardGUI/DapChainWalletsModel.h
index fe59c4ada..afcb2c57d 100755
--- a/KelvinDashboardGUI/DapChainWalletsModel.h
+++ b/KelvinDashboardGUI/DapChainWalletsModel.h
@@ -17,7 +17,8 @@ enum DapChainWalletRole {
         NameWalletRole = Qt::UserRole,
         AddressWalletRole,
         BalanceWalletRole,
-        TokensWalletRole
+        TokensWalletRole,
+        CountWalletRole
     };
 
 class DapChainWalletsModel : public QAbstractListModel
diff --git a/KelvinDashboardGUI/DapUiQmlScreenDialogSendToken.qml b/KelvinDashboardGUI/DapUiQmlScreenDialogSendToken.qml
index 960c3f397..1e410fb61 100755
--- a/KelvinDashboardGUI/DapUiQmlScreenDialogSendToken.qml
+++ b/KelvinDashboardGUI/DapUiQmlScreenDialogSendToken.qml
@@ -57,7 +57,7 @@ Dialog {
             delegate: ItemDelegate {
                 width: comboBoxToken.width
                 contentItem: Text {
-                    text: modelData
+                    text: token
                     font: comboBoxToken.font
                     elide: Text.ElideRight
                     verticalAlignment: Text.AlignVCenter
diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml
index 313d385df..a8f6c3ad2 100755
--- a/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml
+++ b/KelvinDashboardGUI/DapUiQmlWidgetChainWallet.qml
@@ -26,16 +26,15 @@ DapUiQmlWidgetChainWalletForm {
 
     listViewWallet.onCurrentItemChanged:
     {
-        listViewTokens.model = listViewWallet.model.get(listViewWallet.currentIndex).tokens
-        updateBalanceText();
+        listViewTokens.model.clear()
+        for(var i = 0; i < listViewWallet.model.get(listViewWallet.currentIndex).count; i++)
+        {
+            var value = listViewWallet.model.get(listViewWallet.currentIndex).balance[i]
+            listViewTokens.model.append({token: listViewWallet.model.get(listViewWallet.currentIndex).tokens[i], balance: value.replace(/[^\d.-]/g, '')});
+        }
+
         addressWallet.text = listViewWallet.model.get(listViewWallet.currentIndex).address
     }
-    
-    listViewTokens.onCurrentItemChanged:
-    {
-        updateBalanceText();
-        console.log(textBalance.text);
-    }
 
     buttonSaveWallet.onClicked: {
         dialogAddWallet.show()
@@ -43,15 +42,4 @@ DapUiQmlWidgetChainWalletForm {
     buttonSendToken.onClicked: {
         dialogSendToken.show()
     }
-
-    function updateBalanceText() {
-        var value = "";
-        if (listViewTokens.currentIndex > -1) {
-            value = listViewWallet.model.get(listViewWallet.currentIndex).balance[listViewTokens.currentIndex];
-        }
-        if (value)
-            textBalance.text = value.replace(/[^\d.-]/g, '');
-        else
-            textBalance.text = '';
-    }
 }
diff --git a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml
index 54b51460d..d779a0eef 100755
--- a/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml
+++ b/KelvinDashboardGUI/DapUiQmlWidgetChainWalletForm.ui.qml
@@ -14,7 +14,6 @@ Page {
     property alias dialogAddWallet: dialogAddWallet
     property alias dialogSendToken: dialogSendToken
     property alias addressWallet: addressWallet
-    property alias textBalance: textBalance
     property alias listViewTokens: listViewTokens
     property alias buttonSendToken: buttonSendToken
 
@@ -72,53 +71,129 @@ Page {
         anchors.top: parent.top
         anchors.bottom: parent.bottom
 
-        TextEdit {
-            id: addressWallet
-            font.pixelSize: 11
-            wrapMode: Text.Wrap
-            selectByMouse: true
-            color: "black"
-            selectionColor: "#008080"
-            clip: true
+        Row
+        {
+            id: rowAddress
             anchors.top: parent.top
-            anchors.horizontalCenter: parent.horizontalCenter
             anchors.left: parent.left
-            readOnly: true
+            anchors.right: parent.right
+            height: 100
+            width: parent.width
+            Rectangle
+            {
+                id: rectangleLableAddress
+                color: "green"
+                width: 150
+                height: parent.height
+                Text
+                {
+                    id: labelAddress
+                    anchors.centerIn: parent
+                    text: "Address"
+                    font.pixelSize: 22
+                    color: "white"
+                }
+            }
+            Column
+            {
+                id: columnAddress
+                width: rowAddress.width - rectangleLableAddress.width
+                height: parent.height
+                clip: true
+                TextEdit {
+                    id: addressWallet
+                    font.pixelSize: 16
+                    wrapMode: TextEdit.WrapAnywhere
+
+                    selectByMouse: true
+                    color: "#353841"
+                    selectionColor: "#353841"
+                    clip: true
+                    readOnly: true
+                    height: parent.height - rectangleBottomBorder.height
+                    width: parent.width
+                    verticalAlignment: TextEdit.AlignVCenter
+                    horizontalAlignment: TextEdit.AlignHCenter
+                }
+                Rectangle
+                {
+                    id: rectangleBottomBorder
+                    color: "green"
+                    height: 1
+                    width: columnAddress.width
+                }
+            }
         }
         
         ListView {
             id: listViewTokens
-            orientation: ListView.Vertical
-            anchors.top: addressWallet.bottom
+            height: 100
+            orientation: ListView.Horizontal
+            anchors.top: rowAddress.bottom
             anchors.left: parent.left
-            anchors.bottom: parent.bottom
-            width: parent.width*2/3
+            anchors.right: parent.right
             flickableDirection: Flickable.VerticalFlick
+            preferredHighlightBegin: parent.width/2-width/3/2;
+            preferredHighlightEnd: parent.width/2+width/3/2
+            highlightRangeMode: ListView.StrictlyEnforceRange
+            snapMode: ListView.SnapOneItem;
+            model: ListModel {
+                id: modelTokens
+            }
+
             delegate:  Item {
-                width: 200; height: 50
-                Text { id: nameField; text: modelData; color: listViewTokens.currentIndex === index ? 'green' : 'black'; }
+                id: delegateListViewTokens
+                width: listViewTokens.width/3; height: listViewTokens.height
+                Column
+                {
+                    id: itemRectangleIfoWallet
+                    anchors.centerIn: delegateListViewTokens
+                    Text {
+                        id: itemNameWallet;
+                        anchors.horizontalCenter: parent.horizontalCenter
+                        text: token;
+                        color: listViewTokens.currentIndex === index ? 'green' : "#BBBEBF";
+                        font.pixelSize: listViewTokens.currentIndex === index ? 40 : 30;
+                        font.family: "Roboto"
+                        font.weight: Font.Thin
+                    }
+                    Text {
+                        id: itemBalanceWallet;
+                        anchors.horizontalCenter: parent.horizontalCenter
+                        text: balance
+                        color: listViewTokens.currentIndex === index ? 'green' : "#BBBEBF";
+                        font.pixelSize: listViewTokens.currentIndex === index ? 40 : 30;
+                        font.family: "Roboto"
+                        font.weight: Font.Thin
+                    }
+                }
                 MouseArea {
                     anchors.fill: parent
                     onClicked: listViewTokens.currentIndex = index
                 }
             }
-            
+
             focus: true
+            clip: true
         }
-        
-        Text 
+
+        Rectangle
         {
-            id: textBalance
-            wrapMode: Text.NoWrap
-            textFormat: Text.PlainText
-            clip: false
-            anchors.top: addressWallet.bottom
-            anchors.left: listViewTokens.right
-            anchors.bottom: parent.bottom
+            id: rectangleHistory
+            anchors.top: listViewTokens.bottom
+            anchors.left: parent.left
             anchors.right: parent.right
-            
-            font.pixelSize: 30
-            font.bold: true
+            color: "green"
+            width: parent.width
+            height: 30
+            Text
+            {
+                id: labelHistory
+                anchors.centerIn: parent
+                text: "History"
+                font.pixelSize: 22
+                color: "white"
+            }
         }
     }
 
diff --git a/libKelvinDashboardCommon/DapChainWallet.cpp b/libKelvinDashboardCommon/DapChainWallet.cpp
index 1ef76c80b..d2b43c6f2 100755
--- a/libKelvinDashboardCommon/DapChainWallet.cpp
+++ b/libKelvinDashboardCommon/DapChainWallet.cpp
@@ -71,3 +71,8 @@ void DapChainWallet::setTokens(const QStringList &aTokens)
     
     emit tokensChanged(m_tokens);
 }
+
+int DapChainWallet::getCount() const
+{
+    return m_tokens.count();
+}
diff --git a/libKelvinDashboardCommon/DapChainWallet.h b/libKelvinDashboardCommon/DapChainWallet.h
index 1537b883d..062b86047 100755
--- a/libKelvinDashboardCommon/DapChainWallet.h
+++ b/libKelvinDashboardCommon/DapChainWallet.h
@@ -13,6 +13,7 @@ class DapChainWallet : public QObject
     QString m_sAddress;
     QStringList  m_balance;
     QStringList  m_tokens;
+    int m_iCount;
 
 public:
     DapChainWallet(QObject *parent = nullptr) { Q_UNUSED(parent)}
@@ -25,6 +26,7 @@ public:
     Q_PROPERTY(QString address MEMBER m_sAddress READ getAddress WRITE setAddress NOTIFY addressChanged)
     Q_PROPERTY(QStringList balance MEMBER m_balance READ getBalance WRITE setBalance NOTIFY balanceChanged)
     Q_PROPERTY(QStringList tokens MEMBER m_tokens READ getTokens WRITE setTokens NOTIFY tokensChanged)
+    Q_PROPERTY(int count MEMBER m_iCount READ getCount)
 
     QString getName() const;
     void setName(const QString &asName);
@@ -40,6 +42,8 @@ public:
     QStringList getTokens() const;
     void setTokens(const QStringList& aTokens);
 
+    int getCount() const;
+
 signals:
     void iconPathChanged(const QString& asIconPath);
     void nameChanged(const QString& asName);
-- 
GitLab