Home · All Classes · Main Classes · Deprecated
Public Types | Public Slots | Signals | Public Member Functions | Properties

MTextEdit Class Reference

MTextEdit is used to edit and display both plain and rich text. More...

Inheritance diagram for MTextEdit:
Inheritance graph
[legend]
Collaboration diagram for MTextEdit:
Collaboration graph
[legend]

List of all members.

Public Types

enum  TextFieldLocationType { Word, WordBoundary }
typedef M::TextContentType TextContentType

Public Slots

bool setText (const QString &text)
bool insert (const QString &text)
bool setCursorPosition (int index)
void selectAll ()
void clear ()
virtual void copy ()
virtual void paste ()
virtual void cut ()

Signals

void gainedFocus (Qt::FocusReason)
void lostFocus (Qt::FocusReason)
void textChanged ()
void selectionChanged ()
void cursorPositionChanged ()
void copyAvailable (bool yes)
void pasteFailed ()
void returnPressed ()

Public Member Functions

 MTextEdit (MTextEditModel::LineMode type=MTextEditModel::SingleLine, const QString &text=QString(), QGraphicsItem *parent=0)
 MTextEdit (MTextEditModel *model, QGraphicsItem *parent)
virtual ~MTextEdit ()
int cursorPosition () const
MTextEditModel::EditMode mode () const
MTextEditModel::LineMode lineMode () const
M::TextContentType contentType () const
QString text () const
QTextDocumentdocument () const
QTextCursor textCursor () const
void setTextCursor (const QTextCursor &cursor)
void setContentType (M::TextContentType type)
void setTextInteractionFlags (Qt::TextInteractionFlags)
Qt::TextInteractionFlags textInteractionFlags () const
void handleMousePress (int cursorPosition, QGraphicsSceneMouseEvent *event, TextFieldLocationType *location)
void handleMousePress (int cursorPosition, QGraphicsSceneMouseEvent *event)
void handleMouseRelease (int cursorPosition, QGraphicsSceneMouseEvent *event, TextFieldLocationType *location)
void handleMouseRelease (int cursorPosition, QGraphicsSceneMouseEvent *event)
void handleMouseMove (int cursorPosition, QGraphicsSceneMouseEvent *event)
bool isReadOnly () const
void setReadOnly (bool)
MTextEditModel::EchoMode echoMode () const
void setEchoMode (MTextEditModel::EchoMode echoMode)
void deselect ()
void setSelection (int start, int length, bool useBoundaries=false)
int selectionStart () const
QString selectedText () const
bool hasSelectedText () const
bool isSelectionEnabled () const
bool isAutoSelectionEnabled () const
void setAutoSelectionEnabled (bool enable)
void setInputMethodCorrectionEnabled (bool enabled)
bool inputMethodCorrectionEnabled () const
void setInputMethodPredictionEnabled (bool enabled)
bool inputMethodPredictionEnabled () const
int maxLength () const
void setMaxLength (int numChars)
void setInputMethodAutoCapitalizationEnabled (bool enabled)
bool inputMethodAutoCapitalizationEnabled () const
void setPrompt (const QString &prompt)
QString prompt () const
void setValidator (const QValidator *validator)
const QValidatorvalidator () const
bool hasAcceptableInput () const
void setCompleter (MCompleter *completer)
MCompletercompleter ()
void setAutoSipEnabled (bool enabled)
bool isAutoSipEnabled () const
void attachToolbar (const QString &name)
void attachToolbar (int id)
QString attachedToolbar () const
int attachedToolbarId () const
void detachToolbar ()

Properties

QString text
TextContentType contentType
Qt::TextInteractionFlags textInteractionFlags
QString prompt
bool inputMethodCorrectionEnabled
bool isReadOnly
bool inputMethodAutoCapitalizationEnabled
QString selectedText
bool autoSelectionEnabled
bool inputMethodPredictionEnabled
int maxLength
MTextEditModel::EchoMode echoMode
bool autoSipEnabled

Detailed Description

MTextEdit is used to edit and display both plain and rich text.

This widget can be used to show text and allow user to edit it. Roughly corresponds Qt's QTextEdit and QLineEdit widgets, the LineMode determines which. The mode can be set only at the constructor.

MTextEdit can operate in single or multiline mode. In single line mode no new lines can be added. If the text is too long to fit inside the widget, it can be scrolled horizontally in the basic MTextEditView, but text will not be wrapped to new lines. In multi line mode new lines can be added as necessary. The widget may also grow to make room for new lines, and if that is not enough, contents can be scrolled horizontally.

Caution: please do not use setInputMethodHints(Qt::InputMethodHints) with objects of this class, you have to use setContentType, setInputMethodCorrectionEnabled, setMaskedInput and other similar function instead.

If you just need to display a small text snippet then you should use MLabel instead.

Definition at line 58 of file corelib/widgets/mtextedit.h.


Member Typedef Documentation

Definition at line 81 of file corelib/widgets/mtextedit.h.


Member Enumeration Documentation

What is under the press or release location.

Enumerator:
Word 

Pressed on top of a word.

WordBoundary 

Pressed between words or empty space.

Definition at line 84 of file corelib/widgets/mtextedit.h.

                               {
        Word,

        WordBoundary
    };


Constructor & Destructor Documentation

MTextEdit::MTextEdit ( MTextEditModel::LineMode  type = MTextEditModel::SingleLine,
const QString text = QString(),
QGraphicsItem parent = 0 
) [explicit]

Default constructor. Creates a textedit field with a specified text and line mode.

Parameters:
type widget type (single line or multiline).
text optional text.
parent optional parent.

Definition at line 1313 of file mtextedit.cpp.

    : MWidgetController(new MTextEditPrivate, new MTextEditModel, parent)
{
    Q_D(MTextEdit);

    model()->setDocument(new QTextDocument(text, this->model()));
    model()->setLine(type);
    d->init();
}

Here is the call graph for this function:

MTextEdit::MTextEdit ( MTextEditModel model,
QGraphicsItem parent 
)

Creates a textedit field with a specified line mode, model and parent.

Parameters:
type widget type (single line or multiline).
model the model to be used.
parent the parent of the text edit.

Definition at line 1324 of file mtextedit.cpp.

    : MWidgetController(new MTextEditPrivate, model, parent)
{
    Q_D(MTextEdit);

    d->init();
}

MTextEdit::~MTextEdit (  )  [virtual]

Destructor.

Definition at line 1340 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    if (d->focusEventState == MTextEditPrivate::FocusInEventReceived) {
        d->closeAutoSip();
    }

    detachToolbar();

    // TODO: This cannot be right - MTextEdit does not own the model, so we cannot just delete stuff from the model (another text edit could be using them).
    // Revise after MR#434 has been merged!

    // kludge so view doesn't receive memberModified() signals for the deleted pointers
    model()->beginTransaction();

    //should delete QTextDocument and QTextCursor
    delete model()->document();
    delete model()->cursor();

    model()->setDocument(NULL);
    model()->setCursor(NULL);
}

Here is the call graph for this function:


Member Function Documentation

QString MTextEdit::attachedToolbar (  )  const

Returns the name of current attached custom toolbar. Note the toolbar name could be empty if the toolbar is attached by attachToolbar(int).

Definition at line 2780 of file mtextedit.cpp.

{
    return model()->toolbar();
}

Here is the call graph for this function:

int MTextEdit::attachedToolbarId (  )  const

Returns the unique identifier of current attached custom toolbar. Note if the toolbar is registered by attachToolbar(const QString &), then this toolbar identifier is valid until the widget attaches to another toolbar, or calls detachToolbar(), or widget is deleted.

See also:
attachToolbar(const QString&), attachToolbar(int).

Definition at line 2785 of file mtextedit.cpp.

{
    return model()->toolbarId();
}

Here is the call graph for this function:

void MTextEdit::attachToolbar ( int  id  ) 

Attaches a custom toolbar which identifier is id.

Parameters:
id should be a valid toolbar identifier which is registered by other widget or MInputMethodState::registerToolbar(). Note if another toolbar is already attached, detachToolbar() will be automatically called.

Definition at line 2762 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    if (attachedToolbarId() == id)
        return;
    detachToolbar();
    const QString toolbar = MInputMethodState::instance()->toolbar(id);
    if (!toolbar.isEmpty()) {
        // record attached toolbar identifier and file name.
        // The toolbar identifier is an unique id in the space of the application.
        // Two text entries may attach to the same toolbar file, but have two different
        // toolbar instances (two ids).
        model()->setToolbar(toolbar);
        model()->setToolbarId(id);
        d->icUpdate();
    }
}

Here is the call graph for this function:

void MTextEdit::attachToolbar ( const QString name  ) 

Attaches a custom toolbar named name.

Parameters:
name is the absolute file name of a custom toolbar, or the relative file under /usr/share/meegotouch/imtoolbars/. Note if another toolbar is already attached, detachToolbar() will be automatically called.

This method is provided for convenience. Equals with widget uses MInputMethodState::registerToolbar() to register a toolbar and obtain its identifier, then calls attachToolbar(int) to attach. The registered toolbar is valid until this widget attaches to another toolbar, or calls detachToolbar(), or widget is deleted.

See also:
attachToolbar(int), MInputMethodState::registerToolbar()

Definition at line 2749 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    if (attachedToolbar() == name)
        return;
    detachToolbar();
    // record registered toolbar identifier which will be unregistered when detachToolbar().
    d->registeredToolbarId = MInputMethodState::instance()->registerToolbar(name);
    model()->setToolbar(name);
    model()->setToolbarId(d->registeredToolbarId);
    d->icUpdate();
}

Here is the call graph for this function:

void MTextEdit::clear (  )  [slot]

deletes all content in the widget

Definition at line 2023 of file mtextedit.cpp.

{
    setText("");
}

Here is the call graph for this function:

MCompleter * MTextEdit::completer (  ) 

Returns the completer pointer, which is used by this text edit.

Definition at line 2733 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    return d->completer;
}

M::TextContentType MTextEdit::contentType (  )  const

Returns the content type of the text edit widget.

void MTextEdit::copy (  )  [virtual, slot]

Copies the selected text to the clipboard. If there is no selected text nothing happens.

Definition at line 2029 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    d->copy();
}

void MTextEdit::copyAvailable ( bool  yes  )  [signal]

This signal is emitted when text is selected or de-selected in the text edit.

int MTextEdit::cursorPosition (  )  const

Returns cursor position inside the text edit field.

Returns:
cursor position of the text edit widget.

Definition at line 1862 of file mtextedit.cpp.

{
    Q_D(const MTextEdit);
    return d->cursor()->position();
}

void MTextEdit::cursorPositionChanged (  )  [signal]

