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
15namespace KTextEditor
16{
17class Document;
18class View;
19class ViewPrivate;
20class Range;
21}
22
23class WordCounter : public QObject
24{
25 Q_OBJECT
26
27public:
28 explicit WordCounter(KTextEditor::ViewPrivate *view);
29
30Q_SIGNALS:
31 void changed(int wordsInDocument, int wordsInSelection, int charsInDocument, int charsInSelection);
32
33private Q_SLOTS:
34 void textInserted(KTextEditor::Document *document, KTextEditor::Range range);
35 void textRemoved(KTextEditor::Document *document, KTextEditor::Range range, const QString &oldText);
36 void recalculate(KTextEditor::Document *document);
37 void selectionChanged(KTextEditor::View *view);
38 void recalculateLines();
39
40private:
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

source code of ktexteditor/src/view/wordcounter.h