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

📄 qlineedit.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }    else if (event == QKeySequence::Paste) {        if (!d->readOnly)            paste();    }    else if (event == QKeySequence::Cut) {        if (!d->readOnly) {            cut();        }    }    else if (event == QKeySequence::DeleteEndOfLine) {        if (!d->readOnly) {            setSelection(d->cursor, d->text.size());            copy();            del();        }    }#endif //QT_NO_CLIPBOARD    else if (event == QKeySequence::MoveToStartOfLine) {        home(0);    }    else if (event == QKeySequence::MoveToEndOfLine) {        end(0);    }    else if (event == QKeySequence::SelectStartOfLine) {        home(1);    }    else if (event == QKeySequence::SelectEndOfLine) {        end(1);    }    else if (event == QKeySequence::MoveToNextChar) {#ifndef Q_WS_WIN        if (d->hasSelectedText()) {#else        if (d->hasSelectedText() && d->completer            && d->completer->completionMode() == QCompleter::InlineCompletion) {#endif            d->moveCursor(d->selend, false);        } else {            cursorForward(0, layoutDirection() == Qt::LeftToRight ? 1 : -1);        }    }    else if (event == QKeySequence::SelectNextChar) {        cursorForward(1, layoutDirection() == Qt::LeftToRight ? 1 : -1);    }    else if (event == QKeySequence::MoveToPreviousChar) {#ifndef Q_WS_WIN        if (d->hasSelectedText()) {#else        if (d->hasSelectedText() && d->completer            && d->completer->completionMode() == QCompleter::InlineCompletion) {#endif            d->moveCursor(d->selstart, false);        } else {            cursorBackward(0, layoutDirection() == Qt::LeftToRight ? 1 : -1);        }    }    else if (event == QKeySequence::SelectPreviousChar) {        cursorBackward(1, layoutDirection() == Qt::LeftToRight ? 1 : -1);    }    else if (event == QKeySequence::MoveToNextWord) {        if (echoMode() == Normal)            layoutDirection() == Qt::LeftToRight ? cursorWordForward(0) : cursorWordBackward(0);        else            layoutDirection() == Qt::LeftToRight ? end(0) : home(0);    }    else if (event == QKeySequence::MoveToPreviousWord) {        if (echoMode() == Normal)            layoutDirection() == Qt::LeftToRight ? cursorWordBackward(0) : cursorWordForward(0);        else if (!d->readOnly) {            layoutDirection() == Qt::LeftToRight ? home(0) : end(0);        }    }    else if (event == QKeySequence::SelectNextWord) {        if (echoMode() == Normal)            layoutDirection() == Qt::LeftToRight ? cursorWordForward(1) : cursorWordBackward(1);        else            layoutDirection() == Qt::LeftToRight ? end(1) : home(1);    }    else if (event == QKeySequence::SelectPreviousWord) {        if (echoMode() == Normal)            layoutDirection() == Qt::LeftToRight ? cursorWordBackward(1) : cursorWordForward(1);        else            layoutDirection() == Qt::LeftToRight ? home(1) : end(1);    }    else if (event == QKeySequence::Delete) {        if (!d->readOnly)            del();    }    else if (event == QKeySequence::DeleteEndOfWord) {        if (!d->readOnly) {            cursorWordForward(true);            del();        }    }    else if (event == QKeySequence::DeleteStartOfWord) {        if (!d->readOnly) {            cursorWordBackward(true);            del();        }    }#endif // QT_NO_SHORTCUT    else {#ifdef Q_WS_MAC        if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {            Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier);            if (myModifiers & Qt::ShiftModifier) {                if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier)                        || myModifiers == (Qt::AltModifier|Qt::ShiftModifier)                        || myModifiers == Qt::ShiftModifier) {                    event->key() == Qt::Key_Up ? home(1) : end(1);                }            } else {                if ((myModifiers == Qt::ControlModifier                     || myModifiers == Qt::AltModifier                     || myModifiers == Qt::NoModifier)) {                    event->key() == Qt::Key_Up ? home(0) : end(0);                }            }        }#endif        if (event->modifiers() & Qt::ControlModifier) {            switch (event->key()) {            case Qt::Key_Backspace:                if (!d->readOnly) {                    cursorWordBackward(true);                    del();                }                break;#ifndef QT_NO_COMPLETER            case Qt::Key_Up:            case Qt::Key_Down:                d->complete(event->key());                break;#endif#if defined(Q_WS_X11)            case Qt::Key_E:                end(0);                break;            case Qt::Key_U:                if (!d->readOnly) {                    setSelection(0, d->text.size());#ifndef QT_NO_CLIPBOARD                    copy();#endif                    del();                }            break;#endif            default:                unknown = true;            }        } else { // ### check for *no* modifier            switch (event->key()) {            case Qt::Key_Backspace:                if (!d->readOnly) {                    backspace();#ifndef QT_NO_COMPLETER                    d->complete(Qt::Key_Backspace);#endif                }                break;#ifdef QT_KEYPAD_NAVIGATION            case Qt::Key_Back:                if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat()                    && !isReadOnly()) {                    if (text().length() == 0) {                        setText(d->origText);                        if (d->resumePassword)                        {                            setEchoMode(PasswordEchoOnEdit);                            d->resumePassword = false;                        }                        setEditFocus(false);                    } else if (!d->deleteAllTimer.isActive()) {                        d->deleteAllTimer.start(750, this);                    }                } else {                    unknown = true;                }                break;#endif            default:                unknown = true;            }        }    }    if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) {        setLayoutDirection((event->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft);        d->updateTextLayout();        update();        unknown = false;    }    if (unknown && !d->readOnly) {        QString t = event->text();        if (!t.isEmpty() && t.at(0).isPrint()) {            insert(t);#ifndef QT_NO_COMPLETER            d->complete(event->key());#endif            event->accept();            return;        }    }    if (unknown)        event->ignore();    else        event->accept();}/*!  This function is not intended as polymorphic usage. Just a shared code  fragment that calls QInputContext::mouseHandler for this  class.*/bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e ){#if !defined QT_NO_IM    Q_Q(QLineEdit);    if ( composeMode() ) {	int tmp_cursor = xToPos(e->pos().x());	int mousePos = tmp_cursor - cursor;	if ( mousePos < 0 || mousePos > textLayout.preeditAreaText().length() ) {            mousePos = -1;	    // don't send move events outside the preedit area            if ( e->type() == QEvent::MouseMove )                return true;        }        QInputContext *qic = q->inputContext();        if ( qic )            // may be causing reset() in some input methods            qic->mouseHandler(mousePos, e);        if (!textLayout.preeditAreaText().isEmpty())            return true;    }#else    Q_UNUSED(e);#endif    return false;}/*! \reimp */void QLineEdit::inputMethodEvent(QInputMethodEvent *e){    Q_D(QLineEdit);    if (d->readOnly) {        e->ignore();        return;    }    if(echoMode() == PasswordEchoOnEdit)    {        setEchoMode(Normal);        clear();        d->resumePassword = true;    }#ifdef QT_KEYPAD_NAVIGATION    // Focus in if currently in navigation focus on the widget    // Only focus in on preedits, to allow input methods to    // commit text as they focus out without interfering with focus    if (QApplication::keypadNavigationEnabled() &&             hasFocus() && !hasEditFocus()            && !e->preeditString().isEmpty()) {        setEditFocus(true);        selectAll();        // so text is replaced rather than appended to    }#endif    int priorState = d->undoState;    d->removeSelectedText();    int c = d->cursor; // cursor position after insertion of commit string    if (e->replacementStart() <= 0)        c += e->commitString().length() + qMin(-e->replacementStart(), e->replacementLength());    d->cursor += e->replacementStart();    // insert commit string    if (e->replacementLength()) {        d->selstart = d->cursor;        d->selend = d->selstart + e->replacementLength();        d->removeSelectedText();    }    if (!e->commitString().isEmpty())        d->insert(e->commitString());    d->cursor = c;    d->textLayout.setPreeditArea(d->cursor, e->preeditString());    d->preeditCursor = e->preeditString().length();    d->hideCursor = false;    QList<QTextLayout::FormatRange> formats;    for (int i = 0; i < e->attributes().size(); ++i) {        const QInputMethodEvent::Attribute &a = e->attributes().at(i);        if (a.type == QInputMethodEvent::Cursor) {            d->preeditCursor = a.start;            d->hideCursor = !a.length;        } else if (a.type == QInputMethodEvent::TextFormat) {            QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat();            if (f.isValid()) {                QTextLayout::FormatRange o;                o.start = a.start + d->cursor;                o.length = a.length;                o.format = f;                formats.append(o);            }        }    }    d->textLayout.setAdditionalFormats(formats);    d->updateTextLayout();    update();    if (!e->commitString().isEmpty())        d->emitCursorPositionChanged();    d->finishChange(priorState);#ifndef QT_NO_COMPLETER    if (!e->commitString().isEmpty())        d->complete(Qt::Key_unknown);#endif}/*!\reimp*/QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const{    Q_D(const QLineEdit);    switch(property) {    case Qt::ImMicroFocus:        return d->cursorRect();    case Qt::ImFont:        return font();    case Qt::ImCursorPosition:        return QVariant(d->cursor);    case Qt::ImSurroundingText:        return QVariant(d->text);    case Qt::ImCurrentSelection:        return QVariant(selectedText());    default:        return QVariant();    }}/*!\reimp*/void QLineEdit::focusInEvent(QFocusEvent *e){    Q_D(QLineEdit);    if (e->reason() == Qt::TabFocusReason ||         e->reason() == Qt::BacktabFocusReason  ||         e->reason() == Qt::ShortcutFocusReason)        if (d->maskData)            d->moveCursor(d->nextMaskBlank(0));        else if (!d->hasSelectedText())            selectAll();#ifdef QT_KEYPAD_NAVIGATION    if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && e->reason() == Qt::PopupFocusReason))#endif    if (!d->cursorTimer) {        int cft = QApplication::cursorFlashTime();        d->cursorTimer = cft ? startTimer(cft/2) : -1;    }    QStyleOptionFrameV2 opt;    initStyleOption(&opt);    if((!hasSelectedText() && d->textLayout.preeditAreaText().isEmpty())       || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))        d->setCursorVisible(true);#ifdef Q_WS_MAC    if (d->echoMode == Password || d->echoMode == NoEcho)        qt_mac_secure_keyboard(true);#endif#ifdef QT_KEYPAD_NAVIGATION    d->origText = d->text;#endif#ifndef QT_NO_COMPLETER    if (d->completer) {        d->completer->setWidget(this);        QObject::connect(d->completer, SIGNAL(activated(QString)),                         this, SLOT(setText(QString)));        QObject::connect(d->completer, SIGNAL(highlighted(QString)),                         this, SLOT(_q_completionHighlighted(QString)));    }#endif    update();}/*!\reimp*/void QLineEdit::focusOutEvent(QFocusEvent *e){    Q_D(QLineEdit);    if(d->resumePassword){        setEchoMode(PasswordEchoOnEdit);        d->resumePassword = false;    }    Qt::FocusReason reason = e->reason();    if (reason != Qt::ActiveWindowFocusReason &&        reason != Qt::PopupFocusReason)        deselect();    d->setCursorVisible(false);    if (d->cursorTimer > 0)        killTimer(d->cursorTimer);    d->cursorTimer = 0;    if (reason != Qt::PopupFocusReason        && !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) {        if (!d->emitingEditingFinished) {            if (hasAcceptableInput() || d->fixup()) {                d->emitingEditingFinished = true;                emit editingFinished();                d->emitingEditingFinished = false;            }        }#ifdef QT3_SUPPORT        emit lostFocus();#endif    }#ifdef Q_WS_MAC    if (d->echoMode == Password || d->echoMode == NoEcho)        qt_mac_secure_keyboard(false);#endif#ifdef QT_KEYPAD_NAVIGATION    d->origText = QString();#endif#ifndef QT_NO_COMPLETER    if (d->completer) {        QObject::disconnect(d->completer, 0, this, 0);    }#endif    update();}/*!\reimp*/void QLineEdit::paintEvent(QPaintEvent *){    Q_D(QLineEdit);    QPainter p(this);    QRect r = rect();    const QPalet

⌨️ 快捷键说明

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