コード例 #1
0
ファイル: qsensor.cpp プロジェクト: xjohncz/qt5
/*!
    \since 5.1
    Sets the current screen orientation to \a currentOrientation. This is to be called from the
    backend whenever the screen orientation or the userOrientation property changes.
*/
void QSensor::setCurrentOrientation(int currentOrientation)
{
    Q_D(QSensor);
    if (d->currentOrientation != currentOrientation) {
        d->currentOrientation = currentOrientation;
        emit currentOrientationChanged(currentOrientation);
    }
}
コード例 #2
0
RemoteSettingsDialog::RemoteSettingsDialog(const QString &name, QWidget *parent) :
    QDialog(parent),
    m_scrollArea(new QScrollArea(this)),
    m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Vertical, this)),
    m_grid(new QGridLayout(this))
{
    this->setWindowTitle(tr("%1 settings").arg(name));
    this->setAttribute(Qt::WA_DeleteOnClose, true);

    QWidget *scrollWidget = new QWidget(m_scrollArea);
    QVBoxLayout *vbox = new QVBoxLayout(scrollWidget);
    vbox->setContentsMargins(0, 0, 0, 0);
    m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_scrollArea->setWidgetResizable(true);
    m_scrollArea->setWidget(scrollWidget);

    QFile file(REMOTES_DIRECTORY + name + "/settings.xml");

    if (!file.open(QIODevice::ReadOnly)) {
        qWarning() << "Cannot open file" << file.fileName();
        return;
    }

    QXmlStreamReader reader;
    reader.setDevice(&file);
    reader.readNextStartElement();

    while (!reader.atEnd()) {
        if (!reader.attributes().isEmpty()) {
            if (reader.name() == "group") {
                vbox->addWidget(new SeparatorLabel(reader.attributes().value("name").toString(), this));
            }
            else if (reader.name() == "list") {
                RemoteSettingsSelector *selector = new RemoteSettingsSelector(reader.attributes().value("name").toString(), this);
                selector->setKey(QString("%1/%2").arg(name).arg(reader.attributes().value("key").toString()));
                selector->setDefaultValue(reader.attributes().value("default").toString());
                selector->setHandler(reader.attributes().value("onChanged").toString());
                reader.readNextStartElement();

                if (selector->model()) {
                    while (reader.name() == "element") {
                        if (!reader.attributes().isEmpty()) {
                            selector->model()->addItem(reader.attributes().value("name").toString(), reader.attributes().value("value").toString());
                        }

                        reader.readNextStartElement();
                    }
                }

                selector->load();
                vbox->addWidget(selector);
            }
            else if (reader.name() == "boolean") {
                RemoteSettingsCheckbox *checkbox = new RemoteSettingsCheckbox(this);
                checkbox->setText(reader.attributes().value("name").toString());
                checkbox->setKey(QString("%1/%2").arg(name).arg(reader.attributes().value("key").toString()));
                checkbox->setDefaultValue(reader.attributes().value("default").toString());
                checkbox->setHandler(reader.attributes().value("onChanged").toString());
                checkbox->load();
                vbox->addWidget(checkbox);
            }
            else if (reader.name() == "integer") {
                RemoteSettingsSpinbox *spinbox = new RemoteSettingsSpinbox(this);
                spinbox->setKey(QString("%1/%2").arg(name).arg(reader.attributes().value("key").toString()));
                spinbox->setDefaultValue(reader.attributes().value("default").toString());
                spinbox->setHandler(reader.attributes().value("onChanged").toString());
                spinbox->setMinimum(reader.attributes().value("minimum").toString().toInt());
                spinbox->setMaximum(reader.attributes().value("maximum").toString().toInt());
                spinbox->setSingleStep(reader.attributes().value("step").toString().toInt());
                spinbox->load();
                vbox->addWidget(new QLabel(reader.attributes().value("name").toString(), this));
                vbox->addWidget(spinbox);
            }
            else if (reader.name() == "text") {
                RemoteSettingsLineEdit *lineEdit = new RemoteSettingsLineEdit(this);
                lineEdit->setKey(QString("%1/%2").arg(name).arg(reader.attributes().value("key").toString()));
                lineEdit->setDefaultValue(reader.attributes().value("default").toString());
                lineEdit->setHandler(reader.attributes().value("onChanged").toString());
                lineEdit->load();
                vbox->addWidget(new QLabel(reader.attributes().value("name").toString(), this));
                vbox->addWidget(lineEdit);
            }
        }

        reader.readNextStartElement();
    }

    file.close();

    this->connect(Screen::instance(), SIGNAL(currentOrientationChanged(Qt::Orientation)), this, SLOT(onOrientationChanged(Qt::Orientation)));
    this->connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));

    this->onOrientationChanged(Screen::instance()->currentOrientation());
}
コード例 #3
0
void NLStyleTabWidget::currentIndexChanged(int index){
    if(index%_numTabsPerStyle == 0)
        emit currentStyleChanged((int)floorf((float)index/(float)_numTabsPerStyle));
    else if (index%_numTabsPerStyle == 1)
        emit currentOrientationChanged((int)floorf((float)index/(float)_numTabsPerStyle));
}