A signal to be emitted when the cursor position changes.

void MTextEdit::cut (  )  [virtual, slot]

Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is Normal.

If the current validator disallows deleting the selected text, cut() will copy without deleting. If text could not be changed (isReadOnly() return true) then cut() do nothing.

Definition at line 2087 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    QValidator::State result = QValidator::Acceptable;

    if (isReadOnly() || !d->copy()) {
        return;
    }

    QTextCursor *cursor = model()->cursor();

    if (d->validator) {
        QString textCopy = model()->document()->toPlainText();
        int start = cursor->selectionStart();
        int length = cursor->selectionEnd() - start;

        textCopy.remove(start, length);
        result = d->validator->validate(textCopy, start);
    }
    if (result != QValidator::Invalid) {
        cursor->removeSelectedText();
        d->setMode(MTextEditModel::EditModeBasic);
        d->sendCopyAvailable(false);
        emit selectionChanged();
        emit textChanged();
        emit cursorPositionChanged();
        d->updateMicroFocus();
    }
}

Here is the call graph for this function:

void MTextEdit::deselect (  ) 

removes any selection and changes mode to basic

Definition at line 2542 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    if (mode() == MTextEditModel::EditModeSelect) {
        d->cursor()->clearSelection();
        d->setMode(MTextEditModel::EditModeBasic);
        model()->updateCursor();
        d->sendCopyAvailable(false);
        d->updateMicroFocus();
        emit selectionChanged();
    }
}

Here is the call graph for this function:

void MTextEdit::detachToolbar (  ) 

Detaches the custom toolbar which is already attached before. detachToolbar() is automatically called in destructor.

See also:
attachToolbar(const QString &).

Definition at line 2790 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    // only unregister toolbar it has registered.
    if (d->registeredToolbarId >= 0) {
        MInputMethodState::instance()->unregisterToolbar(d->registeredToolbarId);
        d->registeredToolbarId = -1;
    }
    model()->setToolbar(QString());
    model()->setToolbarId(-1);
    d->icUpdate();
}

Here is the call graph for this function:

QTextDocument * MTextEdit::document (  )  const

Returns the current document.

Returns:
pointer to the document

Definition at line 2240 of file mtextedit.cpp.

{
    if (!model()->document()) {
        MTextEditModel *m = const_cast<MTextEditModel *>(model());
        m->setDocument(new QTextDocument(m));
    }

    return model()->document();
}

Here is the call graph for this function:

MTextEditModel::EchoMode MTextEdit::echoMode (  )  const

Returns the current echo mode.

void MTextEdit::gainedFocus ( Qt::FocusReason   )  [signal]

A signal which is emitted whenever the widget gets the focus.

void MTextEdit::handleMouseMove ( int  cursorPosition,
QGraphicsSceneMouseEvent event 
)

Handle mouse move event on the widget. THIS IS PURELY FOR THE VIEW. View should call this when receiving mouse moves that may happen on preedit (active mode). The implementation will notify possible input context.

Parameters:
cursorPosition position of the click within characters
event event the view received

Definition at line 1992 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    d->notifyInputContextMouseHandler(cursorPosition, event);
}

void MTextEdit::handleMousePress ( int  cursorPosition,
QGraphicsSceneMouseEvent event,
TextFieldLocationType location 
)

Handle mouse press event on the widget. THIS IS PURELY FOR THE VIEW. View should call this when receiving mouse presses that may happen on preedit (active mode). The implementation will notify possible input context.

Parameters:
cursorPosition position of the click within characters
event event the view received
location assigned by the method either as Word or as WordBoundary depending on where in text mouse is pressed
Note:
Location parameter is assigned by the method only if Qt::TextInteractionFlags is something other than Qt::NoTextInteraction

Definition at line 1887 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    if (textInteractionFlags() != Qt::NoTextInteraction && location) {
        QString text = document()->toPlainText();
        MBreakIterator breakIterator(text);

        if (breakIterator.isBoundary(cursorPosition) == true) {
            *location = MTextEdit::WordBoundary;
        } else {
            *location = MTextEdit::Word;
        }
    }

    d->notifyInputContextMouseHandler(cursorPosition, event);
}

Here is the call graph for this function:

void MTextEdit::handleMousePress ( int  cursorPosition,
QGraphicsSceneMouseEvent event 
)

Definition at line 1881 of file mtextedit.cpp.

{
    handleMousePress(cursorPosition, event, NULL);
}

Here is the call graph for this function:

void MTextEdit::handleMouseRelease ( int  cursorPosition,
QGraphicsSceneMouseEvent event,
TextFieldLocationType location 
)

Handle mouse release event on the widget. THIS IS PURELY FOR THE VIEW. View should call this on mouse releases, except when release ends a selection the view has not started. The implementation will notify possible input context, relocate the cursor or make clicked word as preedit if possible.

Parameters:
cursorPosition position of the click within characters
event event the view received
location assigned by the method either as Word or as WordBoundary depending on where in text mouse is released
Note:
Location parameter is assigned by the method only if Qt::TextInteractionFlags is something other than Qt::NoTextInteraction

