1 /* 2 SPDX-FileCopyrightText: 2015 Michal Humpula <michal.humpula@hudrydum.cz> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef WORDCOUNTER_H 8 #define WORDCOUNTER_H 9 10 #include <QObject> 11 #include <QString> 12 #include <QTimer> 13 #include <vector> 14 15 namespace KTextEditor 16 { 17 class Document; 18 class View; 19 class ViewPrivate; 20 class Range; 21 } 22 23 class WordCounter : public QObject 24 { 25 Q_OBJECT 26 27 public: 28 explicit WordCounter(KTextEditor::ViewPrivate *view); 29 30 Q_SIGNALS: 31 void changed(int wordsInDocument, int wordsInSelection, int charsInDocument, int charsInSelection); 32 33 private Q_SLOTS: 34 void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range); 35 void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText); 36 void recalculate(KTextEditor::Document *document); 37 void selectionChanged(KTextEditor::View *view); 38 void recalculateLines(); 39 40 private: 41 std::vector<int> m_countByLine; 42 int m_wordsInDocument, m_wordsInSelection; 43 int m_charsInDocument, m_charsInSelection; 44 QTimer m_timer; 45 int m_startRecalculationFrom; 46 KTextEditor::Document *m_document; 47 }; 48 49 #endif 50