summaryrefslogtreecommitdiff
path: root/src/main-view/MainWindow.h
blob: 5165118e6b80ee85a856de81ee220b421dd82478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtWidgets>

class AppModel;
class DictTableView;
class Dictionary;
class IStudyWindow;
class FindPanel;
class CardPreview;
class RecentFilesManager;
class DicRecord;
class Card;
class CardPack;
class WelcomeScreen;

#include "UndoCommands.h"
#include "DictionaryTabWidget.h"

class MainWindow: public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(AppModel* model);
    ~MainWindow();

    const DictTableView* getCurDictView() const;
    QList<QAction*> getContextMenuActions() const { return contextMenuActions; }

    void showContinueSearch() { dictTabWidget->showContinueSearch(); }
    void goToDictionaryRecord( const Dictionary* aDictionary, int aRecordRow );

public slots:
	void openFile(const QString& filePath);

private:
    void init();
    void addDictTab(Dictionary* dict);

    void createActions();
    void createFileActions();
    void createEditActions();
    void createAddImageAct();
    void createinsertRecordsAct();
    void createInsertRecordsAfterAct();
    void createRemoveRecordsAct();
    void createDictContextMenuActions();
    void createSelectionActions();
    void createToolsActions();
    void createSettingsActions();
    void createHelpActions();
    void initActions();

    void createMenus();
    void createToolBars();
    void createStatusBar();

    void createCentralWidget();
    void updateMainStackedWidget(int tabIndex);
    QWidget* createDictionaryView();

    void createDockWindows();
    void createPacksTreeDock();
    void createCardPreviewDock();

    void readSettings();
    void writeSettings();
    bool doSave( const QString& aFilePath, bool aChangeFilePath = true );
    bool proposeToSave();
    void openSession();
    void closeEvent(QCloseEvent *event);
    void saveGeneralSettings();
    void saveSession();
    void loadGeneralSettings();

    void updatePackSelection( int aDic = -1 );
    Dictionary* getCurDict();
    QString selectAddImageFile();
    void checkAddImagePath();
    QString copyImageFileToImagesDir(const QString& filePath);
    QString createNewImageFilePath(const QString& dicImagesDir, const QString& filePath);
    QString createImagesDirFilePath(const QString& dicImagesDir, const QString& filePath,
        int suffixNum);
    int getCurEditorCursorPos();
    int getCurRow();
    int getCurColumn();
    void insertImageIntoCurEditor(int cursorPos, const QString& filePath);

    void createFileMenu();
    void createOptionsMenu();
	void createRecentFilesMenu();

    CardPack* getCurCardPack() const;
    const DicRecord* getCurDictRecord() const;
    const DicRecord* getCurDictRecord(const Dictionary* dict,
        const QAbstractItemView* dictView) const;
	Card* getCurCardFromPack(CardPack* pack) const;
    bool isDictOpened(int index);
    void setCurDictionary(int index);
    void openFileWithDialog(const QString& dirPath);
    bool loadFile(const QString& filePath);
    void showOpenFileError();
    void updateAfterOpenedDictionary(const QString& filePath);

public slots:
    void updateDictTab();
    void updateActions();
    void updatePasteAction();
    void updateSelectionActions();
    bool proposeToSave(int i);

private slots:
    void activate();
    void curTabChanged(int tabIndex);
    void updatePacksTreeView();
    void updateCardPreview();
    void updateAddImageAction();
    void newFile();
    void openFileWithDialog();
    void openOnlineDictionaries();
    bool Save();
    bool saveStudy();
    bool SaveAs( bool aChangeFilePath = true );
    void SaveCopy();
    void importFromCsv();
    void exportToCsv();

    void copyEntries();
    void cutEntries();
    void pasteEntries();
    void addImage();
    void insertRecords();
    void removeRecords();
    void pushToUnoStack(QUndoCommand* command);
    void find();
    void findAgain();
    void openDictionaryOptions();
    void openFontColorSettings();
    void openStudySettings();

    void startStudy(int aStudyType);
    void startSpacedRepetitionStudy();
    void help();
    void about();
    void updateTotalRecordsLabel();
    void setCurDictTab(int index);
    void setCurDictTabByTreeIndex(const QModelIndex& aIndex);
    void showStatistics();

    void saveStudyWithDelay(bool studyModified);

private:
    static const int AutoSaveStudyInterval = 3 * 60 * 1000; // ms

private:
    QString workPath;
    QString addImagePath;
    AppModel* model;  // not own

    // UI elements
    QStackedWidget* mainStackedWidget;
    DictionaryTabWidget* dictTabWidget;
    WelcomeScreen* welcomeScreen;
    QLabel* totalRecordsLabel;
    QPointer<IStudyWindow> studyWindow;
    FindPanel* findPanel;
    QTreeView* packsTreeView;
    CardPreview* cardPreview;

    QMenu* fileMenu;
    QMenu* editMenu;
    QMenu* viewMenu;
    QMenu* toolsMenu;
    QMenu* optionsMenu;
    QMenu* helpMenu;

    RecentFilesManager* recentFilesMan;

    // Actions
    QAction* newAct;
    QAction* loadAct;
    QAction* openFlashcardsAct;
    QAction* saveAct;
    QAction* saveAsAct;
    QAction* saveCopyAct;
    QAction* importAct;
    QAction* exportAct;
    QAction* removeTabAct;
    QAction* quitAct;

    QAction* undoAct;
    QAction* redoAct;
    QAction* cutAct;
    QAction* copyAct;
    QAction* pasteAct;
    QAction* addImageAct;
    QAction* insertRecordsAct;
    QAction* removeRecordsAct;
    QAction* findAgainAct;
    QAction* findAct;
    QList<QAction*> contextMenuActions;
    QList<QAction*> selectionActions;

    QAction* wordDrillAct;
    QAction* spacedRepetitionAct;
    QAction* statisticsAct;

    QAction* dictionaryOptionsAct;
    QAction* fontColorSettingsAct;
    QAction* studySettingsAct;

    QAction* helpAct;
    QAction* aboutAct;
};

#endif