summaryrefslogtreecommitdiffabout
path: root/kaddressbook/imagewidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/imagewidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/imagewidget.cpp7
1 files changed, 1 insertions, 6 deletions
diff --git a/kaddressbook/imagewidget.cpp b/kaddressbook/imagewidget.cpp
index 49d456b..48370e3 100644
--- a/kaddressbook/imagewidget.cpp
+++ b/kaddressbook/imagewidget.cpp
@@ -1,299 +1,294 @@
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 <qapplication.h> 44#include <qapplication.h>
45 45
46#include "imagewidget.h" 46#include "imagewidget.h"
47 47
48ImageWidget::ImageWidget( QWidget *parent, const char *name ) 48ImageWidget::ImageWidget( QWidget *parent, const char *name )
49 : QWidget( parent, name ) 49 : QWidget( parent, name )
50{ 50{
51 QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(), 51 QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(),
52 KDialog::spacingHint() ); 52 KDialog::spacingHint() );
53 53
54 QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this ); 54 QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this );
55 QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 3, 2, 55 QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 3, 2,
56 KDialog::spacingHint() ); 56 KDialog::spacingHint() );
57 boxLayout->setRowStretch( 2, 1 ); 57 boxLayout->setRowStretch( 2, 1 );
58 58
59 mPhotoLabel = new QLabel( photoBox ); 59 mPhotoLabel = new QLabel( photoBox );
60 int fac = 9; 60 int fac = 9;
61 if ( QApplication::desktop()->width() > 320 ) 61 if ( QApplication::desktop()->width() > 320 )
62 fac = 6; 62 fac = 6;
63 mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac ); 63 mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac );
64 mPhotoLabel->setScaledContents( true ); 64 mPhotoLabel->setScaledContents( true );
65 mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 65 mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
66 boxLayout->addMultiCellWidget( mPhotoLabel, 0, 2, 0, 0 ); 66 boxLayout->addMultiCellWidget( mPhotoLabel, 0, 2, 0, 0 );
67 67
68 mPhotoUrl = new KURLRequester( photoBox ); 68 mPhotoUrl = new KURLRequester( photoBox );
69#ifndef KAB_EMBEDDED 69#ifndef KAB_EMBEDDED
70 mPhotoUrl->setFilter( KImageIO::pattern() ); 70 mPhotoUrl->setFilter( KImageIO::pattern() );
71#else //KAB_EMBEDDED 71#else //KAB_EMBEDDED
72//US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???"); 72//US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???");
73#endif //KAB_EMBEDDED 73#endif //KAB_EMBEDDED
74 74
75 75
76 boxLayout->addWidget( mPhotoUrl, 0, 1 ); 76 boxLayout->addWidget( mPhotoUrl, 0, 1 );
77 77
78 mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox ); 78 mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox );
79 mUsePhotoUrl->setEnabled( false ); 79 mUsePhotoUrl->setEnabled( false );
80 boxLayout->addWidget( mUsePhotoUrl, 1, 1 ); 80 boxLayout->addWidget( mUsePhotoUrl, 1, 1 );
81 81
82 topLayout->addWidget( photoBox, 0, 0 ); 82 topLayout->addWidget( photoBox, 0, 0 );
83 83
84 QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this ); 84 QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this );
85 boxLayout = new QGridLayout( logoBox->layout(), 3, 2, KDialog::spacingHint() ); 85 boxLayout = new QGridLayout( logoBox->layout(), 3, 2, KDialog::spacingHint() );
86 boxLayout->setRowStretch( 2, 1 ); 86 boxLayout->setRowStretch( 2, 1 );
87 87
88 mLogoLabel = new QLabel( logoBox ); 88 mLogoLabel = new QLabel( logoBox );
89 mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac ); 89 mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac );
90 mLogoLabel->setScaledContents( true ); 90 mLogoLabel->setScaledContents( true );
91 mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 91 mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
92 boxLayout->addMultiCellWidget( mLogoLabel, 0, 2, 0, 0 ); 92 boxLayout->addMultiCellWidget( mLogoLabel, 0, 2, 0, 0 );
93 93
94 mLogoUrl = new KURLRequester( logoBox ); 94 mLogoUrl = new KURLRequester( logoBox );
95#ifndef KAB_EMBEDDED 95#ifndef KAB_EMBEDDED
96 mLogoUrl->setFilter( KImageIO::pattern() ); 96 mLogoUrl->setFilter( KImageIO::pattern() );
97#else //KAB_EMBEDDED 97#else //KAB_EMBEDDED
98//US qDebug("ImageWidget::ImageWidget KImageIO not defined 2"); 98//US qDebug("ImageWidget::ImageWidget KImageIO not defined 2");
99#endif //KAB_EMBEDDED 99#endif //KAB_EMBEDDED
100 boxLayout->addWidget( mLogoUrl, 0, 1 ); 100 boxLayout->addWidget( mLogoUrl, 0, 1 );
101 101
102 mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox ); 102 mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox );
103 mUseLogoUrl->setEnabled( false ); 103 mUseLogoUrl->setEnabled( false );
104 boxLayout->addWidget( mUseLogoUrl, 1, 1 ); 104 boxLayout->addWidget( mUseLogoUrl, 1, 1 );
105 105
106 topLayout->addWidget( logoBox, 1, 0 ); 106 topLayout->addWidget( logoBox, 1, 0 );
107 107
108 connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ), 108 connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ),
109 SIGNAL( changed() ) ); 109 SIGNAL( changed() ) );
110 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), 110 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
111 SLOT( loadPhoto() ) ); 111 SLOT( loadPhoto() ) );
112 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), 112 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
113 SIGNAL( changed() ) ); 113 SIGNAL( changed() ) );
114 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), 114 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
115 SLOT( updateGUI() ) ); 115 SLOT( updateGUI() ) );
116 connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ), 116 connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ),
117 SIGNAL( changed() ) ); 117 SIGNAL( changed() ) );
118 118
119 connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ), 119 connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ),
120 SIGNAL( changed() ) ); 120 SIGNAL( changed() ) );
121 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), 121 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
122 SLOT( loadLogo() ) ); 122 SLOT( loadLogo() ) );
123 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), 123 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
124 SIGNAL( changed() ) ); 124 SIGNAL( changed() ) );
125 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), 125 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
126 SLOT( updateGUI() ) ); 126 SLOT( updateGUI() ) );
127 connect( mUseLogoUrl, SIGNAL( toggled( bool ) ), 127 connect( mUseLogoUrl, SIGNAL( toggled( bool ) ),
128 SIGNAL( changed() ) ); 128 SIGNAL( changed() ) );
129 129
130#ifndef KAB_EMBEDDED 130#ifndef KAB_EMBEDDED
131 KAcceleratorManager::manage( this ); 131 KAcceleratorManager::manage( this );
132#endif //KAB_EMBEDDED 132#endif //KAB_EMBEDDED
133 133
134#ifndef DESKTOP_VERSION
135 mUsePhotoUrl->setChecked( true );
136 mUseLogoUrl->setChecked( true );
137#endif
138} 134}
139 135
140ImageWidget::~ImageWidget() 136ImageWidget::~ImageWidget()
141{ 137{
142} 138}
143 139
144void ImageWidget::setPhoto( const KABC::Picture &photo ) 140void ImageWidget::setPhoto( const KABC::Picture &photo )
145{ 141{
146 bool blocked = signalsBlocked(); 142 bool blocked = signalsBlocked();
147 blockSignals( true ); 143 blockSignals( true );
148 144
149 if ( photo.isIntern() ) { 145 if ( photo.isIntern() ) {
150//US 146//US
151//US mPhotoLabel->setPixmap( photo.data() ); 147//US mPhotoLabel->setPixmap( photo.data() );
152 if (photo.data().isNull() != true) 148 if (photo.data().isNull() != true)
153 { 149 {
154 QPixmap pm; 150 QPixmap pm;
155 pm.convertFromImage(photo.data()); 151 pm.convertFromImage(photo.data());
156 152
157 mPhotoLabel->setPixmap( pm ); 153 mPhotoLabel->setPixmap( pm );
158 } 154 }
159 155
160 mUsePhotoUrl->setChecked( false ); 156 mUsePhotoUrl->setChecked( false );
161 } else { 157 } else {
162 mPhotoUrl->setURL( photo.url() ); 158 mPhotoUrl->setURL( photo.url() );
163 if ( !photo.url().isEmpty() ) 159 if ( !photo.url().isEmpty() )
164 mUsePhotoUrl->setChecked( true ); 160 mUsePhotoUrl->setChecked( true );
165 loadPhoto(); 161 loadPhoto();
166 } 162 }
167 163
168 blockSignals( blocked ); 164 blockSignals( blocked );
169} 165}
170 166
171KABC::Picture ImageWidget::photo() const 167KABC::Picture ImageWidget::photo() const
172{ 168{
173 KABC::Picture photo; 169 KABC::Picture photo;
174 170
175 if ( mUsePhotoUrl->isChecked() ) 171 if ( mUsePhotoUrl->isChecked() )
176 photo.setUrl( mPhotoUrl->url() ); 172 photo.setUrl( mPhotoUrl->url() );
177 else { 173 else {
178 QPixmap *px = mPhotoLabel->pixmap(); 174 QPixmap *px = mPhotoLabel->pixmap();
179 if ( px ) { 175 if ( px ) {
180#ifndef KAB_EMBEDDED 176#ifndef KAB_EMBEDDED
181 if ( px->height() > px->width() ) 177 if ( px->height() > px->width() )
182 photo.setData( px->convertToImage().scaleHeight( 140 ) ); 178 photo.setData( px->convertToImage().scaleHeight( 140 ) );
183 else 179 else
184 photo.setData( px->convertToImage().scaleWidth( 100 ) ); 180 photo.setData( px->convertToImage().scaleWidth( 100 ) );
185#else //KAB_EMBEDDED 181#else //KAB_EMBEDDED
186//US add teh nullcheck 182//US add teh nullcheck
187 if (px->isNull() != true ) 183 if (px->isNull() != true )
188 photo.setData( px->convertToImage() ); 184 photo.setData( px->convertToImage() );
189#endif //KAB_EMBEDDED 185#endif //KAB_EMBEDDED
190 186
191 photo.setType( "PNG" ); 187 photo.setType( "PNG" );
192 } 188 }
193 } 189 }
194 190
195 return photo; 191 return photo;
196} 192}
197 193
198void ImageWidget::setLogo( const KABC::Picture &logo ) 194void ImageWidget::setLogo( const KABC::Picture &logo )
199{ 195{
200 bool blocked = signalsBlocked(); 196 bool blocked = signalsBlocked();
201 blockSignals( true ); 197 blockSignals( true );
202 198
203 if ( logo.isIntern() ) { 199 if ( logo.isIntern() ) {
204//US 200//US
205//US mLogoLabel->setPixmap( logo.data() ); 201//US mLogoLabel->setPixmap( logo.data() );
206 if (logo.data().isNull() != true) 202 if (logo.data().isNull() != true)
207 { 203 {
208 QPixmap pm; 204 QPixmap pm;
209 pm.convertFromImage(logo.data()); 205 pm.convertFromImage(logo.data());
210 mLogoLabel->setPixmap( pm ); 206 mLogoLabel->setPixmap( pm );
211 } 207 }
212 mUseLogoUrl->setChecked( false ); 208 mUseLogoUrl->setChecked( false );
213 } else { 209 } else {
214 mLogoUrl->setURL( logo.url() ); 210 mLogoUrl->setURL( logo.url() );
215 if ( !logo.url().isEmpty() ) 211 if ( !logo.url().isEmpty() )
216 mUseLogoUrl->setChecked( true ); 212 mUseLogoUrl->setChecked( true );
217 loadLogo(); 213 loadLogo();
218 } 214 }
219 215
220 blockSignals( blocked ); 216 blockSignals( blocked );
221} 217}
222 218
223KABC::Picture ImageWidget::logo() const 219KABC::Picture ImageWidget::logo() const
224{ 220{
225 KABC::Picture logo; 221 KABC::Picture logo;
226 222
227 if ( mUseLogoUrl->isChecked() ) 223 if ( mUseLogoUrl->isChecked() )
228 logo.setUrl( mLogoUrl->url() ); 224 logo.setUrl( mLogoUrl->url() );
229 else { 225 else {
230 QPixmap *px = mLogoLabel->pixmap(); 226 QPixmap *px = mLogoLabel->pixmap();
231 if ( px ) { 227 if ( px ) {
232#ifndef KAB_EMBEDDED 228#ifndef KAB_EMBEDDED
233 if ( px->height() > px->width() ) 229 if ( px->height() > px->width() )
234 logo.setData( px->convertToImage().scaleHeight( 140 ) ); 230 logo.setData( px->convertToImage().scaleHeight( 140 ) );
235 else 231 else
236 logo.setData( px->convertToImage().scaleWidth( 100 ) ); 232 logo.setData( px->convertToImage().scaleWidth( 100 ) );
237#else //KAB_EMBEDDED 233#else //KAB_EMBEDDED
238 logo.setData( px->convertToImage() ); 234 logo.setData( px->convertToImage() );
239#endif //KAB_EMBEDDED 235#endif //KAB_EMBEDDED
240 236
241 logo.setType( "PNG" ); 237 logo.setType( "PNG" );
242 238
243 } 239 }
244 } 240 }
245 241
246 return logo; 242 return logo;
247} 243}
248 244
249void ImageWidget::loadPhoto() 245void ImageWidget::loadPhoto()
250{ 246{
251 mPhotoLabel->setPixmap( loadPixmap( mPhotoUrl->url() ) ); 247 mPhotoLabel->setPixmap( loadPixmap( mPhotoUrl->url() ) );
252} 248}
253 249
254void ImageWidget::loadLogo() 250void ImageWidget::loadLogo()
255{ 251{
256 mLogoLabel->setPixmap( loadPixmap( mLogoUrl->url() ) ); 252 mLogoLabel->setPixmap( loadPixmap( mLogoUrl->url() ) );
257} 253}
258 254
259void ImageWidget::updateGUI() 255void ImageWidget::updateGUI()
260{ 256{
261 KURLRequester *ptr = (KURLRequester*)sender(); 257 KURLRequester *ptr = (KURLRequester*)sender();
262 258
263#ifdef DESKTOP_VERSION 259
264 if ( ptr == mPhotoUrl ) 260 if ( ptr == mPhotoUrl )
265 mUsePhotoUrl->setEnabled( true ); 261 mUsePhotoUrl->setEnabled( true );
266 else if ( ptr == mLogoUrl ) 262 else if ( ptr == mLogoUrl )
267 mUseLogoUrl->setEnabled( true ); 263 mUseLogoUrl->setEnabled( true );
268#endif
269} 264}
270 265
271QPixmap ImageWidget::loadPixmap( const KURL &url ) 266QPixmap ImageWidget::loadPixmap( const KURL &url )
272{ 267{
273 QString tempFile; 268 QString tempFile;
274 QPixmap pixmap; 269 QPixmap pixmap;
275 270
276 if ( url.isEmpty() ) 271 if ( url.isEmpty() )
277 return pixmap; 272 return pixmap;
278 273
279 if ( url.isLocalFile() ) 274 if ( url.isLocalFile() )
280 pixmap = QPixmap( url.path() ); 275 pixmap = QPixmap( url.path() );
281 else 276 else
282 { 277 {
283#ifndef KAB_EMBEDDED 278#ifndef KAB_EMBEDDED
284 if ( KIO::NetAccess::download( url, tempFile ) ) { 279 if ( KIO::NetAccess::download( url, tempFile ) ) {
285 pixmap = QPixmap( tempFile ); 280 pixmap = QPixmap( tempFile );
286 KIO::NetAccess::removeTempFile( tempFile ); 281 KIO::NetAccess::removeTempFile( tempFile );
287 } 282 }
288#else //KAB_EMBEDDED 283#else //KAB_EMBEDDED
289 qDebug("ImageWidget::loadPixmap : only local pixmaps are allowed"); 284 qDebug("ImageWidget::loadPixmap : only local pixmaps are allowed");
290#endif //KAB_EMBEDDED 285#endif //KAB_EMBEDDED
291 286
292 } 287 }
293 288
294 return pixmap; 289 return pixmap;
295} 290}
296 291
297#ifndef KAB_EMBEDDED 292#ifndef KAB_EMBEDDED
298#include "imagewidget.moc" 293#include "imagewidget.moc"
299#endif //KAB_EMBEDDED 294#endif //KAB_EMBEDDED