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

📄 abtable.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	if ( newColLen < min )	    newColLen =  min;	// make sure we fill out the space if there's some integer rounding leftover	if ( i == col - 1 && size - accumulated> min )	    newColLen = size - accumulated;	else	    accumulated += newColLen;	setColumnWidth( i, newColLen );    }    constructorDone = TRUE;#endif}void AbTable::moveTo( const QString &cl ){    int rows = numRows();    /////===========================    int l, u, r = 0;    int comparison=0;    l = 0;    u = rows;    while (l < u)    {	r = (l + u) / 2;	QString first = mSortedContacts.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 ){    // Not clear why this is preferred over fieldText    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;}#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();    QColorGroup::ColorRole empty = QColorGroup::Base;#ifdef QTOPIA_PHONE    if ( /*style().guiStyle() == KeyPadStyle && */ !isModalEditing() )	empty = QColorGroup::Background;#endif    for (unsigned int i=0; i<r.count(); i++)        p->fillRect( r[i], colorGroup().brush( empty ) );}#endif#endifvoid AbTable::fontChange( const QFont &oldFont ){    QFont f = font();    QFontMetrics fm(f);#ifdef PACK_IN_1_COLUMN    fnt[0] = font(); fnt[0].setBold(TRUE);    fnt[1] = differentFont(font(),-2); fnt[1].setBold(FALSE);    fnt[2] = differentFont(fnt[1],-2);    fitToSize();#else    rowH = QMAX(18, fm.height() + 2);#endif    QTable::fontChange(oldFont);}#ifdef PACK_IN_1_COLUMNvoid AbTable::paletteChange( const QPalette &p ){    QBrush hl = colorGroup().brush( QColorGroup::Highlight );    QBrush ba = colorGroup().brush( QColorGroup::Base );#if defined(Q_WS_QWS) || defined(_WS_QWS_)    if (style().extendedBrush(QStyle::AlternateBase).style() != NoBrush)	stripebrush = style().extendedBrush(QStyle::AlternateBase);    else #endif	stripebrush = ba;    QTable::paletteChange(p);}#endif#ifdef PACK_IN_1_COLUMNQFont AbTable::differentFont(const QFont& start, int step){    int osize = QFontMetrics(start).lineSpacing();    QFont f = start;    for (int t=1; t<6; t++) {	f.setPointSize(f.pointSize()+step);	step += step < 0 ? -1 : +1;	QFontMetrics fm(f);	if ( fm.lineSpacing() != osize )	    break;    }    return f;}#endifint AbTable::rowHeight( int ) const{    return rowH;}int AbTable::rowPos( int row ) const{    return rowH*row;}int AbTable::rowAt( int pos ) const{    return QMIN( pos/rowH, 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 ){    //FIXME : don't repaint everything. not sure if this is needed for non phone#if !defined(QTOPIA_PHONE) || defined(QTOPIA_DESKTOP)    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();    }#else    Q_UNUSED(row);#endif    emit currentChanged();}/* simply disabled for now although this might be usefulvoid 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){    QStringList sizes;    if ( f.count() == 0 ) {	f = defaultFields();	headerKeyFields.clear();    }#ifndef PACK_IN_1_COLUMN    QHeader *header = horizontalHeader();    // 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) ) ));    }#endif    setFields(f, sizes);    if ( isVisible() )	fitToSize();}void AbTable::setFields(QValueList<int> f, QStringList sizes){#ifdef PACK_IN_1_COLUMN    headerKeyFields = f;    setNumCols(1);    mSortColumn = -1;    Q_UNUSED(sizes);#else    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);#endif}QValueList<int> AbTable::fields(){    return headerKeyFields;}QValueList<int> AbTable::defaultFields(){    QValueList<int> l;#ifdef QTOPIA_PHONE    l.append( PimContact::FileAs );    l.append( PimContact::Company );    l.append( PimContact::BusinessCity );#else    l.append( PimContact::FileAs );#endif    l.append( FREQ_CONTACT_FIELD );    return l;}#ifndef PACK_IN_1_COLUMNint 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;}#endifvoid AbTable::readSettings(){    QStringList selectedFields, sizeList;    {#ifdef QTOPIA_DESKTOP	QSettings *settings = gQtopiaDesktopConfig->createQSettings();	selectedFields = settings->readListEntry("/addressbook/fields" );	sizeList = settings->readListEntry("/addressbook/colwidths" );	mSortColumn = settings->readNumEntry("/addressbook/sortcolumn", 0);	mAscending = settings->readBoolEntry("/addressbook/ascending", FALSE);	gQtopiaDesktopConfig->deleteQSettings();#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    }#ifdef QTOPIA_PHONE    setFields( defaultFields() );#else    if ( !selectedFields.count() ) {	setFields( defaultFields() );    } else {

⌨️ 快捷键说明

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