QSEditor Class Reference
A widget component providing an enhanced editor for editing
Qt Script source code.
More...
#include <qseditor.h>
List of all member functions.
Public Members
QSEditor ( QWidget * parent = 0, const char * name = 0 )
void
setText ( const QString & text, QObject * context = 0 )
void
setSource ( const QString & fileInProject )
bool
find ( const QString & expr, bool cs, bool wo, bool forward, bool startAtCursor )
bool
replace ( const QString & find, const QString & replace, bool cs, bool wo, bool forward, bool startAtCursor, bool replaceAll )
Signals
Static Public Members
const QPtrList<QSEditor> *
editors ()
Detailed Description
A widget component providing an enhanced editor for editing
Qt Script source code
For some applications the QSA Developer is too complex, even
with the GUI builder and/or debugger parts turned off (see
QProject::openDeveloper()). In this case it might be more
appropriate to embed a simple editor into the application's
UI. QSEditor provides such a widget component, which offers in
addition to normal editor functionality also Qt Script syntax
highlighting, completion, function argument hints and
auto-indentation.
You can either edit normal source code (setText()), the source of a
file in the currently open project (setSource()) or the source of an
application object (setSource()).
If the code of a file or object in a project is edited, it can be
saved back to the project via save(). text() returns the current
text and object() the object whose code is edited.
By default the completion of the editor is disabled. To have the
completion working, the Qt Script interpreter has to be set
up properly and cannot allow any signal handler connections. To tell
the interpreter to go into this mode, the editor for which
completion should be available, has to be activated. This can be
done using activate(). As long as the editor is active (isActive()),
no Qt Script signal handler connections work. But it is possible to
call normal Qt Script functions via QSInterpreter::call() and
to evaluate code (QSInterpreter::evaluate()). To activate the
signal handlers again, the editor has to be deactivated or released
(release()).
Only one editor at a time can be active and offering
completion. QSEditor::activeEditor() returns the
currently active editor.
If you have multiple QSEditors and want to support completion,
listen to the focus Out/In events and activate() and release() the
editor accordingly.
Note that a QSEditor can only be created if no editable QSA
Developer is open. A non editable QSA Developer is allowed together
with QSEditors, as this can be used for debugging.
Look at the examples/simplescript, examples/scriptbutton and
examples/console examples to see an example usage of the QSEditor
class.
Member Function Documentation
QSEditor::QSEditor ( QWidget * parent = 0, const char * name = 0 )
Constructs an editor. The parent and name arguments are
passed to the QWidget constructor.
QSEditor::~QSEditor ()
Destructs the editor.
bool QSEditor::activate ()
Tries to activate this editor. Returns TRUE if it succeeds,
otherwise FALSE.
See the class description for the concept of active editors.
Example: scriptbutton/scriptbutton.cpp.
QSEditor * QSEditor::activeEditor () [static]
Returns the currently active QSEditor, or NULL if there isn't an
active one. See the documentation of QSEditor for the concept of an
active editor.
Example: scriptbutton/scriptbutton.cpp.
void QSEditor::copy ()
Copies the selected text to the clipboard
void QSEditor::cut ()
Cuts the selected text to the clipboard
const QPtrList<QSEditor> * QSEditor::editors () [static]
Returns all open QSEditors
bool QSEditor::find ( const QString & expr, bool cs, bool wo, bool forward, bool startAtCursor )
Finds the expression expr in the editor and selects the
result. If cs is TRUE the search is done case sensitive. If wo
is TRUE, only whole words are searched. If forward is TRUE, the
search is done formward, otherwise backwards. If startAtCursor is
TRUE, the search starts at the current cursor position, otherwise it
starts at the beginning of the document.
Returns TRUE, of expr was found, FALSE otherwise.
void QSEditor::gotoLine ( int line )
Moves the cursor to the line line in the editor
void QSEditor::highlightLine ( int line )
Highlights the line line. This can be used e.g. to show and
error or warning
void QSEditor::indent ()
Indents the current line or selection
bool QSEditor::isActive () const
Returns whether this editor is active or not.
See the class description for the concept of active editors.
bool QSEditor::isRedoAvailable () const
Returns whether redo is available
bool QSEditor::isUndoAvailable () const
Returns whether undo is available
void QSEditor::paste ()
Pastes text from the clipboard into the editor
void QSEditor::readSettings ()
Re-reads settings for syntax highlighting, indentation, etc. The
settings are read from the QSettings path
/Trolltech/QuickScriptEditor/
Following settings are read for syntax highlighting:
- /Comment
- /Number
- /String
- /Type
- /Label
- /Standard
For each of those following settings are read:
- /family (string)
- /size (number)
- /bold (bool)
- /italic (bool)
- /underline (bool)
- /red (number)
- /green (number)
- /blue (number)
So, the font family for strings is e.g. saved in
/Trolltech/QuickScriptEditor/String/family.
Following settings for indentation are read:
- /indentAutoIndent (bool) - whether auto indentation should be done
- /indentTabSize (number) - the tab size for indentation
- /indentIndentSize (number) - the indentation width
- /indentKeepTabs (bool) - whether to keep tabs or to replace them with spaces
Code complection can be switched on or off via /completion,
wordwrapping via /wordWrap and paren matching via /parenMatching
void QSEditor::redo ()
Redoes the last editor operation
void QSEditor::release ()
Releases (deactivates) this editor.
See the class description for the concept of active editors.
bool QSEditor::replace ( const QString & find, const QString & replace, bool cs, bool wo, bool forward, bool startAtCursor, bool replaceAll )
Replaces the expression find in the editor with replace. If
cs is TRUE the search is done case sensitive. If wo is TRUE,
only whole words are searched. If forward is TRUE, the search is
done formward, otherwise backwards. If startAtCursor is TRUE, the
search starts at the current cursor position, otherwise it starts at
the beginning of the document. If replaceAll is TRUE, all found
occurances of find are replaced by replace. Otherwise only the
first occurance is replaced.
void QSEditor::save ()
If a file or application object is edited, saves the code changes
back to the project
void QSEditor::selectAll ()
Selects all the text in the editor
void QSEditor::setSource ( const QString & fileInProject )
Sets the editor to edit the code of the file fileInProject in
the currently opened project.
void QSEditor::setSource ( QObject * appObject )
Sets the editor to edit the code of the application object appObject of the currently opened project.
void QSEditor::setText ( const QString & text, QObject * context = 0 )
Sets the editor contents to text. In case completion is used
and this code should be interpreted as code in the context of an
object, pass this object as context. If the code is global or no
completion is requried, pass 0 as context.
Example: scriptbutton/scriptbutton.cpp.
QString QSEditor::text () const
Returns the text of the editor
Example: scriptbutton/scriptbutton.cpp.
void QSEditor::textChanged () [signal]
This signal is emitted if the text of the editor has been changed
QTextEdit * QSEditor::textEdit () const
Returns the pointer to the real editor widget, which is a
QTextEdit. This might be 0 if an error occured while initializing
the editor.
void QSEditor::undo ()
Undoes the last editor operation
This file is part of Qt Script for Applications,
copyright © 2001-2002
Trolltech. All Rights Reserved.
Copyright © 2001-2002 Trolltech | Trademarks
| QSA version 1.0.0-beta1
|