/***************************************************************************
* Copyright (C) 2011-2016 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <QGridLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSlider>
#include <QCheckBox>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QPainter>
#include <QDialogButtonBox>
#include <QSettings>
#include <QMessageBox>
#include <QDir>
#include <qmmp/qmmpsettings.h>
#include "equalizer.h"
Equalizer::Equalizer(QWidget *parent) : QDialog(parent)
{
setWindowTitle(tr("Equalizer"));
m_layout = new QVBoxLayout(this);
setLayout(m_layout);
m_layout->setSpacing(5);
m_layout->setMargin(5);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->setSpacing(5);
m_enabled = new QCheckBox(tr("Enable equalizer"), this);
buttonsLayout->addWidget(m_enabled);
buttonsLayout->addSpacerItem(new QSpacerItem(30, 0, QSizePolicy::Fixed, QSizePolicy::Fixed));
QLabel *label = new QLabel(this);
label->setText(tr("Preset:"));
buttonsLayout->addWidget(label);
m_presetComboBox = new QComboBox(this);
m_presetComboBox->setEditable(true);
connect(m_presetComboBox, SIGNAL(activated(int)), SLOT(loadPreset(int)));
buttonsLayout->addWidget(m_presetComboBox);
QPushButton *saveButton = new QPushButton(tr("Save"), this);
connect(saveButton, SIGNAL(pressed()), SLOT(savePreset()));
buttonsLayout->addWidget(saveButton);
QPushButton *deleteButton = new QPushButton(tr("Delete"), this);
connect(deleteButton, SIGNAL(pressed()), SLOT(deletePreset()));
buttonsLayout->addWidget(deleteButton);
QPushButton *reset = new QPushButton(tr("Reset"), this);
connect(reset, SIGNAL(clicked()), SLOT(resetSettings()));
buttonsLayout->addWidget(reset);
QDialogButtonBox *dialogButtons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
dialogButtons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
connect(dialogButtons, SIGNAL(rejected()), SLOT(reject()));
buttonsLayout->addWidget(dialogButtons);
QGridLayout *slidersLayout = new QGridLayout;
slidersLayout->setSpacing(5);
QStringList names;
names << tr("Preamp") << "25" << "40" << "63" << "100" << "160" << "250"
<< "400" << "630" << "1k" << "1,6k" << "2,5k"
<< "4k" << "6,3k" << "10k" << "16k";
for(int i = 0; i < 16; ++i)
{
QSlider *slider = new QSlider(this);
slider->setRange(-20, 20);
slider->setTickPosition(QSlider::TicksLeft);
slider->setTickInterval(10);
QLabel *label = new QLabel(this);
label->setFrameShape(QFrame::Box);
label->setText(names.at(i));
slidersLayout->addWidget(slider, 1, i, Qt::AlignHCenter);
slidersLayout->addWidget(label, 2, i, Qt::AlignHCenter);
QLabel *label2 = new QLabel(this);
label2->setText(tr("%1dB").arg(0));
label2->setFrameShape(QFrame::Box);
label2->setMinimumWidth(fontMetrics().width(tr("+%1dB").arg(20) + 5));
label2->setAlignment(Qt::AlignCenter);
slidersLayout->addWidget(label2, 0, i, Qt::AlignHCenter);
connect(slider, SIGNAL(valueChanged(int)), SLOT(updateLabel()));
m_sliders << slider;
m_labels << label2;
}
m_layout->addItem(slidersLayout);
m_layout->addItem(buttonsLayout);
setMinimumHeight(300);
foreach(QSlider *slider, m_sliders)
{
connect(slider, SIGNAL(valueChanged(int)), SLOT(applySettings()));
}
connect(m_enabled, SIGNAL(clicked()), SLOT(applySettings()));
readSettigs();
loadPresets();
}
Equalizer::~Equalizer()
{
savePresets();
qDeleteAll(m_presets);
m_presets.clear();
}