kshortcut.h
/* This file is part of the KDE libraries
Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KSHORTCUT_H
#define __KSHORTCUT_H
#include <qkeysequence.h>
#include <qstring.h>
#include "kdelibs_export.h"
class QKeyEvent;
class KKeyNative;
class KDECORE_EXPORT KKey
{
public:
enum { MOD_FLAG_COUNT = 4 };
enum { QtWIN = (Qt::META) };
enum ModFlag {
SHIFT = 0x01,
CTRL = 0x02,
ALT = 0x04,
WIN = 0x08
};
KKey();
KKey( int keyQt );
KKey( const QKeySequence& keySeq );
KKey( const QKeyEvent* keyEvent );
KKey( const KKey& key );
KKey( const QString& key );
KKey( uint key, uint mod );
~KKey();
// Initialization methods
void clear();
bool init( int keyQt );
bool init( const QKeySequence& keySeq );
bool init( const QKeyEvent* keyEvent );
bool init( const KKey& key );
bool init( const QString& key);
bool init( uint key, uint mod );
KKey& operator =( const KKey& key )
{ init( key ); return *this; }
// Query methods.
bool isNull() const;
uint sym() const;
uint modFlags() const;
// Comparison Methods
int compare( const KKey& key ) const;
bool operator == ( const KKey& key ) const
{ return compare( key ) == 0; }
bool operator != ( const KKey& key ) const
{ return compare( key ) != 0; }
bool operator < ( const KKey& key ) const
{ return compare( key ) < 0; }
// Conversion methods.
int keyCodeQt() const;
QString toString() const;
QString toStringInternal() const;
// Operation methods
void simplify();
static KKey& null();
static QString modFlagLabel( ModFlag f );
private:
/*
* Under X11, m_key will hold an X11 key symbol.
* For Qt/Embedded, it will hold the Qt key code.
*/
uint m_sym;
uint m_mod;
private:
friend class KKeyNative;
};
class KDECORE_EXPORT KKeySequence
{
public:
enum { MAX_KEYS = 4 };
KKeySequence();
KKeySequence( const QKeySequence& keySeq );
KKeySequence( const KKey& key );
KKeySequence( const KKeyNative& key );
KKeySequence( const KKeySequence& keySeq );
KKeySequence( const QString& keySeq );
~KKeySequence();
void clear();
bool init( const QKeySequence& keySeq );
bool init( const KKey& key );
bool init( const KKeyNative& key );
bool init( const KKeySequence& keySeq );
bool init( const QString& key );
KKeySequence& operator =( const KKeySequence& seq )
{ init( seq ); return *this; }
uint count() const;
const KKey& key( uint i ) const;
bool isTriggerOnRelease() const;
bool setKey( uint i, const KKey& key );
bool isNull() const;
bool startsWith( const KKeySequence& keySeq ) const;
int compare( const KKeySequence& keySeq ) const;
bool operator == ( const KKeySequence& seq ) const
{ return compare( seq ) == 0; }
bool operator != ( const KKeySequence& seq ) const
{ return compare( seq ) != 0; }
bool operator < ( const KKeySequence& seq ) const
{ return compare( seq ) < 0; }
// TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence
QKeySequence qt() const;
int keyCodeQt() const;
QString toString() const;
QString toStringInternal() const;
static KKeySequence& null();
protected:
uchar m_nKeys;
uchar m_bTriggerOnRelease;
// BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0
KKey m_rgvar[MAX_KEYS];
private:
class KKeySequencePrivate* d;
friend class KKeyNative;
};
class KDECORE_EXPORT KShortcut
{
public:
enum { MAX_SEQUENCES = 2 };
KShortcut();
KShortcut( int keyQt );
KShortcut( const QKeySequence& keySeq );
KShortcut( const KKey& key );
KShortcut( const KKeySequence& keySeq );
KShortcut( const KShortcut& shortcut );
KShortcut( const char* shortcut );
KShortcut( const QString& shortcut );
~KShortcut();
void clear();
bool init( int keyQt );
bool init( const QKeySequence& keySeq );
bool init( const KKey& key );
bool init( const KKeySequence& keySeq );
bool init( const KShortcut& shortcut );
bool init( const QString& shortcut );
KShortcut& operator =( const KShortcut& cut )
{ init( cut ); return *this; }
uint count() const;
const KKeySequence& seq( uint i ) const;
int keyCodeQt() const;
bool isNull() const;
int compare( const KShortcut& shortcut ) const;
bool operator == ( const KShortcut& cut ) const
{ return compare( cut ) == 0; }
bool operator != ( const KShortcut& cut ) const
{ return compare( cut ) != 0; }
bool operator < ( const KShortcut& cut ) const
{ return compare( cut ) < 0; }
bool contains( const KKey& key ) const;
bool contains( const KKeyNative& key ) const;
bool contains( const KKeySequence& keySeq ) const;
bool setSeq( uint i, const KKeySequence& keySeq );
bool append( const KKeySequence& keySeq );
void remove( const KKeySequence& keySeq );
bool append( const KKey& spec );
bool append( const KShortcut& cut );
operator QKeySequence () const;
QString toString() const;
QString toStringInternal( const KShortcut* pcutDefault = 0 ) const;
static KShortcut& null();
protected:
uint m_nSeqs;
KKeySequence m_rgseq[MAX_SEQUENCES];
private:
class KShortcutPrivate* d;
friend class KKeyNative;
#ifndef KDE_NO_COMPAT
public:
operator int () const { return keyCodeQt(); }
#endif
};
#endif // __KSHORTCUT_H
KKey::ModFlag
ModFlag
Flags to represent the modifiers.
Definition: kshortcut.h:53
KShortcut
The KShortcut class is used to represent a keyboard shortcut to an action.
Definition: kshortcut.h:543
KKeySequence
A KKeySequence object holds a sequence of up to 4 keys.
Definition: kshortcut.h:288
KKeyNative::keyCodeQt
int keyCodeQt() const
Returns the qt key code.
KKeyNative
Representation of a key in the format native of the windowing system (eg.
Definition: kkeynative.h:37
KKey
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
Definition: kshortcut.h:40

KDE Home | KDE Accessibility Home | Description of Access Keys