File indexing completed on 2024-04-14 04:01:05

0001 /*
0002     SPDX-FileCopyrightText: 2001-02 Nicolas Hadacek <hadacek@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KEXTHIGHSCORE_GUI_H
0008 #define KEXTHIGHSCORE_GUI_H
0009 
0010 #include <QCheckBox>
0011 #include <QDialog>
0012 #include <QDialogButtonBox>
0013 #include <QLineEdit>
0014 #include <QList>
0015 #include <QTreeWidget>
0016 
0017 #include <KPageDialog>
0018 
0019 #include "kexthighscore.h"
0020 
0021 class QTabWidget;
0022 class KUrlLabel;
0023 
0024 namespace KExtHighscore
0025 {
0026 
0027 class ItemContainer;
0028 class ItemArray;
0029 class Score;
0030 class AdditionalTab;
0031 
0032 //-----------------------------------------------------------------------------
0033 class ShowItem : public QTreeWidgetItem
0034 {
0035  public:
0036     ShowItem(QTreeWidget *, bool highlight);
0037 
0038  private:
0039     bool _highlight;
0040 };
0041 
0042 class ScoresList : public QTreeWidget
0043 {
0044  Q_OBJECT
0045  public:
0046     explicit ScoresList(QWidget *parent);
0047 
0048     void addHeader(const ItemArray &);
0049 
0050  protected:
0051     QTreeWidgetItem *addLine(const ItemArray &, uint index, bool highlight);
0052     virtual QString itemText(const ItemContainer &, uint row) const = 0;
0053 
0054  private:
0055     virtual void addLineItem(const ItemArray &, uint index,
0056                              QTreeWidgetItem *item);
0057 };
0058 
0059 //-----------------------------------------------------------------------------
0060 class HighscoresList : public ScoresList
0061 {
0062  Q_OBJECT
0063  public:
0064     explicit HighscoresList(QWidget *parent);
0065 
0066     void load(const ItemArray &, int highlight);
0067 
0068  protected:
0069     QString itemText(const ItemContainer &, uint row) const override;
0070 };
0071 
0072 class HighscoresWidget : public QWidget
0073 {
0074  Q_OBJECT
0075  public:
0076     explicit HighscoresWidget(QWidget *parent);
0077 
0078     void load(int rank);
0079 
0080  Q_SIGNALS:
0081     void tabChanged(int i);
0082 
0083  public Q_SLOTS:
0084     void changeTab(int i);
0085 
0086  private Q_SLOTS:
0087     void handleUrlClicked();
0088     void handleTabChanged() { Q_EMIT tabChanged(_tw->currentIndex()); }
0089 
0090  private:
0091     QTabWidget     *_tw = nullptr;
0092     HighscoresList *_scoresList = nullptr;
0093     HighscoresList *_playersList = nullptr;
0094     KUrlLabel      *_scoresUrl = nullptr;
0095     KUrlLabel *_playersUrl = nullptr;
0096     AdditionalTab  *_statsTab = nullptr;
0097     AdditionalTab *_histoTab = nullptr;
0098 };
0099 
0100 class HighscoresDialog : public KPageDialog
0101 {
0102  Q_OBJECT
0103  public:
0104     HighscoresDialog(int rank, QWidget *parent);
0105 
0106  private Q_SLOTS:
0107     void slotUser1();
0108     void slotUser2();
0109     void tabChanged(int i) { _tab = i; }
0110     void highscorePageChanged(KPageWidgetItem *newpage, KPageWidgetItem *before);
0111 
0112  private:
0113     int _rank, _tab;
0114     QWidget *_current = nullptr;
0115     QList<KPageWidgetItem*> _pages;
0116 };
0117 
0118 //-----------------------------------------------------------------------------
0119 class LastMultipleScoresList : public ScoresList
0120 {
0121     Q_OBJECT
0122 public:
0123     LastMultipleScoresList(const QList<Score> &, QWidget *parent);
0124 
0125 private:
0126     void addLineItem(const ItemArray &, uint index, QTreeWidgetItem *line) override;
0127     QString itemText(const ItemContainer &, uint row) const override;
0128 
0129 private:
0130     const QList<Score> &_scores;
0131 };
0132 
0133 class TotalMultipleScoresList : public ScoresList
0134 {
0135     Q_OBJECT
0136 public:
0137     TotalMultipleScoresList(const QList<Score> &, QWidget *parent);
0138 
0139 private:
0140     void addLineItem(const ItemArray &, uint index, QTreeWidgetItem *line) override;
0141     QString itemText(const ItemContainer &, uint row) const override;
0142 
0143 private:
0144     const QList<Score> &_scores;
0145 };
0146 
0147 //-----------------------------------------------------------------------------
0148 class ConfigDialog : public QDialog
0149 {
0150  Q_OBJECT
0151  public:
0152     explicit ConfigDialog(QWidget *parent);
0153 
0154     bool hasBeenSaved() const { return _saved; }
0155 
0156  private Q_SLOTS:
0157     void modifiedSlot();
0158     void removeSlot();
0159     void accept() override;
0160     void slotApply() { save(); }
0161     void nickNameChanged(const QString &);
0162 
0163  private:
0164     bool         _saved;
0165     QCheckBox   *_WWHEnabled = nullptr;
0166     QLineEdit   *_nickname = nullptr;
0167     QLineEdit *_comment = nullptr;
0168     QLineEdit   *_key = nullptr;
0169     QLineEdit *_registeredName = nullptr;
0170     QPushButton *_removeButton = nullptr;
0171     QDialogButtonBox *buttonBox = nullptr;
0172 
0173     void load();
0174     bool save();
0175 };
0176 
0177 //-----------------------------------------------------------------------------
0178 class AskNameDialog : public QDialog
0179 {
0180  Q_OBJECT
0181  public:
0182     explicit AskNameDialog(QWidget *parent);
0183 
0184     QString name() const { return _edit->text(); }
0185     bool dontAskAgain() const { return _checkbox->isChecked(); }
0186 
0187  private Q_SLOTS:
0188     void nameChanged();
0189 
0190  private:
0191     QDialogButtonBox *_buttonBox = nullptr;
0192     QLineEdit *_edit = nullptr;
0193     QCheckBox *_checkbox = nullptr;
0194 };
0195 
0196 } // namespace
0197 
0198 #endif