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

165 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>
*
* 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
2020-02-09 02:29:35 +01:00
#include "engine/engine_fwd.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;
class Appearance;
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 {
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
enum Page {
Page_Behaviour,
Page_Collection,
Page_Backend,
Page_Playback,
Page_Playlist,
2020-05-08 20:25:02 +02:00
Page_Scrobbler,
2020-05-09 01:48:08 +02:00
Page_Covers,
Page_Lyrics,
2018-02-27 18:06:05 +01:00
Page_Transcoding,
Page_Proxy,
2020-05-08 20:25:02 +02:00
Page_Appearance,
Page_Context,
Page_Notifications,
Page_GlobalShortcuts,
2019-06-19 02:22:11 +02:00
Page_Moodbar,
2020-04-13 19:04:06 +02:00
Page_Subsonic,
Page_Tidal,
Page_Qobuz,
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_; }
Player *player() const { return player_; }
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
Appearance *appearance() const { return appearance_; }
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 {
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);
void AddPage(Page id, SettingsPage *page, QTreeWidgetItem *parent = nullptr);
void Apply();
2018-02-27 18:06:05 +01:00
void Save();
2020-04-06 22:02:32 +02:00
signals:
void ReloadSettings();
2020-08-09 01:37:00 +02:00
void NotificationPreview(OSDBase::Behaviour, QString, 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_;
Player *player_;
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
Appearance *appearance_;
Ui_SettingsDialog *ui_;
bool loading_settings_;
QMap<Page, PageData> pages_;
};
#endif // SETTINGSDIALOG_H