kaddressbook

imagewidget.h

00001 /*
00002     This file is part of KAddressBook.
00003     Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #ifndef IMAGEWIDGET_H
00025 #define IMAGEWIDGET_H
00026 
00027 #include <qlabel.h>
00028 #include <qpushbutton.h>
00029 
00030 #include <kabc/picture.h>
00031 #include <kdialogbase.h>
00032 
00033 #include "contacteditorwidget.h"
00034 
00038 class ImageLoader : public QObject
00039 {
00040   Q_OBJECT
00041 
00042   public:
00043     ImageLoader( QWidget *parent );
00044 
00045     KABC::Picture loadPicture( const KURL &url, bool *ok );
00046 
00047   private:
00048     KABC::Picture mPicture;
00049     QWidget *mParent;
00050 };
00051 
00055 class ImageButton : public QPushButton
00056 {
00057   Q_OBJECT
00058 
00059   public:
00060     ImageButton( const QString &title, QWidget *parent );
00061 
00062     void setReadOnly( bool readOnly );
00063 
00064     void setPicture( const KABC::Picture &picture );
00065     KABC::Picture picture() const;
00066 
00067     void setImageLoader( ImageLoader *loader );
00068 
00069   signals:
00070     void changed();
00071     void urlDropped( const KURL& );
00072 
00073   protected:
00074     virtual void dragEnterEvent( QDragEnterEvent *event );
00075     virtual void dropEvent( QDropEvent *event );
00076     virtual void mouseMoveEvent( QMouseEvent *event );
00077     virtual void mousePressEvent( QMouseEvent *event );
00078     virtual void contextMenuEvent( QContextMenuEvent *event );
00079 
00080   private slots:
00081     void load();
00082     void clear();
00083 
00084   private:
00085     void startDrag();
00086     void updateGUI();
00087 
00088     bool mReadOnly;
00089     QPoint mDragStartPos;
00090     KABC::Picture mPicture;
00091 
00092     ImageLoader *mImageLoader;
00093 };
00094 
00095 
00096 class ImageBaseWidget : public QWidget
00097 {
00098   Q_OBJECT
00099 
00100   public:
00101     ImageBaseWidget( const QString &title, QWidget *parent, const char *name = 0 );
00102     ~ImageBaseWidget();
00103 
00107     void setImage( const KABC::Picture &photo );
00108 
00112     KABC::Picture image() const;
00113 
00114     void setReadOnly( bool readOnly );
00115 
00116   signals:
00117     void changed();
00118 
00119   private:
00120     ImageButton *mImageButton;
00121     ImageLoader *mImageLoader;
00122 
00123     bool mReadOnly;
00124 };
00125 
00126 class ImageWidget : public KAB::ContactEditorWidget
00127 {
00128   public:
00129     ImageWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
00130 
00131     void loadContact( KABC::Addressee *addr );
00132     void storeContact( KABC::Addressee *addr );
00133     void setReadOnly( bool readOnly );
00134 
00135     int logicalWidth() const { return 2; }
00136 
00137   private:
00138     ImageBaseWidget *mPhotoWidget;
00139     ImageBaseWidget *mLogoWidget;
00140 };
00141 
00142 class ImageWidgetFactory : public KAB::ContactEditorWidgetFactory
00143 {
00144   public:
00145     KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, QWidget *parent, const char *name )
00146     {
00147       return new ImageWidget( ab, parent, name );
00148     }
00149 
00150     QString pageIdentifier() const { return "misc"; }
00151 };
00152 
00153 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys