KDEUI
kshortcut.h
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org> 00003 Copyright (C) 2006 Hamish Rodda <rodda@kde.org> 00004 Copyright (C) 2006 Andreas Hartmetz <ahartmetz@gmail.com> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00027 #ifndef KSHORTCUT_H 00028 #define KSHORTCUT_H 00029 00030 #include <kdeui_export.h> 00031 00032 #include <QtCore/QList> 00033 #include <QtCore/QMetaType> 00034 #include <QtGui/QKeySequence> 00035 00036 class KShortcutPrivate; 00037 00057 class KDEUI_EXPORT KShortcut 00058 { 00059 public: 00063 enum EmptyHandling { 00065 KeepEmpty = 0, 00067 RemoveEmpty 00068 }; 00069 00075 KShortcut(); 00076 00082 explicit KShortcut(const QKeySequence &primary); 00083 00091 KShortcut(const QKeySequence &primary, const QKeySequence &alternate); 00092 00101 explicit KShortcut(int keyQtPri, int keyQtAlt = 0); 00102 00106 KShortcut(const KShortcut &other); 00107 00117 explicit KShortcut(const QString &description); 00118 00125 explicit KShortcut(const QList<QKeySequence> &seqs); 00126 00130 ~KShortcut(); 00131 00139 QKeySequence primary() const; 00140 00145 QKeySequence alternate() const; 00146 00151 bool isEmpty() const; 00152 00157 bool contains(const QKeySequence &needle) const; 00158 00166 QString toString() const; 00167 00168 bool operator==(const KShortcut &other) const; 00169 00170 bool operator!=(const KShortcut &other) const; 00171 00180 operator QList<QKeySequence>() const; 00181 00189 QList<QKeySequence> toList(enum EmptyHandling handleEmpty = RemoveEmpty) const; 00190 00194 operator QVariant() const; 00195 00204 void setPrimary(const QKeySequence &keySeq); 00205 00210 void setAlternate(const QKeySequence &keySeq); 00211 00218 void remove(const QKeySequence &keySeq, enum EmptyHandling handleEmpty = RemoveEmpty); 00219 00223 KShortcut &operator=(const KShortcut &other); 00224 00225 private: 00226 class KShortcutPrivate *const d; 00227 }; 00228 00229 uint qHash(int); 00230 inline uint qHash(const KShortcut &key) 00231 { 00232 return qHash(key.primary()[0]) + qHash(key.primary()[1]); 00233 } 00234 00235 inline uint qHash(const QKeySequence &key) 00236 { 00237 uint hash = 0; 00238 for(uint i = 0; i < key.count(); i++) 00239 hash += qHash(key[i]); 00240 return hash; 00241 } 00242 00243 Q_DECLARE_METATYPE(KShortcut) 00244 00245 #endif // KSHORTCUT_H