📄 abtable.cpp
字号:
}#endif}void AbTable::columnClicked( int col ){ if ( col != mSortColumn ) { mSortColumn = col; mAscending = FALSE; } else { mAscending = !mAscending; } horizontalHeader()->setSortIndicator(mSortColumn,!mAscending); reload();}PimContact AbTable::currentEntry() const{ if ( mSortedContacts.count() == 0) return PimContact(); int r = currentRow(); if (r < 0 || r >= (int)mSortedContacts.count()) r = 0; const PimContact *c = mSortedContacts.at(r); PimContact newCnt(*c); return newCnt;}#ifdef QTOPIA_PHONEQString AbTable::currentSimEntry() const{ if( mCurSimEntry.isNull() && hasCurrentEntry() ) { PimContact cur = currentEntry(); if( cur.customField("SIM_CONTACT").length() ) return cur.fileAs(); } return mCurSimEntry;}void AbTable::setCurrentSimEntry( const QString &fa ){ mCurSimEntry = fa; //store it, because even if it's not in the list yet it should be when the phonebook updates if( fa.isNull() ) return; QList<PimContact> processed; QString fileAs = fa.lower(); int rows = numRows(); for( int i = 0 ; i < rows ; ++i ) // sorted first { if( mSortedContacts.at( i )->customField( "SIM_CONTACT" ).isEmpty() ) { processed.append( mSortedContacts.at( i ) ); continue; } if( mSortedContacts.at( i )->fileAs().lower() == fileAs ) { setCurrentCell( i, currentColumn() ); return; } else { processed.append( mSortedContacts.at( i ) ); } } // not in sorted, check all for( int i = 0 ; i < (int)mAllContacts.count() ; ++i ) { if( mAllContacts.at( i )->customField( "SIM_CONTACT" ).isEmpty() ) continue; if( !processed.contains(mAllContacts.at(i)) && mAllContacts.at( i )->fileAs().lower() == fileAs ) { setKeyChars(""); setCurrentCell(i, currentColumn()); } }}#endifvoid AbTable::setCurrentEntry(const QUuid &u){ int rows, row; rows = numRows();#ifdef QTOPIA_PHONE QList<PimContact> processed;#endif for ( row = 0; row < rows; row++ ) { // first check sorted contacts if ( mSortedContacts.at(row)->uid() == u) { setCurrentCell(row, currentColumn());#ifdef QTOPIA_PHONE setCurrentSimEntry( QString::null );#endif return; }#ifdef QTOPIA_PHONE else processed.append( mSortedContacts.at( row ) );#endif }#ifdef QTOPIA_PHONE //not in sorted, check if in global for( row = 0 ; row < (int)mAllContacts.count() ; ++row ) { if( !processed.contains( mAllContacts.at( row ) ) && mAllContacts.at( row )->uid() == u ) { setKeyChars(""); setCurrentCell(row, currentColumn()); } }#endif}void AbTable::selectAll(){ if ( mSel == NoSelection || mSel == Single ) return; selectionBeginRow = -1; mSelected.clear(); for ( uint u = 0; u < mSortedContacts.count(); u++ ) { mSelected.append( mSortedContacts.at(u)->uid() ); } refresh();}QValueList<QUuid> AbTable::selectedContacts() const{ QValueList<QUuid> list; if ( mSel == Single ) { if ( hasCurrentEntry() ) list.append( currentEntry().uid() ); } else if ( mSel == Extended ) { list = mSelected; // set current entry as selected when none is selected if ( !list.count() && hasCurrentEntry() ) list.append( currentEntry().uid() ); } return list;}QValueList<PimContact> AbTable::selected() const{ QValueList<PimContact> list; if ( mSel == Single ) { if ( hasCurrentEntry() ) list.append( currentEntry() ); } else if ( mSel == Extended ) { for ( QValueList<QUuid>::ConstIterator it = mSelected.begin(); it != mSelected.end(); ++it) { list.append( pimForUid( *it ) ); } // set current entry as selected when none is selected if ( !list.count() && hasCurrentEntry() ) list.append( currentEntry() ); } return list;}PimContact AbTable::pimForUid(const QUuid &id) const{ for ( uint u = 0; u < mSortedContacts.count(); u++) { if ( id == mSortedContacts.at(u)->uid() ) return *mSortedContacts.at(u); } return PimContact();}bool AbTable::hasCurrentEntry() const{ return mSortedContacts.count() != 0;}void AbTable::reload(){ //qDebug("AbTable::reload");// qDebug("reload callled with %d contacts and sortcol %d", mSortedContacts.count(), mSortColumn); mSelected.clear(); mSortedContacts.clear();#ifdef QTOPIA_PHONE mExistingContactSimData.clear();#endif#ifdef QTOPIA_PHONE contacts->setSorting( PimContact::FileAs, FALSE );#else if ( mSortColumn > -1 ) { contacts->setSorting( headerKeyFields[mSortColumn], mAscending); }#endif mAllContacts = contacts->sortedContacts();#ifdef QTOPIA_PHONE if( contacts->filter() == -1 || contacts->filter() == -2 ) // only display sim contacts for unfiled and all { for( uint i = 0 ; i < mSimContacts.count() ; ++i ) { bool partOfExisting = FALSE; //go through each contact from the sim card bool partialName = FALSE; QString simContactFileAs = mSimContacts.at(i)->fileAs().lower(); if( simContactFileAs[simContactFileAs.length()-1] == AbUtil::SIM_PARTIAL_INDICATOR ) { partialName = TRUE; simContactFileAs = simContactFileAs.left( simContactFileAs.length() -1 ); } for( uint j = 0 ; j < mAllContacts.count() ; ++j ) { if( (partialName && mAllContacts.at(j)->fileAs().lower().startsWith( simContactFileAs )) || (!partialName && simContactFileAs == mAllContacts.at(j)->fileAs().lower()) ) { //this sim contact matches an existing contact, merge it mExistingContactSimData[ mAllContacts.at(j)->fileAs().lower() ] = mSimContacts.at(i); partOfExisting = TRUE; } if( partOfExisting ) //matched the sim contact to a real contact, don't need to look anymore break; } if( !partOfExisting ) //didn't match sim contact to a realcontact, it becomes a contact standalone mAllContacts.append( mSimContacts.at( i ) ); } } mAllContacts.sort();#endif refresh(); emit currentChanged();}#ifdef QTOPIA_PHONEQMap<QString,PimContact *> AbTable::existingContactSimData() const{ return mExistingContactSimData;}void AbTable::setSimContacts( const QList<PimContact> &simContacts ){ QString curSimEntry = currentSimEntry(); PimContact cur = currentEntry(); // get the current entry before calling clear() on mSimContacts. bool hasCur = curSimEntry.length() || hasCurrentEntry(); mExistingContactSimData.clear(); mSimContacts.clear(); mSimContacts = simContacts; reload(); if( hasCur ) { if( curSimEntry.length() ) setCurrentSimEntry( curSimEntry ); else setCurrentEntry( cur.uid() ); }}#endifQValueList<PimContact> AbTable::all() const{ QValueList<PimContact> list; const uint len = mSortedContacts.count(); for( uint i = 0 ; i < len ; ++i ) { PimContact *c = (PimContact *)mSortedContacts.at(i); list.append( *c ); } return list;}void AbTable::refresh(){ //qDebug("AbTable::refresh");// qDebug("AbTable::refresh %d contacts", mSortedContacts.count() ); //fill mSortedContacts with records that match mSortedContacts.clear(); if( keychars.isEmpty() ) { mSortedContacts = mAllContacts; } else { const uint len = mAllContacts.count(); QList<const PimContact> matches; for( uint i = 0 ; i < len ; ++i ) { const PimContact *cnt = mAllContacts.at(i); if( AbUtil::findPrefixInName( cnt->fileAs(), keychars ) != -1#ifdef QTOPIA_PHONE || AbUtil::findPrefixInName( fieldText(*cnt,headerKeyFields[1]), keychars ) != -1#endif ) { matches.append( cnt ); } } mSortedContacts.resize( matches.count() ); const PimContact *cnt; for( cnt = matches.first() ; cnt ; cnt = matches.next() ) mSortedContacts.append( const_cast<PimContact *>(cnt) ); } setNumRows(mSortedContacts.count());}void AbTable::setKeyChars(const QString& k){ if ( keychars != k ) {#ifdef QTOPIA_PHONE if( k.isEmpty() ) //back is go back ContextBar::setLabel( this, Key_Back, ContextBar::Back, ContextBar::ModalAndNonModal ); else //back is backspace ContextBar::setLabel( this, Key_Back, ContextBar::BackSpace, ContextBar::ModalAndNonModal );#endif keychars = k; refresh(); setCurrentCell( 0, currentColumn() ); }}void AbTable::keyPressEvent( QKeyEvent *e ){ switch( e->key() ) {#ifdef QTOPIA_PHONE case Qt::Key_0: case Qt::Key_2: case Qt::Key_3: case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9: { setKeyChars(keychars+e->text()); return; } case Qt::Key_BackSpace: if ( keychars.length() ) { setKeyChars(keychars.left(keychars.length()-1)); return; } else { QTable::keyPressEvent( e ); } break; case Qt::Key_No: case Qt::Key_Back: { if( !keychars.isEmpty() ) { //back resets filter setKeyChars( QString::null ); e->accept(); } else //keychars empty, go back { QTable::keyPressEvent( e ); } break; } case Qt::Key_Select: if( !Global::mousePreferred() ) { if ( !isModalEditing() ) { QTable::keyPressEvent(e); break; } } // Fall through...#endif case Qt::Key_Space: case Qt::Key_Return: case Qt::Key_Enter: emit clicked(); break; default: QTable::keyPressEvent( e ); }}void AbTable::contentsMousePressEvent( QMouseEvent *e ){ if ( mSel == Extended ) { mSelected.clear(); bState = e->button(); } QTable::contentsMousePressEvent( e );}void AbTable::contentsMouseReleaseEvent( QMouseEvent *e ){ if ( mSel == Extended ) { selectionBeginRow = -1; bState = Qt::NoButton; } QTable::contentsMouseReleaseEvent( e );}void AbTable::resizeEvent( QResizeEvent *e ){ QTable::resizeEvent( e ); // we receive a resize event from qtable in the middle of the constrution, since // QTable::columnwidth does qApp->processEvents. Ignore this event as it causes // all sorts of init problems for us}void AbTable::showEvent( QShowEvent *e){ fitToSize(); QTable::showEvent(e);}void AbTable::fitToSize(){ // work out the avail width. May need to subtract scrollbar. int w = width() - frameWidth()*2; if (contentsHeight() >= (height() - horizontalHeader()->height()) ) w -= ( style().scrollBarExtent().width() ); #ifdef PACK_IN_1_COLUMN // Showing close to a whole number of items sucks if it just wastes space QFontMetrics lfm(fnt[0]); QFontMetrics sfm(fnt[1]); rowH = QMAX(AbUtil::ImageHeight+2, lfm.height() + sfm.height() + 2 );#endif calcFieldSizes(0, w);}void AbTable::calcFieldSizes(int oldSize, int size){#ifdef PACK_IN_1_COLUMN Q_UNUSED(oldSize); setColumnWidth(0,size);#else constructorDone = FALSE; //don't let QTable mess up our logic int col = headerKeyFields.count(); int max = 0; int i; for ( i = 0; i < col; i++) { max += columnWidth(i); } if ( oldSize < max ) oldSize = max; int accumulated = 0; for ( i = 0; i < col; i++) { float l = (float) columnWidth( i ) / (float) oldSize; float l2 = l * size; int newColLen = (int) l2; int min = minimumFieldSize( (PimContact::ContactFields) headerKeyFields[i] );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -