author | zautrix <zautrix> | 2005-10-28 14:43:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-10-28 14:43:31 (UTC) |
commit | ab099bc1be027fe01dc252a9d7a0f8821e782d65 (patch) (unidiff) | |
tree | 85bfb03f334da60dffcc52d54202f51d0f947e3f /kaddressbook/phoneeditwidget.cpp | |
parent | caaa030d8bc2aa82c53e5d30abc314b992d7226f (diff) | |
download | kdepimpi-ab099bc1be027fe01dc252a9d7a0f8821e782d65.zip kdepimpi-ab099bc1be027fe01dc252a9d7a0f8821e782d65.tar.gz kdepimpi-ab099bc1be027fe01dc252a9d7a0f8821e782d65.tar.bz2 |
fixxxx
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index 9e7e221..66f0a5e 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp | |||
@@ -1,442 +1,451 @@ | |||
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 | #include <qhbox.h> |
34 | #include <qcursor.h> | 34 | #include <qcursor.h> |
35 | 35 | ||
36 | #include <kbuttonbox.h> | 36 | #include <kbuttonbox.h> |
37 | #include <klistview.h> | 37 | #include <klistview.h> |
38 | #include <kapplication.h> | 38 | #include <kapplication.h> |
39 | #include <qapplication.h> | 39 | #include <qapplication.h> |
40 | #include <kconfig.h> | 40 | #include <kconfig.h> |
41 | #include <klineedit.h> | 41 | #include <klineedit.h> |
42 | #include <kcombobox.h> | 42 | #include <kcombobox.h> |
43 | #include <klocale.h> | 43 | #include <klocale.h> |
44 | #include <kdebug.h> | 44 | #include <kdebug.h> |
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <kiconloader.h> | 46 | #include <kiconloader.h> |
47 | 47 | ||
48 | #include <kabc/phonenumber.h> | 48 | #include <kabc/phonenumber.h> |
49 | 49 | ||
50 | #include "typecombo.h" | 50 | #include "typecombo.h" |
51 | 51 | ||
52 | #include "phoneeditwidget.h" | 52 | #include "phoneeditwidget.h" |
53 | 53 | ||
54 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 54 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
55 | : QWidget(parent,name) | 55 | : QWidget(parent,name) |
56 | { | 56 | { |
57 | QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); | 57 | QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); |
58 | 58 | ||
59 | QLabel *temp = new QLabel( "", this ); | 59 | QLabel *temp = new QLabel( "", this ); |
60 | temp->setAlignment( Qt::AlignCenter ); | 60 | temp->setAlignment( Qt::AlignCenter ); |
61 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | 61 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
62 | gridLayout->addWidget( temp, 1, 0 ); | 62 | gridLayout->addWidget( temp, 1, 0 ); |
63 | QPushButton *addBut = new QPushButton ( "add", this ); | 63 | QPushButton *addBut = new QPushButton ( "add", this ); |
64 | addBut->setPixmap ( SmallIcon("plus")); | 64 | addBut->setPixmap ( SmallIcon("plus")); |
65 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); | 65 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); |
66 | connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); | 66 | connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); |
67 | gridLayout->addWidget( addBut, 0, 0 ); | 67 | gridLayout->addWidget( addBut, 0, 0 ); |
68 | 68 | ||
69 | sv = new QScrollView( this ); | 69 | sv = new QScrollView( this ); |
70 | sv->setFrameStyle ( QFrame::Panel | QFrame::Plain ); | 70 | sv->setFrameStyle ( QFrame::Panel | QFrame::Plain ); |
71 | sv->setLineWidth ( 1 ); | 71 | sv->setLineWidth ( 1 ); |
72 | sv->setMidLineWidth ( 1 ); | 72 | sv->setMidLineWidth ( 1 ); |
73 | mw = new QWidget ( sv->viewport() ); | 73 | mw = new QWidget ( sv->viewport() ); |
74 | sv->addChild(mw); | 74 | sv->addChild(mw); |
75 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 75 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
76 | mainLayout = new QVBoxLayout ( mw ); | 76 | mainLayout = new QVBoxLayout ( mw ); |
77 | mainLayout->setMargin( 2 ); | 77 | mainLayout->setMargin( 2 ); |
78 | mainLayout->setSpacing( 2 ); | 78 | mainLayout->setSpacing( 2 ); |
79 | gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); | 79 | gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); |
80 | setDefaults(); | 80 | setDefaults(); |
81 | mTypeNumberEditList.setAutoDelete( true ); | 81 | mTypeNumberEditList.setAutoDelete( true ); |
82 | mPopup = new QPopupMenu( this ); | 82 | mPopup = new QPopupMenu( this ); |
83 | QStringList list = PhoneNumber::supportedTypeListNames(); | 83 | QStringList list = PhoneNumber::supportedTypeListNames(); |
84 | mPopupCount = list.count(); | 84 | mPopupCount = list.count(); |
85 | int i = 0; | 85 | int i = 0; |
86 | while ( i < mPopupCount ) { | 86 | while ( i < mPopupCount ) { |
87 | mPopup->insertItem( list[ i ], i ); | 87 | mPopup->insertItem( list[ i ], i ); |
88 | ++i; | 88 | ++i; |
89 | } | 89 | } |
90 | connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); | 90 | connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); |
91 | 91 | ||
92 | } | 92 | } |
93 | 93 | ||
94 | PhoneEditWidget::~PhoneEditWidget() | 94 | PhoneEditWidget::~PhoneEditWidget() |
95 | { | 95 | { |
96 | } | 96 | } |
97 | void PhoneEditWidget::setDefaults() | 97 | void PhoneEditWidget::setDefaults() |
98 | { | 98 | { |
99 | mTypeNumberEditList.clear(); | 99 | mTypeNumberEditList.clear(); |
100 | PhoneTypeNumberEdit* edit = appendEditCombo(); | 100 | PhoneTypeNumberEdit* edit = appendEditCombo(); |
101 | KABC::PhoneNumber phoneNumber; | 101 | KABC::PhoneNumber phoneNumber; |
102 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); | 102 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); |
103 | edit->setPhoneNumber( phoneNumber ); | 103 | edit->setPhoneNumber( phoneNumber ); |
104 | edit = appendEditCombo(); | 104 | edit = appendEditCombo(); |
105 | phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); | 105 | phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); |
106 | edit->setPhoneNumber( phoneNumber ); | 106 | edit->setPhoneNumber( phoneNumber ); |
107 | edit = appendEditCombo(); | 107 | edit = appendEditCombo(); |
108 | phoneNumber.setType( KABC::PhoneNumber::Cell ); | 108 | phoneNumber.setType( KABC::PhoneNumber::Cell ); |
109 | edit->setPhoneNumber( phoneNumber ); | 109 | edit->setPhoneNumber( phoneNumber ); |
110 | 110 | ||
111 | } | 111 | } |
112 | void PhoneEditWidget::addNumberInt( int index ) | 112 | void PhoneEditWidget::addNumberInt( int index ) |
113 | { | 113 | { |
114 | PhoneTypeNumberEdit* edit = appendEditCombo(); | 114 | PhoneTypeNumberEdit* edit = appendEditCombo(); |
115 | KABC::PhoneNumber phoneNumber; | 115 | KABC::PhoneNumber phoneNumber; |
116 | phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); | 116 | phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); |
117 | edit->setPhoneNumber( phoneNumber ); | 117 | edit->setPhoneNumber( phoneNumber ); |
118 | //verticalScrollBar()->setValue( 1024); | 118 | //verticalScrollBar()->setValue( 1024); |
119 | QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); | 119 | QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); |
120 | } | 120 | } |
121 | void PhoneEditWidget::bottomVisible() | 121 | void PhoneEditWidget::bottomVisible() |
122 | { | 122 | { |
123 | sv->setContentsPos ( 0, 1024 ); | 123 | sv->setContentsPos ( 0, 1024 ); |
124 | } | 124 | } |
125 | void PhoneEditWidget::addNumber() | 125 | void PhoneEditWidget::addNumber() |
126 | { | 126 | { |
127 | int i = 0; | 127 | int i = 0; |
128 | while ( i < mPopupCount ) { | 128 | while ( i < mPopupCount ) { |
129 | mPopup->setItemEnabled( i, true ); | 129 | mPopup->setItemEnabled( i, true ); |
130 | ++i; | 130 | ++i; |
131 | } | 131 | } |
132 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | 132 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); |
133 | while ( edit ) { | 133 | while ( edit ) { |
134 | if ( edit->currentType() < mPopupCount -1 ) | 134 | if ( edit->currentType() < mPopupCount -1 ) |
135 | mPopup->setItemEnabled( edit->currentType(), false ); | 135 | mPopup->setItemEnabled( edit->currentType(), false ); |
136 | edit = mTypeNumberEditList.next(); | 136 | edit = mTypeNumberEditList.next(); |
137 | } | 137 | } |
138 | mPopup->popup( QCursor::pos() ); | 138 | mPopup->popup( QCursor::pos() ); |
139 | } | 139 | } |
140 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() | 140 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() |
141 | { | 141 | { |
142 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); | 142 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); |
143 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); | 143 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); |
144 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); | 144 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); |
145 | connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); | 145 | connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); |
146 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); | 146 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); |
147 | 147 | ||
148 | mainLayout->add( edit ); | 148 | mainLayout->add( edit ); |
149 | mTypeNumberEditList.append( edit ); | 149 | mTypeNumberEditList.append( edit ); |
150 | return edit; | 150 | return edit; |
151 | } | 151 | } |
152 | 152 | ||
153 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) | 153 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) |
154 | { | 154 | { |
155 | mPendingDelete = ew; | 155 | mPendingDelete = ew; |
156 | QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); | 156 | QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); |
157 | } | 157 | } |
158 | void PhoneEditWidget::pendingDelete() | 158 | void PhoneEditWidget::pendingDelete() |
159 | { | 159 | { |
160 | mTypeNumberEditList.removeRef( mPendingDelete ); | 160 | mTypeNumberEditList.removeRef( mPendingDelete ); |
161 | emit modified(); | 161 | emit modified(); |
162 | } | 162 | } |
163 | 163 | ||
164 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) | 164 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) |
165 | { | 165 | { |
166 | if ( li.isEmpty() ) { | 166 | if ( li.isEmpty() ) { |
167 | setDefaults(); | 167 | setDefaults(); |
168 | return; | 168 | return; |
169 | } | 169 | } |
170 | mTypeNumberEditList.clear(); | 170 | mTypeNumberEditList.clear(); |
171 | KABC::PhoneNumber::List::Iterator it; | 171 | KABC::PhoneNumber::List::Iterator it; |
172 | KABC::PhoneNumber::List list = li; | 172 | KABC::PhoneNumber::List list2 = li; |
173 | PhoneTypeNumberEdit* edit = 0;//mTypeNumberEditList.first(); | 173 | KABC::PhoneNumber::List list ; |
174 | |||
175 | PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList(); | ||
176 | int i = 0; | ||
177 | int max = tList.count(); | ||
178 | while ( i < max-1 ) { | ||
179 | for ( it = list2.begin(); it != list2.end(); ++it ) { | ||
180 | if ( (*it).type() == tList[i] ) { | ||
181 | list.append( (*it ) ); | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | ++i; | ||
186 | } | ||
187 | for ( it = list2.begin(); it != list2.end(); ++it ) { | ||
188 | if ( (*it).type() == tList[ max-1 ] ) | ||
189 | list.append( (*it ) ); | ||
190 | } | ||
174 | for ( it = list.begin(); it != list.end(); ++it ) { | 191 | for ( it = list.begin(); it != list.end(); ++it ) { |
175 | if ( edit ) { | ||
176 | edit->setPhoneNumber( (*it ) ); | ||
177 | edit = mTypeNumberEditList.next(); | ||
178 | } else { | ||
179 | PhoneTypeNumberEdit* editNew = appendEditCombo(); | 192 | PhoneTypeNumberEdit* editNew = appendEditCombo(); |
180 | editNew->setPhoneNumber( (*it ) ); | 193 | editNew->setPhoneNumber( (*it ) ); |
181 | } | ||
182 | } | ||
183 | while ( edit ) { | ||
184 | edit->hide(); | ||
185 | edit = mTypeNumberEditList.next(); | ||
186 | } | 194 | } |
195 | |||
187 | } | 196 | } |
188 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 197 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() |
189 | { | 198 | { |
190 | KABC::PhoneNumber::List retList; | 199 | KABC::PhoneNumber::List retList; |
191 | 200 | ||
192 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | 201 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); |
193 | while ( edit ) { | 202 | while ( edit ) { |
194 | if ( edit->isValid() ) { | 203 | if ( edit->isValid() ) { |
195 | retList.append( edit->phoneNumber()); | 204 | retList.append( edit->phoneNumber()); |
196 | } | 205 | } |
197 | edit = mTypeNumberEditList.next(); | 206 | edit = mTypeNumberEditList.next(); |
198 | 207 | ||
199 | } | 208 | } |
200 | return retList; | 209 | return retList; |
201 | } | 210 | } |
202 | 211 | ||
203 | #if 0 | 212 | #if 0 |
204 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 213 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
205 | : QWidget( parent, name ) | 214 | : QWidget( parent, name ) |
206 | { | 215 | { |
207 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); | 216 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); |
208 | //US layout->setSpacing( KDialog::spacingHint() ); | 217 | //US layout->setSpacing( KDialog::spacingHint() ); |
209 | layout->setSpacing( KDialogBase::spacingHintSmall() ); | 218 | layout->setSpacing( KDialogBase::spacingHintSmall() ); |
210 | 219 | ||
211 | 220 | ||
212 | 221 | ||
213 | QLabel* label = new QLabel( this ); | 222 | QLabel* label = new QLabel( this ); |
214 | //US loadIcon call is ambiguous. Add one more parameter | 223 | //US loadIcon call is ambiguous. Add one more parameter |
215 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); | 224 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); |
216 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | 225 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
217 | label->setAlignment( AlignCenter ); | 226 | label->setAlignment( AlignCenter ); |
218 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); | 227 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); |
219 | layout->addWidget( label, 0, 0 ); | 228 | layout->addWidget( label, 0, 0 ); |
220 | 229 | ||
221 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), | 230 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), |
222 | this ); | 231 | this ); |
223 | if ( QApplication::desktop()->width() < 640 ) | 232 | if ( QApplication::desktop()->width() < 640 ) |
224 | layout->addWidget( editButton, 0, 1 ); | 233 | layout->addWidget( editButton, 0, 1 ); |
225 | else | 234 | else |
226 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); | 235 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); |
227 | 236 | ||
228 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); | 237 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); |
229 | mPrefEdit = new KLineEdit( this ); | 238 | mPrefEdit = new KLineEdit( this ); |
230 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); | 239 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); |
231 | mPrefCombo->setLineEdit( mPrefEdit ); | 240 | mPrefCombo->setLineEdit( mPrefEdit ); |
232 | layout->addWidget( mPrefCombo, 1, 0 ); | 241 | layout->addWidget( mPrefCombo, 1, 0 ); |
233 | layout->addWidget( mPrefEdit, 1, 1 ); | 242 | layout->addWidget( mPrefEdit, 1, 1 ); |
234 | int x = 1, y = 2; | 243 | int x = 1, y = 2; |
235 | if ( QApplication::desktop()->width() < 640 ) { | 244 | if ( QApplication::desktop()->width() < 640 ) { |
236 | ++x; | 245 | ++x; |
237 | y = 0; | 246 | y = 0; |
238 | } | 247 | } |
239 | mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); | 248 | mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); |
240 | mSecondEdit = new KLineEdit( this ); | 249 | mSecondEdit = new KLineEdit( this ); |
241 | mSecondCombo->setLineEdit( mSecondEdit ); | 250 | mSecondCombo->setLineEdit( mSecondEdit ); |
242 | layout->addWidget( mSecondCombo, x, y++ ); | 251 | layout->addWidget( mSecondCombo, x, y++ ); |
243 | layout->addWidget( mSecondEdit, x, y++ ); | 252 | layout->addWidget( mSecondEdit, x, y++ ); |
244 | 253 | ||
245 | y = 0; | 254 | y = 0; |
246 | ++x; | 255 | ++x; |
247 | mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); | 256 | mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); |
248 | mThirdEdit = new KLineEdit( this ); | 257 | mThirdEdit = new KLineEdit( this ); |
249 | mThirdCombo->setLineEdit( mThirdEdit ); | 258 | mThirdCombo->setLineEdit( mThirdEdit ); |
250 | layout->addWidget( mThirdCombo, x, y++ ); | 259 | layout->addWidget( mThirdCombo, x, y++ ); |
251 | layout->addWidget( mThirdEdit, x, y++ ); | 260 | layout->addWidget( mThirdEdit, x, y++ ); |
252 | if ( QApplication::desktop()->width() < 640 ) { | 261 | if ( QApplication::desktop()->width() < 640 ) { |
253 | ++x; | 262 | ++x; |
254 | y = 0; | 263 | y = 0; |
255 | } | 264 | } |
256 | mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); | 265 | mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); |
257 | mFourthEdit = new KLineEdit( this ); | 266 | mFourthEdit = new KLineEdit( this ); |
258 | mFourthCombo->setLineEdit( mFourthEdit ); | 267 | mFourthCombo->setLineEdit( mFourthEdit ); |
259 | layout->addWidget( mFourthCombo, x, y++ ); | 268 | layout->addWidget( mFourthCombo, x, y++ ); |
260 | layout->addWidget( mFourthEdit, x, y++ ); | 269 | layout->addWidget( mFourthEdit, x, y++ ); |
261 | 270 | ||
262 | // Four numbers don't fit in the current dialog | 271 | // Four numbers don't fit in the current dialog |
263 | if ( QApplication::desktop()->width() < 640 ) { | 272 | if ( QApplication::desktop()->width() < 640 ) { |
264 | mFourthCombo->hide(); | 273 | mFourthCombo->hide(); |
265 | mFourthEdit->hide(); | 274 | mFourthEdit->hide(); |
266 | } else { | 275 | } else { |
267 | QFontMetrics fm ( font () ) ; | 276 | QFontMetrics fm ( font () ) ; |
268 | int wid = fm.width( "Messenger" ) +60; | 277 | int wid = fm.width( "Messenger" ) +60; |
269 | mPrefCombo->setMaximumWidth( wid ); | 278 | mPrefCombo->setMaximumWidth( wid ); |
270 | mSecondCombo->setMaximumWidth( wid ); | 279 | mSecondCombo->setMaximumWidth( wid ); |
271 | mThirdCombo->setMaximumWidth( wid ); | 280 | mThirdCombo->setMaximumWidth( wid ); |
272 | mFourthCombo->setMaximumWidth( wid ); | 281 | mFourthCombo->setMaximumWidth( wid ); |
273 | } | 282 | } |
274 | 283 | ||
275 | 284 | ||
276 | connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), | 285 | connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), |
277 | SLOT( slotPrefEditChanged() ) ); | 286 | SLOT( slotPrefEditChanged() ) ); |
278 | connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), | 287 | connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), |
279 | SLOT( slotSecondEditChanged() ) ); | 288 | SLOT( slotSecondEditChanged() ) ); |
280 | connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), | 289 | connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), |
281 | SLOT( slotThirdEditChanged() ) ); | 290 | SLOT( slotThirdEditChanged() ) ); |
282 | connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), | 291 | connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), |
283 | SLOT( slotFourthEditChanged() ) ); | 292 | SLOT( slotFourthEditChanged() ) ); |
284 | 293 | ||
285 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); | 294 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); |
286 | 295 | ||
287 | connect( mPrefCombo, SIGNAL( activated( int ) ), | 296 | connect( mPrefCombo, SIGNAL( activated( int ) ), |
288 | SLOT( updatePrefEdit() ) ); | 297 | SLOT( updatePrefEdit() ) ); |
289 | connect( mSecondCombo, SIGNAL( activated( int ) ), | 298 | connect( mSecondCombo, SIGNAL( activated( int ) ), |
290 | SLOT( updateSecondEdit() ) ); | 299 | SLOT( updateSecondEdit() ) ); |
291 | connect( mThirdCombo, SIGNAL( activated( int ) ), | 300 | connect( mThirdCombo, SIGNAL( activated( int ) ), |
292 | SLOT( updateThirdEdit() ) ); | 301 | SLOT( updateThirdEdit() ) ); |
293 | connect( mFourthCombo, SIGNAL( activated( int ) ), | 302 | connect( mFourthCombo, SIGNAL( activated( int ) ), |
294 | SLOT( updateFourthEdit() ) ); | 303 | SLOT( updateFourthEdit() ) ); |
295 | } | 304 | } |
296 | 305 | ||
297 | PhoneEditWidget::~PhoneEditWidget() | 306 | PhoneEditWidget::~PhoneEditWidget() |
298 | { | 307 | { |
299 | } | 308 | } |
300 | 309 | ||
301 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) | 310 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) |
302 | { | 311 | { |
303 | mPhoneList.clear(); | 312 | mPhoneList.clear(); |
304 | 313 | ||
305 | // Insert types for existing numbers. | 314 | // Insert types for existing numbers. |
306 | mPrefCombo->insertTypeList( list ); | 315 | mPrefCombo->insertTypeList( list ); |
307 | 316 | ||
308 | QValueList<int> defaultTypes; | 317 | QValueList<int> defaultTypes; |
309 | defaultTypes << KABC::PhoneNumber::Home; | 318 | defaultTypes << KABC::PhoneNumber::Home; |
310 | defaultTypes << KABC::PhoneNumber::Work; | 319 | defaultTypes << KABC::PhoneNumber::Work; |
311 | defaultTypes << KABC::PhoneNumber::Cell; | 320 | defaultTypes << KABC::PhoneNumber::Cell; |
312 | defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); | 321 | defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); |
313 | defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); | 322 | defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); |
314 | 323 | ||
315 | // Insert default types. | 324 | // Insert default types. |
316 | // Doing this for mPrefCombo is enough because the list is shared by all | 325 | // Doing this for mPrefCombo is enough because the list is shared by all |
317 | // combos. | 326 | // combos. |
318 | QValueList<int>::ConstIterator it; | 327 | QValueList<int>::ConstIterator it; |
319 | for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { | 328 | for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { |
320 | if ( !mPrefCombo->hasType( *it ) ) | 329 | if ( !mPrefCombo->hasType( *it ) ) |
321 | mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); | 330 | mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); |
322 | } | 331 | } |
323 | 332 | ||
324 | updateCombos(); | 333 | updateCombos(); |
325 | 334 | ||
326 | mPrefCombo->selectType( defaultTypes[ 0 ] ); | 335 | mPrefCombo->selectType( defaultTypes[ 0 ] ); |
327 | mSecondCombo->selectType( defaultTypes[ 1 ] ); | 336 | mSecondCombo->selectType( defaultTypes[ 1 ] ); |
328 | mThirdCombo->selectType( defaultTypes[ 2 ] ); | 337 | mThirdCombo->selectType( defaultTypes[ 2 ] ); |
329 | mFourthCombo->selectType( defaultTypes[ 3 ] ); | 338 | mFourthCombo->selectType( defaultTypes[ 3 ] ); |
330 | 339 | ||
331 | updateLineEdits(); | 340 | updateLineEdits(); |
332 | } | 341 | } |
333 | 342 | ||
334 | void PhoneEditWidget::updateLineEdits() | 343 | void PhoneEditWidget::updateLineEdits() |
335 | { | 344 | { |
336 | updatePrefEdit(); | 345 | updatePrefEdit(); |
337 | updateSecondEdit(); | 346 | updateSecondEdit(); |
338 | updateThirdEdit(); | 347 | updateThirdEdit(); |
339 | updateFourthEdit(); | 348 | updateFourthEdit(); |
340 | } | 349 | } |
341 | 350 | ||
342 | void PhoneEditWidget::updateCombos() | 351 | void PhoneEditWidget::updateCombos() |
343 | { | 352 | { |
344 | mPrefCombo->updateTypes(); | 353 | mPrefCombo->updateTypes(); |
345 | mSecondCombo->updateTypes(); | 354 | mSecondCombo->updateTypes(); |
346 | mThirdCombo->updateTypes(); | 355 | mThirdCombo->updateTypes(); |
347 | mFourthCombo->updateTypes(); | 356 | mFourthCombo->updateTypes(); |
348 | } | 357 | } |
349 | 358 | ||
350 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 359 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() |
351 | { | 360 | { |
352 | KABC::PhoneNumber::List retList; | 361 | KABC::PhoneNumber::List retList; |
353 | 362 | ||
354 | KABC::PhoneNumber::List::Iterator it; | 363 | KABC::PhoneNumber::List::Iterator it; |
355 | for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) | 364 | for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) |
356 | if ( !(*it).number().isEmpty() ) | 365 | if ( !(*it).number().isEmpty() ) |
357 | retList.append( *it ); | 366 | retList.append( *it ); |
358 | 367 | ||
359 | return retList; | 368 | return retList; |
360 | } | 369 | } |
361 | 370 | ||
362 | void PhoneEditWidget::edit() | 371 | void PhoneEditWidget::edit() |
363 | { | 372 | { |
364 | PhoneEditDialog dlg( mPhoneList, this ); | 373 | PhoneEditDialog dlg( mPhoneList, this ); |
365 | 374 | ||
366 | if ( dlg.exec() ) { | 375 | if ( dlg.exec() ) { |
367 | if ( dlg.changed() ) { | 376 | if ( dlg.changed() ) { |
368 | KABC::PhoneNumber::List list = dlg.phoneNumbers(); | 377 | KABC::PhoneNumber::List list = dlg.phoneNumbers(); |
369 | setPhoneNumbers( list ); | 378 | setPhoneNumbers( list ); |
370 | updateCombos(); | 379 | updateCombos(); |
371 | updateLineEdits(); | 380 | updateLineEdits(); |
372 | emit modified(); | 381 | emit modified(); |
373 | } | 382 | } |
374 | } | 383 | } |
375 | } | 384 | } |
376 | 385 | ||
377 | void PhoneEditWidget::updatePrefEdit() | 386 | void PhoneEditWidget::updatePrefEdit() |
378 | { | 387 | { |
379 | updateEdit( mPrefCombo ); | 388 | updateEdit( mPrefCombo ); |
380 | } | 389 | } |
381 | 390 | ||
382 | void PhoneEditWidget::updateSecondEdit() | 391 | void PhoneEditWidget::updateSecondEdit() |
383 | { | 392 | { |
384 | updateEdit( mSecondCombo ); | 393 | updateEdit( mSecondCombo ); |
385 | } | 394 | } |
386 | 395 | ||
387 | void PhoneEditWidget::updateThirdEdit() | 396 | void PhoneEditWidget::updateThirdEdit() |
388 | { | 397 | { |
389 | updateEdit( mThirdCombo ); | 398 | updateEdit( mThirdCombo ); |
390 | } | 399 | } |
391 | 400 | ||
392 | void PhoneEditWidget::updateFourthEdit() | 401 | void PhoneEditWidget::updateFourthEdit() |
393 | { | 402 | { |
394 | updateEdit( mFourthCombo ); | 403 | updateEdit( mFourthCombo ); |
395 | } | 404 | } |
396 | 405 | ||
397 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) | 406 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) |
398 | { | 407 | { |
399 | QLineEdit *edit = combo->lineEdit(); | 408 | QLineEdit *edit = combo->lineEdit(); |
400 | if ( !edit ) | 409 | if ( !edit ) |
401 | return; | 410 | return; |
402 | 411 | ||
403 | #if 0 | 412 | #if 0 |
404 | if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; | 413 | if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; |
405 | if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; | 414 | if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; |
406 | if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; | 415 | if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; |
407 | if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; | 416 | if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; |
408 | #endif | 417 | #endif |
409 | 418 | ||
410 | PhoneNumber::List::Iterator it = combo->selectedElement(); | 419 | PhoneNumber::List::Iterator it = combo->selectedElement(); |
411 | if ( it != mPhoneList.end() ) { | 420 | if ( it != mPhoneList.end() ) { |
412 | edit->setText( (*it).number() ); | 421 | edit->setText( (*it).number() ); |
413 | } else { | 422 | } else { |
414 | kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; | 423 | kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; |
415 | } | 424 | } |
416 | } | 425 | } |
417 | 426 | ||
418 | void PhoneEditWidget::slotPrefEditChanged() | 427 | void PhoneEditWidget::slotPrefEditChanged() |
419 | { | 428 | { |
420 | updatePhoneNumber( mPrefCombo ); | 429 | updatePhoneNumber( mPrefCombo ); |
421 | } | 430 | } |
422 | 431 | ||
423 | void PhoneEditWidget::slotSecondEditChanged() | 432 | void PhoneEditWidget::slotSecondEditChanged() |
424 | { | 433 | { |
425 | updatePhoneNumber( mSecondCombo ); | 434 | updatePhoneNumber( mSecondCombo ); |
426 | } | 435 | } |
427 | 436 | ||
428 | void PhoneEditWidget::slotThirdEditChanged() | 437 | void PhoneEditWidget::slotThirdEditChanged() |
429 | { | 438 | { |
430 | updatePhoneNumber( mThirdCombo ); | 439 | updatePhoneNumber( mThirdCombo ); |
431 | } | 440 | } |
432 | 441 | ||
433 | void PhoneEditWidget::slotFourthEditChanged() | 442 | void PhoneEditWidget::slotFourthEditChanged() |
434 | { | 443 | { |
435 | updatePhoneNumber( mFourthCombo ); | 444 | updatePhoneNumber( mFourthCombo ); |
436 | } | 445 | } |
437 | 446 | ||
438 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) | 447 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) |
439 | { | 448 | { |
440 | QLineEdit *edit = combo->lineEdit(); | 449 | QLineEdit *edit = combo->lineEdit(); |
441 | if ( !edit ) return; | 450 | if ( !edit ) return; |
442 | 451 | ||