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     friend class RecipientsView;
00162     QComboBox *mCombo;
00163     RecipientLineEdit *mEdit;
00164     QPushButton *mRemoveButton;
00165     int mRecipientsCount;
00166     bool mModified;
00167 };
00168 
00169 class RecipientsView : public QScrollView
00170 {
00171     Q_OBJECT
00172   public:
00173     RecipientsView( QWidget *parent );
00174 
00175     QSize minimumSizeHint() const;
00176     QSize sizeHint() const;
00177 
00178     RecipientLine *activeLine();
00179 
00180     RecipientLine *emptyLine();
00181 
00182     Recipient::List recipients() const;
00183 
00188     void removeRecipient( const QString & recipient, Recipient::Type type );
00189 
00193     bool isModified();
00194 
00197     void clearModified();
00198 
00199     void activateLine( RecipientLine * );
00200 
00207     int setFirstColumnWidth( int );
00208 
00209   public slots:
00210     void setCompletionMode( KGlobalSettings::Completion );
00211     RecipientLine *addLine();
00212 
00213     void setFocus();
00214     void setFocusTop();
00215     void setFocusBottom();
00216 
00217   signals:
00218     void totalChanged( int recipients, int lines );
00219     void focusUp();
00220     void focusDown();
00221     void focusRight();
00222     void completionModeChanged( KGlobalSettings::Completion );
00223 
00224   protected:
00225     void viewportResizeEvent( QResizeEvent * );
00226     void resizeView();
00227 
00228   protected slots:
00229     void slotReturnPressed( RecipientLine * );
00230     void slotDownPressed( RecipientLine * );
00231     void slotUpPressed( RecipientLine * );
00232     void slotDecideLineDeletion(  RecipientLine * );
00233     void slotDeleteLine();
00234     void calculateTotal();
00235     void slotTypeModified( RecipientLine * );
00236 
00237   private:
00238     QPtrList<RecipientLine> mLines;
00239     QGuardedPtr<RecipientLine> mCurDelLine;
00240     int mLineHeight;
00241     int mFirstColumnWidth;
00242     bool mModified;
00243     KGlobalSettings::Completion mCompletionMode;
00244 };
00245 
00246 class RecipientsToolTip : public QToolTip
00247 {
00248   public:
00249     RecipientsToolTip( RecipientsView *, QWidget *parent );
00250 
00251   protected:
00252     void maybeTip( const QPoint & p );
00253 
00254     QString line( const Recipient & );
00255 
00256   private:
00257     RecipientsView *mView;
00258 };
00259 
00260 class SideWidget : public QWidget
00261 {
00262     Q_OBJECT
00263   public:
00264     SideWidget( RecipientsView *view, QWidget *parent );
00265     ~SideWidget();
00266 
00267     RecipientsPicker* picker() const;
00268 
00269   public slots:
00270     void setTotal( int recipients, int lines );
00271     void setFocus();
00272 
00273     void pickRecipient();
00274 
00275   signals:
00276     void pickedRecipient( const Recipient & );
00277     void saveDistributionList();
00278 
00279   private:
00280     RecipientsView *mView;
00281     QLabel *mTotalLabel;
00282     QPushButton *mDistributionListButton;
00283     QPushButton *mSelectButton;
00286     mutable RecipientsPicker *mRecipientPicker;
00288     mutable KWindowPositioner *mPickerPositioner;
00289 };
00290 
00291 class RecipientsEditor : public QWidget
00292 {
00293     Q_OBJECT
00294   public:
00295     RecipientsEditor( QWidget *parent );
00296     ~RecipientsEditor();
00297 
00298     void clear();
00299 
00300     Recipient::List recipients() const;
00301     RecipientsPicker* picker() const;
00302 
00303     void setRecipientString( const QString &, Recipient::Type );
00304     QString recipientString( Recipient::Type );
00305 
00310     void addRecipient( const QString & recipient, Recipient::Type type );
00311 
00316     void removeRecipient( const QString & recipient, Recipient::Type type );
00317 
00321     bool isModified();
00322 
00325     void clearModified();
00326 
00333     int setFirstColumnWidth( int );
00334 
00338     void setCompletionMode( KGlobalSettings::Completion );
00339 
00340   public slots:
00341     void setFocus();
00342     void setFocusTop();
00343     void setFocusBottom();
00344 
00345     void selectRecipients();
00346     void saveDistributionList();
00347 
00348   signals:
00349     void focusUp();
00350     void focusDown();
00351     void completionModeChanged( KGlobalSettings::Completion );
00352 
00353   protected slots:
00354     void slotPickedRecipient( const Recipient & );
00355 
00356   private:
00357     RecipientsView *mRecipientsView;
00358     SideWidget* mSideWidget;
00359     bool mModified;
00360 };
00361 
00362 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys