v1.2.3-13-gbd6f'/>
aboutsummaryrefslogblamecommitdiff
path: root/src/ui/eqwidget.cpp
blob: 12ffb9cff520b36114a38844c2b102bfb5a7d5c8 (plain) (tree)
1
2
                                                                            
                                                                            




















                                                                             
                      
                              
                           









                         
                         

                     

                                    
 
                     
                              
                                                  
                                                       
                                       
                           
                                                                        
 
                                   
                                                                      
 

                                                                                                          


                                                                                     
                              
                                    
                                                                                                         
                                                                        
                                                                                
 
                              
     
                                         
                                                                                   


                    

                      
                                                                                                           







                                                              









                                         











                                                   
                                           






                                                  
                                          
 
                          
                      




                           
                                  
                                                  
                                                       













                                     



                             
                                                                  

                                                                                    
                       
                                                                                     
                              










                                                                                 
                                                                 
             
                                                                      






                                     
                                                                                        
                              










                                                                               
                                                               
             
                                                                    









                                         
                                                                  
                                                                
                       
                                                                                     














                                                                                     
                                             














                                                                                       
                       

                   

                                                                

                            

                                                      
     
                                        

 
                        
 









                                                       





                                                                          





                                                                                             
                                  
                                                                                                











                                                                   
              























                                                                                                    
                                                          






                                                                      






                                 
                                                                         


                                        
                                                                                  



                             
                                                                    












                                                      
              












































                                                   


                                                                         
 

                                   
                           

                                                                           
                                     












                                                        



                 






                                                                                             
 


                                    

                                                                             



                                 







                                                                                       
/***************************************************************************
 *   Copyright (C) 2006-2010 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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <QSettings>
#include <QEvent>
#include <QMenu>
#include <QInputDialog>
#include <QCloseEvent>
#include <qmmpui/filedialog.h>
#include <qmmp/soundcore.h>
#include "skin.h"
#include "eqslider.h"
#include "eqtitlebar.h"
#include "togglebutton.h"
#include "eqgraph.h"
#include "button.h"
#include "eqpreset.h"
#include "preseteditor.h"
#include "mainwindow.h"
#include "playlist.h"
#include "windowsystem.h"
#include "eqwidget.h"

EqWidget::EqWidget (QWidget *parent)
        : PixmapWidget (parent)
{
    m_shaded = false;
    m_skin = Skin::instance();
    setPixmap (m_skin->getEqPart (Skin::EQ_MAIN));
    setCursor (m_skin->getCursor (Skin::CUR_EQNORMAL));
    m_titleBar = new EqTitleBar (this);
    m_titleBar->move (0,0);
    connect (m_skin, SIGNAL (skinChanged()), this, SLOT (updateSkin()));

    m_preamp = new EqSlider (this);
    connect (m_preamp,SIGNAL (sliderMoved (double)),SLOT (writeEq()));

    m_on = new ToggleButton (this,Skin::EQ_BT_ON_N,Skin::EQ_BT_ON_P, Skin::EQ_BT_OFF_N,Skin::EQ_BT_OFF_P);
    connect (m_on, SIGNAL (clicked(bool)), SLOT(writeEq()));

    m_autoButton = new ToggleButton(this, Skin::EQ_BT_AUTO_1_N, Skin::EQ_BT_AUTO_1_P,
                                    Skin::EQ_BT_AUTO_0_N, Skin::EQ_BT_AUTO_0_P);
    m_eqg = new EQGraph(this);
    m_presetsMenu = new QMenu(this);
    m_presetButton = new Button (this, Skin::EQ_BT_PRESETS_N, Skin::EQ_BT_PRESETS_P, Skin::CUR_EQNORMAL);
    connect(m_presetButton, SIGNAL(clicked()), SLOT(showPresetsMenu()));
    connect(SoundCore::instance(), SIGNAL(eqSettingsChanged()), SLOT(readEq()));

    for (int i = 0; i<10; ++i)
    {
        m_sliders << new EqSlider (this);
        connect (m_sliders.at (i), SIGNAL (sliderMoved (double)),SLOT (writeEq()));
    }
    readSettings();
    createActions();
    updatePositions();
    updateMask();
    connect(SoundCore::instance(), SIGNAL(volumeChanged(int, int)), m_titleBar, SLOT(setVolume(int, int)));
#ifdef Q_WS_X11
    QString wm_name = WindowSystem::netWindowManagerName();
    if(wm_name.contains("metacity", Qt::CaseInsensitive) ||
       wm_name.contains("openbox", Qt::CaseInsensitive))
        setWindowFlags (Qt::Tool | Qt::FramelessWindowHint);
    else
#endif
        setWindowFlags (Qt::Dialog | Qt::FramelessWindowHint);
}

EqWidget::~EqWidget()
{
    while (!m_presets.isEmpty())
        delete m_presets.takeFirst();
    while (!m_autoPresets.isEmpty())
        delete m_autoPresets.takeFirst();
}

void EqWidget::updatePositions()
{
    int r = m_skin->ratio();
    m_preamp->move (21*r,38*r);
    m_on->move (14*r,18*r);
    m_autoButton->move(39*r,18*r);
    m_eqg->move(87*r,17*r);
    m_presetButton->move(217*r,18*r);
     for (int i = 0; i < 10; ++i)
         m_sliders.at (i)->move ((78+i*18)*r,38*r);
}

void EqWidget::changeEvent (QEvent * event)
{
    if (event->type() == QEvent::ActivationChange)
    {
        m_titleBar->setActive(isActiveWindow());
    }
}

void EqWidget::closeEvent (QCloseEvent* e)
{
    if (e->spontaneous ())
        emit closed();
    writeSettings();
}

void EqWidget::updateSkin()
{
    m_titleBar->setActive (false);
    setPixmap (m_skin->getEqPart (Skin::EQ_MAIN));
    setCursor (m_skin->getCursor (Skin::CUR_EQNORMAL));
    setMimimalMode(m_shaded);
    updatePositions();
}

void EqWidget::setMimimalMode(bool b)
{
    m_shaded = b;
    int r = m_skin->ratio();

    if(m_shaded)
         resize(r*275,r*14);
    else
         resize(r*275,r*116);
    updateMask();
}

void EqWidget::readSettings()
{
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    move (settings.value ("Equalizer/pos", QPoint (100, 216)).toPoint()); //geometry
    readEq();
    //equalizer presets
    QSettings eq_preset (QDir::homePath() +"/.qmmp/eq.preset", QSettings::IniFormat);
    for (int i = 1; true; ++i)
    {
        if (eq_preset.contains("Presets/Preset"+QString("%1").arg(i)))
        {
            QString name = eq_preset.value("Presets/Preset"+QString("%1").arg(i),
                                           tr("preset")).toString();
            EQPreset *preset = new EQPreset();
            preset->setText(name);
            eq_preset.beginGroup(name);
            for (int j = 0; j < 10; ++j)
            {
                preset->setGain(j,eq_preset.value("Band"+QString("%1").arg(j),
                                                  0).toDouble());
            }
            preset->setPreamp(eq_preset.value("Preamp",0).toDouble());
            m_presets.append(preset);
            eq_preset.endGroup();
        }
        else
            break;
    }
    //equalizer auto-load presets
    QSettings eq_auto (QDir::homePath() +"/.qmmp/eq.auto_preset", QSettings::IniFormat);
    for (int i = 1; true; ++i)
    {
        if (eq_auto.contains("Presets/Preset"+QString("%1").arg(i)))
        {
            QString name = eq_auto.value("Presets/Preset"+QString("%1").arg(i),
                                         tr("preset")).toString();
            EQPreset *preset = new EQPreset();
            preset->setText(name);
            eq_auto.beginGroup(name);
            for (int j = 0; j < 10; ++j)
            {
                preset->setGain(j,eq_auto.value("Band"+QString("%1").arg(j),
                                                0).toDouble());
            }
            preset->setPreamp(eq_auto.value("Preamp",0).toDouble());
            m_autoPresets.append(preset);
            eq_auto.endGroup();
        }
        else
            break;
    }
}

void EqWidget::writeSettings()
{
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    settings.setValue ("Equalizer/pos", this->pos()); //geometry
    //equalizer presets
    QSettings eq_preset (QDir::homePath() +"/.qmmp/eq.preset", QSettings::IniFormat);
    eq_preset.clear ();
    for (int i = 0; i < m_presets.size(); ++i)
    {
        eq_preset.setValue("Presets/Preset"+QString("%1").arg(i+1),
                           m_presets.at(i)->text());
        eq_preset.beginGroup(m_presets.at(i)->text());
        for (int j = 0; j < 10; ++j)
        {
            eq_preset.setValue("Band"+QString("%1").arg(j),m_presets.at(i)->gain(j));
        }
        eq_preset.setValue("Preamp",m_presets.at(i)->preamp());
        eq_preset.endGroup();
    }
    //equalizer auto-load presets
    QSettings eq_auto (QDir::homePath() +"/.qmmp/eq.auto_preset",
                       QSettings::IniFormat);
    eq_auto.clear();
    for (int i = 0; i < m_autoPresets.size(); ++i)
    {
        eq_auto.setValue("Presets/Preset"+QString("%1").arg(i+1),
                         m_autoPresets.at(i)->text());
        eq_auto.beginGroup(m_autoPresets.at(i)->text());
        for (int j = 0; j < 10; ++j)
        {
            eq_auto.setValue("Band"+QString("%1").arg(j),m_autoPresets.at(i)->gain(j));
        }
        eq_auto.setValue("Preamp",m_autoPresets.at(i)->preamp());
        eq_auto.endGroup();
    }
}

void EqWidget::readEq()
{