abeditor.cpp
来自「Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3」· C++ 代码 · 共 2,205 行 · 第 1/5 页
CPP
2,205 行
fAffix = formattedAffix( tokens[i], suffixes ); if( i < tokCount && !isQuote( tokens[i][0] ) && fAffix.length() ) { suffix = fAffix; ++i; } if( i < tokCount && isQuote( tokens[i][0] ) ) { QString proStr = stripQuotes( tokens[i++] ); QStringList proTok = QStringList::split( " ", proStr ); firstNamePro = proTok[1]; // pro specified in name order of the rule lastNamePro = proTok[0]; } } else if( tokCount == 1 || (tokCount >= 2 && (formattedAffix( tokens[1], suffixes ).length() || isQuote( tokens[1][0] ))) ) { // rule 3 firstName = tokens[i++]; QString fAffix = formattedAffix( tokens[i], suffixes ); if( i < tokCount && fAffix.length() ) { suffix = fAffix; ++i; } if( i < tokCount && isQuote( tokens[i][0] ) ) { QString proStr = stripQuotes( tokens[i++] ); QStringList proTok = QStringList::split( " ", proStr ); firstNamePro = proTok[0]; } } else if( formattedAffix( tokens[0], prefixes ).length() && (tokCount == 2 || (tokCount >= 3 && (formattedAffix( tokens[2], suffixes ) || isQuote( tokens[2][0] )))) ) { // rule 2 prefix = formattedAffix(tokens[i++], prefixes); lastName = tokens[i++]; QString fAffix = formattedAffix( tokens[i], suffixes ); if( i < tokCount && fAffix.length() ) { suffix = fAffix; ++i; } if( i < tokCount && isQuote( tokens[i][0] ) ) { QString proStr = stripQuotes( tokens[i++] ); QStringList proTok = QStringList::split( " ", proStr ); lastNamePro = proTok[0]; } } else { // rule 1 // because this is the default rule, check to make sure we have // tokens for everything we process (i < tokCount) // so if the user enters Mr. Marc ("The Dude") it doesn't require or // assume there's a Britton token remaining if( i < tokCount ) { QString fAffix = formattedAffix( tokens[i], prefixes ); if( fAffix.length() ) { prefix = fAffix; ++i; } } if( i < tokCount ) firstName = tokens[i++]; if( i < tokCount && tokens[i] == "(" ) { ++i; nickName = tokens[i++]; ++i; // skip closing ) } if( (i+1) < tokCount && !formattedAffix( tokens[i+1], suffixes ).length() && !isQuote( tokens[i+1][0] ) ) middleName = tokens[i++]; if( i < tokCount ) lastName = tokens[i++]; if( i < tokCount ) { QString fAffix = formattedAffix( tokens[i], suffixes ); if( fAffix.length() ) { suffix = fAffix; ++i; } } if( i < tokCount && isQuote( tokens[i][0] ) ) { QString proStr = stripQuotes( tokens[i++] ); QStringList proTok = QStringList::split( " ", proStr ); firstNamePro = proTok[0]; lastNamePro = proTok[1]; } }// QString prefix, suffix, firstName, nickName, middleName, lastName, firstNamePro, lastNamePro; QMap<PimContact::ContactFields, QString> newFields; newFields[PimContact::NameTitle] = prefix; newFields[PimContact::FirstName] = firstName; newFields[PimContact::FirstNamePronunciation] = firstNamePro; newFields[PimContact::MiddleName] = middleName; newFields[PimContact::LastName] = lastName; newFields[PimContact::LastNamePronunciation] = lastNamePro; newFields[PimContact::Suffix] = suffix; newFields[PimContact::Nickname] = nickName; newFields[PimContact::FileAs] = myFields[PimContact::FileAs]; //copy this value across myFields = newFields; /* const QMap<int, QString> &displayNames = PimContact::trFieldsMap(); // use field names from PimContact QMap<PimContact::ContactFields, QString>::Iterator it; for( it = myFields.begin(); it != myFields.end() ; ++it ) if( !(*it).isEmpty() ) qDebug("%s : %s\n", displayNames[ it.key() ].latin1(), (*it).latin1()); qDebug("LastNamePronunciation = %s\n", myFields[PimContact::LastNamePronunciation].latin1()); */}QString AbstractName::formattedAffix( const QString &str, QStringList &affixes ){ QString ia = str.lower(); if( ia.isEmpty() ) return QString::null; bool lastCharPeriod = ia[(int)ia.length()-1] == '.'; for( QStringList::Iterator it = affixes.begin() ; it != affixes.end() ; ++it ) { QString curAffix = (*it).lower(); if( ia == curAffix || lastCharPeriod && ia == (curAffix+".") ) return *it; } return QString::null;}QString AbstractName::stripQuotes( const QString &pro ){ QString str = pro; str = str.left( str.length()-1 ); return str.right( str.length()-1 );}bool AbstractName::isQuote( QChar c ) const{ if( c == '\"' || c == '\'' ) return TRUE; return FALSE;}void AbstractName::fieldsChanged(){ bool firstNameEmpty = myFields[PimContact::FirstName].isEmpty(), lastNameEmpty = myFields[PimContact::LastName].isEmpty(), nickEmpty = myFields[PimContact::Nickname].isEmpty(), firstProEmpty = myFields[PimContact::FirstNamePronunciation].isEmpty(), lastProEmpty = myFields[PimContact::LastNamePronunciation].isEmpty(); QString displayString; QTextOStream os(&displayString); if( firstNameEmpty ) { os << myFields[PimContact::NameTitle] << " " << myFields[PimContact::LastName] << " " << myFields[PimContact::Suffix] << " "; if( !lastProEmpty ) os << "\"" << myFields[PimContact::LastNamePronunciation] << "\""; } else if( lastNameEmpty ) { os << myFields[PimContact::FirstName] << " " << myFields[PimContact::Suffix] << " "; if( !firstProEmpty ) os << "\"" << myFields[PimContact::FirstNamePronunciation] << "\""; } else { os << myFields[PimContact::NameTitle] << " " << myFields[PimContact::FirstName] << " "; if( !nickEmpty ) os << "(" << myFields[PimContact::Nickname] << ") "; os << myFields[PimContact::MiddleName] << " " << myFields[PimContact::LastName] << " " << myFields[PimContact::Suffix] << " "; if( !firstProEmpty && !lastProEmpty ) { os << "\"" << myFields[PimContact::FirstNamePronunciation] << " " << myFields[PimContact::LastNamePronunciation] << "\""; } } displayString = displayString.simplifyWhiteSpace(); mainWidget->setText( displayString );}void AbstractName::textChanged(){ if( mHaveFieldsPrevChanged ) // have the fields changed previously? { mModified = TRUE; } else // allow for the initial setting of fields { mHaveFieldsPrevChanged = TRUE; }}//----------------------------------------------------------------------AbEditor::AbEditor( QWidget *parent, const char *name, WFlags fl ) : QDialog( parent, name, TRUE, fl )#ifdef QTOPIA_PHONE , mHaveSim( FALSE )#endif{ setName( "edit" ); mNewEntry = FALSE; phoneMan = 0; specCompanyLA = 0; lastUpdateInternal = FALSE; init(); resize( 400, 500 );}AbEditor::~AbEditor(){}void AbEditor::setCategory(int id){ cmbCat->setCurrentCategory( id );}void AbEditor::init(){ quitExplicitly = FALSE; // NOTE : If you change these, you also need to change // AbEditor::phoneFieldsToDetailsFilter() and // AbEditor::detailsToPhoneFieldsFilter() mHPType = PhoneFieldType( "homephone", tr("Home Phone") ); mHMType = PhoneFieldType( "homemobile", tr("Home Mobile") ); mHFType = PhoneFieldType( "homefax", tr("Home Fax") ); mBPType = PhoneFieldType( "businessphone", tr("Business Phone") ); mBMType = PhoneFieldType( "businessmobile", tr("Business Mobile") ); mBFType = PhoneFieldType( "businessfax", tr("Business Fax") ); mBPAType = PhoneFieldType( "businesspager", tr("Business Pager") ); phoneTypes.append( mHPType ); phoneTypes.append( mHMType ); phoneTypes.append( mHFType ); phoneTypes.append( mBPType ); phoneTypes.append( mBMType ); phoneTypes.append( mBFType ); phoneTypes.append( mBPAType ); setupTabs(); setTabOrders(); buildLineEditList(); // create a map of QLineEdit pointers for iterating through. // used in AbEditor::isEmpty() QWhatsThis::add(spouseLE, tr("e.g. Husband or Wife.")); QWhatsThis::add(professionLE, tr("Occupation or job description.")); /* MB : now belongs to abstract editor */#if 0 QWhatsThis::add(lineEdits[PimContact::FirstNamePronunciation], tr("Describes the spoken name phonetically.")); QWhatsThis::add(fileAsCombo, tr("Preferred format for the contact name."));#endif #ifdef QTOPIA_DESKTOP tabs->setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum) ); setMinimumSize( tabs->sizeHint().width(), tabs->sizeHint().height() ); setMaximumSize( tabs->sizeHint().width()*2, tabs->sizeHint().height()*2 );#endif new QPEDialogListener(this);}void AbEditor::setTabOrders(void){#if 0 setTabOrder(fileAsCombo, cmbCat); setTabOrder(cmbCat, emailLE); setTabOrder(emailLE, emailBtn); setTabOrder(emailBtn, bdayButton); setTabOrder(bdayButton, genderCombo);#endif // TODO : set tab orders}void AbEditor::tabClicked( QWidget *tab ){#ifdef QTOPIA_DESKTOP if ( summaryTab && tab == summaryTab ) { PimContact c; contactFromFields(c); summary->setText(c.toRichText()); }#else Q_UNUSED(tab);#endif}void AbEditor::editEmails(){ EmailDialog *ed = new EmailDialog(this, "Emails", TRUE); QString strDefaultEmail; QStringList emails; parseEmailFrom( emailLE->text(), strDefaultEmail, emails ); //ent.setDefaultEmail( strDefaultEmail ); //ent.setEmailList( emails ); ed->setEmails( strDefaultEmail, emails );#ifdef QTOPIA_DESKTOP if (ed->exec())#else if (QPEApplication::execDialog(ed))#endif { ent.setDefaultEmail(ed->defaultEmail()); ent.setEmailList(ed->emails()); QString str; parseEmailTo( ed->defaultEmail(), ed->emails(), str ); emailLE->setText( str ); emailLE->home( false ); } delete ed;}#ifdef QTOPIA_PHONEvoid AbEditor::setHaveSim( bool b ){ mHaveSim = b; homePhoneOnSim->setEnabled( b ); homeFaxOnSim->setEnabled( b ); homeMobileOnSim->setEnabled( b ); busPhoneOnSim->setEnabled( b ); busFaxOnSim->setEnabled( b ); busMobileOnSim->setEnabled( b ); busPagerOnSim->setEnabled( b ); phoneMan->setHaveSim( b ); if( b ) { bool hpos = (ent.customField( AbUtil::SIM_HP ).isEmpty() ? FALSE : TRUE), hfos = (ent.customField( AbUtil::SIM_HF ).isEmpty() ? FALSE : TRUE), hmos = (ent.customField( AbUtil::SIM_HM ).isEmpty() ? FALSE : TRUE), bpos = (ent.customField( AbUtil::SIM_BP ).isEmpty() ? FALSE : TRUE), bfos = (ent.customField( AbUtil::SIM_BF ).isEmpty() ? FALSE : TRUE), bmos = (ent.customField( AbUtil::SIM_BM ).isEmpty() ? FALSE : TRUE), bpaos = (ent.customField( AbUtil::SIM_BPA ).isEmpty() ? FALSE : TRUE); //set the toggle actions for both the phone manager and details, because toggled() doesn't already get emitted phoneMan->setFieldOnSim( mHPType, hpos ); phoneMan->setFieldOnSim( mHFType, hfos ); phoneMan->setFieldOnSim( mHMType, hmos ); phoneMan->setFieldOnSim( mBPType, bpos ); phoneMan->setFieldOnSim( mBFType, bfos ); phoneMan->setFieldOnSim( mBMType, bmos ); phoneMan->setFieldOnSim( mBPAType, bpaos ); homePhoneOnSim->setOn( hpos ); homeFaxOnSim->setOn( hfos ); homeMobileOnSim->setOn( hmos ); busPhoneOnSim->setOn( bpos ); busFaxOnSim->setOn( bfos ); busMobileOnSim->setOn( bmos ); busPagerOnSim->setOn( bpaos ); }}#endifvoid AbEditor::setupTabs(){ QVBoxLayout *vb = new QVBoxLayout( this ); // setup tab groups tabs = new QTabWidget( this ); vb->addWidget( tabs ); contactTab = new VScrollView( tabs ); businessTab = new VScrollView( tabs ); personalTab = new VScrollView( tabs ); otherTab = new VScrollView( tabs ); tabs->addTab( contactTab, Resource::loadIconSet( "addressbook/contactdetails" ), #ifdef QTOPIA_DESKTOP tr("Contact")#else ""#endif ); tabs->addTab( businessTab, Resource::loadIconSet( "business" ), #ifdef QTOPIA_DESKTOP tr("Business")#else "" #endif ); tabs->addTab( personalTab, Resource::loadIconSet( "home" ), #ifdef QTOPIA_DESKTOP tr("Personal")#else "" #endif ); tabs->addTab( otherTab, Resource::loadIconSet( "addressbook/notes" ), #ifdef QTOPIA_DESKTOP tr("Other")#else "" #endif );#ifdef QTOPIA_DESKTOP // ### Should use summary tab if has room, not // just compiled for the desktop summaryTab = new QWidget( tabs, "summaryTab" ); tabs->addTab( summaryTab, tr("Summary") ); connect( tabs, SIGNAL( currentChanged(QWidget*) ), SLOT( tabClicked(QWidget*) ) ); QVBoxLayout *vbSummary = new QVBoxLayout( summaryTab, 5, 5 ); summary = new QTextEdit( summaryTab ); summary->setReadOnly( TRUE ); vbSummary->addWidget( summary );#else summaryTab = 0; summary = 0;#endif // Create widgets on tabs
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?