parent
595877445b
commit
e1c44cdc77
@ -13,6 +13,7 @@ set(CLEMENTINE-SOURCES
|
||||
analyzers/analyzerbase.cpp
|
||||
fht.cpp
|
||||
analyzers/blockanalyzer.cpp
|
||||
analyzers/analyzercontainer.cpp
|
||||
sliderwidget.cpp
|
||||
playlistview.cpp
|
||||
librarywatcher.cpp
|
||||
@ -104,6 +105,10 @@ set(CLEMENTINE-MOC-HEADERS
|
||||
m3uparser.h
|
||||
playlistsequence.h
|
||||
xspfparser.h
|
||||
analyzers/analyzercontainer.h
|
||||
analyzers/baranalyzer.h
|
||||
analyzers/blockanalyzer.h
|
||||
analyzers/analyzerbase.h
|
||||
)
|
||||
|
||||
# UI files
|
||||
|
@ -36,14 +36,17 @@ typedef std::vector<float> Scope;
|
||||
|
||||
class Base : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
~Base() { delete m_fht; }
|
||||
|
||||
uint timeout() const { return m_timeout; }
|
||||
|
||||
void set_engine(EngineBase* engine) { m_engine = engine; }
|
||||
|
||||
protected:
|
||||
Base( QWidget*, uint timeout, uint scopeSize = 7 );
|
||||
~Base() { delete m_fht; }
|
||||
|
||||
void hideEvent(QHideEvent *);
|
||||
void showEvent(QShowEvent *);
|
||||
|
91
src/analyzers/analyzercontainer.cpp
Normal file
91
src/analyzers/analyzercontainer.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "analyzercontainer.h"
|
||||
#include "baranalyzer.h"
|
||||
#include "blockanalyzer.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSettings>
|
||||
|
||||
const char* AnalyzerContainer::kSettingsGroup = "Analyzer";
|
||||
|
||||
AnalyzerContainer::AnalyzerContainer(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
context_menu_(new QMenu(this)),
|
||||
group_(new QActionGroup(this)),
|
||||
mapper_(new QSignalMapper(this)),
|
||||
current_analyzer_(NULL),
|
||||
engine_(NULL)
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
setLayout(layout);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
AddAnalyzerType<BarAnalyzer>();
|
||||
AddAnalyzerType<BlockAnalyzer>();
|
||||
connect(mapper_, SIGNAL(mapped(int)), SLOT(ChangeAnalyzer(int)));
|
||||
|
||||
context_menu_->addSeparator();
|
||||
|
||||
disable_action_ =
|
||||
context_menu_->addAction(tr("No analyzer"), this, SLOT(DisableAnalyzer()));
|
||||
disable_action_->setCheckable(true);
|
||||
group_->addAction(disable_action_);
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
void AnalyzerContainer::contextMenuEvent(QContextMenuEvent* e) {
|
||||
context_menu_->popup(e->globalPos());
|
||||
}
|
||||
|
||||
void AnalyzerContainer::set_engine(EngineBase *engine) {
|
||||
if (current_analyzer_)
|
||||
current_analyzer_->set_engine(engine);
|
||||
engine_ = engine;
|
||||
}
|
||||
|
||||
void AnalyzerContainer::DisableAnalyzer() {
|
||||
delete current_analyzer_;
|
||||
current_analyzer_ = NULL;
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
void AnalyzerContainer::ChangeAnalyzer(int id) {
|
||||
delete current_analyzer_;
|
||||
current_analyzer_ = qobject_cast<Analyzer::Base*>(
|
||||
analyzer_types_[id]->newInstance(Q_ARG(QWidget*, this)));
|
||||
current_analyzer_->set_engine(engine_);
|
||||
|
||||
layout()->addWidget(current_analyzer_);
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
void AnalyzerContainer::Load() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
QString type = s.value("type", "BlockAnalyzer").toString();
|
||||
if (type.isEmpty()) {
|
||||
DisableAnalyzer();
|
||||
disable_action_->setChecked(true);
|
||||
} else {
|
||||
for (int i=0 ; i<analyzer_types_.count() ; ++i) {
|
||||
if (type == analyzer_types_[i]->className()) {
|
||||
ChangeAnalyzer(i);
|
||||
actions_[i]->setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnalyzerContainer::Save() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
s.setValue("type", current_analyzer_ ?
|
||||
current_analyzer_->metaObject()->className() :
|
||||
QVariant());
|
||||
}
|
60
src/analyzers/analyzercontainer.h
Normal file
60
src/analyzers/analyzercontainer.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef ANALYZERCONTAINER_H
|
||||
#define ANALYZERCONTAINER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMenu>
|
||||
#include <QSignalMapper>
|
||||
|
||||
#include "analyzerbase.h"
|
||||
#include "engine_fwd.h"
|
||||
|
||||
class AnalyzerContainer : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AnalyzerContainer(QWidget* parent);
|
||||
|
||||
void set_engine(EngineBase* engine);
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *);
|
||||
|
||||
private slots:
|
||||
void ChangeAnalyzer(int id);
|
||||
void DisableAnalyzer();
|
||||
|
||||
private:
|
||||
void Load();
|
||||
void Save();
|
||||
template <typename T>
|
||||
void AddAnalyzerType();
|
||||
|
||||
private:
|
||||
QMenu* context_menu_;
|
||||
QActionGroup* group_;
|
||||
QSignalMapper* mapper_;
|
||||
|
||||
QList<const QMetaObject*> analyzer_types_;
|
||||
QList<QAction*> actions_;
|
||||
QAction* disable_action_;
|
||||
|
||||
Analyzer::Base* current_analyzer_;
|
||||
EngineBase* engine_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void AnalyzerContainer::AddAnalyzerType() {
|
||||
int id = analyzer_types_.count();
|
||||
analyzer_types_ << &T::staticMetaObject;
|
||||
|
||||
QAction* action = context_menu_->addAction(tr(T::kName), mapper_, SLOT(map()));
|
||||
group_->addAction(action);
|
||||
mapper_->setMapping(action, id);
|
||||
action->setCheckable(true);
|
||||
actions_ << action;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <QtDebug>
|
||||
#include <QPainter>
|
||||
|
||||
const char* BarAnalyzer::kName = QT_TR_NOOP("Bar analyzer");
|
||||
|
||||
|
||||
BarAnalyzer::BarAnalyzer( QWidget *parent )
|
||||
: Analyzer::Base( parent, 12, 8 )
|
||||
|
@ -13,8 +13,9 @@ typedef std::vector<uint> aroofMemVec;
|
||||
|
||||
class BarAnalyzer : public Analyzer::Base
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BarAnalyzer( QWidget* );
|
||||
Q_INVOKABLE BarAnalyzer( QWidget* );
|
||||
|
||||
void init();
|
||||
virtual void analyze( QPainter& p, const Scope& );
|
||||
@ -34,6 +35,8 @@ class BarAnalyzer : public Analyzer::Base
|
||||
static const uint NUM_ROOFS = 16;
|
||||
static const uint COLUMN_WIDTH = 4;
|
||||
|
||||
static const char* kName;
|
||||
|
||||
protected:
|
||||
QPixmap m_pixRoof[NUM_ROOFS];
|
||||
//vector<uint> m_roofMem[BAND_COUNT];
|
||||
|
@ -21,6 +21,8 @@ const uint BlockAnalyzer::MIN_COLUMNS = 32; //arbituary
|
||||
const uint BlockAnalyzer::MAX_COLUMNS = 256; //must be 2**n
|
||||
const uint BlockAnalyzer::FADE_SIZE = 90;
|
||||
|
||||
const char* BlockAnalyzer::kName = QT_TR_NOOP("Block analyzer");
|
||||
|
||||
BlockAnalyzer::BlockAnalyzer( QWidget *parent )
|
||||
: Analyzer::Base( parent, 20, 9 )
|
||||
, m_columns( 0 ) //uint
|
||||
|
@ -19,8 +19,9 @@ class QPalette;
|
||||
|
||||
class BlockAnalyzer : public Analyzer::Base
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BlockAnalyzer( QWidget* );
|
||||
Q_INVOKABLE BlockAnalyzer( QWidget* );
|
||||
~BlockAnalyzer();
|
||||
|
||||
static const uint HEIGHT;
|
||||
@ -30,6 +31,8 @@ public:
|
||||
static const uint MAX_COLUMNS;
|
||||
static const uint FADE_SIZE;
|
||||
|
||||
static const char* kName;
|
||||
|
||||
protected:
|
||||
virtual void transform( Scope& );
|
||||
virtual void analyze( QPainter& p, const Scope& );
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <QCloseEvent>
|
||||
#include <QSignalMapper>
|
||||
#include <QFileDialog>
|
||||
#include <QTimer>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -215,7 +215,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlockAnalyzer" name="analyzer" native="true">
|
||||
<widget class="AnalyzerContainer" name="analyzer" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>100</horstretch>
|
||||
@ -747,12 +747,6 @@
|
||||
<extends>QLineEdit</extends>
|
||||
<header>lineedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlockAnalyzer</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>analyzers/blockanalyzer.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Amarok::VolumeSlider</class>
|
||||
<extends>QSlider</extends>
|
||||
@ -779,6 +773,12 @@
|
||||
<extends>QTreeView</extends>
|
||||
<header>radioview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AnalyzerContainer</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>analyzers/analyzercontainer.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../data/data.qrc"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user