File indexing completed on 2024-04-28 03:40:31
0001 /*************************************************************************** 0002 * Copyright (C) 2002 by Gunnar Schmi Dt <kmouth@schmi-dt.de * 0003 * (C) 2015 by Jeremy Whiting <jpwhiting@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #ifndef PHRASEBOOKDIALOG_H 0022 #define PHRASEBOOKDIALOG_H 0023 0024 #include <QDomNode> 0025 #include <QStandardItemModel> 0026 0027 #include <KXmlGuiWindow> 0028 #include <QAction> 0029 #include <QUrl> 0030 0031 // #include "phrasebook.h" 0032 #include "ui_phrasebookdialog.h" 0033 0034 class KActionMenu; 0035 class KToolBarPopupAction; 0036 0037 /** 0038 * The class StandardPhraseBookInsertAction implements an Action for 0039 * inserting a standard phrase book. 0040 * @author Gunnar Schmi Dt 0041 */ 0042 class StandardPhraseBookInsertAction : public QAction 0043 { 0044 Q_OBJECT 0045 public: 0046 StandardPhraseBookInsertAction(const QUrl &url, const QString &name, const QObject *receiver, const char *slot, KActionCollection *parent); 0047 ~StandardPhraseBookInsertAction() override; 0048 0049 public Q_SLOTS: 0050 void slotActivated(); 0051 0052 Q_SIGNALS: 0053 void slotActivated(const QUrl &url); 0054 0055 private: 0056 QUrl url; 0057 }; 0058 0059 /** 0060 * The class PhraseBookDialog implements a dialog for editing phrase books. 0061 * @author Gunnar Schmi Dt 0062 */ 0063 0064 class PhraseBookDialog : public KXmlGuiWindow 0065 { 0066 friend class InitialPhraseBookWidget; 0067 Q_OBJECT 0068 private: 0069 /** Constructor. It is private because this class implements the singleton 0070 * pattern. For creating the instance of the dialog, use the get() method. 0071 */ 0072 PhraseBookDialog(); 0073 0074 public: 0075 /** Returns a pointer to the instance of this dialog. As a part off the 0076 * singleton pattern it will make sure that there is at most one instance 0077 * of the dialog at a given time. 0078 */ 0079 static PhraseBookDialog *get(); 0080 0081 /** Destructor. */ 0082 ~PhraseBookDialog() override; 0083 0084 bool queryClose() override; 0085 0086 public Q_SLOTS: 0087 void slotTextChanged(const QString &s); 0088 void slotNoKey(); 0089 void slotCustomKey(); 0090 void slotKeySequenceChanged(const QKeySequence &sequence); 0091 0092 void selectionChanged(); 0093 void contextMenuRequested(const QPoint &pos); 0094 0095 void slotRemove(); 0096 void slotCut(); 0097 void slotCopy(); 0098 void slotPaste(); 0099 0100 void slotAddPhrasebook(); 0101 void slotAddPhrase(); 0102 0103 void slotSave(); 0104 void slotImportPhrasebook(); 0105 void slotImportPhrasebook(const QUrl &url); 0106 void slotExportPhrasebook(); 0107 // void slotPrint (); 0108 0109 void slotModelChanged(); 0110 0111 Q_SIGNALS: 0112 void phrasebookConfirmed(); 0113 0114 private: 0115 void initGUI(); 0116 /** initializes the KActions of the window */ 0117 void initActions(); 0118 /** initializes the list of standard phrase books */ 0119 void initStandardPhraseBooks(); 0120 0121 void connectEditor(); 0122 void disconnectEditor(); 0123 0124 // Deserialize the book from the given QDomNode and under the given parent 0125 // Return the new QStandardItem so it can get focused. 0126 QStandardItem *deserializeBook(const QDomNode &node, QStandardItem *parent); 0127 // Return a serialized string of the book or phrase at the given index. 0128 QString serializeBook(const QModelIndex &index); 0129 0130 // Get the current parent, if the current index is not a book, get it's parent. 0131 QModelIndex getCurrentParent(); 0132 0133 // Expand to, select and focus a new item from the given parameters 0134 void focusNewItem(const QModelIndex &parent, QStandardItem *item); 0135 0136 void setShortcut(const QKeySequence &sequence); 0137 0138 bool phrasebookChanged; 0139 0140 QAction *fileNewPhrase; 0141 QAction *fileNewBook; 0142 QAction *fileSave; 0143 QAction *fileImport; 0144 KToolBarPopupAction *toolbarImport; 0145 KActionMenu *fileImportStandardBook; 0146 QAction *fileExport; 0147 // QAction* filePrint; 0148 QAction *fileClose; 0149 QAction *editCut; 0150 QAction *editCopy; 0151 QAction *editPaste; 0152 QAction *editDelete; 0153 0154 QStandardItemModel *m_bookModel; 0155 QStandardItem *m_rootItem; 0156 0157 // Keep QPrinter so settings persist 0158 // QPrinter *printer; 0159 0160 Ui::PhraseBookDialog *m_ui; 0161 }; 0162 0163 #endif