strawberry-audio-player-win.../src/analyzer/analyzercontainer.h

115 lines
2.8 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/>.
*/
#ifndef ANALYZERCONTAINER_H
#define ANALYZERCONTAINER_H
#include "config.h"
2018-02-27 18:06:05 +01:00
#include <QWidget>
2019-02-04 21:34:12 +01:00
#include <QList>
#include <QString>
#include <QPoint>
2018-02-27 18:06:05 +01:00
#include <QMenu>
#include <QAction>
2020-07-18 03:54:52 +02:00
#include <QActionGroup>
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"
2018-02-27 18:06:05 +01:00
class QTimer;
class QMouseEvent;
class QWheelEvent;
2023-04-22 19:45:21 +02:00
class AnalyzerBase;
2018-02-27 18:06:05 +01:00
class AnalyzerContainer : public QWidget {
Q_OBJECT
public:
2020-06-15 21:55:05 +02:00
explicit AnalyzerContainer(QWidget *parent);
2018-02-27 18:06:05 +01:00
void SetEngine(SharedPtr<EngineBase> engine);
2018-02-27 18:06:05 +01:00
void SetActions(QAction *visualisation);
static const char *kSettingsGroup;
static const char *kSettingsFramerate;
2020-06-15 21:55:05 +02:00
signals:
void WheelEvent(const int delta);
2018-02-27 18:06:05 +01:00
protected:
2020-06-15 21:55:05 +02:00
void mouseReleaseEvent(QMouseEvent*) override;
void wheelEvent(QWheelEvent *e) override;
2018-02-27 18:06:05 +01:00
private slots:
2021-01-26 16:48:04 +01:00
void ChangeAnalyzer(const int id);
2018-02-27 18:06:05 +01:00
void ChangeFramerate(int new_framerate);
void DisableAnalyzer();
void ShowPopupMenu();
private:
static const int kLowFramerate;
static const int kMediumFramerate;
static const int kHighFramerate;
static const int kSuperHighFramerate;
void Load();
void Save();
2021-01-26 16:48:04 +01:00
void SaveFramerate(const int framerate);
2022-03-22 21:09:05 +01:00
template<typename T>
2018-02-27 18:06:05 +01:00
void AddAnalyzerType();
2021-06-12 20:53:23 +02:00
void AddFramerate(const QString &name, const int framerate);
2018-02-27 18:06:05 +01:00
private:
int current_framerate_; // fps
QMenu *context_menu_;
QMenu *context_menu_framerate_;
QActionGroup *group_;
QActionGroup *group_framerate_;
QList<const QMetaObject*> analyzer_types_;
QList<int> framerate_list_;
QList<QAction*> actions_;
QAction *disable_action_;
QTimer *double_click_timer_;
QPoint last_click_pos_;
bool ignore_next_click_;
2023-04-22 19:45:21 +02:00
AnalyzerBase *current_analyzer_;
SharedPtr<EngineBase> engine_;
2018-02-27 18:06:05 +01:00
};
2022-03-22 21:09:05 +01:00
template<typename T>
2018-02-27 18:06:05 +01:00
void AnalyzerContainer::AddAnalyzerType() {
2018-02-27 18:06:05 +01:00
int id = analyzer_types_.count();
analyzer_types_ << &T::staticMetaObject;
QAction *action = context_menu_->addAction(tr(T::kName));
2018-02-27 18:06:05 +01:00
group_->addAction(action);
action->setCheckable(true);
actions_ << action;
2021-01-26 16:48:04 +01:00
QObject::connect(action, &QAction::triggered, [this, id]() { ChangeAnalyzer(id); } );
2018-02-27 18:06:05 +01:00
}
2019-02-04 21:34:12 +01:00
#endif // ANALYZERCONTAINER_H