From 78431b493f273b35c2509df0c6b1e5754959b83f Mon Sep 17 00:00:00 2001
From: jonymt <johanmt@yandex.ru>
Date: Thu, 29 Aug 2019 17:03:28 +0200
Subject: [PATCH] [+] added last actions widget

---
 KelvinDashboardGUI/DapScreenHistoryModel.cpp  |  17 ++
 KelvinDashboardGUI/DapScreenHistoryModel.h    |   2 +
 .../DapUiQmlScreenDashboard.qml               |   2 +
 KelvinDashboardGUI/DapUiQmlScreenDialog.qml   |   2 +
 .../DapUiQmlWidgetLastActions.qml             | 145 ++++++++++++++++++
 KelvinDashboardGUI/main.cpp                   |   2 +-
 KelvinDashboardGUI/qml.qrc                    |   3 +-
 7 files changed, 171 insertions(+), 2 deletions(-)
 create mode 100644 KelvinDashboardGUI/DapUiQmlWidgetLastActions.qml

diff --git a/KelvinDashboardGUI/DapScreenHistoryModel.cpp b/KelvinDashboardGUI/DapScreenHistoryModel.cpp
index 24656d6ef..868349982 100644
--- a/KelvinDashboardGUI/DapScreenHistoryModel.cpp
+++ b/KelvinDashboardGUI/DapScreenHistoryModel.cpp
@@ -26,6 +26,22 @@ QHash<int, QByteArray> DapScreenHistoryModel::roleNames() const
     return names;
 }
 
+QString DapScreenHistoryModel::toConvertCurrency(const QString& aMoney) const
+{
+    QString money;
+
+    QStringList major = aMoney.split(".");
+    if(!major.isEmpty()) money = major.at(0);
+    else money = aMoney;
+
+    for (int i = money.size() - 3; i >= 1; i -= 3)
+        money.insert(i, ' ');
+
+    if(major.count() > 1) money.append("." + major.at(1));
+
+    return money;
+}
+
 void DapScreenHistoryModel::receiveNewData(const QVariant& aData)
 {
     if(!aData.isValid()) return;
@@ -59,6 +75,7 @@ void DapScreenHistoryModel::receiveNewData(const QVariant& aData)
             default: break;
         }
 
+        item.Cryptocurrency = toConvertCurrency(item.Cryptocurrency);
         item.Cryptocurrency += " " + item.TokenName;
 
         m_elementList.append(item);
diff --git a/KelvinDashboardGUI/DapScreenHistoryModel.h b/KelvinDashboardGUI/DapScreenHistoryModel.h
index 4314fe2fb..b08ce517d 100644
--- a/KelvinDashboardGUI/DapScreenHistoryModel.h
+++ b/KelvinDashboardGUI/DapScreenHistoryModel.h
@@ -55,6 +55,8 @@ public:
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
     QHash<int, QByteArray> roleNames() const override;
 
+    Q_INVOKABLE QString toConvertCurrency(const QString& aMoney) const;
+
 public slots:
     void receiveNewData(const QVariant& aData);
 };
diff --git a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml
index ad42c4374..0c58bdff8 100755
--- a/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml
+++ b/KelvinDashboardGUI/DapUiQmlScreenDashboard.qml
@@ -178,5 +178,7 @@ Page {
             source: "DapUiQmlScreenDialog.qml"
         }
     }
+
+
 }
 
diff --git a/KelvinDashboardGUI/DapUiQmlScreenDialog.qml b/KelvinDashboardGUI/DapUiQmlScreenDialog.qml
index 98b903eb1..1b98ea59d 100644
--- a/KelvinDashboardGUI/DapUiQmlScreenDialog.qml
+++ b/KelvinDashboardGUI/DapUiQmlScreenDialog.qml
@@ -57,4 +57,6 @@ Page {
                        listViewDapWidgets.addWidget()
                    }
        }
+
+    DapUiQmlWidgetLastActions {}
 }
