kshortcut.h Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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
    00029 /*
    00030 * A KKey object represents a single key with possible modifiers
    00031 * (Shift, Ctrl, Alt, Win).  It can represent both keys which are
    00032 * understood by Qt as well as those which are additionally supported
    00033 * by the underlying system (e.g. X11).
    00034 * @see KKeyNative
    00035 * @see KKeySequence
    00036 * @see KShortcut
    00037 */
    00038
    00039 class KKey
    00040 {
    00041  public:
    00046         enum { MOD_FLAG_COUNT = 4 };
    00047         enum { QtWIN = (Qt::ALT << 1) };
    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& );
    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         bool isValidQt() const;
    00178
    00182         bool isValidNative() const;
    00183
    00187         uint sym() const;
    00191         uint modFlags() const;
    00192
    00193  // Comparison Methods
    00204         int compare( const KKey& key ) const;
    00205
    00210         bool operator == ( const KKey& key ) const
    00211                 { return compare( key ) == 0; }
    00216         bool operator != ( const KKey& key ) const
    00217                 { return compare( key ) != 0; }
    00222         bool operator < ( const KKey& key ) const
    00223                 { return compare( key ) < 0; }
    00224
    00225  // Conversion methods.
    00231         int keyCodeQt() const;
    00232
    00238         QString toString() const;
    00239
    00243         QString toStringInternal() const;
    00244
    00245  // Operation methods
    00249         void simplify();
    00250
    00257         static KKey& null();
    00258
    00264         static QString modFlagLabel( ModFlag f );
    00265
    00266  private:
    00267         /*
    00268          * Under X11, m_key will hold an X11 key symbol.
    00269          * For Qt/Embedded, it will hold the Qt key code.
    00270          */
    00277         uint m_sym;
    00281         uint m_mod;
    00282
    00283  private:
    00284         friend class KKeyNative;
    00285 };
    00286
    00294 class KKeySequence
    00295 {
    00296  public:
    00298         enum { MAX_KEYS = 4 };
    00299
    00306         KKeySequence();
    00307
    00312         KKeySequence( const QKeySequence& keySeq );
    00313
    00318         KKeySequence( const KKey& key );
    00319
    00324         KKeySequence( const KKeyNative& key );
    00325
    00330         KKeySequence( const KKeySequence& keySeq );
    00331
    00340         KKeySequence( const QString& keySeq );
    00341
    00342         ~KKeySequence();
    00343
    00349         void clear();
    00350
    00356         bool init( const QKeySequence& keySeq );
    00357
    00363         bool init( const KKey& key );
    00364
    00370         bool init( const KKeyNative& key );
    00371
    00377         bool init( const KKeySequence& keySeq );
    00378
    00388         bool init( const QString& key );
    00389
    00393         KKeySequence& operator =( const KKeySequence& seq )
    00394                 { init( seq ); return *this; }
    00395
    00401         uint count() const;
    00402
    00411         const KKey& key( uint i ) const;
    00412
    00416         bool isTriggerOnRelease() const;
    00417
    00426         bool setKey( uint i, const KKey& key );
    00427
    00431         void setTriggerOnRelease( bool );
    00432
    00440         bool isNull() const;
    00441
    00447         bool startsWith( const KKeySequence& keySeq ) const;
    00448
    00461         int compare( const KKeySequence& keySeq ) const;
    00462
    00467         bool operator == ( const KKeySequence& seq ) const
    00468                 { return compare( seq ) == 0; }
    00469
    00474         bool operator != ( const KKeySequence& seq ) const
    00475                 { return compare( seq ) != 0; }
    00476
    00481         bool operator < ( const KKeySequence& seq ) const
    00482                 { return compare( seq ) < 0; }
    00483         // TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence
    00484
    00489         QKeySequence qt() const;
    00490
    00497         int keyCodeQt() const;
    00498
    00505         QString toString() const;
    00506
    00510         QString toStringInternal() const;
    00511
    00518         static KKeySequence& null();
    00519
    00520  protected:
    00521         uchar m_nKeys;
    00522         uchar m_bTriggerOnRelease;
    00523         // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0
    00524         KKey m_rgvar[MAX_KEYS];
    00525
    00526  private:
    00527         class KKeySequencePrivate* d;
    00528         friend class KKeyNative;
    00529 };
    00530
    00531 /*
    00532 * The KShortcut class is used to represent a keyboard shortcut to an action.
    00533 * A shortcut is normally a single key with modifiers, such as Ctrl+V.
    00534 * A KShortcut object may also contain an alternate key which will also
    00535 * activate the action it's associated to, as long as no other actions have
    00536 * defined that key as their primary key.  Ex: Ctrl+V;Shift+Insert.
    00537 */
    00538
    00539 class KShortcut
    00540 {
    00541  public:
    00546         enum { MAX_SEQUENCES = 2 };
    00547
    00554         KShortcut();
    00555
    00562         KShortcut( int keyQt );
    00563
    00569         KShortcut( const QKeySequence& keySeq );
    00570
    00576         KShortcut( const KKey& key );
    00577
    00583         KShortcut( const KKeySequence& keySeq );
    00584
    00589         KShortcut( const KShortcut& shortcut );
    00590
    00598         KShortcut( const char* shortcut );
    00599
    00607         KShortcut( const QString& shortcut );
    00608         ~KShortcut();
    00609
    00615         void clear();
    00616
    00623         bool init( int keyQt );
    00624
    00629         bool init( const QKeySequence& keySeq );
    00630
    00635         bool init( const KKey& key );
    00636
    00641         bool init( const KKeySequence& keySeq );
    00642
    00647         bool init( const KShortcut& shortcut );
    00648
    00656         bool init( const QString& shortcut );
    00657
    00661         KShortcut& operator =( const KShortcut& cut )
    00662                 { init( cut ); return *this; }
    00663
    00670         uint count() const;
    00671
    00679         const KKeySequence& seq( uint i ) const;
    00680
    00688         int keyCodeQt() const;
    00689
    00697         bool isNull() const;
    00698
    00712         int compare( const KShortcut& shortcut ) const;
    00713
    00718         bool operator == ( const KShortcut& cut ) const
    00719                 { return compare( cut ) == 0; }
    00720
    00725         bool operator != ( const KShortcut& cut ) const
    00726                 { return compare( cut ) != 0; }
    00727
    00732         bool operator < ( const KShortcut& cut ) const
    00733                 { return compare( cut ) < 0; }
    00734
    00741         bool contains( const KKey& key ) const;
    00742
    00749         bool contains( const KKeyNative& key ) const;
    00750
    00756         bool contains( const KKeySequence& keySeq ) const;
    00757
    00767         bool setSeq( uint i, const KKeySequence& keySeq );
    00768
    00776         bool append( const KKeySequence& keySeq );
    00777
    00782         operator QKeySequence () const;
    00783
    00791         QString toString() const;
    00792
    00796         QString toStringInternal( const KShortcut* pcutDefault = 0 ) const;
    00797
    00804         static KShortcut& null();
    00805
    00806  protected:
    00807         uint m_nSeqs;
    00808         KKeySequence m_rgseq[MAX_SEQUENCES];
    00809
    00810  private:
    00811         class KShortcutPrivate* d;
    00812         friend class KKeyNative;
    00813
    00814 #ifndef KDE_NO_COMPAT
    00815  public:
    00816         operator int () const    { return keyCodeQt(); }
    00817 #endif
    00818 };
    00819
    00820 #endif // __KSHORTCUT_H

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:52 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001