summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Client/Code/Core/Utility/HotKeys.cpp
blob: b62ccd4a0503261d3b6d6bbd289ad7902e6d4bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/****************************************************************************
**
** Copyright (C) 2002 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "Qt3DSCommonPrecompile.h"
#include "HotKeys.h"
#include "StringTokenizer.h"

#include "Studio/UI/SceneView.h"
#include "Studio/MainFrm.h"

#include <QtGui/qguiapplication.h>
#include <QtGui/qevent.h>
#include <QtQuickWidgets/qquickwidget.h>
#include <QtQuick/qquickwindow.h>
#include <QtQuick/qquickitem.h>
#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qabstractbutton.h>
#include <QtWidgets/qgraphicsview.h>
#include <QtWidgets/qgraphicsitem.h>

class KeyEventFilter : public QObject
{
public:
    KeyEventFilter(CHotKeys* hotkeys)
        : QObject(qApp)
        , m_hotkeys(hotkeys)
    {
    }

    bool eventFilter(QObject *watched, QEvent *event) override
    {
        const QEvent::Type eventType = event->type();
        if (eventType != QEvent::ShortcutOverride
                && eventType != QEvent::KeyPress
                && eventType != QEvent::KeyRelease) {
            return false;
        }

        QKeyEvent *ke = static_cast<QKeyEvent *>(event);

        if (eventType == QEvent::ShortcutOverride) {
            // If we are in key consuming control, eat all plain and shift-adjusted hotkeys
            // We want to also skip some editing related global hotkeys (CTRL-A/Z)
            // and value adjusting keys (CTRL-UP/DOWN).
            const bool normalChar = !(ke->modifiers() && ke->modifiers() != Qt::ShiftModifier);
            const bool editShortcut = (ke->modifiers() == Qt::ControlModifier)
                    && (ke->key() == Qt::Key_Z || ke->key() == Qt::Key_A
                        || ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down);
            if ((normalChar || editShortcut) && m_hotkeys->isFocusOnControlThatWantsKeys()) {
                ke->accept();
                return true;
            }
        }

        if (qobject_cast<CSceneView *>(watched) == nullptr
                && qobject_cast<CMainFrame *>(watched) == nullptr
                && qobject_cast<QComboBox *>(watched) == nullptr
                && qobject_cast<CPlayerContainerWnd *>(watched) == nullptr
                && qobject_cast<QAbstractButton *>(watched) == nullptr) {
            return false;
        }

        // Ignore global shortcuts if we are in a text control that
        // wants key events.
        if (m_hotkeys->isFocusOnControlThatWantsKeys())
            return false;

        switch (eventType) {
        case QEvent::KeyPress: {
                bool success = m_hotkeys->OnKeyDown(ke->key(), ke->count(), ke->modifiers())
                        || m_hotkeys->OnChar(ke->key(), ke->count(), ke->modifiers());
                if (success)
                    ke->accept();
                return success;
        }
        case QEvent::KeyRelease: {
            // We are not in a text field, so we can
            // ignore auto-repeated key releases as it breaks
            // timeline animation on/off switching by hotkey
            if (!ke->isAutoRepeat())
                return m_hotkeys->OnKeyUp(ke->key(), ke->count(), ke->modifiers());
            else
                return true;
        }
        default:
            break;
        }
        return false;
    }

private:
    CHotKeys* m_hotkeys;
};

//==============================================================================
//	Defines
//==============================================================================

IMPLEMENT_OBJECT_COUNTER(CHotKeys)

//=============================================================================
/**
 * Constructor, nothing interesting.
 */
//=============================================================================
CHotKeys::CHotKeys()
    : m_CaptureKeys(false)
{
    ADDTO_OBJECT_COUNTER(CHotKeys)

    m_EventFilter = new KeyEventFilter(this);
    qApp->installEventFilter(m_EventFilter);
}

//=============================================================================
/**
 * Destructor, have to delete all the listeners.
 * This is not the cleanest way to do this but, oh well.
 */
//=============================================================================
CHotKeys::~CHotKeys()
{
    if (qApp)
        qApp->removeEventFilter(m_EventFilter);
    this->ClearAllEvents();
    REMOVEFROM_OBJECT_COUNTER(CHotKeys)
}

//=============================================================================
/**
 * Clears and deletes all the events from this.
 */
