Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Q3SyntaxHighlighter Class Reference
[Qt3Support module]

The Q3SyntaxHighlighter class is a base class for implementing Q3TextEdit syntax highlighters. More...

 #include <Q3SyntaxHighlighter>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

Public Functions


Detailed Description

The Q3SyntaxHighlighter class is a base class for implementing Q3TextEdit syntax highlighters.

A syntax highligher automatically highlights parts of the text in a Q3TextEdit. Syntax highlighters are often used when the user is entering text in a specific format (for example, source code) and help the user to read the text and identify syntax errors.

To provide your own syntax highlighting for Q3TextEdit, you must subclass Q3SyntaxHighlighter and reimplement highlightParagraph().

When you create an instance of your Q3SyntaxHighlighter subclass, pass it the Q3TextEdit that you want the syntax highlighting to be applied to. After this your highlightParagraph() function will be called automatically whenever necessary. Use your highlightParagraph() function to apply formatting (e.g. setting the font and color) to the text that is passed to it.


Member Function Documentation

Q3SyntaxHighlighter::Q3SyntaxHighlighter ( Q3TextEdit * textEdit )

Constructs the Q3SyntaxHighlighter and installs it on textEdit. Ownership of the Q3SyntaxHighlighter is transferred to the textEdit

Q3SyntaxHighlighter::~Q3SyntaxHighlighter ()   [virtual]

Destructor. Uninstalls this syntax highlighter from the textEdit()

int Q3SyntaxHighlighter::currentParagraph () const

Returns the id of the paragraph which is highlighted, or -1 of no paragraph is currently highlighted.

Usually this function is called from within highlightParagraph().

int Q3SyntaxHighlighter::highlightParagraph ( const QString & text, int endStateOfLastPara )   [pure virtual]

This function is called when necessary by the rich text engine, i.e. on paragraphs which have changed.

In your reimplementation you should parse the paragraph's text and call setFormat() as often as necessary to apply any font and color changes that you require. Your function must return a value which indicates the paragraph's end state: see below.

Some syntaxes can have constructs that span paragraphs. For example, a C++ syntax highlighter should be able to cope with /*...*/ comments that span paragraphs. To deal with these cases it is necessary to know the end state of the previous paragraph (e.g. "in comment").

If your syntax does not have paragraph spanning constructs, simply ignore the endStateOfLastPara parameter and always return 0.

Whenever highlightParagraph() is called it is passed a value for endStateOfLastPara. For the very first paragraph this value is always -2. For any other paragraph the value is the value returned by the most recent highlightParagraph() call that applied to the preceding paragraph.

The value you return is up to you. We recommend only returning 0 (to signify that this paragraph's syntax highlighting does not affect the following paragraph), or a positive integer (to signify that this paragraph has ended in the middle of a paragraph spanning construct).

To find out which paragraph is highlighted, call currentParagraph().

For example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify "in comment". For a paragraph that ended in the middle of a comment you'd return 1, and for other paragraphs you'd return 0. In your parsing code if endStateOfLastPara was 1, you would highlight the text as a C++ comment until you reached the closing */.

void Q3SyntaxHighlighter::rehighlight ()

Redoes the highlighting of the whole document.

void Q3SyntaxHighlighter::setFormat ( int start, int count, const QFont & font, const QColor & color )

This function is applied to the syntax highlighter's current paragraph (the text of which is passed to the highlightParagraph() function).

The specified font and color are applied to the text from position start for count characters. (If count is 0, nothing is done.)

void Q3SyntaxHighlighter::setFormat ( int start, int count, const QColor & color )

This is an overloaded member function, provided for convenience.

void Q3SyntaxHighlighter::setFormat ( int start, int count, const QFont & font )

This is an overloaded member function, provided for convenience.

Q3TextEdit * Q3SyntaxHighlighter::textEdit () const

Returns the Q3TextEdit on which this syntax highlighter is installed

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  4. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web