recipientseditor.h
00001 /* 00002 This file is part of KMail. 00003 00004 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 #ifndef RECIPIENTSEDITOR_H 00025 #define RECIPIENTSEDITOR_H 00026 00027 #include <tqwidget.h> 00028 #include <tqscrollview.h> 00029 #include <tqguardedptr.h> 00030 #include <tqlineedit.h> 00031 #include <tqtooltip.h> 00032 00033 #include "kmlineeditspell.h" 00034 #include <tqcombobox.h> 00035 00036 class RecipientsPicker; 00037 00038 class KWindowPositioner; 00039 00040 class TQLabel; 00041 class TQPushButton; 00042 class SideWidget; 00043 00044 class Recipient 00045 { 00046 public: 00047 typedef TQValueList<Recipient> List; 00048 00049 enum Type { To, Cc, Bcc, Undefined }; 00050 00051 Recipient( const TQString &email = TQString(), Type type = To ); 00052 00053 void setType( Type ); 00054 Type type() const; 00055 00056 void setEmail( const TQString & ); 00057 TQString email() const; 00058 00059 bool isEmpty() const; 00060 00061 static int typeToId( Type ); 00062 static Type idToType( int ); 00063 00064 TQString typeLabel() const; static TQString typeLabel( Type ); 00065 static TQStringList allTypeLabels(); 00066 00067 private: 00068 TQString mEmail; 00069 Type mType; 00070 }; 00071 00072 class RecipientComboBox : public TQComboBox 00073 { 00074 Q_OBJECT 00075 TQ_OBJECT 00076 public: 00077 RecipientComboBox( TQWidget *parent ); 00078 00079 signals: 00080 void rightPressed(); 00081 00082 protected: 00083 void keyPressEvent( TQKeyEvent *ev ); 00084 }; 00085 00086 class RecipientLineEdit : public KMLineEdit 00087 { 00088 Q_OBJECT 00089 TQ_OBJECT 00090 public: 00091 RecipientLineEdit( TQWidget * parent ) : 00092 KMLineEdit( true, parent ) {} 00093 00094 signals: 00095 void deleteMe(); 00096 void leftPressed(); 00097 void rightPressed(); 00098 00099 protected: 00100 void keyPressEvent( TQKeyEvent *ev ); 00101 }; 00102 00103 class RecipientLine : public TQWidget 00104 { 00105 Q_OBJECT 00106 TQ_OBJECT 00107 public: 00108 RecipientLine( TQWidget *parent ); 00109 00110 void setRecipient( const Recipient & ); 00111 Recipient recipient() const; 00112 00113 void setRecipientType( Recipient::Type ); 00114 Recipient::Type recipientType() const; 00115 00116 void setRecipient( const TQString & ); 00117 00118 void activate(); 00119 bool isActive(); 00120 00121 bool isEmpty(); 00122 00126 bool isModified(); 00127 00130 void clearModified(); 00131 00132 int setComboWidth( int w ); 00133 00134 void fixTabOrder( TQWidget *previous ); 00135 TQWidget *tabOut() const; 00136 00137 void clear(); 00138 00139 int recipientsCount(); 00140 00141 void setRemoveLineButtonEnabled( bool b ); 00142 00143 signals: 00144 void returnPressed( RecipientLine * ); 00145 void downPressed( RecipientLine * ); 00146 void upPressed( RecipientLine * ); 00147 void rightPressed(); 00148 void deleteLine( RecipientLine * ); 00149 void countChanged(); 00150 void typeModified( RecipientLine * ); 00151 00152 protected: 00153 void keyPressEvent( TQKeyEvent * ); 00154 RecipientLineEdit* lineEdit() const { return mEdit; } 00155 00156 protected slots: 00157 void slotReturnPressed(); 00158 void analyzeLine( const TQString & ); 00159 void slotFocusUp(); 00160 void slotFocusDown(); 00161 void slotPropagateDeletion(); 00162 void slotTypeModified(); 00163 00164 private: 00165 friend class RecipientsView; 00166 TQComboBox *mCombo; 00167 RecipientLineEdit *mEdit; 00168 TQPushButton *mRemoveButton; 00169 int mRecipientsCount; 00170 bool mModified; 00171 }; 00172 00173 class RecipientsView : public TQScrollView 00174 { 00175 Q_OBJECT 00176 TQ_OBJECT 00177 public: 00178 RecipientsView( TQWidget *parent ); 00179 00180 TQSize minimumSizeHint() const; 00181 TQSize sizeHint() const; 00182 00183 RecipientLine *activeLine(); 00184 00185 RecipientLine *emptyLine(); 00186 00187 Recipient::List recipients() const; 00188 00193 void removeRecipient( const TQString & recipient, Recipient::Type type ); 00194 00198 bool isModified(); 00199 00202 void clearModified(); 00203 00204 void activateLine( RecipientLine * ); 00205 00212 int setFirstColumnWidth( int ); 00213 00214 public slots: 00215 void setCompletionMode( KGlobalSettings::Completion ); 00216 RecipientLine *addLine(); 00217 00218 void setFocus(); 00219 void setFocusTop(); 00220 void setFocusBottom(); 00221 00222 signals: 00223 void totalChanged( int recipients, int lines ); 00224 void focusUp(); 00225 void focusDown(); 00226 void focusRight(); 00227 void completionModeChanged( KGlobalSettings::Completion ); 00228 void sizeHintChanged(); 00229 00230 protected: 00231 void viewportResizeEvent( TQResizeEvent * ); 00232 void resizeView(); 00233 00234 protected slots: 00235 void slotReturnPressed( RecipientLine * ); 00236 void slotDownPressed( RecipientLine * ); 00237 void slotUpPressed( RecipientLine * ); 00238 void slotDecideLineDeletion( RecipientLine * ); 00239 void slotDeleteLine(); 00240 void calculateTotal(); 00241 void slotTypeModified( RecipientLine * ); 00242 void moveCompletionPopup(); 00243 00244 private: 00245 TQPtrList<RecipientLine> mLines; 00246 TQGuardedPtr<RecipientLine> mCurDelLine; 00247 int mLineHeight; 00248 int mFirstColumnWidth; 00249 bool mModified; 00250 KGlobalSettings::Completion mCompletionMode; 00251 }; 00252 00253 class RecipientsToolTip : public TQToolTip 00254 { 00255 public: 00256 RecipientsToolTip( RecipientsView *, TQWidget *parent ); 00257 00258 protected: 00259 void maybeTip( const TQPoint & p ); 00260 00261 TQString line( const Recipient & ); 00262 00263 private: 00264 RecipientsView *mView; 00265 }; 00266 00267 class SideWidget : public TQWidget 00268 { 00269 Q_OBJECT 00270 TQ_OBJECT 00271 public: 00272 SideWidget( RecipientsView *view, TQWidget *parent ); 00273 ~SideWidget(); 00274 00275 RecipientsPicker* picker() const; 00276 00277 public slots: 00278 void setTotal( int recipients, int lines ); 00279 void setFocus(); 00280 00281 void pickRecipient(); 00282 00283 signals: 00284 void pickedRecipient( const Recipient & ); 00285 void saveDistributionList(); 00286 00287 private: 00288 RecipientsView *mView; 00289 TQLabel *mTotalLabel; 00290 TQPushButton *mDistributionListButton; 00291 TQPushButton *mSelectButton; 00294 mutable RecipientsPicker *mRecipientPicker; 00296 mutable KWindowPositioner *mPickerPositioner; 00297 }; 00298 00299 class RecipientsEditor : public TQWidget 00300 { 00301 Q_OBJECT 00302 TQ_OBJECT 00303 public: 00304 RecipientsEditor( TQWidget *parent ); 00305 ~RecipientsEditor(); 00306 00307 void clear(); 00308 00309 Recipient::List recipients() const; 00310 RecipientsPicker* picker() const; 00311 00312 void setRecipientString( const TQString &, Recipient::Type ); 00313 TQString recipientString( Recipient::Type ); 00314 00319 void addRecipient( const TQString & recipient, Recipient::Type type ); 00320 00325 void removeRecipient( const TQString & recipient, Recipient::Type type ); 00326 00330 bool isModified(); 00331 00334 void clearModified(); 00335 00342 int setFirstColumnWidth( int ); 00343 00347 void setCompletionMode( KGlobalSettings::Completion ); 00348 00349 public slots: 00350 void setFocus(); 00351 void setFocusTop(); 00352 void setFocusBottom(); 00353 00354 void selectRecipients(); 00355 void saveDistributionList(); 00356 00357 signals: 00358 void focusUp(); 00359 void focusDown(); 00360 void completionModeChanged( KGlobalSettings::Completion ); 00361 void sizeHintChanged(); 00362 00363 protected slots: 00364 void slotPickedRecipient( const Recipient & ); 00365 00366 private: 00367 RecipientsView *mRecipientsView; 00368 SideWidget* mSideWidget; 00369 bool mModified; 00370 }; 00371 00372 #endif