MTextEdit is used to edit and display both plain and rich text.
More...
Inherits MWidgetController.
Inherited by MRichTextEdit.
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 |
QTextDocument * | document () 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 anchorPosition, 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 QValidator * | validator () const |
bool | hasAcceptableInput () const |
void | setCompleter (MCompleter *completer) |
MCompleter * | completer () |
void | setAutoSipEnabled (bool enabled) |
bool | isAutoSipEnabled () const |
void | attachToolbar (const QString &name) |
void | attachToolbar (int id) |
QString | attachedToolbar () const |
int | attachedToolbarId () const |
void | detachToolbar () |
bool | errorHighlight () const |
void | setErrorHighlight (bool showErrorHighlight) |
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 |
bool | errorHighlight |
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.
Member Typedef Documentation
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.
|
Constructor & Destructor Documentation
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. |
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. |
MTextEdit::~MTextEdit |
( |
|
) |
[virtual] |
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).
int MTextEdit::attachedToolbarId |
( |
|
) |
const |
void MTextEdit::attachToolbar |
( |
int |
id |
) |
|
Attaches a custom toolbar which identifier is id.
- Parameters:
-
void MTextEdit::attachToolbar |
( |
const QString & |
name |
) |
|
void MTextEdit::clear |
( |
|
) |
[slot] |
deletes all content in the widget
Returns the completer pointer, which is used by this text edit.
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.
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.
void MTextEdit::cursorPositionChanged |
( |
|
) |
[signal] |
A signal to be emitted when the cursor position changes.
Preedit cursor (as defined by the MTextEditModel) changes also cause this signal to be emitted.
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.
void MTextEdit::deselect |
( |
|
) |
|
removes any selection and changes mode to basic
void MTextEdit::detachToolbar |
( |
|
) |
|
Returns the current document.
- Returns:
- pointer to the document
- Note:
- Caution advised if changes are done using this interface. Change signals are not necessarily emitted and care is needed not to break MTextEdit state.
Returns the current echo mode.
bool MTextEdit::errorHighlight |
( |
|
) |
const |
Returns true if the textedit has error highlighting enabled.
void MTextEdit::gainedFocus |
( |
Qt::FocusReason |
|
) |
[signal] |
A signal which is emitted whenever the widget gets the focus.
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 |
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
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
bool MTextEdit::hasAcceptableInput |
( |
|
) |
const |
returns boolean value that indicates if input satisfies the validator
bool MTextEdit::hasSelectedText |
( |
|
) |
const |
Returns true if some or all of the text has been selected.
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:
-
- Returns:
- true if text was accepted
bool MTextEdit::isAutoSelectionEnabled |
( |
|
) |
const |
Returns whether text should be selected when focus is gained.
bool MTextEdit::isAutoSipEnabled |
( |
|
) |
const |
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
Returns the line mode of the text edit widget.
- Returns:
- the line mode.
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.
Returns the edit mode of the text edit widget.
- Returns:
- the edit mode.
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.
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.
QString MTextEdit::selectedText |
( |
|
) |
const |
void MTextEdit::selectionChanged |
( |
|
) |
[signal] |
This signal is emitted whenever the selection changes.
int MTextEdit::selectionStart |
( |
|
) |
const |
void MTextEdit::setAutoSelectionEnabled |
( |
bool |
enable |
) |
|
Enables or disables text auto selection if enabled, all text will be selected when focus is gained.
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.
void MTextEdit::setCompleter |
( |
MCompleter * |
completer |
) |
|
Sets this text edit to provide auto completions from the completer.
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.
Sets the echo mode which determines how input is made visible.
void MTextEdit::setErrorHighlight |
( |
bool |
showErrorHighlight |
) |
|
void MTextEdit::setInputMethodAutoCapitalizationEnabled |
( |
bool |
enabled |
) |
|
void MTextEdit::setInputMethodCorrectionEnabled |
( |
bool |
enabled |
) |
|
sets correction on the input method server side to be enabled or disabled
void MTextEdit::setInputMethodPredictionEnabled |
( |
bool |
enabled |
) |
|
sets word prediction on the input method server side to be enabled or disabled
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. |
void MTextEdit::setPrompt |
( |
const QString & |
prompt |
) |
|
sets prompt value
- Parameters:
-
| prompt | prompt text Prompt is placeholder text for describing a text enty. |
void MTextEdit::setReadOnly |
( |
bool |
readOnly |
) |
|
If readOnly equal true, then set the text entry to read only, vice versa.
void MTextEdit::setSelection |
( |
int |
anchorPosition, |
|
|
int |
length, |
|
|
bool |
useBoundaries = false | |
|
) |
| | |
Selects text from word boundary to another so that anchorPosition and anchorPosition+length are included in the selection. Puts the cursor position to anchorPosition+length. length may be negative.
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
void MTextEdit::setTextCursor |
( |
const QTextCursor & |
cursor |
) |
|
Sets the currently visible cursor.
void MTextEdit::setTextInteractionFlags |
( |
Qt::TextInteractionFlags |
flags |
) |
|
Set text interaction flags.
- Parameters:
-
- See also:
- Qt::TextInteractionFlags
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. |
Returns current text.
- Returns:
- QString containing current widget text
void MTextEdit::textChanged |
( |
|
) |
[signal] |
A signal which is emitted whenever the text has been changed.
Returns a copy of the currently visible cursor.
- Note:
- Caution advised if changes are done using this interface. Change signals are not necessarily emitted and care is needed not to break MTextEdit state.
Qt::TextInteractionFlags MTextEdit::textInteractionFlags |
( |
|
) |
const |
Text interaction flags.
- See also:
- Qt::TextInteractionFlags
- Returns:
- Text interaction flags
returns a pointer to the current validator or 0 if no validator is used
Property Documentation
bool MTextEdit::autoSelectionEnabled [read, write] |
bool MTextEdit::autoSipEnabled [read, write] |
bool MTextEdit::errorHighlight [read, write] |
bool MTextEdit::inputMethodAutoCapitalizationEnabled [read, write] |
bool MTextEdit::inputMethodCorrectionEnabled [read, write] |
bool MTextEdit::inputMethodPredictionEnabled [read, write] |
bool MTextEdit::isReadOnly [read, write] |
int MTextEdit::maxLength [read, write] |
QString MTextEdit::prompt [read, write] |
QString MTextEdit::selectedText [read] |
QString MTextEdit::text [read, write] |
Qt::TextInteractionFlags MTextEdit::textInteractionFlags [read, write] |