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

📄 qlineedit.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + horizontalMargin);    if (chr && pos < (int) d->text.length())        *chr = d->text.at(pos);    return pos;}/*!    Use selectedText() and selectionStart() instead.*/bool QLineEdit::getSelection(int *start, int *end){    Q_D(QLineEdit);    if (d->hasSelectedText() && start && end) {        *start = d->selstart;        *end = d->selend;        return true;    }    return false;}#endif/*!    Selects text from position \a start and for \a length characters.    Negative lengths are allowed.    \sa deselect() selectAll() selectedText()*/void QLineEdit::setSelection(int start, int length){    Q_D(QLineEdit);    if (start < 0 || start > (int)d->text.length()) {        qWarning("QLineEdit: Invalid start position: %d.", start);        return;    } else {        if (length > 0) {            d->selstart = start;            d->selend = qMin(start + length, (int)d->text.length());            d->cursor = d->selend;        } else {            d->selstart = qMax(start + length, 0);            d->selend = start;            d->cursor = d->selstart;        }    }    update();    d->emitCursorPositionChanged();}/*!    \property QLineEdit::undoAvailable    \brief whether undo is available*/bool QLineEdit::isUndoAvailable() const{    Q_D(const QLineEdit);    return d->isUndoAvailable();}/*!    \property QLineEdit::redoAvailable    \brief whether redo is available*/bool QLineEdit::isRedoAvailable() const{    Q_D(const QLineEdit);    return d->isRedoAvailable();}/*!    \property QLineEdit::dragEnabled    \brief whether the lineedit starts a drag if the user presses and    moves the mouse on some selected text    Dragging is disabled by default.*/bool QLineEdit::dragEnabled() const{    Q_D(const QLineEdit);    return d->dragEnabled;}void QLineEdit::setDragEnabled(bool b){    Q_D(QLineEdit);    d->dragEnabled = b;}/*!    \property QLineEdit::acceptableInput    \brief whether the input satisfies the inputMask and the    validator.    \sa setInputMask(), setValidator()*/bool QLineEdit::hasAcceptableInput() const{    Q_D(const QLineEdit);    return d->hasAcceptableInput(d->text);}/*!    \property QLineEdit::inputMask    \brief The validation input mask    If no mask is set, inputMask() returns an empty string.    Sets the QLineEdit's validation mask. Validators can be used    instead of, or in conjunction with masks; see setValidator().    Unset the mask and return to normal QLineEdit operation by passing    an empty string ("") or just calling setInputMask() with no    arguments.    The mask format understands these mask characters:    \table    \header \i Character \i Meaning    \row \i \c A \i ASCII alphabetic character required. A-Z, a-z.    \row \i \c a \i ASCII alphabetic character permitted but not required.    \row \i \c N \i ASCII alphanumeric character required. A-Z, a-z, 0-9.    \row \i \c n \i ASCII alphanumeric character permitted but not required.    \row \i \c X \i Any character required.    \row \i \c x \i Any character permitted but not required.    \row \i \c 9 \i ASCII digit required. 0-9.    \row \i \c 0 \i ASCII digit permitted but not required.    \row \i \c D \i ASCII digit required. 1-9.    \row \i \c d \i ASCII digit permitted but not required (1-9).    \row \i \c # \i ASCII digit or plus/minus sign permitted but not required.    \row \i \c H \i Hexadecimal character required. A-F, a-f, 0-9.    \row \i \c h \i Hexadecimal character permitted but not required.    \row \i \c B \i Binary character required. 0-1.    \row \i \c b \i Binary character permitted but not required.    \row \i \c > \i All following alphabetic characters are uppercased.    \row \i \c < \i All following alphabetic characters are lowercased.    \row \i \c ! \i Switch off case conversion.    \row \i \tt{\\} \i Use \tt{\\} to escape the special                           characters listed above to use them as                           separators.    \endtable    The mask consists of a string of mask characters and separators,    optionally followed by a semicolon and the character used for    blanks: the blank characters are always removed from the text    after editing. The default blank character is space.    Examples:    \table    \header \i Mask \i Notes    \row \i \c 000.000.000.000;_ \i IP address; blanks are \c{_}.    \row \i \c HH:HH:HH:HH:HH:HH;_ \i MAC address    \row \i \c 0000-00-00 \i ISO Date; blanks are \c space    \row \i \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \i License number;    blanks are \c - and all (alphabetic) characters are converted to    uppercase.    \endtable    To get range control (e.g. for an IP address) use masks together    with \link setValidator() validators\endlink.    \sa maxLength*/QString QLineEdit::inputMask() const{    Q_D(const QLineEdit);    return (d->maskData ? d->inputMask + ';' + d->blank : QString());}void QLineEdit::setInputMask(const QString &inputMask){    Q_D(QLineEdit);    d->parseInputMask(inputMask);    if (d->maskData)        d->moveCursor(d->nextMaskBlank(0));}/*!    Selects all the text (i.e. highlights it) and moves the cursor to    the end. This is useful when a default value has been inserted    because if the user types before clicking on the widget, the    selected text will be deleted.    \sa setSelection() deselect()*/void QLineEdit::selectAll(){    Q_D(QLineEdit);    d->selstart = d->selend = d->cursor = 0;    d->moveCursor(d->text.length(), true);}/*!    Deselects any selected text.    \sa setSelection() selectAll()*/void QLineEdit::deselect(){    Q_D(QLineEdit);    d->deselect();    d->finishChange();}/*!    Deletes any selected text, inserts \a newText, and validates the    result. If it is valid, it sets it as the new contents of the line    edit.    \sa setText(), clear()*/void QLineEdit::insert(const QString &newText){//     q->resetInputContext(); //#### FIX ME IN QT    Q_D(QLineEdit);    int priorState = d->undoState;    d->removeSelectedText();    d->insert(newText);    d->finishChange(priorState);}/*!    Clears the contents of the line edit.    \sa setText(), insert()*/void QLineEdit::clear(){    Q_D(QLineEdit);    int priorState = d->undoState;    resetInputContext();    d->selstart = 0;    d->selend = d->text.length();    d->removeSelectedText();    d->separate();    d->finishChange(priorState);}/*!    Undoes the last operation if undo is \link    QLineEdit::undoAvailable available\endlink. Deselects any current    selection, and updates the selection start to the current cursor    position.*/void QLineEdit::undo(){    Q_D(QLineEdit);    resetInputContext();    d->undo();    d->finishChange(-1, true);}/*!    Redoes the last operation if redo is \link    QLineEdit::redoAvailable available\endlink.*/void QLineEdit::redo(){    Q_D(QLineEdit);    resetInputContext();    d->redo();    d->finishChange();}/*!    \property QLineEdit::readOnly    \brief whether the line edit is read only.    In read-only mode, the user can still copy the text to the    clipboard, or drag and drop the text (if echoMode() is \l Normal),    but cannot edit it.    QLineEdit does not show a cursor in read-only mode.    \sa setEnabled()*/bool QLineEdit::isReadOnly() const{    Q_D(const QLineEdit);    return d->readOnly;}void QLineEdit::setReadOnly(bool enable){    Q_D(QLineEdit);    d->readOnly = enable;    update();}#ifndef QT_NO_CLIPBOARD/*!    Copies the selected text to the clipboard and deletes it, if there    is any, and if echoMode() is \l Normal.    If the current validator disallows deleting the selected text,    cut() will copy without deleting.    \sa copy() paste() setValidator()*/void QLineEdit::cut(){    if (hasSelectedText()) {        copy();        del();    }}/*!    Copies the selected text to the clipboard, if there is any, and if    echoMode() is \l Normal.    \sa cut() paste()*/void QLineEdit::copy() const{    Q_D(const QLineEdit);    d->copy();}/*!    Inserts the clipboard's text at the cursor position, deleting any    selected text, providing the line edit is not \link    QLineEdit::readOnly read-only\endlink.    If the end result would not be acceptable to the current    \link setValidator() validator\endlink, nothing happens.    \sa copy() cut()*/void QLineEdit::paste(){    insert(QApplication::clipboard()->text(QClipboard::Clipboard));}void QLineEditPrivate::copy(bool clipboard) const{    Q_Q(const QLineEdit);    QString t = q->selectedText();    if (!t.isEmpty() && echoMode == QLineEdit::Normal) {        q->disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), q, 0);        QApplication::clipboard()->setText(t, clipboard ? QClipboard::Clipboard : QClipboard::Selection);        q->connect(QApplication::clipboard(), SIGNAL(selectionChanged()),                   q, SLOT(_q_clipboardChanged()));    }}#endif // !QT_NO_CLIPBOARD/*! \reimp*/bool QLineEdit::event(QEvent * e){    Q_D(QLineEdit);    if (e->type() == QEvent::ShortcutOverride && !d->readOnly) {        QKeyEvent* ke = (QKeyEvent*) e;        if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier            || ke->modifiers() == Qt::KeypadModifier) {            if (ke->key() < Qt::Key_Escape) {                ke->accept();            } else {                switch (ke->key()) {                case Qt::Key_Delete:                case Qt::Key_Home:                case Qt::Key_End:                case Qt::Key_Backspace:                case Qt::Key_Left:                case Qt::Key_Right:                    ke->accept();                default:                    break;                }            }        } else if (ke->modifiers() & Qt::ControlModifier) {            switch (ke->key()) {// Those are too frequently used for application functionality/*            case Qt::Key_A:            case Qt::Key_B:            case Qt::Key_D:            case Qt::Key_E:            case Qt::Key_F:            case Qt::Key_H:            case Qt::Key_K:*/            case Qt::Key_C:            case Qt::Key_V:            case Qt::Key_X:            case Qt::Key_Y:            case Qt::Key_Z:            case Qt::Key_Left:            case Qt::Key_Right:#if !defined(Q_WS_MAC)            case Qt::Key_Insert:            case Qt::Key_Delete:#endif                ke->accept();            default:                break;            }        }    } else if (e->type() == QEvent::Timer) {        // should be timerEvent, is here for binary compatibility        int timerId = ((QTimerEvent*)e)->timerId();        if (timerId == d->cursorTimer) {            QStyleOptionFrame opt = d->getStyleOption();            if(!hasSelectedText()               || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))                d->setCursorVisible(!d->cursorVisible);#ifndef QT_NO_DRAGANDDROP        } else if (timerId == d->dndTimer.timerId()) {            d->drag();#endif        }        else if (timerId == d->tripleClickTimer.timerId())            d->tripleClickTimer.stop();#ifdef QT_KEYPAD_NAVIGATION        else if (timerId == d->deleteAllTimer.timerId()) {            d->deleteAllTimer.stop();            clear();        }#endif    } else if (e->type() == QEvent::ContextMenu) {#ifndef QT_NO_IM        if (d->composeMode())            return true;#endif        d->separate();    }#ifdef QT_KEYPAD_NAVIGATION    else if (e->type() == QEvent::KeyRelease) {        if (QApplication::keypadNavigationEnabled()) {            QKeyEvent *ke = (QKeyEvent *)e;            if ( !ke->isAutoRepeat() && !isReadOnly()                    && ke->key() == Qt::Key_Back                    && d->deleteAllTimer.isActive()) {                d->deleteAllTimer.stop();                backspace();                ke->accept();                return true;            }        }    }#endif    return QWidget::event(e);}/*! \reimp*/void QLineEdit::mousePressEvent(QMouseEvent* e){

⌨️ 快捷键说明

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