Songbook-Client  0.7
This application is a manager of customguitar songbooks
 All Classes Files Functions Variables Enumerations Enumerator Pages
song-highlighter.hh
Go to the documentation of this file.
1 // Copyright (C) 2009-2011, Romain Goffe <romain.goffe@gmail.com>
2 // Copyright (C) 2009-2011, Alexandre Dupas <alexandre.dupas@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301, USA.
18 //******************************************************************************
19 #ifndef __HIGHLIGHTER_HH__
20 #define __HIGHLIGHTER_HH__
21 
22 #include "config.hh"
23 #include <QSyntaxHighlighter>
24 #include <QHash>
25 #include <QTextCharFormat>
26 
27 class QTextDocument;
28 class Hunspell;
29 
42 class CSongHighlighter : public QSyntaxHighlighter
43 {
44  Q_OBJECT
45 
46 public:
48  CSongHighlighter(QTextDocument *parent = 0);
51 
55  void setDictionary(const QString &filename);
56 
59  Hunspell* checker() const;
60 
61 #ifdef ENABLE_SPELLCHECK
62 public slots:
66  void addWord(const QString &word);
67 
70  void setSpellCheckActive(const bool state);
71 #endif //ENABLE_SPELLCHECK
72 
73 protected:
76  void highlightBlock(const QString &text);
77 
80  void spellCheck(const QString &text);
81 
85  bool checkWord(const QString &word);
86 
87 
88 private:
89  struct HighlightingRule
90  {
91  QRegExp pattern;
92  QTextCharFormat format;
93  };
94  QVector<HighlightingRule> highlightingRules;
95 
96  QTextCharFormat keywordFormat;
97  QTextCharFormat keyword2Format;
98  QTextCharFormat environmentFormat;
99  QTextCharFormat singleLineCommentFormat;
100  QTextCharFormat chordFormat;
101  QTextCharFormat quotationFormat;
102  QTextCharFormat argumentFormat;
103  QTextCharFormat optionFormat;
104 
105  QTextCharFormat multiLineCommentFormat;
106 
107  Hunspell * m_checker;
108  bool m_isSpellCheckActive;
109  QTextCharFormat m_spellCheckFormat;
110  QTextCodec *m_codec;
111 };
112 
113 #endif // __HIGHLIGHTER_HH__