⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3accel.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    if (QKeySequence::NoMatch == currentState) {        e->t = QEvent::AccelOverride;        e->ignore();        QApplication::sendSpontaneousEvent(w, e);        if (e->isAccepted())            return false;    }    e->t = QEvent::Accel;    e->ignore();    QApplication::sendSpontaneousEvent(w, e);    return e->isAccepted();}bool Q3AccelManager::tryComposeUnicode(QWidget* w, QKeyEvent* e){    if (metaComposeUnicode) {        int value = e->key() - Key_0;        // Ignore acceloverrides so we don't trigger        // accels on keypad when Meta compose is on        if ((e->type() == QEvent::AccelOverride) &&             (e->state() == Qt::Keypad + Qt::MetaButton)) {            e->accept();        // Meta compose start/continue        } else if ((e->type() == QEvent::KeyPress) &&             (e->state() == Qt::Keypad + Qt::MetaButton)) {            if (value >= 0 && value <= 9) {                composedUnicode *= 10;                composedUnicode += value;                return true;            } else {                // Composing interrupted, dispatch!                if (composedUnicode) {                    QChar ch(composedUnicode);                    QString s(ch);                    QKeyEvent kep(QEvent::KeyPress, 0, ch.row() ? 0 : ch.cell(), 0, s);                    QKeyEvent ker(QEvent::KeyRelease, 0, ch.row() ? 0 : ch.cell(), 0, s);                    QApplication::sendEvent(w, &kep);                    QApplication::sendEvent(w, &ker);                }                composedUnicode = 0;                return true;            }        // Meta compose end, dispatch        } else if ((e->type() == QEvent::KeyRelease) &&                    (e->key() == Key_Meta) &&                    (composedUnicode != 0)) {            if ((composedUnicode > 0) &&                 (composedUnicode < 0xFFFE)) {                QChar ch(composedUnicode);                QString s(ch);                QKeyEvent kep(QEvent::KeyPress, 0, ch.row() ? 0 : ch.cell(), 0, s);                QKeyEvent ker(QEvent::KeyRelease, 0, ch.row() ? 0 : ch.cell(), 0, s);                QApplication::sendEvent(w, &kep);                QApplication::sendEvent(w, &ker);            }            composedUnicode = 0;            return true;        }    }    return false;}/*    \internal    Checks for possible accelerators, if no widget    ate the keypres, or we are in the middle of a    partial key sequence.*/bool Q3AccelManager::dispatchAccelEvent(QWidget* w, QKeyEvent* e){#ifndef QT_NO_STATUSBAR    // Needs to be declared and used here because of "goto doclash"    QStatusBar* mainStatusBar = 0;#endif    // Modifiers can NOT be accelerators...    if (e->key() >= Key_Shift &&         e->key() <= Key_Alt)         return false;    QKeySequence::SequenceMatch result = QKeySequence::NoMatch;    QKeySequence tocheck, partial;    Q3AccelPrivate* accel = 0;    Q3AccelItem* item = 0;    Q3AccelPrivate* firstaccel = 0;    Q3AccelItem* firstitem = 0;    Q3AccelPrivate* lastaccel = 0;    Q3AccelItem* lastitem = 0;    QKeyEvent pe = *e;    int n = -1;    int hasShift = (e->state()&Qt::ShiftButton)?1:0;    bool identicalDisabled = false;    bool matchFound = false;    do {        accel = accels.first();        matchFound = false;        while (accel) {            if (correctSubWindow(w, accel)) {                if (accel->enabled) {                    item = accel->aitems.last();                    while(item) {                        if (QKeySequence::Identical == (result = match(&pe, item, tocheck))) {                            if (item->enabled) {                                if (!firstaccel) {                                    firstaccel = accel;                                    firstitem = item;                                }                                lastaccel = accel;                                lastitem = item;                                n++;                                matchFound = true;                                if (n > QMAX(clash,0))                                    goto doclash;                            } else {                                identicalDisabled = true;                            }                        }                        if (item->enabled && QKeySequence::PartialMatch == result) {                            partial = tocheck;                            matchFound = true;                        }                        item = accel->aitems.prev();                    }                } else {                    item = accel->aitems.last();                    while(item) {                        if (QKeySequence::Identical == match(&pe, item, tocheck))                            identicalDisabled = true;                        item = accel->aitems.prev();                    }                }            }            accel = accels.next();        }        pe = QKeyEvent(QEvent::Accel, pe.key(), pe.ascii(), pe.state()&~Qt::ShiftButton, pe.text());    } while (hasShift-- && !matchFound && !identicalDisabled);#ifndef QT_NO_STATUSBAR    mainStatusBar = (QStatusBar*) w->window()->child(0, "QStatusBar");#endif    if (n < 0) { // no match found        currentState = partial.count() ? QKeySequence::PartialMatch : QKeySequence::NoMatch;#ifndef QT_NO_STATUSBAR        // Only display message if we are, or were, in a partial match        if (mainStatusBar && (QKeySequence::PartialMatch == currentState || intermediate.count())) {            if (currentState == QKeySequence::PartialMatch) {                mainStatusBar->showMessage((QString)partial + QLatin1String(", ..."));            } else if (!identicalDisabled) {                QString message = Q3Accel::tr("%1, %2 not defined").                    arg((QString)intermediate).                    arg(QKeySequence::encodeString(e->key() | translateModifiers(e->state())));                mainStatusBar->showMessage(message, 2000);                // Since we're a NoMatch, reset the clash count                clash = -1;            } else {            	mainStatusBar->clearMessage();            }        }#endif        bool eatKey = (QKeySequence::PartialMatch == currentState || intermediate.count());        intermediate = partial;        if (eatKey)            e->accept();        return eatKey;    } else if (n == 0) { // found exactly one match        clash = -1; // reset#ifndef QT_NO_STATUSBAR        if (currentState == QKeySequence::PartialMatch && mainStatusBar)                mainStatusBar->clearMessage();#endif        currentState = QKeySequence::NoMatch; // Free sequence keylock        intermediate = QKeySequence();        lastaccel->activate(lastitem);        e->accept();        return true;    } doclash: // found more than one match#ifndef QT_NO_STATUSBAR    if (!mainStatusBar) // if "goto doclash", we need to get status bar again.        mainStatusBar = (QStatusBar*) w->window()->child(0, "QStatusBar");#endif    QString message = Q3Accel::tr("Ambiguous %1 not handled").arg((QString)tocheck);    if (clash >= 0 && n > clash) { // pick next  match        intermediate = QKeySequence();        currentState = QKeySequence::NoMatch; // Free sequence keylock        clash++;#ifndef QT_NO_STATUSBAR        if (mainStatusBar &&             !lastitem->signal &&             !(lastaccel->parent->receivers(SIGNAL(activatedAmbiguously(int)))))            mainStatusBar->showMessage(message, 2000);#endif        lastaccel->activateAmbiguously(lastitem);    } else { // start (or wrap) with the first matching        intermediate = QKeySequence();        currentState = QKeySequence::NoMatch; // Free sequence keylock        clash = 0;#ifndef QT_NO_STATUSBAR        if (mainStatusBar &&             !firstitem->signal &&             !(firstaccel->parent->receivers(SIGNAL(activatedAmbiguously(int)))))            mainStatusBar->showMessage(message, 2000);#endif        firstaccel->activateAmbiguously(firstitem);    }    e->accept();    return true;}Q3AccelPrivate::Q3AccelPrivate(Q3Accel* p)    : parent(p){    Q3AccelManager::self()->registerAccel(this);    aitems.setAutoDelete(true);    ignorewhatsthis = false;}Q3AccelPrivate::~Q3AccelPrivate(){    Q3AccelManager::self()->unregisterAccel(this);}static Q3AccelItem *find_id(Q3AccelList &list, int id){    register Q3AccelItem *item = list.first();    while (item && item->id != id)        item = list.next();    return item;}static Q3AccelItem *find_key(Q3AccelList &list, const QKeySequence &key){    register Q3AccelItem *item = list.first();    while (item && !(item->key == key))        item = list.next();    return item;}/*!    Constructs a Q3Accel object called \a name, with parent \a parent.    The accelerator operates on \a parent.*/Q3Accel::Q3Accel(QWidget *parent, const char *name)    : QObject(parent, name){    d = new Q3AccelPrivate(this);    d->enabled = true;    d->watch = parent;#if defined(QT_CHECK_NULL)    if (!d->watch)        qWarning("Q3Accel: An accelerator must have a parent or a watch widget");#endif}/*!    Constructs a Q3Accel object called \a name, that operates on \a    watch, and is a child of \a parent.    This constructor is not needed for normal application programming.*/Q3Accel::Q3Accel(QWidget* watch, QObject *parent, const char *name)    : QObject(parent, name){    d = new Q3AccelPrivate(this);    d->enabled = true;    d->watch = watch;#if defined(QT_CHECK_NULL)    if (!d->watch)        qWarning("Q3Accel: An accelerator must have a parent or a watch widget");#endif}/*!    Destroys the accelerator object and frees all allocated resources.*/Q3Accel::~Q3Accel(){    delete d;}/*!    \fn void Q3Accel::activated(int id)    This signal is emitted when the user types the shortcut's key    sequence. \a id is a number that identifies this particular    accelerator item.    \sa activatedAmbiguously()*//*!    \fn void Q3Accel::activatedAmbiguously(int id)    This signal is emitted when the user types a shortcut key    sequence that is ambiguous. For example, if one key sequence is a    "prefix" for another and the user types these keys it isn't clear    if they want the shorter key sequence, or if they're about to    type more to complete the longer key sequence. \a id is a number    that identifies this particular accelerator item.    \sa activated()*//*!    Returns true if the accelerator is enabled; otherwise returns    false.    \sa setEnabled(), isItemEnabled()*/bool Q3Accel::isEnabled() const{    return d->enabled;}/*!    Enables the accelerator if \a enable is true, or disables it if \a    enable is false.    Individual keys can also be enabled or disabled using    setItemEnabled(). To work, a key must be an enabled item in an    enabled Q3Accel.    \sa isEnabled(), setItemEnabled()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -