1 /*
2     SPDX-FileCopyrightText: 2009 Mathias Kraus <k.hias@gmx.de>
3     SPDX-FileCopyrightText: 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
4     SPDX-FileCopyrightText: 2007 Matt Williams <matt@milliams.com>
5 
6     SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #ifndef ARENASELECTOR_H
10 #define ARENASELECTOR_H
11 
12 #include <QWidget>
13 
14 class KConfigSkeleton;
15 class ArenaSelectorPrivate;
16 
17 /**
18  * \class ArenaSelector arenaselector.h <ArenaSelector>
19  *
20  * @short A widget used to select the game's arena
21  *
22  * The most common way to use the arena selector is to add it as page to a KConfigDialog
23  * \code
24  * KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
25  * dialog->addPage(new ArenaSelector(dialog, Settings::self()), i18n("Arena"), "game_arena");
26  * dialog->show();
27  * \endcode
28  * This will create a page in your KConfigDialog with the title "Arena" and using the
29  * "game_arena" icon. By default, the widget will search in the share/apps/appname/arenas
30  * directory for .desktop files with a group called "Arena".
31  *
32  * @author Mauricio Piacentini
33  **/
34 class ArenaSelector : public QWidget
35 {
36 Q_OBJECT
37 public:
38     ///Flags which control the behavior of ArenaSelector.
39     enum Option {
40         DefaultBehavior = 0,
41         ///Enable downloading of additional themes with KNewStuff3.
42         ///This requires a KNS3 config file to be installed for this app.
43         EnableNewStuffDownload = 1 << 0
44     };
45     Q_DECLARE_FLAGS(Options, Option)
46 
47     /**
48     * Load a specific arena file.
49     * @param parent the parent widget
50     * @param aconfig the KConfigSceleton
51     * @param randomArenaModeArenaList the arena mode list
52     * @param options the options
53     * @param groupName the title of the config group in the arena .desktop file
54     * @param directory subdirectory (of share/apps/appname) to search in
55     * @return true if the arena files and properties could be loaded
56     */
57     ArenaSelector(QWidget* parent, KConfigSkeleton* aconfig, QStringList* randomArenaModeArenaList, Options options = DefaultBehavior, const QString& groupName = QStringLiteral("Arena"), const QString& directory = QStringLiteral("arenas"));
58     ~ArenaSelector() override;
59 
60 protected:
61     /**
62     * Resizes the items when the view is resized.
63     * @param p_event the resize event
64     */
65     void resizeEvent(QResizeEvent* p_event) override;
66 
67     /**
68     * Resizes the items when the view is showed.
69     * @param p_event the resize event
70     */
71     void showEvent(QShowEvent* p_event) override;
72 
73 private:
74     class Private;
75     Private* const d;
76 
77     Q_DISABLE_COPY(ArenaSelector)
78 
79     Q_PRIVATE_SLOT(d, void _k_updatePreview(QListWidgetItem* currentItem = NULL))
80     Q_PRIVATE_SLOT(d, void _k_updateArenaList(const QString&))
81     Q_PRIVATE_SLOT(d, void _k_setRandomArenaMode(bool randomModeEnabled))
82     Q_PRIVATE_SLOT(d, void _k_updateRandomArenaModeArenaList(QListWidgetItem* item))
83 };
84 
85 #endif
86