View Full Version : QtScript script text editor for Qt 4.4.3 with Syntax Highlighter
sergey_85
9th November 2009, 13:54
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
JohannesMunk
9th November 2009, 18:01
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-programming-2/t-highlight-with-two-different-syntaxes-with-qsyntaxhighlighter-25483.html
and add something like this:
class JSHighlighter : public MultiLineCommentHighlighter { Q_OBJECT
public:
JSHighlighter(QTextDocument *parent = 0);
};
JSHighlighter::JSHighlighter(QTextDocument *parent) : MultiLineCommentHighlighter(parent)
{
QTextCharFormat keywordFormat;
keywordFormat.setForeground(Qt::black);
keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns;
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
QTextCharFormat valueFormat;
valueFormat.setForeground(Qt::blue);
SetRule("03_Values","\\btrue\\b|\\bfalse\\b|\\b[0-9]+\\b",valueFormat);
QTextCharFormat functionFormat;
//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
QTextCharFormat quotationFormat;
quotationFormat.setForeground(Qt::blue);
SetRule("z1_Quotations","\"[^\"]*\"",quotationFormat);
// Single Line Comments
QTextCharFormat singleLineCommentFormat;
singleLineCommentFormat.setForeground(Qt::darkGree n);
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-based-software-16/t-qcodeedit-3178.html
HIH
Johannes
packadal
7th May 2010, 10:52
...
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
The code widget is read-only; it cannot currently be used to edit and (re)evaluate scripts.
(source (http://doc.trolltech.com/4.6/qtscriptdebugger-manual.html))
JohannesMunk
7th May 2010, 11:11
Uuh. My fault! At the time I looked at
http://doc.trolltech.com/qq/qq02-fun-fast-and-flexible-qt-script.html#qtscriptforapplicationsdeveloper
and thought, that it was an example of the script engine debugger. But thats an old story for QSA!
Misleading title though :-> Sorry!
Johannes
Strix Code
11th May 2010, 18:33
The best open source JavaScript syntax highlighter you can find is the one written by Nokia for QtCreator.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.