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 
00228     QString toString() const;
00229 
00233     QString toStringInternal() const;
00234 
00235  // Operation methods
00239     void simplify();
00240 
00247     static KKey& null();
00248 
00254     static QString modFlagLabel( ModFlag f );
00255 
00256  private:
00257     /*
00258      * Under X11, m_key will hold an X11 key symbol.
00259      * For Qt/Embedded, it will hold the Qt key code.
00260      */
00267     uint m_sym;
00271     uint m_mod;
00272 
00273  private:
00274     friend class KKeyNative;
00275 };
00276 
00284 class KKeySequence
00285 {
00286  public:
00288         enum { MAX_KEYS = 4 };
00289 
00296     KKeySequence();
00297 
00302     KKeySequence( const QKeySequence& keySeq );
00303 
00308     KKeySequence( const KKey& key );
00309 
00314     KKeySequence( const KKeyNative& key );
00315 
00320     KKeySequence( const KKeySequence& keySeq );
00321 
00330     KKeySequence( const QString& keySeq );
00331 
00332     ~KKeySequence();
00333 
00339     void clear();
00340 
00346     bool init( const QKeySequence& keySeq );
00347 
00353     bool init( const KKey& key );
00354 
00360     bool init( const KKeyNative& key );
00361 
00367     bool init( const KKeySequence& keySeq );
00368 
00378     bool init( const QString& key );
00379 
00383     KKeySequence& operator =( const KKeySequence& seq )
00384         { init( seq ); return *this; }
00385 
00391     uint count() const;
00392 
00401     const KKey& key( uint i ) const;
00402 
00406     bool isTriggerOnRelease() const;
00407 
00416     bool setKey( uint i, const KKey& key );
00417 
00425     bool isNull() const;
00426 
00432     bool startsWith( const KKeySequence& keySeq ) const;
00433 
00446     int compare( const KKeySequence& keySeq ) const;
00447 
00452     bool operator == ( const KKeySequence& seq ) const
00453         { return compare( seq ) == 0; }
00454 
00459     bool operator != ( const KKeySequence& seq ) const
00460         { return compare( seq ) != 0; }
00461 
00466     bool operator < ( const KKeySequence& seq ) const
00467         { return compare( seq ) < 0; }
00468     // TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence
00469 
00474     QKeySequence qt() const;
00475 
00482     int keyCodeQt() const;
00483 
00490     QString toString() const;
00491 
00495     QString toStringInternal() const;
00496 
00503     static KKeySequence& null();
00504 
00505  protected:
00506     uchar m_nKeys;
00507     uchar m_bTriggerOnRelease;
00508     // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0
00509     KKey m_rgvar[MAX_KEYS];
00510 
00511  private:
00512     class KKeySequencePrivate* d;
00513     friend class KKeyNative;
00514 };
00515 
00524 class KShortcut
00525 {
00526  public:
00531     enum { MAX_SEQUENCES = 2 };
00532 
00539     KShortcut();
00540 
00547     KShortcut( int keyQt );
00548 
00554     KShortcut( const QKeySequence& keySeq );
00555 
00561     KShortcut( const KKey& key );
00562 
00568     KShortcut( const KKeySequence& keySeq );
00569 
00574     KShortcut( const KShortcut& shortcut );
00575 
00583     KShortcut( const char* shortcut );
00584 
00592     KShortcut( const QString& shortcut );
00593     ~KShortcut();
00594 
00600     void clear();
00601 
00608     bool init( int keyQt );
00609 
00614     bool init( const QKeySequence& keySeq );
00615 
00620     bool init( const KKey& key );
00621 
00626     bool init( const KKeySequence& keySeq );
00627 
00632     bool init( const KShortcut& shortcut );
00633 
00641     bool init( const QString& shortcut );
00642 
00646     KShortcut& operator =( const KShortcut& cut )
00647         { init( cut ); return *this; }
00648 
00655     uint count() const;
00656 
00664     const KKeySequence& seq( uint i ) const;
00665 
00673     int keyCodeQt() const;
00674 
00682     bool isNull() const;
00683 
00697     int compare( const KShortcut& shortcut ) const;
00698 
00703     bool operator == ( const KShortcut& cut ) const
00704         { return compare( cut ) == 0; }
00705 
00710     bool operator != ( const KShortcut& cut ) const
00711         { return compare( cut ) != 0; }
00712 
00717     bool operator < ( const KShortcut& cut ) const
00718         { return compare( cut ) < 0; }
00719 
00726     bool contains( const KKey& key ) const;
00727 
00734     bool contains( const KKeyNative& key ) const;
00735 
00741     bool contains( const KKeySequence& keySeq ) const;
00742 
00752     bool setSeq( uint i, const KKeySequence& keySeq );
00753 
00761     bool append( const KKeySequence& keySeq );
00762 
00771     bool append( const KKey& spec );
00772 
00780     bool append( const KShortcut& cut );
00781 
00786     operator QKeySequence () const;
00787 
00795     QString toString() const;
00796 
00800     QString toStringInternal( const KShortcut* pcutDefault = 0 ) const;
00801 
00808     static KShortcut& null();
00809 
00810  protected:
00811     uint m_nSeqs;
00812     KKeySequence m_rgseq[MAX_SEQUENCES];
00813 
00814  private:
00815     class KShortcutPrivate* d;
00816     friend class KKeyNative;
00817 
00818 #ifndef KDE_NO_COMPAT
00819  public:
00820     operator int () const    { return keyCodeQt(); }
00821 #endif
00822 };
00823 
00824 #endif // __KSHORTCUT_H
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jan 21 09:57:10 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003