Definition at line 1913 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    if (textInteractionFlags() == Qt::NoTextInteraction)
        return;

    int cursorPositionBefore = cursorPosition();

    deselect();

    if (d->isPositionOnPreedit(eventCursorPosition) == false) {
        // input context takes care of releases happening on top of preedit, the rest
        // is handled here
        d->commitPreedit();

        QString text = document()->toPlainText();
        MBreakIterator breakIterator(text);
        QInputContext *ic = qApp->inputContext();

        // clicks on word boundaries move the cursor
        if (breakIterator.isBoundary(eventCursorPosition) == true) {
            if (location) {
                *location = MTextEdit::WordBoundary;
            }
            d->setCursorPosition(eventCursorPosition);

        } else {
            if (location) {
                *location = MTextEdit::Word;
            }
            if (inputMethodCorrectionEnabled()) {
                // clicks on words remove them from the normal contents and makes them preedit.
                int start = breakIterator.previousInclusive(eventCursorPosition);
                int end = breakIterator.next(eventCursorPosition);
                QString preedit = text.mid(start, end - start);

                d->storePreeditTextStyling(start, end);
                d->cursor()->setPosition(start);
                d->cursor()->setPosition(end, QTextCursor::KeepAnchor);
                QTextDocumentFragment preeditFragment = d->cursor()->selection();
                d->cursor()->removeSelectedText();

                // offer the word to input context as preedit. if the input context accepts it and
                // plays nicely, it should offer the preedit right back, changing the mode to
                // active.
                bool injectionAccepted = false;

                if (ic) {
                    MPreeditInjectionEvent event(preedit);
                    QCoreApplication::sendEvent(ic, &event);

                    injectionAccepted = event.isAccepted();
                }

                // if injection wasn't supported, put the text back and fall back to cursor changing
                if (injectionAccepted == false) {
                    d->cursor()->insertFragment(preeditFragment);
                    d->setCursorPosition(eventCursorPosition);
                    d->preeditStyling.clear();
                }

            } else {
                d->setCursorPosition(eventCursorPosition);
            }
        }

    } else {
        if (location) {
            *location = MTextEdit::Word;
        }
        d->notifyInputContextMouseHandler(eventCursorPosition, event);
    }

    if (cursorPosition() != cursorPositionBefore) {
        d->updateMicroFocus();
    }
}

Here is the call graph for this function:

void MTextEdit::handleMouseRelease ( int  cursorPosition,
QGraphicsSceneMouseEvent event 
)

Definition at line 1907 of file mtextedit.cpp.

{
    handleMouseRelease(eventCursorPosition, event, NULL);
}

Here is the call graph for this function:

bool MTextEdit::hasAcceptableInput (  )  const

returns boolean value that indicates if input satisfies the validator

Definition at line 2695 of file mtextedit.cpp.

{
    Q_D(const MTextEdit);

    if (d->validator == 0) {
        return true;
    } else {
        QString textCopy = model()->document()->toPlainText();
        int cursorCopy = model()->cursor()->position();
        QValidator::State result = d->validator->validate(textCopy, cursorCopy);
        return (result == QValidator::Acceptable);
    }
}

Here is the call graph for this function:

bool MTextEdit::hasSelectedText (  )  const

Returns true if some or all of the text has been selected.

Definition at line 1447 of file mtextedit.cpp.

{
    return mode() == MTextEditModel::EditModeSelect;
}

Here is the call graph for this function:

bool MTextEdit::inputMethodAutoCapitalizationEnabled (  )  const
bool MTextEdit::inputMethodCorrectionEnabled (  )  const

returns if correction support is enabled for input method servers

bool MTextEdit::inputMethodPredictionEnabled (  )  const

returns if word prediction support is enabled for input method servers

bool MTextEdit::insert ( const QString text  )  [slot]

deletes any selection or preedit, and inserts text to the cursor position

Parameters:
text text to insert
Returns:
true if text was accepted

Definition at line 1768 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    bool wasSelecting = hasSelectedText();

    // back to basic mode
    if ((mode() == MTextEditModel::EditModeSelect) && d->cursor()->hasSelection()) {
        d->cursor()->removeSelectedText();
        emit selectionChanged();
    } else if (mode() == MTextEditModel::EditModeActive) {
        d->removePreedit();
        d->preeditStyling.clear();
    }

    d->setMode(MTextEditModel::EditModeBasic);

    if (wasSelecting) {
        d->sendCopyAvailable(false);
    }

    bool insertionSuccess = d->doTextInsert(text);

    // either something was inserted or something was deleted, or both
    if (insertionSuccess || wasSelecting) {
        emit textChanged();
        d->updateMicroFocus();
    }

    return insertionSuccess;
}

Here is the call graph for this function:

bool MTextEdit::isAutoSelectionEnabled (  )  const

Returns whether text should be selected when focus is gained.

Definition at line 2557 of file mtextedit.cpp.

{
    return isSelectionEnabled() && model()->autoSelectionEnabled();
}

Here is the call graph for this function:

bool MTextEdit::isAutoSipEnabled (  )  const
See also:
setAutoSipEnabled

Definition at line 2744 of file mtextedit.cpp.

{
    return model()->isAutoSipEnabled();
}

Here is the call graph for this function:

bool MTextEdit::isReadOnly (  )  const

Returns whether the text entry is read only.

bool MTextEdit::isSelectionEnabled (  )  const

tell whether text is allowed to be selected

Returns:
true if text selection is allowed, otherwise false

Definition at line 1462 of file mtextedit.cpp.

{
    return (textInteractionFlags() &
            (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard)) != 0;
}

Here is the call graph for this function:

MTextEditModel::LineMode MTextEdit::lineMode (  )  const

