File indexing completed on 2022-09-27 13:16:03

0001 /*
0002     SPDX-FileCopyrightText: 2002 Nicolas Hadacek <hadacek@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KEXTHIGHSCORE_TAB_H
0008 #define KEXTHIGHSCORE_TAB_H
0009 
0010 #include <QtGlobal> // for QT_VERSION_CHECK
0011 // KF
0012 #include <ki18n_version.h>
0013 #include <KLazyLocalizedString>
0014 // Qt
0015 #include <QComboBox>
0016 #include <QVector>
0017 
0018 class QLabel;
0019 class QTreeWidget;
0020 
0021 
0022 namespace KExtHighscore
0023 {
0024 
0025 //-----------------------------------------------------------------------------
0026 class PlayersCombo : public QComboBox
0027 {
0028  Q_OBJECT
0029  public:
0030     explicit PlayersCombo(QWidget *parent = nullptr);
0031 
0032     void load();
0033 
0034  Q_SIGNALS:
0035     void playerSelected(uint i);
0036     void allSelected();
0037     void noneSelected();
0038 
0039  private Q_SLOTS:
0040     void activatedSlot(int i);
0041 };
0042 
0043 //-----------------------------------------------------------------------------
0044 class AdditionalTab : public QWidget
0045 {
0046  Q_OBJECT
0047  public:
0048     explicit AdditionalTab(QWidget *parent);
0049 
0050     virtual void load();
0051 
0052  private Q_SLOTS:
0053     void playerSelected(uint i) { display(i) ; }
0054     void allSelected();
0055 
0056  protected:
0057     void init();
0058     static QString percent(uint n, uint total, bool withBraces = false);
0059     virtual void display(uint i) = 0;
0060 
0061  private:
0062     PlayersCombo *_combo;
0063 };
0064 
0065 //-----------------------------------------------------------------------------
0066 class StatisticsTab : public AdditionalTab
0067 {
0068  Q_OBJECT
0069  public:
0070     explicit StatisticsTab(QWidget *parent);
0071 
0072     void load() override;
0073 
0074  private:
0075     enum Count { Total = 0, Won, Lost, Draw, Nb_Counts };
0076     static const KLazyLocalizedString COUNT_LABELS[Nb_Counts];
0077     enum Trend { CurrentTrend = 0, WonTrend, LostTrend, Nb_Trends };
0078     static const KLazyLocalizedString TREND_LABELS[Nb_Trends];
0079     struct Data {
0080         uint count[Nb_Counts];
0081         double trend[Nb_Trends];
0082     };
0083     QVector<Data> _data;
0084     QLabel *_nbs[Nb_Counts], *_percents[Nb_Counts], *_trends[Nb_Trends];
0085 
0086     QString percent(const Data &, Count) const;
0087     void display(uint i) override;
0088 };
0089 
0090 //-----------------------------------------------------------------------------
0091 class HistogramTab : public AdditionalTab
0092 {
0093  Q_OBJECT
0094  public:
0095     explicit HistogramTab(QWidget *parent);
0096 
0097     void load() override;
0098 
0099  private:
0100     QVector<uint> _counts;
0101     QVector<uint> _data;
0102     QTreeWidget   *_list;
0103 
0104     void display(uint i) override;
0105 };
0106 
0107 } // namespace
0108 
0109 #endif