⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abtable.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    l = 0;    u = rows;    while (l < u)    {	r = (l + u) / 2;	QString first = contacts->sortedContacts().at(r)->bestLabel().lower();	//QString first = contacts->sortedContacts().at(r).bestLabel().lower();	comparison = Qtopia::compare(cl, first);	if (comparison < 0)	    u = r;	else if (comparison > 0)	    l = r + 1;	else	    break;    }    if ( comparison > 0) {	if ( l == rows )	    r = rows - 1;// last element...	else	    r++;    }    setCurrentCell( r, currentColumn() );}QString AbTable::findContactName( const PimContact &entry ){    // We use the fileAs, then company, defaultEmail    return entry.bestLabel();}QString AbTable::findContactContact( const PimContact &entry ){    const int idList[] = {	PimContact::DefaultEmail,	PimContact::BusinessMobile,	PimContact::BusinessPhone,	PimContact::BusinessStreet,	PimContact::Company,	PimContact::HomeMobile,	PimContact::HomePhone,	PimContact::HomeStreet,	-1    };    QString value;    // try to get the preferred entry    switch (prefField) {	default:	case PimContact::DefaultEmail:	    value = getField(entry, PimContact::DefaultEmail);	    break;	case PimContact::HomePhone:	    value = getField(entry, PimContact::HomePhone);	    if (value.isEmpty())		value = getField(entry, PimContact::HomeMobile);	    if (value.isEmpty())		value = getField(entry, PimContact::BusinessMobile);	    break;	case PimContact::HomeMobile:	    value = getField(entry, PimContact::HomeMobile);	    if (value.isEmpty())		value = getField(entry, PimContact::BusinessMobile);	    if (value.isEmpty())		value = getField(entry, PimContact::HomePhone);	    break;	case PimContact::BusinessPhone:	    value = getField(entry, PimContact::BusinessPhone);	    if (value.isEmpty())		value = getField(entry, PimContact::BusinessMobile);	    if (value.isEmpty())		value = getField(entry, PimContact::HomeMobile);	    break;	case PimContact::BusinessMobile:	    value = getField(entry, PimContact::BusinessMobile);	    if (value.isEmpty())		value = getField(entry, PimContact::HomeMobile);	    if (value.isEmpty())		value = getField(entry, PimContact::BusinessPhone);	    break;    }    if (value.isEmpty()) {	// try to get a sensible entry	for (int i = 0; idList[i] >= 0; i++) {	    QString v = getField( entry, idList[i] );	    if ( !v.isEmpty() ) {		value = v.simplifyWhiteSpace();		break;	    }	}    }    return value;}QString AbTable::getField( const PimContact &entry, int key ){    QString res = entry.field( key );    QString type;     if ( !res.isEmpty() )	switch ( key ) {	case PimContact::DefaultEmail:	    // type = tr("E: ","Short title for Default email address");	    // break;	    return QString(res); // Had to do this because of text freeze - Luke	case PimContact::HomePhone:	    type = tr("H: ","Short title for Home phone");	    break;	case PimContact::BusinessPhone:	    type = tr("B: ","Short title for Business phone");	    break;	case PimContact::HomeMobile:	    type = tr("HM: ","Short title for Home mobile");	    break;	case PimContact::BusinessMobile:	    type = tr("BM: ","Short title for Business mobile");	    break;	}    if ( !type.isEmpty() )	res = type + res;    return res;}static bool contactCompare( const PimContact &cnt, const QRegExp &r, int category );void AbTable::findNext( const QString &findString, int category ){    static bool wrapAround = false;    if ( currFindString != findString ) {	currFindRow = -1;	wrapAround = false;    }    currFindString = findString;    if ( currFindRow < -1 )	currFindRow = currentRow() - 1;    clearSelection( TRUE );    int rows,        row;    QRegExp r( findString );    r.setCaseSensitive( FALSE );    rows = numRows();    for ( row = currFindRow + 1; row < rows; row++ ) {	if ( contactCompare( *(contacts->sortedContacts().at(row)), r, category ) )	    break;    }    if ( row >= rows ) {	currFindRow = -1;	if ( wrapAround )	    emit findWrapAround();	else	    emit findNotFound();    } else {	currFindRow = row;	QTableSelection foundSelection;	foundSelection.init( currFindRow, 0 );	foundSelection.expandTo( currFindRow, numCols() - 1 );	addSelection( foundSelection );	setCurrentCell( currFindRow, currentColumn());	emit findFound();	wrapAround = true;    }}static bool contactCompare( const PimContact &cnt, const QRegExp &r, int category ){    bool returnMe;    QArray<int> cats;    cats = cnt.categories();    returnMe = false;    if ( (category == -1 && cats.count() == 0) || category == -2 )	returnMe = cnt.match( r );    else {	int i;	for ( i = 0; i < int(cats.count()); i++ ) {	    if ( cats[i] == category ) {		returnMe = cnt.match( r );		break;	    }	}    }    return returnMe;}#if QT_VERSION <= 230#ifndef SINGLE_APPvoid QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ){    // Region of the rect we should draw    QRegion reg( QRect( cx, cy, cw, ch ) );    // Subtract the table from it    reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) );    // And draw the rectangles (transformed as needed)    QArray<QRect> r = reg.rects();    for (unsigned int i=0; i<r.count(); i++)        p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) );}#endif#endifvoid AbTable::fontChange( const QFont &oldFont ){    QFont f = font();    QFontMetrics fm(f);    RowHeight = QMAX(18, fm.height() + 2);    QTable::fontChange(oldFont);}int AbTable::rowHeight( int ) const{    return RowHeight;}int AbTable::rowPos( int row ) const{    return RowHeight*row;}int AbTable::rowAt( int pos ) const{    return QMIN( pos/RowHeight, numRows()-1 );}void AbTable::show(){    QTable::show();}void AbTable::itemClicked(int,int /* col */){    emit clicked();}void AbTable::slotDoubleClicked(int, int, int, const QPoint &){    emit doubleClicked();}void AbTable::slotCurrentChanged( int row, int ){    bool needRefresh = FALSE;    if ( mSel == Extended ) {	if ( (bState & Qt::LeftButton) ) {	    if ( selectionBeginRow == -1 )		selectionBeginRow = row;	    else		setSelection( selectionBeginRow, row);	    needRefresh = TRUE;	} else {	    mSelected.clear();	    needRefresh = TRUE;	}    }    if ( needRefresh ) {	refresh();    }    emit currentChanged();}void AbTable::setPreferredField( int id ){    prefField = id;}void AbTable::setPaintingEnabled( bool e ){    if ( e != enablePainting ) {	if ( !enablePainting ) {	    enablePainting = true;	    rowHeightChanged( 0 );	    viewport()->update();	} else {	    enablePainting = false;	}    }}void AbTable::rowHeightChanged( int row ){    if ( enablePainting )	QTable::rowHeightChanged( row );}void AbTable::setFields(QValueList<int> f){    QHeader *header = horizontalHeader();    QStringList sizes;    if ( f.count() == 0 ) {	f = defaultFields();	headerKeyFields.clear();    }    // map old sizes to new pos in header list    for ( int i = 0; i < (int) f.count(); i++) {	int pos = headerKeyFields.findIndex( *f.at(i) );	if ( pos > -1 && pos < header->count() )	    sizes.append( QString::number( header->sectionSize(pos) ) );	else	    sizes.append( QString::number( defaultFieldSize( (PimContact::ContactFields) *f.at(i) ) ));    }    setFields(f, sizes);    if ( isVisible() )	fitHeadersToWidth();}void AbTable::setFields(QValueList<int> f, QStringList sizes){    QHeader *header = horizontalHeader();    int prevSortKey = -1;    if ( mSortColumn > -1 && headerKeyFields.count() )	prevSortKey = headerKeyFields[mSortColumn];    headerKeyFields = f;    while ( header->count() )	header->removeLabel( header->count() - 1 );    // We have to create the internal list before calling QTable::setNumCols as    // setnNumCols forces a repaint    QValueList<int>::Iterator iit;    int i = 0;    for (iit = f.begin(); iit != f.end(); ++iit) {	if ( *iit == prevSortKey ) {	    mSortColumn = i;	    break;	}	i++;    }    setNumCols( f.count() );    QMap<int, QString> trFields = PimContact::trFieldsMap();    i = 0;    for (iit = f.begin(); iit != f.end(); ++iit) {	if ( *iit == FREQ_CONTACT_FIELD )	    header->setLabel(i, tr("Contact") );	else	    header->setLabel(i, trFields[*iit] );	i++;    }    i = 0;    for (QStringList::ConstIterator it = sizes.begin(); it != sizes.end(); ++it) {	if ( i < (int) f.count() )	    setColumnWidth(i, (*it).toInt() );	i++;    }    if ( mSortColumn > -1 )	header->setSortIndicator(mSortColumn, !mAscending);}QValueList<int> AbTable::fields(){    return headerKeyFields;}QValueList<int> AbTable::defaultFields(){    QValueList<int> l;    l.append( PimContact::FileAs );    l.append( FREQ_CONTACT_FIELD );    return l;}int AbTable::defaultFieldSize(PimContact::ContactFields f){    switch( f ) {	case PimContact::FileAs: return 119;	case FREQ_CONTACT_FIELD: return 119;	default: return 80;    }}int AbTable::minimumFieldSize(PimContact::ContactFields){    return 40;}void AbTable::readSettings(){    QStringList selectedFields, sizeList;    {#ifdef QTOPIA_DESKTOP	QSettings settings;	settings.insertSearchPath( QSettings::Unix, applicationPath );	settings.insertSearchPath( QSettings::Windows, "/Trolltech" );	selectedFields = settings.readListEntry("/palmtopcenter/addressbook/fields" );	sizeList = settings.readListEntry("/palmtopcenter/addressbook/colwidths" );	mSortColumn = settings.readNumEntry("/palmtopcenter/addressbook/sortcolumn", 0);	mAscending = settings.readBoolEntry("/palmtopcenter/addressbook/ascending", FALSE);#else	Config config( "addressbook" );	config.setGroup( "View" );	selectedFields = config.readListEntry("fields", ',');	sizeList = config.readListEntry("colwidths",',');	mSortColumn = config.readNumEntry("sortcolumn", 0);	mAscending = config.readBoolEntry("ascending", FALSE);#endif    }    if ( !selectedFields.count() ) {	setFields( defaultFields() );    } else {	QMap<QCString, int> identifierToKey = PimContact::identifierToKeyMap();	for ( QStringList::Iterator it = selectedFields.begin(); it != selectedFields.end(); ++it) {	    if ( *it == "Contact" ) { // No tr		headerKeyFields.append( FREQ_CONTACT_FIELD );	    } else {		int field = identifierToKey[ (*it).data() ];		headerKeyFields.append( field );	    }	}	setFields( headerKeyFields, sizeList );    }    if ( mSortColumn > -1 ) {	reload(); 	horizontalHeader()->setSortIndicator(mSortColumn,!mAscending);    }    constructorDone = TRUE;    fitHeadersToWidth();    refresh();}void AbTable::saveSettings(){    QMap<int,QCString> keyToIdentifier = PimContact::keyToIdentifierMap();    QHeader *header = horizontalHeader();    QStringList fieldList, sizeList;    for ( int i = 0; i < header->count(); i++) {	if ( headerKeyFields[i] != FREQ_CONTACT_FIELD )	    fieldList.append( keyToIdentifier[ headerKeyFields[i]  ]  );	else	    fieldList.append( "Contact" ); // No tr	sizeList.append( QString::number(header->sectionSize(i)) );    }#ifdef QTOPIA_DESKTOP    QSettings settings;    settings.insertSearchPath( QSettings::Unix, applicationPath );    settings.insertSearchPath( QSettings::Windows, "/Trolltech" );    settings.writeEntry( "/palmtopcenter/addressbook/fields", fieldList );    settings.writeEntry( "/palmtopcenter/addressbook/colwidths", sizeList );    settings.writeEntry( "/palmtopcenter/addressbook/sortcolumn", mSortColumn );    settings.writeEntry( "/palmtopcenter/addressbook/ascending", mAscending );#else    Config config( "addressbook" );    config.setGroup( "View" );    config.writeEntry("fields", fieldList, ',' );    config.writeEntry("colwidths", sizeList, ',' );    config.writeEntry("sortcolumn", mSortColumn );    config.writeEntry("ascending", mAscending );#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -