Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index a435959..2bce39a 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp @@ -271,257 +271,260 @@ void PhoneEditWidget::slotPrefEditChanged() void PhoneEditWidget::slotSecondEditChanged() { updatePhoneNumber( mSecondCombo ); } void PhoneEditWidget::slotThirdEditChanged() { updatePhoneNumber( mThirdCombo ); } void PhoneEditWidget::slotFourthEditChanged() { updatePhoneNumber( mFourthCombo ); } void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) { QLineEdit *edit = combo->lineEdit(); if ( !edit ) return; PhoneNumber::List::Iterator it = combo->selectedElement(); if ( it != mPhoneList.end() ) { (*it).setNumber( edit->text() ); } updateOtherEdit( combo, mPrefCombo ); updateOtherEdit( combo, mSecondCombo ); updateOtherEdit( combo, mThirdCombo ); updateOtherEdit( combo, mFourthCombo ); emit modified(); } void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) { if ( combo == otherCombo ) return; if ( combo->currentItem() == otherCombo->currentItem() ) { updateEdit( otherCombo ); } } /////////////////////////////////////////// // PhoneEditDialog class PhoneViewItem : public QListViewItem { public: PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); void setPhoneNumber( const KABC::PhoneNumber &number ) { mPhoneNumber = number; makeText(); } QString key() { return mPhoneNumber.id(); } QString country() { return ""; } QString region() { return ""; } QString number() { return ""; } KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } private: void makeText(); KABC::PhoneNumber mPhoneNumber; }; PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) : QListViewItem( parent ), mPhoneNumber( number ) { #ifdef DESKTOP_VERSION setRenameEnabled ( 0, true ); #endif makeText(); } void PhoneViewItem::makeText() { /** * Will be used in future versions of kaddressbook/libkabc setText( 0, mPhoneNumber.country() ); setText( 1, mPhoneNumber.region() ); setText( 2, mPhoneNumber.number() ); setText( 3, mPhoneNumber.typeLabel() ); */ setText( 0, mPhoneNumber.number() ); setText( 1, mPhoneNumber.typeLabel() ); } PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent, name, true) { mPhoneNumberList = list; QWidget *page = plainPage(); QGridLayout *layout = new QGridLayout( page, 1, 2 ); layout->setSpacing( spacingHint() ); mListView = new KListView( page ); mListView->setAllColumnsShowFocus( true ); mListView->addColumn( i18n( "Number" ) ); mListView->addColumn( i18n( "Type" ) ); KButtonBox *buttonBox = new KButtonBox( page, Vertical ); buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); mEditButton->setEnabled( false ); mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); mRemoveButton->setEnabled( false ); buttonBox->layout(); layout->addWidget( mListView, 0, 0 ); layout->addWidget( buttonBox, 0, 1 ); connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); KABC::PhoneNumber::List::Iterator it; for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) new PhoneViewItem( mListView, *it ); - + if (QApplication::desktop()->width() < 480 ) + showMaximized(); + else + resize( 400, 400 ); mChanged = false; } PhoneEditDialog::~PhoneEditDialog() { } void PhoneEditDialog::slotAddPhoneNumber() { KABC::PhoneNumber tmp( "", 0 ); PhoneTypeDialog dlg( tmp, this ); if ( dlg.exec() ) { QListViewItem* i = mListView->firstChild(); KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); bool insert = true; while ( i ) { PhoneViewItem* p = ( PhoneViewItem* ) i; KABC::PhoneNumber pn = p->phoneNumber(); if ( (pn.type() | KABC::PhoneNumber::Pref) == (phoneNumber.type() | KABC::PhoneNumber::Pref) ) { if ( p->text(0).isEmpty()) { p->setPhoneNumber( phoneNumber ); mPhoneNumberList.remove( pn ); mPhoneNumberList.append( phoneNumber ); insert = false; break; } } i = i->nextSibling(); } if ( insert ) { mPhoneNumberList.append( phoneNumber ); new PhoneViewItem( mListView, phoneNumber ); } mChanged = true; } } void PhoneEditDialog::slotRemovePhoneNumber() { PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); if ( !item ) return; mPhoneNumberList.remove( item->phoneNumber() ); QListViewItem *currItem = mListView->currentItem(); mListView->takeItem( currItem ); delete currItem; mChanged = true; } void PhoneEditDialog::slotEditPhoneNumber() { PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); if ( !item ) return; PhoneTypeDialog dlg( item->phoneNumber(), this ); if ( dlg.exec() ) { slotRemovePhoneNumber(); KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); mPhoneNumberList.append( phoneNumber ); new PhoneViewItem( mListView, phoneNumber ); mChanged = true; } } void PhoneEditDialog::slotSelectionChanged() { bool state = ( mListView->currentItem() != 0 ); mRemoveButton->setEnabled( state ); mEditButton->setEnabled( state ); } const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() { return mPhoneNumberList; } bool PhoneEditDialog::changed() const { return mChanged; } /////////////////////////////////////////// // PhoneTypeDialog PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, QWidget *parent, const char *name) : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent, name, true), mPhoneNumber( phoneNumber ) { QWidget *page = plainPage(); QLabel *label = 0; QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); label = new QLabel( i18n( "Number:" ), page ); layout->addWidget( label, 0, 0 ); mNumber = new KLineEdit( page ); layout->addWidget( mNumber, 0, 1 ); mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); // fill widgets mNumber->setText( mPhoneNumber.number() ); mTypeList = KABC::PhoneNumber::typeList(); mTypeList.remove( KABC::PhoneNumber::Pref ); KABC::PhoneNumber::TypeList::Iterator it; for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); for ( int i = 0; i < mGroup->count(); ++i ) { int type = mPhoneNumber.type(); QCheckBox *box = (QCheckBox*)mGroup->find( i ); box->setChecked( type & mTypeList[ i ] ); } mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); |