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 TQt, and distribute the resulting executable,
00021     without including the source code for TQt in the source distribution.
00022 */
00023 
00024 #ifndef IMAGEWIDGET_H
00025 #define IMAGEWIDGET_H
00026 
00027 #include <tqlabel.h>
00028 #include <tqpushbutton.h>
00029 
00030 #include <kabc/picture.h>
00031 #include <kdialogbase.h>
00032 
00033 #include "contacteditorwidget.h"
00034 
00038 class ImageLoader : public TQObject
00039 {
00040   Q_OBJECT
00041   TQ_OBJECT
00042 
00043   public:
00044     ImageLoader( TQWidget *parent );
00045 
00046     KABC::Picture loadPicture( const KURL &url, bool *ok );
00047 
00048   private:
00049     KABC::Picture mPicture;
00050     TQWidget *mParent;
00051 };
00052 
00056 class ImageButton : public TQPushButton
00057 {
00058   Q_OBJECT
00059   TQ_OBJECT
00060 
00061   public:
00062     ImageButton( const TQString &title, TQWidget *parent );
00063 
00064     void setReadOnly( bool readOnly );
00065 
00066     void setPicture( const KABC::Picture &picture );
00067     KABC::Picture picture() const;
00068 
00069     void setImageLoader( ImageLoader *loader );
00070 
00071   signals:
00072     void changed();
00073     void urlDropped( const KURL& );
00074 
00075   protected:
00076     virtual void dragEnterEvent( TQDragEnterEvent *event );
00077     virtual void dropEvent( TQDropEvent *event );
00078     virtual void mouseMoveEvent( TQMouseEvent *event );
00079     virtual void mousePressEvent( TQMouseEvent *event );
00080     virtual void contextMenuEvent( TQContextMenuEvent *event );
00081 
00082   private slots:
00083     void load();
00084     void clear();
00085 
00086   private:
00087     void startDrag();
00088     void updateGUI();
00089 
00090     bool mReadOnly;
00091     TQPoint mDragStartPos;
00092     KABC::Picture mPicture;
00093 
00094     ImageLoader *mImageLoader;
00095 };
00096 
00097 
00098 class ImageBaseWidget : public TQWidget
00099 {
00100   Q_OBJECT
00101   TQ_OBJECT
00102 
00103   public:
00104     ImageBaseWidget( const TQString &title, TQWidget *parent, const char *name = 0 );
00105     ~ImageBaseWidget();
00106 
00110     void setImage( const KABC::Picture &photo );
00111 
00115     KABC::Picture image() const;
00116 
00117     void setReadOnly( bool readOnly );
00118 
00119   signals:
00120     void changed();
00121 
00122   private:
00123     ImageButton *mImageButton;
00124     ImageLoader *mImageLoader;
00125 
00126     bool mReadOnly;
00127 };
00128 
00129 class ImageWidget : public KAB::ContactEditorWidget
00130 {
00131   public:
00132     ImageWidget( KABC::AddressBook *ab, TQWidget *parent, const char *name = 0 );
00133 
00134     void loadContact( KABC::Addressee *addr );
00135     void storeContact( KABC::Addressee *addr );
00136     void setReadOnly( bool readOnly );
00137 
00138     int logicalWidth() const { return 2; }
00139 
00140   private:
00141     ImageBaseWidget *mPhotoWidget;
00142     ImageBaseWidget *mLogoWidget;
00143 };
00144 
00145 class ImageWidgetFactory : public KAB::ContactEditorWidgetFactory
00146 {
00147   public:
00148     KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, TQWidget *parent, const char *name )
00149     {
00150       return new ImageWidget( ab, parent, name );
00151     }
00152 
00153     TQString pageIdentifier() const { return "misc"; }
00154 };
00155 
00156 #endif