FEATURE: (contracted in prokde35)
[kdepim.git] / kaddressbook / imagewidget.h
blob02a3577c1f79a00ae415898aff85bdf985590fdf
1 /*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
24 #ifndef IMAGEWIDGET_H
25 #define IMAGEWIDGET_H
27 #include <qlabel.h>
28 #include <qpushbutton.h>
30 #include <kabc/picture.h>
31 #include <kdialogbase.h>
33 #include "contacteditorwidget.h"
35 /**
36 Small helper class
38 class ImageLoader : public QObject
40 Q_OBJECT
42 public:
43 ImageLoader( QWidget *parent );
45 KABC::Picture loadPicture( const KURL &url, bool *ok );
47 private:
48 KABC::Picture mPicture;
49 QWidget *mParent;
52 /**
53 Small helper class
55 class ImageButton : public QPushButton
57 Q_OBJECT
59 public:
60 ImageButton( const QString &title, QWidget *parent );
62 void setReadOnly( bool readOnly );
64 void setPicture( const KABC::Picture &picture );
65 KABC::Picture picture() const;
67 void setImageLoader( ImageLoader *loader );
69 signals:
70 void changed();
71 void urlDropped( const KURL& );
73 protected:
74 virtual void dragEnterEvent( QDragEnterEvent *event );
75 virtual void dropEvent( QDropEvent *event );
76 virtual void mouseMoveEvent( QMouseEvent *event );
77 virtual void mousePressEvent( QMouseEvent *event );
78 virtual void contextMenuEvent( QContextMenuEvent *event );
80 private slots:
81 void load();
82 void clear();
84 private:
85 void startDrag();
86 void updateGUI();
88 bool mReadOnly;
89 QPoint mDragStartPos;
90 KABC::Picture mPicture;
92 ImageLoader *mImageLoader;
96 class ImageBaseWidget : public QWidget
98 Q_OBJECT
100 public:
101 ImageBaseWidget( const QString &title, QWidget *parent, const char *name = 0 );
102 ~ImageBaseWidget();
105 Sets the photo object.
107 void setImage( const KABC::Picture &photo );
110 Returns a photo object.
112 KABC::Picture image() const;
114 void setReadOnly( bool readOnly );
116 signals:
117 void changed();
119 private:
120 ImageButton *mImageButton;
121 ImageLoader *mImageLoader;
123 bool mReadOnly;
126 class ImageWidget : public KAB::ContactEditorWidget
128 public:
129 ImageWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
131 void loadContact( KABC::Addressee *addr );
132 void storeContact( KABC::Addressee *addr );
133 void setReadOnly( bool readOnly );
135 int logicalWidth() const { return 2; }
137 private:
138 ImageBaseWidget *mPhotoWidget;
139 ImageBaseWidget *mLogoWidget;
142 class ImageWidgetFactory : public KAB::ContactEditorWidgetFactory
144 public:
145 KAB::ContactEditorWidget *createWidget( KABC::AddressBook *ab, QWidget *parent, const char *name )
147 return new ImageWidget( ab, parent, name );
150 QString pageIdentifier() const { return "misc"; }
153 #endif