Returns the line mode of the text edit widget.

Returns:
the line mode.

Definition at line 2123 of file mtextedit.cpp.

{
    return model()->line();
}

Here is the call graph for this function:

void MTextEdit::lostFocus ( Qt::FocusReason   )  [signal]

A signal which is emitted whenever the widget lost the focus.

int MTextEdit::maxLength (  )  const

Returns maximum allowed length for text in the text edit.

MTextEditModel::EditMode MTextEdit::mode (  )  const

Returns the edit mode of the text edit widget.

Returns:
the edit mode.

Definition at line 2117 of file mtextedit.cpp.

{
    return model()->edit();
}

Here is the call graph for this function:

void MTextEdit::paste (  )  [virtual, slot]

Pastes the plain text from the clipboard into the text edit at the current cursor position. If there is no text in the clipboard nothing happens. If clipboard content is rejected by assigned validator then signal pasteFailed() is emitted.

Definition at line 2037 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    QClipboard *clipboard = QApplication::clipboard();
    bool wasSelecting = hasSelectedText();
    bool changed = false;


    if (isReadOnly() || !clipboard) {
        return;
    }

    QString text = clipboard->text();

    if (text.isEmpty()) {
        return;
    }

    // back to basic mode
    if (wasSelecting) {
        d->cursor()->removeSelectedText();
        emit selectionChanged();
    } else if (mode() == MTextEditModel::EditModeActive) {
        d->commitPreedit();
    }

    d->setMode(MTextEditModel::EditModeBasic);
    if (wasSelecting) {
        d->sendCopyAvailable(false);
    }

    if (d->validator) {
        //use slow algorithm if validator was assigned
        foreach(const QChar & c, text) {
            changed = d->doTextInsert(c) || changed;
        }
    } else {
        changed = d->doTextInsert(text);
    }

    if (changed) {
        emit textChanged();
        emit cursorPositionChanged();
        d->updateMicroFocus();
    } else {
        mDebug("MTextEdit") << __PRETTY_FUNCTION__ << "paste failed";
        emit pasteFailed();
    }
}

Here is the call graph for this function:

void MTextEdit::pasteFailed (  )  [signal]

This signal is emitted when paste is failed and nothing was inserted.

QString MTextEdit::prompt (  )  const

returns current prompt text

void MTextEdit::returnPressed (  )  [signal]

This signal is emitted when the Enter key is pressed in single line editor. Note that if there is a validator() set on the line edit, the returnPressed() signal will only be emitted if the validator() returns QValidator::Acceptable.

void MTextEdit::selectAll (  )  [slot]

makes the whole document text selected. No-op if there is no content.

Definition at line 1999 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    d->disableUpdateMicroFocus();
    d->commitPreedit();

    d->cursor()->setPosition(0);
    d->cursor()->movePosition(QTextCursor::End, QTextCursor::KeepAnchor);

    if (d->cursor()->position() > 0) {
        // change mode only if there was something to select
        if (mode() != MTextEditModel::EditModeSelect) {
            d->setMode(MTextEditModel::EditModeSelect);
        }

        model()->updateCursor();
        emit selectionChanged();
        d->sendCopyAvailable(true);
        d->updateMicroFocus();
    }
    d->enableUpdateMicroFocus(true);
}

Here is the call graph for this function:

QString MTextEdit::selectedText (  )  const
void MTextEdit::selectionChanged (  )  [signal]

This signal is emitted whenever the selection changes.

int MTextEdit::selectionStart (  )  const

Definition at line 1452 of file mtextedit.cpp.

{
    if (mode() == MTextEditModel::EditModeSelect) {
        return textCursor().selectionStart();
    } else {
        return -1;
    }
}

Here is the call graph for this function:

void MTextEdit::setAutoSelectionEnabled ( bool  enable  ) 

Enables or disables text auto selection if enabled, all text will be selected when focus is gained.

Definition at line 2563 of file mtextedit.cpp.

{
    model()->setAutoSelectionEnabled(enable);
}

Here is the call graph for this function:

void MTextEdit::setAutoSipEnabled ( bool  enabled  ) 

Allows control over SIP handling.

When a text edit is focused and this property is disabled, no software input panel will be requested.

Definition at line 2739 of file mtextedit.cpp.

{
    model()->setAutoSipEnabled(enabled);
}

Here is the call graph for this function:

void MTextEdit::setCompleter ( MCompleter completer  ) 

Sets this text edit to provide auto completions from the completer.

Definition at line 2709 of file mtextedit.cpp.

{
    Q_D(MTextEdit);
    if (completer == d->completer)
        return;
    if (d->completer) {
        disconnect(d->completer, 0, this, 0);
        d->completer->setWidget(0);
    }

    d->completer = completer;
    if (d->completer) {
        d->completer->setWidget(this);
        setInputMethodCorrectionEnabled(false);
        setInputMethodAutoCapitalizationEnabled(false);

        if (hasFocus()) {
            d->updateMicroFocus();
            connect(d->completer, SIGNAL(confirmed(QString, QModelIndex)),
                    this, SLOT(_q_confirmCompletion(QString)));
        }
    }
}

Here is the call graph for this function:

void MTextEdit::setContentType ( M::TextContentType  type  ) 

set content type