//=============================================================================
void CHotKeys::ClearAllEvents()
{
    // Delete all the OnChar listeners
    THotKeyMap::iterator theMapPos = m_KeyCharMap.begin();
    for (; theMapPos != m_KeyCharMap.end(); ++theMapPos) {
        THotKeyList::iterator theListPos = theMapPos->second.begin();
        for (; theListPos != theMapPos->second.end(); ++theListPos) {
            SHotKeyInfo *theInfo = (*theListPos);
            delete theInfo->Consumer;
            delete theInfo;
        }
    }

    m_KeyCharMap.clear();

    // Delete all the OnKeyDown listeners.
    theMapPos = m_KeyDownMap.begin();
    for (; theMapPos != m_KeyDownMap.end(); ++theMapPos) {
        THotKeyList::iterator theListPos = theMapPos->second.begin();
        for (; theListPos != theMapPos->second.end(); ++theListPos) {
            SHotKeyInfo *theInfo = (*theListPos);
            delete theInfo->Consumer;
            delete theInfo;
        }
    }

    m_KeyDownMap.clear();

    // Delete all the OnKeyUp listeners.
    theMapPos = m_KeyUpMap.begin();
    for (; theMapPos != m_KeyUpMap.end(); ++theMapPos) {
        THotKeyList::iterator theListPos = theMapPos->second.begin();
        for (; theListPos != theMapPos->second.end(); ++theListPos) {
            SHotKeyInfo *theInfo = (*theListPos);
            delete theInfo->Consumer;
            delete theInfo;
        }
    }

    m_KeyUpMap.clear();
}

//=============================================================================
/**
 * Register a consumer to get called on the equivalent of OnChar.
 * This will call the consumer when all the modifiers are met and the character
 * has been received. If a modifier such as MOD_SHIFT is set but the key is not
 * pressed then the consumer will not be called.
 *
 * If there are duplicate listeners for the same exact event the previous one
 * will be removed.
 *
 * @param inConsumer the consumer to add for events, this will be deleted by this.
 * @param inModifiers mask of keyboard modifiers- MOD_SHIFT, MOD_CONTROL, MOD_MENU...
 * @param inCharacter the character the event is to occur on.
 */
//=============================================================================
void CHotKeys::RegisterKeyEvent(CHotKeyConsumer *inConsumer, Qt::KeyboardModifiers inModifiers,
                                int inCharacter)
{
    // Remove any previous consumers.
    this->RemoveConsumers(inModifiers, inCharacter, &m_KeyCharMap);
    this->InsertConsumer(inConsumer, inModifiers, inCharacter, &m_KeyCharMap);
}

//=============================================================================
/**
 * Register a consumer to get called on the equivalent of OnKeyDown.
 * This will call the consumer when all the modifiers are met and the character
 * has been received. If a modifier such as MOD_SHIFT is set but the key is not
 * pressed then the consumer will not be called.
 *
 * If there are duplicate listeners for the same exact event the previous one
 * will be removed.
 *
 * @param inConsumer the consumer to add for events, this will be deleted by this.
 * @param inModifiers mask of keyboard modifiers- MOD_SHIFT, MOD_CONTROL, MOD_MENU...
 * @param inVirtualKey the virtualkey the event is to occur on.
 */
//=============================================================================
void CHotKeys::RegisterKeyDownEvent(CHotKeyConsumer *inConsumer, Qt::KeyboardModifiers inModifiers,
                                    int inVirtualKey)
{
    // Remove any previous consumers.
    this->RemoveConsumers(inModifiers, inVirtualKey, &m_KeyDownMap);
    this->InsertConsumer(inConsumer, inModifiers, inVirtualKey, &m_KeyDownMap);
}

//=============================================================================
/**
 * Register a consumer to get called on the equivalent of OnKeyUp.
 * This will call the consumer when all the modifiers are met and the character
 * has been received. If a modifier such as MOD_SHIFT is set but the key is not
 * pressed then the consumer will not be called.
 *
 * If there are duplicate listeners for the same exact event the previous one
 * will be removed.
 *
 * @param inConsumer the consumer to add for events, this will be deleted by this.
 * @param inModifiers mask of keyboard modifiers- MOD_SHIFT, MOD_CONTROL, MOD_MENU...
 * @param inVirtualKey the virtualkey the event is to occur on.
 */
//=============================================================================
void CHotKeys::RegisterKeyUpEvent(CHotKeyConsumer *inConsumer, Qt::KeyboardModifiers inModifiers,
                                  int inVirtualKey)
{
    // Remove any previous consumers.
    this->RemoveConsumers(inModifiers, inVirtualKey, &m_KeyUpMap);
    this->InsertConsumer(inConsumer, inModifiers, inVirtualKey, &m_KeyUpMap);
}

