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

📄 mmscomposer.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void MMSSlide::showEvent( QShowEvent *event ){    QWidget::showEvent( event );    if( m_firstShow )    {	m_imageContent->setFocus();	m_firstShow = false;    }}//==============================================================================MMSComposer::MMSComposer(QWidget *parent)    : QWidget(parent), m_curSlide(-1), m_internalUpdate(false){    setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );    setFocusPolicy( Qt::NoFocus );    QVBoxLayout *l = new QVBoxLayout( this );    l->setMargin(0);    QHBoxLayout *labelLayout = new QHBoxLayout;    m_durationLabel = new QLabel( this );    labelLayout->addWidget( m_durationLabel );    m_slideLabel = new QLabel( this );    m_slideLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );    labelLayout->addWidget( m_slideLabel );    l->addLayout( labelLayout );    m_slideStack = new QStackedWidget( this );    m_slideStack->setFocusPolicy( Qt::NoFocus );    l->addWidget( m_slideStack, 1 );    connect( this, SIGNAL(currentChanged(uint)), this, SLOT(updateLabels()) );    setBackgroundColor(palette().color(QPalette::Base));    setTextColor(palette().color(QPalette::Text));    QMenu *thisMenu = QSoftMenuBar::menuFor( this );    QAction *action = new QAction(tr("Add Slide"), this);    connect( action, SIGNAL(triggered()), this, SLOT(addSlide()) );    thisMenu->addAction(action);    action = new QAction(tr("Remove Slide"), this);    connect( action, SIGNAL(triggered()), this, SLOT(removeSlide()) );    thisMenu->addAction(action);    thisMenu->addSeparator();    action = new QAction(tr("Slide Options"), this);    connect( action, SIGNAL(triggered()), this, SLOT(slideOptions()) );    thisMenu->addAction(action);    addSlide();}MMSComposer::~MMSComposer(){    qDeleteAll(m_slides);}void MMSComposer::slideOptions(){    MMSSlide *cur = slide( currentSlide() );    if( !cur )	return;    QDialog *dlg = new QDialog(this);    dlg->setModal(true);    dlg->setWindowTitle( tr("Slide Options") );    QGridLayout *l = new QGridLayout( dlg );    l->setMargin(3);    int rowCount = 0;    QLabel *la = new QLabel( tr("Duration", "duration between images in a slide show"), dlg );    l->addWidget( la, rowCount, 0 );    QHBoxLayout *durCon = new QHBoxLayout( dlg );    QSpinBox *durBox = new QSpinBox(dlg );    durCon->addWidget(durBox);    durBox->setMinimum( 1 );    durBox->setMaximum( 10 );    durBox->setValue( cur->duration()/1000 );    la = new QLabel( dlg );    durCon->addWidget(la);    la->setText( tr("seconds") );    l->addLayout( durCon, rowCount, 1 );    ++rowCount;/*    la = new QLabel( tr("Text Color"), dlg );	    l->addWidget( la, rowCount, 0 );    QColorButton *tc = new QColorButton( dlg );    tc->setColor( textColor() );    l->addWidget( tc, rowCount, 1 );    ++rowCount;*/    la = new QLabel( tr("Slide Color"), dlg );    l->addWidget( la, rowCount, 0 );    QColorButton *bg = new QColorButton( dlg );    bg->setColor( backgroundColor() );    l->addWidget( bg, rowCount, 1 );    int r = QtopiaApplication::execDialog( dlg );    if( r == QDialog::Accepted )    {//	setTextColor( tc->color() );	setBackgroundColor( bg->color() );	cur->setDuration( durBox->value()*1000 );    }}QRect MMSComposer::contentsRect() const{    QRect r = rect();    r.setHeight( r.height() - qMax( m_slideLabel->height(), m_durationLabel->height() ) );    return r;}void MMSComposer::addSlide(){    addSlide( -1 );}void MMSComposer::addSlide( int a_slide ){    if( a_slide < 0 )    {	if( currentSlide() == -1 )	    a_slide = 0;	else	    a_slide = currentSlide();    }    else if( a_slide >= (int)slideCount() )    {	a_slide = slideCount() - 1;    }    if( slideCount() )	++a_slide; // add to the next slide    MMSSlide *newSlide = new MMSSlide( m_slideStack );    connect( newSlide, SIGNAL(leftPressed()), this, SLOT(previousSlide()) );    connect( newSlide, SIGNAL(rightPressed()), this, SLOT(nextSlide()) );    connect( newSlide, SIGNAL(durationChanged(int)), this, SLOT(updateLabels()) );    m_slides.insert( a_slide, newSlide );    m_slideStack->addWidget(newSlide);    QMenu *thisMenu = QSoftMenuBar::menuFor( this );    QSoftMenuBar::addMenuTo( newSlide, thisMenu );    QSoftMenuBar::addMenuTo( newSlide->m_textContent, thisMenu );    QSoftMenuBar::addMenuTo( newSlide->m_imageContent, thisMenu );    connect( newSlide->m_textContent, SIGNAL(textChanged()), this, SIGNAL(contentChanged()) );    connect( newSlide->m_imageContent, SIGNAL(changed()), this, SIGNAL(contentChanged()) );    connect( newSlide->m_audioContent, SIGNAL(changed()), this, SIGNAL(contentChanged()) );    m_internalUpdate = true;    setCurrentSlide( a_slide );}void MMSComposer::removeSlide(){    removeSlide( -1 );}void MMSComposer::removeSlide( int a_slide ){    if( slideCount() <= 1 )	return;    int s = a_slide;    if( s == -1 )	s = currentSlide();    if( s < 0 || s >= (int)slideCount() )	return;    m_slideStack->removeWidget( slide( s ) );    delete m_slides.takeAt( s );    if( s >= (int)slideCount() )	s = slideCount() - 1;    if( s >= 0 )	m_internalUpdate = true;    setCurrentSlide( s );}void MMSComposer::setTextColor( const QColor &col ){    m_textColor = col;    QPalette pal = m_slideStack->palette();    pal.setColor( QPalette::Foreground, m_textColor );    pal.setColor( QPalette::Text, m_textColor );    m_slideStack->setPalette( pal );}QColor MMSComposer::textColor() const{    return m_textColor;}QColor MMSComposer::backgroundColor() const{    return m_backgroundColor;}void MMSComposer::setBackgroundColor( const QColor &col ){    m_backgroundColor = col;    QPalette pal = m_slideStack->palette();    pal.setColor( QPalette::Background, m_backgroundColor );    pal.setColor( QPalette::Base, m_backgroundColor );    m_slideStack->setPalette( pal );}void MMSComposer::setCurrentSlide( int a_slide ){    if( a_slide >= (int)slideCount() )	return;    if( a_slide < 0 )    {	m_curSlide = -1;	return;    }    if( m_internalUpdate || a_slide != m_curSlide )    {	m_internalUpdate = false;	m_curSlide = a_slide;	m_slideStack->setCurrentWidget( slide( m_curSlide ) );	slide( m_curSlide )->m_imageContent->setFocus();	emit currentChanged( m_curSlide );    }}void MMSComposer::nextSlide(){    if( !slideCount() )	return;    int cur = currentSlide();    if( cur == -1 || ++cur >= (int)slideCount() )	cur = 0;    setCurrentSlide( cur );}void MMSComposer::previousSlide(){    if( !slideCount() )	return;    int cur = currentSlide();    --cur;    if( cur < 0 )	cur = slideCount() - 1;    setCurrentSlide( cur );}void MMSComposer::updateLabels(){    QString baseLabel = tr("Slide %1 of %2");    m_slideLabel->setText( baseLabel.arg( QString::number( currentSlide()+1 ) )			       .arg( QString::number( slideCount() ) ) );    baseLabel = tr("Duration: %1secs", "duration between images in a slide show");    m_durationLabel->setText(    baseLabel.arg( QString::number( slide( currentSlide() )->duration()/1000 ) ) );}int MMSComposer::currentSlide() const{    return m_curSlide;}uint MMSComposer::slideCount() const{    return m_slides.count();}MMSSlide *MMSComposer::slide( uint slide ) const{    if( slide >= slideCount() )	return 0;    return m_slides.at(slide);}class SmilHandler : public QXmlDefaultHandler{public:    QList<MMSSmilPart> parts;    MMSSmil smil;    SmilHandler() : m_insidePart( false ) {}    bool startElement( const QString &, const QString &, const QString &qName,						const QXmlAttributes & atts )    {	if( qName == "smil" )	{	    smil.fgColor = QColor();	    smil.bgColor = QColor();	    smil.parts.clear();	}	else if( qName == "par" )	{	    m_insidePart = true;	    MMSSmilPart newPart;	    if( atts.value( "duration" ).length() )		newPart.duration = atts.value( "duration" ).toInt();	    smil.parts.append( newPart );	}	else if( qName == "region" )	{	    if( atts.value("background-color").length() )		smil.bgColor.setNamedColor( atts.value("background-color") );	}	else if( m_insidePart )	{	    if( qName == "img" && atts.value( "src" ).length() )		smil.parts.last().image = atts.value( "src" );	    else if( qName == "text" && atts.value( "src" ).length() )		smil.parts.last().text = atts.value( "src" );	    else if( qName == "audio" && atts.value( "src" ).length() )		smil.parts.last().audio = atts.value( "src" );	}	return true;    }    bool endElement( const QString &, const QString &, const QString &qName )    {	if( qName == "par" )	    m_insidePart = false;	return true;    }private:    bool m_insidePart;};MMSSmil MMSComposer::parseSmil( const QString &smil ){    QXmlInputSource input;    input.setData( smil );    QXmlSimpleReader reader;    SmilHandler *handler = new SmilHandler;    reader.setContentHandler( handler );    if( !reader.parse( input ) )	qWarning( "MMSComposer unable to parse smil message." );    MMSSmil s = handler->smil;    delete handler;    return s;}void MMSComposer::setMailMessage( Email &mail ){    //qDebug("MMSComposer::setMailMessage");    QBitArray handledParts(mail.messagePartCount());    handledParts.fill(false);    clear();    MMSSlide *curSlide = slide( currentSlide() );    QString doc;    for( uint i = 0 ; i < mail.messagePartCount() ; ++i )    {	if( mail.messagePartAt( i ).contentID().toLower().contains("presentation-part") )	{	    doc = mail.messagePartAt( i ).decodedBody();	    handledParts.setBit(i);	    break;	}    }    if( !doc.isNull() )    {	// parse smil	MMSSmil smil = parseSmil( doc );	QList<MMSSmilPart> smilParts = smil.parts;//	qDebug("numSmilParts = %d", smilParts.count());	int numSlides = 0;	for( QList<MMSSmilPart>::Iterator it = smilParts.begin() ;				    it != smilParts.end() ; ++it, ++numSlides )	{	    if( numSlides )		addSlide();	    MMSSlide *curSlide = slide( slideCount() -1 );	    for( uint i = 0 ; i < mail.messagePartCount() ; ++i )	    {		QString partName = mail.messagePartAt( i ).contentLocation();		if( partName == (*it).text )		{//		    qDebug() << "text part" << partName;		    MailMessagePart part = mail.messagePartAt( i );		    QByteArray data = QByteArray::fromBase64(part.rawEncodedBody());		    QTextStream stream( data, QIODevice::ReadOnly );		    QString t = stream.readAll();		    curSlide->textContent()->setText( t );//		    qDebug() << "text of part is" << t;		    handledParts.setBit(i);		}		else if( partName == (*it).image )		{//		    qDebug() << "image part" << partName;		    MailMessagePart part = mail.messagePartAt( i );		    QByteArray data = QByteArray::fromBase64(part.rawEncodedBody());//                    qDebug() << data.size() << "bytes of data";		    QPixmap pix;                    pix.loadFromData(data);//                    qDebug() << "Read pixmap of size" << pix.size();		    curSlide->imageContent()->setImage( pix );		    handledParts.setBit(i);		}		else if ( partName == (*it).audio )		{		    MailMessagePart part = mail.messagePartAt( i );		    QByteArray data = QByteArray::fromBase64(part.rawEncodedBody());		    curSlide->audioContent()->setAudio( data, part.contentLocation() );		    handledParts.setBit(i);		}	    }	}	if( smil.bgColor.isValid() )	    setBackgroundColor( smil.bgColor );	if( smil.fgColor.isValid() )	    setTextColor( smil.fgColor );	setCurrentSlide( 0 );    } else {	//qDebug("mail message has no presentation part");	if (!mail.plainTextBody().isEmpty()) {	    curSlide->textContent()->setText(mail.plainTextBody());	}	for (uint i = 0 ; i < mail.messagePartCount() ; ++i) {	    MailMessagePart part = mail.messagePartAt( i );

⌨️ 快捷键说明

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