⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmaccelmanager.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* qmaccelmanager.cpp * * $Id: qmaccelmanager.cpp,v 1.19.2.2 2002/10/11 06:39:03 kyllingstad Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * 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. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmaccelmanager.h"#include "qmmainwindow.h"#include "qmconfig.h"#include "qmmixer.h"#include "qmbrowser.h"#include <qaccel.h>#include <qnamespace.h>#include <qobject.h>#include <qdict.h>#include <iostream>/*!   \file qmaccelmanager.cpp   \brief The central control for shortcut keys handling*/QmAutoPtr<QmAccelManager> QmAccelManager::s_pInstance;/*!  \class QmAccelManager qmaccelmanager.h  \brief The Shortcut key manager.  Has a list of commands that can be bound to a key, and members for doing  so.  Used from \sa qmshortcutpage.cpp.  Instantiated by \sa  qmmainwindow.cpp on startup (restoreState).*//*!  Reads the bindings from QmConfig and sets them.*/QmAccelManager::QmAccelManager(){	m_pAccel = new QAccel(QmMainWindow::mainwin);	// set up the bindable commands	QmMainWindow *m = QmMainWindow::mainwin;    m_Keys.setAutoDelete(true);    Group *song = new Group( QObject::tr( "Playing" ) );    Group *browser = new Group( QObject::tr( "Browser" ) );    Group *misc = new Group( QObject::tr( "Miscellaneous" ) );    m_Groups.appendGroup( song );    m_Groups.appendGroup( browser );    m_Groups.appendGroup( misc );	addKey( song, new Key( "next-song", m, SLOT(next()), QObject::tr("Next song")));	addKey( song, new Key( "prev-song", m, SLOT(prev()), QObject::tr("Previous song")));	addKey( song, new Key( "stop-song", m, SLOT(stop()), QObject::tr("Stop")));	addKey( song, new Key( "pause-song", m, SLOT(pause()), QObject::tr("Pause")));	addKey( song, new Key( "play-song", m, SLOT(play()), QObject::tr("Play")));	addKey( browser, new Key( "toggle-browser", m, SLOT(toggleBrowser()), QObject::tr("Toggle the playlist/directory browser"),                              Key::KeyValue( DefaultKey ), Qt::CTRL + Qt::Key_B));	addKey( browser, new Key( "show-dir-browser", m, SLOT(showDirectoryBrowser()), QObject::tr("Show the directory browser")));	addKey( browser, new Key( "show-playlist-browser", m, SLOT(showPlaylistBrowser()), QObject::tr("Show the playlist browser")));//	m_Keys.insert("toggle-minimized", new Key(m, QObject::tr("Toggle the main window to be minimized")));	QmMixer *mix = QmMixer::instance(); 	addKey( misc, new Key( "volume-up", mix, SLOT(incVolume()), QObject::tr("Volume Increase"))); 	addKey( misc, new Key( "volume-down", mix, SLOT(decVolume()), QObject::tr("Volume Decrease")));// 	m_Keys.insert("forward-song", new Key( , QObject::tr("Fast forward")));// 	m_Keys.insert("backward-song", new Key( , QObject::tr("Fast backward")));	addKey( misc, new Key( "search", m, SLOT(activateSearch()), QObject::tr("Search in playlist"),                           Key::KeyValue( DefaultKey ), Qt::CTRL + Qt::Key_F));	// read bindings from config	QmConfig *conf = QmConfig::instance();	Key *k;	for (QDictIterator<Key> i(m_Keys); i.current(); ++i)	{		k = i.current();        if ( conf->has( "shortcut-keys", i.currentKey()+"-key" ) )        {            int key_val = conf->getInt("shortcut-keys", i.currentKey()+"-key");            if ( key_val )                setCustomKey( k, key_val , true );            else                setNoKey( k, true );            key_val = usedKey( k );            k->id  = m_pAccel->insertItem(key_val);            if (key_val)                if (!m_pAccel->connectItem(k->id, k->receiver, k->slot))                    std::cout << "Binding failed\n"; // flag error        }		m_Commands.append(i.currentKey());	}	m_Commands.sort();}/*!*/QmAccelManager::~QmAccelManager(){}/*!  Adds the key \a k to the group \a g and insert the command to the command map.*/voidQmAccelManager::addKey(    Group *g,    Key *k ){    g->appendKey( k->command );    m_Keys.insert( k->command, k );}/*!  Returns the keycode which is currently used (custom or default) for key \a k.*/intQmAccelManager::usedKey(    Key *k ) const{    if ( k->modified )        return usedKey( k, k->tmpValue );    else        return usedKey( k, k->value );}/*!  Helper function which returns the keycode for the keyvalue \a kv for key \a k.*/intQmAccelManager::usedKey(    Key *k,    Key::KeyValue &kv ) const{    if ( kv.type == DefaultKey )        return k->defKey;    else if ( kv.type == CustomKey )        return kv.key;    else        return 0;}/*!  Sets the keyvalue \a kv to keytype \a t and keycode \a key.*/voidQmAccelManager::setKeyValue(    Key::KeyValue &kv,    KeyType t,    int key ) const{    kv.type = t;    kv.key = key;}/*!  Sets the key \a k to be a custom key and sets the keycode to \a key.  If \a apply is true the key is marked as not being modified.*/voidQmAccelManager::setCustomKey( Key *k,                              int key,                              bool apply ) const{    setKeyValue( apply ? k->value : k->tmpValue, CustomKey, key );    k->modified = !apply;}/*!  Sets the key \a k to be a default key.  If \a apply is true the key is marked as not being modified.*/voidQmAccelManager::setDefaultKey(    Key *k,    bool apply ) const{    setKeyValue( apply ? k->value : k->tmpValue, DefaultKey, k->defKey );    k->modified = !apply;}/*!  Sets the key \a k to be without a.  If \a apply is true the key is marked as not being modified.*/voidQmAccelManager::setNoKey(    Key *k,    bool apply ) const{    setKeyValue( apply ? k->value : k->tmpValue, NoKey, 0 );    k->modified = !apply;}/*! */QmAccelManager*QmAccelManager::instance(){    if ( QmAccelManager::s_pInstance.get() == 0 )    {        s_pInstance.reset( new QmAccelManager() );    }    return reinterpret_cast<QmAccelManager *>(QmAccelManager::s_pInstance.get());}/*!  Sets the command \a command to have the key \a key.  \return `false' if it failed (possibly becase the command didn't exist). */boolQmAccelManager::set(	const QString &command,	int key,	bool apply){    if ( command.isEmpty() )        return false;	Key *k = m_Keys[command];	if (!k)		return false;	if (!apply)        setCustomKey( k, key );// 		k->testKey = key;	else	{		if (k->id)        {			m_pAccel->disconnectItem(k->id, k->receiver, k->slot);			m_pAccel->removeItem(k->id);		}        setCustomKey( k, key, true );		k->id = m_pAccel->insertItem(key);		bool ret =  m_pAccel->connectItem(k->id, k->receiver, k->slot);		if (ret)			return true;        setNoKey( k, true );// 		k->key = 0;		m_pAccel->removeItem(k->id);		k->id = 0;		return false;	}	return true;}/*!  \return `true' if \a key is used as a short-cut key */boolQmAccelManager::setp(int key, const QString &command) const{	for (QDictIterator<Key> it( m_Keys );  it.current(); ++it)	{        Key *k = it.current();        if ( it.currentKey() != command &&             usedKey( k ) == key )			return true;	}	return false;}// /*!//   \return True if the command \a command has a key, or false if no key.//  */// bool// QmAccelManager::setp(// 	const QString &command) const// {// 	Key *k = m_Keys[command];// 	return k && ( k->key > 0 || k->defKey > 0 || k->testKey > 0 );// }/*!  \return The command currently attached to \a key, or blank if none.*/QStringQmAccelManager::setTo( int key ) const{	for (QDictIterator<Key> it( m_Keys );  it.current(); ++it)	{		if ( usedKey( it.current() ) == key )			return it.current()->desc;	}	return QString::null;}/*!  \return The command currently attached to \a key, or blank if none.*/QStringQmAccelManager::commandName( int key ) const{	for (QDictIterator<Key> it( m_Keys );  it.current(); ++it)	{		if ( usedKey( it.current() ) == key )			return it.currentKey();	}	return QString::null;}/*!  \return The key for command \a command, or 0 if no key is set. */intQmAccelManager::key(	const QString &command) const{    if ( command.isEmpty() )        return 0;	Key *k = m_Keys[command];	return k ? usedKey( k ) : 0;}/*!  \return The default key for command \a command, or 0 if no key is set. */intQmAccelManager::defaultKey(	const QString &command) const{    if ( command.isEmpty() )        return 0;	Key *k = m_Keys[command];	return k ? k->defKey : 0;}/*!  \return the keytype for command \a command.*/QmAccelManager::KeyTypeQmAccelManager::keyType(    const QString &command ) const{    if ( command.isEmpty() )        return NoKey;	Key *k = m_Keys[command];    if ( !k )        return NoKey;    if ( k->modified )        return k->tmpValue.type;    else        return k->value.type;}/*!  Removes any key from command \a command and unregisters the last key if any.*/boolQmAccelManager::remove(	const QString& command,	bool apply){    if ( command.isEmpty() )        return true;	Key *k = m_Keys[command];	if (k)	{		if (apply)		{			m_pAccel->disconnectItem(k->id, k->receiver, k->slot);			m_pAccel->removeItem(k->id);			k->id = 0;            setNoKey( k, true );		}		else        {            setNoKey( k );        }	}	else		return false;	return true;}/*!  Sets the command \a command to use the default key and unregisters the last key if any.  Registers the default key if any.*/boolQmAccelManager::setDefault(	const QString& command,	bool apply){    if ( command.isEmpty() )        return true;	Key *k = m_Keys[command];	if (k)	{		if (apply)		{			m_pAccel->disconnectItem(k->id, k->receiver, k->slot);			m_pAccel->removeItem(k->id);			k->id = 0;            setDefaultKey( k, true );            int key = usedKey( k );            if ( key > 0 )            {                k->id = m_pAccel->insertItem(key);                m_pAccel->connectItem(k->id, k->receiver, k->slot);            }		}		else        {            setDefaultKey( k );        }	}	else		return false;	return true;}/*!  Bind or remove keys scheduled by calling functions with apply=false*/voidQmAccelManager::apply(){	Key *k;

⌨️ 快捷键说明

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