1 /*
2     This file is part of Kiten, a KDE Japanese Reference Tool
3     SPDX-FileCopyrightText: 2011 Daniel E. Moctezuma <democtezuma@gmail.com>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KANJIBROWSERVIEW_H
9 #define KANJIBROWSERVIEW_H
10 
11 #include "ui_kanjibrowserview.h"
12 
13 class EntryKanjidic;
14 class QAction;
15 class KanjiBrowser;
16 class QListWidgetItem;
17 
18 class KanjiBrowserView : public QWidget, private Ui::KanjiBrowserView
19 {
20   Q_OBJECT
21 
22   public:
23         /**
24          * Constructor.
25          *
26          * @param parent parent QWidget
27          */
28          explicit KanjiBrowserView( QWidget *parent );
29         ~KanjiBrowserView() override;
30 
31     /**
32      * Initial setup.
33      *
34      * @param parent      parent to which we are going to add some QActions
35      * @param kanji       hash containing kanji with its grades and number of strokes
36      * @param kanjiGrades sorted list of grades found in KANJIDIC
37      * @param strokeCount sorted list of strokes found in KANJIDIC
38      */
39     void setupView(   KanjiBrowser *parent
40                     , const QHash< QString, QPair<int, int> > &kanji
41                     , QList<int> &kanjiGrades
42                     , QList<int> &strokeCount );
43 
44   Q_SIGNALS:
45     /**
46      * Emitted when the status bar changed.
47      *
48      * @param text new text to put in the status bar
49      */
50     void statusBarChanged( const QString &text );
51 
52   public Q_SLOTS:
53     /**
54      * Load the font settings.
55      */
56     void loadSettings();
57 
58   private Q_SLOTS:
59     /**
60      * Called when the user changed the grade
61      * of a kanji to be shown in the ComboBox.
62      *
63      * @param grade kanji grade to filter
64      */
65     void changeGrade( const int grade );
66     /**
67      * Change StackedWidget to "Kanji Information" page.
68      */
69     void changeToInfoPage();
70     /**
71      * Change StackedWidget to "Kanji List" page.
72      */
73     void changeToListPage();
74     /**
75      * Called when the user changed the strokes
76      * of a kanji to be shown in the ComboBox.
77      *
78      * @param strokes number of strokes of a kanji to filter
79      */
80     void changeStrokeCount( const int strokes );
81     /**
82      * Search for an item (kanji) in KANJIDIC.
83      *
84      * @param item item to search in the dictionary
85      */
86     void searchKanji( QListWidgetItem *item );
87 
88   private:
89     /**
90      * QFont to CSS font style conversion.
91      *
92      * @param font font to be convert
93      */
94     QString convertToCSS( const QFont &font );
95     /**
96      * Reload the KListWidget items.
97      */
98     void reloadKanjiList();
99     /**
100      * Shows the information of a kanji as HTML in a QTextBrowser.
101      *
102      * @param kanji kanji that will be displayed as HTML
103      */
104     void showKanjiInformation( const EntryKanjidic *kanji );
105 
106     /**
107      * Copies last selected kanji to clipboard
108      */
109     void toClipboard();
110 
111     /**
112      * Enumerations of our possible states in QStackedWidget.
113      */
114     enum Page
115     {
116       List,
117       Info
118     };
119 
120     enum Grade
121     {
122       AllJouyouGrades = 0,
123       Grade7          = 7,
124       Jinmeiyou       = 9
125     };
126 
127     enum StrokesCount
128     {
129       NoStrokeLimit
130     };
131 
132     /**
133      * We need this as we are going to add some QActions to it.
134      */
135     KanjiBrowser                     *_parent;
136     /**
137      * We need to update this action's text from different functions.
138      */
139     QAction                          *_goToKanjiInfo;
140     /**
141      * We need to update this action's text from different functions.
142      */
143     QAction                          *_copyToClipboard;
144     /**
145      * Keep track of the current kanji being displayed in the Kanji Information page.
146      */
147     EntryKanjidic                    *_currentKanji;
148     /**
149      * A hash containing all the kanji (found in KANJIDIC) we need to filter.
150      */
151     QHash< QString, QPair<int, int> > _kanji;
152     /**
153      * A list containing all the kanji grades found in KANJIDIC.
154      */
155     QList<int>                        _gradeList;
156     /**
157      * A list containing all the number of strokes found in KANJIDIC.
158      */
159     QList<int>                        _strokesList;
160     /**
161      * Current kanji grades selected by the user to be filtered.
162      */
163     QList<int>                        _currentGradeList;
164     /**
165      * Current number of strokes selected by the user to be filtered.
166      */
167     QList<int>                        _currentStrokesList;
168     /**
169      * Font size of the kanji displayed in the Kanji Information page.
170      */
171     QVariant                          _kanjiSize;
172     /**
173      * Font used in kana (onyomi and kunyomi pronunciations of a kanji).
174      */
175     QFont                             _kanaFont;
176     /**
177      * Font used in information labels of a kanji (Grades, Strokes, etc.).
178      */
179     QFont                             _labelFont;
180 };
181 
182 #endif
183