Results 1 to 5 of 5

Thread: QtScript script text editor for Qt 4.4.3 with Syntax Highlighter

  1. #1
    Join Date
    Oct 2009
    Location
    Russia, South Ural, Chelyabinsk
    Posts
    42
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. class JSHighlighter : public MultiLineCommentHighlighter { Q_OBJECT
    2. public:
    3. JSHighlighter(QTextDocument *parent = 0);
    4. };
    5.  
    6. JSHighlighter::JSHighlighter(QTextDocument *parent) : MultiLineCommentHighlighter(parent)
    7. {
    8. QTextCharFormat keywordFormat;
    9. keywordFormat.setForeground(Qt::black);
    10. keywordFormat.setFontWeight(QFont::Bold);
    11. QStringList keywordPatterns;
    12. keywordPatterns << "\\bvar\\b" << "\\bArray\\b" << "\\bfunction\\b"
    13. << "\\breturn\\b" << "\\barguments\\b" << "\\bif\\b"
    14. << "\\belse\\b" << "\\bfor\\b" << "\\bswitch\\b"
    15. << "\\bcase\\b" << "\\bbreak\\b" << "\\bwhile\\b";
    16. int i = 0;
    17. foreach (const QString &pattern, keywordPatterns) {
    18. SetRule(QString("00_KeyWord_%1").arg(i),pattern,keywordFormat);
    19. ++i;
    20. }
    21. // Values
    22. QTextCharFormat valueFormat;
    23. valueFormat.setForeground(Qt::blue);
    24. SetRule("03_Values","\\btrue\\b|\\bfalse\\b|\\b[0-9]+\\b",valueFormat);
    25. QTextCharFormat functionFormat;
    26. //functionFormat.setFontItalic(false);
    27. functionFormat.setForeground(Qt::darkBlue);
    28. SetRule("04_Functions","\\b[A-Za-z0-9_]+(?=\\()",functionFormat);
    29. // Qt Classes
    30. classFormat.setFontWeight(QFont::Bold);
    31. classFormat.setForeground(Qt::darkMagenta);
    32. SetRule("06_QtClasses","\\bQ[A-Z]+[A-Za-z]+\\b",classFormat);
    33. // Quotation
    34. QTextCharFormat quotationFormat;
    35. quotationFormat.setForeground(Qt::blue);
    36. SetRule("z1_Quotations","\"[^\"]*\"",quotationFormat);
    37. // Single Line Comments
    38. QTextCharFormat singleLineCommentFormat;
    39. singleLineCommentFormat.setForeground(Qt::darkGreen);
    40. SetRule("z2_SingleLineComments","//[^\n]*",singleLineCommentFormat);
    41. }
    To copy to clipboard, switch view to plain text mode 
    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

  3. #3
    Join Date
    May 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtScript script text editor for Qt 4.4.3 with Syntax Highlighter

    Quote Originally Posted by JohannesMunk View Post
    ...
    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)

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    May 2010
    Location
    Czestochowa, Poland
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Q7Goodies - The sweetest way to add Windows 7 features to your Qt application

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.