Definition at line 2302 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    model()->setType(type);

    // update validator if it's currently our, otherwise leave it intact
    // FIXME: doesn't work if model has content type already from somewhere
    if (d->ownValidator == true) {
        delete d->validator;
        d->validator = 0;
        d->ownValidator = false;
    }

    if (d->validator == 0) {
        QRegExp rx;

        switch (type) {
        case M::NumberContentType:
            rx.setPattern(NumberCharacterSet);
            d->validator = new QRegExpValidator(rx, 0);
            break;

        case M::PhoneNumberContentType:
            rx.setPattern(PhoneNumberCharacterSet);
            d->validator = new QRegExpValidator(rx, 0);
            break;

        case M::EmailContentType:
            rx.setPattern(EmailCharacterSet);
            d->validator = new QRegExpValidator(rx, 0);
            break;

        case M::UrlContentType:
            //TODO: No check rule for URL yet
            break;

        default:
            break;
        }

        // if a validator was created, we own it
        if (d->validator != 0) {
            d->ownValidator = true;
        }
    }

    // update other state
    Qt::InputMethodHints newHint;

    switch (type) {
    case M::NumberContentType:
        setInputMethodCorrectionEnabled(false);
        newHint = Qt::ImhFormattedNumbersOnly;
        break;

    case M::PhoneNumberContentType:
        setInputMethodCorrectionEnabled(false);
        newHint = Qt::ImhDialableCharactersOnly;
        break;

    case M::EmailContentType:
        setInputMethodCorrectionEnabled(false);
        setInputMethodAutoCapitalizationEnabled(false);
        newHint = Qt::ImhEmailCharactersOnly;
        if (attachedToolbar().isEmpty()) {
            attachToolbar(QString(M_IM_TOOLBARS_DIR) + "/" + EmailContentToolbarFile);
        }
        break;

    case M::UrlContentType:
        setInputMethodCorrectionEnabled(false);
        setInputMethodAutoCapitalizationEnabled(false);
        newHint = Qt::ImhUrlCharactersOnly;
        if (attachedToolbar().isEmpty()) {
            attachToolbar(QString(M_IM_TOOLBARS_DIR) + "/" + UrlContentToolbarFile);
        }
        break;

    default:
        setInputMethodAutoCapitalizationEnabled(true);
        break;
    }

    setInputMethodHints((inputMethodHints() & ~Qt::ImhExclusiveInputMask) | newHint);
}

Here is the call graph for this function:

bool MTextEdit::setCursorPosition ( int  index  )  [slot]

Sets the cursor position of the text edit field. Moves to basic mode by committing preedit and removing selection.

Parameters:
index The index at which the cursor appears.
Returns:
false if index is an invalid cursor position.

Definition at line 1869 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    d->commitPreedit();
    deselect();
    bool val = d->setCursorPosition(index);

    return val;
}

Here is the call graph for this function:

void MTextEdit::setEchoMode ( MTextEditModel::EchoMode  echoMode  ) 

Sets the echo mode which determines how input is made visible.

Definition at line 2524 of file mtextedit.cpp.

{
    model()->setEcho(echoMode);
    if (echoMode != MTextEditModel::Normal) {
        setInputMethodHints(inputMethodHints() | Qt::ImhHiddenText);
        setInputMethodCorrectionEnabled(false);
        setInputMethodAutoCapitalizationEnabled(false);

    } else {
        setInputMethodHints(inputMethodHints() & ~Qt::ImhHiddenText);
    }

    if (mode() == MTextEditModel::EditModeSelect) {
        emit copyAvailable(echoMode == MTextEditModel::Normal);
    }
}

Here is the call graph for this function:

void MTextEdit::setInputMethodAutoCapitalizationEnabled ( bool  enabled  ) 

Definition at line 2638 of file mtextedit.cpp.

{
    // only allow to turn on auto capitalization for the text edit which is normal echo mode
    // content type is free text or custom content type.
    if ((enabled == false)
        || (echoMode() == MTextEditModel::Normal
            && (contentType() == M::FreeTextContentType || contentType() == M::CustomContentType))) {
        model()->setInputMethodAutoCapitalizationEnabled(enabled);
    }

    if (model()->inputMethodAutoCapitalizationEnabled()) {
        setInputMethodHints(inputMethodHints() & ~Qt::ImhNoAutoUppercase);
    } else {
        setInputMethodHints(inputMethodHints() | Qt::ImhNoAutoUppercase);
    }
}

Here is the call graph for this function:

void MTextEdit::setInputMethodCorrectionEnabled ( bool  enabled  ) 

sets correction on the input method server side to be enabled or disabled

Definition at line 2569 of file mtextedit.cpp.

{
    // only allow to turn on correction for the text edit which is normal echo mode
    // content type is free text or custom content type.
    if ((enabled == false)
        || (echoMode() == MTextEditModel::Normal
            && (contentType() == M::FreeTextContentType || contentType() == M::CustomContentType))) {
        model()->setInputMethodCorrectionEnabled(enabled);
    }
}

Here is the call graph for this function:

void MTextEdit::setInputMethodPredictionEnabled ( bool  enabled  ) 

sets word prediction on the input method server side to be enabled or disabled

Definition at line 2587 of file mtextedit.cpp.

{
    model()->setInputMethodPredictionEnabled(enabled);
    if (enabled) {
        setInputMethodHints(inputMethodHints() & ~Qt::ImhNoPredictiveText);
    } else {
        setInputMethodHints(inputMethodHints() | Qt::ImhNoPredictiveText);
    }
}

