File indexing completed on 2024-04-28 07:29:20

0001 /*
0002     This file is part of Kiten, a KDE Japanese Reference Tool
0003     SPDX-FileCopyrightText: 2011 Daniel E. Moctezuma <democtezuma@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KANJIBROWSERVIEW_H
0009 #define KANJIBROWSERVIEW_H
0010 
0011 #include "ui_kanjibrowserview.h"
0012 
0013 class EntryKanjidic;
0014 class QAction;
0015 class KanjiBrowser;
0016 class QListWidgetItem;
0017 
0018 class KanjiBrowserView : public QWidget, private Ui::KanjiBrowserView
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     /**
0024      * Constructor.
0025      *
0026      * @param parent parent QWidget
0027      */
0028     explicit KanjiBrowserView(QWidget *parent);
0029     ~KanjiBrowserView() override = default;
0030 
0031     /**
0032      * Initial setup.
0033      *
0034      * @param parent      parent to which we are going to add some QActions
0035      * @param kanji       hash containing kanji with its grades and number of strokes
0036      * @param kanjiGrades sorted list of grades found in KANJIDIC
0037      * @param strokeCount sorted list of strokes found in KANJIDIC
0038      */
0039     void setupView(KanjiBrowser *parent, const QHash<QString, QPair<int, int>> &kanji, QList<int> &kanjiGrades, QList<int> &strokeCount);
0040 
0041 Q_SIGNALS:
0042     /**
0043      * Emitted when the status bar changed.
0044      *
0045      * @param text new text to put in the status bar
0046      */
0047     void statusBarChanged(const QString &text);
0048 
0049 public Q_SLOTS:
0050     /**
0051      * Load the font settings.
0052      */
0053     void loadSettings();
0054 
0055 private Q_SLOTS:
0056     /**
0057      * Called when the user changed the grade
0058      * of a kanji to be shown in the ComboBox.
0059      *
0060      * @param grade kanji grade to filter
0061      */
0062     void changeGrade(const int grade);
0063     /**
0064      * Change StackedWidget to "Kanji Information" page.
0065      */
0066     void changeToInfoPage();
0067     /**
0068      * Change StackedWidget to "Kanji List" page.
0069      */
0070     void changeToListPage();
0071     /**
0072      * Called when the user changed the strokes
0073      * of a kanji to be shown in the ComboBox.
0074      *
0075      * @param strokes number of strokes of a kanji to filter
0076      */
0077     void changeStrokeCount(const int strokes);
0078     /**
0079      * Search for an item (kanji) in KANJIDIC.
0080      *
0081      * @param item item to search in the dictionary
0082      */
0083     void searchKanji(const QString &term);
0084 
0085 private:
0086     /**
0087      * QFont to CSS font style conversion.
0088      *
0089      * @param font font to be convert
0090      */
0091     QString convertToCSS(const QFont &font);
0092     /**
0093      * Reload the KListWidget items.
0094      */
0095     void reloadKanjiList();
0096     /**
0097      * Shows the information of a kanji as HTML in a QTextBrowser.
0098      *
0099      * @param kanji kanji that will be displayed as HTML
0100      */
0101     void showKanjiInformation(const EntryKanjidic *kanji);
0102 
0103     /**
0104      * Copies last selected kanji to clipboard
0105      */
0106     void toClipboard();
0107 
0108     /**
0109      * Open the search dialog.
0110      */
0111     void openSearchDialog();
0112 
0113     /**
0114      * Enumerations of our possible states in QStackedWidget.
0115      */
0116     enum Page { List, Info };
0117 
0118     enum Grade { AllJouyouGrades = 0, Grade7 = 7, Jinmeiyou = 9 };
0119 
0120     enum StrokesCount { NoStrokeLimit };
0121 
0122     /**
0123      * We need this as we are going to add some QActions to it.
0124      */
0125     KanjiBrowser *_parent;
0126     /**
0127      * We need to update this action's text from different functions.
0128      */
0129     QAction *_goToKanjiInfo;
0130     /**
0131      * We need to update this action's text from different functions.
0132      */
0133     QAction *_searchKanjiAction;
0134     /**
0135      * We need to update this action's text from different functions.
0136      */
0137     QAction *_copyToClipboard;
0138     /**
0139      * Keep track of the current kanji being displayed in the Kanji Information page.
0140      */
0141     EntryKanjidic *_currentKanji;
0142     /**
0143      * A hash containing all the kanji (found in KANJIDIC) we need to filter.
0144      */
0145     QHash<QString, QPair<int, int>> _kanji;
0146     /**
0147      * A list containing all the kanji grades found in KANJIDIC.
0148      */
0149     QList<int> _gradeList;
0150     /**
0151      * A list containing all the number of strokes found in KANJIDIC.
0152      */
0153     QList<int> _strokesList;
0154     /**
0155      * Current kanji grades selected by the user to be filtered.
0156      */
0157     QList<int> _currentGradeList;
0158     /**
0159      * Current number of strokes selected by the user to be filtered.
0160      */
0161     QList<int> _currentStrokesList;
0162     /**
0163      * Font size of the kanji displayed in the Kanji Information page.
0164      */
0165     QVariant _kanjiSize;
0166     /**
0167      * Font used in kana (onyomi and kunyomi pronunciations of a kanji).
0168      */
0169     QFont _kanaFont;
0170     /**
0171      * Font used in information labels of a kanji (Grades, Strokes, etc.).
0172      */
0173     QFont _labelFont;
0174 };
0175 
0176 #endif