text: // Copyright (c) 2019 The PIVX developers
  // Distributed under the MIT software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #ifndef DASHBOARDWIDGET_H
  #define DASHBOARDWIDGET_H
  
  #include "qt/fls/pwidget.h"
  #include "qt/fls/furabstractlistitemdelegate.h"
  #include "qt/fls/furlistrow.h"
  #include "transactiontablemodel.h"
  #include "qt/fls/txviewholder.h"
  #include "transactionfilterproxy.h"
  
  #include <atomic>
  #include <cstdlib>
  #include <QWidget>
  #include <QLineEdit>
  #include <QMap>
  
  #if defined(HAVE_CONFIG_H)
  #include "config/flits-config.h" /* for USE_QTCHARTS */
  #endif
  
  #ifdef USE_QTCHARTS
  
  #include <QtCharts/QChartView>
  #include <QtCharts/QBarSeries>
  #include <QtCharts/QBarCategoryAxis>
  #include <QtCharts/QBarSet>
  #include <QtCharts/QChart>
  #include <QtCharts/QValueAxis>
  
  QT_CHARTS_USE_NAMESPACE
  
  using namespace QtCharts;
  
  #endif
  
  class FLSGUI;
  class WalletModel;
  
  namespace Ui {
  class DashboardWidget;
  }
  
  class SortEdit : public QLineEdit{
      Q_OBJECT
  public:
      explicit SortEdit(QWidget* parent = nullptr) : QLineEdit(parent){}
  
      inline void mousePressEvent(QMouseEvent *) override{
          Q_EMIT Mouse_Pressed();
      }
  
      ~SortEdit() override{}
  
  Q_SIGNALS:
      void Mouse_Pressed();
  
  };
  
  enum SortTx {
      DATE_ASC = 0,
      DATE_DESC = 1,
      AMOUNT_ASC = 2,
      AMOUNT_DESC = 3
  };
  
  enum ChartShowType {
      ALL,
      YEAR,
      MONTH,
      DAY
  };
  
  class ChartData {
  public:
      ChartData() {}
  
      QMap<int, std::pair<qint64, qint64>> amountsByCache;
      qreal maxValue = 0;
      qint64 totalFLS = 0;
      qint64 totalzFLS = 0;
      QList<qreal> valuesFLS;
      QList<qreal> valueszFLS;
      QStringList xLabels;
  };
  
  QT_BEGIN_NAMESPACE
  class QModelIndex;
  QT_END_NAMESPACE
  
  class DashboardWidget : public PWidget
  {
      Q_OBJECT
  
  public:
      explicit DashboardWidget(FLSGUI* _window);
      ~DashboardWidget();
  
      void loadWalletModel() override;
      void loadChart();
  
      void run(int type) override;
      void onError(QString error, int type) override;
  
  public Q_SLOTS:
      void walletSynced(bool isSync);
      /**
       * Show incoming transaction notification for new transactions.
       * The new items are those between start and end inclusive, under the given parent item.
      */
      void processNewTransaction(const QModelIndex& parent, int start, int /*end*/);
  Q_SIGNALS:
      /** Notify that a new transaction appeared */
      void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address);
  private Q_SLOTS:
      void handleTransactionClicked(const QModelIndex &index);
      void changeTheme(bool isLightTheme, QString &theme) override;
      void onSortChanged(const QString&);
      void onSortTypeChanged(const QString& value);
      void updateDisplayUnit();
      void showList();
      void onTxArrived(const QString& hash, const bool& isCoinStake, const bool& isCSAnyType);
  
  #ifdef USE_QTCHARTS
      void windowResizeEvent(QResizeEvent* event);
      void changeChartColors();
      void onChartYearChanged(const QString&);
      void onChartMonthChanged(const QString&);
      void onChartArrowClicked(bool goLeft);
  #endif
  
  private:
      Ui::DashboardWidget *ui;
      FurAbstractListItemDelegate* txViewDelegate;
      TransactionFilterProxy* filter;
      TxViewHolder* txHolder;
      TransactionTableModel* txModel;
      int nDisplayUnit = -1;
      bool isSync = false;
  
  #ifdef USE_QTCHARTS
  
      int64_t lastRefreshTime = 0;
      std::atomic<bool> isLoading;
  
      // Chart
      TransactionFilterProxy* stakesFilter = nullptr;
      bool isChartInitialized = false;
      QChartView *chartView = nullptr;
      QBarSeries *series = nullptr;
      QBarSet *set0 = nullptr;
      QBarSet *set1 = nullptr;
  
      QBarCategoryAxis *axisX = nullptr;
      QValueAxis *axisY = nullptr;
  
      QChart *chart = nullptr;
      bool isChartMin = false;
      ChartShowType chartShow = YEAR;
      int yearFilter = 0;
      int monthFilter = 0;
      int dayStart = 1;
      bool haszFLSStakes = false;
  
      ChartData* chartData = nullptr;
      bool hasStakes = false;
      bool fShowCharts = true;
  
      void initChart();
      void showHideEmptyChart(bool show, bool loading, bool forceView = false);
      bool refreshChart();
      void tryChartRefresh();
      void updateStakeFilter();
      const QMap<int, std::pair<qint64, qint64>> getAmountBy();
      bool loadChartData(bool withMonthNames);
      void updateAxisX(const QStringList *arg = nullptr);
      void setChartShow(ChartShowType type);
      std::pair<int, int> getChartRange(QMap<int, std::pair<qint64, qint64>> amountsBy);
  
  private Q_SLOTS:
      void onChartRefreshed();
      void onHideChartsChanged(bool fHide);
  
  #endif
  
  };
  
  #endif // DASHBOARDWIDGET_H
  