summaryrefslogtreecommitdiffabout
path: root/kaddressbook/imagewidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/imagewidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/imagewidget.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/kaddressbook/imagewidget.cpp b/kaddressbook/imagewidget.cpp
index 48370e3..9ee4eac 100644
--- a/kaddressbook/imagewidget.cpp
+++ b/kaddressbook/imagewidget.cpp
@@ -1,153 +1,163 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <kabc/picture.h> 24#include <kabc/picture.h>
25 25
26#ifndef KAB_EMBEDDED 26#ifndef KAB_EMBEDDED
27#include <kaccelmanager.h> 27#include <kaccelmanager.h>
28#include <kio/netaccess.h> 28#include <kio/netaccess.h>
29#include <kimageio.h> 29#include <kimageio.h>
30#endif //KAB_EMBEDDED 30#endif //KAB_EMBEDDED
31 31
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kdialog.h> 33#include <kdialog.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <klocale.h> 35#include <klocale.h>
36#include <kurlrequester.h> 36#include <kurlrequester.h>
37#include <kurl.h> 37#include <kurl.h>
38 38
39#include <qcheckbox.h> 39#include <qcheckbox.h>
40#include <qgroupbox.h> 40#include <qgroupbox.h>
41#include <qlabel.h> 41#include <qlabel.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qpixmap.h> 43#include <qpixmap.h>
44#include <qpushbutton.h>
44#include <qapplication.h> 45#include <qapplication.h>
45 46
46#include "imagewidget.h" 47#include "imagewidget.h"
47 48
48ImageWidget::ImageWidget( QWidget *parent, const char *name ) 49ImageWidget::ImageWidget( QWidget *parent, const char *name )
49 : QWidget( parent, name ) 50 : QWidget( parent, name )
50{ 51{
51 QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(), 52 QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(),
52 KDialog::spacingHint() ); 53 KDialog::spacingHint() );
53 54
54 QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this ); 55 QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this );
55 QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 3, 2, 56 QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 4, 2,
56 KDialog::spacingHint() ); 57 KDialog::spacingHint() );
57 boxLayout->setRowStretch( 2, 1 ); 58 boxLayout->setRowStretch( 2, 1 );
58 59
59 mPhotoLabel = new QLabel( photoBox ); 60 mPhotoLabel = new QLabel( photoBox );
60 int fac = 9; 61 int fac = 9;
61 if ( QApplication::desktop()->width() > 320 ) 62 if ( QApplication::desktop()->width() > 320 )
62 fac = 6; 63 fac = 6;
63 mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac ); 64 mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac );
64 mPhotoLabel->setScaledContents( true ); 65 mPhotoLabel->setScaledContents( true );
65 mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 66 mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
66 boxLayout->addMultiCellWidget( mPhotoLabel, 0, 2, 0, 0 ); 67 boxLayout->addMultiCellWidget( mPhotoLabel, 0, 3, 0, 0 );
67 68
68 mPhotoUrl = new KURLRequester( photoBox ); 69 mPhotoUrl = new KURLRequester( photoBox );
69#ifndef KAB_EMBEDDED 70#ifndef KAB_EMBEDDED
70 mPhotoUrl->setFilter( KImageIO::pattern() ); 71 mPhotoUrl->setFilter( KImageIO::pattern() );
71#else //KAB_EMBEDDED 72#else //KAB_EMBEDDED
72//US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???"); 73//US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???");
73#endif //KAB_EMBEDDED 74#endif //KAB_EMBEDDED
74 75
75 76
76 boxLayout->addWidget( mPhotoUrl, 0, 1 ); 77 boxLayout->addWidget( mPhotoUrl, 0, 1 );
77 78
78 mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox ); 79 mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox );
79 mUsePhotoUrl->setEnabled( false ); 80 mUsePhotoUrl->setEnabled( false );
80 boxLayout->addWidget( mUsePhotoUrl, 1, 1 ); 81 boxLayout->addWidget( mUsePhotoUrl, 1, 1 );
81 82
83 QPushButton * pb = new QPushButton( i18n( "Remove" ), photoBox );
84 connect( pb, SIGNAL( clicked() ),this, SLOT( removePhoto() ) );
85 boxLayout->addWidget( pb, 2, 1 );
86 boxLayout->addWidget( new QLabel( photoBox ), 3, 1 );
87
82 topLayout->addWidget( photoBox, 0, 0 ); 88 topLayout->addWidget( photoBox, 0, 0 );
83 89
84 QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this ); 90 QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this );
85 boxLayout = new QGridLayout( logoBox->layout(), 3, 2, KDialog::spacingHint() ); 91 boxLayout = new QGridLayout( logoBox->layout(), 4, 2, KDialog::spacingHint() );
86 boxLayout->setRowStretch( 2, 1 ); 92 boxLayout->setRowStretch( 2, 1 );
87 93
88 mLogoLabel = new QLabel( logoBox ); 94 mLogoLabel = new QLabel( logoBox );
89 mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac ); 95 mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac );
90 mLogoLabel->setScaledContents( true ); 96 mLogoLabel->setScaledContents( true );
91 mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 97 mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
92 boxLayout->addMultiCellWidget( mLogoLabel, 0, 2, 0, 0 ); 98 boxLayout->addMultiCellWidget( mLogoLabel, 0, 3, 0, 0 );
93 99
94 mLogoUrl = new KURLRequester( logoBox ); 100 mLogoUrl = new KURLRequester( logoBox );
95#ifndef KAB_EMBEDDED 101#ifndef KAB_EMBEDDED
96 mLogoUrl->setFilter( KImageIO::pattern() ); 102 mLogoUrl->setFilter( KImageIO::pattern() );
97#else //KAB_EMBEDDED 103#else //KAB_EMBEDDED
98//US qDebug("ImageWidget::ImageWidget KImageIO not defined 2"); 104//US qDebug("ImageWidget::ImageWidget KImageIO not defined 2");
99#endif //KAB_EMBEDDED 105#endif //KAB_EMBEDDED
100 boxLayout->addWidget( mLogoUrl, 0, 1 ); 106 boxLayout->addWidget( mLogoUrl, 0, 1 );
101 107
102 mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox ); 108 mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox );
103 mUseLogoUrl->setEnabled( false ); 109 mUseLogoUrl->setEnabled( false );
104 boxLayout->addWidget( mUseLogoUrl, 1, 1 ); 110 boxLayout->addWidget( mUseLogoUrl, 1, 1 );
105 111
112 pb = new QPushButton( i18n( "Remove" ), logoBox );
113 connect( pb, SIGNAL( clicked() ),this, SLOT( removeLogo() ) );
114 boxLayout->addWidget( pb, 2, 1 );
115 boxLayout->addWidget( new QLabel( logoBox ), 3, 1 );
106 topLayout->addWidget( logoBox, 1, 0 ); 116 topLayout->addWidget( logoBox, 1, 0 );
107 117
108 connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ), 118 connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ),
109 SIGNAL( changed() ) ); 119 SIGNAL( changed() ) );
110 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), 120 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
111 SLOT( loadPhoto() ) ); 121 SLOT( loadPhoto() ) );
112 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), 122 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
113 SIGNAL( changed() ) ); 123 SIGNAL( changed() ) );
114 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), 124 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
115 SLOT( updateGUI() ) ); 125 SLOT( updateGUI() ) );
116 connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ), 126 connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ),
117 SIGNAL( changed() ) ); 127 SIGNAL( changed() ) );
118 128
119 connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ), 129 connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ),
120 SIGNAL( changed() ) ); 130 SIGNAL( changed() ) );
121 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), 131 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
122 SLOT( loadLogo() ) ); 132 SLOT( loadLogo() ) );
123 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), 133 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
124 SIGNAL( changed() ) ); 134 SIGNAL( changed() ) );
125 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), 135 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
126 SLOT( updateGUI() ) ); 136 SLOT( updateGUI() ) );
127 connect( mUseLogoUrl, SIGNAL( toggled( bool ) ), 137 connect( mUseLogoUrl, SIGNAL( toggled( bool ) ),
128 SIGNAL( changed() ) ); 138 SIGNAL( changed() ) );
129 139
130#ifndef KAB_EMBEDDED 140#ifndef KAB_EMBEDDED
131 KAcceleratorManager::manage( this ); 141 KAcceleratorManager::manage( this );
132#endif //KAB_EMBEDDED 142#endif //KAB_EMBEDDED
133 143
134} 144}
135 145
136ImageWidget::~ImageWidget() 146ImageWidget::~ImageWidget()
137{ 147{
138} 148}
139 149
140void ImageWidget::setPhoto( const KABC::Picture &photo ) 150void ImageWidget::setPhoto( const KABC::Picture &photo )
141{ 151{
142 bool blocked = signalsBlocked(); 152 bool blocked = signalsBlocked();
143 blockSignals( true ); 153 blockSignals( true );
144 154
145 if ( photo.isIntern() ) { 155 if ( photo.isIntern() ) {
146//US 156//US
147//US mPhotoLabel->setPixmap( photo.data() ); 157//US mPhotoLabel->setPixmap( photo.data() );
148 if (photo.data().isNull() != true) 158 if (photo.data().isNull() != true)
149 { 159 {
150 QPixmap pm; 160 QPixmap pm;
151 pm.convertFromImage(photo.data()); 161 pm.convertFromImage(photo.data());
152 162
153 mPhotoLabel->setPixmap( pm ); 163 mPhotoLabel->setPixmap( pm );
@@ -193,99 +203,107 @@ KABC::Picture ImageWidget::photo() const
193 203
194void ImageWidget::setLogo( const KABC::Picture &logo ) 204void ImageWidget::setLogo( const KABC::Picture &logo )
195{ 205{
196 bool blocked = signalsBlocked(); 206 bool blocked = signalsBlocked();
197 blockSignals( true ); 207 blockSignals( true );
198 208
199 if ( logo.isIntern() ) { 209 if ( logo.isIntern() ) {
200//US 210//US
201//US mLogoLabel->setPixmap( logo.data() ); 211//US mLogoLabel->setPixmap( logo.data() );
202 if (logo.data().isNull() != true) 212 if (logo.data().isNull() != true)
203 { 213 {
204 QPixmap pm; 214 QPixmap pm;
205 pm.convertFromImage(logo.data()); 215 pm.convertFromImage(logo.data());
206 mLogoLabel->setPixmap( pm ); 216 mLogoLabel->setPixmap( pm );
207 } 217 }
208 mUseLogoUrl->setChecked( false ); 218 mUseLogoUrl->setChecked( false );
209 } else { 219 } else {
210 mLogoUrl->setURL( logo.url() ); 220 mLogoUrl->setURL( logo.url() );
211 if ( !logo.url().isEmpty() ) 221 if ( !logo.url().isEmpty() )
212 mUseLogoUrl->setChecked( true ); 222 mUseLogoUrl->setChecked( true );
213 loadLogo(); 223 loadLogo();
214 } 224 }
215 225
216 blockSignals( blocked ); 226 blockSignals( blocked );
217} 227}
218 228
219KABC::Picture ImageWidget::logo() const 229KABC::Picture ImageWidget::logo() const
220{ 230{
221 KABC::Picture logo; 231 KABC::Picture logo;
222 232
223 if ( mUseLogoUrl->isChecked() ) 233 if ( mUseLogoUrl->isChecked() )
224 logo.setUrl( mLogoUrl->url() ); 234 logo.setUrl( mLogoUrl->url() );
225 else { 235 else {
226 QPixmap *px = mLogoLabel->pixmap(); 236 QPixmap *px = mLogoLabel->pixmap();
227 if ( px ) { 237 if ( px ) {
228#ifndef KAB_EMBEDDED 238#ifndef KAB_EMBEDDED
229 if ( px->height() > px->width() ) 239 if ( px->height() > px->width() )
230 logo.setData( px->convertToImage().scaleHeight( 140 ) ); 240 logo.setData( px->convertToImage().scaleHeight( 140 ) );
231 else 241 else
232 logo.setData( px->convertToImage().scaleWidth( 100 ) ); 242 logo.setData( px->convertToImage().scaleWidth( 100 ) );
233#else //KAB_EMBEDDED 243#else //KAB_EMBEDDED
234 logo.setData( px->convertToImage() ); 244 logo.setData( px->convertToImage() );
235#endif //KAB_EMBEDDED 245#endif //KAB_EMBEDDED
236 246
237 logo.setType( "PNG" ); 247 logo.setType( "PNG" );
238 248
239 } 249 }
240 } 250 }
241
242 return logo; 251 return logo;
243} 252}
253void ImageWidget::removePhoto()
254{
255 setPhoto(KABC::Picture() );
256}
257
258void ImageWidget::removeLogo()
259{
260 setLogo(KABC::Picture() );
261}
244 262
245void ImageWidget::loadPhoto() 263void ImageWidget::loadPhoto()
246{ 264{
247 mPhotoLabel->setPixmap( loadPixmap( mPhotoUrl->url() ) ); 265 mPhotoLabel->setPixmap( loadPixmap( mPhotoUrl->url() ) );
248} 266}
249 267
250void ImageWidget::loadLogo() 268void ImageWidget::loadLogo()
251{ 269{
252 mLogoLabel->setPixmap( loadPixmap( mLogoUrl->url() ) ); 270 mLogoLabel->setPixmap( loadPixmap( mLogoUrl->url() ) );
253} 271}
254 272
255void ImageWidget::updateGUI() 273void ImageWidget::updateGUI()
256{ 274{
257 KURLRequester *ptr = (KURLRequester*)sender(); 275 KURLRequester *ptr = (KURLRequester*)sender();
258 276
259 277
260 if ( ptr == mPhotoUrl ) 278 if ( ptr == mPhotoUrl )
261 mUsePhotoUrl->setEnabled( true ); 279 mUsePhotoUrl->setEnabled( true );
262 else if ( ptr == mLogoUrl ) 280 else if ( ptr == mLogoUrl )
263 mUseLogoUrl->setEnabled( true ); 281 mUseLogoUrl->setEnabled( true );
264} 282}
265 283
266QPixmap ImageWidget::loadPixmap( const KURL &url ) 284QPixmap ImageWidget::loadPixmap( const KURL &url )
267{ 285{
268 QString tempFile; 286 QString tempFile;
269 QPixmap pixmap; 287 QPixmap pixmap;
270 288
271 if ( url.isEmpty() ) 289 if ( url.isEmpty() )
272 return pixmap; 290 return pixmap;
273 291
274 if ( url.isLocalFile() ) 292 if ( url.isLocalFile() )
275 pixmap = QPixmap( url.path() ); 293 pixmap = QPixmap( url.path() );
276 else 294 else
277 { 295 {
278#ifndef KAB_EMBEDDED 296#ifndef KAB_EMBEDDED
279 if ( KIO::NetAccess::download( url, tempFile ) ) { 297 if ( KIO::NetAccess::download( url, tempFile ) ) {
280 pixmap = QPixmap( tempFile ); 298 pixmap = QPixmap( tempFile );
281 KIO::NetAccess::removeTempFile( tempFile ); 299 KIO::NetAccess::removeTempFile( tempFile );
282 } 300 }
283#else //KAB_EMBEDDED 301#else //KAB_EMBEDDED
284 qDebug("ImageWidget::loadPixmap : only local pixmaps are allowed"); 302 qDebug("ImageWidget::loadPixmap : only local pixmaps are allowed");
285#endif //KAB_EMBEDDED 303#endif //KAB_EMBEDDED
286 304
287 } 305 }
288 306
289 return pixmap; 307 return pixmap;
290} 308}
291 309