abeditor.cpp
来自「Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3」· C++ 代码 · 共 2,205 行 · 第 1/5 页
CPP
2,205 行
for( ; *it ; ++it ) if( (*it)->isEmpty() ) full = FALSE; } return full;}void PhoneFieldManager::add( const QString &number, const PhoneFieldType &type ){ if ( number.isEmpty() || isFull() ) return; PhoneField *eField = 0; QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) { PhoneFieldType t( (*it)->type() ); if( t == type ) { eField = (*it); break; } } if( eField ) { eField->setNumber( number ); } else { for( it.toFirst() ; *it ; ++it ) { if( (*it)->isEmpty() ) { (*it)->setType( type ); (*it)->setNumber( number ); break; } } }}void PhoneFieldManager::addEmpty(){ if ( isFull() ) return; QValueList<PhoneFieldType> availTypes = mTypes; QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) { PhoneFieldType t( (*it)->type() ); availTypes.remove( t ); } PhoneField *nf = new PhoneField( parLayout, rowCount, (QWidget *)parent() ); phoneFields.append( nf ); nf->setTypes( mTypes ); nf->setType( availTypes.first() ); connect( nf, SIGNAL(userChangedType(const PhoneFieldType&)), this, SLOT(updateTypes(const PhoneFieldType &)) ); connect( nf, SIGNAL(numberChanged(const QString&)), this, SLOT(checkForAdd()) ); connect( nf, SIGNAL(fieldChanged(const QString&,const PhoneFieldType&)), this, SLOT(emitFieldChanged(const QString&,const PhoneFieldType&)) );#ifdef QTOPIA_PHONE connect( nf, SIGNAL(fieldOnSim(bool,const PhoneFieldType&)), this, SIGNAL(fieldOnSim(bool,const PhoneFieldType&)) );#endif}void PhoneFieldManager::emitFieldChanged( const QString &str, const PhoneFieldType &type ){ if( mEmitFieldChanged ) emit fieldChanged( str, type );}void PhoneFieldManager::setTypes( const QValueList<PhoneFieldType> &newTypes ){ if( phoneFields.count() > newTypes.count() ) { qDebug("BUG : phoneFields.count() > newTypes.count()\n"); return; } mTypes = newTypes; QValueList<PhoneFieldType> availTypes = newTypes; QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) { (*it)->setTypes( mTypes ); if( !availTypes.contains( (*it)->type() ) ) { if( !availTypes.count() ) qDebug("BUG : Not enough types for phone fields."); PhoneFieldType nt = availTypes.first(); (*it)->setType( nt ); availTypes.remove( nt ); } }}QValueList<PhoneFieldType> PhoneFieldManager::types() const{ return mTypes;}void PhoneFieldManager::updateTypes( const PhoneFieldType &newType ){ const QObject *s = sender(); // the phone field whose type has changed QValueList<PhoneFieldType> availTypes = mTypes; QList<PhoneField> changedFields; QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) availTypes.remove( (*it)->type() ); mEmitFieldChanged = FALSE; for( it.toFirst() ; *it ; ++it ) { if( (QObject *)(*it) == s ) continue; if( (*it)->type() == newType ) { if( !availTypes.count() ) qDebug("BUG : Not enough types for phone fields."); PhoneFieldType nt = availTypes.first(); (*it)->setType( nt ); availTypes.remove( nt ); changedFields.append( *it ); } } mEmitFieldChanged = TRUE; //emit field changed signals only after we've rearranged QListIterator<PhoneField> cit( changedFields ); for( ; *cit ; ++cit ) emitFieldChanged( (*cit)->number(), (*cit)->type() );}#ifdef QTOPIA_PHONEvoid PhoneFieldManager::setHaveSim( bool b ){ QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) (*it)->setHaveSim( b );}#endifvoid PhoneFieldManager::checkForAdd(){ QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) if( (*it)->isEmpty() ) return; addEmpty();}void PhoneFieldManager::setNumberFromType( const PhoneFieldType &type, const QString &newNumber ){ QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) { if( (*it)->type() == type ) { (*it)->setNumber( newNumber ); break; } } //no fields matching, add a field add( newNumber, type );}QString PhoneFieldManager::numberFromType( const PhoneFieldType &type ){ QListIterator<PhoneField> it(phoneFields); for( ; *it ; ++it ) if( (*it)->type() == type ) return (*it)->number(); return QString("");}PhoneFieldLineEdit::PhoneFieldLineEdit( QWidget *typeSibling, QWidget *parent, const char *name ) : QLineEdit( parent, name ), mTypeSibling( typeSibling ){ mTypeSibling->installEventFilter( this );}bool PhoneFieldLineEdit::eventFilter( QObject *o, QEvent *e ){ if( o == mTypeSibling && e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent *)e; if( !ke->text().isEmpty() ) { setFocus(); appendText( ke->text() ); return TRUE; } } return FALSE;}void PhoneFieldLineEdit::appendText( const QString &txt ){#ifdef QTOPIA_PHONE if( !Global::mousePreferred() ) { if( !isModalEditing() ) setModalEditing( TRUE ); }#endif setText( text()+txt );}PhoneField::PhoneField( QGridLayout *l, int &rowCount, QWidget *parent, const char *name ) : QObject( parent, name ){// label = new QLabel( parent );// label->show(); /* QHBox *hBox = new QHBox( parent ); hBox->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred) ); hBox->setBackgroundColor( QColor( 0, 0, 255 ) ); */#ifndef QTOPIA_DESKTOP typeIS = new IconSelect( parent ); typeIS->setDisplaySize( QSize( 24, 16) );#else typeIS = new QComboBox( FALSE, parent );#endif connect( typeIS, SIGNAL(activated(int)), this, SLOT(userChangedType(int)) ); numberLE = new PhoneFieldLineEdit( typeIS, parent ); connect( numberLE, SIGNAL(textChanged(const QString&)), this, SIGNAL(numberChanged(const QString&)) ); QPEApplication::setInputMethodHint(numberLE,QPEApplication::PhoneNumber);#ifdef QTOPIA_PHONE ContextMenu *menu = ContextMenu::menuFor( numberLE ); simAction = addStoreOnSim(menu, this, SLOT(emitFieldOnSim(bool)));#endif/* l->addWidget( label, rowCount, 0 ); l->addWidget( hBox, rowCount, 2 );*/ l->addWidget( typeIS, rowCount, 0, AlignHCenter ); l->addWidget( numberLE, rowCount, 2 );// l->addMultiCellWidget( hBox, rowCount, rowCount, 0, 2 ); ++rowCount;// hBox->show(); numberLE->show(); typeIS->show(); connect( this, SIGNAL(numberChanged(const QString&)), this, SLOT(emitFieldChanged()) ); connect( this, SIGNAL(internalChangedType(const PhoneFieldType&)), this, SIGNAL(typeChanged(const PhoneFieldType&)) ); connect( this, SIGNAL(userChangedType(const PhoneFieldType&)), this, SIGNAL(typeChanged(const PhoneFieldType&)) ); connect( this, SIGNAL(typeChanged(const PhoneFieldType&)), this, SLOT(emitFieldChanged()) );}#ifdef QTOPIA_PHONEvoid PhoneField::setHaveSim( bool b ){ simAction->setEnabled( b );}#endifvoid PhoneField::emitFieldOnSim( bool f ){#ifdef QTOPIA_PHONE simAction->setOn( f ); emit fieldOnSim( f, type() );#else Q_UNUSED( f );#endif}#ifdef QTOPIA_PHONEvoid PhoneField::setOnSim( bool onSim ){ simAction->setOn( onSim );}bool PhoneField::onSim() const{ return simAction->isOn();}#endifPhoneField::~PhoneField(){ delete typeIS; delete numberLE;}void PhoneField::userChangedType( int /* idx */){ emit userChangedType( mTypes[typeIS->currentItem()] );}void PhoneField::setTypes( const QValueList<PhoneFieldType> &types ){ typeIS->clear(); mTypes = types; QValueList<PhoneFieldType>::ConstIterator it; for( it = mTypes.begin() ; it != mTypes.end() ; ++it ) { QPixmap p = (*it).pixmap; typeIS->insertItem( p, (*it).name ); } emit internalChangedType( mTypes[typeIS->currentItem()] );}void PhoneField::setType( const PhoneFieldType &newType ){ PhoneFieldType t(newType); int idx = mTypes.findIndex( t ); if( idx != -1 ) typeIS->setCurrentItem( idx ); }PhoneFieldType PhoneField::type(){ return mTypes[typeIS->currentItem()];}QString PhoneField::number() const{ return numberLE->text();}bool PhoneField::isEmpty() const{ return number().stripWhiteSpace().isEmpty();}void PhoneField::setNumber( const QString &newNumber ){ numberLE->setText( newNumber );}void PhoneField::emitFieldChanged(){ emit fieldChanged( numberLE->text(), mTypes[typeIS->currentItem()] );}//-----------------------------------------------------------------------//FIXME : This is crap iterative widget creation that has survived from the rewrite. //now that address parsing has gone, make this into AbNameDetails dialogAbDetailEditor::AbDetailEditor( QWidget *parent, const char *name, WFlags fl ) : QDialog( parent, name, TRUE, fl ), fileAsCombo(0), suffixCombo(0), titleCombo(0){ mView = new VScrollView( this ); editorLayout = new QVBoxLayout( this ); editorLayout->addWidget( mView );#ifdef QTOPIA_DESKTOP editorLayout->setResizeMode( QLayout::FreeResize ); setMinimumSize( sizeHint().width()*2, sizeHint().height()*3 ); setMaximumSize( sizeHint().width()*4, sizeHint().height()*6 ); QHBoxLayout *buttonLayout = new QHBoxLayout( editorLayout ); QPushButton *okButton = new QPushButton( tr("OK"), this ); QPushButton *cancelButton = new QPushButton( tr("Cancel"), this ); connect( okButton, SIGNAL(clicked()), this, SLOT(accept()) ); connect( cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); buttonLayout->addStretch(); buttonLayout->addWidget( okButton ); buttonLayout->addWidget( cancelButton );#endif}AbDetailEditor::~AbDetailEditor(){}void AbDetailEditor::accept(){ QMap<PimContact::ContactFields, QString> newFields; for ( QMap<PimContact::ContactFields, QString>::Iterator it = myFields.begin(); it != myFields.end(); ++it ) { switch ( it.key() ) { case PimContact::Suffix: myFields[PimContact::Suffix] = suffixCombo->currentText(); break; case PimContact::NameTitle: myFields[PimContact::NameTitle] = titleCombo->currentText(); break; case PimContact::FileAs: { myFields[PimContact::FileAs] = fileAsCombo->selected(); break; } default: { myFields[ it.key() ] = lineEdits[ it.key() ]->text(); break; } } } QDialog::accept();}/* Determines the type of field we're editing and returns a valuelist which is used to create the GUI elements */QValueList<PimContact::ContactFields> AbDetailEditor::guiValueList( const QMap<PimContact::ContactFields, QString> &f ) const{ QValueList<PimContact::ContactFields> gvl; if( f.contains( PimContact::NameTitle ) ) // editing a name field { gvl += PimContact::NameTitle; gvl += PimContact::FirstName; gvl += PimContact::FirstNamePronunciation; gvl += PimContact::MiddleName; gvl += PimContact::LastName; gvl += PimContact::LastNamePronunciation; gvl += PimContact::Suffix; gvl += PimContact::Nickname; gvl += PimContact::FileAs; } return gvl;}static void adjustPronWidgets(QLabel* label, QLineEdit* le){ label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); QFont sm = label->font();#ifndef QTOPIA_DESKTOP sm.setPointSize(sm.pointSize()/2); le->setFont(sm);#else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?