Ignore:
Timestamp:
Aug 2, 2010, 9:27:30 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/examples/multimedia/audiodevices/audiodevices.cpp

    r651 r769  
    4444
    4545#include "audiodevices.h"
     46
     47// Utility functions for converting QAudioFormat fields into text
     48
     49QString toString(QAudioFormat::SampleType sampleType)
     50{
     51    QString result("Unknown");
     52    switch (sampleType) {
     53    case QAudioFormat::SignedInt:
     54        result = "SignedInt";
     55        break;
     56    case QAudioFormat::UnSignedInt:
     57        result = "UnSignedInt";
     58        break;
     59    case QAudioFormat::Float:
     60        result = "Float";
     61        break;
     62    }
     63    return result;
     64}
     65
     66QString toString(QAudioFormat::Endian endian)
     67{
     68    QString result("Unknown");
     69    switch (endian) {
     70    case QAudioFormat::LittleEndian:
     71        result = "LittleEndian";
     72        break;
     73    case QAudioFormat::BigEndian:
     74        result = "BigEndian";
     75        break;
     76    }
     77    return result;
     78}
     79
    4680
    4781AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f)
     
    68102    connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int)));
    69103    connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int)));
     104    connect(populateTableButton, SIGNAL(clicked()), SLOT(populateTable()));
    70105
    71106    modeBox->setCurrentIndex(0);
     
    82117{
    83118    // tries to set all the settings picked.
    84     logOutput->clear();
    85     logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition.");
     119    testResult->clear();
    86120
    87121    if (!deviceInfo.isNull()) {
    88122        if (deviceInfo.isFormatSupported(settings)) {
    89             logOutput->append(tr("Success"));
     123            testResult->setText(tr("Success"));
    90124            nearestFreq->setText("");
    91125            nearestChannel->setText("");
     
    96130        } else {
    97131            QAudioFormat nearest = deviceInfo.nearestFormat(settings);
    98             logOutput->append(tr("Failed"));
     132            testResult->setText(tr("Failed"));
    99133            nearestFreq->setText(QString("%1").arg(nearest.frequency()));
    100134            nearestChannel->setText(QString("%1").arg(nearest.channels()));
    101135            nearestCodec->setText(nearest.codec());
    102136            nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize()));
    103 
    104             switch(nearest.sampleType()) {
    105                 case QAudioFormat::SignedInt:
    106                     nearestSampleType->setText("SignedInt");
    107                     break;
    108                 case QAudioFormat::UnSignedInt:
    109                     nearestSampleType->setText("UnSignedInt");
    110                     break;
    111                 case QAudioFormat::Float:
    112                     nearestSampleType->setText("Float");
    113                     break;
    114                 case QAudioFormat::Unknown:
    115                     nearestSampleType->setText("Unknown");
    116             }
    117             switch(nearest.byteOrder()) {
    118                 case QAudioFormat::LittleEndian:
    119                     nearestEndian->setText("LittleEndian");
    120                     break;
    121                 case QAudioFormat::BigEndian:
    122                     nearestEndian->setText("BigEndian");
    123             }
     137            nearestSampleType->setText(toString(nearest.sampleType()));
     138            nearestEndian->setText(toString(nearest.byteOrder()));
    124139        }
    125140    }
    126141    else
    127         logOutput->append(tr("No Device"));
     142        testResult->setText(tr("No Device"));
    128143}
    129144
    130145void AudioTest::modeChanged(int idx)
    131146{
     147    testResult->clear();
     148
    132149    // mode has changed
    133150    if (idx == 0)
     
    139156    foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode))
    140157        deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo));
     158
     159    deviceBox->setCurrentIndex(0);
     160    deviceChanged(0);
    141161}
    142162
    143163void AudioTest::deviceChanged(int idx)
    144164{
     165    testResult->clear();
     166
    145167    if (deviceBox->count() == 0)
    146168        return;
     
    181203    sampleTypesBox->clear();
    182204    QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes();
    183     for (int i = 0; i < sampleTypez.size(); ++i) {
    184         switch(sampleTypez.at(i)) {
    185             case QAudioFormat::SignedInt:
    186                 sampleTypesBox->addItem("SignedInt");
    187                 break;
    188             case QAudioFormat::UnSignedInt:
    189                 sampleTypesBox->addItem("UnSignedInt");
    190                 break;
    191             case QAudioFormat::Float:
    192                 sampleTypesBox->addItem("Float");
    193                 break;
    194             case QAudioFormat::Unknown:
    195                 sampleTypesBox->addItem("Unknown");
    196         }
    197         if (sampleTypez.size())
    198             settings.setSampleType(sampleTypez.at(0));
    199     }
     205
     206    for (int i = 0; i < sampleTypez.size(); ++i)
     207        sampleTypesBox->addItem(toString(sampleTypez.at(i)));
     208    if (sampleTypez.size())
     209        settings.setSampleType(sampleTypez.at(0));
    200210
    201211    endianBox->clear();
    202212    QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders();
    203     for (int i = 0; i < endianz.size(); ++i) {
    204         switch (endianz.at(i)) {
    205             case QAudioFormat::LittleEndian:
    206                 endianBox->addItem("Little Endian");
    207                 break;
    208             case QAudioFormat::BigEndian:
    209                 endianBox->addItem("Big Endian");
    210                 break;
    211         }
    212     }
     213    for (int i = 0; i < endianz.size(); ++i)
     214        endianBox->addItem(toString(endianz.at(i)));
    213215    if (endianz.size())
    214216        settings.setByteOrder(endianz.at(0));
     217
     218    allFormatsTable->clearContents();
     219}
     220
     221void AudioTest::populateTable()
     222{
     223    int row = 0;
     224
     225    QAudioFormat format;
     226    foreach (QString codec, deviceInfo.supportedCodecs()) {
     227        format.setCodec(codec);
     228        foreach (int frequency, deviceInfo.supportedFrequencies()) {
     229            format.setFrequency(frequency);
     230            foreach (int channels, deviceInfo.supportedChannels()) {
     231                format.setChannels(channels);
     232                foreach (QAudioFormat::SampleType sampleType, deviceInfo.supportedSampleTypes()) {
     233                    format.setSampleType(sampleType);
     234                    foreach (int sampleSize, deviceInfo.supportedSampleSizes()) {
     235                        format.setSampleSize(sampleSize);
     236                        foreach (QAudioFormat::Endian endian, deviceInfo.supportedByteOrders()) {
     237                            format.setByteOrder(endian);
     238                            if (deviceInfo.isFormatSupported(format)) {
     239                                allFormatsTable->setRowCount(row + 1);
     240
     241                                QTableWidgetItem *codecItem = new QTableWidgetItem(format.codec());
     242                                allFormatsTable->setItem(row, 0, codecItem);
     243
     244                                QTableWidgetItem *frequencyItem = new QTableWidgetItem(QString("%1").arg(format.frequency()));
     245                                allFormatsTable->setItem(row, 1, frequencyItem);
     246
     247                                QTableWidgetItem *channelsItem = new QTableWidgetItem(QString("%1").arg(format.channels()));
     248                                allFormatsTable->setItem(row, 2, channelsItem);
     249
     250                                QTableWidgetItem *sampleTypeItem = new QTableWidgetItem(toString(format.sampleType()));
     251                                allFormatsTable->setItem(row, 3, sampleTypeItem);
     252
     253                                QTableWidgetItem *sampleSizeItem = new QTableWidgetItem(QString("%1").arg(format.sampleSize()));
     254                                allFormatsTable->setItem(row, 4, sampleSizeItem);
     255
     256                                QTableWidgetItem *byteOrderItem = new QTableWidgetItem(toString(format.byteOrder()));
     257                                allFormatsTable->setItem(row, 5, byteOrderItem);
     258
     259                                ++row;
     260                            }
     261                        }
     262                    }
     263                }
     264            }
     265        }
     266    }
    215267}
    216268
Note: See TracChangeset for help on using the changeset viewer.