//=============================================================================
/**
 * Register a consumer to get called on the equivalent of OnChar.
 * This will call the consumer when all the modifiers are met and the character
 * has been received. If a modifier such as MOD_SHIFT is set but the key is not
 * pressed then the consumer will not be called.
 *
 * If there are duplicate listeners for the same exact event the previous one
 * will be removed.
 *
 * @param inConsumer the consumer to which to add this key
 * @param inString the string containing key/mods.  This needs to be in the form of
 *key/:Mod/,Mod/,Mod ie x/:ctrl/,shift
 *				   see IDS_HK_SEPARATOR & IDS_HK_MOD_SEPARATOR & IDS_HK_CTRL -
 *IDS_HK_ALPHALOCK for useful info in creating these strings
 */
void CHotKeys::RegisterKeyEvent(CHotKeyConsumer *inConsumer, const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifiers theMod;
    int theKey;
    GetModAndKeyFromString(inString, theMod, theKey);

    RegisterKeyEvent(inConsumer, theMod, theKey);
}

//=============================================================================
/**
 * Register a consumer to get called on the equivalent of OnKeyDown.
 * This will call the consumer when all the modifiers are met and the character
 * has been received. If a modifier such as MOD_SHIFT is set but the key is not
 * pressed then the consumer will not be called.
 *
 * If there are duplicate listeners for the same exact event the previous one
 * will be removed.
 *
 */
void CHotKeys::RegisterKeyDownEvent(CHotKeyConsumer *inConsumer, const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifiers theMod;
    int theVirtualKey;
    GetModAndKeyFromString(inString, theMod, theVirtualKey);

    RegisterKeyDownEvent(inConsumer, theMod, theVirtualKey);
}

//=============================================================================
/**
 * Register a consumer to get called on the equivalent of OnKeyUp.
 * This will call the consumer when all the modifiers are met and the character
 * has been received. If a modifier such as MOD_SHIFT is set but the key is not
 * pressed then the consumer will not be called.
 *
 * If there are duplicate listeners for the same exact event the previous one
 * will be removed.
 *
 */
void CHotKeys::RegisterKeyUpEvent(CHotKeyConsumer *inConsumer, const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifiers theMod;
    int theVirtualKey;
    GetModAndKeyFromString(inString, theMod, theVirtualKey);

    RegisterKeyUpEvent(inConsumer, theMod, theVirtualKey);
}

//=============================================================================
/**
 * Remove a previous key char event.
 * This removes a consumer from the list of events, the consumer is also deleted.
 *
 * @param inModifiers the modifiers for the event.
 * @param inCharacter the character for the event.
 */
//=============================================================================
void CHotKeys::UnregisterKeyEvent(Qt::KeyboardModifiers inModifiers, int inCharacter)
{
    this->RemoveConsumers(inModifiers, inCharacter, &m_KeyCharMap);
}

//=============================================================================
/**
 * Remove a previous key down event.
 * This removes a consumer from the list of events, the consumer is also deleted.
 *
 * @param inModifiers the modifiers for the event.
 * @param inVirtualKey the virtualkey for the event.
 */
//=============================================================================
void CHotKeys::UnregisterKeyDownEvent(Qt::KeyboardModifiers inModifiers, int inVirtualKey)
{
    this->RemoveConsumers(inModifiers, inVirtualKey, &m_KeyDownMap);
}

//=============================================================================
/**
 * Remove a previous key up event.
 * This removes a consumer from the list of events, the consumer is also deleted.
 *
 * @param inModifiers the modifiers for the event.
 * @param inVirtualKey the virtualkey for the event.
 */
//=============================================================================
void CHotKeys::UnregisterKeyUpEvent(Qt::KeyboardModifiers inModifiers, int inVirtualKey)
{
    this->RemoveConsumers(inModifiers, inVirtualKey, &m_KeyUpMap);
}

void CHotKeys::UnregisterKeyEvent(const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifiers theMod;
    int theKey;
    GetModAndKeyFromString(inString, theMod, theKey);

    UnregisterKeyEvent(theMod, theKey);
}

void CHotKeys::UnregisterKeyDownEvent(const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifiers theMod;
    int theVirtualKey;
    GetModAndKeyFromString(inString, theMod, theVirtualKey);

    UnregisterKeyDownEvent(theMod, theVirtualKey);
}

void CHotKeys::UnregisterKeyUpEvent(const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifiers theMod;
    int theVirtualKey;
    GetModAndKeyFromString(inString, theMod, theVirtualKey);

    UnregisterKeyUpEvent(theMod, theVirtualKey);
}

//=============================================================================
/**
 * Called by owner window on a WM_CHAR event.
 *
 * @param inChar the character received.
 * @param inRepeatCount the repeat count.
 * @param inFlags the flags.
 */
