QtScript script text editor for Qt 4.4.3 with Syntax Highlighter
Hi!
I'am building app with QtScript support, but for QtScript I not found standart editor control with Syntax Highlighter.
(QSA has syntax highliter text editor by default)
Is it possible to find any third party opensource script editor control for QtScript?
//----
using Qt 4.4.3
Re: QtScript script text editor for Qt 4.4.3 with Syntax Highlighter
Hey!
1. Build your own Syntaxhighlighter as is described in Qt's Syntaxhighlighter example.
See my other post:
http://www.qtcentre.org/forum/f-qt-p...ter-25483.html
and add something like this:
Code:
class JSHighlighter : public MultiLineCommentHighlighter { Q_OBJECT
public:
};
JSHighlighter
::JSHighlighter(QTextDocument *parent
) : MultiLineCommentHighlighter
(parent
) {
keywordFormat.setForeground(Qt::black);
keywordFormat.
setFontWeight(QFont::Bold);
keywordPatterns << "\\bvar\\b" << "\\bArray\\b" << "\\bfunction\\b"
<< "\\breturn\\b" << "\\barguments\\b" << "\\bif\\b"
<< "\\belse\\b" << "\\bfor\\b" << "\\bswitch\\b"
<< "\\bcase\\b" << "\\bbreak\\b" << "\\bwhile\\b";
int i = 0;
foreach
(const QString &pattern, keywordPatterns
) { SetRule
(QString("00_KeyWord_%1").
arg(i
),pattern,keywordFormat
);
++i;
}
// Values
valueFormat.setForeground(Qt::blue);
SetRule("03_Values","\\btrue\\b|\\bfalse\\b|\\b[0-9]+\\b",valueFormat);
//functionFormat.setFontItalic(false);
functionFormat.setForeground(Qt::darkBlue);
SetRule("04_Functions","\\b[A-Za-z0-9_]+(?=\\()",functionFormat);
// Qt Classes
classFormat.
setFontWeight(QFont::Bold);
classFormat.setForeground(Qt::darkMagenta);
SetRule("06_QtClasses","\\bQ[A-Z]+[A-Za-z]+\\b",classFormat);
// Quotation
quotationFormat.setForeground(Qt::blue);
SetRule("z1_Quotations","\"[^\"]*\"",quotationFormat);
// Single Line Comments
singleLineCommentFormat.setForeground(Qt::darkGreen);
SetRule("z2_SingleLineComments","//[^\n]*",singleLineCommentFormat);
}
That's of course a bit ugly, but works for me.
2. Use the QScriptEngineDebugger. That even features code completition. But that works only for scripts beeing executed/loaded in the engine I think. So that's nothing for offline editing. See the Qt Script Debugger manual in the Qt Help.
3. Look into CodeEdit: http://www.qtcentre.org/forum/f-qt-b...edit-3178.html
HIH
Johannes
Re: QtScript script text editor for Qt 4.4.3 with Syntax Highlighter
Quote:
Originally Posted by
JohannesMunk
...
2. Use the QScriptEngineDebugger. That even features code completition. But that works only for scripts beeing executed/loaded in the engine I think. So that's nothing for offline editing. See the Qt Script Debugger manual in the Qt Help.
...
I wonder where you have seen QScriptEngineDebugger can be used to even edit code.
The codeWidget is read-only, and the Qt doc states that
Quote:
The code widget is read-only; it cannot currently be used to edit and (re)evaluate scripts.
(source)
Re: QtScript script text editor for Qt 4.4.3 with Syntax Highlighter
Uuh. My fault! At the time I looked at
http://doc.trolltech.com/qq/qq02-fun...tionsdeveloper
and thought, that it was an example of the script engine debugger. But thats an old story for QSA!
Misleading title though :-> Sorry!
Johannes
Re: QtScript script text editor for Qt 4.4.3 with Syntax Highlighter
The best open source JavaScript syntax highlighter you can find is the one written by Nokia for QtCreator.