summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kaddressbook/phoneeditwidget.cpp
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp60
1 files changed, 33 insertions, 27 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
index df3b551..3661677 100644
--- a/kaddressbook/phoneeditwidget.cpp
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -6,112 +6,118 @@
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 <qlayout.h> 24#include <qlayout.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qtooltip.h> 26#include <qtooltip.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qstring.h> 29#include <qstring.h>
30#include <qlistbox.h> 30#include <q3listbox.h>
31#include <qlistview.h> 31#include <q3listview.h>
32#include <qbuttongroup.h> 32#include <q3buttongroup.h>
33#include <qhbox.h> 33#include <q3hbox.h>
34#include <qcursor.h> 34#include <qcursor.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qapplication.h> 36#include <qapplication.h>
37//Added by qt3to4:
38#include <Q3ValueList>
39#include <Q3GridLayout>
40#include <Q3Frame>
41#include <Q3PopupMenu>
42#include <Q3VBoxLayout>
37 43
38#include <kbuttonbox.h> 44#include <kbuttonbox.h>
39#include <klistview.h> 45#include <klistview.h>
40#include <kapplication.h> 46#include <kapplication.h>
41#include <qapplication.h> 47#include <qapplication.h>
42#include <kconfig.h> 48#include <kconfig.h>
43#include <kmessagebox.h> 49#include <kmessagebox.h>
44#include <klineedit.h> 50#include <klineedit.h>
45#include <kcombobox.h> 51#include <kcombobox.h>
46#include <klocale.h> 52#include <klocale.h>
47#include <kdebug.h> 53#include <kdebug.h>
48#include <kglobal.h> 54#include <kglobal.h>
49#include <kiconloader.h> 55#include <kiconloader.h>
50 56
51#include <kabc/phonenumber.h> 57#include <kabc/phonenumber.h>
52 58
53#include "typecombo.h" 59#include "typecombo.h"
54 60
55#include "phoneeditwidget.h" 61#include "phoneeditwidget.h"
56 62
57PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 63PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
58 : QWidget(parent,name) 64 : QWidget(parent,name)
59{ 65{
60 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); 66 Q3GridLayout* gridLayout = new Q3GridLayout ( this, 2,2 );
61 67
62 QLabel *temp = new QLabel( "", this ); 68 QLabel *temp = new QLabel( "", this );
63 temp->setAlignment( Qt::AlignCenter ); 69 temp->setAlignment( Qt::AlignCenter );
64 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 70 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
65 QPushButton *addBut = new QPushButton ( "add", this ); 71 QPushButton *addBut = new QPushButton ( "add", this );
66 addBut->setPixmap ( SmallIcon("plus")); 72 addBut->setPixmap ( SmallIcon("plus"));
67 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); 73 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() );
68 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); 74 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber()));
69 75
70 sv = new QScrollView( this ); 76 sv = new Q3ScrollView( this );
71 sv->setFrameStyle ( QFrame::Plain ); 77 sv->setFrameStyle ( Q3Frame::Plain );
72 sv->setLineWidth ( 0 ); 78 sv->setLineWidth ( 0 );
73 sv->setMidLineWidth ( 0 ); 79 sv->setMidLineWidth ( 0 );
74 mw = new QWidget ( sv->viewport() ); 80 mw = new QWidget ( sv->viewport() );
75 sv->addChild(mw); 81 sv->addChild(mw);
76 sv->setResizePolicy( QScrollView::AutoOneFit ); 82 sv->setResizePolicy( Q3ScrollView::AutoOneFit );
77 mainLayout = new QVBoxLayout ( mw ); 83 mainLayout = new Q3VBoxLayout ( mw );
78 mainLayout->setMargin( 0 ); 84 mainLayout->setMargin( 0 );
79 mainLayout->setSpacing( 0 ); 85 mainLayout->setSpacing( 0 );
80 gridLayout->setMargin( 2 ); 86 gridLayout->setMargin( 2 );
81 gridLayout->setSpacing( 4 ); 87 gridLayout->setSpacing( 4 );
82 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { 88 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) {
83 gridLayout->addWidget( addBut, 0, 0 ); 89 gridLayout->addWidget( addBut, 0, 0 );
84 gridLayout->addWidget( temp, 0, 1 ); 90 gridLayout->addWidget( temp, 0, 1 );
85 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); 91 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 );
86 } else { 92 } else {
87 gridLayout->addWidget( temp, 1, 0 ); 93 gridLayout->addWidget( temp, 1, 0 );
88 gridLayout->addWidget( addBut, 0, 0 ); 94 gridLayout->addWidget( addBut, 0, 0 );
89 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); 95 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 );
90 } 96 }
91 setDefaults(); 97 setDefaults();
92 mTypeNumberEditList.setAutoDelete( true ); 98 mTypeNumberEditList.setAutoDelete( true );
93 mPopup = new QPopupMenu( this ); 99 mPopup = new Q3PopupMenu( this );
94 QStringList list = PhoneNumber::supportedTypeListNames(); 100 QStringList list = PhoneNumber::supportedTypeListNames();
95 mPopupCount = list.count(); 101 mPopupCount = list.count();
96 int i = 0; 102 int i = 0;
97 while ( i < mPopupCount ) { 103 while ( i < mPopupCount ) {
98 mPopup->insertItem( list[ i ], i ); 104 mPopup->insertItem( list[ i ], i );
99 ++i; 105 ++i;
100 } 106 }
101 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); 107 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int)));
102 108
103} 109}
104 110
105PhoneEditWidget::~PhoneEditWidget() 111PhoneEditWidget::~PhoneEditWidget()
106{ 112{
107} 113}
108void PhoneEditWidget::setDefaults() 114void PhoneEditWidget::setDefaults()
109{ 115{
110 mTypeNumberEditList.clear(); 116 mTypeNumberEditList.clear();
111 PhoneTypeNumberEdit* edit = appendEditCombo(); 117 PhoneTypeNumberEdit* edit = appendEditCombo();
112 KABC::PhoneNumber phoneNumber; 118 KABC::PhoneNumber phoneNumber;
113 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); 119 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref );
114 edit->setPhoneNumber( phoneNumber ); 120 edit->setPhoneNumber( phoneNumber );
115 edit = appendEditCombo(); 121 edit = appendEditCombo();
116 KABC::PhoneNumber phoneNumber2; 122 KABC::PhoneNumber phoneNumber2;
117 phoneNumber2.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); 123 phoneNumber2.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref );
@@ -205,59 +211,59 @@ void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li )
205 PhoneTypeNumberEdit* editNew = appendEditCombo(); 211 PhoneTypeNumberEdit* editNew = appendEditCombo();
206 editNew->setPhoneNumber( (*it ) ); 212 editNew->setPhoneNumber( (*it ) );
207 } 213 }
208 214
209} 215}
210KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 216KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
211{ 217{
212 KABC::PhoneNumber::List retList; 218 KABC::PhoneNumber::List retList;
213 219
214 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 220 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first();
215 while ( edit ) { 221 while ( edit ) {
216 if ( edit->isValid() ) { 222 if ( edit->isValid() ) {
217 retList.append( edit->phoneNumber()); 223 retList.append( edit->phoneNumber());
218 } 224 }
219 edit = mTypeNumberEditList.next(); 225 edit = mTypeNumberEditList.next();
220 226
221 } 227 }
222 return retList; 228 return retList;
223} 229}
224 230
225#if 0 231#if 0
226PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 232PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
227 : QWidget( parent, name ) 233 : QWidget( parent, name )
228{ 234{
229 QGridLayout *layout = new QGridLayout( this, 4, 1 ); 235 Q3GridLayout *layout = new Q3GridLayout( this, 4, 1 );
230//US layout->setSpacing( KDialog::spacingHint() ); 236//US layout->setSpacing( KDialog::spacingHint() );
231 layout->setSpacing( KDialogBase::spacingHintSmall() ); 237 layout->setSpacing( KDialogBase::spacingHintSmall() );
232 238
233 239
234 240
235 QLabel* label = new QLabel( this ); 241 QLabel* label = new QLabel( this );
236//US loadIcon call is ambiguous. Add one more parameter 242//US loadIcon call is ambiguous. Add one more parameter
237//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); 243//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
238 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 244 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
239 label->setAlignment( AlignCenter ); 245 label->setAlignment( Qt::AlignCenter );
240//US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); 246//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
241 layout->addWidget( label, 0, 0 ); 247 layout->addWidget( label, 0, 0 );
242 248
243 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), 249 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
244 this ); 250 this );
245 if ( QApplication::desktop()->width() < 640 ) 251 if ( QApplication::desktop()->width() < 640 )
246 layout->addWidget( editButton, 0, 1 ); 252 layout->addWidget( editButton, 0, 1 );
247 else 253 else
248 layout->addMultiCellWidget( editButton, 0, 0, 1, 3); 254 layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
249 255
250 mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); 256 mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
251 mPrefEdit = new KLineEdit( this ); 257 mPrefEdit = new KLineEdit( this );
252 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); 258 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
253 mPrefCombo->setLineEdit( mPrefEdit ); 259 mPrefCombo->setLineEdit( mPrefEdit );
254 layout->addWidget( mPrefCombo, 1, 0 ); 260 layout->addWidget( mPrefCombo, 1, 0 );
255 layout->addWidget( mPrefEdit, 1, 1 ); 261 layout->addWidget( mPrefEdit, 1, 1 );
256 int x = 1, y = 2; 262 int x = 1, y = 2;
257 if ( QApplication::desktop()->width() < 640 ) { 263 if ( QApplication::desktop()->width() < 640 ) {
258 ++x; 264 ++x;
259 y = 0; 265 y = 0;
260 } 266 }
261 mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); 267 mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
262 mSecondEdit = new KLineEdit( this ); 268 mSecondEdit = new KLineEdit( this );
263 mSecondCombo->setLineEdit( mSecondEdit ); 269 mSecondCombo->setLineEdit( mSecondEdit );
@@ -306,59 +312,59 @@ PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
306 312
307 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); 313 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
308 314
309 connect( mPrefCombo, SIGNAL( activated( int ) ), 315 connect( mPrefCombo, SIGNAL( activated( int ) ),
310 SLOT( updatePrefEdit() ) ); 316 SLOT( updatePrefEdit() ) );
311 connect( mSecondCombo, SIGNAL( activated( int ) ), 317 connect( mSecondCombo, SIGNAL( activated( int ) ),
312 SLOT( updateSecondEdit() ) ); 318 SLOT( updateSecondEdit() ) );
313 connect( mThirdCombo, SIGNAL( activated( int ) ), 319 connect( mThirdCombo, SIGNAL( activated( int ) ),
314 SLOT( updateThirdEdit() ) ); 320 SLOT( updateThirdEdit() ) );
315 connect( mFourthCombo, SIGNAL( activated( int ) ), 321 connect( mFourthCombo, SIGNAL( activated( int ) ),
316 SLOT( updateFourthEdit() ) ); 322 SLOT( updateFourthEdit() ) );
317} 323}
318 324
319PhoneEditWidget::~PhoneEditWidget() 325PhoneEditWidget::~PhoneEditWidget()
320{ 326{
321} 327}
322 328
323void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) 329void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list )
324{ 330{
325 mPhoneList.clear(); 331 mPhoneList.clear();
326 332
327 // Insert types for existing numbers. 333 // Insert types for existing numbers.
328 mPrefCombo->insertTypeList( list ); 334 mPrefCombo->insertTypeList( list );
329 335
330 QValueList<int> defaultTypes; 336 Q3ValueList<int> defaultTypes;
331 defaultTypes << KABC::PhoneNumber::Home; 337 defaultTypes << KABC::PhoneNumber::Home;
332 defaultTypes << KABC::PhoneNumber::Work; 338 defaultTypes << KABC::PhoneNumber::Work;
333 defaultTypes << KABC::PhoneNumber::Cell; 339 defaultTypes << KABC::PhoneNumber::Cell;
334 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); 340 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
335 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); 341 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
336 342
337 // Insert default types. 343 // Insert default types.
338 // Doing this for mPrefCombo is enough because the list is shared by all 344 // Doing this for mPrefCombo is enough because the list is shared by all
339 // combos. 345 // combos.
340 QValueList<int>::ConstIterator it; 346 Q3ValueList<int>::ConstIterator it;
341 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { 347 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
342 if ( !mPrefCombo->hasType( *it ) ) 348 if ( !mPrefCombo->hasType( *it ) )
343 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); 349 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) );
344 } 350 }
345 351
346 updateCombos(); 352 updateCombos();
347 353
348 mPrefCombo->selectType( defaultTypes[ 0 ] ); 354 mPrefCombo->selectType( defaultTypes[ 0 ] );
349 mSecondCombo->selectType( defaultTypes[ 1 ] ); 355 mSecondCombo->selectType( defaultTypes[ 1 ] );
350 mThirdCombo->selectType( defaultTypes[ 2 ] ); 356 mThirdCombo->selectType( defaultTypes[ 2 ] );
351 mFourthCombo->selectType( defaultTypes[ 3 ] ); 357 mFourthCombo->selectType( defaultTypes[ 3 ] );
352 358
353 updateLineEdits(); 359 updateLineEdits();
354} 360}
355 361
356void PhoneEditWidget::updateLineEdits() 362void PhoneEditWidget::updateLineEdits()
357{ 363{
358 updatePrefEdit(); 364 updatePrefEdit();
359 updateSecondEdit(); 365 updateSecondEdit();
360 updateThirdEdit(); 366 updateThirdEdit();
361 updateFourthEdit(); 367 updateFourthEdit();
362} 368}
363 369
364void PhoneEditWidget::updateCombos() 370void PhoneEditWidget::updateCombos()
@@ -466,182 +472,182 @@ void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo )
466 if ( it != mPhoneList.end() ) { 472 if ( it != mPhoneList.end() ) {
467 (*it).setNumber( edit->text() ); 473 (*it).setNumber( edit->text() );
468 } 474 }
469 475
470 updateOtherEdit( combo, mPrefCombo ); 476 updateOtherEdit( combo, mPrefCombo );
471 updateOtherEdit( combo, mSecondCombo ); 477 updateOtherEdit( combo, mSecondCombo );
472 updateOtherEdit( combo, mThirdCombo ); 478 updateOtherEdit( combo, mThirdCombo );
473 updateOtherEdit( combo, mFourthCombo ); 479 updateOtherEdit( combo, mFourthCombo );
474 480
475 emit modified(); 481 emit modified();
476} 482}
477 483
478void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) 484void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo )
479{ 485{
480 if ( combo == otherCombo ) return; 486 if ( combo == otherCombo ) return;
481 487
482 if ( combo->currentItem() == otherCombo->currentItem() ) { 488 if ( combo->currentItem() == otherCombo->currentItem() ) {
483 updateEdit( otherCombo ); 489 updateEdit( otherCombo );
484 } 490 }
485} 491}
486 492
487/////////////////////////////////////////// 493///////////////////////////////////////////
488// PhoneEditDialog 494// PhoneEditDialog
489 495
490class PhoneViewItem : public QListViewItem 496class PhoneViewItem : public Q3ListViewItem
491{ 497{
492public: 498public:
493 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); 499 PhoneViewItem( Q3ListView *parent, const KABC::PhoneNumber &number );
494 500
495 void setPhoneNumber( const KABC::PhoneNumber &number ) 501 void setPhoneNumber( const KABC::PhoneNumber &number )
496 { 502 {
497 mPhoneNumber = number; 503 mPhoneNumber = number;
498 makeText(); 504 makeText();
499 } 505 }
500 506
501 QString key() { return mPhoneNumber.id(); } 507 QString key() { return mPhoneNumber.id(); }
502 QString country() { return ""; } 508 QString country() { return ""; }
503 QString region() { return ""; } 509 QString region() { return ""; }
504 QString number() { return ""; } 510 QString number() { return ""; }
505 511
506 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } 512 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; }
507 513
508private: 514private:
509 void makeText(); 515 void makeText();
510 516
511 KABC::PhoneNumber mPhoneNumber; 517 KABC::PhoneNumber mPhoneNumber;
512}; 518};
513 519
514PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) 520PhoneViewItem::PhoneViewItem( Q3ListView *parent, const KABC::PhoneNumber &number )
515 : QListViewItem( parent ), mPhoneNumber( number ) 521 : Q3ListViewItem( parent ), mPhoneNumber( number )
516{ 522{
517#ifdef DESKTOP_VERSION 523#ifdef DESKTOP_VERSION
518 setRenameEnabled ( 0, true ); 524 setRenameEnabled ( 0, true );
519#endif 525#endif
520 makeText(); 526 makeText();
521} 527}
522 528
523void PhoneViewItem::makeText() 529void PhoneViewItem::makeText()
524{ 530{
525 /** 531 /**
526 * Will be used in future versions of kaddressbook/libkabc 532 * Will be used in future versions of kaddressbook/libkabc
527 533
528 setText( 0, mPhoneNumber.country() ); 534 setText( 0, mPhoneNumber.country() );
529 setText( 1, mPhoneNumber.region() ); 535 setText( 1, mPhoneNumber.region() );
530 setText( 2, mPhoneNumber.number() ); 536 setText( 2, mPhoneNumber.number() );
531 setText( 3, mPhoneNumber.typeLabel() ); 537 setText( 3, mPhoneNumber.typeLabel() );
532 */ 538 */
533 539
534 setText( 0, mPhoneNumber.number() ); 540 setText( 0, mPhoneNumber.number() );
535 setText( 1, mPhoneNumber.typeLabel() ); 541 setText( 1, mPhoneNumber.typeLabel() );
536} 542}
537 543
538PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) 544PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name )
539 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), 545 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ),
540 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 546 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
541 parent, name, true) 547 parent, name, true)
542{ 548{
543 mPhoneNumberList = list; 549 mPhoneNumberList = list;
544 550
545 QWidget *page = plainPage(); 551 QWidget *page = plainPage();
546 552
547 QGridLayout *layout = new QGridLayout( page, 1, 2 ); 553 Q3GridLayout *layout = new Q3GridLayout( page, 1, 2 );
548 layout->setSpacing( spacingHint() ); 554 layout->setSpacing( spacingHint() );
549 555
550 mListView = new KListView( page ); 556 mListView = new KListView( page );
551 mListView->setAllColumnsShowFocus( true ); 557 mListView->setAllColumnsShowFocus( true );
552 mListView->addColumn( i18n( "Number" ) ); 558 mListView->addColumn( i18n( "Number" ) );
553 mListView->addColumn( i18n( "Type" ) ); 559 mListView->addColumn( i18n( "Type" ) );
554 560
555 KButtonBox *buttonBox = new KButtonBox( page, Vertical ); 561 KButtonBox *buttonBox = new KButtonBox( page, Qt::Vertical );
556 562
557 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); 563 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) );
558 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); 564 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) );
559 mEditButton->setEnabled( false ); 565 mEditButton->setEnabled( false );
560 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); 566 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) );
561 mRemoveButton->setEnabled( false ); 567 mRemoveButton->setEnabled( false );
562 buttonBox->layout(); 568 buttonBox->layout();
563 569
564 layout->addWidget( mListView, 0, 0 ); 570 layout->addWidget( mListView, 0, 0 );
565 layout->addWidget( buttonBox, 0, 1 ); 571 layout->addWidget( buttonBox, 0, 1 );
566 572
567 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); 573 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) );
568 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); 574 connect( mListView, SIGNAL(doubleClicked( Q3ListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber()));
569 575
570 KABC::PhoneNumber::List::Iterator it; 576 KABC::PhoneNumber::List::Iterator it;
571 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) 577 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
572 new PhoneViewItem( mListView, *it ); 578 new PhoneViewItem( mListView, *it );
573 if (QApplication::desktop()->width() < 480 ) 579 if (QApplication::desktop()->width() < 480 )
574 showMaximized(); 580 showMaximized();
575 else 581 else
576 resize( 400, 400 ); 582 resize( 400, 400 );
577 mChanged = false; 583 mChanged = false;
578} 584}
579 585
580PhoneEditDialog::~PhoneEditDialog() 586PhoneEditDialog::~PhoneEditDialog()
581{ 587{
582 qDebug("PhoneEditDialog::~PhoneEditDialog() "); 588 qDebug("PhoneEditDialog::~PhoneEditDialog() ");
583} 589}
584 590
585void PhoneEditDialog::slotAddPhoneNumber() 591void PhoneEditDialog::slotAddPhoneNumber()
586{ 592{
587 KABC::PhoneNumber tmp( "", 0 ); 593 KABC::PhoneNumber tmp( "", 0 );
588 PhoneTypeDialog dlg( tmp, this ); 594 PhoneTypeDialog dlg( tmp, this );
589 595
590 if ( dlg.exec() ) { 596 if ( dlg.exec() ) {
591 QListViewItem* i = mListView->firstChild(); 597 Q3ListViewItem* i = mListView->firstChild();
592 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 598 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
593 bool insert = true; 599 bool insert = true;
594 while ( i ) { 600 while ( i ) {
595 PhoneViewItem* p = ( PhoneViewItem* ) i; 601 PhoneViewItem* p = ( PhoneViewItem* ) i;
596 KABC::PhoneNumber pn = p->phoneNumber(); 602 KABC::PhoneNumber pn = p->phoneNumber();
597 if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { 603 if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) {
598 if ( p->text(0).isEmpty()) { 604 if ( p->text(0).isEmpty()) {
599 p->setPhoneNumber( phoneNumber ); 605 p->setPhoneNumber( phoneNumber );
600 mPhoneNumberList.remove( pn ); 606 mPhoneNumberList.remove( pn );
601 mPhoneNumberList.append( phoneNumber ); 607 mPhoneNumberList.append( phoneNumber );
602 insert = false; 608 insert = false;
603 break; 609 break;
604 } 610 }
605 } 611 }
606 i = i->nextSibling(); 612 i = i->nextSibling();
607 } 613 }
608 if ( insert ) { 614 if ( insert ) {
609 mPhoneNumberList.append( phoneNumber ); 615 mPhoneNumberList.append( phoneNumber );
610 new PhoneViewItem( mListView, phoneNumber ); 616 new PhoneViewItem( mListView, phoneNumber );
611 } 617 }
612 mChanged = true; 618 mChanged = true;
613 } 619 }
614} 620}
615 621
616void PhoneEditDialog::slotRemovePhoneNumber() 622void PhoneEditDialog::slotRemovePhoneNumber()
617{ 623{
618 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 624 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
619 if ( !item ) 625 if ( !item )
620 return; 626 return;
621 627
622 mPhoneNumberList.remove( item->phoneNumber() ); 628 mPhoneNumberList.remove( item->phoneNumber() );
623 QListViewItem *currItem = mListView->currentItem(); 629 Q3ListViewItem *currItem = mListView->currentItem();
624 mListView->takeItem( currItem ); 630 mListView->takeItem( currItem );
625 delete currItem; 631 delete currItem;
626 632
627 mChanged = true; 633 mChanged = true;
628} 634}
629 635
630void PhoneEditDialog::slotEditPhoneNumber() 636void PhoneEditDialog::slotEditPhoneNumber()
631{ 637{
632 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 638 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
633 if ( !item ) 639 if ( !item )
634 return; 640 return;
635 641
636 PhoneTypeDialog dlg( item->phoneNumber(), this ); 642 PhoneTypeDialog dlg( item->phoneNumber(), this );
637 643
638 if ( dlg.exec() ) { 644 if ( dlg.exec() ) {
639 slotRemovePhoneNumber(); 645 slotRemovePhoneNumber();
640 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 646 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
641 mPhoneNumberList.append( phoneNumber ); 647 mPhoneNumberList.append( phoneNumber );
642 new PhoneViewItem( mListView, phoneNumber ); 648 new PhoneViewItem( mListView, phoneNumber );
643 649
644 mChanged = true; 650 mChanged = true;
645 } 651 }
646} 652}
647 653
@@ -652,80 +658,80 @@ void PhoneEditDialog::slotSelectionChanged()
652 mRemoveButton->setEnabled( state ); 658 mRemoveButton->setEnabled( state );
653 mEditButton->setEnabled( state ); 659 mEditButton->setEnabled( state );
654} 660}
655 661
656const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() 662const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers()
657{ 663{
658 return mPhoneNumberList; 664 return mPhoneNumberList;
659} 665}
660 666
661bool PhoneEditDialog::changed() const 667bool PhoneEditDialog::changed() const
662{ 668{
663 return mChanged; 669 return mChanged;
664} 670}
665 671
666/////////////////////////////////////////// 672///////////////////////////////////////////
667// PhoneTypeDialog 673// PhoneTypeDialog
668PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, 674PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber,
669 QWidget *parent, const char *name) 675 QWidget *parent, const char *name)
670 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), 676 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ),
671 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 677 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
672 parent, name, true), mPhoneNumber( phoneNumber ) 678 parent, name, true), mPhoneNumber( phoneNumber )
673{ 679{
674 QWidget *page = plainPage(); 680 QWidget *page = plainPage();
675 QLabel *label = 0; 681 QLabel *label = 0;
676 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); 682 Q3GridLayout *layout = new Q3GridLayout( page, 3, 2, marginHint(), spacingHint() );
677 683
678 label = new QLabel( i18n( "Number:" ), page ); 684 label = new QLabel( i18n( "Number:" ), page );
679 layout->addWidget( label, 0, 0 ); 685 layout->addWidget( label, 0, 0 );
680 mNumber = new KLineEdit( page ); 686 mNumber = new KLineEdit( page );
681 layout->addWidget( mNumber, 0, 1 ); 687 layout->addWidget( mNumber, 0, 1 );
682 688
683 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); 689 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page );
684 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); 690 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 );
685 691
686 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); 692 mGroup = new Q3ButtonGroup( 2, Qt::Horizontal, i18n( "Types" ), page );
687 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); 693 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 );
688 694
689 // fill widgets 695 // fill widgets
690 mNumber->setText( mPhoneNumber.number() ); 696 mNumber->setText( mPhoneNumber.number() );
691 697
692 mTypeList = KABC::PhoneNumber::typeList(); 698 mTypeList = KABC::PhoneNumber::typeList();
693 mTypeList.remove( KABC::PhoneNumber::Pref ); 699 mTypeList.remove( KABC::PhoneNumber::Pref );
694 700
695 KABC::PhoneNumber::TypeList::Iterator it; 701 KABC::PhoneNumber::TypeList::Iterator it;
696 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) 702 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
697 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); 703 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup );
698 704
699 for ( int i = 0; i < mGroup->count(); ++i ) { 705 for ( int i = 0; i < mGroup->count(); ++i ) {
700 int type = mPhoneNumber.type(); 706 int type = mPhoneNumber.type();
701 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 707 QCheckBox *box = (QCheckBox*)mGroup->find( i );
702 box->setChecked( type & mTypeList[ i ] ); 708 box->setChecked( type & mTypeList[ i ] );
703 } 709 }
704 710
705 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); 711 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref );
706 mNumber->setFocus(); 712 mNumber->setFocus();
707 mNumber->setSelection( 0, 1024); 713 mNumber->setSelection( 0, 1024);
708} 714}
709 715
710KABC::PhoneNumber PhoneTypeDialog::phoneNumber() 716KABC::PhoneNumber PhoneTypeDialog::phoneNumber()
711{ 717{
712 mPhoneNumber.setNumber( mNumber->text() ); 718 mPhoneNumber.setNumber( mNumber->text() );
713 719
714 int type = 0; 720 int type = 0;
715 for ( int i = 0; i < mGroup->count(); ++i ) { 721 for ( int i = 0; i < mGroup->count(); ++i ) {
716 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 722 QCheckBox *box = (QCheckBox*)mGroup->find( i );
717 if ( box->isChecked() ) 723 if ( box->isChecked() )
718 type += mTypeList[ i ]; 724 type += mTypeList[ i ];
719 } 725 }
720 726
721 if ( mPreferredBox->isChecked() ) 727 if ( mPreferredBox->isChecked() )
722 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); 728 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref );
723 else 729 else
724 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); 730 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref );
725 731
726 return mPhoneNumber; 732 return mPhoneNumber;
727} 733}
728#endif 734#endif
729#ifndef KAB_EMBEDDED 735#ifndef KAB_EMBEDDED_
730#include "phoneeditwidget.moc" 736#include "moc_phoneeditwidget.cpp"
731#endif //KAB_EMBEDDED 737#endif //KAB_EMBEDDED