implement equalizer widget. access to legacy equalizer is now possible
This commit is contained in:
parent
47d8e323ab
commit
ac44b4efc6
6 changed files with 168 additions and 21 deletions
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "XMMSHandler.h"
|
||||
#include "xsettings.h"
|
||||
|
||||
#include "equalizerwidget.h"
|
||||
|
||||
|
@ -21,9 +22,34 @@
|
|||
#include "Button.h"
|
||||
#include "VolumeSlider.h"
|
||||
|
||||
|
||||
EqualizerSlider::EqualizerSlider (QWidget *parent, uint pix_min, uint pix_max,
|
||||
uint pix_on, uint pix_off, int min, int max,
|
||||
int id) :
|
||||
Slider (parent, pix_min, pix_max, pix_on,
|
||||
pix_off, min, max)
|
||||
{
|
||||
m_id = id;
|
||||
connect ( this, SIGNAL (valueChanged (int)),
|
||||
this, SLOT (on_self_value_changed (int)) );
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerSlider::on_self_value_changed (int value)
|
||||
{
|
||||
emit numberedValueChanged (value, m_id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* EqualizerWidget
|
||||
*/
|
||||
|
||||
EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent)
|
||||
{
|
||||
Skin *skin = Skin::getInstance ();
|
||||
XMMSHandler &client = XMMSHandler::getInstance ();
|
||||
m_xsettings = client.settings ();
|
||||
|
||||
connect (skin, SIGNAL(skinChanged(Skin *)),
|
||||
this, SLOT(setPixmaps(Skin *)));
|
||||
|
@ -31,9 +57,11 @@ EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent)
|
|||
m_enable = new ToggleButton(this, Skin::EQ_WIN_ON_0, Skin::EQ_WIN_ON_1,
|
||||
Skin::EQ_WIN_OFF_0, Skin::EQ_WIN_OFF_1);
|
||||
m_enable->move(14, 18);
|
||||
m_enable->setEnabled(false); // FIXME: needs to be implemented
|
||||
// must use signal clicked here, as this button also becomes unchecked if
|
||||
// use_legacy is deactivated
|
||||
connect(m_enable, SIGNAL (clicked (bool)),
|
||||
this, SLOT (setEqualizerEnabled (bool)));
|
||||
|
||||
connect(m_enable, SIGNAL(clicked()), parent, SLOT(setEnabled()));
|
||||
|
||||
m_auto = new ToggleButton(this, Skin::EQ_WIN_AUTO_ON_0, Skin::EQ_WIN_AUTO_ON_1,
|
||||
Skin::EQ_WIN_AUTO_OFF_0, Skin::EQ_WIN_AUTO_OFF_1);
|
||||
|
@ -49,13 +77,43 @@ EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent)
|
|||
connect(m_preset, SIGNAL(clicked()), parent, SLOT(setEnabled()));
|
||||
|
||||
m_preamp = new Slider(this, Skin::EQ_WIN_BAR_POS_0, Skin::EQ_WIN_BAR_POS_27,
|
||||
Skin::EQ_WIN_BAR_BTN_0, Skin::EQ_WIN_BAR_BTN_1, -20, 20);
|
||||
Skin::EQ_WIN_BAR_BTN_0, Skin::EQ_WIN_BAR_BTN_1,
|
||||
-20, 20);
|
||||
m_preamp->move(21, 38);
|
||||
connect (m_preamp, SIGNAL (valueChanged (int)),
|
||||
this, SLOT (updateServerPreamp (int)));
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
m_bands[i] = new Slider(this, Skin::EQ_WIN_BAR_POS_0, Skin::EQ_WIN_BAR_POS_27,
|
||||
Skin::EQ_WIN_BAR_BTN_0, Skin::EQ_WIN_BAR_BTN_1, -20, 20);
|
||||
m_bands[i] = new EqualizerSlider(this, Skin::EQ_WIN_BAR_POS_0,
|
||||
Skin::EQ_WIN_BAR_POS_27,
|
||||
Skin::EQ_WIN_BAR_BTN_0,
|
||||
Skin::EQ_WIN_BAR_BTN_1, -20, 20, i);
|
||||
m_bands[i]->move(78+i*18, 38);
|
||||
connect (m_bands[i], SIGNAL (numberedValueChanged (int, int)),
|
||||
this, SLOT (updateServerBands (int, int)));
|
||||
}
|
||||
|
||||
connect (m_xsettings, SIGNAL (configChanged (QString, QString)),
|
||||
this, SLOT (serverConfigChanged (QString, QString)));
|
||||
|
||||
// if the settings from the server were already loaded, we will only
|
||||
// receive configChanged signals for values that really change
|
||||
// so we must request the existing values manually
|
||||
if (m_xsettings->isReady()) {
|
||||
QString key;
|
||||
QString value;
|
||||
// set enabled checkbox
|
||||
key = QString ("equalizer.enabled");
|
||||
value = m_xsettings->value_get (key);
|
||||
serverConfigChanged (key, value);
|
||||
// set preamp
|
||||
|
||||
// Set band-sliders
|
||||
for (int i=0; i < 10; i++) {
|
||||
key = QString ("equalizer.legacy%1").arg(i);
|
||||
value = m_xsettings->value_get (key);
|
||||
serverConfigChanged (key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +133,7 @@ EqualizerWidget::setPixmaps (Skin *skin)
|
|||
update();
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
EqualizerWidget::paintEvent (QPaintEvent *event)
|
||||
{
|
||||
if (m_pixmap.isNull ()) {
|
||||
|
@ -85,10 +143,64 @@ EqualizerWidget::paintEvent (QPaintEvent *event)
|
|||
QRect r;
|
||||
|
||||
paint.begin(this);
|
||||
|
||||
|
||||
paint.drawPixmap(rect(), m_pixmap, m_pixmap.rect());
|
||||
r.setRect(86, 17, 113, 19);
|
||||
paint.drawPixmap(r, m_graph, m_graph.rect());
|
||||
|
||||
|
||||
paint.end();
|
||||
}
|
||||
|
||||
/*
|
||||
* These methods handle server configuration updates and
|
||||
* update the serverconfiguraten if we change something
|
||||
*/
|
||||
void
|
||||
EqualizerWidget::serverConfigChanged (QString key, QString value)
|
||||
{
|
||||
// qDebug (key.toAscii ());
|
||||
// qDebug (value.toAscii ());
|
||||
|
||||
// FIXME: also test on use_legacy
|
||||
if (key.startsWith ("equalizer.enabled")) {
|
||||
if (value != "0") {
|
||||
m_enable->setChecked (true);
|
||||
} else {
|
||||
m_enable->setChecked (false);
|
||||
}
|
||||
}
|
||||
if (key == "equalizer.preamp") {
|
||||
// FIXME: value can be of type floas
|
||||
// '-20' should not be necessary. seems to be a bug in slider
|
||||
m_preamp->setValue (value.toInt () -20);
|
||||
}
|
||||
if (key.startsWith ("equalizer.legacy")) {
|
||||
int i = key.right (1).toInt ();
|
||||
// FIXME: value can be float
|
||||
// '-20' should not be necessary. seems to be a bug in slider
|
||||
m_bands[i]->setValue (value.toInt () -20 );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWidget::setEqualizerEnabled (bool enabled) {
|
||||
if (enabled) {
|
||||
m_xsettings->value_set ("equalizer.enabled", "1");
|
||||
m_xsettings->value_set ("equalizer.use_legacy", "1");
|
||||
} else {
|
||||
m_xsettings->value_set ("equalizer.enabled", "0");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWidget::updateServerPreamp (int value)
|
||||
{
|
||||
m_xsettings->value_set ("equalizer.preamp", QString::number (value));
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWidget::updateServerBands (int value, int id)
|
||||
{
|
||||
QString key = QString ("equalizer.legacy%1").arg (id);
|
||||
m_xsettings->value_set (key, QString::number (value));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue