kmail

recipientseditor.h
1 /*
2  This file is part of KMail.
3 
4  Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 #ifndef RECIPIENTSEDITOR_H
25 #define RECIPIENTSEDITOR_H
26 
27 #include <tqwidget.h>
28 #include <tqscrollview.h>
29 #include <tqguardedptr.h>
30 #include <tqlineedit.h>
31 #include <tqtooltip.h>
32 
33 #include "kmlineeditspell.h"
34 #include <tqcombobox.h>
35 
36 class RecipientsPicker;
37 
38 class KWindowPositioner;
39 
40 class TQLabel;
41 class TQPushButton;
42 class SideWidget;
43 
44 class Recipient
45 {
46  public:
47  typedef TQValueList<Recipient> List;
48 
49  enum Type { To, Cc, Bcc, Undefined };
50 
51  Recipient( const TQString &email = TQString(), Type type = To );
52 
53  void setType( Type );
54  Type type() const;
55 
56  void setEmail( const TQString & );
57  TQString email() const;
58 
59  bool isEmpty() const;
60 
61  static int typeToId( Type );
62  static Type idToType( int );
63 
64  TQString typeLabel() const; static TQString typeLabel( Type );
65  static TQStringList allTypeLabels();
66 
67  private:
68  TQString mEmail;
69  Type mType;
70 };
71 
72 class RecipientComboBox : public TQComboBox
73 {
74  TQ_OBJECT
75 
76  public:
77  RecipientComboBox( TQWidget *parent );
78 
79  signals:
80  void rightPressed();
81 
82  protected:
83  void keyPressEvent( TQKeyEvent *ev );
84 };
85 
86 class RecipientLineEdit : public KMLineEdit
87 {
88  TQ_OBJECT
89 
90  public:
91  RecipientLineEdit( TQWidget * parent ) :
92  KMLineEdit( true, parent ) {}
93 
94  signals:
95  void deleteMe();
96  void leftPressed();
97  void rightPressed();
98 
99  protected:
100  void keyPressEvent( TQKeyEvent *ev );
101 };
102 
103 class RecipientLine : public TQWidget
104 {
105  TQ_OBJECT
106 
107  public:
108  RecipientLine( TQWidget *parent );
109 
110  void setRecipient( const Recipient & );
111  Recipient recipient() const;
112 
113  void setRecipientType( Recipient::Type );
114  Recipient::Type recipientType() const;
115 
116  void setRecipient( const TQString & );
117 
118  void activate();
119  bool isActive();
120 
121  bool isEmpty();
122 
126  bool isModified();
127 
130  void clearModified();
131 
132  int setComboWidth( int w );
133 
134  void fixTabOrder( TQWidget *previous );
135  TQWidget *tabOut() const;
136 
137  void clear();
138 
139  int recipientsCount();
140 
141  void setRemoveLineButtonEnabled( bool b );
142 
143  signals:
144  void returnPressed( RecipientLine * );
145  void downPressed( RecipientLine * );
146  void upPressed( RecipientLine * );
147  void rightPressed();
148  void deleteLine( RecipientLine * );
149  void countChanged();
150  void typeModified( RecipientLine * );
151 
152  protected:
153  void keyPressEvent( TQKeyEvent * );
154  RecipientLineEdit* lineEdit() const { return mEdit; }
155 
156  protected slots:
157  void slotReturnPressed();
158  void analyzeLine( const TQString & );
159  void slotFocusUp();
160  void slotFocusDown();
161  void slotPropagateDeletion();
162  void slotTypeModified();
163 
164  private:
165  friend class RecipientsView;
166  TQComboBox *mCombo;
167  RecipientLineEdit *mEdit;
168  TQPushButton *mRemoveButton;
169  int mRecipientsCount;
170  bool mModified;
171 };
172 
173 class RecipientsView : public TQScrollView
174 {
175  TQ_OBJECT
176 
177  public:
178  RecipientsView( TQWidget *parent );
179 
180  TQSize minimumSizeHint() const;
181  TQSize sizeHint() const;
182 
183  RecipientLine *activeLine();
184 
185  RecipientLine *emptyLine();
186 
187  Recipient::List recipients() const;
188 
193  void removeRecipient( const TQString & recipient, Recipient::Type type );
194 
198  bool isModified();
199 
202  void clearModified();
203 
204  void activateLine( RecipientLine * );
205 
212  int setFirstColumnWidth( int );
213 
214  public slots:
215  void setCompletionMode( TDEGlobalSettings::Completion );
216  RecipientLine *addLine();
217 
218  void setFocus();
219  void setFocusTop();
220  void setFocusBottom();
221 
222  signals:
223  void totalChanged( int recipients, int lines );
224  void focusUp();
225  void focusDown();
226  void focusRight();
227  void completionModeChanged( TDEGlobalSettings::Completion );
228  void sizeHintChanged();
229 
230  protected:
231  void viewportResizeEvent( TQResizeEvent * );
232  void resizeView();
233 
234  protected slots:
235  void slotReturnPressed( RecipientLine * );
236  void slotDownPressed( RecipientLine * );
237  void slotUpPressed( RecipientLine * );
238  void slotDecideLineDeletion( RecipientLine * );
239  void slotDeleteLine();
240  void calculateTotal();
241  void slotTypeModified( RecipientLine * );
242  void moveCompletionPopup();
243 
244  private:
245  TQPtrList<RecipientLine> mLines;
246  TQGuardedPtr<RecipientLine> mCurDelLine;
247  int mLineHeight;
248  int mFirstColumnWidth;
249  bool mModified;
250  TDEGlobalSettings::Completion mCompletionMode;
251 };
252 
253 class RecipientsToolTip : public TQToolTip
254 {
255  public:
256  RecipientsToolTip( RecipientsView *, TQWidget *parent );
257 
258  protected:
259  void maybeTip( const TQPoint & p );
260 
261  TQString line( const Recipient & );
262 
263  private:
264  RecipientsView *mView;
265 };
266 
267 class SideWidget : public TQWidget
268 {
269  TQ_OBJECT
270 
271  public:
272  SideWidget( RecipientsView *view, TQWidget *parent );
273  ~SideWidget();
274 
275  RecipientsPicker* picker() const;
276 
277  public slots:
278  void setTotal( int recipients, int lines );
279  void setFocus();
280 
281  void pickRecipient();
282 
283  signals:
284  void pickedRecipient( const Recipient & );
285  void saveDistributionList();
286 
287  private:
288  RecipientsView *mView;
289  TQLabel *mTotalLabel;
290  TQPushButton *mDistributionListButton;
291  TQPushButton *mSelectButton;
294  mutable RecipientsPicker *mRecipientPicker;
296  mutable KWindowPositioner *mPickerPositioner;
297 };
298 
299 class RecipientsEditor : public TQWidget
300 {
301  TQ_OBJECT
302 
303  public:
304  RecipientsEditor( TQWidget *parent );
305  ~RecipientsEditor();
306 
307  void clear();
308 
309  Recipient::List recipients() const;
310  RecipientsPicker* picker() const;
311 
312  void setRecipientString( const TQString &, Recipient::Type );
313  TQString recipientString( Recipient::Type );
314 
319  void addRecipient( const TQString & recipient, Recipient::Type type );
320 
325  void removeRecipient( const TQString & recipient, Recipient::Type type );
326 
330  bool isModified();
331 
334  void clearModified();
335 
342  int setFirstColumnWidth( int );
343 
347  void setCompletionMode( TDEGlobalSettings::Completion );
348 
349  public slots:
350  void setFocus();
351  void setFocusTop();
352  void setFocusBottom();
353 
354  void selectRecipients();
355  void saveDistributionList();
356 
357  signals:
358  void focusUp();
359  void focusDown();
360  void completionModeChanged( TDEGlobalSettings::Completion );
361  void sizeHintChanged();
362 
363  protected slots:
364  void slotPickedRecipient( const Recipient & );
365 
366  private:
367  RecipientsView *mRecipientsView;
368  SideWidget* mSideWidget;
369  bool mModified;
370 };
371 
372 #endif