//=============================================================================
bool CHotKeys::OnChar(int inChar, int inRepeatCount, Qt::KeyboardModifiers inFlags)
{
    return FireEvent(inChar, inRepeatCount, inFlags, &m_KeyCharMap);
}

//=============================================================================
/**
 * Called by owner window on a WM_KEYDOWN event.
 *
 * @param inChar the character received.
 * @param inRepeatCount the repeat count.
 * @param inFlags the flags.
 */
//=============================================================================
bool CHotKeys::OnKeyDown(int inVirtualKey, int inRepeatCount,
                         Qt::KeyboardModifiers modifiers)
{
    return FireEvent(inVirtualKey, inRepeatCount, modifiers, &m_KeyDownMap);
}

//=============================================================================
/**
 * Called by owner window on a WM_KEYUP event.
 *
 * @param inChar the character received.
 * @param inRepeatCount the repeat count.
 * @param inFlags the flags.
 */
//=============================================================================
bool CHotKeys::OnKeyUp(int inVirtualKey, int inRepeatCount, Qt::KeyboardModifiers modifiers)
{
    return FireEvent(inVirtualKey, inRepeatCount, modifiers, &m_KeyUpMap);
}

//=============================================================================
/**
 * Helper function for adding consumers to the map.
 *
 * @param inConsumer the consumer to be added.
 * @param inModifiers the keyboard modifiers.
 * @param inCharacter the character to be pressed.
 * @param inMap the map the consumer is to be added to.
 */
//=============================================================================
void CHotKeys::InsertConsumer(CHotKeyConsumer *inConsumer, Qt::KeyboardModifiers inModifiers,
                              int inCharacter, THotKeyMap *inMap)
{
    SHotKeyInfo *theInfo = new SHotKeyInfo;
    theInfo->Consumer = inConsumer;
    theInfo->Character = inCharacter;
    theInfo->Modifiers = inModifiers;

    THotKeyMap::iterator theMapPos = inMap->find(inCharacter);
    // There is already a list, just add this one to it.
    if (theMapPos != inMap->end()) {
        theMapPos->second.push_back(theInfo);
    } else {
        // Add a new list to the map
        THotKeyList theList;
        theList.push_back(theInfo);
        inMap->insert(std::pair<unsigned int, THotKeyList>(inCharacter, theList));
    }
}

//=============================================================================
/**
 * Remove all the consumers listening for the specified event.
 *
 * @param inModifiers the keyboard modifiers.
 * @param inCharacter the character to be pressed.
 * @param inMap the map to remove the consumers from.
 */
//=============================================================================
void CHotKeys::RemoveConsumers(Qt::KeyboardModifiers inModifiers, int inCharacter,
                               THotKeyMap *inMap)
{
    THotKeyMap::iterator theMapPos = inMap->find(inCharacter);
    if (theMapPos != inMap->end()) {
        THotKeyList::iterator theListPos = theMapPos->second.begin();
        while (theListPos != theMapPos->second.end()) {
            if ((*theListPos)->Modifiers == inModifiers) {
                SHotKeyInfo *theInfo = (*theListPos);
                delete theInfo->Consumer;
                delete theInfo;

                theListPos = theMapPos->second.erase(theListPos);
            } else
                ++theListPos;
        }
    }
}

//=============================================================================
/**
 * Fire off an event for the specified char.
 * This will go through the map for the event and find all applicable consumers
 * then call OnHotKeyEvent on that consumer.
 *
 * @param inChar the character that was pressed.
 * @param inRepeatCount the number of times the character was pressed.
 * @param inFlags the flags from the WM_KEY* call.
 * @param inMap the map to find the consumers in.
 * @return true if the event was dispatched.
 */
//=============================================================================
bool CHotKeys::FireEvent(int inChar, int inRepeatCount, Qt::KeyboardModifiers modifiers,
                         THotKeyMap *inMap)
{
    bool theRetVal = false;

    // Get the state of the keys before iterating through the key events. If a key event takes a
    // while to
    // be dispatched then the state of the modifier key may change and will cause incorrect results.
    unsigned int isMenuDown = modifiers & Qt::AltModifier;
    unsigned int isControlDown = modifiers & Qt::ControlModifier;
    unsigned int isShiftDown = modifiers & Qt::ShiftModifier;

    // If the keys are captured by a window and not modified, then don't send this
    // event to the registered consumers. This is mainly a hack to allow the command
    // window to work properly.
    if (m_CaptureKeys && !(isMenuDown || isControlDown || isShiftDown))
        return false;

    // Find the list of consumers for inChar
    THotKeyMap::iterator theMapPos = inMap->find(inChar);
    if (theMapPos != inMap->end()) {
        // Go through all the consumers checking if their key modifiers are met
        THotKeyList::iterator theListPos = theMapPos->second.begin();
        for (; theListPos != theMapPos->second.end(); ++theListPos) {
            SHotKeyInfo *theHotKeyInfo = *theListPos;
            // Check to see if the modifier is set and the key is down or neither of them are set
            // for each of the modifiers.
            if ((isMenuDown == (theHotKeyInfo->Modifiers & Qt::AltModifier))
                && (isControlDown == (theHotKeyInfo->Modifiers & Qt::ControlModifier))
                && (isShiftDown == (theHotKeyInfo->Modifiers & Qt::ShiftModifier))) {
                // If all the modifiers are correct then call the event.
                theRetVal = theHotKeyInfo->Consumer->OnHotKeyEvent(inChar, inRepeatCount, modifiers);
            }
        }
    }

    return theRetVal;
}

