1 /* 2 SPDX-FileCopyrightText: 2011 Graeme Gott <graeme@gottcode.org> 3 4 SPDX-License-Identifier: GPL-3.0-or-later 5 */ 6 7 #ifndef TANGLET_WORD_COUNTS_H 8 #define TANGLET_WORD_COUNTS_H 9 10 #include <QScrollArea> 11 class QLabel; 12 13 /** 14 * @brief The WordCounts class displays the lengths of found words. 15 */ 16 class WordCounts : public QScrollArea 17 { 18 Q_OBJECT 19 20 /** 21 * @brief The WordCounts::Group struct represents a count of words for a length 22 */ 23 struct Group 24 { 25 int length; /**< how long the words are */ 26 int count; /**< wow many words have been found */ 27 int max; /**< how many words are available */ 28 QLabel* label; /**< display count */ 29 }; 30 31 public: 32 /** 33 * Constructs a word counts instance. 34 * @param parent the widget that owns the word counts 35 */ 36 explicit WordCounts(QWidget* parent = nullptr); 37 38 /** 39 * Add one to a word length column. 40 * @param word the word whose length is used 41 */ 42 void findWord(const QString& word); 43 44 /** 45 * Hides or shows the maximum available word lengths. 46 * @param visible whether maximums are shown 47 */ 48 void setMaximumsVisible(bool visible); 49 50 /** 51 * Determines the maximum available word lengths. 52 * @param words list of words to scan for lengths 53 */ 54 void setWords(const QStringList& words); 55 56 private: 57 /** 58 * Updates the display of word counts. 59 */ 60 void updateString(); 61 62 private: 63 bool m_show_max; /**< whether to show the maximum scores available for each length */ 64 QVector<Group> m_groups; /**< collection of word lengths */ 65 }; 66 67 #endif // TANGLET_WORD_COUNTS_H 68