File indexing completed on 2024-04-21 03:58:00
0001 /* 0002 SPDX-FileCopyrightText: 2015 Michal Humpula <michal.humpula@hudrydum.cz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef WORDCOUNTER_H 0008 #define WORDCOUNTER_H 0009 0010 #include <QObject> 0011 #include <QString> 0012 #include <QTimer> 0013 #include <vector> 0014 0015 namespace KTextEditor 0016 { 0017 class Document; 0018 class View; 0019 class ViewPrivate; 0020 class Range; 0021 } 0022 0023 class WordCounter : public QObject 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 explicit WordCounter(KTextEditor::ViewPrivate *view); 0029 0030 Q_SIGNALS: 0031 void changed(int wordsInDocument, int wordsInSelection, int charsInDocument, int charsInSelection); 0032 0033 private Q_SLOTS: 0034 void textInserted(KTextEditor::Document *document, KTextEditor::Range range); 0035 void textRemoved(KTextEditor::Document *document, KTextEditor::Range range, const QString &oldText); 0036 void recalculate(KTextEditor::Document *document); 0037 void selectionChanged(KTextEditor::View *view); 0038 void recalculateLines(); 0039 0040 private: 0041 std::vector<int> m_countByLine; 0042 int m_wordsInDocument, m_wordsInSelection; 0043 int m_charsInDocument, m_charsInSelection; 0044 QTimer m_timer; 0045 int m_startRecalculationFrom; 0046 KTextEditor::Document *m_document; 0047 }; 0048 0049 #endif