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