kdecore Library API Documentation

kshortcut.h

00001 /*  This file is part of the KDE libraries
00002     Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017     Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __KSHORTCUT_H
00021 #define __KSHORTCUT_H
00022 
00023 #include <qkeysequence.h>
00024 #include <qstring.h>
00025 
00026 class QKeyEvent;
00027 class KKeyNative;
00028 
00039 class KKey
00040 {
00041  public:
00046     enum { MOD_FLAG_COUNT = 4 };
00047     enum { QtWIN = (Qt::META) };
00052     enum ModFlag {
00053         SHIFT = 0x01,
00054         CTRL = 0x02,
00055         ALT = 0x04,
00056         WIN = 0x08
00057     };
00058 
00065     KKey();
00066 
00072     KKey( int keyQt );
00073 
00078     KKey( const QKeySequence& keySeq );
00079 
00084     KKey( const QKeyEvent* keyEvent );
00085 
00089     KKey( const KKey& key );
00090 
00099     KKey( const QString& key );
00103     KKey( uint key, uint mod );
00104     ~KKey();
00105 
00106  // Initialization methods
00111     void clear();
00112 
00119     bool init( int keyQt );
00120 
00126     bool init( const QKeySequence& keySeq );
00127 
00133     bool init( const QKeyEvent* keyEvent );
00134 
00140     bool init( const KKey& key );
00141 
00151     bool init( const QString& key);
00152 
00156     bool init( uint key, uint mod );
00157 
00161     KKey& operator =( const KKey& key )
00162         { init( key ); return *this; }
00163 
00164  // Query methods.
00172     bool isNull() const;
00173 
00177     uint sym() const;
00181     uint modFlags() const;
00182 
00183  // Comparison Methods
00194     int compare( const KKey& key ) const;
00195 
00200     bool operator == ( const KKey& key ) const
00201         { return compare( key ) == 0; }
00206     bool operator != ( const KKey& key ) const
00207         { return compare( key ) != 0; }
00212     bool operator < ( const KKey& key ) const
00213         { return compare( key ) < 0; }
00214 
00215  // Conversion methods.
00221     int keyCodeQt() const;
00222 
00230     QString toString() const;
00231 
00236     QString toStringInternal() const;
00237 
00238  // Operation methods
00242     void simplify();
00243 
00250     static KKey& null();
00251 
00257     static QString modFlagLabel( ModFlag f );
00258 
00259  private:
00260     /*
00261      * Under X11, m_key will hold an X11 key symbol.
00262      * For Qt/Embedded, it will hold the Qt key code.
00263      */
00270     uint m_sym;
00274     uint m_mod;
00275 
00276  private:
00277     friend class KKeyNative;
00278 };
00279 
00287 class KKeySequence
00288 {
00289  public:
00291         enum { MAX_KEYS = 4 };
00292 
00299     KKeySequence();
00300 
00305     KKeySequence( const QKeySequence& keySeq );
00306 
00311     KKeySequence( const KKey& key );
00312 
00317     KKeySequence( const KKeyNative& key );
00318 
00323     KKeySequence( const KKeySequence& keySeq );
00324 
00333     KKeySequence( const QString& keySeq );
00334 
00335     ~KKeySequence();
00336 
00342     void clear();
00343 
00349     bool init( const QKeySequence& keySeq );
00350 
00356     bool init( const KKey& key );
00357 
00363     bool init( const KKeyNative& key );
00364 
00370     bool init( const KKeySequence& keySeq );
00371 
00381     bool init( const QString& key );
00382 
00386     KKeySequence& operator =( const KKeySequence& seq )
00387         { init( seq ); return *this; }
00388 
00394     uint count() const;
00395 
00404     const KKey& key( uint i ) const;
00405 
00409     bool isTriggerOnRelease() const;
00410 
00419     bool setKey( uint i, const KKey& key );
00420 
00428     bool isNull() const;
00429 
00435     bool startsWith( const KKeySequence& keySeq ) const;
00436 
00449     int compare( const KKeySequence& keySeq ) const;
00450 
00455     bool operator == ( const KKeySequence& seq ) const
00456         { return compare( seq ) == 0; }
00457 
00462     bool operator != ( const KKeySequence& seq ) const
00463         { return compare( seq ) != 0; }
00464 
00469     bool operator < ( const KKeySequence& seq ) const
00470         { return compare( seq ) < 0; }
00471     // TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence
00472 
00477     QKeySequence qt() const;
00478 
00485     int keyCodeQt() const;
00486 
00493     QString toString() const;
00494 
00498     QString toStringInternal() const;
00499 
00506     static KKeySequence& null();
00507 
00508  protected:
00509     uchar m_nKeys;
00510     uchar m_bTriggerOnRelease;
00511     // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0
00512     KKey m_rgvar[MAX_KEYS];
00513 
00514  private:
00515     class KKeySequencePrivate* d;
00516     friend class KKeyNative;
00517 };
00518 
00527 class KShortcut
00528 {
00529  public:
00534     enum { MAX_SEQUENCES = 2 };
00535 
00542     KShortcut();
00543 
00550     KShortcut( int keyQt );
00551 
00557     KShortcut( const QKeySequence& keySeq );
00558 
00564     KShortcut( const KKey& key );
00565 
00571     KShortcut( const KKeySequence& keySeq );
00572 
00577     KShortcut( const KShortcut& shortcut );
00578 
00586     KShortcut( const char* shortcut );
00587 
00595     KShortcut( const QString& shortcut );
00596     ~KShortcut();
00597 
00603     void clear();
00604 
00611     bool init( int keyQt );
00612 
00617     bool init( const QKeySequence& keySeq );
00618 
00623     bool init( const KKey& key );
00624 
00629     bool init( const KKeySequence& keySeq );
00630 
00635     bool init( const KShortcut& shortcut );
00636 
00644     bool init( const QString& shortcut );
00645 
00649     KShortcut& operator =( const KShortcut& cut )
00650         { init( cut ); return *this; }
00651 
00658     uint count() const;
00659 
00667     const KKeySequence& seq( uint i ) const;
00668 
00676     int keyCodeQt() const;
00677 
00685     bool isNull() const;
00686 
00700     int compare( const KShortcut& shortcut ) const;
00701 
00706     bool operator == ( const KShortcut& cut ) const
00707         { return compare( cut ) == 0; }
00708 
00713     bool operator != ( const KShortcut& cut ) const
00714         { return compare( cut ) != 0; }
00715 
00720     bool operator < ( const KShortcut& cut ) const
00721         { return compare( cut ) < 0; }
00722 
00729     bool contains( const KKey& key ) const;
00730 
00737     bool contains( const KKeyNative& key ) const;
00738 
00744     bool contains( const KKeySequence& keySeq ) const;
00745 
00755     bool setSeq( uint i, const KKeySequence& keySeq );
00756 
00764     bool append( const KKeySequence& keySeq );
00765 
00771     void remove( const KKeySequence& keySeq );
00772 
00781     bool append( const KKey& spec );
00782 
00790     bool append( const KShortcut& cut );
00791 
00796     operator QKeySequence () const;
00797 
00805     QString toString() const;
00806 
00810     QString toStringInternal( const KShortcut* pcutDefault = 0 ) const;
00811 
00818     static KShortcut& null();
00819 
00820  protected:
00821     uint m_nSeqs;
00822     KKeySequence m_rgseq[MAX_SEQUENCES];
00823 
00824  private:
00825     class KShortcutPrivate* d;
00826     friend class KKeyNative;
00827 
00828 #ifndef KDE_NO_COMPAT
00829  public:
00830     operator int () const    { return keyCodeQt(); }
00831 #endif
00832 };
00833 
00834 #endif // __KSHORTCUT_H
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:43:46 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003