detailspage.cpp

来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 605 行 · 第 1/2 页

CPP
605 行
字号
/******************************************************************************** Copyright (C) 2000-2006 TROLLTECH ASA. All rights reserved.**** This file is part of the Phone Edition of the Qtopia Toolkit.**** Licensees holding a valid license agreement from Trolltech or any of its** authorized distributors may use this file in accordance with** the License Agreement provided with the Licensed Software.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Trolltech's Commercial License Agreements.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.********** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "detailspage.h"#include <qtopia/qsoftmenubar.h>#include <qtopia/qtopiaapplication.h>#include <qtopia/pim/qcontact.h>#ifdef QTOPIA4_TODO#include <qtopia/pim/private/contactfieldselector_p.h>#endif#include <qtopia/pim/qcontactview.h>#include <qcheckbox.h>#include <qlineedit.h>#include <qtextedit.h>#include <qcombobox.h>#include <qlabel.h>#include <qlayout.h>#include <qpixmap.h>#include <qtoolbutton.h>#include <qmenu.h>#include <qdesktopwidget.h>#include <qevent.h>#include <QScrollArea>//#include <qwhatsthis.h>#include "composer.h"#include "addresslist.h"static QStringList splitAddresses(const QString& txt){    // only separates them ( use parseContact to fetch email/name )    QStringList out, list = txt.split(',');    QString str;    for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {	str = (*it).trimmed();	if ( !str.isEmpty() ) {	    out.append( str );	    AddressPicker::addressList()->addAddress( str );	}    }    return out;}DetailsPage::DetailsPage( QWidget *parent, const char *name )    : QWidget( parent ), m_type( -1 ){    m_ignoreFocus = true;    setObjectName( name );    QIcon abicon(":icon/addressbook/AddressBook");    QMenu *menu = QSoftMenuBar::menuFor( this );    if( !Qtopia::mousePreferred() )    {	menu->addAction( abicon, tr("Edit Recipients"),			 this, SLOT(editRecipients()) );	menu->addSeparator();	menu->addAction( QIcon(":icon/copy"), tr("Copy"),			 this, SLOT(copy()) );	menu->addAction( QIcon(":icon/paste"), tr("Paste"),			 this, SLOT(paste()) );    }    const int margin = 2;    setMaximumWidth( qApp->desktop()->width() - 2 * margin );    QGridLayout *l = new QGridLayout( this );    int rowCount = 0;    m_toFieldLabel = new QLabel( this );    m_toFieldLabel->setText( tr( "To" ) );    m_toBox = new QHBoxLayout( this );    m_toField = new QLineEdit( this );    m_toBox->addWidget( m_toField );    connect( m_toField, SIGNAL(textChanged(const QString&)), this, SIGNAL(recipientsChanged()) );    l->addWidget( m_toFieldLabel, rowCount, 0 );    QSoftMenuBar::addMenuTo(m_toField, menu);#ifdef QTOPIA_PHONE    m_toPicker = 0;    if( Qtopia::mousePreferred() )    {	m_toPicker = new QToolButton( this );	m_toBox->addWidget( m_toPicker );	m_toPicker->setText( tr( "..." ) );	//QWhatsThis::add(  m_toPicker, tr( "Select recipients from the addressbook." ) );	m_toPicker->setIcon( abicon );	connect( m_toPicker, SIGNAL(clicked()), this, SLOT(editRecipients()) );    }#endif    l->addLayout( m_toBox, rowCount, 2 );    ++rowCount;    m_ccFieldLabel = new QLabel( this );    m_ccFieldLabel->setText( tr( "CC" ) );    m_ccBox = new QHBoxLayout( this );    m_ccField = new QLineEdit( this );    m_ccBox->addWidget( m_ccField );    connect( m_ccField, SIGNAL(textChanged(const QString&)), this, SIGNAL(recipientsChanged()) );    l->addWidget( m_ccFieldLabel, rowCount, 0 );    QSoftMenuBar::addMenuTo( m_ccField, menu );#ifdef QTOPIA_PHONE    m_ccPicker = 0;    if( Qtopia::mousePreferred() )    {	m_ccPicker = new QToolButton( this );	m_ccBox->addWidget( m_ccPicker );	m_ccPicker->setText( tr( "..." ) );	m_ccPicker->setIcon( abicon );	connect( m_ccPicker, SIGNAL(clicked()), this, SLOT(editRecipients()) );	//QWhatsThis::add( m_ccPicker, tr( "Select carbon copies from the addressbook." ) );    }#endif    l->addLayout( m_ccBox, rowCount, 2 );    ++rowCount;    m_bccFieldLabel = new QLabel( this );    m_bccFieldLabel->setText( tr( "BCC" ) );    m_bccBox = new QHBoxLayout( this );    m_bccField = new QLineEdit( this );    m_bccBox->addWidget( m_bccField );    connect( m_bccField, SIGNAL(textChanged(const QString&)), this, SIGNAL(recipientsChanged()) );    l->addWidget( m_bccFieldLabel, rowCount, 0 );#ifdef QTOPIA_PHONE    m_bccPicker = 0;    if( Qtopia::mousePreferred() )    {	m_bccPicker = new QToolButton( this );	m_bccBox->addWidget( m_bccPicker );	m_bccPicker->setEnabled( true );	m_bccPicker->setText( tr( "..." ) );	m_bccPicker->setIcon( abicon );	connect( m_bccPicker, SIGNAL(clicked()), this, SLOT(editRecipients()) );    ////QWhatsThis::add(  m_bccPicker, tr( "Select blind carbon copies from the addressbook." ) );    }#endif    l->addLayout( m_bccBox, rowCount, 2 );    ++rowCount;    QSoftMenuBar::addMenuTo( m_bccField, menu );    m_subjectFieldLabel = new QLabel( this );    m_subjectFieldLabel->setText( tr( "Subject" ) );    m_subjectField = new QLineEdit( this );    l->addWidget( m_subjectFieldLabel, rowCount, 0 );    l->addWidget( m_subjectField, rowCount, 2 );    ++rowCount;    QSoftMenuBar::addMenuTo( m_subjectField, menu );    m_deliveryReportField = new QCheckBox( tr("Delivery Report"), this );    l->addWidget( m_deliveryReportField, rowCount, 0, 1, 3, Qt::AlignLeft );    ++rowCount;    m_readReplyField = new QCheckBox( tr("Read Reply"), this );    l->addWidget( m_readReplyField, rowCount, 0, 1, 3, Qt::AlignLeft );    ++rowCount;    m_fromFieldLabel = new QLabel( this );    m_fromFieldLabel->setEnabled( true );    m_fromFieldLabel->setText( tr( "From" ) );    m_fromField = new QComboBox( this );    m_fromField->setEditFocus( false );    m_fromField->setEnabled( true );    m_fromField->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum )); // Why not automatic?    //QWhatsThis::add(  m_fromField, tr( "Select the from address used for this mail." ) );    l->addWidget( m_fromFieldLabel, rowCount, 0 );    l->addWidget( m_fromField, rowCount, 2 );    ++rowCount;    QSoftMenuBar::addMenuTo( m_fromField, menu );    QSpacerItem* spacer1 = new QSpacerItem( 4, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );    l->addItem( spacer1, rowCount, 1 );    ++rowCount;    QList<QWidget*> tabOrderList;    tabOrderList.append( m_toField );#ifdef QTOPIA_PHONE    if( Qtopia::mousePreferred() )#endif	if (m_toPicker)	    tabOrderList.append( m_toPicker );    tabOrderList.append( m_ccField );#ifdef QTOPIA_PHONE    if( Qtopia::mousePreferred() )#endif	if (m_ccPicker)	    tabOrderList.append( m_ccPicker );    tabOrderList.append( m_bccField );#ifdef QTOPIA_PHONE    if( Qtopia::mousePreferred() )#endif	if (m_bccPicker)	    tabOrderList.append( m_bccPicker );    tabOrderList.append( m_subjectField );    tabOrderList.append( m_fromField );    QListIterator<QWidget*> it( tabOrderList );    QWidget *prev = 0;    QWidget *next;    while ( it.hasNext() ) {	next = it.next();	if ( prev )	    setTabOrder( prev, next );	prev = next;    }    m_toField->installEventFilter(this);    m_ccField->installEventFilter(this);    m_bccField->installEventFilter(this);}void DetailsPage::editRecipients(){    QLineEdit *le = 0;#ifdef QTOPIA_PHONE    if( Qtopia::mousePreferred() )    {	if( sender() == m_toPicker )	    le = m_toField;	else if( sender() == m_ccPicker )	    le = m_ccField;	else if( sender() == m_bccPicker )	    le = m_bccField;    }    else    {	QWidget *w = focusWidget();	if( w && w->inherits("QLineEdit") )	    le = (QLineEdit *)w;    }#endif    if( !le )    {	qDebug("Couldn't find line edit for recipients.");	return;    }    // Use the contactselector for now    QContactSelector picker( false, this );    QContactModel *model = new QContactModel( this );    if( m_allowPhoneNumbers )	model->setFilter( "", QContactModel::ContainsPhoneNumber );    else // m_allowEmails	model->setFilter( "", QContactModel::ContainsEmail );    picker.setModel( model );        int r = QtopiaApplication::execDialog( &picker );    if ( r == QDialog::Accepted && picker.contactSelected() ) {	QString newText;	if( m_allowPhoneNumbers )        {            QContact c = picker.selectedContact();            if (c.phoneNumbers().count() > 1) {                QPhoneTypeSelector ph_sel(c, QString());                ph_sel.showMaximized();                if (ph_sel.exec())                    newText = ph_sel.selectedNumber();            } else {                 newText = picker.selectedContact().defaultPhoneNumber();            }        }	else //  m_allowEmails        {	    newText = picker.selectedContact().defaultEmail();        }        if ( !newText.isEmpty() )        {            if ( le->text().trimmed().isEmpty() )                le->setText( newText );            else                le->setText( le->text()  + ", " + newText );        }    }    #ifdef QTOPIA4_TODO    QList<QContact::ContactFields> fields;    if( m_allowPhoneNumbers )    {	fields.append( PimContact::HomeMobile );	fields.append( PimContact::BusinessMobile );    }

⌨️ 快捷键说明

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