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

📄 globalaccel.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* globalaccel.cpp *   * This file is a slightly modified version of kglobalaccel.cpp from * the KDE libraries, to be used with apollo without the KDE dependencies. * * $Id: globalaccel.cpp,v 1.5 2002/03/13 15:09:36 amos Exp $ *  * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>, *                     Jani Jaakkola (jjaakkol@cs.helsinki.fi), *                     Nicolas Hadacek <hadacek@via.ecp.fr> *                     Matthias Ettrich (ettrich@kde.org) * * 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 "globalaccel.h"#include "qmapplication.h"#include "qmconfig.h"#include <qkeycode.h>#include <qlayout.h>#include <qpainter.h>#include <qapplication.h>#include <qdrawutil.h>#include <X11/X.h>#include <X11/Xlib.h>#include <X11/keysym.h>#include <string.h>#include <iostream>#ifdef KeyPressconst int XKeyPress = KeyPress;#undef KeyPress#endif// from KAccel from the KDE librariesvoid KeyEntry::operator=(const KeyEntry& e) {    aCurrentKeyCode = e.aCurrentKeyCode;    aDefaultKeyCode = e.aDefaultKeyCode;    aConfigKeyCode = e.aConfigKeyCode;    bConfigurable = e.bConfigurable;    bEnabled = e.bEnabled;    aAccelId = e.aAccelId;    receiver = e.receiver;    member = e.member;    descr = e.descr;    menuId = e.menuId;    menu = e.menu;}KeyEntry::KeyEntry() {    aCurrentKeyCode = 0;    aDefaultKeyCode = 0;    aConfigKeyCode = 0;    bConfigurable = false;    bEnabled = false;    aAccelId = 0;    receiver = 0;    member = 0;    menuId = 0;    menu = 0;}KeyEntry::KeyEntry(const KeyEntry& e) {    *this = e;}// end KAccel// NOTE ABOUT CONFIGURATION CHANGES// Test if keys enabled because these keys have made X server grabsclass  GlobalAccelPrivate : public QWidget{public:    GlobalAccelPrivate( GlobalAccel* a)        :QWidget(), accel( a )        {            QmApp->installX11EventFilter( this );        }protected:    bool x11Event( XEvent * e )        {            return accel->x11EventFilter( e );        }private:    GlobalAccel* accel;};GlobalAccel::GlobalAccel(bool _do_not_grab)    : QObject(){    aAvailableId = 1;    bEnabled = true;    aGroup = "Global Keys";    do_not_grab =_do_not_grab;    d = 0;    if ( !do_not_grab )        d = new GlobalAccelPrivate( this );}GlobalAccel::GlobalAccel(QWidget * parent, const char *name, bool _do_not_grab)    : QObject(parent, name) {    aAvailableId = 1;    bEnabled = true;    aGroup = "Global Keys";    do_not_grab =_do_not_grab;    d = 0;    if ( !do_not_grab )        d = new GlobalAccelPrivate( this );}GlobalAccel::~GlobalAccel(){    setEnabled( false );    delete d;}voidGlobalAccel::setKeys(QWidget *mainwin){	QmConfig *conf = QmConfig::instance();	QString key;	conf->get("key", "prev", key);	if (!key.isEmpty())		if ( insertItem("Apollo Skip Backward", "apollo-skip-backward", key) )			connectItem("apollo-skip-backward", mainwin, SLOT(prev()));	conf->get("key", "next", key);	if (!key.isEmpty())		if ( insertItem("Apollo Skip Forward", "apollo-skip-forward", key) )			connectItem("apollo-skip-forward", mainwin, SLOT(next()));		conf->get("key", "play", key);	if (!key.isEmpty())		if ( insertItem("Apollo Play", "apollo-play", key) )			connectItem("apollo-play", mainwin, SLOT(play()));	conf->get("key", "stop", key);	if (!key.isEmpty())		if ( insertItem("Apollo Stop", "apollo-stop", key) )			connectItem("apollo-stop", mainwin, SLOT(stop()));}void GlobalAccel::clear(){    setEnabled( false );    aKeyMap.clear();}void GlobalAccel::connectItem( const QString& action,                               const QObject* receiver, const char *member,                               bool activate ){    if (!aKeyMap.contains(action)) {        std::cerr << QString::fromLatin1("GlobalAccel : Cannot connect action %1 "                                    "which is not in the object dictionary\n").arg(action);        return;    }            KeyEntry entry = aKeyMap[ action ];    entry.receiver = receiver;    entry.member = member;    entry.aAccelId = aAvailableId;    aKeyMap.replace(action, entry);    aAvailableId++;    setItemEnabled( action, activate );}uint GlobalAccel::count() const{    return aKeyMap.count();}int GlobalAccel::currentKey( const QString& action ) const{    KeyEntry entry = aKeyMap[ action ];    return entry.aCurrentKeyCode;}int GlobalAccel::defaultKey( const QString& action ) const{    KeyEntry entry = aKeyMap[ action ];    return entry.aDefaultKeyCode;}void GlobalAccel::disconnectItem( const QString& action,                                  const QObject* /*receiver*/, const char */*member*/ ){    // TODO    KeyEntry entry = aKeyMap[ action ];}QString GlobalAccel::findKey( int key ) const{    for (KeyEntryMap::ConstIterator aKeyIt = aKeyMap.begin();         aKeyIt != aKeyMap.end(); ++aKeyIt)        if ( key == (*aKeyIt).aCurrentKeyCode )            return aKeyIt.key();    return QString::null; }bool grabFailed;extern "C" {    static int XGrabErrorHandler( Display *, XErrorEvent *e ) {        if ( e->error_code != BadAccess ) {            std::cerr << "grabKey: got X error " << e->type << " instead of BadAccess\n";        }        grabFailed = true;        return 0;    }}bool GlobalAccel::grabKey( uint keysym, uint mod ) {    // Most of this comes from kpanel/main.C    // Copyright (C) 1996,97 Matthias Ettrich    static int NumLockMask = 0;    if (do_not_grab)        return true;    if (!keysym || !XKeysymToKeycode(qt_xdisplay(), keysym)) return false;    if (!NumLockMask){        XModifierKeymap* xmk = XGetModifierMapping(qt_xdisplay());        int i;        for (i=0; i<8; i++){            if (xmk->modifiermap[xmk->max_keypermod * i] ==                XKeysymToKeycode(qt_xdisplay(), XK_Num_Lock))                NumLockMask = (1<<i);        }        XFreeModifiermap(xmk);    }    grabFailed = false;    // We wan't to catch only our own errors    XSync(qt_xdisplay(),0);    XErrorHandler savedErrorHandler=XSetErrorHandler(XGrabErrorHandler);            XGrabKey(qt_xdisplay(),             XKeysymToKeycode(qt_xdisplay(), keysym), mod,             qt_xrootwin(), True,             GrabModeAsync, GrabModeSync);    XGrabKey(qt_xdisplay(),             XKeysymToKeycode(qt_xdisplay(), keysym), mod | LockMask,             qt_xrootwin(), True,             GrabModeAsync, GrabModeSync);    XGrabKey(qt_xdisplay(),             XKeysymToKeycode(qt_xdisplay(), keysym), mod | NumLockMask,             qt_xrootwin(), True,             GrabModeAsync, GrabModeSync);    XGrabKey(qt_xdisplay(),             XKeysymToKeycode(qt_xdisplay(), keysym), mod | LockMask | NumLockMask,             qt_xrootwin(), True,             GrabModeAsync, GrabModeSync);    XSync(qt_xdisplay(),0);    XSetErrorHandler(savedErrorHandler);            if (grabFailed) {        // FIXME: ungrab all successfull grabs!        //warning("Global grab failed!");        return false;    }    return true;}bool GlobalAccel::insertItem(  const QString& descr, const QString& action, int keyCode,                               bool configurable ){    if (aKeyMap.contains(action))        removeItem( action );            KeyEntry entry;    entry.aDefaultKeyCode = keyCode;    entry.aCurrentKeyCode = keyCode;    entry.bConfigurable = configurable;    entry.bEnabled = false;    entry.aAccelId = 0;    entry.receiver = 0;    entry.member = 0;    entry.descr = descr;    aKeyMap[action] = entry;    return true;}bool GlobalAccel::insertItem( const QString& descr, const QString& action,                              const QString& keyCode, bool configurable ){    int iKeyCode = stringToKey( keyCode );    return insertItem(descr, action, iKeyCode, configurable);}bool GlobalAccel::isEnabled() const{    return bEnabled;}bool GlobalAccel::isItemEnabled( const QString& action ) const{    return aKeyMap[action].bEnabled;}KeyEntryMap GlobalAccel::keyDict() const{    return aKeyMap;}void GlobalAccel::readSettings(){

⌨️ 快捷键说明

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