43 #include "private/qobject_p.h" 56 #include <private/qaction_p.h> 57 #include <private/qkeymapper_p.h> 58 #include <private/qwidget_p.h> 60 #ifndef QT_NO_SHORTCUT 102 #if 0 //ndef QT_NO_DEBUG_STREAM 111 return dbg <<
"QShortcutEntry(0x0)";
113 <<
"QShortcutEntry(" << se->
keyseq 114 <<
"), id(" << se->
id <<
"), enabled(" << se->
enabled <<
"), autorepeat(" << se->
autorepeat 115 <<
"), owner(" << se->
owner <<
')';
118 #endif // QT_NO_DEBUGSTREAM 129 : q_ptr(parent), currentId(0), ambigCount(0), currentState(
QKeySequence::NoMatch)
131 identicals.reserve(10);
132 currentSequences.reserve(10);
179 Q_ASSERT_X(owner,
"QShortcutMap::addShortcut",
"All shortcuts need an owner");
180 Q_ASSERT_X(!key.
isEmpty(),
"QShortcutMap::addShortcut",
"Cannot add keyless shortcuts to map");
185 d->sequences.insert(it, newEntry);
186 #if defined(DEBUG_QSHORTCUTMAP) 188 <<
"QShortcutMap::addShortcut(" << owner <<
", " 189 << key <<
", " << context <<
") = " <<
d->currentId;
209 int itemsRemoved = 0;
210 bool allOwners = (owner == 0);
212 bool allIds =
id == 0;
215 if (allOwners && allKeys &&
id == 0) {
216 itemsRemoved =
d->sequences.size();
217 d->sequences.clear();
221 int i =
d->sequences.size()-1;
225 int entryId = entry.
id;
226 if ((allOwners || entry.
owner == owner)
227 && (allIds || entry.
id ==
id)
228 && (allKeys || entry.
keyseq == key)) {
229 d->sequences.removeAt(i);
236 #if defined(DEBUG_QSHORTCUTMAP) 238 <<
"QShortcutMap::removeShortcut(" <<
id <<
", " << owner <<
", " 239 << key <<
") = " << itemsRemoved;
258 int itemsChanged = 0;
259 bool allOwners = (owner == 0);
261 bool allIds =
id == 0;
263 int i =
d->sequences.size()-1;
267 if ((allOwners || entry.
owner == owner)
268 && (allIds || entry.
id ==
id)
269 && (allKeys || entry.
keyseq == key)) {
270 d->sequences[i].enabled = enable;
277 #if defined(DEBUG_QSHORTCUTMAP) 279 <<
"QShortcutMap::setShortcutEnabled(" << enable <<
", " <<
id <<
", " 280 << owner <<
", " << key <<
") = " << itemsChanged;
299 int itemsChanged = 0;
300 bool allOwners = (owner == 0);
302 bool allIds =
id == 0;
304 int i =
d->sequences.size()-1;
308 if ((allOwners || entry.
owner == owner)
309 && (allIds || entry.
id ==
id)
310 && (allKeys || entry.
keyseq == key)) {
311 d->sequences[i].autorepeat = on;
318 #if defined(DEBUG_QSHORTCUTMAP) 320 <<
"QShortcutMap::setShortcutAutoRepeat(" << on <<
", " <<
id <<
", " 321 << owner <<
", " << key <<
") = " << itemsChanged;
342 return d->currentState;
362 bool wasSpontaneous = e->spont;
369 e->spont = wasSpontaneous;
384 int identicalMatches =
d->identicals.count();
388 return stateWasAccepted;
412 return d->currentState;
417 d->identicals.resize(0);
441 d->currentState = result;
443 #if defined(DEBUG_QSHORTCUTMAP) 444 qDebug().nospace() <<
"QShortcutMap::nextState(" << e <<
") = " << result;
463 for (;it != itEnd; ++
it) {
486 if (!
d->sequences.count())
490 #if defined(DEBUG_QSHORTCUTMAP) 491 qDebug() <<
"Possible shortcut key sequences:" <<
d->newEntries;
495 if (
d->newEntries ==
d->currentSequences) {
497 "QShortcutMap::find",
"New sequence to find identical to previous");
502 d->identicals.resize(0);
504 bool partialFound =
false;
505 bool identicalDisabledFound =
false;
508 for (
int i =
d->newEntries.count()-1; i >= 0 ; --i) {
519 tempRes =
matches(entry.keyseq, (*it).keyseq);
520 oneKSResult =
qMax(oneKSResult, tempRes);
524 d->identicals.append(&*it);
526 identicalDisabledFound =
true;
529 if (
d->identicals.size())
533 partialFound |= (*it).enabled;
544 if (oneKSResult > result) {
546 #if defined(DEBUG_QSHORTCUTMAP) 547 qDebug() <<
"Found better match (" <<
d->newEntries <<
"), clearing key sequence list";
550 if (oneKSResult && oneKSResult >= result) {
551 okEntries <<
d->newEntries.at(i);
552 #if defined(DEBUG_QSHORTCUTMAP) 553 qDebug() <<
"Added ok key sequence" <<
d->newEntries;
558 if (
d->identicals.size()) {
560 }
else if (partialFound) {
562 }
else if (identicalDisabledFound) {
569 d->currentSequences = okEntries;
570 #if defined(DEBUG_QSHORTCUTMAP) 571 qDebug() <<
"Returning shortcut match == " << result;
587 d_func()->newEntries.clear();
601 int pkTotal = possibleKeys.
count();
605 int ssActual =
d->currentSequences.count();
606 int ssTotal =
qMax(1, ssActual);
608 ksl.
resize(pkTotal * ssTotal);
610 int index = ssActual ?
d->currentSequences.at(0).count() : 0;
611 for (
int pkNum = 0; pkNum < pkTotal; ++pkNum) {
612 for (
int ssNum = 0; ssNum < ssTotal; ++ssNum) {
613 int i = (pkNum * ssTotal) + ssNum;
617 curKsl.
setKey(curSeq[0], 0);
618 curKsl.
setKey(curSeq[1], 1);
619 curKsl.
setKey(curSeq[2], 2);
620 curKsl.
setKey(curSeq[3], 3);
655 for (
uint i = 0; i < userN; ++i) {
656 int userKey = seq1[i],
657 sequenceKey = seq2[i];
661 sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) |
Qt::Key_Minus;
662 if (userKey != sequenceKey)
676 Q_ASSERT_X(item.
owner,
"QShortcutMap",
"Shortcut has no owner. Illegal map state!");
692 #ifndef QT_NO_GRAPHICSVIEW 730 #ifndef QT_NO_GRAPHICSVIEW 731 if (
QWExtra *topData = tlw->d_func()->extra) {
732 if (topData->proxyWidget) {
745 if (active_window != tlw)
755 while (focus_widget && focus_widget != sw)
757 return sw == focus_widget;
760 #if defined(DEBUG_QSHORTCUTMAP) 761 qDebug().nospace() <<
"..true [Pass-through]";
766 #ifndef QT_NO_GRAPHICSVIEW 783 for (
int i = 0; i < views.
size(); ++i) {
809 for (
int i = 0; i < views.
size(); ++i) {
811 if (view->
window() == active_window) {
830 #if defined(DEBUG_QSHORTCUTMAP) 832 qDebug() << a <<
"not connected to any widgets; won't trigger";
834 for (
int i = 0; i < widgets.
size(); ++i) {
837 if (
QMenu *menu = qobject_cast<QMenu *>(w)) {
838 QAction *a = menu->menuAction();
847 #ifndef QT_NO_GRAPHICSVIEW 849 #if defined(DEBUG_QSHORTCUTMAP) 851 qDebug() << a <<
"not connected to any widgets; won't trigger";
853 for (
int i = 0; i < graphicsWidgets.
size(); ++i) {
861 #endif // QT_NO_ACTION 889 return d->identicals;
901 if (!
d->identicals.size())
905 if (
d->prevSequence != curKey) {
907 d->prevSequence = curKey;
911 int i = 0, enabledShortcuts = 0;
912 while(i < d->identicals.size()) {
913 current =
d->identicals.at(i);
914 if (current->
enabled || !next){
916 if (enabledShortcuts >
d->ambigCount + 1)
922 d->ambigCount = (
d->identicals.size() == i ? 0 :
d->ambigCount + 1);
928 #if defined(DEBUG_QSHORTCUTMAP) 930 <<
"QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\"" 931 << (
QString)next->keyseq <<
"\", " << next->id <<
", " 932 << (
bool)(enabledShortcuts>1) <<
") to object(" << next->owner <<
')';
942 #if defined(Dump_QShortcutMap) 943 void QShortcutMap::dumpMap()
const 946 for (
int i = 0; i <
d->sequences.size(); ++i)
947 qDebug().nospace() << &(
d->sequences.at(i));
953 #endif // QT_NO_SHORTCUT T qobject_cast(QObject *object)
The QDebug class provides an output stream for debugging information.
static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result)
QGraphicsWidget * activeWindow() const
Returns the current active window, or 0 if no window is currently active.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
The QKeyEvent class describes a key event.
QGraphicsWidget * parentWidget() const
Returns a pointer to the item's parent widget.
#define QT_END_NAMESPACE
This macro expands to.
int setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key=QKeySequence())
Changes the enable state of a shortcut to enable.
void dispatchEvent(QKeyEvent *e)
Dispatches QShortcutEvents to widgets who grabbed the matched key sequence.
bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window) const
QVector< const QShortcutEntry * > identicals
#define it(className, varName)
QDebug & nospace()
Clears the stream's internal flag that records whether the last character was a space and returns a r...
QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i, bool a)
int length() const
Returns the number of characters in this string.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void setKey(int key, int index)
KeySequences should never be modified, but rather just created.
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
static bool match(const uchar *found, const char *target, uint len)
bool hasShortcutForKeySequence(const QKeySequence &seq) const
Determines if an enabled shortcut has a matcing key sequence.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
QShortcutMap()
QShortcutMap constructor.
QKeySequence::SequenceMatch currentState
Qt::ShortcutContext context
The QString class provides a Unicode character string.
QList< QShortcutEntry > sequences
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
The QObject class is the base class of all Qt objects.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
void resize(int size)
Sets the size of the vector to size.
The QShortcut class is used to create keyboard shortcuts.
Q_CORE_EXPORT void qDebug(const char *,...)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
static QList< int > possibleKeys(QKeyEvent *e)
int key() const
Returns the code of the key that was pressed or released.
QVector< const QShortcutEntry * > matches() const
Returns the vector of QShortcutEntry's matching the last Identical state.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene's current focus item, or 0 if no item curr...
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
QKeySequence::SequenceMatch nextState(QKeyEvent *e)
const T & at(int i) const
Returns the item at index position i in the list.
void createNewSequences(QKeyEvent *e, QVector< QKeySequence > &ksl)
Alters seq to the new sequence state, based on the current sequence state, and the new key event e...
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QShortcutMapPrivate(QShortcutMap *parent)
bool operator<(const QShortcutEntry &f) const
QVector< QKeySequence > currentSequences
bool isEmpty() const
Returns true if the key sequence is empty; otherwise returns false.
QKeySequence::SequenceMatch find(QKeyEvent *e)
Returns the next state of the statemachine, based on the new key event e.
~QShortcutMap()
QShortcutMap destructor.
QKeySequence prevSequence
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
int setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key=QKeySequence())
Changes the auto repeat state of a shortcut to enable.
static bool tryModalHelper(QWidget *widget, QWidget **rettop=0)
#define Q_ASSERT_X(cond, where, what)
int translateModifiers(Qt::KeyboardModifiers modifiers)
#define Q_DECLARE_PUBLIC(Class)
bool tryShortcutEvent(QObject *o, QKeyEvent *e)
Uses ShortcutOverride event to see if any widgets want to override the event.
static QWidget * activePopupWidget()
Returns the active popup widget.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
QString text() const
Returns the Unicode text that this key generated.
QKeySequence::SequenceMatch state()
void clearSequence(QVector< QKeySequence > &ksl)
Clears seq to an empty QKeySequence.
int size() const
Returns the number of items in the list.
QGraphicsWidget * window() const
Returns the item's window, or 0 if this item does not have a window.
int removeShortcut(int id, QObject *owner, const QKeySequence &key=QKeySequence())
Removes a shortcut from the global map.
bool isWidget() const
Returns true if this item is a widget (i.
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
uint count() const
Returns the number of keys in the key sequence.
bool correctContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window) const
bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window) const
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
QDataStream & operator<<(QDataStream &s, const QAxBase &c)
int addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context)
Adds a shortcut to the global map.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i)
QShortcutEntry(const QKeySequence &k)
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Type type() const
Returns the event type.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
QVector< QKeySequence > newEntries
The QAction class provides an abstract user interface action that can be inserted into widgets...
QWidget * parentWidget() const
Returns the shortcut's parent widget.