1 /* 2 SPDX-FileCopyrightText: 2002-2010 Peter Hedlund <peter.hedlund@kdemail.net> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #ifndef KWORDQUIZ_H 7 #define KWORDQUIZ_H 8 9 #include <QAction> 10 #include <QActionGroup> 11 #include <QUndoStack> 12 #include <QUrl> 13 14 #include <KDirWatch> 15 #include <KXmlGuiWindow> 16 17 #include "filterproxysearchline.h" 18 #include "kwqquizmodel.h" 19 20 class KActionMenu; 21 class KRecentFilesAction; 22 class KPageWidget; 23 class KPageWidgetItem; 24 class FilterProxySearchLine; 25 class KEduVocDocument; 26 class KWQTableModel; 27 class KWQSortFilterModel; 28 class KWQTableView; 29 class KWordQuizPrefs; 30 class QAView; 31 class QLabel; 32 class MultipleView; 33 class FlashView; 34 35 /** 36 * The base class for KWordQuiz application windows. It sets up the main 37 * window and reads the config file as well as providing a menubar, toolbar 38 * and statusbar. 39 * KWordQuizApp reimplements the methods that KXmlGuiWindow provides for main window handling and supports 40 * full session management. 41 * @see KXmlGuiWindow 42 * @see KConfig 43 */ 44 class KWordQuizApp : public KXmlGuiWindow 45 { 46 Q_OBJECT 47 48 public: 49 /** 50 * constructor of KWordQuizApp, calls all init functions to create the application. 51 */ 52 explicit KWordQuizApp(QWidget* parent=nullptr); 53 54 /** 55 * destructor 56 */ 57 ~KWordQuizApp() override; 58 59 /** 60 * opens a file specified by commandline option 61 * @param url the URL to be opened 62 */ 63 void openDocumentFile(const QUrl &url=QUrl()); 64 65 /** 66 * returns a pointer to the current document connected to the KXmlGuiWindow instance 67 * @return 68 */ 69 KEduVocDocument * document() const; 70 71 /** 72 * @param document the @see KEduVocDocument to save 73 * @return whether the saving was successful 74 */ 75 bool saveDocAsFileName(KEduVocDocument * document); 76 77 protected: 78 /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration 79 * file 80 */ 81 void saveOptions(); 82 /** read general Options again and initialize all variables like the recent file list 83 */ 84 void readOptions(); 85 /** initializes the KActions of the application */ 86 87 void initActions(); 88 /** sets up the statusbar for the main window by initializing a statuslabel. 89 */ 90 void initStatusBar(); 91 /** initializes the document object of the main window that is connected to the view in initView(). 92 * @see initView(); 93 */ 94 void initDocument(); 95 /** creates a data model that reads and writes data from the document and displays it in a view 96 * @see initDocument(); 97 * @see initView(); 98 */ 99 void initModel(); 100 /** creates the centerwidget of the KXmlGuiWindow instance and sets it as the view 101 */ 102 void initView(); 103 /** queryClose is called by KXmlGuiWindow on each closeEvent of a window. Against the 104 * default implementation (only returns true), this calls saveModified() on the document object to ask if the document shall 105 * be saved if Modified; on cancel the closeEvent is rejected. 106 * @see KXmlGuiWindow#queryClose 107 * @see KXmlGuiWindow#closeEvent 108 */ 109 bool queryClose() override; 110 /** saves the window properties for each open window during session end to the session config file, including saving the currently 111 * opened file by a temporary filename provided by QApplication. 112 * @see KXmlGuiWindow#saveProperties 113 */ 114 void saveProperties(KConfigGroup &_cfg) override; 115 /** reads the session config file and restores the application's state including the last opened files and documents by reading the 116 * temporary files saved by saveProperties() 117 * @see KXmlGuiWindow#readProperties 118 */ 119 void readProperties(const KConfigGroup &_cfg) override; 120 121 Q_SIGNALS: 122 void settingsChanged(); 123 124 public Q_SLOTS: 125 /** open a new application window by creating a new instance of KWordQuizApp */ 126 void slotFileNew(); 127 /** open a file and load it into the document*/ 128 void slotFileOpen(); 129 /** opens a file from the recent files menu */ 130 void slotFileOpenRecent(const QUrl &url); 131 /** download vocabularies from the Internet */ 132 void slotFileGHNS(); 133 /** save a document */ 134 void slotFileSave(); 135 /** save a document by a new filename*/ 136 void slotFileSaveAs(); 137 /** asks for saving if the file is modified, then closes the actual file and window*/ 138 void slotFileClose(); 139 /** print the actual file */ 140 void slotFilePrint(); 141 /** preview the appearance of the vocabulary as printed */ 142 void slotFilePrintPreview(); 143 /** closes all open windows by calling close() on each memberList item until the list is empty, then quits the application. 144 * If queryClose() returns false because the user canceled the saveModified() dialog, the closing breaks.*/ 145 void slotFileQuit(); 146 147 /** put the marked text/object into the clipboard and remove it from the document */ 148 void slotEditCut(); 149 /** put the marked text/object into the clipboard */ 150 void slotEditCopy(); 151 /** paste the clipboard into the document */ 152 void slotEditPaste(); 153 /** clear the grid selection */ 154 void slotEditClear(); 155 /** insert a new row */ 156 void slotEditInsert(); 157 /** delete selected row(s) */ 158 void slotEditDelete(); 159 /** mark word as blank */ 160 void slotEditMarkBlank(); 161 /** unmark word as blank */ 162 void slotEditUnmarkBlank(); 163 164 /** define vocabulary settings */ 165 void slotVocabLanguages(); 166 /** define vocabulary fonts */ 167 void slotVocabFont(); 168 /** link an image to the current entry */ 169 void slotVocabImage(); 170 /** link a sound to the current entry */ 171 void slotVocabSound(); 172 /** automatically adjust row heights */ 173 void slotVocabAdjustRows(); 174 /** shuffle the vocabulary */ 175 void slotVocabShuffle(); 176 177 void slotModeChange(); 178 void slotModeActionGroupTriggered(QAction *); 179 180 /** editor session */ 181 void slotQuizEditor(); 182 /** flashcard session */ 183 void slotQuizFlash(); 184 /** multiple choice session */ 185 void slotQuizMultiple(); 186 /** question and answer session */ 187 void slotQuizQA(); 188 /** create a new vocabulary document from quiz errors */ 189 void slotCreateErrorListDocument(); 190 191 void slotConfigShowSearch(); 192 /** configure notifications */ 193 void slotConfigureNotifications(); 194 /** configure kwordquiz */ 195 void slotConfigure(); 196 197 198 /** changes the statusbar contents for the standard label permanently, used to indicate current actions. 199 * @param text the text that is displayed in the statusbar */ 200 void slotStatusMsg(const QString &text); 201 202 /** applies changes from the preferences dialog */ 203 void slotApplyPreferences(); 204 205 void slotInsertChar(int i); 206 207 void slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before); 208 209 void slotCleanChanged(bool); 210 void slotUndoTextChanged(const QString &); 211 void slotRedoTextChanged(const QString &); 212 213 void slotTableContextMenuRequested(const QPoint &); 214 void slotLayoutActionGroupTriggered(QAction *); 215 216 private: 217 KWQQuizModel *m_quiz; 218 219 /** view is the main widget which represents your working area. The View 220 * class should handle all events of the view widget. It is kept empty so 221 * you can create your view according to your application's needs by 222 * changing the view class. 223 */ 224 KPageWidget *m_pageWidget; 225 QWidget *m_editorView; 226 KWQTableView *m_tableView; 227 KWQTableModel *m_tableModel; 228 KWQSortFilterModel *m_sortFilterModel; 229 FlashView *m_flashView; 230 MultipleView *m_multipleView; 231 QAView *m_qaView; 232 233 KPageWidgetItem *m_editorPage; 234 KPageWidgetItem *m_flashPage; 235 KPageWidgetItem *m_multiplePage; 236 KPageWidgetItem *m_qaPage; 237 238 KWordQuizPrefs *m_prefDialog; 239 240 FilterProxySearchLine *m_searchLine; 241 242 /** m_doc represents your actual document and is created only once. It keeps 243 * information such as filename and does the serialization of your files. 244 */ 245 KEduVocDocument * m_doc; 246 247 // QAction pointers to enable/disable actions 248 QAction* fileNew; 249 QAction* fileOpen; 250 KRecentFilesAction* fileOpenRecent; 251 QAction * fileGHNS; 252 QAction* fileSave; 253 QAction* fileSaveAs; 254 QAction* fileClose; 255 QAction* filePrint; 256 QAction* filePrintPreview; 257 QAction* fileQuit; 258 259 QAction* editUndo; 260 QAction* editRedo; 261 QAction* editCut; 262 QAction* editCopy; 263 QAction* editPaste; 264 QAction* editClear; 265 QAction * editInsert; 266 QAction * editDelete; 267 QAction * editMarkBlank; 268 QAction * editUnmarkBlank; 269 270 QAction * vocabLanguages; 271 QAction* vocabFont; 272 QAction* vocabAdjustRows; 273 QAction* vocabShuffle; 274 QAction* vocabLayouts; 275 QActionGroup *m_layoutActionGroup; 276 277 KActionMenu *m_modeActionMenu; 278 QActionGroup *m_modeActionGroup; 279 280 QAction * quizEditor; 281 QAction * quizFlash; 282 QAction * quizMultiple; 283 QAction * quizQA; 284 285 QAction * quizCheck; 286 QAction * quizRestart; 287 QAction * quizRepeatErrors; 288 QAction * quizExportErrors; 289 290 QAction * flashKnow; 291 QAction * flashDontKnow; 292 293 QAction * qaHint; 294 QAction * qaMarkLastCorrect; 295 296 QAction * quizOpt1; 297 QAction * quizOpt2; 298 QAction * quizOpt3; 299 300 QAction* configShowSearchBar; 301 302 KDirWatch * m_dirWatch; 303 304 QUndoStack * m_undoStack; 305 306 QLabel * m_statusLabel; 307 308 void updateActions(); 309 void updateSpecialCharIcons(); 310 QIcon charIcon(const QChar &); 311 void openUrl(const QUrl &url); 312 }; 313 314 #endif // KWORDQUIZ_H 315