/****************************************************************************
    Kalkulon - A programmable calculator for programmers

    This file is part of the Kalkulon GUI.

    If you find this source code useful, your are encouraged to use it in your own projects.
    Please give me credit!

    COPYRIGHT by Juergen Holetzeck 2003 - 2007
    e-mail:		contact@kalkulon.de
    homepage:	www.kalkulon.de
****************************************************************************/


#ifndef KALKULONSYNTAXHIGHLIGHTER_H
#define KALKULONSYNTAXHIGHLIGHTER_H

#include <QSyntaxHighlighter>
#include <QTextCharFormat>

class QTextDocument;
class QSettings;

class SyntaxHighlighter : public QSyntaxHighlighter
{
    Q_OBJECT

public:
    SyntaxHighlighter(QTextDocument *parent = 0);
    void writeSettings(QSettings *psettings);
    void readSettings(QSettings *psettings);
    void restoreDefaults();

    static const int NUM_NUMFORMATS = 8;
    struct Settings 	// only declaration here, actual Settings are private
    {
        int sameDigitsDec_;
        int sameDigitsHex_;
        int sameDigitsBin_;
        int sameDigitsOct_;
        QRgb opColor_;
        QRgb funcColor_;
        QRgb stringColor_;
        QRgb labelColor_;
        QRgb numColor_[NUM_NUMFORMATS];
    };
    const Settings& settings() {return s_;};
    void setSettings(const Settings& s);

public slots:
    void on_sameDigitsDec_changed(int digits) { s_.sameDigitsDec_=digits; rehighlight();}
    void on_sameDigitsHex_changed(int digits) { s_.sameDigitsHex_=digits; rehighlight();}
    void on_sameDigitsBin_changed(int digits) { s_.sameDigitsBin_=digits; rehighlight();}
    void on_sameDigitsOct_changed(int digits) { s_.sameDigitsOct_=digits; rehighlight();}

protected:
    void highlightBlock(const QString &text);

private:
    void doNumColoring(int begin, int end, int same_digits);

    QTextCharFormat opFormat_;
    QTextCharFormat funcFormat_;
    QTextCharFormat stringFormat_;
    QTextCharFormat labelFormat_;
    QTextCharFormat numFormat_[NUM_NUMFORMATS];

    Settings s_;
};


#endif // KALKULONSYNTAXHIGHLIGHTER_H
