1 /************************************************************************
2 **
3 **  Copyright (C) 2020      Kevin B. Hendricks, Stratford Ontario Canada
4 **  Copyright (C) 2012-2013 John Schember <john@nachtimwald.com>
5 **  Copyright (C) 2012-2013 Dave Heiland
6 **
7 **  This file is part of Sigil.
8 **
9 **  Sigil is free software: you can redistribute it and/or modify
10 **  it under the terms of the GNU General Public License as published by
11 **  the Free Software Foundation, either version 3 of the License, or
12 **  (at your option) any later version.
13 **
14 **  Sigil is distributed in the hope that it will be useful,
15 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 **  GNU General Public License for more details.
18 **
19 **  You should have received a copy of the GNU General Public License
20 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
21 **
22 *************************************************************************/
23 
24 #pragma once
25 #ifndef SPELLCHECKEDITOR_H
26 #define SPELLCHECKEDITOR_H
27 
28 #include <QtWidgets/QDialog>
29 #include <QtGui/QStandardItemModel>
30 #include <QtWidgets/QAction>
31 #include <QtWidgets/QMenu>
32 #include <QShortcut>
33 #include <QtCore/QSharedPointer>
34 #include <QPointer>
35 
36 #include "Misc/SettingsStore.h"
37 #include "BookManipulation/Book.h"
38 
39 #include "ui_SpellcheckEditor.h"
40 
41 class QPoint;
42 
43 /**
44  * The editor used to create and modify index entries
45  */
46 class SpellcheckEditor : public QDialog
47 {
48     Q_OBJECT
49 
50 public:
51     SpellcheckEditor(QWidget *parent);
52     ~SpellcheckEditor();
53 
54     void SetBook(QSharedPointer <Book> book);
55     void ForceClose();
56 
57 public slots:
58     void Refresh(int sort_column = 1, Qt::SortOrder sort_order = Qt::AscendingOrder);
59 
60 signals:
61     void ShowStatusMessageRequest(const QString &message);
62     void SpellingHighlightRefreshRequest();
63     void FindWordRequest(QString word);
64     void UpdateWordRequest(QString old_word, QString new_word);
65 
66 protected:
67     bool eventFilter(QObject *obj, QEvent *ev);
68 
69 protected slots:
70     void showEvent(QShowEvent *event);
71 
72 private slots:
73     void FindSelectedWord();
74     void SelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
75     void UpdateSuggestions();
76 
77     void DictionaryChanged(QString dictionary);
78     void ChangeState(int state);
79 
80     void Ignore();
81     void Add();
82     void SelectAll();
83     void ChangeAll();
84 
85     void toggleShowAllWords();
86     void toggleCaseInsensitiveSort();
87 
88     void FilterEditTextChangedSlot(const QString &text);
89 
90     void OpenContextMenu(const QPoint &point);
91 
92     void Sort(int logicalindex, Qt::SortOrder order);
93 
94 private:
95     void CreateModel(int logicalindex, Qt::SortOrder order);
96     void UpdateDictionaries();
97     void SetupSpellcheckEditorTree();
98     void MarkSpelledOkay(int row);
99     QString GetSelectedWord();
100     int GetSelectedRow();
101 
102     int SelectedRowsCount();
103 
104     void SelectRow(int row);
105 
106     QList<QStandardItem *> GetSelectedItems();
107 
108     void ReadSettings();
109     void WriteSettings();
110 
111     void CreateContextMenuActions();
112     void SetupContextMenu(const QPoint &point);
113 
114     void ConnectSignalsSlots();
115 
116     QAction *m_Ignore;
117     QAction *m_Add;
118     QAction *m_Find;
119     QAction *m_SelectAll;
120 
121     QSharedPointer<Book> m_Book;
122 
123     QStandardItemModel *m_SpellcheckEditorModel;
124 
125     QPointer<QMenu> m_ContextMenu;
126 
127     bool m_MultipleSelection;
128 
129     int m_SelectRow;
130 
131     QShortcut * m_FilterSC;
132     QShortcut * m_ShowAllSC;
133     QShortcut * m_NoCaseSC;
134     QShortcut * m_RefreshSC;
135 
136     Ui::SpellcheckEditor ui;
137 };
138 
139 #endif // SPELLCHECKEDITOR_H
140