Songbook-Client  0.7
This application is a manager of customguitar songbooks
 All Classes Files Functions Variables Enumerations Enumerator Pages
song-code-editor.hh
Go to the documentation of this file.
1 // Copyright (C) 2009-2012, Romain Goffe <romain.goffe@gmail.com>
2 // Copyright (C) 2009-2012, 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 __SONG_CODE_EDITOR_HH__
20 #define __SONG_CODE_EDITOR_HH__
21 
22 #include "config.hh"
23 #include "code-editor.hh"
24 
25 #include <QTextCursor>
26 
27 class QKeyEvent;
28 class QCompleter;
29 class CSongHighlighter;
30 class Hunspell;
31 class CSearchWidget;
40 class CSongCodeEditor : public CodeEditor
41 {
42  Q_OBJECT
43  Q_ENUMS(SongEnvironment)
44 
45 public:
58  };
59 
61  CSongCodeEditor(QWidget *parent = 0);
62 
65 
70  void readSettings();
71 
76  void writeSettings();
77 
82  void installHighlighter();
83 
89 
94  QCompleter* completer() const;
95 
100  bool environmentsHighlighted() const;
101 
106  void setEnvironmentsHighlighted(bool value);
107 
113  void indent();
114 
119  void indentSelection();
120 
126  bool isSpellCheckAvailable() const;
127 
133  void setSpellCheckAvailable(const bool value);
134 
139  bool isSpellCheckActive() const;
140 
141 public slots:
146  void setSpellCheckActive(const bool value);
147 
151  void toggleQuickSearch();
152 
153 protected:
159  virtual void keyPressEvent(QKeyEvent *event);
160 
165  virtual void resizeEvent(QResizeEvent *event);
166 
171  void contextMenuEvent(QContextMenuEvent *event);
172 
173 signals:
177  void wordAdded(const QString &word);
178 
179 private slots:
180  void highlightEnvironments();
181  void insertCompletion(const QString &completion);
182  void insertVerse();
183  void insertChorus();
184  void insertBridge();
185  void commentSelection();
186  void uncommentSelection();
187 
188 #ifdef ENABLE_SPELLCHECK
189 public:
194  Hunspell* checker() const;
195 
196 public slots:
202  void setDictionary(const QString &dictionary);
203 
204 private slots:
205  QString currentWord();
206  void correctWord();
207  void addWord();
208  void ignoreWord();
209 
210 private:
211  QStringList getWordPropositions(const QString &word);
212 #endif //ENABLE_SPELLCHECK
213 
214 private:
215  void indentLine(const QTextCursor &cursor);
216  void trimLine(const QTextCursor &cursor);
217  QString textUnderCursor() const;
218 
219  QTextEdit::ExtraSelection environmentSelection(const SongEnvironment & env,
220  const QTextCursor & cursor);
221 
222  CSongHighlighter* m_highlighter;
223  QCompleter* m_completer;
224 
225  bool m_environmentsHighlighted;
226 
227  QColor m_verseColor;
228  QColor m_chorusColor;
229  QColor m_bridgeColor;
230  QColor m_scriptureColor;
231 
232  bool m_isSpellCheckAvailable;
233  bool m_isSpellCheckActive;
234 
235 #ifdef ENABLE_SPELLCHECK
236  QList<QAction *> m_misspelledWordsActs;
237  QPoint m_lastPos;
238  QStringList m_addedWords;
239  uint m_maxSuggestedWords;
240 #endif //ENABLE_SPELLCHECK
241 
242  CSearchWidget *m_quickSearch;
243 };
244 
245 #endif // __SONG_CODE_EDITOR_HH__