//=============================================================================
/**
 * Indicates whether the specified key is currently down or not.
 * @param inKeyCode The key to be checked
 * @return true if the key is down, otherwise false
 */
bool CHotKeys::IsKeyDown(Qt::KeyboardModifier inKeyCode)
{
    return qApp->keyboardModifiers() & inKeyCode;
}

//=============================================================================
/**
 * Retrieves the current status of the various modifier keys.
 * @return flag containing all of the modifier keys that are currently depressed
 */
Qt::KeyboardModifiers CHotKeys::GetCurrentKeyModifiers()
{
    return qApp->keyboardModifiers();
}

bool CHotKeys::isFocusOnControlThatWantsKeys()
{
    auto gview = qobject_cast<QGraphicsView *>(qApp->focusObject());
    if (gview) {
        auto control = gview->scene()->focusItem();
        if (control) {
            auto obj = qobject_cast<QGraphicsTextItem *>(control->toGraphicsObject());
            if (obj)
                return true;
        }
    } else {
        auto quickWidget = dynamic_cast<QQuickWidget *>(qApp->focusObject());
        if (quickWidget) {
            auto focusItem = quickWidget->quickWindow()->activeFocusItem();
            if (focusItem && focusItem->property("ignoreHotkeys").toBool())
                return true;
        }
    }
    return false;
}

//=============================================================================
/**
 * returns the mod and key.... mod will include all mods that came in comma delimeted
 *
 * @param inString a string containing a key combo to parse
 */
void CHotKeys::GetModAndKeyFromString(const Q3DStudio::CString &inString,
                                      Qt::KeyboardModifiers &inMod,
                                      int &inKey)
{
    inMod = 0;
    inKey = 0;
    CStringTokenizer theTokenizer(inString, L"/:");
    Q3DStudio::CString theMods = theTokenizer.GetCurrentPartition();
    ++theTokenizer;
    Q3DStudio::CString theKey = theTokenizer.GetCurrentPartition();
    CStringTokenizer theModTokenizer(theMods, L"/,");
    while (theModTokenizer.HasNextPartition()) {
        Q3DStudio::CString theCurrentMod = theModTokenizer.GetCurrentPartition();
        inMod |= GetModifierFromString(theCurrentMod);
        ++theModTokenizer;
    }
    inKey = GetKeyFromString(theKey);
}

//=============================================================================
/**
 * returns the unsigned int equivalent of a string modifer type
 *
 * @param inString a string containing a modifier
 */
Qt::KeyboardModifier CHotKeys::GetModifierFromString(const Q3DStudio::CString &inString)
{
    Qt::KeyboardModifier theRetVal = Qt::NoModifier;

    if (inString == L"ctrl")
        theRetVal = Qt::ControlModifier;
    else if (inString == L"shift")
        theRetVal = Qt::ShiftModifier;
    else if (inString == L"alt")
        theRetVal = Qt::AltModifier;
    return theRetVal;
}

//=============================================================================
/**
 * Finds a character or a unicode key depending on  lenght of the string
 *
 * @param inChar the ascii or key code for the char
 */
int CHotKeys::GetKeyFromString(Q3DStudio::CString inChar)
{
    int theRetVal = 0;
    if (inChar.Length() == 1) {
        Q3DStudio::CString theLowerCase = inChar.ToLower();
        char theChar = static_cast<char>(theLowerCase[(long)0]);
        theRetVal = theChar;
    } else if (inChar.Length() > 1) {
        theRetVal = atoi(inChar.GetCharStar());
    }
    return theRetVal;
}

void CHotKeys::CaptureHotKeys()
{
    m_CaptureKeys = true;
}

void CHotKeys::ReleaseHotKeys()
{
    m_CaptureKeys = false;
}