summaryrefslogtreecommitdiffstats
path: root/kmouth/phrasebook/phrasebookdialog.h
blob: bacd7a909f4cb48665c87d21fe78e7fbbd6374e5 (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/***************************************************************************
                          phrasebookdialog.h  -  description
                             -------------------
    begin                : Don Sep 19 2002
    copyright            : (C) 2002 by Gunnar Schmi Dt
    email                : kmouth@schmi-dt.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PHRASEBOOKDIALOG_H
#define PHRASEBOOKDIALOG_H

#include <tqbutton.h>
#include <tqradiobutton.h>
#include <tqbuttongroup.h>
#include <tqlabel.h>
#include <tqlistview.h> 
#include <kmainwindow.h>
#include <klineedit.h>
#include <kkeybutton.h>
#include <kurl.h>
#include "phrasebook.h"
#include "buttonboxui.h"

class TQListViewItem;
class PhraseTreeItem;
class PhraseTree;
class TQStringList;
class TQString;
class TDEListView;

struct StandardBook {
   TQString name;
   TQString path;
   TQString filename;
};
typedef TQValueList<StandardBook> StandardBookList;

/**The class PhraseTreeItem is an ListViewItem for either a phrase or a phrase book.
  *@author Gunnar Schmi Dt
  */

class CheckBookItem : public TQCheckListItem {
public:
   CheckBookItem (TQListViewItem *parent, TQListViewItem *last,
            const TQString &text, const TQString &name, const TQString &filename);
   CheckBookItem (TQListView *parent, TQListViewItem *last,
            const TQString &text, const TQString &name, const TQString &filename);
   ~CheckBookItem();

protected:
   virtual void activate ();
   virtual void stateChange (bool);
   virtual void propagateStateChange ();
   virtual void childChange (int numberDiff, int selDiff);

private:
   int numberOfBooks;
   int selectedBooks;
};

/**
 * This class represents a widget for configuring the initial phrasebook.
 * @author Gunnar Schmi Dt
 */

class InitialPhraseBookWidget : public TQWidget {
   Q_OBJECT
  
public:
   InitialPhraseBookWidget(TQWidget *parent, const char *name);
   ~InitialPhraseBookWidget();

   void createBook();

private:
   /** initializes the list of standard phrase books */
   void initStandardPhraseBooks ();

   TDEListView *books;
};

/**
 * The class StandardPhraseBookInsertAction implements an Action for
 * inserting a standard phrase book.
 * @author Gunnar Schmi Dt
 */
class StandardPhraseBookInsertAction : public TDEAction {
   Q_OBJECT
  
public:
   StandardPhraseBookInsertAction (const KURL &url, const TQString& name, const TQObject* receiver, const char* slot, TDEActionCollection* parent)
   : TDEAction (name, "phrasebook", 0, 0, 0, parent, 0) {
      this->url = url;
      connect (this, TQT_SIGNAL(slotActivated (const KURL &)), receiver, slot);
   };
   ~StandardPhraseBookInsertAction () {
   };

public slots:
   void slotActivated () {
      TDEAction::slotActivated();
      emit slotActivated (url);
   };

signals:
   void slotActivated (const KURL &url);

private:
   KURL url;
};

/**
 * This class represents a widget holding the buttons of the phrase book
 * edit window.
 * @author Gunnar Schmi Dt
 */
class ButtonBoxWidget : public ButtonBoxUI {
public:
   ButtonBoxWidget (TQWidget *parent = 0, const char *name = 0);
   ~ButtonBoxWidget ();

   KKeyButton *keyButton;
   TQButtonGroup *group;

protected:
   TQGridLayout *keyButtonPlaceLayout;
};

/**
 * The class PhraseBookDialog implements a dialog for editing phrase books.
 * @author Gunnar Schmi Dt
 */

class PhraseBookDialog : public TDEMainWindow {
   friend class InitialPhraseBookWidget;
   Q_OBJECT
  
private:
   /** Constructor. It is private because this class implements the singleton
    * pattern. For creating the instance of the dialog, use the get() method.
    */
   PhraseBookDialog ();

   static TQString displayPath (TQString path);

public:
   /** Returns a pointer to the instance of this dialog. As a part off the
    * singleton pattern it will make sure that there is at most one instance
    * of the dialog at a given time.
    */
   static PhraseBookDialog *get();

   /** Destructor. */
   ~PhraseBookDialog();

   bool queryClose ();

public slots:
   void slotTextChanged (const TQString &s);
   void slotNoKey();
   void slotCustomKey();
   void capturedShortcut (const TDEShortcut& cut);
   
   void selectionChanged ();
   void contextMenuRequested(TQListViewItem *, const TQPoint &pos, int);

   void slotRemove ();
   void slotCut ();
   void slotCopy ();
   void slotPaste ();

   void slotAddPhrasebook ();
   void slotAddPhrase ();

   void slotSave ();
   void slotImportPhrasebook ();
   void slotImportPhrasebook (const KURL &url);
   void slotExportPhrasebook ();
   void slotPrint ();

   void slotDropped (TQDropEvent *e, TQListViewItem *parent, TQListViewItem *after);
   void slotMoved (TQListViewItem *item, TQListViewItem *, TQListViewItem *);

signals:
   void phrasebookConfirmed (PhraseBook &book);

private:
   static StandardBookList standardPhraseBooks ();

   void initGUI();
   /** initializes the TDEActions of the window */
   void initActions();
   /** initializes the list of standard phrase books */
   void initStandardPhraseBooks ();
   
   TQListViewItem *addBook (TQListViewItem *parent, TQListViewItem *after, PhraseBook *book);
   TQListViewItem *addBook (TQListViewItem *item, PhraseBook *book);
   
   void setShortcut (const TDEShortcut &cut);

   void _warning (const KKeySequence &cut, TQString sAction, TQString sTitle);
   
   bool isGlobalKeyPresent (const TDEShortcut& cut, bool warnUser);
   bool isPhraseKeyPresent (const TDEShortcut& cut, bool warnUser);
   bool isKeyPresent (const TDEShortcut& cut, bool warnUser);

   PhraseBook book;
   bool phrasebookChanged;

   PhraseTree *treeView;
   ButtonBoxWidget *buttonBox;

   TDEAction* fileNewPhrase;
   TDEAction* fileNewBook;
   TDEAction* fileSave;
   TDEAction* fileImport;
   TDEToolBarPopupAction* toolbarImport;
   TDEActionMenu* fileImportStandardBook;
   TDEAction* fileExport;
   TDEAction* filePrint;
   TDEAction* fileClose;
   TDEAction* editCut;
   TDEAction* editCopy;
   TDEAction* editPaste;
   TDEAction* editDelete;
};

#endif