2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2022-08-20 14:51:19 +02:00
|
|
|
* Copyright 2019-2022, 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:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COLLECTIONFILTERWIDGET_H
|
|
|
|
#define COLLECTIONFILTERWIDGET_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <QWidget>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
2021-07-12 08:28:52 +02:00
|
|
|
#include <QHash>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QString>
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "collectionmodel.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
|
2019-07-08 22:27:45 +02:00
|
|
|
class QTimer;
|
|
|
|
class QMenu;
|
|
|
|
class QAction;
|
|
|
|
class QActionGroup;
|
2018-05-01 00:41:33 +02:00
|
|
|
class QKeyEvent;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class GroupByDialog;
|
2018-05-01 00:41:33 +02:00
|
|
|
class SavedGroupingManager;
|
2018-02-27 18:06:05 +01:00
|
|
|
class Ui_CollectionFilterWidget;
|
|
|
|
|
|
|
|
class CollectionFilterWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit CollectionFilterWidget(QWidget *parent = nullptr);
|
2020-06-15 21:55:05 +02:00
|
|
|
~CollectionFilterWidget() override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
static const int kFilterDelay = 500; // msec
|
|
|
|
|
2023-02-18 14:09:27 +01:00
|
|
|
enum class DelayBehaviour {
|
2018-02-27 18:06:05 +01:00
|
|
|
AlwaysInstant,
|
|
|
|
DelayedOnLargeLibraries,
|
|
|
|
AlwaysDelayed,
|
|
|
|
};
|
|
|
|
|
2021-06-28 00:14:16 +02:00
|
|
|
void Init(CollectionModel *model);
|
|
|
|
|
2022-08-20 14:51:19 +02:00
|
|
|
static QActionGroup *CreateGroupByActions(const QString &saved_groupings_settings_group, QObject *parent);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void SetFilterHint(const QString &hint);
|
|
|
|
void SetApplyFilterToCollection(bool filter_applies_to_model) { filter_applies_to_model_ = filter_applies_to_model; }
|
|
|
|
void SetDelayBehaviour(DelayBehaviour behaviour) { delay_behaviour_ = behaviour; }
|
|
|
|
void SetAgeFilterEnabled(bool enabled);
|
|
|
|
void SetGroupByEnabled(bool enabled);
|
|
|
|
void ShowInCollection(const QString &search);
|
|
|
|
|
|
|
|
QMenu *menu() const { return collection_menu_; }
|
|
|
|
void AddMenuAction(QAction *action);
|
|
|
|
|
2022-08-20 14:51:19 +02:00
|
|
|
void SetSettingsGroup(const QString &group);
|
|
|
|
void SetSettingsPrefix(const QString &prefix);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2022-08-20 14:51:19 +02:00
|
|
|
QString group_by_version() const;
|
|
|
|
QString group_by_key() const;
|
|
|
|
QString group_by_key(const int number) const;
|
|
|
|
QString separate_albums_by_grouping_key() const;
|
2019-06-08 00:15:54 +02:00
|
|
|
|
2020-06-28 18:36:48 +02:00
|
|
|
void ReloadSettings();
|
|
|
|
|
2021-09-27 21:42:30 +02:00
|
|
|
bool SearchFieldHasFocus() const;
|
|
|
|
void FocusSearchField();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
public slots:
|
2022-08-20 14:51:19 +02:00
|
|
|
void UpdateGroupByActions();
|
2023-01-08 15:40:54 +01:00
|
|
|
void SetFilterMode(CollectionFilterOptions::FilterMode filter_mode);
|
2018-02-27 18:06:05 +01:00
|
|
|
void FocusOnFilter(QKeyEvent *e);
|
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
signals:
|
2018-02-27 18:06:05 +01:00
|
|
|
void UpPressed();
|
|
|
|
void DownPressed();
|
|
|
|
void ReturnPressed();
|
2023-04-09 20:23:42 +02:00
|
|
|
void Filter(const QString &text);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
protected:
|
2020-06-15 21:55:05 +02:00
|
|
|
void keyReleaseEvent(QKeyEvent *e) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private slots:
|
2022-08-20 14:51:19 +02:00
|
|
|
void GroupingChanged(const CollectionModel::Grouping g, const bool separate_albums_by_grouping);
|
2018-02-27 18:06:05 +01:00
|
|
|
void GroupByClicked(QAction *action);
|
|
|
|
void SaveGroupBy();
|
|
|
|
void ShowGroupingManager();
|
|
|
|
|
|
|
|
void FilterTextChanged(const QString &text);
|
|
|
|
void FilterDelayTimeout();
|
|
|
|
|
|
|
|
private:
|
2021-06-20 19:04:08 +02:00
|
|
|
static QAction *CreateGroupByAction(const QString &text, QObject *parent, const CollectionModel::Grouping grouping);
|
2021-06-21 19:54:42 +02:00
|
|
|
void CheckCurrentGrouping(const CollectionModel::Grouping g);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Ui_CollectionFilterWidget *ui_;
|
|
|
|
CollectionModel *model_;
|
|
|
|
|
2022-08-20 14:51:19 +02:00
|
|
|
GroupByDialog *group_by_dialog_;
|
|
|
|
SavedGroupingManager *groupings_manager_;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QMenu *filter_age_menu_;
|
|
|
|
QMenu *group_by_menu_;
|
|
|
|
QMenu *collection_menu_;
|
|
|
|
QActionGroup *group_by_group_;
|
2021-07-12 08:28:52 +02:00
|
|
|
QHash<QAction*, int> filter_ages_;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QTimer *filter_delay_;
|
|
|
|
|
|
|
|
bool filter_applies_to_model_;
|
|
|
|
DelayBehaviour delay_behaviour_;
|
|
|
|
|
|
|
|
QString settings_group_;
|
2022-08-20 14:51:19 +02:00
|
|
|
QString saved_groupings_settings_group_;
|
2019-06-08 00:15:54 +02:00
|
|
|
QString settings_prefix_;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COLLECTIONFILTERWIDGET_H
|
|
|
|
|