audiosource.cpp
来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 286 行
CPP
286 行
/******************************************************************************** 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 "audiosource.h"#ifndef QT_NO_COP#include <qtopia/qcopenvelope.h>#endif#include <qtopia/qtopiaapplication.h>#include <qtopia/qdocumentselector.h>#include <qtopia/qsoftmenubar.h>#include <qlayout.h>#include <qlabel.h>#include <qpushbutton.h>#include <qfiledialog.h>#include <qpainter.h>#include <qstring.h>#include <qdebug.h>AudioServerManager::AudioServerManager(QObject* parent) : ValueService(parent,ValueService::Get,"audio","QString,QString,int,int","QString") // No tr{}AudioServerManager::~AudioServerManager(){}void AudioServerManager::valueSupplied(QDataStream& ds){ QString filename; ds >> filename; qDebug() << "audio value supplied: " << filename.data()->unicode(); emit audioSupplied(QContent(filename));}void AudioServerManager::setDefaultAudio( const QString &type, const QString &subFormat, int fr, int ch ){ dftType = type; dftFormat = subFormat; dftFreq = fr; dftChannels = ch;}#ifndef QT_NO_COPvoid AudioServerManager::sendParameters( QCopEnvelope &sreq){ sreq << dftType << dftFormat << dftFreq << dftChannels;}#endif//===========================================================================class AudioSelectorDialog : public QDialog{ Q_OBJECTpublic: AudioSelectorDialog(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("Select Audio")); setModal( true ); QtopiaApplication::setMenuLike(this, true); QVBoxLayout *vb = new QVBoxLayout(this); fileSelector = new QDocumentSelector("audio/*", this);#ifdef QTOPIA_PHONE // Remove soft menu from selector QSoftMenuBar::removeMenuFrom( fileSelector, QSoftMenuBar::menuFor( fileSelector ) );#endif vb->addWidget(fileSelector); connect(fileSelector, SIGNAL(documentSelected(const QContent&)), this, SLOT(documentSelected(const QContent&))); } QContent selected() const { return file; }protected slots: void documentSelected(const QContent &doc) { file = doc; accept(); }private: QDocumentSelector *fileSelector; QContent file;};class AudioSourceWidgetPrivate{public: AudioSourceWidgetPrivate() { } QContent audio; QLabel *label; QPushButton *removePB, *changePB;};AudioSourceWidget::AudioSourceWidget( QWidget *parent ) : QWidget( parent ){ init(); haveAudio( false );}AudioSourceWidget::~AudioSourceWidget(){ delete d;}void AudioSourceWidget::init(){ d = new AudioSourceWidgetPrivate(); d->label = new QLabel( this ); d->label->setAlignment( Qt::AlignCenter ); QVBoxLayout *vl = new QVBoxLayout( this ); vl->addWidget( d->label ); d->changePB = new QPushButton( tr("Audio Files"), this ); connect( d->changePB, SIGNAL(clicked()), this, SLOT(change()) ); vl->addWidget( d->changePB ); audioServer = new AudioServerManager(this); connect(audioServer,SIGNAL(audioSupplied(const QContent&)),this,SLOT(setAudio(const QContent&))); int n = audioServer->serverCount(); for (int i=0; i<n; i++) { ValueServiceServer s = audioServer->server(i); if ( !s.isNull() ) { QPushButton* pb = new QPushButton( s.pixmap(), s.name(), this ); //XXX icon too! audioServer->connectToServer(pb, SIGNAL(clicked()), i); vl->addWidget(pb); } else qDebug("AB : server %d is null", i ); } d->removePB = new QPushButton( tr("Remove"), this ); connect( d->removePB, SIGNAL(clicked()), this, SLOT(remove()) ); vl->addWidget( d->removePB ); vl->addStretch();}void AudioSourceWidget::change(){#ifndef QTOPIA_DESKTOP AudioSelectorDialog *dlg = new AudioSelectorDialog(parentWidget()); dlg->showMaximized(); if (QtopiaApplication::execDialog(dlg) == QDialog::Accepted) { if (dlg->selected().fileKnown()) setAudio(dlg->selected()); } delete dlg;#else QString formatStr = "Audio (*.amr)"; QFileDialog *fd = new QFileDialog( QDir::homeDirPath(), formatStr, this, "audioSelector", true ); fd->setMode( QFileDialog::ExistingFile ); if( fd->exec() == QDialog::Accepted && fd->selectedFile().length() ) { setAudio( DocLnk(fd->selectedFile()) ); haveAudio( true ); }#endif}void AudioSourceWidget::setDefaultAudio( const QString &type, const QString &subFormat, int fr, int ch ){ audioServer->setDefaultAudio(type, subFormat, fr, ch);}void AudioSourceWidget::setAudio( const QContent &doc ){ qDebug() << "***** set audio: " << doc.name(); d->audio = doc; if ( !doc.fileKnown() ) { haveAudio( false ); QFont f = font(); f.setItalic( true ); d->label->setFont( f ); d->label->setText( tr("No Audio") ); } else { haveAudio( true ); d->label->setFont( font() ); d->label->setText(doc.name()); }}QContent AudioSourceWidget::audio() const{ return d->audio;}void AudioSourceWidget::remove(){ setAudio(QContent());}void AudioSourceWidget::haveAudio( bool f ){ d->removePB->setEnabled( f );}//dialog convenience wrapperAudioSourceDialog::AudioSourceDialog( QWidget *parent, const QString name, bool modal, Qt::WFlags fl ) : QDialog( parent, fl ){ setModal( modal ); setObjectName( name ); init();}AudioSourceDialog::~AudioSourceDialog(){}void AudioSourceDialog::init(){ QVBoxLayout *l = new QVBoxLayout( this ); mWidget = new AudioSourceWidget( this ); l->addWidget( mWidget );#if defined(QTOPIA_DESKTOP) || !defined(QTOPIA_PHONE) QHBoxLayout *bottomLayout = new QHBoxLayout( l ); bottomLayout->addStretch(); QPushButton *okButton = new QPushButton( tr("OK"), this ); okButton->setDefault( true ); connect( okButton, SIGNAL(clicked()), this, SLOT(accept()) ); bottomLayout->addWidget( okButton ); QPushButton *cancelButton = new QPushButton( tr("Cancel"), this ); cancelButton->setAutoDefault( true ); connect( cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); bottomLayout->addWidget( cancelButton );#endif#ifdef QTOPIA_DESKTOP l->setResizeMode( QLayout::FreeResize ); QSize sh = sizeHint(); setMinimumSize( sh ); setMaximumSize( sh.width()*2, sh.height()*2 );#endif setWindowTitle( tr("Audio") );#ifdef AB_PDA setGeometry( qApp->desktop()->geometry() );#endif}void AudioSourceDialog::setDefaultAudio( const QString &type, const QString &subFormat, int fr, int ch ){ mWidget->setDefaultAudio(type, subFormat, fr, ch);}void AudioSourceDialog::setAudio( const QContent &fn ){ mWidget->setAudio( fn );}QContent AudioSourceDialog::audio() const{ return mWidget->audio();}#include "audiosource.moc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?