home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kshortcut.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  22.0 KB  |  852 lines

  1. /*  This file is part of the KDE libraries
  2.     Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __KSHORTCUT_H
  21. #define __KSHORTCUT_H
  22.  
  23. #include <qkeysequence.h>
  24. #include <qstring.h>
  25. #include "kdelibs_export.h"
  26.  
  27. class QKeyEvent;
  28. class KKeyNative;
  29.  
  30. /**
  31. * A KKey object represents a single key with possible modifiers
  32. * (Shift, Ctrl, Alt, Win).  It can represent both keys which are
  33. * understood by Qt as well as those which are additionally supported
  34. * by the underlying system (e.g. X11).
  35. * @see KKeyNative
  36. * @see KKeySequence
  37. * @see KShortcut
  38. */
  39.  
  40. class KDECORE_EXPORT KKey
  41. {
  42.  public:
  43.         /**
  44.      * The number of flags.
  45.      * @see ModFlag
  46.      */
  47.     enum { MOD_FLAG_COUNT = 4 };
  48.     enum { QtWIN = (Qt::META) };
  49.     /**
  50.      * Flags to represent the modifiers. You can combine modifiers
  51.      * by ORing them.
  52.      */
  53.     enum ModFlag {
  54.         SHIFT = 0x01,
  55.         CTRL = 0x02,
  56.         ALT = 0x04,
  57.         WIN = 0x08
  58.     };
  59.  
  60.     /**
  61.      * Creates a new null KKey.
  62.      * @see clear()
  63.      * @see isNull()
  64.      * @see null()
  65.      */
  66.     KKey();
  67.  
  68.     /**
  69.      * Creates a new key for the given Qt key code.
  70.      * @param keyQt the qt keycode
  71.      * @see Qt::Key
  72.      */
  73.     KKey( int keyQt );
  74.  
  75.     /**
  76.      * Creates a new key from the first key code of the given key sequence.
  77.      * @param keySeq the key sequence that contains the key
  78.      */
  79.     KKey( const QKeySequence& keySeq );
  80.  
  81.     /**
  82.      * Extracts the key from the given key event.
  83.      * @param keyEvent the key event to get the key from
  84.      */
  85.     KKey( const QKeyEvent* keyEvent );
  86.  
  87.     /**
  88.      * Copy constructor.
  89.      */
  90.     KKey( const KKey& key );
  91.  
  92.     /**
  93.      * Creates a new key from the given description. The form of the description
  94.      * is "[modifier+[modifier+]]+key", for example "e", "CTRL+q" or
  95.      * "CTRL+ALT+DEL". Allowed modifiers are "SHIFT", "CTRL", "ALT", "WIN" and
  96.      * "META". "WIN" and "META" are equivalent. Modifiers are not case-sensitive.
  97.      * @param key the description of the key
  98.      * @see KKeyServer::Sym::init()
  99.      */
  100.     KKey( const QString& key );
  101.     /**
  102.      * @internal
  103.      */
  104.     KKey( uint key, uint mod );
  105.     ~KKey();
  106.  
  107.  // Initialization methods
  108.     /**
  109.      * Clears the key. The key is null after calling this function.
  110.      * @see isNull()
  111.      */
  112.     void clear();
  113.  
  114.     /**
  115.      * Initializes the key with the given Qt key code.
  116.      * @param keyQt the qt keycode
  117.      * @return true if successful, false otherwise
  118.      * @see Qt::Key
  119.      */
  120.     bool init( int keyQt );
  121.  
  122.     /**
  123.      * Initializes the key with the first key code of the given key sequence.
  124.      * @param keySeq the key sequence that contains the key
  125.      * @return true if successful, false otherwise
  126.      */
  127.     bool init( const QKeySequence& keySeq );
  128.  
  129.     /**
  130.      * Initializes the key by extracting the code from the given key event.
  131.      * @param keyEvent the key event to get the key from
  132.      * @return true if successful, false otherwise
  133.      */
  134.     bool init( const QKeyEvent* keyEvent );
  135.  
  136.     /**
  137.      * Copies the given key.
  138.      * @param key the key to copy
  139.      * @return true if successful, false otherwise
  140.      */
  141.     bool init( const KKey& key );
  142.  
  143.     /**
  144.      * Initializes the key with the given description. The form of the description
  145.      * is "[modifier+[modifier+]]+key", for example "e", "CTRL+q" or
  146.      * "CTRL+ALT+DEL". Allowed modifiers are "SHIFT", "CTRL", "ALT", "WIN" and
  147.      * "META". "WIN" and "META" are equivalent. Modifiers are not case-sensitive.
  148.      * @param key the description of the key
  149.      * @return true if successful, false otherwise
  150.      * @see KKeyServer::Sym::init()
  151.      */
  152.     bool init( const QString& key);
  153.  
  154.     /**
  155.      * @internal
  156.      */
  157.     bool init( uint key, uint mod );
  158.  
  159.     /**
  160.      * Copies the key.
  161.      */
  162.     KKey& operator =( const KKey& key )
  163.         { init( key ); return *this; }
  164.  
  165.  // Query methods.
  166.     /**
  167.      * Returns true if the key is null (after clear() or empty
  168.      * constructor).
  169.      * @return true if the key is null
  170.      * @see clear()
  171.      * @see null()
  172.      */
  173.     bool isNull() const;
  174.  
  175.     /**
  176.      * @internal
  177.      */
  178.     uint sym() const;
  179.     /**
  180.      * @internal
  181.      */
  182.     uint modFlags() const;
  183.  
  184.  // Comparison Methods
  185.     /**
  186.      * Compares this key with the given KKey object. Returns a negative
  187.      * number if the given KKey is larger, 0 if they are equal and
  188.      * a positive number this KKey is larger. The returned value
  189.      * is the difference between the symbol or, if the symbols
  190.      * are equal, the difference between the encoded modifiers.
  191.      * @param key the key to compare with this key
  192.      * @return a negative number if the given KKey is larger, 0 if
  193.      * they are equal and a positive number this KKey is larger
  194.      */
  195.     int compare( const KKey& key ) const;
  196.  
  197.     /**
  198.      * Compares the symbol and modifiers of both keys.
  199.      * @see compare()
  200.      */
  201.     bool operator == ( const KKey& key ) const
  202.         { return compare( key ) == 0; }
  203.     /**
  204.      * Compares the symbol and modifiers of both keys.
  205.      * @see compare()
  206.      */
  207.     bool operator != ( const KKey& key ) const
  208.         { return compare( key ) != 0; }
  209.     /**
  210.      * Compares the symbol and modifiers of both keys.
  211.      * @see compare()
  212.      */
  213.     bool operator < ( const KKey& key ) const
  214.         { return compare( key ) < 0; }
  215.  
  216.  // Conversion methods.
  217.     /**
  218.      * Returns the qt key code.
  219.      * @return the qt key code or 0 if there is no key set.
  220.      * @see Qt::Key
  221.      */
  222.     int keyCodeQt() const;
  223.  
  224.     /**
  225.      * Returns a human-readable representation of the key in the form
  226.      * "modifier+key". Note that the representation is localised,
  227.      * use toStringInternal() for cases like saving to configuration files.
  228.      * @return the string representation of the key
  229.      * @see toStringInternal()
  230.      */
  231.     QString toString() const;
  232.  
  233.     /**
  234.      * Returns an untranslated text representation of the key in the form
  235.      * "modifier+key", suitable e.g. for saving in configuration files.
  236.      */
  237.     QString toStringInternal() const;
  238.  
  239.  // Operation methods
  240.     /**
  241.      * @internal
  242.      */
  243.     void simplify();
  244.  
  245.     /**
  246.      * Returns a null key.
  247.      * @return the null key
  248.      * @see isNull()
  249.      * @see clear()
  250.      */
  251.     static KKey& null();
  252.  
  253.     /**
  254.      * Returns a user-readable representation of the given modifiers.
  255.      * @param f the modifiers to convert
  256.      * @return the string representation of the modifiers
  257.      */
  258.     static QString modFlagLabel( ModFlag f );
  259.  
  260.  private:
  261.     /*
  262.      * Under X11, m_key will hold an X11 key symbol.
  263.      * For Qt/Embedded, it will hold the Qt key code.
  264.      */
  265.     /**
  266.      * Returns the native key symbol value key.  Under X11, this is the X
  267.      * keycode.  Under Qt/Embedded, this is the Qt keycode.
  268.      * @see /usr/include/X11/keysymdef.h
  269.      * @see qnamespace.h
  270.      */
  271.     uint m_sym;
  272.     /**
  273.      * m_mod holds the
  274.      */
  275.     uint m_mod;
  276.  
  277.  private:
  278.     friend class KKeyNative;
  279. };
  280.  
  281. /**
  282. * A KKeySequence object holds a sequence of up to 4 keys.
  283. * Ex: Ctrl+X,I
  284. * @see KKey
  285. * @see KShortcut
  286. */
  287.  
  288. class KDECORE_EXPORT KKeySequence
  289. {
  290.  public:
  291.         /// Defines the maximum length of the key sequence
  292.         enum { MAX_KEYS = 4 };
  293.  
  294.     /**
  295.      * Create a new null key sequence.
  296.      * @see isNull()
  297.      * @see null()
  298.      * @see clear()
  299.      */
  300.     KKeySequence();
  301.  
  302.     /**
  303.      * Copies the given qt key sequence.
  304.      * @param keySeq the qt key sequence to copy
  305.      */
  306.     KKeySequence( const QKeySequence& keySeq );
  307.  
  308.     /**
  309.      * Create a new key sequence that only contains the given key.
  310.      * @param key the key to add
  311.      */
  312.     KKeySequence( const KKey& key );
  313.  
  314.     /**
  315.      * Create a new key sequence that only contains the given key.
  316.      * @param key the key to add
  317.      */
  318.     KKeySequence( const KKeyNative& key );
  319.  
  320.     /**
  321.      * Copies the given key sequence.
  322.      * @param keySeq the key sequence to copy
  323.      */
  324.     KKeySequence( const KKeySequence& keySeq );
  325.  
  326.     /**
  327.      * Creates a new key sequence that contains the given key sequence.
  328.      * The description consists of comma-separated keys as
  329.      * required by KKey::KKey(const QString&).
  330.      * @param keySeq the description of the key
  331.      * @see KKeyServer::Sym::init()
  332.      * @see KKey::KKey(const QString&)
  333.      */
  334.     KKeySequence( const QString& keySeq );
  335.  
  336.     ~KKeySequence();
  337.  
  338.     /**
  339.      * Clears the key sequence. The key sequence is null after calling this
  340.      * function.
  341.      * @see isNull()
  342.      */
  343.     void clear();
  344.  
  345.     /**
  346.      * Copies the given qt key sequence over this key sequence.
  347.      * @param keySeq the qt key sequence to copy
  348.      * @return true if successful, false otherwise
  349.      */
  350.     bool init( const QKeySequence& keySeq );
  351.  
  352.     /**
  353.      * Initializes the key sequence to only contain the given key.
  354.      * @param key the key to set
  355.      * @return true if successful, false otherwise
  356.      */
  357.     bool init( const KKey& key );
  358.  
  359.     /**
  360.      * Initializes the key sequence to only contain the given key.
  361.      * @param key the key to set
  362.      * @return true if successful, false otherwise
  363.      */
  364.     bool init( const KKeyNative& key );
  365.  
  366.     /**
  367.      * Copies the given key sequence over this key sequence.
  368.      * @param keySeq the key sequence to copy
  369.      * @return true if successful, false otherwise
  370.      */
  371.     bool init( const KKeySequence& keySeq );
  372.  
  373.     /**
  374.      * Initializes this key sequence to contain the given key sequence.
  375.      * The description consists of comma-separated keys as
  376.      * required by KKey::KKey(const QString&).
  377.      * @param key the description of the key
  378.      * @return true if successful, false otherwise
  379.      * @see KKeyServer::Sym::init()
  380.      * @see KKey::KKey(const QString&)
  381.      */
  382.     bool init( const QString& key );
  383.  
  384.     /**
  385.      * Copy the given key sequence into this sequence.
  386.      */
  387.     KKeySequence& operator =( const KKeySequence& seq )
  388.         { init( seq ); return *this; }
  389.  
  390.     /**
  391.      * Returns the number of key strokes of this sequence.
  392.      * @return the number of key strokes
  393.      * @see MAX_KEYS
  394.      */
  395.     uint count() const;
  396.  
  397.     /**
  398.      * Return the @p i'th key of this sequence, or a null key if there
  399.      * are less then i keys.
  400.      * @param i the key to retrieve
  401.      * @return the @p i'th key, or KKey::null() if there are less
  402.      *         than i keys
  403.      * @see MAX_KEYS
  404.      */
  405.     const KKey& key( uint i ) const;
  406.  
  407.     /**
  408.      * @internal
  409.      */
  410.     bool isTriggerOnRelease() const;
  411.  
  412.     /**
  413.      * Sets the @p i'th key of the sequence. You can not introduce gaps
  414.      * in a sequence, so you must use an @p i <= count(). Also note that
  415.      * the maximum length of a key sequence is MAX_KEYS.
  416.      * @param i the position of the new key (<= count(), <= MAX_KEYS)
  417.      * @param key the key to set
  418.      * @return true if successful, false otherwise
  419.      */
  420.     bool setKey( uint i, const KKey& key );
  421.  
  422.     /**
  423.      * Returns true if the key sequence is null (after clear() or empty
  424.      * constructor).
  425.      * @return true if the key sequence is null
  426.      * @see clear()
  427.      * @see null()
  428.      */
  429.     bool isNull() const;
  430.  
  431.     /**
  432.      * Returns true if this key sequence begins with the given sequence.
  433.      * @param keySeq the key sequence to search
  434.      * @return true if this key sequence begins with the given sequence
  435.      */
  436.     bool startsWith( const KKeySequence& keySeq ) const;
  437.  
  438.     /**
  439.      * Compares this object with the given key sequence. Returns a negative
  440.      * number if the given KKeySequence is larger, 0 if they are equal and
  441.      * a positive number this KKeySequence is larger. Key sequences are
  442.      * compared by comparing the individual keys, starting from the beginning
  443.      * until an unequal key has been found. If a sequence contains more
  444.      * keys, it is considered larger.
  445.      * @param keySeq the key sequence to compare to
  446.      * @return a negative number if the given KKeySequence is larger, 0 if
  447.      * they are equal and a positive number this KKeySequence is larger
  448.      * @see KKey::sequence
  449.      */
  450.     int compare( const KKeySequence& keySeq ) const;
  451.  
  452.     /**
  453.      * Compares the keys of both sequences.
  454.      * @see compare()
  455.      */
  456.     bool operator == ( const KKeySequence& seq ) const
  457.         { return compare( seq ) == 0; }
  458.  
  459.     /**
  460.      * Compares the keys of both sequences.
  461.      * @see compare()
  462.      */
  463.     bool operator != ( const KKeySequence& seq ) const
  464.         { return compare( seq ) != 0; }
  465.  
  466.     /**
  467.      * Compares the keys of both sequences.
  468.      * @see compare()
  469.      */
  470.     bool operator < ( const KKeySequence& seq ) const
  471.         { return compare( seq ) < 0; }
  472.     // TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence
  473.  
  474.     /**
  475.      * Converts this key sequence to a QKeySequence.
  476.      * @return the QKeySequence
  477.      */
  478.     QKeySequence qt() const;
  479.  
  480.     /**
  481.      * Returns the qt key code of the first key.
  482.      * @return the qt key code of the first key
  483.      * @see Qt::Key
  484.      * @see KKey::keyCodeQt()
  485.      */
  486.     int keyCodeQt() const;
  487.  
  488.     /**
  489.      * Returns the key sequence as a number of key presses as
  490.      * returned by KKey::toString(), separated by commas.
  491.      * @return the string represenation of this key sequence
  492.      * @see KKey::toString()
  493.      */
  494.     QString toString() const;
  495.  
  496.     /**
  497.      * @internal
  498.      */
  499.     QString toStringInternal() const;
  500.  
  501.     /**
  502.      * Returns a null key sequence.
  503.      * @return the null key sequence
  504.      * @see isNull()
  505.      * @see clear()
  506.      */
  507.     static KKeySequence& null();
  508.  
  509.  protected:
  510.     uchar m_nKeys;
  511.     uchar m_bTriggerOnRelease;
  512.     // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0
  513.     KKey m_rgvar[MAX_KEYS];
  514.  
  515.  private:
  516.     class KKeySequencePrivate* d;
  517.     friend class KKeyNative;
  518. };
  519.  
  520. /**
  521. * The KShortcut class is used to represent a keyboard shortcut to an action.
  522. * A shortcut is normally a single key with modifiers, such as Ctrl+V.
  523. * A KShortcut object may also contain an alternate key which will also
  524. * activate the action it's associated to, as long as no other actions have
  525. * defined that key as their primary key.  Ex: Ctrl+V;Shift+Insert.
  526. *
  527. * This can be used to add additional accelerators to a KAction.  For example,
  528. * the below code binds the escape key to the close action.
  529. *
  530. * \code
  531. *  KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() );
  532. *  KShortcut closeShortcut = closeAction->shortcut();
  533. *  closeShortcut.append( KKey(Key_Escape));
  534. *  closeAction->setShortcut(closeShortcut);
  535. * \endcode
  536. *
  537. * Note that a shortcut cannot have more than 2 key combinations associated with it, so the above
  538. * code would not do anything (and append() would return false) if the closeAction already had
  539. * an key and alternate key.
  540. */
  541.  
  542. class KDECORE_EXPORT KShortcut
  543. {
  544.  public:
  545.         /**
  546.      * The maximum number of key sequences that can be contained in
  547.      * a KShortcut.
  548.          */
  549.     enum { MAX_SEQUENCES = 2 };
  550.  
  551.     /**
  552.      * Creates a new null shortcut.
  553.      * @see null()
  554.      * @see isNull()
  555.      * @see clear()
  556.      */
  557.     KShortcut();
  558.  
  559.     /**
  560.      * Creates a new shortcut with the given Qt key code
  561.      * as the only key sequence.
  562.      * @param keyQt the qt keycode
  563.      * @see Qt::Key
  564.      */
  565.     KShortcut( int keyQt );
  566.  
  567.     /**
  568.      * Creates a new shortcut that contains only the given qt key
  569.      * sequence.
  570.      * @param keySeq the qt key sequence to add
  571.      */
  572.     KShortcut( const QKeySequence& keySeq );
  573.  
  574.     /**
  575.      * Creates a new shortcut that contains only the given key
  576.      * in its only sequence.
  577.      * @param key the key to add
  578.      */
  579.     KShortcut( const KKey& key );
  580.  
  581.     /**
  582.      * Creates a new shortcut that contains only the given key
  583.      * sequence.
  584.      * @param keySeq the key sequence to add
  585.      */
  586.     KShortcut( const KKeySequence& keySeq );
  587.  
  588.     /**
  589.      * Copies the given shortcut.
  590.      * @param shortcut the shortcut to add
  591.      */
  592.     KShortcut( const KShortcut& shortcut );
  593.  
  594.     /**
  595.      * Creates a new key sequence that contains the given key sequence.
  596.      * The description consists of semicolon-separated keys as
  597.      * used in KKeySequence::KKeySequence(const QString&).
  598.      * @param shortcut the description of the key
  599.      * @see KKeySequence::KKeySequence(const QString&)
  600.      */
  601.     KShortcut( const char* shortcut );
  602.  
  603.     /**
  604.      * Creates a new key sequence that contains the given key sequence.
  605.      * The description consists of semicolon-separated keys as
  606.      * used in KKeySequence::KKeySequence(const QString&).
  607.      * @param shortcut the description of the key
  608.      * @see KKeySequence::KKeySequence(const QString&)
  609.      */
  610.     KShortcut( const QString& shortcut );
  611.     ~KShortcut();
  612.  
  613.     /**
  614.      * Clears the shortcut. The shortcut is null after calling this
  615.      * function.
  616.      * @see isNull()
  617.      */
  618.     void clear();
  619.  
  620.     /**
  621.      * Initializes the shortcut with the given Qt key code
  622.      * as the only key sequence.
  623.      * @param keyQt the qt keycode
  624.      * @see Qt::Key
  625.      */
  626.     bool init( int keyQt );
  627.  
  628.     /**
  629.      * Initializes the shortcut with the given qt key sequence.
  630.      * @param keySeq the qt key sequence to add
  631.      */
  632.     bool init( const QKeySequence& keySeq );
  633.  
  634.     /**
  635.      * Initializes the shortcut with the given key as its only sequence.
  636.      * @param key the key to add
  637.      */
  638.     bool init( const KKey& key );
  639.  
  640.     /**
  641.      * Initializes the shortcut with the given qt key sequence.
  642.      * @param keySeq the qt key sequence to add
  643.      */
  644.     bool init( const KKeySequence& keySeq );
  645.  
  646.     /**
  647.      * Copies the given shortcut.
  648.      * @param shortcut the shortcut to add
  649.      */
  650.     bool init( const KShortcut& shortcut );
  651.  
  652.     /**
  653.      * Initializes the key sequence with the given key sequence.
  654.      * The description consists of semicolon-separated keys as
  655.      * used in KKeySequence::KKeySequence(const QString&).
  656.      * @param shortcut the description of the key
  657.      * @see KKeySequence::KKeySequence(const QString&)
  658.      */
  659.     bool init( const QString& shortcut );
  660.  
  661.     /**
  662.      * Copies the given shortcut over this shortcut.
  663.      */
  664.     KShortcut& operator =( const KShortcut& cut )
  665.         { init( cut ); return *this; }
  666.  
  667.     /**
  668.      * Returns the number of sequences that are in this
  669.      * shortcut.
  670.      * @return the number of sequences
  671.      * MAX_SEQUENCES
  672.      */
  673.     uint count() const;
  674.  
  675.     /**
  676.      * Returns the @p i'th key sequence of this shortcut.
  677.      * @param i the number of the key sequence to retrieve
  678.      * @return the @p i'th sequence or KKeySequence::null() if
  679.      *         there are less than @p i key sequences
  680.      * MAX_SEQUENCES
  681.      */
  682.     const KKeySequence& seq( uint i ) const;
  683.  
  684.     /**
  685.      * Returns the key code of the first key sequence, or
  686.      * null if there is no first key sequence.
  687.      * @return the key code of the first sequence's first key
  688.      * @see Qt::Key
  689.      * @see KKeySequence::keyCodeQt()
  690.      */
  691.     int keyCodeQt() const;
  692.  
  693.     /**
  694.      * Returns true if the shortcut is null (after clear() or empty
  695.      * constructor).
  696.      * @return true if the shortcut is null
  697.      * @see clear()
  698.      * @see null()
  699.      */
  700.     bool isNull() const;
  701.  
  702.     /**
  703.      * Compares this object with the given shortcut. Returns a negative
  704.      * number if the given shortcut is larger, 0 if they are equal and
  705.      * a positive number this shortcut is larger. Shortcuts are
  706.      * compared by comparing the individual key sequences, starting from the
  707.      * beginning until an unequal key sequences has been found. If a shortcut
  708.      * contains more key sequences, it is considered larger.
  709.      * @param shortcut the shortcut to compare to
  710.      * @return a negative number if the given KShortcut is larger, 0 if
  711.      * they are equal and a positive number this KShortcut is larger
  712.      * @see KKey::compare()
  713.      * @see KKeyShortcut::compare()
  714.      */
  715.     int compare( const KShortcut& shortcut ) const;
  716.  
  717.     /**
  718.      * Compares the sequences of both shortcuts.
  719.      * @see compare()
  720.      */
  721.     bool operator == ( const KShortcut& cut ) const
  722.         { return compare( cut ) == 0; }
  723.  
  724.     /**
  725.      * Compares the sequences of both shortcuts.
  726.      * @see compare()
  727.      */
  728.     bool operator != ( const KShortcut& cut ) const
  729.         { return compare( cut ) != 0; }
  730.  
  731.     /**
  732.      * Compares the sequences of both shortcuts.
  733.      * @see compare()
  734.      */
  735.     bool operator < ( const KShortcut& cut ) const
  736.         { return compare( cut ) < 0; }
  737.  
  738.     /**
  739.      * Checks whether this shortcut contains a sequence that starts
  740.      * with the given key.
  741.      * @param key the key to check
  742.      * @return true if a key sequence starts with the key
  743.      */
  744.     bool contains( const KKey& key ) const;
  745.  
  746.     /**
  747.      * Checks whether this shortcut contains a sequence that starts
  748.      * with the given key.
  749.      * @param key the key to check
  750.      * @return true if a key sequence starts with the key
  751.      */
  752.     bool contains( const KKeyNative& key ) const;
  753.  
  754.     /**
  755.      * Checks whether this shortcut contains the given sequence.
  756.      * @param keySeq the key sequence to check
  757.      * @return true if the shortcut has the given key sequence
  758.      */
  759.     bool contains( const KKeySequence& keySeq ) const;
  760.  
  761.     /**
  762.      * Sets the @p i 'th key sequence of the shortcut. You can not introduce
  763.      * gaps in the list of sequences, so you must use an @p i <= count().
  764.      * Also note that the maximum number of key sequences is MAX_SEQUENCES.
  765.      * @param i the position of the new key sequence(0 <= i <= count(), 0 <= i < MAX_SEQUENCES)
  766.      * @param keySeq the key sequence to set
  767.      * @return true if successful, false otherwise
  768.      */
  769.     bool setSeq( uint i, const KKeySequence& keySeq );
  770.  
  771.     /**
  772.      * Appends the given key sequence.  This sets it as either the keysequence or
  773.      * the alternate keysequence.  If the shortcut already has MAX_SEQUENCES
  774.      * sequences then this call does nothing, and returns false.
  775.      *
  776.      * @param keySeq the key sequence to add
  777.      * @return true if successful, false otherwise
  778.      * @see setSeq()
  779.     */
  780.     bool append( const KKeySequence& keySeq );
  781.  
  782.     /**
  783.      * Removes the given key sequence from this shortcut
  784.      * @param keySeq the key sequence to remove
  785.      * @since 3.3
  786.     */
  787.     void remove( const KKeySequence& keySeq );
  788.  
  789.     /**
  790.      * Appends the given key
  791.      * @param spec the key to add
  792.      * @return true if successful, false otherwise
  793.      * @see setSeq()
  794.      * @see MAX_SEQUENCES
  795.      * @since 3.2
  796.     */
  797.     bool append( const KKey& spec );
  798.  
  799.     /**
  800.      * Appends the sequences from the given shortcut.
  801.      * @param cut the shortcut to append
  802.      * @return true if successful, false otherwise
  803.      * @see MAX_SEQUENCES
  804.      * @since 3.2
  805.     */
  806.     bool append( const KShortcut& cut );
  807.  
  808.     /**
  809.      * Converts this shortcut to a key sequence. The first key sequence
  810.      * will be taken.
  811.      */
  812.     operator QKeySequence () const;
  813.  
  814.     /**
  815.      * Returns a description of the shortcut as semicolon-separated
  816.      * ket sequences, as returned by KKeySequence::toString().
  817.      * @return the string represenation of this shortcut
  818.      * @see KKey::toString()
  819.      * @see KKeySequence::toString()
  820.      */
  821.     QString toString() const;
  822.  
  823.     /**
  824.      * @internal
  825.      */
  826.     QString toStringInternal( const KShortcut* pcutDefault = 0 ) const;
  827.  
  828.     /**
  829.      * Returns a null shortcut.
  830.      * @return the null shortcut
  831.      * @see isNull()
  832.      * @see clear()
  833.      */
  834.     static KShortcut& null();
  835.  
  836.  protected:
  837.     uint m_nSeqs;
  838.     KKeySequence m_rgseq[MAX_SEQUENCES];
  839.  
  840.  private:
  841.     class KShortcutPrivate* d;
  842.     friend class KKeyNative;
  843.  
  844. #ifndef KDE_NO_COMPAT
  845.  public:
  846.     operator int () const    { return keyCodeQt(); }
  847. #endif
  848. };
  849.  
  850. #endif // __KSHORTCUT_H
  851.