-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 112 | ||||
-rw-r--r-- | kaddressbook/phoneeditwidget.h | 87 |
2 files changed, 187 insertions, 12 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index 2bce39a..b20275d 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp | |||
@@ -1,100 +1,210 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
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 <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 <qlistbox.h> |
31 | #include <qlistview.h> | 31 | #include <qlistview.h> |
32 | #include <qbuttongroup.h> | 32 | #include <qbuttongroup.h> |
33 | #include <qhbox.h> | ||
33 | 34 | ||
34 | #include <kbuttonbox.h> | 35 | #include <kbuttonbox.h> |
35 | #include <klistview.h> | 36 | #include <klistview.h> |
36 | #include <kapplication.h> | 37 | #include <kapplication.h> |
37 | #include <qapplication.h> | 38 | #include <qapplication.h> |
38 | #include <kconfig.h> | 39 | #include <kconfig.h> |
39 | #include <klineedit.h> | 40 | #include <klineedit.h> |
40 | #include <kcombobox.h> | 41 | #include <kcombobox.h> |
41 | #include <klocale.h> | 42 | #include <klocale.h> |
42 | #include <kdebug.h> | 43 | #include <kdebug.h> |
43 | #include <kglobal.h> | 44 | #include <kglobal.h> |
44 | #include <kiconloader.h> | 45 | #include <kiconloader.h> |
45 | 46 | ||
46 | #include <kabc/phonenumber.h> | 47 | #include <kabc/phonenumber.h> |
47 | 48 | ||
48 | #include "typecombo.h" | 49 | #include "typecombo.h" |
49 | 50 | ||
50 | #include "phoneeditwidget.h" | 51 | #include "phoneeditwidget.h" |
51 | 52 | ||
52 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 53 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
54 | : QScrollView(parent,name) | ||
55 | { | ||
56 | setFrameStyle ( QFrame::Panel | QFrame::Plain ); | ||
57 | setLineWidth ( 1 ); | ||
58 | setMidLineWidth ( 1 ); | ||
59 | mw = new QWidget ( viewport() ); | ||
60 | addChild(mw); | ||
61 | setResizePolicy( AutoOneFit ); | ||
62 | mainLayout = new QVBoxLayout ( mw ); | ||
63 | mainLayout->setMargin( 2 ); | ||
64 | mainLayout->setSpacing( 2 ); | ||
65 | QWidget* hb = new QWidget ( mw ); | ||
66 | mainLayout->add( hb ); | ||
67 | QHBoxLayout* hbLayout = new QHBoxLayout ( hb ); | ||
68 | QPushButton *addBut = new QPushButton ( "add", hb ); | ||
69 | hbLayout->add( addBut ); | ||
70 | addBut->setPixmap ( SmallIcon("plus")); | ||
71 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); | ||
72 | connect(addBut,SIGNAL(clicked()),SLOT(addNumber())); | ||
73 | //QLabel * temp = new QLabel( i18n("Phone Type"), hb ); | ||
74 | QLabel *temp = new QLabel( i18n("Phone Number"),hb ); | ||
75 | temp->setAlignment( Qt::AlignCenter ); | ||
76 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | ||
77 | hbLayout->add( temp ); | ||
78 | appendEditCombo(); | ||
79 | appendEditCombo(); | ||
80 | appendEditCombo(); | ||
81 | setDefaults(); | ||
82 | } | ||
83 | |||
84 | PhoneEditWidget::~PhoneEditWidget() | ||
85 | { | ||
86 | } | ||
87 | void PhoneEditWidget::setDefaults() | ||
88 | { | ||
89 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | ||
90 | KABC::PhoneNumber phoneNumber; | ||
91 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); | ||
92 | edit->setPhoneNumber( phoneNumber ); | ||
93 | edit = mTypeNumberEditList.next(); | ||
94 | phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); | ||
95 | edit->setPhoneNumber( phoneNumber ); | ||
96 | edit = mTypeNumberEditList.next(); | ||
97 | phoneNumber.setType( KABC::PhoneNumber::Cell ); | ||
98 | edit->setPhoneNumber( phoneNumber ); | ||
99 | edit = mTypeNumberEditList.next(); | ||
100 | while ( edit ) { | ||
101 | edit->hide(); | ||
102 | edit = mTypeNumberEditList.next(); | ||
103 | } | ||
104 | } | ||
105 | void PhoneEditWidget::addNumber() | ||
106 | { | ||
107 | |||
108 | } | ||
109 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() | ||
110 | { | ||
111 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); | ||
112 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); | ||
113 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); | ||
114 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); | ||
115 | |||
116 | mainLayout->add( edit ); | ||
117 | mTypeNumberEditList.append( edit ); | ||
118 | return edit; | ||
119 | } | ||
120 | |||
121 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) | ||
122 | { | ||
123 | if ( li.isEmpty() ) { | ||
124 | setDefaults(); | ||
125 | return; | ||
126 | } | ||
127 | KABC::PhoneNumber::List::Iterator it; | ||
128 | KABC::PhoneNumber::List list = li; | ||
129 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | ||
130 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
131 | if ( edit ) { | ||
132 | edit->setPhoneNumber( (*it ) ); | ||
133 | edit = mTypeNumberEditList.next(); | ||
134 | } else { | ||
135 | PhoneTypeNumberEdit* editNew = appendEditCombo(); | ||
136 | editNew->setPhoneNumber( (*it ) ); | ||
137 | } | ||
138 | } | ||
139 | while ( edit ) { | ||
140 | edit->hide(); | ||
141 | edit = mTypeNumberEditList.next(); | ||
142 | } | ||
143 | //mainLayout->invalidate (); | ||
144 | mw->update(); | ||
145 | } | ||
146 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | ||
147 | { | ||
148 | KABC::PhoneNumber::List retList; | ||
149 | |||
150 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | ||
151 | while ( edit ) { | ||
152 | if ( edit->isValid() ) { | ||
153 | retList.append( edit->phoneNumber()); | ||
154 | } | ||
155 | edit = mTypeNumberEditList.next(); | ||
156 | |||
157 | } | ||
158 | return retList; | ||
159 | } | ||
160 | |||
161 | #if 0 | ||
162 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | ||
53 | : QWidget( parent, name ) | 163 | : QWidget( parent, name ) |
54 | { | 164 | { |
55 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); | 165 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); |
56 | //US layout->setSpacing( KDialog::spacingHint() ); | 166 | //US layout->setSpacing( KDialog::spacingHint() ); |
57 | layout->setSpacing( KDialogBase::spacingHintSmall() ); | 167 | layout->setSpacing( KDialogBase::spacingHintSmall() ); |
58 | 168 | ||
59 | 169 | ||
60 | 170 | ||
61 | QLabel* label = new QLabel( this ); | 171 | QLabel* label = new QLabel( this ); |
62 | //US loadIcon call is ambiguous. Add one more parameter | 172 | //US loadIcon call is ambiguous. Add one more parameter |
63 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); | 173 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); |
64 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | 174 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
65 | label->setAlignment( AlignCenter ); | 175 | label->setAlignment( AlignCenter ); |
66 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); | 176 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); |
67 | layout->addWidget( label, 0, 0 ); | 177 | layout->addWidget( label, 0, 0 ); |
68 | 178 | ||
69 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), | 179 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), |
70 | this ); | 180 | this ); |
71 | if ( QApplication::desktop()->width() < 640 ) | 181 | if ( QApplication::desktop()->width() < 640 ) |
72 | layout->addWidget( editButton, 0, 1 ); | 182 | layout->addWidget( editButton, 0, 1 ); |
73 | else | 183 | else |
74 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); | 184 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); |
75 | 185 | ||
76 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); | 186 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); |
77 | mPrefEdit = new KLineEdit( this ); | 187 | mPrefEdit = new KLineEdit( this ); |
78 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); | 188 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); |
79 | mPrefCombo->setLineEdit( mPrefEdit ); | 189 | mPrefCombo->setLineEdit( mPrefEdit ); |
80 | layout->addWidget( mPrefCombo, 1, 0 ); | 190 | layout->addWidget( mPrefCombo, 1, 0 ); |
81 | layout->addWidget( mPrefEdit, 1, 1 ); | 191 | layout->addWidget( mPrefEdit, 1, 1 ); |
82 | int x = 1, y = 2; | 192 | int x = 1, y = 2; |
83 | if ( QApplication::desktop()->width() < 640 ) { | 193 | if ( QApplication::desktop()->width() < 640 ) { |
84 | ++x; | 194 | ++x; |
85 | y = 0; | 195 | y = 0; |
86 | } | 196 | } |
87 | mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); | 197 | mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); |
88 | mSecondEdit = new KLineEdit( this ); | 198 | mSecondEdit = new KLineEdit( this ); |
89 | mSecondCombo->setLineEdit( mSecondEdit ); | 199 | mSecondCombo->setLineEdit( mSecondEdit ); |
90 | layout->addWidget( mSecondCombo, x, y++ ); | 200 | layout->addWidget( mSecondCombo, x, y++ ); |
91 | layout->addWidget( mSecondEdit, x, y++ ); | 201 | layout->addWidget( mSecondEdit, x, y++ ); |
92 | 202 | ||
93 | y = 0; | 203 | y = 0; |
94 | ++x; | 204 | ++x; |
95 | mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); | 205 | mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); |
96 | mThirdEdit = new KLineEdit( this ); | 206 | mThirdEdit = new KLineEdit( this ); |
97 | mThirdCombo->setLineEdit( mThirdEdit ); | 207 | mThirdCombo->setLineEdit( mThirdEdit ); |
98 | layout->addWidget( mThirdCombo, x, y++ ); | 208 | layout->addWidget( mThirdCombo, x, y++ ); |
99 | layout->addWidget( mThirdEdit, x, y++ ); | 209 | layout->addWidget( mThirdEdit, x, y++ ); |
100 | if ( QApplication::desktop()->width() < 640 ) { | 210 | if ( QApplication::desktop()->width() < 640 ) { |
@@ -505,52 +615,52 @@ PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, | |||
505 | mNumber = new KLineEdit( page ); | 615 | mNumber = new KLineEdit( page ); |
506 | layout->addWidget( mNumber, 0, 1 ); | 616 | layout->addWidget( mNumber, 0, 1 ); |
507 | 617 | ||
508 | mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); | 618 | mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); |
509 | layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); | 619 | layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); |
510 | 620 | ||
511 | mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); | 621 | mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); |
512 | layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); | 622 | layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); |
513 | 623 | ||
514 | // fill widgets | 624 | // fill widgets |
515 | mNumber->setText( mPhoneNumber.number() ); | 625 | mNumber->setText( mPhoneNumber.number() ); |
516 | 626 | ||
517 | mTypeList = KABC::PhoneNumber::typeList(); | 627 | mTypeList = KABC::PhoneNumber::typeList(); |
518 | mTypeList.remove( KABC::PhoneNumber::Pref ); | 628 | mTypeList.remove( KABC::PhoneNumber::Pref ); |
519 | 629 | ||
520 | KABC::PhoneNumber::TypeList::Iterator it; | 630 | KABC::PhoneNumber::TypeList::Iterator it; |
521 | for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) | 631 | for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) |
522 | new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); | 632 | new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); |
523 | 633 | ||
524 | for ( int i = 0; i < mGroup->count(); ++i ) { | 634 | for ( int i = 0; i < mGroup->count(); ++i ) { |
525 | int type = mPhoneNumber.type(); | 635 | int type = mPhoneNumber.type(); |
526 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); | 636 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); |
527 | box->setChecked( type & mTypeList[ i ] ); | 637 | box->setChecked( type & mTypeList[ i ] ); |
528 | } | 638 | } |
529 | 639 | ||
530 | mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); | 640 | mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); |
531 | mNumber->setFocus(); | 641 | mNumber->setFocus(); |
532 | mNumber->setSelection( 0, 1024); | 642 | mNumber->setSelection( 0, 1024); |
533 | } | 643 | } |
534 | 644 | ||
535 | KABC::PhoneNumber PhoneTypeDialog::phoneNumber() | 645 | KABC::PhoneNumber PhoneTypeDialog::phoneNumber() |
536 | { | 646 | { |
537 | mPhoneNumber.setNumber( mNumber->text() ); | 647 | mPhoneNumber.setNumber( mNumber->text() ); |
538 | 648 | ||
539 | int type = 0; | 649 | int type = 0; |
540 | for ( int i = 0; i < mGroup->count(); ++i ) { | 650 | for ( int i = 0; i < mGroup->count(); ++i ) { |
541 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); | 651 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); |
542 | if ( box->isChecked() ) | 652 | if ( box->isChecked() ) |
543 | type += mTypeList[ i ]; | 653 | type += mTypeList[ i ]; |
544 | } | 654 | } |
545 | 655 | ||
546 | if ( mPreferredBox->isChecked() ) | 656 | if ( mPreferredBox->isChecked() ) |
547 | mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); | 657 | mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); |
548 | else | 658 | else |
549 | mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); | 659 | mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); |
550 | 660 | ||
551 | return mPhoneNumber; | 661 | return mPhoneNumber; |
552 | } | 662 | } |
553 | 663 | #endif | |
554 | #ifndef KAB_EMBEDDED | 664 | #ifndef KAB_EMBEDDED |
555 | #include "phoneeditwidget.moc" | 665 | #include "phoneeditwidget.moc" |
556 | #endif //KAB_EMBEDDED | 666 | #endif //KAB_EMBEDDED |
diff --git a/kaddressbook/phoneeditwidget.h b/kaddressbook/phoneeditwidget.h index 0241cf0..6a514ed 100644 --- a/kaddressbook/phoneeditwidget.h +++ b/kaddressbook/phoneeditwidget.h | |||
@@ -1,222 +1,287 @@ | |||
1 | #ifndef PHONEEDITWIDGET_H | 1 | #ifndef PHONEEDITWIDGET_H |
2 | #define PHONEEDITWIDGET_H | 2 | #define PHONEEDITWIDGET_H |
3 | /* | 3 | /* |
4 | This file is part of KAddressBook. | 4 | This file is part of KAddressBook. |
5 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 5 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
6 | 6 | ||
7 | This program is free software; you can redistribute it and/or modify | 7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or | 9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | 10 | (at your option) any later version. |
11 | 11 | ||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | 18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 | 20 | ||
21 | As a special exception, permission is given to link this program | 21 | As a special exception, permission is given to link this program |
22 | with any edition of Qt, and distribute the resulting executable, | 22 | with any edition of Qt, and distribute the resulting executable, |
23 | without including the source code for Qt in the source distribution. | 23 | without including the source code for Qt in the source distribution. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <kdialogbase.h> | 26 | #include <kdialogbase.h> |
27 | #include <kiconloader.h> | 27 | #include <kiconloader.h> |
28 | #include <qpushbutton.h> | 28 | #include <qpushbutton.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | 30 | ||
31 | #include <qptrlist.h> | ||
32 | #include <qscrollview.h> | ||
31 | 33 | ||
32 | #include "addresseeconfig.h" | 34 | #include "addresseeconfig.h" |
33 | #include "typecombo.h" | 35 | #include "typecombo.h" |
34 | 36 | ||
35 | class QButtonGroup; | 37 | class QButtonGroup; |
36 | class QCheckBox; | 38 | class QCheckBox; |
39 | class PhoneTypeNumberEdit; | ||
37 | 40 | ||
38 | #include <klineedit.h> | 41 | #include <klineedit.h> |
39 | #include <kcombobox.h> | 42 | #include <kcombobox.h> |
40 | class KListView; | 43 | #include <kabc/phonenumber.h> |
41 | 44 | ||
42 | typedef TypeCombo<KABC::PhoneNumber> PhoneTypeCombo; | 45 | typedef TypeCombo<KABC::PhoneNumber> PhoneTypeCombo; |
43 | 46 | ||
44 | /** | 47 | /** |
45 | Widget for editing phone numbers. | 48 | Widget for editing phone numbers. |
46 | */ | 49 | */ |
47 | class PhoneEditWidget : public QWidget | 50 | class PhoneEditWidget : public QScrollView |
48 | { | 51 | { |
49 | Q_OBJECT | 52 | Q_OBJECT |
50 | 53 | ||
51 | public: | 54 | public: |
52 | PhoneEditWidget( QWidget *parent, const char *name = 0 ); | 55 | PhoneEditWidget( QWidget *parent, const char *name = 0 ); |
53 | ~PhoneEditWidget(); | 56 | ~PhoneEditWidget(); |
54 | 57 | ||
55 | void setPhoneNumbers( const KABC::PhoneNumber::List &list ); | 58 | void setPhoneNumbers( const KABC::PhoneNumber::List &list ); |
56 | KABC::PhoneNumber::List phoneNumbers(); | 59 | KABC::PhoneNumber::List phoneNumbers(); |
57 | 60 | ||
58 | void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* ); | 61 | // void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* ); |
59 | KABC::PhoneNumber currentPhoneNumber( KComboBox*, int ); | 62 | //KABC::PhoneNumber currentPhoneNumber( KComboBox*, int ); |
60 | 63 | ||
61 | signals: | 64 | signals: |
62 | void modified(); | 65 | void modified(); |
66 | void typeChange( int oldType, int newType ); | ||
63 | 67 | ||
64 | private slots: | 68 | private slots: |
69 | void addNumber(); | ||
70 | protected: | ||
71 | |||
72 | private: | ||
73 | void setDefaults(); | ||
74 | PhoneTypeNumberEdit* appendEditCombo(); | ||
75 | QWidget* mw; | ||
76 | QVBoxLayout* mainLayout; | ||
77 | QPtrList <PhoneTypeNumberEdit> mTypeNumberEditList; | ||
78 | |||
79 | KABC::PhoneNumber::List mPhoneList; | ||
80 | }; | ||
81 | |||
82 | |||
83 | |||
84 | |||
85 | |||
86 | #if 0 | ||
87 | class PhoneEditWidget : public QWidget | ||
88 | { | ||
89 | Q___OBJECT | ||
90 | |||
91 | public: | ||
92 | PhoneEditWidget( QWidget *parent, const char *name = 0 ); | ||
93 | ~PhoneEditWidget(); | ||
94 | |||
95 | void setPhoneNumbers( const KABC::PhoneNumber::List &list ); | ||
96 | KABC::PhoneNumber::List phoneNumbers(); | ||
97 | |||
98 | void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* ); | ||
99 | KABC::PhoneNumber currentPhoneNumber( KComboBox*, int ); | ||
100 | |||
101 | sig_nals: | ||
102 | void modified(); | ||
103 | void typeChange( int oldType, int newType ); | ||
104 | |||
105 | private sl_ots: | ||
65 | void edit(); | 106 | void edit(); |
66 | 107 | ||
67 | void updatePrefEdit(); | 108 | void updatePrefEdit(); |
68 | void updateSecondEdit(); | 109 | void updateSecondEdit(); |
69 | void updateThirdEdit(); | 110 | void updateThirdEdit(); |
70 | void updateFourthEdit(); | 111 | void updateFourthEdit(); |
71 | 112 | ||
72 | void slotPrefEditChanged(); | 113 | void slotPrefEditChanged(); |
73 | void slotSecondEditChanged(); | 114 | void slotSecondEditChanged(); |
74 | void slotThirdEditChanged(); | 115 | void slotThirdEditChanged(); |
75 | void slotFourthEditChanged(); | 116 | void slotFourthEditChanged(); |
76 | 117 | ||
77 | protected: | 118 | protected: |
78 | void updateLineEdits(); | 119 | void updateLineEdits(); |
79 | void updateCombos(); | 120 | void updateCombos(); |
80 | 121 | ||
81 | private: | 122 | private: |
123 | QPtrList <PhoneTypeNumberEdit> mTypeNumberEditList; | ||
82 | void updateEdit( PhoneTypeCombo *combo ); | 124 | void updateEdit( PhoneTypeCombo *combo ); |
83 | void updatePhoneNumber( PhoneTypeCombo *combo ); | 125 | void updatePhoneNumber( PhoneTypeCombo *combo ); |
84 | void updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ); | 126 | void updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ); |
85 | 127 | ||
86 | PhoneTypeCombo *mPrefCombo; | 128 | PhoneTypeCombo *mPrefCombo; |
87 | PhoneTypeCombo *mSecondCombo; | 129 | PhoneTypeCombo *mSecondCombo; |
88 | PhoneTypeCombo *mThirdCombo; | 130 | PhoneTypeCombo *mThirdCombo; |
89 | PhoneTypeCombo *mFourthCombo; | 131 | PhoneTypeCombo *mFourthCombo; |
90 | 132 | ||
91 | KLineEdit *mPrefEdit; | 133 | KLineEdit *mPrefEdit; |
92 | KLineEdit *mSecondEdit; | 134 | KLineEdit *mSecondEdit; |
93 | KLineEdit *mThirdEdit; | 135 | KLineEdit *mThirdEdit; |
94 | KLineEdit *mFourthEdit; | 136 | KLineEdit *mFourthEdit; |
95 | 137 | ||
96 | KABC::PhoneNumber::List mPhoneList; | 138 | KABC::PhoneNumber::List mPhoneList; |
97 | }; | 139 | }; |
98 | 140 | ||
99 | /** | 141 | /** |
100 | Dialog for editing lists of phonenumbers. | 142 | Dialog for editing lists of phonenumbers. |
101 | */ | 143 | */ |
102 | class PhoneEditDialog : public KDialogBase | 144 | class PhoneEditDialog : public KDialogBase |
103 | { | 145 | { |
104 | Q_OBJECT | 146 | Q___OBJECT |
105 | 147 | ||
106 | public: | 148 | public: |
107 | PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name = 0 ); | 149 | PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name = 0 ); |
108 | ~PhoneEditDialog(); | 150 | ~PhoneEditDialog(); |
109 | 151 | ||
110 | const KABC::PhoneNumber::List &phoneNumbers(); | 152 | const KABC::PhoneNumber::List &phoneNumbers(); |
111 | bool changed() const; | 153 | bool changed() const; |
112 | 154 | ||
113 | protected slots: | 155 | protected s__lots: |
114 | void slotAddPhoneNumber(); | 156 | void slotAddPhoneNumber(); |
115 | void slotRemovePhoneNumber(); | 157 | void slotRemovePhoneNumber(); |
116 | void slotEditPhoneNumber(); | 158 | void slotEditPhoneNumber(); |
117 | void slotSelectionChanged(); | 159 | void slotSelectionChanged(); |
118 | 160 | ||
119 | private: | 161 | private: |
120 | KABC::PhoneNumber::List mPhoneNumberList; | 162 | KABC::PhoneNumber::List mPhoneNumberList; |
121 | KABC::PhoneNumber::TypeList mTypeList; | 163 | KABC::PhoneNumber::TypeList mTypeList; |
122 | KComboBox *mTypeBox; | 164 | KComboBox *mTypeBox; |
123 | KListView *mListView; | 165 | KListView *mListView; |
124 | 166 | ||
125 | QPushButton *mRemoveButton; | 167 | QPushButton *mRemoveButton; |
126 | QPushButton *mEditButton; | 168 | QPushButton *mEditButton; |
127 | 169 | ||
128 | bool mChanged; | 170 | bool mChanged; |
129 | }; | 171 | }; |
130 | 172 | ||
131 | /** | 173 | /** |
132 | Dialog for editing phone number types. | 174 | Dialog for editing phone number types. |
133 | */ | 175 | */ |
134 | class PhoneTypeDialog : public KDialogBase | 176 | class PhoneTypeDialog : public KDialogBase |
135 | { | 177 | { |
136 | Q_OBJECT | 178 | Q___OBJECT |
137 | public: | 179 | public: |
138 | PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, QWidget *parent, const char *name = 0 ); | 180 | PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, QWidget *parent, const char *name = 0 ); |
139 | 181 | ||
140 | KABC::PhoneNumber phoneNumber(); | 182 | KABC::PhoneNumber phoneNumber(); |
141 | 183 | ||
142 | private: | 184 | private: |
143 | KABC::PhoneNumber mPhoneNumber; | 185 | KABC::PhoneNumber mPhoneNumber; |
144 | KABC::PhoneNumber::TypeList mTypeList; | 186 | KABC::PhoneNumber::TypeList mTypeList; |
145 | 187 | ||
146 | QButtonGroup *mGroup; | 188 | QButtonGroup *mGroup; |
147 | QCheckBox *mPreferredBox; | 189 | QCheckBox *mPreferredBox; |
148 | KLineEdit *mNumber; | 190 | KLineEdit *mNumber; |
149 | }; | 191 | }; |
192 | #endif | ||
193 | |||
150 | class PhoneTypeNumberEdit : public QWidget | 194 | class PhoneTypeNumberEdit : public QWidget |
151 | { | 195 | { |
152 | Q_OBJECT | 196 | Q_OBJECT |
153 | public: | 197 | public: |
154 | PhoneTypeNumberEdit( QWidget *parent, const char *name = 0 ) | 198 | PhoneTypeNumberEdit( QWidget *parent, const char *name = 0 ) :QWidget( parent ) |
155 | { | 199 | { |
156 | QHBoxLayout * lay = new QHBoxLayout( this ); | 200 | QHBoxLayout * lay = new QHBoxLayout( this ); |
157 | lay->setSpacing( KDialogBase::spacingHintSmall() ); | 201 | lay->setSpacing( KDialogBase::spacingHintSmall() ); |
158 | lay->setMargin( KDialogBase::marginHintSmall() ); | 202 | lay->setMargin( KDialogBase::marginHintSmall() ); |
159 | mMinusButton = new QPushButton ( this ); | 203 | mMinusButton = new QPushButton ( this ); |
160 | mMinusButton->setPixmap ( SmallIcon("minus")); | 204 | mMinusButton->setPixmap ( SmallIcon("minus")); |
161 | mCombo = new KComboBox( this ); | 205 | mCombo = new KComboBox( this ); |
162 | mNumber = new KLineEdit( this ); | 206 | mNumber = new KLineEdit( this ); |
163 | lay->addWidget( mMinusButton ); | 207 | lay->addWidget( mMinusButton ); |
164 | lay->addWidget( mCombo ); | 208 | lay->addWidget( mCombo ); |
165 | lay->addWidget( mNumber ); | 209 | lay->addWidget( mNumber ); |
166 | connect( mMinusButton , SIGNAL ( clicked() ), this, SLOT ( deleteNumber() ) ); | 210 | connect( mMinusButton , SIGNAL ( clicked() ), this, SLOT ( deleteNumber() ) ); |
167 | connect( mCombo , SIGNAL ( activated ( int ) ), this, SLOT ( comboTypeChange( int ) ) ); | 211 | connect( mCombo , SIGNAL ( activated ( int ) ), this, SLOT ( comboTypeChange( int ) ) ); |
212 | connect( mNumber , SIGNAL ( textChanged ( const QString & ) ), | ||
213 | this, SLOT ( textChanged ( const QString & ) ) ); | ||
168 | mCombo->insertStringList( PhoneNumber::supportedTypeListNames() ); | 214 | mCombo->insertStringList( PhoneNumber::supportedTypeListNames() ); |
215 | mIsValid = true; | ||
169 | } | 216 | } |
170 | 217 | ||
171 | void setPhoneNumber( const KABC::PhoneNumber &phoneNumber ) | 218 | void setPhoneNumber( const KABC::PhoneNumber &phoneNumber ) |
172 | { | 219 | { |
173 | mPhoneNumber = phoneNumber; | 220 | mPhoneNumber = phoneNumber; |
174 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); | 221 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); |
175 | mCombo->setCurrentItem( index ); | 222 | mCombo->setCurrentItem( index ); |
176 | mNumber->setText( mPhoneNumber.number() ); | 223 | mNumber->setText( mPhoneNumber.number() ); |
224 | mIsValid = true; | ||
177 | show(); | 225 | show(); |
178 | 226 | ||
179 | } | 227 | } |
180 | KABC::PhoneNumber phoneNumber() | 228 | KABC::PhoneNumber phoneNumber() |
181 | { | 229 | { |
182 | mPhoneNumber.setNumber( mNumber->text() ); | 230 | mPhoneNumber.setNumber( mNumber->text() ); |
183 | int index = mCombo->currentItem(); | 231 | int index = mCombo->currentItem(); |
184 | mPhoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); | 232 | mPhoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); |
185 | return mPhoneNumber; | 233 | return mPhoneNumber; |
186 | |||
187 | } | 234 | } |
235 | bool isValid() | ||
236 | { | ||
237 | if ( !mIsValid ) return false; | ||
238 | if ( mNumber->text().isEmpty() )return false; | ||
239 | return true; | ||
240 | } | ||
188 | private slots: | 241 | private slots: |
189 | void typeExternalChanged( int oldType, int newType ) | 242 | void typeExternalChanged( int oldType, int newType ) |
190 | { | 243 | { |
191 | if ( mPhoneNumber.type() == newType ) { | 244 | if ( mPhoneNumber.type() == newType ) { |
192 | mPhoneNumber.setType(oldType); | 245 | mPhoneNumber.setType(oldType); |
193 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); | 246 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); |
194 | mCombo->setCurrentItem( index ); | 247 | mCombo->setCurrentItem( index ); |
195 | } | 248 | } |
196 | |||
197 | } | 249 | } |
198 | void deleteNumber() | 250 | void deleteNumber() |
199 | { | 251 | { |
252 | emit modified(); | ||
200 | hide(); | 253 | hide(); |
254 | mIsValid = false; | ||
201 | } | 255 | } |
202 | void comboTypeChange( int index ) | 256 | void comboTypeChange( int index ) |
203 | { | 257 | { |
204 | int old = mPhoneNumber.type(); | 258 | int old = mPhoneNumber.type(); |
205 | int newT = PhoneNumber::supportedTypeList()[index]; | 259 | int newT = PhoneNumber::supportedTypeList()[index]; |
206 | if ( old != newT ) { | 260 | if ( old != newT ) { |
207 | mPhoneNumber.setType(newT ); | 261 | emit modified(); |
208 | emit typeChange ( old, newT ); | 262 | emit typeChange ( old, newT ); |
263 | mPhoneNumber.setType(newT ); | ||
209 | } | 264 | } |
210 | 265 | ||
211 | } | 266 | } |
267 | int currentType() | ||
268 | { | ||
269 | return mCombo->currentItem(); | ||
270 | } | ||
271 | void textChanged ( const QString & ) | ||
272 | { | ||
273 | emit modified(); | ||
274 | } | ||
212 | signals: | 275 | signals: |
213 | void typeChange( int oldType, int newType ); | 276 | void typeChange( int oldType, int newType ); |
277 | void modified(); | ||
214 | 278 | ||
215 | private: | 279 | private: |
280 | bool mIsValid; | ||
216 | KABC::PhoneNumber mPhoneNumber; | 281 | KABC::PhoneNumber mPhoneNumber; |
217 | QPushButton* mMinusButton; | 282 | QPushButton* mMinusButton; |
218 | KComboBox *mCombo; | 283 | KComboBox *mCombo; |
219 | KLineEdit *mNumber; | 284 | KLineEdit *mNumber; |
220 | }; | 285 | }; |
221 | 286 | ||
222 | #endif | 287 | #endif |