Here is the call graph for this function:

void MTextEdit::setMaxLength ( int  numChars  ) 

Sets the maximum allowed length for text in the text edit.

It is still possible, however, to exceed the maximum by inserting text with QTextCursor::insertText().

If truncation occurs any selected text will be unselected.

Parameters:
[in] numChars The number of characters to set as maximum length.

Definition at line 2607 of file mtextedit.cpp.

{
    if (numChars < 0) {
        numChars = 0;
    }
    model()->setMaxLength(numChars);

    // Bug in QTextDocument::characterCount?
    int characterCount = document()->characterCount() - 1;
    Q_ASSERT(characterCount >= 0);

    if (characterCount > maxLength()) {
        Q_D(MTextEdit);

        // If we have preedit commit it first
        d->commitPreedit();

        // Make sure we're not in selection mode.
        d->setMode(MTextEditModel::EditModeBasic);

        // Check again
        characterCount = document()->characterCount() - 1;
        if (characterCount > maxLength()) {
            // Select everything after position maxLength and remove the selection.
            d->setCursorPosition(maxLength());
            d->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
            d->cursor()->removeSelectedText();
        }
    }
}

Here is the call graph for this function:

void MTextEdit::setPrompt ( const QString prompt  ) 

sets prompt value

Parameters:
prompt prompt text Prompt is shown inside text entry when the entry doesn't have focus or contents

Definition at line 2662 of file mtextedit.cpp.

{
    // TODO: should replace newlines with spaces in single line?
    model()->setPrompt(prompt);
}

Here is the call graph for this function:

void MTextEdit::setReadOnly ( bool  readOnly  ) 

If readOnly equal true, then set the text entry to read only, vice versa.

Definition at line 2504 of file mtextedit.cpp.

{
    Qt::TextInteractionFlags flags = textInteractionFlags();

    if (readOnly == true) {
        flags = flags & ~Qt::TextEditable;
    } else {
        flags = flags | Qt::TextEditable;
    }

    setTextInteractionFlags(flags);
}

Here is the call graph for this function:

void MTextEdit::setSelection ( int  start,
int  length,
bool  useBoundaries = false 
)

Selects text from word boundary to another so that start and start+length are included in the selection.

Definition at line 1365 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    if (!isSelectionEnabled()) {
        return;
    }

    QString text = document()->toPlainText();

    // boundary check for positions
    start = qBound(0, start, text.length());
    length = qBound(-start, length, text.length() - start);

    d->commitPreedit();

    // determine beginning of selection and the end
    int begin;
    int end;

    if (length > 0) {
        begin = start;
        end = start + length;
    } else {
        begin = qMax(start + length, 0);
        end = begin - length;
    }

    if (useBoundaries) {
        MBreakIterator breakIterator(text);
        begin = breakIterator.previousInclusive(begin);

        if (breakIterator.isBoundary(end) == false) {
            end = breakIterator.next(end);
        }
    }

    // check if change actually happens
    QTextCursor *currentCursor = d->cursor();
    if (begin == currentCursor->anchor() && end == currentCursor->position()) {
        return;
    }

    // make an actual selection
    currentCursor->setPosition(begin);
    currentCursor->setPosition(end, QTextCursor::KeepAnchor);

    // update mode to selection or basic if needed
    if (begin != end) {
        if (mode() != MTextEditModel::EditModeSelect) {
            d->setMode(MTextEditModel::EditModeSelect);
            d->sendCopyAvailable(true);
        }
    } else if (mode() != MTextEditModel::EditModeBasic) {
        bool wasSelecting = hasSelectedText();
        d->setMode(MTextEditModel::EditModeBasic);

        if (wasSelecting) {
            d->sendCopyAvailable(false);
        }
    }

    model()->updateCursor();

    d->updateMicroFocus();

    emit selectionChanged();

    return;
}

Here is the call graph for this function:

bool MTextEdit::setText ( const QString text  )  [slot]

Set text for this widget.

This replaces the existing text.

Parameters:
text New text for this text edit widget.
Returns:
false if text is not allowed to be set. On successful insertion, the cursor is moved to the end of the text

Definition at line 1801 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    d->safeReset();

    int cursorPosBefore = d->cursor()->position();
    bool wasSelecting = hasSelectedText();
    bool wasEmpty = (document()->characterCount() == 0);

    // clear the state
    d->removePreedit();
    d->preeditStyling.clear();
    d->cursor()->clearSelection();
    document()->clear();
    d->setMode(MTextEditModel::EditModeBasic);

    //set cursor to the start again
    d->cursor()->movePosition(QTextCursor::Start);

    QString filteredText = text;

    // Limit text length.
    filteredText.truncate(maxLength());

    if (lineMode() == MTextEditModel::SingleLine) {
        filteredText.replace(QChar('\n'), QChar(' '));
    }

    d->cursor()->insertText(filteredText);

    bool accepted = d->validate();

    if (!accepted) {
        document()->clear();
    }

    // only avoid signaling if empty before and after
    if (!((document()->characterCount() == 0) && wasEmpty)) {
        d->updateMicroFocus();
        emit textChanged();
    }

    if (d->cursor()->position() != cursorPosBefore) {
        emit cursorPositionChanged();
    }

    if (wasSelecting) {
        d->sendCopyAvailable(false);
    }

    return accepted;
}

Here is the call graph for this function:

void MTextEdit::setTextCursor ( const QTextCursor cursor  ) 