diff --git a/KelvinDashboardGUI/DapUiQmlWidgetLastActions.qml b/KelvinDashboardGUI/DapUiQmlWidgetLastActions.qml
new file mode 100644
index 000000000..87da7be00
--- /dev/null
+++ b/KelvinDashboardGUI/DapUiQmlWidgetLastActions.qml
@@ -0,0 +1,145 @@
+import QtQuick 2.9
+import QtQml 2.12
+import QtQuick.Controls 2.2
+import QtQuick.Layouts 1.12
+
+import DapTransactionHistory 1.0
+
+Rectangle {
+    width: 400 * pt
+    border.color: "#B5B5B5"
+    border.width: 1 * pt
+    color: "#EDEFF2"
+
+    anchors {
+        top: parent.top
+        right: parent.right
+        bottom: parent.bottom
+    }
+
+    Rectangle {
+        id: dapHeader
+        width: parent.width
+        height: 36 * pt
+        color: "#EDEFF2"
+
+        Item {
+            width: childrenRect.width
+            height: childrenRect.height
+            anchors.top: parent.top
+            anchors.left: parent.left
+
+            anchors.leftMargin: 16 * pt
+            anchors.topMargin: 13
+
+            Text {
+                text: qsTr("Last actions")
+                font.family: "Roboto"
+                font.pixelSize: 12 * pt
+                color: "#5F5F63"
+            }
+        }
+    }
+
+    ListView {
+        id: dapListView
+        anchors.top: dapHeader.bottom
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.bottom: parent.bottom
+        clip: true
+
+        model: dapHistoryModel
+        delegate: dapDelegate
+        section.property: "date"
+        section.criteria: ViewSection.FullString
+        section.delegate: dapDate
+
+        Component {
+            id: dapDate
+            Rectangle {
+                width:  dapListView.width
+                height: 30 * pt
+                color: "#C2CAD1"
+
+                Text {
+                    anchors.fill: parent
+                    verticalAlignment: Qt.AlignVCenter
+                    horizontalAlignment: Qt.AlignLeft
+                    color: "#797979"
+                    text: section
+                    font.family: "Roboto"
+                    font.pixelSize: 12 * pt
+                    leftPadding: 16 * pt
+                }
+            }
+        }
+
+        Component {
+            id: dapDelegate
+
+            Rectangle {
+                id: dapContentDelegate
+                width: parent.width
+                height: 50 * pt
+                color: "transparent"
+
+                border.color: "#C2CAD1"
+                border.width: 1 * pt
+
+                Rectangle {
+                    id: dapData
+                    width: childrenRect.width
+                    height: childrenRect.height
+                    Layout.alignment: Qt.AlignVCenter
+                    anchors.left: dapContentDelegate.left
+                    anchors.leftMargin: 16 * pt
+                    anchors.top: parent.top
+                    anchors.topMargin: 13
+
+                    Column {
+                        anchors.fill: parent
+                        spacing: 2
+
+                        Text {
+                            text: tokenName
+                            color: "#5F5F63"
+                            font.family: "Roboto Regular"
+                            font.pixelSize: 14 * pt
+                        }
+
+                        Text {
+                            text: txStatus
+                            color: "#A7A7A7"
+                            font.family: "Roboto"
+                            font.pixelSize: 12 * pt
+                        }
+                    }
+                }
+
+                Text {
+                    anchors.left: dapData.right
+                    anchors.top: parent.top
+                    anchors.right: parent.right
+                    anchors.bottom: parent.bottom
+                    anchors.rightMargin: 20 * pt
+
+                    horizontalAlignment: Qt.AlignRight
+                    verticalAlignment: Qt.AlignVCenter
+                    color: "#505559"
+                    text: cryptocurrency;
+                    font.family: "Roboto"
+                    font.pixelSize: 14 * pt
+                }
+
+                Rectangle {
+                    width: parent.width
+                    height: 1 * pt
+                    color: "#C7C9CC"
+                    anchors.bottom: parent.bottom
+                }
+            }
+        }
+
+    }
+}
diff --git a/KelvinDashboardGUI/main.cpp b/KelvinDashboardGUI/main.cpp
index 0239d20a4..93b34e115 100755
--- a/KelvinDashboardGUI/main.cpp
+++ b/KelvinDashboardGUI/main.cpp
@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
 //    set.setGroupPropertyValue("widgets", "name", "Services client", "visible", f);
 //    qDebug() << set.getGroupPropertyValue("widgets", "name", "Services client", "visible").toBool();
 //    qDebug() << set.getKeyValue("user");
-    
+
     if (engine.rootObjects().isEmpty())
         return -1;
     
diff --git a/KelvinDashboardGUI/qml.qrc b/KelvinDashboardGUI/qml.qrc
index a3f93cb2c..ab19a4667 100755
--- a/KelvinDashboardGUI/qml.qrc
+++ b/KelvinDashboardGUI/qml.qrc
@@ -28,6 +28,7 @@
         <file>DapUiQmlWidgetConsole.qml</file>
         <file>DapUiQmlWidgetNodeNetworkExplorer.qml</file>
         <file>DapUiQmlScreenHistory.qml</file>
-<file>Resources/Icons/defaul_icon.png</file>
+        <file>Resources/Icons/defaul_icon.png</file>
+        <file>DapUiQmlWidgetLastActions.qml</file>
     </qresource>
 </RCC>
-- 
GitLab