Example #1
0
BTSettingsMainWindow::BTSettingsMainWindow(QWidget *parent, Qt::WFlags fl)
    : QMainWindow(parent, fl), m_localDevice(new QBluetoothLocalDevice(this)),
      m_controller(0)
{
    if (!m_localDevice->isValid()) {
        QLabel *label = new QLabel(tr("(Bluetooth not available.)"));
        label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        label->setWordWrap(true);
        label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        setCentralWidget(label);
        return;
    }

    QScrollArea* scroll = new QScrollArea();
    scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    scroll->setWidgetResizable(true);
    scroll->setFrameStyle(QFrame::NoFrame);

    m_menu = QSoftMenuBar::menuFor(this);
    m_tabs = new QTabWidget();

    m_controller =
            new QCommDeviceController(m_localDevice->deviceName().toLatin1(), this);

    SettingsDisplay *settings = new SettingsDisplay(m_localDevice, m_controller);
    scroll->setWidget(settings);
    scroll->setFocusProxy(settings);
    m_tabs->addTab(scroll, tr("Settings"));

    // Delay initialization of tabs other than the first
    m_tabs->addTab(new QWidget, tr("Paired Devices"));
    m_tabs->setTabEnabled(1, false);

    m_tabs->setCurrentIndex(0);

    // change the context menu when the tab changes
    connect(m_tabs, SIGNAL(currentChanged(int)), SLOT(tabChanged(int)));

    // set the current context menu
    tabChanged(m_tabs->currentIndex());

    setCentralWidget(m_tabs);
    setWindowTitle(tr("Bluetooth"));

    QTimer::singleShot(0, this, SLOT(init()));
}