kaddressbook

imagewidget.h
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 
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.
9 
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.
14 
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.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #ifndef IMAGEWIDGET_H
25 #define IMAGEWIDGET_H
26 
27 #include <tqlabel.h>
28 #include <tqpushbutton.h>
29 
30 #include <tdeabc/picture.h>
31 #include <kdialogbase.h>
32 
33 #include "contacteditorwidget.h"
34 
38 class ImageLoader : public TQObject
39 {
40  TQ_OBJECT
41 
42 
43  public:
44  ImageLoader( TQWidget *parent );
45 
46  TDEABC::Picture loadPicture( const KURL &url, bool *ok );
47 
48  private:
49  TDEABC::Picture mPicture;
50  TQWidget *mParent;
51 };
52 
56 class ImageButton : public TQPushButton
57 {
58  TQ_OBJECT
59 
60 
61  public:
62  ImageButton( const TQString &title, TQWidget *parent );
63 
64  void setReadOnly( bool readOnly );
65 
66  void setPicture( const TDEABC::Picture &picture );
67  TDEABC::Picture picture() const;
68 
69  void setImageLoader( ImageLoader *loader );
70 
71  signals:
72  void changed();
73  void urlDropped( const KURL& );
74 
75  protected:
76  virtual void dragEnterEvent( TQDragEnterEvent *event );
77  virtual void dropEvent( TQDropEvent *event );
78  virtual void mouseMoveEvent( TQMouseEvent *event );
79  virtual void mousePressEvent( TQMouseEvent *event );
80  virtual void contextMenuEvent( TQContextMenuEvent *event );
81 
82  private slots:
83  void load();
84  void clear();
85 
86  private:
87  void startDrag();
88  void updateGUI();
89 
90  bool mReadOnly;
91  TQPoint mDragStartPos;
92  TDEABC::Picture mPicture;
93 
94  ImageLoader *mImageLoader;
95 };
96 
97 
98 class ImageBaseWidget : public TQWidget
99 {
100  TQ_OBJECT
101 
102 
103  public:
104  ImageBaseWidget( const TQString &title, TQWidget *parent, const char *name = 0 );
105  ~ImageBaseWidget();
106 
110  void setImage( const TDEABC::Picture &photo );
111 
115  TDEABC::Picture image() const;
116 
117  void setReadOnly( bool readOnly );
118 
119  signals:
120  void changed();
121 
122  private:
123  ImageButton *mImageButton;
124  ImageLoader *mImageLoader;
125 
126  bool mReadOnly;
127 };
128 
129 class ImageWidget : public KAB::ContactEditorWidget
130 {
131  public:
132  ImageWidget( TDEABC::AddressBook *ab, TQWidget *parent, const char *name = 0 );
133 
134  void loadContact( TDEABC::Addressee *addr );
135  void storeContact( TDEABC::Addressee *addr );
136  void setReadOnly( bool readOnly );
137 
138  int logicalWidth() const { return 2; }
139 
140  private:
141  ImageBaseWidget *mPhotoWidget;
142  ImageBaseWidget *mLogoWidget;
143 };
144 
145 class ImageWidgetFactory : public KAB::ContactEditorWidgetFactory
146 {
147  public:
148  KAB::ContactEditorWidget *createWidget( TDEABC::AddressBook *ab, TQWidget *parent, const char *name )
149  {
150  return new ImageWidget( ab, parent, name );
151  }
152 
153  TQString pageIdentifier() const { return "misc"; }
154 };
155 
156 #endif
Small helper class.
Definition: imagewidget.h:57
Small helper class.
Definition: imagewidget.h:39