File indexing completed on 2023-05-30 10:45:25
0001 /* 0002 SPDX-FileCopyrightText: 2002-2010 Peter Hedlund <peter.hedlund@kdemail.net> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KWORDQUIZ_H 0007 #define KWORDQUIZ_H 0008 0009 #include <QAction> 0010 #include <QActionGroup> 0011 #include <QUndoStack> 0012 #include <QUrl> 0013 0014 #include <KDirWatch> 0015 #include <KXmlGuiWindow> 0016 #include <KNSWidgets/Action> 0017 0018 #include "filterproxysearchline.h" 0019 #include "kwqquizmodel.h" 0020 #include "keduvocdocument.h" 0021 0022 class KActionMenu; 0023 class KRecentFilesAction; 0024 class KPageWidget; 0025 class KPageWidgetItem; 0026 class FilterProxySearchLine; 0027 class KWQTableModel; 0028 class KWQSortFilterModel; 0029 class KWQTableView; 0030 class KWordQuizPrefs; 0031 class QAView; 0032 class QLabel; 0033 class MultipleView; 0034 class FlashView; 0035 0036 /** 0037 * The base class for KWordQuiz application windows. It sets up the main 0038 * window and reads the config file as well as providing a menubar, toolbar 0039 * and statusbar. 0040 * KWordQuizApp reimplements the methods that KXmlGuiWindow provides for main window handling and supports 0041 * full session management. 0042 * @see KXmlGuiWindow 0043 * @see KConfig 0044 */ 0045 class KWordQuizApp : public KXmlGuiWindow 0046 { 0047 Q_OBJECT 0048 0049 public: 0050 /** 0051 * constructor of KWordQuizApp, calls all init functions to create the application. 0052 */ 0053 explicit KWordQuizApp(QWidget* parent=nullptr); 0054 0055 /** 0056 * destructor 0057 */ 0058 ~KWordQuizApp() override; 0059 0060 /** 0061 * opens a file specified by commandline option 0062 * @param url the URL to be opened 0063 */ 0064 void openDocumentFile(const QUrl &url=QUrl(), KEduVocDocument::FileHandlingFlags flags = KEduVocDocument::FileDefaultHandling); 0065 0066 /** 0067 * returns a pointer to the current document connected to the KXmlGuiWindow instance 0068 * @return 0069 */ 0070 KEduVocDocument * document() const; 0071 0072 /** 0073 * @param document the @see KEduVocDocument to save 0074 * @return whether the saving was successful 0075 */ 0076 bool saveDocAsFileName(KEduVocDocument * document); 0077 0078 protected: 0079 /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration 0080 * file 0081 */ 0082 void saveOptions(); 0083 /** read general Options again and initialize all variables like the recent file list 0084 */ 0085 void readOptions(); 0086 /** initializes the KActions of the application */ 0087 0088 void initActions(); 0089 /** sets up the statusbar for the main window by initializing a statuslabel. 0090 */ 0091 void initStatusBar(); 0092 /** initializes the document object of the main window that is connected to the view in initView(). 0093 * @see initView(); 0094 */ 0095 void initDocument(); 0096 /** creates a data model that reads and writes data from the document and displays it in a view 0097 * @see initDocument(); 0098 * @see initView(); 0099 */ 0100 void initModel(); 0101 /** creates the centerwidget of the KXmlGuiWindow instance and sets it as the view 0102 */ 0103 void initView(); 0104 /** queryClose is called by KXmlGuiWindow on each closeEvent of a window. Against the 0105 * default implementation (only returns true), this calls saveModified() on the document object to ask if the document shall 0106 * be saved if Modified; on cancel the closeEvent is rejected. 0107 * @see KXmlGuiWindow#queryClose 0108 * @see KXmlGuiWindow#closeEvent 0109 */ 0110 bool queryClose() override; 0111 /** saves the window properties for each open window during session end to the session config file, including saving the currently 0112 * opened file by a temporary filename provided by QApplication. 0113 * @see KXmlGuiWindow#saveProperties 0114 */ 0115 void saveProperties(KConfigGroup &_cfg) override; 0116 /** reads the session config file and restores the application's state including the last opened files and documents by reading the 0117 * temporary files saved by saveProperties() 0118 * @see KXmlGuiWindow#readProperties 0119 */ 0120 void readProperties(const KConfigGroup &_cfg) override; 0121 0122 Q_SIGNALS: 0123 void settingsChanged(); 0124 0125 public Q_SLOTS: 0126 /** open a new application window by creating a new instance of KWordQuizApp */ 0127 void slotFileNew(); 0128 /** open a file and load it into the document*/ 0129 void slotFileOpen(); 0130 /** opens a file from the recent files menu */ 0131 void slotFileOpenRecent(const QUrl &url); 0132 /** download vocabularies from the Internet */ 0133 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0134 void slotFileGHNS(const KNS3::Entry::List &changedEntries); 0135 #else 0136 void slotFileGHNS(const KNSCore::Entry::List &changedEntries); 0137 #endif 0138 /** save a document */ 0139 void slotFileSave(); 0140 /** save a document by a new filename*/ 0141 void slotFileSaveAs(); 0142 /** asks for saving if the file is modified, then closes the actual file and window*/ 0143 void slotFileClose(); 0144 /** print the actual file */ 0145 void slotFilePrint(); 0146 /** preview the appearance of the vocabulary as printed */ 0147 void slotFilePrintPreview(); 0148 /** closes all open windows by calling close() on each memberList item until the list is empty, then quits the application. 0149 * If queryClose() returns false because the user canceled the saveModified() dialog, the closing breaks.*/ 0150 void slotFileQuit(); 0151 0152 /** put the marked text/object into the clipboard and remove it from the document */ 0153 void slotEditCut(); 0154 /** put the marked text/object into the clipboard */ 0155 void slotEditCopy(); 0156 /** paste the clipboard into the document */ 0157 void slotEditPaste(); 0158 /** clear the grid selection */ 0159 void slotEditClear(); 0160 /** insert a new row */ 0161 void slotEditInsert(); 0162 /** delete selected row(s) */ 0163 void slotEditDelete(); 0164 /** mark word as blank */ 0165 void slotEditMarkBlank(); 0166 /** unmark word as blank */ 0167 void slotEditUnmarkBlank(); 0168 0169 /** define vocabulary settings */ 0170 void slotVocabLanguages(); 0171 /** define vocabulary fonts */ 0172 void slotVocabFont(); 0173 /** link an image to the current entry */ 0174 void slotVocabImage(); 0175 /** link a sound to the current entry */ 0176 void slotVocabSound(); 0177 /** automatically adjust row heights */ 0178 void slotVocabAdjustRows(); 0179 /** shuffle the vocabulary */ 0180 void slotVocabShuffle(); 0181 0182 void slotModeChange(); 0183 void slotModeActionGroupTriggered(QAction *); 0184 0185 /** editor session */ 0186 void slotQuizEditor(); 0187 /** flashcard session */ 0188 void slotQuizFlash(); 0189 /** multiple choice session */ 0190 void slotQuizMultiple(); 0191 /** question and answer session */ 0192 void slotQuizQA(); 0193 /** create a new vocabulary document from quiz errors */ 0194 void slotCreateErrorListDocument(); 0195 0196 void slotConfigShowSearch(); 0197 /** configure notifications */ 0198 void slotConfigureNotifications(); 0199 /** configure kwordquiz */ 0200 void slotConfigure(); 0201 0202 0203 /** changes the statusbar contents for the standard label permanently, used to indicate current actions. 0204 * @param text the text that is displayed in the statusbar */ 0205 void slotStatusMsg(const QString &text); 0206 0207 /** applies changes from the preferences dialog */ 0208 void slotApplyPreferences(); 0209 0210 void slotInsertChar(int i); 0211 0212 void slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before); 0213 0214 void slotCleanChanged(bool); 0215 void slotUndoTextChanged(const QString &); 0216 void slotRedoTextChanged(const QString &); 0217 0218 void slotTableContextMenuRequested(const QPoint &); 0219 void slotLayoutActionGroupTriggered(QAction *); 0220 0221 private: 0222 KWQQuizModel *m_quiz; 0223 0224 /** view is the main widget which represents your working area. The View 0225 * class should handle all events of the view widget. It is kept empty so 0226 * you can create your view according to your application's needs by 0227 * changing the view class. 0228 */ 0229 KPageWidget *m_pageWidget; 0230 QWidget *m_editorView; 0231 KWQTableView *m_tableView; 0232 KWQTableModel *m_tableModel; 0233 KWQSortFilterModel *m_sortFilterModel; 0234 FlashView *m_flashView; 0235 MultipleView *m_multipleView; 0236 QAView *m_qaView; 0237 0238 KPageWidgetItem *m_editorPage = nullptr; 0239 KPageWidgetItem *m_flashPage = nullptr; 0240 KPageWidgetItem *m_multiplePage = nullptr; 0241 KPageWidgetItem *m_qaPage = nullptr; 0242 0243 KWordQuizPrefs *m_prefDialog; 0244 0245 FilterProxySearchLine *m_searchLine; 0246 0247 /** m_doc represents your actual document and is created only once. It keeps 0248 * information such as filename and does the serialization of your files. 0249 */ 0250 KEduVocDocument * m_doc; 0251 0252 // QAction pointers to enable/disable actions 0253 QAction* fileNew; 0254 QAction* fileOpen; 0255 KRecentFilesAction* fileOpenRecent; 0256 QAction * fileGHNS; 0257 QAction* fileSave; 0258 QAction* fileSaveAs; 0259 QAction* fileClose; 0260 QAction* filePrint; 0261 QAction* filePrintPreview; 0262 QAction* fileQuit; 0263 0264 QAction* editUndo; 0265 QAction* editRedo; 0266 QAction* editCut; 0267 QAction* editCopy; 0268 QAction* editPaste; 0269 QAction* editClear; 0270 QAction * editInsert; 0271 QAction * editDelete; 0272 QAction * editMarkBlank; 0273 QAction * editUnmarkBlank; 0274 0275 QAction * vocabLanguages; 0276 QAction* vocabFont; 0277 QAction* vocabAdjustRows; 0278 QAction* vocabShuffle; 0279 QAction* vocabLayouts; 0280 QActionGroup *m_layoutActionGroup; 0281 0282 KActionMenu *m_modeActionMenu; 0283 QActionGroup *m_modeActionGroup; 0284 0285 QAction * quizEditor; 0286 QAction * quizFlash; 0287 QAction * quizMultiple; 0288 QAction * quizQA; 0289 0290 QAction * quizCheck; 0291 QAction * quizRestart; 0292 QAction * quizRepeatErrors; 0293 QAction * quizExportErrors; 0294 0295 QAction * flashKnow; 0296 QAction * flashDontKnow; 0297 0298 QAction * qaHint; 0299 QAction * qaMarkLastCorrect; 0300 0301 QAction * quizOpt1; 0302 QAction * quizOpt2; 0303 QAction * quizOpt3; 0304 0305 QAction* configShowSearchBar; 0306 0307 KDirWatch * m_dirWatch; 0308 0309 QUndoStack * m_undoStack; 0310 0311 QLabel * m_statusLabel; 0312 0313 void updateActions(); 0314 void updateSpecialCharIcons(); 0315 QIcon charIcon(const QChar &); 0316 void openUrl(const QUrl &url); 0317 }; 0318 0319 #endif // KWORDQUIZ_H