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 
00035 #include <librss/global.h>
00036 
00037 namespace RSS {
00038 class Loader;
00039 class Document;
00040 }
00041 
00042 using namespace RSS;
00043 
00047 class ImageLoader : public QObject
00048 {
00049   Q_OBJECT
00050 
00051   public:
00052     ImageLoader();
00053 
00054     KABC::Picture loadPicture( const KURL &url, bool *ok );
00055     KABC::Picture loadBlog( const KURL &url, bool *ok );
00056 
00057   private slots:
00058     void loadingComplete( Loader*, Document, Status );
00059 
00060   private:
00061     bool mIsLoadingBlog;
00062     KABC::Picture mPicture;
00063 };
00064 
00068 class ImageButton : public QPushButton
00069 {
00070   Q_OBJECT
00071 
00072   public:
00073     ImageButton( const QString &title, QWidget *parent );
00074 
00075     void setReadOnly( bool readOnly );
00076 
00077     void setPicture( const KABC::Picture &picture );
00078     KABC::Picture picture() const;
00079 
00080     void setImageLoader( ImageLoader *loader );
00081 
00082     void setBlogFeed( const KURL &url );
00083 
00084   signals:
00085     void changed();
00086     void urlDropped( const KURL& );
00087 
00088   protected:
00089     virtual void dragEnterEvent( QDragEnterEvent *event );
00090     virtual void dropEvent( QDropEvent *event );
00091     virtual void mouseMoveEvent( QMouseEvent *event );
00092     virtual void mousePressEvent( QMouseEvent *event );
00093     virtual void contextMenuEvent( QContextMenuEvent *event );
00094 
00095   private slots:
00096     void load();
00097     void loadBlog();
00098     void clear();
00099 
00100   private:
00101     void startDrag();
00102     void updateGUI();
00103 
00104     bool mReadOnly;
00105     KURL mBlogFeed;
00106     QPoint mDragStartPos;
00107     KABC::Picture mPicture;
00108 
00109     ImageLoader *mImageLoader;
00110 };
00111 
00112 
00113 class ImageBaseWidget : public QWidget
00114 {
00115   Q_OBJECT
00116 
00117   public:
00118     ImageBaseWidget( const QString &title, QWidget *parent, const char *name = 0 );
00119     ~ImageBaseWidget();
00120 
00124     void setBlogFeed( const QString & );
00125 
00129     void setImage( const KABC::Picture &photo );
00130 
00134     KABC::Picture image() const;
00135 
00136     void setReadOnly( bool readOnly );
00137 
00138   signals:
00139     void changed();
00140 
00141   private:
00142     ImageButton *mImageButton;
00143     ImageLoader *mImageLoader;
00144 
00145     bool mReadOnly;
00146 };
00147 
00148 class ImageWidget : public KAB::ContactEditorWidget
00149 {
00150   public:
00151     ImageWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
00152 
00153     void loadContact( KABC::Addressee *addr );
00154     void storeContact( KABC::Addressee *addr );
00155     void setReadOnly( bool readOnly );
00156 
00157     int logicalWidth() const { return 2; }
00158 
00159   private:
00160     ImageBaseWidget *mPhotoWidget;
00161     ImageBaseWidget *mLogoWidget;
00162 };
00163 
00164 class ImageWidgetFactory : public KAB::ContactEditorWidgetFactory
00165 {
00166   public:
00167     KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, QWidget *parent, const char *name )
00168     {
00169       return new ImageWidget( ab, parent, name );
00170     }
00171 
00172     QString pageIdentifier() const { return "misc"; }
00173 };
00174 
00175 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys