equalizersetup.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 496 行 · 第 1/2 页

CPP
496
字号
/*************************************************************************** Setup dialog for the equalizer (c) 2004 Mark Kretschmann <markey@web.de> (c) 2005 Seb Ruiz <me@sebruiz.net> (c) 2005 Markus Brueffer <markus@brueffer.de>***************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************/#include "amarok.h"#include "amarokconfig.h"#include "enginebase.h"#include "enginecontroller.h"#include "equalizergraph.h"#include "equalizerpresetmanager.h"#include "equalizersetup.h"#include "sliderwidget.h"#include <qcheckbox.h>#include <qdom.h>#include <qfile.h>#include <qgroupbox.h>#include <qlabel.h>#include <qlayout.h>#include <qpushbutton.h>#include <qstringlist.h>#include <qtextstream.h>   //presets#include <qtooltip.h>#include <qvbox.h>#include <kapplication.h>#include <kcombobox.h>#include <kiconloader.h>#include <kinputdialog.h>  //presets#include <klocale.h>#include <kmessagebox.h>#include <kpopupmenu.h>#include <kstandarddirs.h> //locate()#include <kwin.h>EqualizerSetup* EqualizerSetup::s_instance = 0;EqualizerSetup::EqualizerSetup()        : KDialogBase( Amarok::mainWindow(), 0, false, 0, 0, Ok, false ){    using Amarok::Slider;    s_instance = this;    kapp->setTopWidget( this );    setCaption( kapp->makeStdCaption( i18n( "Equalizer" ) ) );    // Gives the window a small title bar, and skips a taskbar entry    KWin::setType( winId(), NET::Utility );    KWin::setState( winId(), NET::SkipTaskbar );    QVBox* vbox = makeVBoxMainWidget();    vbox->setSpacing( KDialog::spacingHint() );    // BEGIN Presets    QHBox* presetBox = new QHBox( vbox );    presetBox->setSpacing( KDialog::spacingHint() );    new QLabel( i18n("Presets:"), presetBox );    m_presetCombo = new KComboBox( presetBox );    m_presetCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );    QPushButton* presetAdd = new QPushButton( presetBox );    presetAdd->setIconSet( SmallIconSet( Amarok::icon( "add_playlist" ) ) );    QToolTip::add( presetAdd, i18n("Add new preset") );    connect( presetAdd, SIGNAL( clicked() ), SLOT( addPreset() ) );    QPushButton* presetConf = new QPushButton( presetBox );    presetConf->setIconSet( SmallIconSet( Amarok::icon( "configure" ) ) );    QToolTip::add( presetConf, i18n("Manage presets") );    connect( presetConf, SIGNAL( clicked() ), SLOT( editPresets() ) );    loadPresets();    connect( m_presetCombo, SIGNAL( activated(int) ), SLOT( presetChanged(int) ) );    // END Presets    // BEGIN GroupBox    m_groupBoxSliders = new QGroupBox( 1, Qt::Vertical, i18n("Enable Equalizer"), vbox );    m_groupBoxSliders->setCheckable( true );    m_groupBoxSliders->setChecked( AmarokConfig::equalizerEnabled() );    m_groupBoxSliders->setInsideMargin( KDialog::marginHint() );    connect( m_groupBoxSliders, SIGNAL( toggled( bool ) ), SLOT( setEqualizerEnabled( bool ) ) );    // Helper widget for layouting inside the groupbox    QWidget* slidersLayoutWidget = new QWidget( m_groupBoxSliders );    slidersLayoutWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);    QGridLayout* slidersGridLayout = new QGridLayout( slidersLayoutWidget, 1, 1, 0, KDialog::spacingHint() );    // END GroupBox    // BEGIN Preamp slider    m_slider_preamp = new Slider( Qt::Vertical, slidersLayoutWidget, 100 );    m_slider_preamp->setMinValue( -100 );    m_slider_preamp->setTickmarks( QSlider::Right );    m_slider_preamp->setTickInterval( 100 );    connect( m_slider_preamp, SIGNAL( valueChanged( int ) ), SLOT( setEqualizerParameters() ) );    slidersGridLayout->addMultiCellWidget(m_slider_preamp, 0, 0, 0, 1, Qt::AlignHCenter );    QLabel* preampLabel = new QLabel( i18n("Pre-amp"), slidersLayoutWidget );    slidersGridLayout->addMultiCellWidget(preampLabel, 1, 1 , 0, 1, Qt::AlignHCenter );    // END    // BEGIN Band Sliders    const char *bandLabels[] = { "30", "60", "125", "250", "500", "1k", "2k", "4k", "8k", "16k" };    int minWidth = 0;    QFontMetrics fm = fontMetrics(); //apparently it's an expensive call    for ( int i = 0; i < 10; i++ ) {         int w = fm.width( bandLabels[i] );         if ( w > minWidth )             minWidth = w;    }    for ( int i = 0; i < 10; i++ ) {        Slider *slider = new Slider( Qt::Vertical, slidersLayoutWidget );        QLabel *label  = new QLabel( bandLabels[i], slidersLayoutWidget );        slider->setMinValue( -100 );        slider->setMaxValue( +100 );        slider->setMinimumWidth( minWidth );        slidersGridLayout->addMultiCellWidget(slider, 0, 0, 2 * i + 2, 2 * i + 3, Qt::AlignHCenter );        slidersGridLayout->addMultiCellWidget(label, 1, 1, 2 * i + 2, 2 * i + 3, Qt::AlignHCenter );        m_bandSliders.append( slider );        connect( slider, SIGNAL( valueChanged( int ) ), SLOT( setEqualizerParameters() ) );        connect( slider, SIGNAL( valueChanged( int ) ), SLOT( sliderChanged() ) );    }    // END    // BEGIN Equalizer Graph Widget    QGroupBox* graphGBox = new QGroupBox( 2, Qt::Horizontal, 0, vbox );    graphGBox->setInsideMargin( KDialog::marginHint() );    QVBox* graphVBox = new QVBox( graphGBox );    QLabel* graphLabel1 = new QLabel("+20 db", graphVBox);    QLabel* graphLabel2 = new QLabel("0 db", graphVBox);    QLabel* graphLabel3 = new QLabel("-20 db", graphVBox);    graphLabel1->setAlignment( Qt::AlignRight | Qt::AlignTop );    graphLabel2->setAlignment( Qt::AlignRight | Qt::AlignVCenter );    graphLabel3->setAlignment( Qt::AlignRight | Qt::AlignBottom );    m_equalizerGraph = new EqualizerGraph( graphGBox );    m_equalizerGraph->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );    // END Graph Widget    // Fill the combobox    updatePresets( AmarokConfig::equalizerPreset() );    // make sure to restore the current preamp value    m_slider_preamp->setValue( AmarokConfig::equalizerPreamp() );    // Init sliders    presetChanged( AmarokConfig::equalizerPreset() );}EqualizerSetup::~EqualizerSetup(){    savePresets();    s_instance = 0;}voidEqualizerSetup::setActive( bool active ){    m_groupBoxSliders->setChecked( active );}voidEqualizerSetup::setBands( int preamp, QValueList<int> gains ){    m_slider_preamp->setValue( preamp );    // Note: As a side effect, this automatically switches the    //       preset to 'Manual', which is by intention    for ( uint i = 0; i < m_bandSliders.count(); i++ )        m_bandSliders.at(i)->setValue( ( *gains.at(i) ) );    setEqualizerParameters();}voidEqualizerSetup::setPreset( QString name ){    // Look for the preset id and verify name    int i, count = m_presetCombo->count();    bool found = false;    for( i = 0; i < count; i++ ) {        if ( m_presetCombo->text( i ) == name ) {            found = true;            break;        }    }    if ( found ) {        m_presetCombo->setCurrentItem( i );        presetChanged( name );    }}/////////////////////////////////////////////////////////////////////////////////////// EQUALIZER PRESETS/////////////////////////////////////////////////////////////////////////////////////QStringEqualizerSetup::presetsCache() const{    // returns the playlists stats cache file    return Amarok::saveLocation() + "equalizerpresets_save.xml";}voidEqualizerSetup::loadPresets(){    // Create predefined presets 'Zero' and 'Manual'    QValueList<int> zeroGains;    zeroGains << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0;    m_presets[ i18n("Manual") ] = zeroGains;    m_presets[ i18n("Zero") ] = zeroGains;    QFile file( presetsCache() );    if ( !file.exists() )        file.setName( locate( "data", "amarok/data/equalizer_presets.xml" ) );    QTextStream stream( &file );    stream.setEncoding( QTextStream::UnicodeUTF8 );    QDomDocument d;    if( !file.open( IO_ReadOnly ) || !d.setContent( stream.read() ) ) {        // Everything went wrong, so at least provide the two predefined presets        updatePresets( AmarokConfig::equalizerPreset() );        return;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?