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
@@ -20,110 +20,120 @@
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
@@ -217,51 +227,59 @@ void ImageWidget::setLogo( const KABC::Picture &logo )
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{