1 /****************************************************************************** 2 Copyright (c) 2010, Artem Galichkin <doomer3d@gmail.com> 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 * Neither the name of the <organization> nor the 14 names of its contributors may be used to endorse or promote products 15 derived from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 *******************************************************************************/ 28 29 #ifndef QKEYSEQUENCEWIDGET_H 30 #define QKEYSEQUENCEWIDGET_H 31 32 #include "qkeysequencewidget_p.h" 33 34 #include <QWidget> 35 #include <QIcon> 36 37 #if defined IS_SHARED 38 #define QKSW_EXPORT Q_DECL_EXPORT 39 #else 40 #define QKSW_EXPORT Q_DECL_IMPORT 41 #endif 42 43 class QKeySequenceWidgetPrivate; 44 45 /*! 46 \class QKeySequenceWidget 47 48 \brief The QKeySequenceWidget is a widget to input a QKeySequence. 49 50 This widget lets the user choose a QKeySequence, which is usually used as a 51 shortcut key. The recording is initiated by calling captureKeySequence() or 52 the user clicking into the widget. 53 54 \code 55 // create new QKeySequenceWidget with empty sequence 56 QKeySequenceWidget *keyWidget = new QKeySequenceWidget; 57 58 // Set sequence as "Ctrl+Alt+Space" 59 keyWidget->setJeySequence(QKeySequence("Ctrl+Alt+Space")); 60 61 // set clear button position is left 62 setClearButtonShow(QKeySequenceWidget::ShowLeft); 63 64 // set cutom clear button icon 65 setClearButtonIcon(QIcon("/path/to/icon.png")); 66 67 // connecting keySequenceChanged signal to slot 68 connect(keyWidget, SIGNAL(keySequenceChanged(QKeySequence)), this, SLOT(slotKeySequenceChanged(QKeySequence))); 69 \endcode 70 */ 71 class QKSW_EXPORT QKeySequenceWidget : public QWidget 72 { 73 Q_OBJECT 74 Q_DECLARE_PRIVATE(QKeySequenceWidget); 75 Q_PRIVATE_SLOT(d_func(), void doneRecording()) 76 77 Q_PROPERTY(QKeySequence keySequence READ keySequence WRITE setKeySequence) 78 Q_PROPERTY(QKeySequenceWidget::ClearButtonShow clearButton READ clearButtonShow WRITE setClearButtonShow) 79 Q_PROPERTY(QString noneText READ noneText WRITE setNoneText) 80 Q_PROPERTY(QIcon clearButtonIcon READ clearButtonIcon WRITE setClearButtonIcon) 81 82 private: 83 QKeySequenceWidgetPrivate * const d_ptr; 84 void _connectingSlots(); 85 86 public: 87 explicit QKeySequenceWidget(QWidget *parent = 0); 88 explicit QKeySequenceWidget(const QKeySequence &seq, QWidget *parent = 0); 89 explicit QKeySequenceWidget(const QString &noneString, QWidget *parent = 0); 90 explicit QKeySequenceWidget(const QKeySequence &seq, const QString &noneString, QWidget *parent = 0); 91 virtual ~QKeySequenceWidget(); 92 QSize sizeHint() const; 93 void setToolTip(const QString &tip); 94 QKeySequence keySequence() const; 95 QString noneText() const; 96 QIcon clearButtonIcon() const; 97 98 /*! 99 \brief Modes of sohow ClearButton 100 */ 101 enum ClearButton { 102 NoShow = 0x00, /**< Hide ClearButton */ 103 ShowLeft = 0x01, /**< ClearButton isow is left */ 104 ShowRight = 0x02 /**< ClearButton isow is left */ 105 }; 106 107 Q_DECLARE_FLAGS(ClearButtonShow, ClearButton); 108 Q_FLAGS(ClearButtonShow) 109 110 QKeySequenceWidget::ClearButtonShow clearButtonShow() const; 111 112 Q_SIGNALS: 113 void keySequenceChanged(const QKeySequence &seq); 114 void keySequenceAccepted(const QKeySequence &seq); 115 void keySequenceCleared(); 116 void keyNotSupported(); 117 118 public Q_SLOTS: 119 void setKeySequence(const QKeySequence &key); 120 void clearKeySequence(); 121 void setNoneText(const QString &text); 122 void setClearButtonIcon(const QIcon& icon); 123 void setClearButtonShow(QKeySequenceWidget::ClearButtonShow show); 124 void captureKeySequence(); 125 }; 126 127 #endif // QKEYSEQUENCEWIDGET_H 128