author | zautrix <zautrix> | 2005-10-28 17:12:43 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-10-28 17:12:43 (UTC) |
commit | 16e87ac5b81352c51343715cf1080191aaba9611 (patch) (side-by-side diff) | |
tree | ba64a88d20259728559af64e8def62179775c104 | |
parent | d6eb485cf2ff7a14918f51a5b21b5306f9908fdb (diff) | |
download | kdepimpi-16e87ac5b81352c51343715cf1080191aaba9611.zip kdepimpi-16e87ac5b81352c51343715cf1080191aaba9611.tar.gz kdepimpi-16e87ac5b81352c51343715cf1080191aaba9611.tar.bz2 |
ff
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index f52cedb..7e2aec1 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp @@ -1,272 +1,279 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Mike Pilone <mpilone@slac.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qlayout.h> #include <qlabel.h> #include <qtooltip.h> #include <qpushbutton.h> #include <qcheckbox.h> #include <qstring.h> #include <qlistbox.h> #include <qlistview.h> #include <qbuttongroup.h> #include <qhbox.h> #include <qcursor.h> #include <qtimer.h> +#include <qapplication.h> #include <kbuttonbox.h> #include <klistview.h> #include <kapplication.h> #include <qapplication.h> #include <kconfig.h> #include <klineedit.h> #include <kcombobox.h> #include <klocale.h> #include <kdebug.h> #include <kglobal.h> #include <kiconloader.h> #include <kabc/phonenumber.h> #include "typecombo.h" #include "phoneeditwidget.h" PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) : QWidget(parent,name) { QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); QLabel *temp = new QLabel( "", this ); temp->setAlignment( Qt::AlignCenter ); temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); - gridLayout->addWidget( temp, 1, 0 ); QPushButton *addBut = new QPushButton ( "add", this ); addBut->setPixmap ( SmallIcon("plus")); addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); - gridLayout->addWidget( addBut, 0, 0 ); sv = new QScrollView( this ); sv->setFrameStyle ( QFrame::Panel | QFrame::Plain ); sv->setLineWidth ( 1 ); sv->setMidLineWidth ( 1 ); mw = new QWidget ( sv->viewport() ); sv->addChild(mw); sv->setResizePolicy( QScrollView::AutoOneFit ); mainLayout = new QVBoxLayout ( mw ); mainLayout->setMargin( 0 ); mainLayout->setSpacing( 0 ); + if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { + gridLayout->addWidget( addBut, 0, 0 ); + gridLayout->addWidget( temp, 0, 1 ); + gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); + } else { + gridLayout->addWidget( temp, 1, 0 ); + gridLayout->addWidget( addBut, 0, 0 ); gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); + } setDefaults(); mTypeNumberEditList.setAutoDelete( true ); mPopup = new QPopupMenu( this ); QStringList list = PhoneNumber::supportedTypeListNames(); mPopupCount = list.count(); int i = 0; while ( i < mPopupCount ) { mPopup->insertItem( list[ i ], i ); ++i; } connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); } PhoneEditWidget::~PhoneEditWidget() { } void PhoneEditWidget::setDefaults() { mTypeNumberEditList.clear(); PhoneTypeNumberEdit* edit = appendEditCombo(); KABC::PhoneNumber phoneNumber; phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); edit->setPhoneNumber( phoneNumber ); edit = appendEditCombo(); phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); edit->setPhoneNumber( phoneNumber ); edit = appendEditCombo(); phoneNumber.setType( KABC::PhoneNumber::Cell ); edit->setPhoneNumber( phoneNumber ); } void PhoneEditWidget::addNumberInt( int index ) { PhoneTypeNumberEdit* edit = appendEditCombo(); KABC::PhoneNumber phoneNumber; phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); edit->setPhoneNumber( phoneNumber ); //verticalScrollBar()->setValue( 1024); QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); } void PhoneEditWidget::bottomVisible() { sv->setContentsPos ( 0, 1024 ); } void PhoneEditWidget::addNumber() { int i = 0; while ( i < mPopupCount ) { mPopup->setItemEnabled( i, true ); ++i; } PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); while ( edit ) { if ( edit->currentType() < mPopupCount -1 ) mPopup->setItemEnabled( edit->currentType(), false ); edit = mTypeNumberEditList.next(); } mPopup->popup( QCursor::pos() ); } PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() { PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); mainLayout->add( edit ); mTypeNumberEditList.append( edit ); return edit; } void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) { mPendingDelete = ew; QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); } void PhoneEditWidget::pendingDelete() { mTypeNumberEditList.removeRef( mPendingDelete ); emit modified(); } void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) { if ( li.isEmpty() ) { setDefaults(); return; } mTypeNumberEditList.clear(); KABC::PhoneNumber::List::Iterator it; KABC::PhoneNumber::List list2 = li; KABC::PhoneNumber::List list ; PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList(); int i = 0; int max = tList.count(); while ( i < max-1 ) { for ( it = list2.begin(); it != list2.end(); ++it ) { if ( (*it).type() == tList[i] ) { list.append( (*it ) ); break; } } ++i; } for ( it = list2.begin(); it != list2.end(); ++it ) { if ( (*it).type() == tList[ max-1 ] ) list.append( (*it ) ); } for ( it = list.begin(); it != list.end(); ++it ) { PhoneTypeNumberEdit* editNew = appendEditCombo(); editNew->setPhoneNumber( (*it ) ); } } KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() { KABC::PhoneNumber::List retList; PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); while ( edit ) { if ( edit->isValid() ) { retList.append( edit->phoneNumber()); } edit = mTypeNumberEditList.next(); } return retList; } #if 0 PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) { QGridLayout *layout = new QGridLayout( this, 4, 1 ); //US layout->setSpacing( KDialog::spacingHint() ); layout->setSpacing( KDialogBase::spacingHintSmall() ); QLabel* label = new QLabel( this ); //US loadIcon call is ambiguous. Add one more parameter //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); label->setAlignment( AlignCenter ); //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); layout->addWidget( label, 0, 0 ); QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), this ); if ( QApplication::desktop()->width() < 640 ) layout->addWidget( editButton, 0, 1 ); else layout->addMultiCellWidget( editButton, 0, 0, 1, 3); mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); mPrefEdit = new KLineEdit( this ); //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); mPrefCombo->setLineEdit( mPrefEdit ); layout->addWidget( mPrefCombo, 1, 0 ); layout->addWidget( mPrefEdit, 1, 1 ); int x = 1, y = 2; if ( QApplication::desktop()->width() < 640 ) { ++x; y = 0; } mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); mSecondEdit = new KLineEdit( this ); mSecondCombo->setLineEdit( mSecondEdit ); layout->addWidget( mSecondCombo, x, y++ ); layout->addWidget( mSecondEdit, x, y++ ); y = 0; ++x; mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); mThirdEdit = new KLineEdit( this ); mThirdCombo->setLineEdit( mThirdEdit ); layout->addWidget( mThirdCombo, x, y++ ); layout->addWidget( mThirdEdit, x, y++ ); if ( QApplication::desktop()->width() < 640 ) { ++x; y = 0; } mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); mFourthEdit = new KLineEdit( this ); mFourthCombo->setLineEdit( mFourthEdit ); layout->addWidget( mFourthCombo, x, y++ ); layout->addWidget( mFourthEdit, x, y++ ); // Four numbers don't fit in the current dialog |