author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kaddressbook/phoneeditwidget.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index df3b551..3661677 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp | |||
@@ -1,731 +1,737 @@ | |||
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 <q3listbox.h> |
31 | #include <qlistview.h> | 31 | #include <q3listview.h> |
32 | #include <qbuttongroup.h> | 32 | #include <q3buttongroup.h> |
33 | #include <qhbox.h> | 33 | #include <q3hbox.h> |
34 | #include <qcursor.h> | 34 | #include <qcursor.h> |
35 | #include <qtimer.h> | 35 | #include <qtimer.h> |
36 | #include <qapplication.h> | 36 | #include <qapplication.h> |
37 | //Added by qt3to4: | ||
38 | #include <Q3ValueList> | ||
39 | #include <Q3GridLayout> | ||
40 | #include <Q3Frame> | ||
41 | #include <Q3PopupMenu> | ||
42 | #include <Q3VBoxLayout> | ||
37 | 43 | ||
38 | #include <kbuttonbox.h> | 44 | #include <kbuttonbox.h> |
39 | #include <klistview.h> | 45 | #include <klistview.h> |
40 | #include <kapplication.h> | 46 | #include <kapplication.h> |
41 | #include <qapplication.h> | 47 | #include <qapplication.h> |
42 | #include <kconfig.h> | 48 | #include <kconfig.h> |
43 | #include <kmessagebox.h> | 49 | #include <kmessagebox.h> |
44 | #include <klineedit.h> | 50 | #include <klineedit.h> |
45 | #include <kcombobox.h> | 51 | #include <kcombobox.h> |
46 | #include <klocale.h> | 52 | #include <klocale.h> |
47 | #include <kdebug.h> | 53 | #include <kdebug.h> |
48 | #include <kglobal.h> | 54 | #include <kglobal.h> |
49 | #include <kiconloader.h> | 55 | #include <kiconloader.h> |
50 | 56 | ||
51 | #include <kabc/phonenumber.h> | 57 | #include <kabc/phonenumber.h> |
52 | 58 | ||
53 | #include "typecombo.h" | 59 | #include "typecombo.h" |
54 | 60 | ||
55 | #include "phoneeditwidget.h" | 61 | #include "phoneeditwidget.h" |
56 | 62 | ||
57 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 63 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
58 | : QWidget(parent,name) | 64 | : QWidget(parent,name) |
59 | { | 65 | { |
60 | QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); | 66 | Q3GridLayout* gridLayout = new Q3GridLayout ( this, 2,2 ); |
61 | 67 | ||
62 | QLabel *temp = new QLabel( "", this ); | 68 | QLabel *temp = new QLabel( "", this ); |
63 | temp->setAlignment( Qt::AlignCenter ); | 69 | temp->setAlignment( Qt::AlignCenter ); |
64 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | 70 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
65 | QPushButton *addBut = new QPushButton ( "add", this ); | 71 | QPushButton *addBut = new QPushButton ( "add", this ); |
66 | addBut->setPixmap ( SmallIcon("plus")); | 72 | addBut->setPixmap ( SmallIcon("plus")); |
67 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); | 73 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); |
68 | connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); | 74 | connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); |
69 | 75 | ||
70 | sv = new QScrollView( this ); | 76 | sv = new Q3ScrollView( this ); |
71 | sv->setFrameStyle ( QFrame::Plain ); | 77 | sv->setFrameStyle ( Q3Frame::Plain ); |
72 | sv->setLineWidth ( 0 ); | 78 | sv->setLineWidth ( 0 ); |
73 | sv->setMidLineWidth ( 0 ); | 79 | sv->setMidLineWidth ( 0 ); |
74 | mw = new QWidget ( sv->viewport() ); | 80 | mw = new QWidget ( sv->viewport() ); |
75 | sv->addChild(mw); | 81 | sv->addChild(mw); |
76 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 82 | sv->setResizePolicy( Q3ScrollView::AutoOneFit ); |
77 | mainLayout = new QVBoxLayout ( mw ); | 83 | mainLayout = new Q3VBoxLayout ( mw ); |
78 | mainLayout->setMargin( 0 ); | 84 | mainLayout->setMargin( 0 ); |
79 | mainLayout->setSpacing( 0 ); | 85 | mainLayout->setSpacing( 0 ); |
80 | gridLayout->setMargin( 2 ); | 86 | gridLayout->setMargin( 2 ); |
81 | gridLayout->setSpacing( 4 ); | 87 | gridLayout->setSpacing( 4 ); |
82 | if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { | 88 | if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { |
83 | gridLayout->addWidget( addBut, 0, 0 ); | 89 | gridLayout->addWidget( addBut, 0, 0 ); |
84 | gridLayout->addWidget( temp, 0, 1 ); | 90 | gridLayout->addWidget( temp, 0, 1 ); |
85 | gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); | 91 | gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); |
86 | } else { | 92 | } else { |
87 | gridLayout->addWidget( temp, 1, 0 ); | 93 | gridLayout->addWidget( temp, 1, 0 ); |
88 | gridLayout->addWidget( addBut, 0, 0 ); | 94 | gridLayout->addWidget( addBut, 0, 0 ); |
89 | gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); | 95 | gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); |
90 | } | 96 | } |
91 | setDefaults(); | 97 | setDefaults(); |
92 | mTypeNumberEditList.setAutoDelete( true ); | 98 | mTypeNumberEditList.setAutoDelete( true ); |
93 | mPopup = new QPopupMenu( this ); | 99 | mPopup = new Q3PopupMenu( this ); |
94 | QStringList list = PhoneNumber::supportedTypeListNames(); | 100 | QStringList list = PhoneNumber::supportedTypeListNames(); |
95 | mPopupCount = list.count(); | 101 | mPopupCount = list.count(); |
96 | int i = 0; | 102 | int i = 0; |
97 | while ( i < mPopupCount ) { | 103 | while ( i < mPopupCount ) { |
98 | mPopup->insertItem( list[ i ], i ); | 104 | mPopup->insertItem( list[ i ], i ); |
99 | ++i; | 105 | ++i; |
100 | } | 106 | } |
101 | connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); | 107 | connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); |
102 | 108 | ||
103 | } | 109 | } |
104 | 110 | ||
105 | PhoneEditWidget::~PhoneEditWidget() | 111 | PhoneEditWidget::~PhoneEditWidget() |
106 | { | 112 | { |
107 | } | 113 | } |
108 | void PhoneEditWidget::setDefaults() | 114 | void PhoneEditWidget::setDefaults() |
109 | { | 115 | { |
110 | mTypeNumberEditList.clear(); | 116 | mTypeNumberEditList.clear(); |
111 | PhoneTypeNumberEdit* edit = appendEditCombo(); | 117 | PhoneTypeNumberEdit* edit = appendEditCombo(); |
112 | KABC::PhoneNumber phoneNumber; | 118 | KABC::PhoneNumber phoneNumber; |
113 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); | 119 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); |
114 | edit->setPhoneNumber( phoneNumber ); | 120 | edit->setPhoneNumber( phoneNumber ); |
115 | edit = appendEditCombo(); | 121 | edit = appendEditCombo(); |
116 | KABC::PhoneNumber phoneNumber2; | 122 | KABC::PhoneNumber phoneNumber2; |
117 | phoneNumber2.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); | 123 | phoneNumber2.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); |
118 | edit->setPhoneNumber( phoneNumber2 ); | 124 | edit->setPhoneNumber( phoneNumber2 ); |
119 | edit = appendEditCombo(); | 125 | edit = appendEditCombo(); |
120 | KABC::PhoneNumber phoneNumber3; | 126 | KABC::PhoneNumber phoneNumber3; |
121 | phoneNumber3.setType( KABC::PhoneNumber::Cell ); | 127 | phoneNumber3.setType( KABC::PhoneNumber::Cell ); |
122 | edit->setPhoneNumber( phoneNumber3 ); | 128 | edit->setPhoneNumber( phoneNumber3 ); |
123 | 129 | ||
124 | } | 130 | } |
125 | void PhoneEditWidget::addNumberInt( int index ) | 131 | void PhoneEditWidget::addNumberInt( int index ) |
126 | { | 132 | { |
127 | PhoneTypeNumberEdit* edit = appendEditCombo(); | 133 | PhoneTypeNumberEdit* edit = appendEditCombo(); |
128 | KABC::PhoneNumber phoneNumber; | 134 | KABC::PhoneNumber phoneNumber; |
129 | phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); | 135 | phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); |
130 | edit->setPhoneNumber( phoneNumber ); | 136 | edit->setPhoneNumber( phoneNumber ); |
131 | //verticalScrollBar()->setValue( 1024); | 137 | //verticalScrollBar()->setValue( 1024); |
132 | QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); | 138 | QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); |
133 | } | 139 | } |
134 | void PhoneEditWidget::bottomVisible() | 140 | void PhoneEditWidget::bottomVisible() |
135 | { | 141 | { |
136 | sv->setContentsPos ( 0, 1024 ); | 142 | sv->setContentsPos ( 0, 1024 ); |
137 | } | 143 | } |
138 | void PhoneEditWidget::addNumber() | 144 | void PhoneEditWidget::addNumber() |
139 | { | 145 | { |
140 | int i = 0; | 146 | int i = 0; |
141 | while ( i < mPopupCount ) { | 147 | while ( i < mPopupCount ) { |
142 | mPopup->setItemEnabled( i, true ); | 148 | mPopup->setItemEnabled( i, true ); |
143 | ++i; | 149 | ++i; |
144 | } | 150 | } |
145 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | 151 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); |
146 | while ( edit ) { | 152 | while ( edit ) { |
147 | if ( edit->currentType() < mPopupCount -1 ) | 153 | if ( edit->currentType() < mPopupCount -1 ) |
148 | mPopup->setItemEnabled( edit->currentType(), false ); | 154 | mPopup->setItemEnabled( edit->currentType(), false ); |
149 | edit = mTypeNumberEditList.next(); | 155 | edit = mTypeNumberEditList.next(); |
150 | } | 156 | } |
151 | mPopup->popup( QCursor::pos() ); | 157 | mPopup->popup( QCursor::pos() ); |
152 | } | 158 | } |
153 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() | 159 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() |
154 | { | 160 | { |
155 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); | 161 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); |
156 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); | 162 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); |
157 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); | 163 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); |
158 | connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); | 164 | connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); |
159 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); | 165 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); |
160 | 166 | ||
161 | mainLayout->add( edit ); | 167 | mainLayout->add( edit ); |
162 | mTypeNumberEditList.append( edit ); | 168 | mTypeNumberEditList.append( edit ); |
163 | return edit; | 169 | return edit; |
164 | } | 170 | } |
165 | 171 | ||
166 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) | 172 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) |
167 | { | 173 | { |
168 | mPendingDelete = ew; | 174 | mPendingDelete = ew; |
169 | QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); | 175 | QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); |
170 | } | 176 | } |
171 | void PhoneEditWidget::pendingDelete() | 177 | void PhoneEditWidget::pendingDelete() |
172 | { | 178 | { |
173 | mTypeNumberEditList.removeRef( mPendingDelete ); | 179 | mTypeNumberEditList.removeRef( mPendingDelete ); |
174 | emit modified(); | 180 | emit modified(); |
175 | } | 181 | } |
176 | 182 | ||
177 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) | 183 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) |
178 | { | 184 | { |
179 | if ( li.isEmpty() ) { | 185 | if ( li.isEmpty() ) { |
180 | setDefaults(); | 186 | setDefaults(); |
181 | return; | 187 | return; |
182 | } | 188 | } |
183 | mTypeNumberEditList.clear(); | 189 | mTypeNumberEditList.clear(); |
184 | KABC::PhoneNumber::List::Iterator it; | 190 | KABC::PhoneNumber::List::Iterator it; |
185 | KABC::PhoneNumber::List list2 = li; | 191 | KABC::PhoneNumber::List list2 = li; |
186 | KABC::PhoneNumber::List list ; | 192 | KABC::PhoneNumber::List list ; |
187 | 193 | ||
188 | PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList(); | 194 | PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList(); |
189 | int i = 0; | 195 | int i = 0; |
190 | int max = tList.count(); | 196 | int max = tList.count(); |
191 | while ( i < max-1 ) { | 197 | while ( i < max-1 ) { |
192 | for ( it = list2.begin(); it != list2.end(); ++it ) { | 198 | for ( it = list2.begin(); it != list2.end(); ++it ) { |
193 | if ( (*it).type() == tList[i] ) { | 199 | if ( (*it).type() == tList[i] ) { |
194 | list.append( (*it ) ); | 200 | list.append( (*it ) ); |
195 | break; | 201 | break; |
196 | } | 202 | } |
197 | } | 203 | } |
198 | ++i; | 204 | ++i; |
199 | } | 205 | } |
200 | for ( it = list2.begin(); it != list2.end(); ++it ) { | 206 | for ( it = list2.begin(); it != list2.end(); ++it ) { |
201 | if ( (*it).type() == tList[ max-1 ] ) | 207 | if ( (*it).type() == tList[ max-1 ] ) |
202 | list.append( (*it ) ); | 208 | list.append( (*it ) ); |
203 | } | 209 | } |
204 | for ( it = list.begin(); it != list.end(); ++it ) { | 210 | for ( it = list.begin(); it != list.end(); ++it ) { |
205 | PhoneTypeNumberEdit* editNew = appendEditCombo(); | 211 | PhoneTypeNumberEdit* editNew = appendEditCombo(); |
206 | editNew->setPhoneNumber( (*it ) ); | 212 | editNew->setPhoneNumber( (*it ) ); |
207 | } | 213 | } |
208 | 214 | ||
209 | } | 215 | } |
210 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 216 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() |
211 | { | 217 | { |
212 | KABC::PhoneNumber::List retList; | 218 | KABC::PhoneNumber::List retList; |
213 | 219 | ||
214 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | 220 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); |
215 | while ( edit ) { | 221 | while ( edit ) { |
216 | if ( edit->isValid() ) { | 222 | if ( edit->isValid() ) { |
217 | retList.append( edit->phoneNumber()); | 223 | retList.append( edit->phoneNumber()); |
218 | } | 224 | } |
219 | edit = mTypeNumberEditList.next(); | 225 | edit = mTypeNumberEditList.next(); |
220 | 226 | ||
221 | } | 227 | } |
222 | return retList; | 228 | return retList; |
223 | } | 229 | } |
224 | 230 | ||
225 | #if 0 | 231 | #if 0 |
226 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 232 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
227 | : QWidget( parent, name ) | 233 | : QWidget( parent, name ) |
228 | { | 234 | { |
229 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); | 235 | Q3GridLayout *layout = new Q3GridLayout( this, 4, 1 ); |
230 | //US layout->setSpacing( KDialog::spacingHint() ); | 236 | //US layout->setSpacing( KDialog::spacingHint() ); |
231 | layout->setSpacing( KDialogBase::spacingHintSmall() ); | 237 | layout->setSpacing( KDialogBase::spacingHintSmall() ); |
232 | 238 | ||
233 | 239 | ||
234 | 240 | ||
235 | QLabel* label = new QLabel( this ); | 241 | QLabel* label = new QLabel( this ); |
236 | //US loadIcon call is ambiguous. Add one more parameter | 242 | //US loadIcon call is ambiguous. Add one more parameter |
237 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); | 243 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); |
238 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | 244 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
239 | label->setAlignment( AlignCenter ); | 245 | label->setAlignment( Qt::AlignCenter ); |
240 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); | 246 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); |
241 | layout->addWidget( label, 0, 0 ); | 247 | layout->addWidget( label, 0, 0 ); |
242 | 248 | ||
243 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), | 249 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), |
244 | this ); | 250 | this ); |
245 | if ( QApplication::desktop()->width() < 640 ) | 251 | if ( QApplication::desktop()->width() < 640 ) |
246 | layout->addWidget( editButton, 0, 1 ); | 252 | layout->addWidget( editButton, 0, 1 ); |
247 | else | 253 | else |
248 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); | 254 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); |
249 | 255 | ||
250 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); | 256 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); |
251 | mPrefEdit = new KLineEdit( this ); | 257 | mPrefEdit = new KLineEdit( this ); |
252 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); | 258 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); |
253 | mPrefCombo->setLineEdit( mPrefEdit ); | 259 | mPrefCombo->setLineEdit( mPrefEdit ); |
254 | layout->addWidget( mPrefCombo, 1, 0 ); | 260 | layout->addWidget( mPrefCombo, 1, 0 ); |
255 | layout->addWidget( mPrefEdit, 1, 1 ); | 261 | layout->addWidget( mPrefEdit, 1, 1 ); |
256 | int x = 1, y = 2; | 262 | int x = 1, y = 2; |
257 | if ( QApplication::desktop()->width() < 640 ) { | 263 | if ( QApplication::desktop()->width() < 640 ) { |
258 | ++x; | 264 | ++x; |
259 | y = 0; | 265 | y = 0; |
260 | } | 266 | } |
261 | mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); | 267 | mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); |
262 | mSecondEdit = new KLineEdit( this ); | 268 | mSecondEdit = new KLineEdit( this ); |
263 | mSecondCombo->setLineEdit( mSecondEdit ); | 269 | mSecondCombo->setLineEdit( mSecondEdit ); |
264 | layout->addWidget( mSecondCombo, x, y++ ); | 270 | layout->addWidget( mSecondCombo, x, y++ ); |
265 | layout->addWidget( mSecondEdit, x, y++ ); | 271 | layout->addWidget( mSecondEdit, x, y++ ); |
266 | 272 | ||
267 | y = 0; | 273 | y = 0; |
268 | ++x; | 274 | ++x; |
269 | mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); | 275 | mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); |
270 | mThirdEdit = new KLineEdit( this ); | 276 | mThirdEdit = new KLineEdit( this ); |
271 | mThirdCombo->setLineEdit( mThirdEdit ); | 277 | mThirdCombo->setLineEdit( mThirdEdit ); |
272 | layout->addWidget( mThirdCombo, x, y++ ); | 278 | layout->addWidget( mThirdCombo, x, y++ ); |
273 | layout->addWidget( mThirdEdit, x, y++ ); | 279 | layout->addWidget( mThirdEdit, x, y++ ); |
274 | if ( QApplication::desktop()->width() < 640 ) { | 280 | if ( QApplication::desktop()->width() < 640 ) { |
275 | ++x; | 281 | ++x; |
276 | y = 0; | 282 | y = 0; |
277 | } | 283 | } |
278 | mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); | 284 | mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); |
279 | mFourthEdit = new KLineEdit( this ); | 285 | mFourthEdit = new KLineEdit( this ); |
280 | mFourthCombo->setLineEdit( mFourthEdit ); | 286 | mFourthCombo->setLineEdit( mFourthEdit ); |
281 | layout->addWidget( mFourthCombo, x, y++ ); | 287 | layout->addWidget( mFourthCombo, x, y++ ); |
282 | layout->addWidget( mFourthEdit, x, y++ ); | 288 | layout->addWidget( mFourthEdit, x, y++ ); |
283 | 289 | ||
284 | // Four numbers don't fit in the current dialog | 290 | // Four numbers don't fit in the current dialog |
285 | if ( QApplication::desktop()->width() < 640 ) { | 291 | if ( QApplication::desktop()->width() < 640 ) { |
286 | mFourthCombo->hide(); | 292 | mFourthCombo->hide(); |
287 | mFourthEdit->hide(); | 293 | mFourthEdit->hide(); |
288 | } else { | 294 | } else { |
289 | QFontMetrics fm ( font () ) ; | 295 | QFontMetrics fm ( font () ) ; |
290 | int wid = fm.width( "Messenger" ) +60; | 296 | int wid = fm.width( "Messenger" ) +60; |
291 | mPrefCombo->setMaximumWidth( wid ); | 297 | mPrefCombo->setMaximumWidth( wid ); |
292 | mSecondCombo->setMaximumWidth( wid ); | 298 | mSecondCombo->setMaximumWidth( wid ); |
293 | mThirdCombo->setMaximumWidth( wid ); | 299 | mThirdCombo->setMaximumWidth( wid ); |
294 | mFourthCombo->setMaximumWidth( wid ); | 300 | mFourthCombo->setMaximumWidth( wid ); |
295 | } | 301 | } |
296 | 302 | ||
297 | 303 | ||
298 | connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), | 304 | connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), |
299 | SLOT( slotPrefEditChanged() ) ); | 305 | SLOT( slotPrefEditChanged() ) ); |
300 | connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), | 306 | connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), |
301 | SLOT( slotSecondEditChanged() ) ); | 307 | SLOT( slotSecondEditChanged() ) ); |
302 | connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), | 308 | connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), |
303 | SLOT( slotThirdEditChanged() ) ); | 309 | SLOT( slotThirdEditChanged() ) ); |
304 | connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), | 310 | connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), |
305 | SLOT( slotFourthEditChanged() ) ); | 311 | SLOT( slotFourthEditChanged() ) ); |
306 | 312 | ||
307 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); | 313 | connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); |
308 | 314 | ||
309 | connect( mPrefCombo, SIGNAL( activated( int ) ), | 315 | connect( mPrefCombo, SIGNAL( activated( int ) ), |
310 | SLOT( updatePrefEdit() ) ); | 316 | SLOT( updatePrefEdit() ) ); |
311 | connect( mSecondCombo, SIGNAL( activated( int ) ), | 317 | connect( mSecondCombo, SIGNAL( activated( int ) ), |
312 | SLOT( updateSecondEdit() ) ); | 318 | SLOT( updateSecondEdit() ) ); |
313 | connect( mThirdCombo, SIGNAL( activated( int ) ), | 319 | connect( mThirdCombo, SIGNAL( activated( int ) ), |
314 | SLOT( updateThirdEdit() ) ); | 320 | SLOT( updateThirdEdit() ) ); |
315 | connect( mFourthCombo, SIGNAL( activated( int ) ), | 321 | connect( mFourthCombo, SIGNAL( activated( int ) ), |
316 | SLOT( updateFourthEdit() ) ); | 322 | SLOT( updateFourthEdit() ) ); |
317 | } | 323 | } |
318 | 324 | ||
319 | PhoneEditWidget::~PhoneEditWidget() | 325 | PhoneEditWidget::~PhoneEditWidget() |
320 | { | 326 | { |
321 | } | 327 | } |
322 | 328 | ||
323 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) | 329 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) |
324 | { | 330 | { |
325 | mPhoneList.clear(); | 331 | mPhoneList.clear(); |
326 | 332 | ||
327 | // Insert types for existing numbers. | 333 | // Insert types for existing numbers. |
328 | mPrefCombo->insertTypeList( list ); | 334 | mPrefCombo->insertTypeList( list ); |
329 | 335 | ||
330 | QValueList<int> defaultTypes; | 336 | Q3ValueList<int> defaultTypes; |
331 | defaultTypes << KABC::PhoneNumber::Home; | 337 | defaultTypes << KABC::PhoneNumber::Home; |
332 | defaultTypes << KABC::PhoneNumber::Work; | 338 | defaultTypes << KABC::PhoneNumber::Work; |
333 | defaultTypes << KABC::PhoneNumber::Cell; | 339 | defaultTypes << KABC::PhoneNumber::Cell; |
334 | defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); | 340 | defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); |
335 | defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); | 341 | defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); |
336 | 342 | ||
337 | // Insert default types. | 343 | // Insert default types. |
338 | // Doing this for mPrefCombo is enough because the list is shared by all | 344 | // Doing this for mPrefCombo is enough because the list is shared by all |
339 | // combos. | 345 | // combos. |
340 | QValueList<int>::ConstIterator it; | 346 | Q3ValueList<int>::ConstIterator it; |
341 | for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { | 347 | for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { |
342 | if ( !mPrefCombo->hasType( *it ) ) | 348 | if ( !mPrefCombo->hasType( *it ) ) |
343 | mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); | 349 | mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); |
344 | } | 350 | } |
345 | 351 | ||
346 | updateCombos(); | 352 | updateCombos(); |
347 | 353 | ||
348 | mPrefCombo->selectType( defaultTypes[ 0 ] ); | 354 | mPrefCombo->selectType( defaultTypes[ 0 ] ); |
349 | mSecondCombo->selectType( defaultTypes[ 1 ] ); | 355 | mSecondCombo->selectType( defaultTypes[ 1 ] ); |
350 | mThirdCombo->selectType( defaultTypes[ 2 ] ); | 356 | mThirdCombo->selectType( defaultTypes[ 2 ] ); |
351 | mFourthCombo->selectType( defaultTypes[ 3 ] ); | 357 | mFourthCombo->selectType( defaultTypes[ 3 ] ); |
352 | 358 | ||
353 | updateLineEdits(); | 359 | updateLineEdits(); |
354 | } | 360 | } |
355 | 361 | ||
356 | void PhoneEditWidget::updateLineEdits() | 362 | void PhoneEditWidget::updateLineEdits() |
357 | { | 363 | { |
358 | updatePrefEdit(); | 364 | updatePrefEdit(); |
359 | updateSecondEdit(); | 365 | updateSecondEdit(); |
360 | updateThirdEdit(); | 366 | updateThirdEdit(); |
361 | updateFourthEdit(); | 367 | updateFourthEdit(); |
362 | } | 368 | } |
363 | 369 | ||
364 | void PhoneEditWidget::updateCombos() | 370 | void PhoneEditWidget::updateCombos() |
365 | { | 371 | { |
366 | mPrefCombo->updateTypes(); | 372 | mPrefCombo->updateTypes(); |
367 | mSecondCombo->updateTypes(); | 373 | mSecondCombo->updateTypes(); |
368 | mThirdCombo->updateTypes(); | 374 | mThirdCombo->updateTypes(); |
369 | mFourthCombo->updateTypes(); | 375 | mFourthCombo->updateTypes(); |
370 | } | 376 | } |
371 | 377 | ||
372 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 378 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() |
373 | { | 379 | { |
374 | KABC::PhoneNumber::List retList; | 380 | KABC::PhoneNumber::List retList; |
375 | 381 | ||
376 | KABC::PhoneNumber::List::Iterator it; | 382 | KABC::PhoneNumber::List::Iterator it; |
377 | for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) | 383 | for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) |
378 | if ( !(*it).number().isEmpty() ) | 384 | if ( !(*it).number().isEmpty() ) |
379 | retList.append( *it ); | 385 | retList.append( *it ); |
380 | 386 | ||
381 | return retList; | 387 | return retList; |
382 | } | 388 | } |
383 | 389 | ||
384 | void PhoneEditWidget::edit() | 390 | void PhoneEditWidget::edit() |
385 | { | 391 | { |
386 | PhoneEditDialog dlg( mPhoneList, this ); | 392 | PhoneEditDialog dlg( mPhoneList, this ); |
387 | 393 | ||
388 | if ( dlg.exec() ) { | 394 | if ( dlg.exec() ) { |
389 | if ( dlg.changed() ) { | 395 | if ( dlg.changed() ) { |
390 | KABC::PhoneNumber::List list = dlg.phoneNumbers(); | 396 | KABC::PhoneNumber::List list = dlg.phoneNumbers(); |
391 | setPhoneNumbers( list ); | 397 | setPhoneNumbers( list ); |
392 | updateCombos(); | 398 | updateCombos(); |
393 | updateLineEdits(); | 399 | updateLineEdits(); |
394 | emit modified(); | 400 | emit modified(); |
395 | } | 401 | } |
396 | } | 402 | } |
397 | } | 403 | } |
398 | 404 | ||
399 | void PhoneEditWidget::updatePrefEdit() | 405 | void PhoneEditWidget::updatePrefEdit() |
400 | { | 406 | { |
401 | updateEdit( mPrefCombo ); | 407 | updateEdit( mPrefCombo ); |
402 | } | 408 | } |
403 | 409 | ||
404 | void PhoneEditWidget::updateSecondEdit() | 410 | void PhoneEditWidget::updateSecondEdit() |
405 | { | 411 | { |
406 | updateEdit( mSecondCombo ); | 412 | updateEdit( mSecondCombo ); |
407 | } | 413 | } |
408 | 414 | ||
409 | void PhoneEditWidget::updateThirdEdit() | 415 | void PhoneEditWidget::updateThirdEdit() |
410 | { | 416 | { |
411 | updateEdit( mThirdCombo ); | 417 | updateEdit( mThirdCombo ); |
412 | } | 418 | } |
413 | 419 | ||
414 | void PhoneEditWidget::updateFourthEdit() | 420 | void PhoneEditWidget::updateFourthEdit() |
415 | { | 421 | { |
416 | updateEdit( mFourthCombo ); | 422 | updateEdit( mFourthCombo ); |
417 | } | 423 | } |
418 | 424 | ||
419 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) | 425 | void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) |
420 | { | 426 | { |
421 | QLineEdit *edit = combo->lineEdit(); | 427 | QLineEdit *edit = combo->lineEdit(); |
422 | if ( !edit ) | 428 | if ( !edit ) |
423 | return; | 429 | return; |
424 | 430 | ||
425 | #if 0 | 431 | #if 0 |
426 | if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; | 432 | if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; |
427 | if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; | 433 | if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; |
428 | if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; | 434 | if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; |
429 | if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; | 435 | if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; |
430 | #endif | 436 | #endif |
431 | 437 | ||
432 | PhoneNumber::List::Iterator it = combo->selectedElement(); | 438 | PhoneNumber::List::Iterator it = combo->selectedElement(); |
433 | if ( it != mPhoneList.end() ) { | 439 | if ( it != mPhoneList.end() ) { |
434 | edit->setText( (*it).number() ); | 440 | edit->setText( (*it).number() ); |
435 | } else { | 441 | } else { |
436 | kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; | 442 | kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; |
437 | } | 443 | } |
438 | } | 444 | } |
439 | 445 | ||
440 | void PhoneEditWidget::slotPrefEditChanged() | 446 | void PhoneEditWidget::slotPrefEditChanged() |
441 | { | 447 | { |
442 | updatePhoneNumber( mPrefCombo ); | 448 | updatePhoneNumber( mPrefCombo ); |
443 | } | 449 | } |
444 | 450 | ||
445 | void PhoneEditWidget::slotSecondEditChanged() | 451 | void PhoneEditWidget::slotSecondEditChanged() |
446 | { | 452 | { |
447 | updatePhoneNumber( mSecondCombo ); | 453 | updatePhoneNumber( mSecondCombo ); |
448 | } | 454 | } |
449 | 455 | ||
450 | void PhoneEditWidget::slotThirdEditChanged() | 456 | void PhoneEditWidget::slotThirdEditChanged() |
451 | { | 457 | { |
452 | updatePhoneNumber( mThirdCombo ); | 458 | updatePhoneNumber( mThirdCombo ); |
453 | } | 459 | } |
454 | 460 | ||
455 | void PhoneEditWidget::slotFourthEditChanged() | 461 | void PhoneEditWidget::slotFourthEditChanged() |
456 | { | 462 | { |
457 | updatePhoneNumber( mFourthCombo ); | 463 | updatePhoneNumber( mFourthCombo ); |
458 | } | 464 | } |
459 | 465 | ||
460 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) | 466 | void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) |
461 | { | 467 | { |
462 | QLineEdit *edit = combo->lineEdit(); | 468 | QLineEdit *edit = combo->lineEdit(); |
463 | if ( !edit ) return; | 469 | if ( !edit ) return; |
464 | 470 | ||
465 | PhoneNumber::List::Iterator it = combo->selectedElement(); | 471 | PhoneNumber::List::Iterator it = combo->selectedElement(); |
466 | if ( it != mPhoneList.end() ) { | 472 | if ( it != mPhoneList.end() ) { |
467 | (*it).setNumber( edit->text() ); | 473 | (*it).setNumber( edit->text() ); |
468 | } | 474 | } |
469 | 475 | ||
470 | updateOtherEdit( combo, mPrefCombo ); | 476 | updateOtherEdit( combo, mPrefCombo ); |
471 | updateOtherEdit( combo, mSecondCombo ); | 477 | updateOtherEdit( combo, mSecondCombo ); |
472 | updateOtherEdit( combo, mThirdCombo ); | 478 | updateOtherEdit( combo, mThirdCombo ); |
473 | updateOtherEdit( combo, mFourthCombo ); | 479 | updateOtherEdit( combo, mFourthCombo ); |
474 | 480 | ||
475 | emit modified(); | 481 | emit modified(); |
476 | } | 482 | } |
477 | 483 | ||
478 | void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) | 484 | void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) |
479 | { | 485 | { |
480 | if ( combo == otherCombo ) return; | 486 | if ( combo == otherCombo ) return; |
481 | 487 | ||
482 | if ( combo->currentItem() == otherCombo->currentItem() ) { | 488 | if ( combo->currentItem() == otherCombo->currentItem() ) { |
483 | updateEdit( otherCombo ); | 489 | updateEdit( otherCombo ); |
484 | } | 490 | } |
485 | } | 491 | } |
486 | 492 | ||
487 | /////////////////////////////////////////// | 493 | /////////////////////////////////////////// |
488 | // PhoneEditDialog | 494 | // PhoneEditDialog |
489 | 495 | ||
490 | class PhoneViewItem : public QListViewItem | 496 | class PhoneViewItem : public Q3ListViewItem |
491 | { | 497 | { |
492 | public: | 498 | public: |
493 | PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); | 499 | PhoneViewItem( Q3ListView *parent, const KABC::PhoneNumber &number ); |
494 | 500 | ||
495 | void setPhoneNumber( const KABC::PhoneNumber &number ) | 501 | void setPhoneNumber( const KABC::PhoneNumber &number ) |
496 | { | 502 | { |
497 | mPhoneNumber = number; | 503 | mPhoneNumber = number; |
498 | makeText(); | 504 | makeText(); |
499 | } | 505 | } |
500 | 506 | ||
501 | QString key() { return mPhoneNumber.id(); } | 507 | QString key() { return mPhoneNumber.id(); } |
502 | QString country() { return ""; } | 508 | QString country() { return ""; } |
503 | QString region() { return ""; } | 509 | QString region() { return ""; } |
504 | QString number() { return ""; } | 510 | QString number() { return ""; } |
505 | 511 | ||
506 | KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } | 512 | KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } |
507 | 513 | ||
508 | private: | 514 | private: |
509 | void makeText(); | 515 | void makeText(); |
510 | 516 | ||
511 | KABC::PhoneNumber mPhoneNumber; | 517 | KABC::PhoneNumber mPhoneNumber; |
512 | }; | 518 | }; |
513 | 519 | ||
514 | PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) | 520 | PhoneViewItem::PhoneViewItem( Q3ListView *parent, const KABC::PhoneNumber &number ) |
515 | : QListViewItem( parent ), mPhoneNumber( number ) | 521 | : Q3ListViewItem( parent ), mPhoneNumber( number ) |
516 | { | 522 | { |
517 | #ifdef DESKTOP_VERSION | 523 | #ifdef DESKTOP_VERSION |
518 | setRenameEnabled ( 0, true ); | 524 | setRenameEnabled ( 0, true ); |
519 | #endif | 525 | #endif |
520 | makeText(); | 526 | makeText(); |
521 | } | 527 | } |
522 | 528 | ||
523 | void PhoneViewItem::makeText() | 529 | void PhoneViewItem::makeText() |
524 | { | 530 | { |
525 | /** | 531 | /** |
526 | * Will be used in future versions of kaddressbook/libkabc | 532 | * Will be used in future versions of kaddressbook/libkabc |
527 | 533 | ||
528 | setText( 0, mPhoneNumber.country() ); | 534 | setText( 0, mPhoneNumber.country() ); |
529 | setText( 1, mPhoneNumber.region() ); | 535 | setText( 1, mPhoneNumber.region() ); |
530 | setText( 2, mPhoneNumber.number() ); | 536 | setText( 2, mPhoneNumber.number() ); |
531 | setText( 3, mPhoneNumber.typeLabel() ); | 537 | setText( 3, mPhoneNumber.typeLabel() ); |
532 | */ | 538 | */ |
533 | 539 | ||
534 | setText( 0, mPhoneNumber.number() ); | 540 | setText( 0, mPhoneNumber.number() ); |
535 | setText( 1, mPhoneNumber.typeLabel() ); | 541 | setText( 1, mPhoneNumber.typeLabel() ); |
536 | } | 542 | } |
537 | 543 | ||
538 | PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) | 544 | PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) |
539 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), | 545 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), |
540 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, | 546 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, |
541 | parent, name, true) | 547 | parent, name, true) |
542 | { | 548 | { |
543 | mPhoneNumberList = list; | 549 | mPhoneNumberList = list; |
544 | 550 | ||
545 | QWidget *page = plainPage(); | 551 | QWidget *page = plainPage(); |
546 | 552 | ||
547 | QGridLayout *layout = new QGridLayout( page, 1, 2 ); | 553 | Q3GridLayout *layout = new Q3GridLayout( page, 1, 2 ); |
548 | layout->setSpacing( spacingHint() ); | 554 | layout->setSpacing( spacingHint() ); |
549 | 555 | ||
550 | mListView = new KListView( page ); | 556 | mListView = new KListView( page ); |
551 | mListView->setAllColumnsShowFocus( true ); | 557 | mListView->setAllColumnsShowFocus( true ); |
552 | mListView->addColumn( i18n( "Number" ) ); | 558 | mListView->addColumn( i18n( "Number" ) ); |
553 | mListView->addColumn( i18n( "Type" ) ); | 559 | mListView->addColumn( i18n( "Type" ) ); |
554 | 560 | ||
555 | KButtonBox *buttonBox = new KButtonBox( page, Vertical ); | 561 | KButtonBox *buttonBox = new KButtonBox( page, Qt::Vertical ); |
556 | 562 | ||
557 | buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); | 563 | buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); |
558 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); | 564 | mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); |
559 | mEditButton->setEnabled( false ); | 565 | mEditButton->setEnabled( false ); |
560 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); | 566 | mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); |
561 | mRemoveButton->setEnabled( false ); | 567 | mRemoveButton->setEnabled( false ); |
562 | buttonBox->layout(); | 568 | buttonBox->layout(); |
563 | 569 | ||
564 | layout->addWidget( mListView, 0, 0 ); | 570 | layout->addWidget( mListView, 0, 0 ); |
565 | layout->addWidget( buttonBox, 0, 1 ); | 571 | layout->addWidget( buttonBox, 0, 1 ); |
566 | 572 | ||
567 | connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); | 573 | connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); |
568 | connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); | 574 | connect( mListView, SIGNAL(doubleClicked( Q3ListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); |
569 | 575 | ||
570 | KABC::PhoneNumber::List::Iterator it; | 576 | KABC::PhoneNumber::List::Iterator it; |
571 | for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) | 577 | for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) |
572 | new PhoneViewItem( mListView, *it ); | 578 | new PhoneViewItem( mListView, *it ); |
573 | if (QApplication::desktop()->width() < 480 ) | 579 | if (QApplication::desktop()->width() < 480 ) |
574 | showMaximized(); | 580 | showMaximized(); |
575 | else | 581 | else |
576 | resize( 400, 400 ); | 582 | resize( 400, 400 ); |
577 | mChanged = false; | 583 | mChanged = false; |
578 | } | 584 | } |
579 | 585 | ||
580 | PhoneEditDialog::~PhoneEditDialog() | 586 | PhoneEditDialog::~PhoneEditDialog() |
581 | { | 587 | { |
582 | qDebug("PhoneEditDialog::~PhoneEditDialog() "); | 588 | qDebug("PhoneEditDialog::~PhoneEditDialog() "); |
583 | } | 589 | } |
584 | 590 | ||
585 | void PhoneEditDialog::slotAddPhoneNumber() | 591 | void PhoneEditDialog::slotAddPhoneNumber() |
586 | { | 592 | { |
587 | KABC::PhoneNumber tmp( "", 0 ); | 593 | KABC::PhoneNumber tmp( "", 0 ); |
588 | PhoneTypeDialog dlg( tmp, this ); | 594 | PhoneTypeDialog dlg( tmp, this ); |
589 | 595 | ||
590 | if ( dlg.exec() ) { | 596 | if ( dlg.exec() ) { |
591 | QListViewItem* i = mListView->firstChild(); | 597 | Q3ListViewItem* i = mListView->firstChild(); |
592 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); | 598 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); |
593 | bool insert = true; | 599 | bool insert = true; |
594 | while ( i ) { | 600 | while ( i ) { |
595 | PhoneViewItem* p = ( PhoneViewItem* ) i; | 601 | PhoneViewItem* p = ( PhoneViewItem* ) i; |
596 | KABC::PhoneNumber pn = p->phoneNumber(); | 602 | KABC::PhoneNumber pn = p->phoneNumber(); |
597 | if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { | 603 | if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { |
598 | if ( p->text(0).isEmpty()) { | 604 | if ( p->text(0).isEmpty()) { |
599 | p->setPhoneNumber( phoneNumber ); | 605 | p->setPhoneNumber( phoneNumber ); |
600 | mPhoneNumberList.remove( pn ); | 606 | mPhoneNumberList.remove( pn ); |
601 | mPhoneNumberList.append( phoneNumber ); | 607 | mPhoneNumberList.append( phoneNumber ); |
602 | insert = false; | 608 | insert = false; |
603 | break; | 609 | break; |
604 | } | 610 | } |
605 | } | 611 | } |
606 | i = i->nextSibling(); | 612 | i = i->nextSibling(); |
607 | } | 613 | } |
608 | if ( insert ) { | 614 | if ( insert ) { |
609 | mPhoneNumberList.append( phoneNumber ); | 615 | mPhoneNumberList.append( phoneNumber ); |
610 | new PhoneViewItem( mListView, phoneNumber ); | 616 | new PhoneViewItem( mListView, phoneNumber ); |
611 | } | 617 | } |
612 | mChanged = true; | 618 | mChanged = true; |
613 | } | 619 | } |
614 | } | 620 | } |
615 | 621 | ||
616 | void PhoneEditDialog::slotRemovePhoneNumber() | 622 | void PhoneEditDialog::slotRemovePhoneNumber() |
617 | { | 623 | { |
618 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); | 624 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); |
619 | if ( !item ) | 625 | if ( !item ) |
620 | return; | 626 | return; |
621 | 627 | ||
622 | mPhoneNumberList.remove( item->phoneNumber() ); | 628 | mPhoneNumberList.remove( item->phoneNumber() ); |
623 | QListViewItem *currItem = mListView->currentItem(); | 629 | Q3ListViewItem *currItem = mListView->currentItem(); |
624 | mListView->takeItem( currItem ); | 630 | mListView->takeItem( currItem ); |
625 | delete currItem; | 631 | delete currItem; |
626 | 632 | ||
627 | mChanged = true; | 633 | mChanged = true; |
628 | } | 634 | } |
629 | 635 | ||
630 | void PhoneEditDialog::slotEditPhoneNumber() | 636 | void PhoneEditDialog::slotEditPhoneNumber() |
631 | { | 637 | { |
632 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); | 638 | PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); |
633 | if ( !item ) | 639 | if ( !item ) |
634 | return; | 640 | return; |
635 | 641 | ||
636 | PhoneTypeDialog dlg( item->phoneNumber(), this ); | 642 | PhoneTypeDialog dlg( item->phoneNumber(), this ); |
637 | 643 | ||
638 | if ( dlg.exec() ) { | 644 | if ( dlg.exec() ) { |
639 | slotRemovePhoneNumber(); | 645 | slotRemovePhoneNumber(); |
640 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); | 646 | KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); |
641 | mPhoneNumberList.append( phoneNumber ); | 647 | mPhoneNumberList.append( phoneNumber ); |
642 | new PhoneViewItem( mListView, phoneNumber ); | 648 | new PhoneViewItem( mListView, phoneNumber ); |
643 | 649 | ||
644 | mChanged = true; | 650 | mChanged = true; |
645 | } | 651 | } |
646 | } | 652 | } |
647 | 653 | ||
648 | void PhoneEditDialog::slotSelectionChanged() | 654 | void PhoneEditDialog::slotSelectionChanged() |
649 | { | 655 | { |
650 | bool state = ( mListView->currentItem() != 0 ); | 656 | bool state = ( mListView->currentItem() != 0 ); |
651 | 657 | ||
652 | mRemoveButton->setEnabled( state ); | 658 | mRemoveButton->setEnabled( state ); |
653 | mEditButton->setEnabled( state ); | 659 | mEditButton->setEnabled( state ); |
654 | } | 660 | } |
655 | 661 | ||
656 | const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() | 662 | const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() |
657 | { | 663 | { |
658 | return mPhoneNumberList; | 664 | return mPhoneNumberList; |
659 | } | 665 | } |
660 | 666 | ||
661 | bool PhoneEditDialog::changed() const | 667 | bool PhoneEditDialog::changed() const |
662 | { | 668 | { |
663 | return mChanged; | 669 | return mChanged; |
664 | } | 670 | } |
665 | 671 | ||
666 | /////////////////////////////////////////// | 672 | /////////////////////////////////////////// |
667 | // PhoneTypeDialog | 673 | // PhoneTypeDialog |
668 | PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, | 674 | PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, |
669 | QWidget *parent, const char *name) | 675 | QWidget *parent, const char *name) |
670 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), | 676 | : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), |
671 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, | 677 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, |
672 | parent, name, true), mPhoneNumber( phoneNumber ) | 678 | parent, name, true), mPhoneNumber( phoneNumber ) |
673 | { | 679 | { |
674 | QWidget *page = plainPage(); | 680 | QWidget *page = plainPage(); |
675 | QLabel *label = 0; | 681 | QLabel *label = 0; |
676 | QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); | 682 | Q3GridLayout *layout = new Q3GridLayout( page, 3, 2, marginHint(), spacingHint() ); |
677 | 683 | ||
678 | label = new QLabel( i18n( "Number:" ), page ); | 684 | label = new QLabel( i18n( "Number:" ), page ); |
679 | layout->addWidget( label, 0, 0 ); | 685 | layout->addWidget( label, 0, 0 ); |
680 | mNumber = new KLineEdit( page ); | 686 | mNumber = new KLineEdit( page ); |
681 | layout->addWidget( mNumber, 0, 1 ); | 687 | layout->addWidget( mNumber, 0, 1 ); |
682 | 688 | ||
683 | mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); | 689 | mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); |
684 | layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); | 690 | layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); |
685 | 691 | ||
686 | mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); | 692 | mGroup = new Q3ButtonGroup( 2, Qt::Horizontal, i18n( "Types" ), page ); |
687 | layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); | 693 | layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); |
688 | 694 | ||
689 | // fill widgets | 695 | // fill widgets |
690 | mNumber->setText( mPhoneNumber.number() ); | 696 | mNumber->setText( mPhoneNumber.number() ); |
691 | 697 | ||
692 | mTypeList = KABC::PhoneNumber::typeList(); | 698 | mTypeList = KABC::PhoneNumber::typeList(); |
693 | mTypeList.remove( KABC::PhoneNumber::Pref ); | 699 | mTypeList.remove( KABC::PhoneNumber::Pref ); |
694 | 700 | ||
695 | KABC::PhoneNumber::TypeList::Iterator it; | 701 | KABC::PhoneNumber::TypeList::Iterator it; |
696 | for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) | 702 | for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) |
697 | new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); | 703 | new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); |
698 | 704 | ||
699 | for ( int i = 0; i < mGroup->count(); ++i ) { | 705 | for ( int i = 0; i < mGroup->count(); ++i ) { |
700 | int type = mPhoneNumber.type(); | 706 | int type = mPhoneNumber.type(); |
701 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); | 707 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); |
702 | box->setChecked( type & mTypeList[ i ] ); | 708 | box->setChecked( type & mTypeList[ i ] ); |
703 | } | 709 | } |
704 | 710 | ||
705 | mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); | 711 | mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); |
706 | mNumber->setFocus(); | 712 | mNumber->setFocus(); |
707 | mNumber->setSelection( 0, 1024); | 713 | mNumber->setSelection( 0, 1024); |
708 | } | 714 | } |
709 | 715 | ||
710 | KABC::PhoneNumber PhoneTypeDialog::phoneNumber() | 716 | KABC::PhoneNumber PhoneTypeDialog::phoneNumber() |
711 | { | 717 | { |
712 | mPhoneNumber.setNumber( mNumber->text() ); | 718 | mPhoneNumber.setNumber( mNumber->text() ); |
713 | 719 | ||
714 | int type = 0; | 720 | int type = 0; |
715 | for ( int i = 0; i < mGroup->count(); ++i ) { | 721 | for ( int i = 0; i < mGroup->count(); ++i ) { |
716 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); | 722 | QCheckBox *box = (QCheckBox*)mGroup->find( i ); |
717 | if ( box->isChecked() ) | 723 | if ( box->isChecked() ) |
718 | type += mTypeList[ i ]; | 724 | type += mTypeList[ i ]; |
719 | } | 725 | } |
720 | 726 | ||
721 | if ( mPreferredBox->isChecked() ) | 727 | if ( mPreferredBox->isChecked() ) |
722 | mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); | 728 | mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); |
723 | else | 729 | else |
724 | mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); | 730 | mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); |
725 | 731 | ||
726 | return mPhoneNumber; | 732 | return mPhoneNumber; |
727 | } | 733 | } |
728 | #endif | 734 | #endif |
729 | #ifndef KAB_EMBEDDED | 735 | #ifndef KAB_EMBEDDED_ |
730 | #include "phoneeditwidget.moc" | 736 | #include "moc_phoneeditwidget.cpp" |
731 | #endif //KAB_EMBEDDED | 737 | #endif //KAB_EMBEDDED |