strawberry-audio-player-win.../src/settings/settingsdialog.h

167 lines
4.0 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:10:03 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H
#include "config.h"
2020-02-09 02:29:35 +01:00
#include <QObject>
2018-02-27 18:06:05 +01:00
#include <QDialog>
#include <QStyledItemDelegate>
2020-02-09 02:29:35 +01:00
#include <QStyleOptionViewItem>
#include <QStyleOption>
#include <QMap>
#include <QSize>
#include <QString>
#include <QSettings>
2018-02-27 18:06:05 +01:00
#include "core/shared_ptr.h"
2023-04-22 19:13:42 +02:00
#include "engine/enginebase.h"
2020-08-09 01:37:00 +02:00
#include "osd/osdbase.h"
2018-02-27 18:06:05 +01:00
2020-04-06 22:02:32 +02:00
class QMainWindow;
2020-02-09 02:29:35 +01:00
class QWidget;
class QModelIndex;
class QPainter;
class QTreeWidgetItem;
class QComboBox;
class QScrollArea;
class QAbstractButton;
class QShowEvent;
2020-04-06 22:02:32 +02:00
class QCloseEvent;
2018-02-27 18:06:05 +01:00
class Application;
class Player;
2018-02-27 18:06:05 +01:00
class CollectionDirectoryModel;
2021-01-26 19:13:29 +01:00
class GlobalShortcutsManager;
2018-02-27 18:06:05 +01:00
class SettingsPage;
class Ui_SettingsDialog;
2018-02-27 18:06:05 +01:00
class SettingsItemDelegate : public QStyledItemDelegate {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2020-04-07 16:49:15 +02:00
public:
explicit SettingsItemDelegate(QObject *parent);
2021-01-26 16:48:04 +01:00
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2018-02-27 18:06:05 +01:00
};
class SettingsDialog : public QDialog {
Q_OBJECT
public:
2020-08-09 01:37:00 +02:00
explicit SettingsDialog(Application *app, OSDBase *osd, QMainWindow *mainwindow, QWidget *parent = nullptr);
2020-06-15 21:55:05 +02:00
~SettingsDialog() override;
2018-02-27 18:06:05 +01:00
2023-02-18 14:09:27 +01:00
enum class Page {
Behaviour,
Collection,
Backend,
Playback,
Playlist,
Scrobbler,
Covers,
Lyrics,
Transcoding,
Proxy,
Appearance,
Context,
Notifications,
GlobalShortcuts,
Moodbar,
Subsonic,
Tidal,
Qobuz,
2022-06-04 15:51:35 +02:00
Spotify,
2018-02-27 18:06:05 +01:00
};
enum Role {
Role_IsSeparator = Qt::UserRole
};
2021-01-26 19:13:29 +01:00
void SetGlobalShortcutManager(GlobalShortcutsManager *manager) { manager_ = manager; }
2018-02-27 18:06:05 +01:00
bool is_loading_settings() const { return loading_settings_; }
Application *app() const { return app_; }
2020-08-09 01:37:00 +02:00
OSDBase *osd() const { return osd_; }
SharedPtr<Player> player() const { return player_; }
SharedPtr<EngineBase> engine() const { return engine_; }
2018-02-27 18:06:05 +01:00
CollectionDirectoryModel *collection_directory_model() const { return model_; }
2021-01-26 19:13:29 +01:00
GlobalShortcutsManager *global_shortcuts_manager() const { return manager_; }
2018-02-27 18:06:05 +01:00
void OpenAtPage(Page page);
2020-04-06 22:02:32 +02:00
protected:
2020-06-15 21:55:05 +02:00
void showEvent(QShowEvent *e) override;
void closeEvent(QCloseEvent*) override;
2018-02-27 18:06:05 +01:00
private:
2018-02-27 18:06:05 +01:00
struct PageData {
2021-06-20 23:53:28 +02:00
PageData() : item_(nullptr), scroll_area_(nullptr), page_(nullptr) {}
2018-02-27 18:06:05 +01:00
QTreeWidgetItem *item_;
QScrollArea *scroll_area_;
SettingsPage *page_;
};
2020-04-06 22:02:32 +02:00
// QDialog
2020-06-15 21:55:05 +02:00
void accept() override;
void reject() override;
2020-04-06 22:02:32 +02:00
void LoadGeometry();
void SaveGeometry();
2018-02-27 18:06:05 +01:00
QTreeWidgetItem *AddCategory(const QString &name);
2021-06-20 19:04:08 +02:00
void AddPage(const Page id, SettingsPage *page, QTreeWidgetItem *parent = nullptr);
2018-02-27 18:06:05 +01:00
void Apply();
2018-02-27 18:06:05 +01:00
void Save();
2020-04-06 22:02:32 +02:00
signals:
void ReloadSettings();
void NotificationPreview(const OSDBase::Behaviour, const QString&, const QString&);
2020-04-06 22:02:32 +02:00
private slots:
void CurrentItemChanged(QTreeWidgetItem *item);
void DialogButtonClicked(QAbstractButton *button);
private:
static const char *kSettingsGroup;
2020-04-06 22:02:32 +02:00
QMainWindow *mainwindow_;
2018-02-27 18:06:05 +01:00
Application *app_;
2020-08-09 01:37:00 +02:00
OSDBase *osd_;
SharedPtr<Player> player_;
SharedPtr<EngineBase> engine_;
2018-02-27 18:06:05 +01:00
CollectionDirectoryModel *model_;
2021-01-26 19:13:29 +01:00
GlobalShortcutsManager *manager_;
2018-02-27 18:06:05 +01:00
Ui_SettingsDialog *ui_;
bool loading_settings_;
QMap<Page, PageData> pages_;
};
#endif // SETTINGSDIALOG_H