equalizersetup.cpp
来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 496 行 · 第 1/2 页
CPP
496 行
} QDomNode n = d.namedItem( "equalizerpresets" ).namedItem("preset"); for( ; !n.isNull(); n = n.nextSibling() ) { QDomElement e = n.toElement(); QString title = e.attribute( "name" ); QValueList<int> gains; gains << e.namedItem( "b0" ).toElement().text().toInt(); gains << e.namedItem( "b1" ).toElement().text().toInt(); gains << e.namedItem( "b2" ).toElement().text().toInt(); gains << e.namedItem( "b3" ).toElement().text().toInt(); gains << e.namedItem( "b4" ).toElement().text().toInt(); gains << e.namedItem( "b5" ).toElement().text().toInt(); gains << e.namedItem( "b6" ).toElement().text().toInt(); gains << e.namedItem( "b7" ).toElement().text().toInt(); gains << e.namedItem( "b8" ).toElement().text().toInt(); gains << e.namedItem( "b9" ).toElement().text().toInt(); m_presets[ title ] = gains; } file.close();}voidEqualizerSetup::savePresets(){ QFile file( presetsCache() ); if( !file.open( IO_WriteOnly ) ) return; QDomDocument doc; QDomElement e = doc.createElement("equalizerpresets"); e.setAttribute( "product", "Amarok" ); e.setAttribute( "version", APP_VERSION ); e.setAttribute( "formatversion", "1.1" ); doc.appendChild( e ); QStringList info; info << "b0" << "b1" << "b2" << "b3" << "b4" << "b5" << "b6" << "b7" << "b8" << "b9"; for( uint x = 0; x < m_presets.count(); x++ ) { const QString title = m_presetCombo->text( x ); // don't save the 'Zero' preset if ( title == i18n("Zero") ) continue; QValueList<int> gains = m_presets[ title ]; QDomElement i = doc.createElement("preset"); i.setAttribute( "name", title ); QDomElement attr; QDomText t; for( uint y=0; y < info.count(); y++ ) { attr = doc.createElement( info[y] ); t = doc.createTextNode( QString::number( gains.first() ) ); attr.appendChild( t ); i.appendChild( attr ); gains.pop_front(); } e.appendChild( i ); } QTextStream stream( &file ); stream.setEncoding( QTextStream::UnicodeUTF8 ); stream << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; stream << doc.toString(); file.close();}voidEqualizerSetup::editPresets(){ EqualizerPresetManager * editor = new EqualizerPresetManager(this); editor->setPresets(m_presets); if ( editor->exec() ) { QMap< QString, QValueList<int> > presets = editor->presets(); QString currentTitle = m_presetCombo->currentText(); QValueList<int> currentGains= m_presets[ currentTitle ]; QString newTitle = currentTitle; // Check if the selected item was renamed if ( presets.find( currentTitle ) == presets.end() || currentGains != presets[ currentTitle ] ) { // Find the new name QMap< QString, QValueList<int> >::Iterator end = presets.end(); for ( QMap< QString, QValueList<int> >::Iterator it = presets.begin(); it != end; ++it ) { if ( it.data() == currentGains ) { newTitle = it.key(); break; } } } m_presets = presets; updatePresets( newTitle ); } delete editor;}voidEqualizerSetup::addPreset(){ bool ok; const QString title = KInputDialog::getText( i18n("Add Equalizer Preset"), i18n("Enter preset name:"), i18n("Untitled"), &ok, this); if (ok) { // Check if the new preset title exists if ( m_presets.find( title ) != m_presets.end() ) { int button = KMessageBox::warningYesNo( this, i18n( "A preset with the name %1 already exists. Overwrite?" ).arg( title ) ); if ( button != KMessageBox::Yes ) return; } // Add the new preset based on the current slider positions QValueList <int> gains; for ( uint i = 0; i < m_bandSliders.count(); i++ ) gains += m_bandSliders.at( i )->value(); m_presets[ title ] = gains; // Rebuild the combobox updatePresets(title); // Save setEqualizerParameters(); }}voidEqualizerSetup::updatePresets(QString selectTitle){ // Save the selected item if ( selectTitle.isEmpty() ) selectTitle = m_presetCombo->currentText(); // Sort titles QStringList titles; QMap< QString, QValueList<int> >::Iterator end = m_presets.end(); for ( QMap< QString, QValueList<int> >::Iterator it = m_presets.begin(); it != end; ++it ) titles << it.key(); titles.sort(); // rebuild preset combobox and look for the previously selected title int i = 0; int newIndex = -1; m_presetCombo->clear(); QStringList::Iterator titlesEnd = titles.end(); for ( QStringList::Iterator it = titles.begin(); it != titlesEnd; ++it ) { m_presetCombo->insertItem( *it ); if ( *it == selectTitle ) newIndex = i; if ( *it == i18n("Manual") ) m_manualPos = i; i++; } if ( newIndex == -1 ) newIndex = m_manualPos; m_presetCombo->setCurrentItem( newIndex );}/////////////////////////////////////////////////////////////////////////////////////// PRIVATE SLOTS/////////////////////////////////////////////////////////////////////////////////////voidEqualizerSetup::presetChanged( int id ) //SLOT{ presetChanged( m_presetCombo->text(id) );}voidEqualizerSetup::presetChanged( QString title ) //SLOT{ const QValueList<int> gains = m_presets[ title ]; for ( uint i = 0; i < m_bandSliders.count(); i++ ) { // Block signals to prevent unwanted setting to 'Manual' m_bandSliders.at(i)->blockSignals(true); m_bandSliders.at(i)->setValue( ( *gains.at(i) ) ); m_bandSliders.at(i)->blockSignals(false); } setEqualizerParameters();}voidEqualizerSetup::setEqualizerEnabled( bool active ) //SLOT{ EngineController::engine()->setEqualizerEnabled( active ); AmarokConfig::setEqualizerEnabled( active ); if( active ) //this way the developer of the eq doesn't have to cache the eq values setEqualizerParameters(); else // zero the graph m_equalizerGraph->update();}voidEqualizerSetup::setEqualizerParameters() //SLOT{ AmarokConfig::setEqualizerPreamp( m_slider_preamp->value() ); AmarokConfig::setEqualizerPreset( m_presetCombo->currentText() ); AmarokConfig::setEqualizerGains ( m_presets[ m_presetCombo->currentText() ] ); // Transfer values to the engine if the EQ is enabled if ( AmarokConfig::equalizerEnabled() ) EngineController::engine()->setEqualizerParameters( m_slider_preamp->value(), m_presets[ m_presetCombo->currentText() ] ); m_equalizerGraph->update();}voidEqualizerSetup::sliderChanged() //SLOT{ m_presetCombo->setCurrentItem( m_manualPos ); QValueList<int> gains; for ( uint i = 0; i < m_bandSliders.count(); i++ ) gains += m_bandSliders.at( i )->value(); m_presets[ i18n("Manual") ] = gains;}#include "equalizersetup.moc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?