File indexing completed on 2024-04-14 03:49:08

0001 /*
0002     SPDX-FileCopyrightText: 2006, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
0003     SPDX-FileCopyrightText: 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef VOCABULARYVIEW_H
0008 #define VOCABULARYVIEW_H
0009 
0010 #include <memory>
0011 #include <sonnet/dialog.h>
0012 
0013 // Qt
0014 #include <QMap>
0015 #include <QTableView>
0016 
0017 // KDE
0018 class KActionMenu;
0019 class QAction;
0020 
0021 // KEduVocDocument
0022 class KEduVocExpression;
0023 class KEduVocDocument;
0024 
0025 // parley / collection
0026 class VocabularyFilter;
0027 
0028 class Translator;
0029 
0030 namespace Editor
0031 {
0032 class EditorWindow;
0033 class VocabularyDelegate;
0034 
0035 class VocabularyView : public QTableView
0036 {
0037     Q_OBJECT
0038 public:
0039     explicit VocabularyView(EditorWindow *parent);
0040     ~VocabularyView() override
0041     {
0042     }
0043 
0044     KActionMenu *columnsActionMenu();
0045 
0046     void setFilter(VocabularyFilter *model);
0047 
0048     /** Save column visibility settings */
0049     void saveColumnVisibility() const;
0050 
0051     QModelIndexList getSelectedIndexes() const;
0052 
0053 public Q_SLOTS:
0054     void reset() override;
0055     void appendEntry();
0056 
0057     /** Delete the currently selected entries */
0058     void deleteSelectedEntries(bool askConfirmation = true);
0059 
0060     /** put the marked text/object into the clipboard*/
0061     void slotEditCopy();
0062 
0063     /** Cut an entry */
0064     void slotCutEntry();
0065 
0066     /** paste the clipboard into the document*/
0067     void slotEditPaste();
0068 
0069     /**
0070      * Append a char to the last edited entry (used to add the phonetic stuff).
0071      * @param c the char
0072      */
0073     void appendChar(const QChar &c);
0074 
0075     void setDocument(const std::shared_ptr<KEduVocDocument> &doc);
0076 
0077     void checkSpelling(int language);
0078 
0079     /**
0080      * Show the vocabulary columns dialog to enable or disable the columns in the view
0081      */
0082     void slotShowVocabularyColumnsDialog();
0083 
0084 Q_SIGNALS:
0085     void translationChanged(KEduVocExpression *, int);
0086 
0087 private Q_SLOTS:
0088     void slotCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
0089     void slotSelectionChanged(const QItemSelection &, const QItemSelection &);
0090 
0091     void continueSpelling();
0092     void misspelling(const QString &word, int start);
0093     void spellingReplace(const QString &oldWord, int start, const QString &newWord);
0094 
0095 private:
0096     void selectIndex(const QModelIndex &index);
0097     // trap enter presses at the end of the document to add a new entry instead of moving to the first cell
0098     bool eventFilter(QObject *obj, QEvent *event) override;
0099 
0100     // Make this private to avoid inadvertent use. Instead use setFilter() which is public.
0101     void setModel(QAbstractItemModel *model) override
0102     {
0103         Q_UNUSED(model)
0104     }
0105 
0106     QAction *m_appendEntryAction{nullptr};
0107     QAction *m_deleteEntriesAction{nullptr};
0108     QAction *m_copyAction{nullptr};
0109     QAction *m_cutAction{nullptr};
0110     QAction *m_pasteAction{nullptr};
0111     QAction *m_selectAllAction{nullptr};
0112     QAction *m_clearSelectionAction{nullptr};
0113 
0114     VocabularyFilter *m_model{nullptr};
0115     VocabularyDelegate *m_vocabularyDelegate{nullptr};
0116     std::shared_ptr<KEduVocDocument> m_doc;
0117 
0118     int m_spellColumn{0};
0119     int m_spellRow{0};
0120     Sonnet::BackgroundChecker *m_spellChecker{nullptr};
0121     Sonnet::Dialog *m_spellDialog{nullptr};
0122 };
0123 
0124 }
0125 
0126 #endif