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

📄 abtable.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#define QTOPIA_INTERNAL_CONTACT_MRE#include <qlayout.h>#include <qlabel.h>#include <qlineedit.h>#include <qhbox.h>#include <qvaluelist.h>#include <qevent.h>#include <qasciidict.h>#include <qpainter.h>#include <qregexp.h>#include <qdatetime.h>#include <qfile.h>#include <qapplication.h>#include <qstyle.h>#include <qtimer.h>#include <qlist.h>#include <qlistview.h>#include <qaction.h>#include <qsimplerichtext.h>#include <qpixmapcache.h>#ifdef QTOPIA_DESKTOP#include <qdconfig.h>#include <qsettings.h>#include <qapplication.h>#else#include <qtopia/qpeapplication.h>#endif#include <qtopia/pim/private/contactxmlio_p.h>#include <qtopia/categoryselect.h>#include <qtopia/config.h>#include <qtopia/resource.h>#include <qtopia/global.h>#include <qtopia/stringutil.h>#include <qtopia/timestring.h>#include <qtopia/image.h>#ifdef QWS#include <qtopia/qcopenvelope_qws.h>#endif#ifdef QTOPIA_PHONE#include <qtopia/contextmenu.h>#include <qtopia/contextbar.h>#include <qtopia/phone/phone.h>#include <qtopia/phone/phonebook.h>#endif//#include "addressbook.h"#include "abtable_p.h"#include <errno.h>#include <fcntl.h>#ifndef Q_OS_WIN32 #include <unistd.h>#endif#include <stdlib.h>#include <ctype.h> //toupper() for key hackconst int AbUtil::ImageHeight = 30;const int AbUtil::ImageWidth = 24;const int AbTable::FREQ_CONTACT_FIELD = PimContact::ContactFieldsEnd;static Qt::ButtonState bState = Qt::NoButton;static int selectionBeginRow = -1;static bool constructorDone = FALSE;static QString applicationPath;/*!  \class AbTable abtable.h  \brief The AbTable class shows list of contacts.  \internal*/AbTable::AbTable( ContactXmlIO *c, QWidget *parent, const char *name, const char *appPath )    : QTable( 0, 0, parent, name ),      showCat(-2),      prefField(PimContact::DefaultEmail){    // TODO : connect signals for 'personal' changes    applicationPath = appPath;    fontChange(font());    paletteChange(palette());    contacts = c;    mSel = NoSelection;    QTable::setSelectionMode( QTable::NoSelection );    setLeftMargin( 0 );#ifndef QTOPIA_DESKTOP    setFrameStyle( NoFrame );#endif#ifdef PACK_IN_1_COLUMN    generic = Resource::loadPixmap("addressbook/generic-contact");//depot/qtopia/main/src/libraries/qtopiapim/abtable.cpp#76 - opened for edit    setTopMargin( 0 );    setShowGrid(FALSE);    horizontalHeader()->hide();    sim = Resource::loadPixmap("addressbook/sim-contact");#endif    verticalHeader()->hide();    setSorting( TRUE );    connect( this, SIGNAL(clicked(int,int,int,const QPoint&)),             this, SLOT(itemClicked(int,int)) );    connect( this, SIGNAL( doubleClicked(int,int,int,const QPoint&) ),	     this, SLOT( slotDoubleClicked(int,int,int,const QPoint&) ) );    connect( this, SIGNAL( currentChanged(int,int) ),             this, SLOT( slotCurrentChanged(int,int) ) );    mAscending = FALSE;    mSortColumn = #if defined(QTOPIA_PHONE) && !defined(QTOPIA_DESKTOP)	-1#else	0#endif	;#ifdef QTOPIA_DESKTOP    readSettings();#else    QTimer::singleShot(0, this, SLOT(readSettings()) );#endif#ifdef QTOPIA_PHONE    setHScrollBarMode( QScrollView::AlwaysOff );    mSimContacts.setAutoDelete( TRUE );#endif}AbTable::~AbTable(){    saveSettings();#ifdef QTOPIA_PHONE    mSimContacts.clear();#endif}void AbTable::setSelectionMode(SelectionMode m){    if ( m == NoSelection && mSel != m ) {	mSelected.clear();	refresh();    }    mSel = m;}// We clear the selection and loop through all the rows since currentChanged// will skip some rows if you move the pointing device fast enoughvoid AbTable::setSelection(int fromRow, int toRow){    // fromLow must be lower    if ( toRow < fromRow ) {	int t = toRow;	toRow = fromRow;	fromRow = t;    }    int row = fromRow;    mSelected.clear();    while ( row <= toRow )     {	mSelected.append( mSortedContacts.at(row)->uid() );	row++;    }}QString AbTable::fieldText(const PimContact& c, int key){    QString text;    switch(key) {    case PimContact::FileAs:	text = findContactName(c);	break;    case FREQ_CONTACT_FIELD:	text = findContactContact(c);	break;    case PimContact::Birthday:	{	    QDate d = c.birthday();	    if ( !d.isNull() )		text = TimeString::localYMD( d );	}	break;    case PimContact::Anniversary:	{	    QDate d = c.anniversary();	    if ( !d.isNull() )		text = TimeString::localYMD( d );	}	break;    case PimContact::Gender:	switch( c.gender() ) {	    case PimContact::Male: text = tr("Male"); break;	    case PimContact::Female: text = tr("Female"); break;	    default: text = ""; break;	}	break;    case PimContact::Notes:	text = c.field( key ).simplifyWhiteSpace();	break;    case PimContact::BusinessStreet:    case PimContact::HomeStreet:	text = c.field( key ).simplifyWhiteSpace();	break;    default:	text = c.field( key );    }    return text;}void AbTable::paintCell( QPainter *p, int row, int col,	const QRect &cr, bool ){    if ( !constructorDone )	return;    //qDebug("AbTable::paintCell( %d, %d )", row, col );#if defined(Q_WS_WIN)    const QColorGroup &cg = ( style().styleHint( QStyle::SH_ItemView_ChangeHighlightOnFocus ) ? palette().inactive() : colorGroup() );#else    const QColorGroup &cg = colorGroup();#endif    PimContact c(*( mSortedContacts.at(row)));    int key = headerKeyFields[ col ];    QString text = fieldText(c,key);    bool selected = FALSE;    if ( mSel != NoSelection  && mSelected.find(c.uid()) != mSelected.end() )	selected = TRUE;#ifdef QTOPIA_PHONE    if (row == currentRow())	selected = TRUE;    int kcl = keychars.length();    int hl = -1;    if ( kcl ) {	hl = AbUtil::findPrefixInName(text,keychars);    }#endif    p->save();    QPoint pt(0,0);    pt = viewport()->mapToParent(pt);    p->setBrushOrigin(cr.x()-pt.x(), cr.y()-pt.y());    if ( !selected ) {	QBrush br;#ifdef PACK_IN_1_COLUMN	if ( row % 2 )	    br = stripebrush;	else#endif	br = cg.brush( QColorGroup::Base );	p->fillRect( 0, 0, cr.width(), cr.height(), br );	p->setPen(cg.text());    } else {	p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Highlight ) );	p->setPen(cg.highlightedText() );    }#ifdef PACK_IN_1_COLUMN    QPixmap portrait;    QString baseDirStr = Global::applicationFileName( "addressbook", "contactimages/" );    QString pFileName( baseDirStr + c.customField( "photofile" ) );    if( !c.customField( "photofile" ).isEmpty() )    {	QPixmap *cached = QPixmapCache::find( "pimcontact" + c.uid().toString() + "-cfl" );	if( cached )	{	    portrait = *cached;	}	else	{	    portrait.convertFromImage(Image::loadPortrait(pFileName, AbUtil::ImageWidth, AbUtil::ImageHeight));	    if (portrait.isNull()) 	    {		portrait = generic;	    } else {		QPixmapCache::insert( "pimcontact" + c.uid().toString() + "-cfl", portrait );	    }	}    }    else    {	//is it a sim contact or generic?	if( !c.customField( "SIM_CONTACT" ).isEmpty() )	    portrait = sim;	else	    portrait = generic;    }    p->drawPixmap(0,1,portrait);    int y = 0;    p->setFont(fnt[0]);    QFontMetrics fm = p->fontMetrics();    int sz = 0;    int w = columnWidth(0);    QString sep = tr(", ","seperate address/info fields");    for (int f=0; f < (int)headerKeyFields.count(); f++) {	bool last = f+1==(int)headerKeyFields.count();	QString nexttext;	if ( !last )	    nexttext = fieldText(c,headerKeyFields[f+1]);#ifdef QTOPIA_PHONE	if ( f==0 && hl==-1 && !nexttext.isEmpty() ) {	    // hl must be in field field	    if ( kcl ) {		int hl2 = AbUtil::findPrefixInName(nexttext,keychars);		nexttext = nexttext.insert( hl2+kcl, "</u>" );		nexttext = nexttext.insert( hl2, "<u>" );	    }	}#endif	int align = AlignLeft+WordBreak;	bool busCard = c.customField("BusinessCard") == "TRUE";	int bmw = (busCard && f == 0 ? fm.lineSpacing() : 0);	//scroll bar width already accounted for in columnWidth()	const int brw = w-AbUtil::ImageWidth-2-bmw,		  brh = rowH-2-y;	QRect br = p->boundingRect(AbUtil::ImageWidth+2, y, brw, brh, align, text);	/* always paint the first(fileas). paint additional information only if it fits */	if ( f == 0 || 		(br.width() <= brw && br.height() <= brh) ) 	{	    // flush a line/block, go to next smaller size	    QColorGroup cg = colorGroup();	    if( selected )		cg.setColor( QColorGroup::Text, cg.highlightedText() );#ifdef QTOPIA_PHONE	    if ( f==0 && hl != -1) { // draw the underline with QSimpleRichText		text = text.insert( hl+kcl, "</u>" );		text = text.insert( hl, "<u>" );	    }#endif	    if( f == 0 && busCard )	    {		text += QString("<img src=\"%1\" width=%2 height=%3>").arg(			    Resource::findPixmap("addressbook/business") )		    .arg( fm.lineSpacing() ).arg( fm.lineSpacing() );	    }	    QSimpleRichText srt( text, p->font() );	    srt.setWidth( brw );	    srt.draw( p, AbUtil::ImageWidth+2, y, QRegion(br), cg );	    //p->drawText(ImageWidth+2, y, w-ImageWidth+2, br.height(), align, text);	    if ( !last ) {		y += br.height();		if ( sz++ == 0 ) {		    p->setFont(fnt[1]);		} else {		    p->setFont(fnt[2]);		}		QFontMetrics fm = p->fontMetrics();		if ( fm.lineSpacing() + y >= rowH )		    break;		text = nexttext;	    }	} else if ( !nexttext.isEmpty() ) {	    if( !text.isEmpty() )		text += sep;	    text += nexttext;	}    }# ifndef QTOPIA_PHONE    if (row == currentRow())	p->drawRect(0,0,w,rowH);# endif#else    if ( showGrid() ) {	p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );	p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );    }    if (row == currentRow()) {	QPen op = p->pen();	p->setPen( QColor(black) );	if (col == 0)	    p->drawLine( 0, 1, 0, cr.height() - 2);	if (col == numCols() - 1)	    p->drawLine( cr.width() - 2, 1, cr.width() - 2, cr.height() - 2);	p->drawLine( 0, cr.height() - 2, cr.width() - 1, cr.height() - 2 );	p->drawLine( 0, 0, cr.width() - 2, 0 );	p->setPen(op);    }    QFont f = p->font();    QFontMetrics fm(f);    p->drawText(2,2 + fm.ascent(), text);#endif    p->restore();}void AbTable::setCurrentCell( int row, int col){    //qDebug("--> AbTable::setCurrentCell( %d, %d )", row, col);#if !defined(QTOPIA_PHONE) || defined(QTOPIA_DESKTOP)    int orow = currentRow();#endif    QTable::setCurrentCell(row, col);    //qDebug("<-- AbTable::setCurrentCell( %d, %d )", row, col);    //FIXME : QTable calls updateCell itself in this fashion, no need to do it manually #if !defined(QTOPIA_PHONE) || defined(QTOPIA_DESKTOP)    for (int i = 0; i < numCols(); i++) {	updateCell(orow, i);	updateCell(row, i);

⌨️ 快捷键说明

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