actionclasses.cpp
来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 666 行 · 第 1/2 页
CPP
666 行
// Maintainer: Max Howell <max.howell@methylblue.com>, (C) 2004// Copyright: See COPYING file that comes with this distribution#include "config.h" //HAVE_LIBVISUAL definition#include "actionclasses.h"#include "amarok.h"#include "amarokconfig.h"#include "app.h"#include "debug.h"#include "collectiondb.h"#include "covermanager.h"#include "enginecontroller.h"#include "k3bexporter.h"#include "mediumpluginmanager.h"#include "playlistwindow.h"#include "playlist.h"#include "socketserver.h" //Vis::Selector::showInstance()#include "threadmanager.h"#include <qpixmap.h>#include <qtooltip.h>#include <kaction.h>#include <khelpmenu.h>#include <kiconloader.h>#include <klocale.h>#include <kstandarddirs.h>#include <ktoolbar.h>#include <ktoolbarbutton.h>#include <kurl.h>namespace Amarok{ bool repeatNone() { return AmarokConfig::repeat() == AmarokConfig::EnumRepeat::Off; } bool repeatTrack() { return AmarokConfig::repeat() == AmarokConfig::EnumRepeat::Track; } bool repeatAlbum() { return AmarokConfig::repeat() == AmarokConfig::EnumRepeat::Album; } bool repeatPlaylist() { return AmarokConfig::repeat() == AmarokConfig::EnumRepeat::Playlist; } bool randomOff() { return AmarokConfig::randomMode() == AmarokConfig::EnumRandomMode::Off; } bool randomTracks() { return AmarokConfig::randomMode() == AmarokConfig::EnumRandomMode::Tracks; } bool randomAlbums() { return AmarokConfig::randomMode() == AmarokConfig::EnumRandomMode::Albums; } bool favorNone() { return AmarokConfig::favorTracks() == AmarokConfig::EnumFavorTracks::Off; } bool favorScores() { return AmarokConfig::favorTracks() == AmarokConfig::EnumFavorTracks::HigherScores; } bool favorRatings() { return AmarokConfig::favorTracks() == AmarokConfig::EnumFavorTracks::HigherRatings; } bool favorLastPlay() { return AmarokConfig::favorTracks() == AmarokConfig::EnumFavorTracks::LessRecentlyPlayed; } bool entireAlbums() { return repeatAlbum() || randomAlbums(); }}using namespace Amarok;KHelpMenu *Menu::s_helpMenu = 0;static voidsafePlug( KActionCollection *ac, const char *name, QWidget *w ){ if( ac ) { KAction *a = ac->action( name ); if( a ) a->plug( w ); }}//////////////////////////////////////////////////////////////////////////////////////////// MenuAction && Menu// KActionMenu doesn't work very well, so we derived our own//////////////////////////////////////////////////////////////////////////////////////////MenuAction::MenuAction( KActionCollection *ac ) : KAction( i18n( "Amarok Menu" ), 0, ac, "amarok_menu" ){ setShortcutConfigurable ( false ); //FIXME disabled as it doesn't work, should use QCursor::pos()}intMenuAction::plug( QWidget *w, int index ){ KToolBar *bar = dynamic_cast<KToolBar*>(w); if( bar && kapp->authorizeKAction( name() ) ) { const int id = KAction::getToolButtonID(); addContainer( bar, id ); connect( bar, SIGNAL( destroyed() ), SLOT( slotDestroyed() ) ); //TODO create menu on demand //TODO create menu above and aligned within window //TODO make the arrow point upwards! bar->insertButton( QString::null, id, true, i18n( "Menu" ), index ); bar->alignItemRight( id ); KToolBarButton* button = bar->getButton( id ); button->setPopup( Amarok::Menu::instance() ); button->setName( "toolbutton_amarok_menu" ); button->setIcon( "amarok" ); return containerCount() - 1; } else return -1;}Menu::Menu(){ KActionCollection *ac = Amarok::actionCollection(); setCheckable( true ); safePlug( ac, "repeat", this ); safePlug( ac, "random_mode", this ); insertSeparator(); safePlug( ac, "playlist_playmedia", this ); safePlug( ac, "play_audiocd", this ); safePlug( ac, "lastfm_play", this ); insertSeparator(); insertItem( SmallIconSet( Amarok::icon( "covermanager" ) ), i18n( "C&over Manager" ), ID_SHOW_COVER_MANAGER ); safePlug( ac, "queue_manager", this ); insertItem( SmallIconSet( Amarok::icon( "visualizations" ) ), i18n( "&Visualizations" ), ID_SHOW_VIS_SELECTOR ); insertItem( SmallIconSet( Amarok::icon( "equalizer" ) ), i18n( "E&qualizer" ), kapp, SLOT( slotConfigEqualizer() ), 0, ID_CONFIGURE_EQUALIZER ); safePlug( ac, "script_manager", this ); safePlug( ac, "statistics", this ); insertSeparator(); safePlug( ac, "update_collection", this ); insertItem( SmallIconSet( Amarok::icon( "rescan" ) ), i18n("&Rescan Collection"), ID_RESCAN_COLLECTION ); setItemEnabled( ID_RESCAN_COLLECTION, !ThreadManager::instance()->isJobPending( "CollectionScanner" ) );#ifndef Q_WS_MAC insertSeparator(); safePlug( ac, KStdAction::name(KStdAction::ShowMenubar), this );#endif insertSeparator(); safePlug( ac, KStdAction::name(KStdAction::ConfigureToolbars), this ); safePlug( ac, KStdAction::name(KStdAction::KeyBindings), this ); safePlug( ac, "options_configure_globals", this ); //we created this one safePlug( ac, KStdAction::name(KStdAction::Preferences), this ); insertSeparator(); insertItem( SmallIconSet("help"), i18n( "&Help" ), helpMenu( this ) ); insertSeparator(); safePlug( ac, KStdAction::name(KStdAction::Quit), this ); connect( this, SIGNAL( aboutToShow() ), SLOT( slotAboutToShow() ) ); connect( this, SIGNAL( activated(int) ), SLOT( slotActivated(int) ) ); setItemEnabled( ID_SHOW_VIS_SELECTOR, false ); #ifdef HAVE_LIBVISUAL setItemEnabled( ID_SHOW_VIS_SELECTOR, true ); #endif}Menu*Menu::instance(){ static Menu menu; return &menu;}KPopupMenu*Menu::helpMenu( QWidget *parent ) //STATIC{ extern KAboutData aboutData; if ( s_helpMenu == 0 ) s_helpMenu = new KHelpMenu( parent, &aboutData, Amarok::actionCollection() ); return s_helpMenu->menu();}voidMenu::slotAboutToShow(){ setItemEnabled( ID_CONFIGURE_EQUALIZER, EngineController::hasEngineProperty( "HasEqualizer" ) ); setItemEnabled( ID_CONF_DECODER, EngineController::hasEngineProperty( "HasConfigure" ) );}voidMenu::slotActivated( int index ){ switch( index ) { case ID_SHOW_COVER_MANAGER: CoverManager::showOnce(); break; case ID_SHOW_VIS_SELECTOR: Vis::Selector::instance()->show(); //doing it here means we delay creation of the widget break; case ID_RESCAN_COLLECTION: CollectionDB::instance()->startScan(); break; }}//////////////////////////////////////////////////////////////////////////////////////////// PlayPauseAction//////////////////////////////////////////////////////////////////////////////////////////PlayPauseAction::PlayPauseAction( KActionCollection *ac ) : KToggleAction( i18n( "Play/Pause" ), 0, ac, "play_pause" ) , EngineObserver( EngineController::instance() ){ engineStateChanged( EngineController::engine()->state() ); connect( this, SIGNAL(activated()), EngineController::instance(), SLOT(playPause()) );}voidPlayPauseAction::engineStateChanged( Engine::State state, Engine::State /*oldState*/ ){ QString text; switch( state ) { case Engine::Playing: setChecked( false ); setIcon( Amarok::icon( "pause" ) ); text = i18n( "Pause" ); break; case Engine::Paused: setChecked( true ); setIcon( Amarok::icon( "pause" ) ); text = i18n( "Pause" ); break; case Engine::Empty: setChecked( false ); setIcon( Amarok::icon( "play" ) ); text = i18n( "Play" ); break; case Engine::Idle: return; } //update menu texts for this special action for( int x = 0; x < containerCount(); ++x ) { QWidget *w = container( x ); if( w->inherits( "QPopupMenu" ) ) static_cast<QPopupMenu*>(w)->changeItem( itemId( x ), text ); //TODO KToolBar sucks so much// else if( w->inherits( "KToolBar" ) )// static_cast<KToolBar*>(w)->getButton( itemId( x ) )->setText( text ); }}//////////////////////////////////////////////////////////////////////////////////////////// AnalyzerAction//////////////////////////////////////////////////////////////////////////////////////////#include "analyzerbase.h"AnalyzerAction::AnalyzerAction( KActionCollection *ac ) : KAction( i18n( "Analyzer" ), 0, ac, "toolbar_analyzer" ){ setShortcutConfigurable( false );}intAnalyzerAction::plug( QWidget *w, int index ){ //NOTE the analyzer will be deleted when the toolbar is deleted or cleared() //we are not designed for unplugging() yet so there would be a leak if that happens //but it's a rare event and unplugging is complicated. KToolBar *bar = dynamic_cast<KToolBar*>(w); if( bar && kapp->authorizeKAction( name() ) ) { const int id = KAction::getToolButtonID(); addContainer( w, id ); connect( w, SIGNAL( destroyed() ), SLOT( slotDestroyed() ) ); QWidget *container = new AnalyzerContainer( w ); bar->insertWidget( id, 0, container, index ); bar->setItemAutoSized( id, true ); return containerCount() - 1; } else return -1;}AnalyzerContainer::AnalyzerContainer( QWidget *parent ) : QWidget( parent, "AnalyzerContainer" ) , m_child( 0 ){ QToolTip::add( this, i18n( "Click for more analyzers" ) ); changeAnalyzer();}voidAnalyzerContainer::resizeEvent( QResizeEvent *){ m_child->resize( size() );}void AnalyzerContainer::changeAnalyzer(){ delete m_child; m_child = Analyzer::Factory::createPlaylistAnalyzer( this ); m_child->setName( "ToolBarAnalyzer" ); m_child->resize( size() ); m_child->show();}voidAnalyzerContainer::mousePressEvent( QMouseEvent *e){ if( e->button() == Qt::LeftButton ) { AmarokConfig::setCurrentPlaylistAnalyzer( AmarokConfig::currentPlaylistAnalyzer() + 1 ); changeAnalyzer(); }}voidAnalyzerContainer::contextMenuEvent( QContextMenuEvent *e){#if defined HAVE_LIBVISUAL KPopupMenu menu; menu.insertItem( SmallIconSet( Amarok::icon( "visualizations" ) ), i18n("&Visualizations"), Menu::ID_SHOW_VIS_SELECTOR ); if( menu.exec( mapToGlobal( e->pos() ) ) == Menu::ID_SHOW_VIS_SELECTOR ) Menu::instance()->slotActivated( Menu::ID_SHOW_VIS_SELECTOR );#else Q_UNUSED(e);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?