24 #include <tqbuttongroup.h>
25 #include <tqcheckbox.h>
28 #include <tqlistbox.h>
29 #include <tqlistview.h>
30 #include <tqpushbutton.h>
31 #include <tqsignalmapper.h>
33 #include <tqtooltip.h>
35 #include <tdeapplication.h>
36 #include <kbuttonbox.h>
37 #include <kcombobox.h>
38 #include <tdeconfig.h>
40 #include <kiconloader.h>
41 #include <klineedit.h>
42 #include <tdelistview.h>
43 #include <tdelocale.h>
45 #include <tdeabc/phonenumber.h>
47 #include "phoneeditwidget.h"
49 PhoneTypeCombo::PhoneTypeCombo( TQWidget *parent )
50 : KComboBox( parent,
"TypeCombo" ),
51 mType( TDEABC::PhoneNumber::Home ),
53 mTypeList( TDEABC::PhoneNumber::typeList() )
55 mTypeList.append( -1 );
59 connect(
this, TQ_SIGNAL( activated(
int ) ),
60 this, TQ_SLOT( selected(
int ) ) );
61 connect(
this, TQ_SIGNAL( activated(
int ) ),
62 this, TQ_SIGNAL( modified() ) );
65 PhoneTypeCombo::~PhoneTypeCombo()
69 void PhoneTypeCombo::setType(
int type )
71 if ( !mTypeList.contains( type ) )
72 mTypeList.insert( mTypeList.at( mTypeList.count() - 1 ), type );
78 int PhoneTypeCombo::type()
const
83 void PhoneTypeCombo::update()
85 bool blocked = signalsBlocked();
89 TQValueList<int>::ConstIterator it;
90 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) {
92 insertItem( i18n(
"Other..." ) );
94 TDEABC::PhoneNumber number;
95 number.setType( *it );
96 insertItem( number.typeLabel() );
100 setCurrentItem( mLastSelected = mTypeList.findIndex( mType ) );
102 blockSignals( blocked );
105 void PhoneTypeCombo::selected(
int pos )
107 if ( mTypeList[ pos ] == -1 )
110 mType = mTypeList[ pos ];
115 void PhoneTypeCombo::otherSelected()
120 if ( !mTypeList.contains( mType ) )
121 mTypeList.insert( mTypeList.at( mTypeList.count() - 1 ), mType );
123 setType( mTypeList[ mLastSelected ] );
129 PhoneNumberWidget::PhoneNumberWidget( TQWidget *parent )
132 TQHBoxLayout *layout =
new TQHBoxLayout(
this, 6, 11 );
134 mTypeCombo =
new PhoneTypeCombo(
this );
135 mNumberEdit =
new KLineEdit(
this );
137 layout->addWidget( mTypeCombo );
138 layout->addWidget( mNumberEdit );
140 connect( mTypeCombo, TQ_SIGNAL( modified() ), TQ_SIGNAL( modified() ) );
141 connect( mNumberEdit, TQ_SIGNAL( textChanged(
const TQString& ) ), TQ_SIGNAL( modified() ) );
144 void PhoneNumberWidget::setNumber(
const TDEABC::PhoneNumber &number )
148 mTypeCombo->setType( number.type() );
149 mNumberEdit->setText( number.number() );
152 TDEABC::PhoneNumber PhoneNumberWidget::number()
const
154 TDEABC::PhoneNumber number( mNumber );
156 number.setType( mTypeCombo->type() );
157 number.setNumber( mNumberEdit->text() );
162 void PhoneNumberWidget::setReadOnly(
bool readOnly )
164 mTypeCombo->setEnabled( !readOnly );
165 mNumberEdit->setReadOnly( readOnly );
169 PhoneEditWidget::PhoneEditWidget( TQWidget *parent,
const char *name )
170 : TQWidget( parent, name ), mReadOnly( false )
172 TQGridLayout *layout =
new TQGridLayout(
this, 2, 2 );
173 layout->setSpacing( KDialog::spacingHint() );
175 mWidgetLayout =
new TQVBoxLayout( layout );
176 layout->addMultiCellLayout( mWidgetLayout, 0, 0, 0, 1 );
178 mAddButton =
new TQPushButton( i18n(
"Add" ),
this );
179 mAddButton->setMaximumSize( mAddButton->sizeHint() );
180 layout->addWidget( mAddButton, 1, 0, TQt::AlignRight );
182 mRemoveButton =
new TQPushButton( i18n(
"Remove" ),
this );
183 mRemoveButton->setMaximumSize( mRemoveButton->sizeHint() );
184 layout->addWidget( mRemoveButton, 1, 1 );
186 mMapper =
new TQSignalMapper(
this );
187 connect( mMapper, TQ_SIGNAL( mapped(
int ) ), TQ_SLOT( changed(
int ) ) );
189 connect( mAddButton, TQ_SIGNAL( clicked() ), TQ_SLOT( add() ) );
190 connect( mRemoveButton, TQ_SIGNAL( clicked() ), TQ_SLOT( remove() ) );
193 PhoneEditWidget::~PhoneEditWidget()
197 void PhoneEditWidget::setReadOnly(
bool readOnly )
199 mReadOnly = readOnly;
200 mAddButton->setEnabled( !readOnly );
201 mRemoveButton->setEnabled( !readOnly && mPhoneNumberList.count() > 3 );
203 TQPtrListIterator<PhoneNumberWidget> it( mWidgets );
204 while ( it.current() ) {
205 it.current()->setReadOnly( readOnly );
210 void PhoneEditWidget::setPhoneNumbers(
const TDEABC::PhoneNumber::List &list )
212 mPhoneNumberList = list;
214 TDEABC::PhoneNumber::TypeList types;
215 types << TDEABC::PhoneNumber::Home;
216 types << TDEABC::PhoneNumber::Work;
217 types << TDEABC::PhoneNumber::Cell;
220 if ( mPhoneNumberList.count() < 3 )
221 for (
int i = mPhoneNumberList.count(); i < 3; ++i )
222 mPhoneNumberList.append( TDEABC::PhoneNumber(
"", types[ i ] ) );
224 recreateNumberWidgets();
227 TDEABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
const
229 TDEABC::PhoneNumber::List list;
231 TDEABC::PhoneNumber::List::ConstIterator it;
232 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
233 if ( !(*it).number().isEmpty() )
239 void PhoneEditWidget::changed()
245 void PhoneEditWidget::add()
247 mPhoneNumberList.append( TDEABC::PhoneNumber() );
249 recreateNumberWidgets();
252 void PhoneEditWidget::remove()
254 mPhoneNumberList.remove( mPhoneNumberList.last() );
257 recreateNumberWidgets();
260 void PhoneEditWidget::recreateNumberWidgets()
262 for ( TQWidget *w = mWidgets.first(); w; w = mWidgets.next() ) {
263 mWidgetLayout->remove( w );
268 TDEABC::PhoneNumber::List::ConstIterator it;
270 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) {
271 PhoneNumberWidget *wdg =
new PhoneNumberWidget(
this );
272 wdg->setNumber( *it );
274 mMapper->setMapping( wdg, counter );
275 connect( wdg, TQ_SIGNAL( modified() ), mMapper, TQ_SLOT( map() ) );
277 mWidgetLayout->addWidget( wdg );
278 mWidgets.append( wdg );
283 setReadOnly(mReadOnly);
286 void PhoneEditWidget::changed(
int pos )
288 mPhoneNumberList[ pos ] = mWidgets.at( pos )->number();
294 PhoneTypeDialog::PhoneTypeDialog(
int type, TQWidget *parent )
295 : KDialogBase( Plain, i18n(
"Edit Phone Number" ), Ok | Cancel, Ok,
296 parent,
"PhoneTypeDialog", true ),
299 TQWidget *page = plainPage();
301 TQVBoxLayout *layout =
new TQVBoxLayout( page, spacingHint() );
303 mPreferredBox =
new TQCheckBox( i18n(
"This is the preferred phone number" ), page );
304 layout->addWidget( mPreferredBox );
306 mGroup =
new TQButtonGroup( 2, TQt::Horizontal, i18n(
"Types" ), page );
307 layout->addWidget( mGroup );
310 mTypeList = TDEABC::PhoneNumber::typeList();
311 mTypeList.remove( TDEABC::PhoneNumber::Pref );
313 TDEABC::PhoneNumber::TypeList::ConstIterator it;
314 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
315 new TQCheckBox( TDEABC::PhoneNumber::typeLabel( *it ), mGroup );
317 for (
int i = 0; i < mGroup->count(); ++i ) {
318 TQCheckBox *box = (TQCheckBox*)mGroup->find( i );
319 box->setChecked( mType & mTypeList[ i ] );
322 mPreferredBox->setChecked( mType & TDEABC::PhoneNumber::Pref );
325 int PhoneTypeDialog::type()
const
329 for (
int i = 0; i < mGroup->count(); ++i ) {
330 TQCheckBox *box = (TQCheckBox*)mGroup->find( i );
331 if ( box->isChecked() )
332 type += mTypeList[ i ];
335 if ( mPreferredBox->isChecked() )
336 type = type | TDEABC::PhoneNumber::Pref;
338 type = type & ~TDEABC::PhoneNumber::Pref;
344 #include "phoneeditwidget.moc"
Dialog for editing phone number types.