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

📄 ablabel.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ 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.************************************************************************/#include "ablabel.h"#ifdef QTOPIA_DATA_LINKING#include <qtopia/qdl.h>#endif#include <qtopia/stringutil.h>#include <qtopia/timestring.h>#ifndef QTOPIA_DESKTOP#include <qtopia/qcopenvelope_qws.h>#endif#include <qtopia/resource.h>#include <qtopia/global.h>#include <qtopia/categories.h>#include <qtopia/image.h>#include <qapplication.h>#include <qdatetime.h>#include <qsimplerichtext.h>#include <qregexp.h>#include <qstylesheet.h>AbLabel::AbLabel( QWidget *parent, const char *name )  : QTextBrowser( parent, name ){    setFrameStyle(NoFrame);    setHScrollBarMode( AlwaysOff );    dirty = TRUE;    mOnlyActivateDialLinks = FALSE;#ifdef QTOPIA_DATA_LINKING    mNotesQC = new QDLClient( this, "contactNotes" );#endif}AbLabel::~AbLabel(){}void AbLabel::setSource( const QString& name ){#ifndef QTOPIA_DESKTOP    ServiceRequest req = anchorService(name);    if ( !req.isNull() ) {	req.send();	emit externalLinkActivated();    } else#endif    if( !mOnlyActivateDialLinks )    {#ifdef QTOPIA_DATA_LINKING    if( name.startsWith("qdl://") )	QDL::activateLink( name, QDL::clients( this )  );    else#endif	QTextBrowser::setSource( name );    }}ServiceRequest AbLabel::anchorService(const QString& name) const{    //TODO : This should probably be in a library. 'QDL::activateLink' - handle activation of links in textbrowser    if ( name.startsWith( "dialer:" ) ) { // No tr	QString number = name.mid(7);	if( number.startsWith("phoneType:") )	{	    number = number.mid(10);	    int f = number.find(":");	    if( f != -1 )		number = number.mid( f+1 );	    else		number = QString::null;	}	if ( number.length() > 0  ) {	    ServiceRequest req( "Dialer", "dial(QString,QString)" ); // No tr	    req << ent.fileAs();	    req << number;	    return req;	}    }    else if( !mOnlyActivateDialLinks )    {	if( name.startsWith( "email:" ) )	{	    QString e = name.mid(6);		    if( !e.isEmpty() )	    {		ServiceRequest req( "Email", "writeMail(QString,QString)" );		req << ent.fileAs() << e;		return req;	    }	}	else if( name.startsWith("sms:") )	{	    QString s = name.mid(4);	    if( !s.isEmpty() )	    {		ServiceRequest req( "Email", "writeSms(QString,QString)" );		req << ent.fileAs() << s;		return req;	    }	}    }    return ServiceRequest();}PimContact AbLabel::entry() const{    return ent;}void AbLabel::init( const PimContact &entry ){    ent = entry;    dirty = TRUE;}static bool dialerPresent(){#ifdef QTOPIA_DESKTOP    return FALSE;#else    return ( Service::channel( "Dialer" ) != 0 );#endif}void AbLabel::sync(){    if ( !dirty )	return;    dirty = FALSE;    QString text = contactToRichText( ent, dialerPresent() );    setText( text );}void AbLabel::keyPressEvent( QKeyEvent *e ){#ifdef QTOPIA_PHONE    //trick the text browser into activating a call     QKeyEvent *oldEvent = 0;    if( e->key() == Key_Yes || e->key() == Key_Call )    {	oldEvent = e;	e = new QKeyEvent( QEvent::KeyPress, Key_Select, 0, 0 );	if( oldEvent->key() == Key_Call )	    mOnlyActivateDialLinks = TRUE;    }    QTextBrowser::keyPressEvent(e);    if( oldEvent )    {	if( e->isAccepted() )	    oldEvent->accept();	delete e;	e = oldEvent;	mOnlyActivateDialLinks = FALSE;	return;    }#else    switch( e->key() ) {    case Key_Space:    case Key_Return:	emit okPressed();	break;    case Key_Left:    case Key_Up:	emit previous();	break;    case Key_Right:    case Key_Down:	emit next();	break;    default:	QTextBrowser::keyPressEvent( e );    }#endif}enum LinkType { NoLink, Dialer, Messaging };static QString phoneToRichText( const QString& pm, const QString& num, LinkType link, int phoneType = -1 ){    if ( num.isEmpty() )	return num;    QString img = "<img src=\"" + ("addressbook/"+pm) + "\"> ";    QString name = Qtopia::escapeString(num);    QString r = img + name;    QString escnum = num;    escnum = Qtopia::escapeString( escnum.replace( QRegExp(" "), "-" ) );    if ( link == Dialer )	r = "<a href=\"dialer:" + 	(phoneType != -1 ? "phoneType:" + QString::number( phoneType ) + ":" : QString::null) + escnum + "\">" + r + "</a>";#ifdef QTOPIA_PHONE    // sms only available on phone    else if ( link == Messaging )	r = "<a href=\"sms:" + escnum + "\">" + r + "</a>";#endif    if( !Global::mousePreferred() )	r = "<small>"+r+"</small>";    return r + "<br>";}static QString phoneToRichText( const QString& pm, const QString& num, bool dialer, int phoneType = -1 ){    return phoneToRichText(pm,num,dialer ? Dialer : NoLink, phoneType);}bool AbLabel::decodeHref(const QString& href, ServiceRequest* req, QString* pm) const{    if ( req )	*req = anchorService(href);    if ( pm ) {	bool sms = FALSE;	QString num, email;	if ( href.left(7) == "dialer:" ) { // No tr	    num = href.mid(7);	    if( num.startsWith("phoneType:") )	    {		num = num.mid(10);		int f = num.find(":");		if( f != -1 )		    num.mid( f+1 );		else		    num = QString::null;	    }	} else if ( href.left(6) == "email:" ) {	    email = href.mid(6);	    if ( email.right(4) == "@sms" ) {		sms = TRUE;		num = email.left(email.length()-4);		email = QString::null;	    }	}	QString f;	if ( !email.isEmpty() && ent.emailList().contains(email) )	    f = "email";	else if ( !num.isNull() ) {	    if ( num == ent.businessMobile().replace( QRegExp(" "), "-" ) )		f = sms ? "businessmessage" : "businessmobile";	    else if ( num == ent.businessPhone().replace( QRegExp(" "), "-" ) )		f = "businessphone";	    else if ( num == ent.homeMobile().replace( QRegExp(" "), "-" ) )		f = sms ? "homemessage" : "homemobile";	    else if ( num == ent.homePhone().replace( QRegExp(" "), "-" ) )		f = "homephone";	}	if ( !f.isNull() )	    *pm = f;    }    return (!req || !req->isNull()) && (!pm || !pm->isNull());}QString AbLabel::contactToRichText( const PimContact & contact, bool dialer ){    QString text;    QString value, comp, state;    QString baseDirStr = Global::applicationFileName( "addressbook", "contactimages/" );#ifdef QTOPIA_DATA_LINKING    mNotesQC->clear();    QDL::loadLinks( contact.customField( QDL::DATA_KEY ), QDL::clients( this ) );#endif    QString thumb = contact.customField( "photofile" );    QString thumbtxt;    if( !thumb.isEmpty() )    {	thumb = baseDirStr + thumb;	// Should be using a 'portrait', but that would mean	// adding 'portrait' intelligence to the MimeSourceFactory.	QSimpleRichText srt("A<br><small>B<br>C</small>",font());	srt.setWidth(100);	int thh = srt.height();	QSize dims = Image::loadScaledImageSize( thumb, thh*3/2, thh );	QString iml = "<img src=\"%1\" width=\"%2\" height=\"%3\">";	iml = iml.arg(Qtopia::escapeString(thumb)).arg(dims.width()).arg(dims.height());	thumbtxt = iml;

⌨️ 快捷键说明

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