Sets the currently visible cursor.

Definition at line 2262 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    MTextEditModel::EditMode newMode;

    if (cursor.hasSelection()) {
        newMode = MTextEditModel::EditModeSelect;
    } else {
        newMode = MTextEditModel::EditModeBasic;
    }

    MTextEditModel::EditMode oldMode = model()->edit();
    bool changed = (*model()->cursor() != cursor);

    d->commitPreedit();
    *(d->cursor()) = cursor;
    model()->setEdit(newMode);

    if ((newMode == MTextEditModel::EditModeSelect && changed) ||
            (newMode == MTextEditModel::EditModeBasic &&
             oldMode == MTextEditModel::EditModeSelect)) {
        emit selectionChanged();
    }

    if (changed) {
        emit cursorPositionChanged();
    }

    if (echoMode() == MTextEditModel::Normal) {
        if ((newMode == MTextEditModel::EditModeSelect) && (newMode != oldMode)) {
            emit copyAvailable(true);
        } else if ((newMode == MTextEditModel::EditModeBasic) &&
                   oldMode == MTextEditModel::EditModeSelect) {
            emit copyAvailable(false);
        }
    }
}

Here is the call graph for this function:

void MTextEdit::setTextInteractionFlags ( Qt::TextInteractionFlags  flags  ) 

Set text interaction flags.

Parameters:
flags 
See also:
Qt::TextInteractionFlags

Definition at line 2466 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    // don't set same flags twice
    if (model()->textInteractionFlags() == flags)
        return;

    model()->setTextInteractionFlags(flags);

    // if not editable, remove focus and hide cursor. Commit preedit
    if (!(model()->textInteractionFlags() & Qt::TextEditable)) {
        d->commitPreedit();
        setFocusPolicy(Qt::NoFocus);

    } else {
        setFocusPolicy(Qt::ClickFocus);
    }

    // TODO: notify input context if editability changed

    // TODO: Check other flags (Qt::TextSelectableByKeyboard etc) if necessary
}

Here is the call graph for this function:

void MTextEdit::setValidator ( const QValidator validator  ) 

sets the MTextEdit only to accept input that the validator accepts.

Parameters:
validator the validator for input text Validator will check that current paragraph validates after text insertion, and disallows insertion on validation failure. The whole content is used to check on hasAcceptableInput(). Note: Checking per paragraph doesn not include the possible paragraph ending newline.

Definition at line 2675 of file mtextedit.cpp.

{
    Q_D(MTextEdit);

    if (d->ownValidator == true) {
        delete d->validator;
    }

    d->validator = validator;
    d->ownValidator = false;
}

QString MTextEdit::text (  )  const

Returns current text.

Returns:
QString containing current widget text
void MTextEdit::textChanged (  )  [signal]

A signal which is emitted whenever the text has been changed.

QTextCursor MTextEdit::textCursor (  )  const

Returns a copy of the currently visible cursor.

Definition at line 2251 of file mtextedit.cpp.

{
    if (!model()->cursor()) {
        MTextEditModel *m = const_cast<MTextEditModel *>(model());
        m->setCursor(new QTextCursor(document()));
    }

    return QTextCursor(*model()->cursor());
}

Here is the call graph for this function:

Qt::TextInteractionFlags MTextEdit::textInteractionFlags (  )  const

Text interaction flags.

See also:
Qt::TextInteractionFlags
Returns:
Text interaction flags
const QValidator * MTextEdit::validator (  )  const

returns a pointer to the current validator or 0 if no validator is used

Definition at line 2688 of file mtextedit.cpp.

{
    Q_D(const MTextEdit);
    return d->validator;
}


Property Documentation

bool MTextEdit::autoSelectionEnabled [read, write]

Definition at line 74 of file corelib/widgets/mtextedit.h.

bool MTextEdit::autoSipEnabled [read, write]

Definition at line 78 of file corelib/widgets/mtextedit.h.

M::TextContentType MTextEdit::contentType [read, write]

Definition at line 66 of file corelib/widgets/mtextedit.h.

MTextEditModel::EchoMode MTextEdit::echoMode [read, write]

Definition at line 77 of file corelib/widgets/mtextedit.h.

bool MTextEdit::inputMethodAutoCapitalizationEnabled [read, write]

Definition at line 72 of file corelib/widgets/mtextedit.h.

bool MTextEdit::inputMethodCorrectionEnabled [read, write]

Definition at line 70 of file corelib/widgets/mtextedit.h.

bool MTextEdit::inputMethodPredictionEnabled [read, write]

Definition at line 75 of file corelib/widgets/mtextedit.h.

bool MTextEdit::isReadOnly [read, write]

Definition at line 71 of file corelib/widgets/mtextedit.h.

int MTextEdit::maxLength [read, write]

Definition at line 76 of file corelib/widgets/mtextedit.h.

QString MTextEdit::prompt [read, write]

Definition at line 68 of file corelib/widgets/mtextedit.h.

QString MTextEdit::selectedText [read]

Definition at line 73 of file corelib/widgets/mtextedit.h.

QString MTextEdit::text [read, write]

Definition at line 63 of file corelib/widgets/mtextedit.h.

Qt::TextInteractionFlags MTextEdit::textInteractionFlags [read, write]

Definition at line 67 of file corelib/widgets/mtextedit.h.


Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:27 (PDT)
Doxygen 1.7.1
MeeGo Touch