kmail

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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 #ifndef RECIPIENTSEDITOR_H
00025 #define RECIPIENTSEDITOR_H
00026 
00027 #include <qwidget.h>
00028 #include <qscrollview.h>
00029 #include <qguardedptr.h>
00030 #include <qlineedit.h>
00031 #include <qtooltip.h>
00032 
00033 #include "kmlineeditspell.h"
00034 #include <qcombobox.h>
00035 
00036 class RecipientsPicker;
00037 
00038 class KWindowPositioner;
00039 
00040 class QLabel;
00041 class QPushButton;
00042 class SideWidget;
00043 
00044 class Recipient
00045 {
00046   public:
00047     typedef QValueList<Recipient> List;
00048 
00049     enum Type { To, Cc, Bcc, Undefined };
00050 
00051     Recipient( const QString &email = QString::null, Type type = To );
00052 
00053     void setType( Type );
00054     Type type() const;
00055 
00056     void setEmail( const QString & );
00057     QString email() const;
00058 
00059     bool isEmpty() const;
00060 
00061     static int typeToId( Type );
00062     static Type idToType( int );
00063 
00064     QString typeLabel() const;    static QString typeLabel( Type );
00065     static QStringList allTypeLabels();
00066 
00067   private:
00068     QString mEmail;
00069     Type mType;
00070 };
00071 
00072 class RecipientComboBox : public QComboBox
00073 {
00074     Q_OBJECT
00075   public:
00076     RecipientComboBox( QWidget *parent );
00077 
00078   signals:
00079     void rightPressed();
00080 
00081   protected:
00082     void keyPressEvent( QKeyEvent *ev );
00083 };
00084 
00085 class RecipientLineEdit : public KMLineEdit
00086 {
00087     Q_OBJECT
00088   public:
00089     RecipientLineEdit( QWidget * parent ) :
00090       KMLineEdit( true, parent ) {}
00091 
00092   signals:
00093     void deleteMe();
00094     void leftPressed();
00095     void rightPressed();
00096 
00097   protected:
00098     void keyPressEvent( QKeyEvent *ev );
00099 };
00100 
00101 class RecipientLine : public QWidget
00102 {
00103     Q_OBJECT
00104   public:
00105     RecipientLine( QWidget *parent );
00106 
00107     void setRecipient( const Recipient & );
00108     Recipient recipient() const;
00109 
00110     void setRecipientType( Recipient::Type );
00111     Recipient::Type recipientType() const;
00112 
00113     void setRecipient( const QString & );
00114 
00115     void activate();
00116     bool isActive();
00117 
00118     bool isEmpty();
00119 
00123     bool isModified();
00124 
00127     void clearModified();
00128 
00129     int setComboWidth( int w );
00130 
00131     void fixTabOrder( QWidget *previous );
00132     QWidget *tabOut() const;
00133 
00134     void clear();
00135 
00136     int recipientsCount();
00137 
00138     void setRemoveLineButtonEnabled( bool b );
00139 
00140   signals:
00141     void returnPressed( RecipientLine * );
00142     void downPressed( RecipientLine * );
00143     void upPressed( RecipientLine * );
00144     void rightPressed();
00145     void deleteLine(  RecipientLine * );
00146     void countChanged();
00147     void typeModified( RecipientLine * );
00148 
00149   protected:
00150     void keyPressEvent( QKeyEvent * );
00151 
00152   protected slots:
00153     void slotReturnPressed();
00154     void analyzeLine( const QString & );
00155     void slotFocusUp();
00156     void slotFocusDown();
00157     void slotPropagateDeletion();
00158     void slotTypeModified();
00159 
00160   private:
00161     QComboBox *mCombo;
00162     RecipientLineEdit *mEdit;
00163     QPushButton *mRemoveButton;
00164     int mRecipientsCount;
00165     bool mModified;
00166 };
00167 
00168 class RecipientsView : public QScrollView
00169 {
00170     Q_OBJECT
00171   public:
00172     RecipientsView( QWidget *parent );
00173 
00174     QSize minimumSizeHint() const;
00175     QSize sizeHint() const;
00176 
00177     RecipientLine *activeLine();
00178 
00179     RecipientLine *emptyLine();
00180 
00181     Recipient::List recipients() const;
00182 
00187     void removeRecipient( const QString & recipient, Recipient::Type type );
00188 
00192     bool isModified();
00193 
00196     void clearModified();
00197 
00198     void activateLine( RecipientLine * );
00199 
00206     int setFirstColumnWidth( int );
00207 
00208   public slots:
00209     RecipientLine *addLine();
00210 
00211     void setFocus();
00212     void setFocusTop();
00213     void setFocusBottom();
00214 
00215   signals:
00216     void totalChanged( int recipients, int lines );
00217     void focusUp();
00218     void focusDown();
00219     void focusRight();
00220 
00221   protected:
00222     void viewportResizeEvent( QResizeEvent * );
00223     void resizeView();
00224 
00225   protected slots:
00226     void slotReturnPressed( RecipientLine * );
00227     void slotDownPressed( RecipientLine * );
00228     void slotUpPressed( RecipientLine * );
00229     void slotDecideLineDeletion(  RecipientLine * );
00230     void slotDeleteLine();
00231     void calculateTotal();
00232     void slotTypeModified( RecipientLine * );
00233 
00234   private:
00235     QPtrList<RecipientLine> mLines;
00236     QGuardedPtr<RecipientLine> mCurDelLine;
00237     int mLineHeight;
00238     int mFirstColumnWidth;
00239     bool mModified;
00240 };
00241 
00242 class RecipientsToolTip : public QToolTip
00243 {
00244   public:
00245     RecipientsToolTip( RecipientsView *, QWidget *parent );
00246 
00247   protected:
00248     void maybeTip( const QPoint & p );
00249 
00250     QString line( const Recipient & );
00251 
00252   private:
00253     RecipientsView *mView;
00254 };
00255 
00256 class SideWidget : public QWidget
00257 {
00258     Q_OBJECT
00259   public:
00260     SideWidget( RecipientsView *view, QWidget *parent );
00261     ~SideWidget();
00262 
00263     RecipientsPicker* picker() const;
00264 
00265   public slots:
00266     void setTotal( int recipients, int lines );
00267     void setFocus();
00268 
00269     void pickRecipient();
00270 
00271   signals:
00272     void pickedRecipient( const Recipient & );
00273     void saveDistributionList();
00274 
00275   private:
00276     RecipientsView *mView;
00277     QLabel *mTotalLabel;
00278     QPushButton *mDistributionListButton;
00279     QPushButton *mSelectButton;
00282     mutable RecipientsPicker *mRecipientPicker;
00284     mutable KWindowPositioner *mPickerPositioner;
00285 };
00286 
00287 class RecipientsEditor : public QWidget
00288 {
00289     Q_OBJECT
00290   public:
00291     RecipientsEditor( QWidget *parent );
00292     ~RecipientsEditor();
00293 
00294     void clear();
00295 
00296     Recipient::List recipients() const;
00297     RecipientsPicker* picker() const;
00298 
00299     void setRecipientString( const QString &, Recipient::Type );
00300     QString recipientString( Recipient::Type );
00301 
00306     void addRecipient( const QString & recipient, Recipient::Type type );
00307 
00312     void removeRecipient( const QString & recipient, Recipient::Type type );
00313 
00317     bool isModified();
00318 
00321     void clearModified();
00322 
00329     int setFirstColumnWidth( int );
00330 
00331   public slots:
00332     void setFocus();
00333     void setFocusTop();
00334     void setFocusBottom();
00335 
00336     void selectRecipients();
00337     void saveDistributionList();
00338 
00339   signals:
00340     void focusUp();
00341     void focusDown();
00342 
00343   protected slots:
00344     void slotPickedRecipient( const Recipient & );
00345 
00346   private:
00347     RecipientsView *mRecipientsView;
00348     SideWidget* mSideWidget;
00349     bool mModified;
00350 };
00351 
00352 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys