diff options
Diffstat (limited to 'testapp/settingswidget.cpp')
| -rw-r--r-- | testapp/settingswidget.cpp | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/testapp/settingswidget.cpp b/testapp/settingswidget.cpp index 7f41a7b..5756cf8 100644 --- a/testapp/settingswidget.cpp +++ b/testapp/settingswidget.cpp @@ -86,9 +86,10 @@ public: m_slider2 = 0; m_control = m_slider; } - m_unitLabel = new QLabel(QLatin1String(m_item->unit)); m_valueLabel = new QLabel(); m_nameLabel = new QLabel(QLatin1String(m_item->name)); + if (m_item->unit && m_item->unit[0]) + m_nameLabel->setText(m_nameLabel->text() + QLatin1String(" [") + QLatin1String(m_item->unit) + QLatin1String("]")); m_resetButton = new QToolButton(); m_resetButton->setText(QLatin1String("Reset")); m_resetButton->setEnabled(false); @@ -107,7 +108,6 @@ public: } QWidget *nameLabel() { return m_nameLabel; } - QWidget *unitLabel() { return m_unitLabel; } QWidget *valueLabel() { return m_valueLabel; } QWidget *valueControl() { return m_control; } QWidget *resetButton() { return m_resetButton; } @@ -177,7 +177,7 @@ private: QKineticScroller *m_scroller; QSlider *m_slider, *m_slider2; - QLabel *m_unitLabel, *m_nameLabel, *m_valueLabel; + QLabel *m_nameLabel, *m_valueLabel; QToolButton *m_resetButton; QWidget *m_control; @@ -189,11 +189,11 @@ private: MetricItem items[QKineticScroller::ScrollMetricCount] = { { METRIC(DragVelocitySmoothingFactor), 1, "", qreal(0), qreal(1), qreal(0.01) }, - { METRIC(LinearDecelerationFactor), 1, "m/s^2", qreal(0), qreal(3), qreal(0.01) }, + { METRIC(LinearDecelerationFactor), 1, "m/s\xb2", qreal(0), qreal(3), qreal(0.01) }, { METRIC(ExponentialDecelerationBase), 1, "", qreal(0), qreal(1), qreal(0.01) }, - { METRIC(OvershootSpringConstant), 1, "kg/s^2", qreal(1), qreal(500), qreal(1) }, + { METRIC(OvershootSpringConstant), 1, "kg/s\xb2", qreal(1), qreal(500), qreal(1) }, { METRIC(OvershootDragResistanceFactor), 1, "", qreal(0), qreal(1), qreal(0.01) }, - { METRIC(OvershootMaximumDistance), 1000, "(mm, mm)", QPointF(0, 0), QPointF(500, 500), qreal(1) }, + { METRIC(OvershootMaximumDistance), 1000, "mm, mm", QPointF(0, 0), QPointF(500, 500), qreal(1) }, { METRIC(DragStartDistance), 1000, "mm", qreal(1), qreal(20), qreal(0.1) }, { METRIC(DragStartDirectionErrorMargin), 1000, "mm", qreal(1), qreal(20), qreal(0.1) }, @@ -214,23 +214,36 @@ MetricItem items[QKineticScroller::ScrollMetricCount] = { #undef METRIC +void SettingsWidget::addToGrid(QGridLayout *grid, QWidget *label, int widgetCount, ...) +{ + va_list args; + va_start(args, widgetCount); + + int rows = grid->rowCount(); + int cols = grid->columnCount(); + + if (label) { + if (m_smallscreen) + grid->addWidget(label, rows++, 0, 1, qMax(cols, widgetCount)); + else + grid->addWidget(label, rows, 0); + } + for (int i = 0; i < widgetCount; i++) { + if (QWidget *w = va_arg(args, QWidget *)) + grid->addWidget(w, rows, m_smallscreen ? i : i + 1); + } + va_end(args); +} + QGridLayout *SettingsWidget::createMetricsItemGrid() { QGridLayout *grid = new QGridLayout(); - grid->setVerticalSpacing(2); - int row = 0; + grid->setVerticalSpacing(m_smallscreen ? 4 : 2); for (int i = 0; i < QKineticScroller::ScrollMetricCount; i++) { MetricItemUpdater *u = new MetricItemUpdater(items + i, m_scroller); u->setParent(this); - - grid->addWidget(u->nameLabel(), row, 0); - grid->addWidget(u->valueControl(), row, 1); - grid->addWidget(u->valueLabel(), row, 2); - grid->addWidget(u->unitLabel(), row, 3); - grid->addWidget(u->resetButton(), row, 4); - - row++; + addToGrid(grid, u->nameLabel(), 3, u->valueControl(), u->valueLabel(), u->resetButton()); } return grid; } @@ -246,56 +259,56 @@ public: using QAbstractSpinBox::lineEdit; }; -SettingsWidget::SettingsWidget(QKineticScroller *scroller) - : QWidget(), m_scroller(scroller) +SettingsWidget::SettingsWidget(QKineticScroller *scroller, bool smallscreen) + : QScrollArea(), m_scroller(scroller), m_smallscreen(smallscreen) { setWindowTitle(QLatin1String("Settings")); - QVBoxLayout *layout = new QVBoxLayout(this); + QWidget *view = new QWidget(); + QVBoxLayout *layout = new QVBoxLayout(view); QGroupBox *grp; QGridLayout *grid; grp = new QGroupBox(QLatin1String("General")); grid = new QGridLayout(); - grid->setVerticalSpacing(2); + grid->setVerticalSpacing(smallscreen ? 4 : 2); QCheckBox *onoff = new QCheckBox(QLatin1String("Enabled")); onoff->setChecked(m_scroller->isEnabled()); connect(onoff, SIGNAL(toggled(bool)), this, SLOT(enabledChanged(bool))); - grid->addWidget(onoff, 0, 0, 1, 2); - grid->addWidget(new QLabel("DPI"), 1, 0); + addToGrid(grid, onoff, 0); + QSpinBox *dpi = new QSpinBox(); dpi->setRange(10, 1000); dpi->setSuffix(QLatin1String(" dpi")); dpi->setValue(m_scroller->dpi()); connect(dpi, SIGNAL(valueChanged(int)), this, SLOT(dpiChanged(int))); - grid->addWidget(dpi, 1, 1); + addToGrid(grid, new QLabel("DPI"), 1, dpi); - grid->addWidget(new QLabel("Horizontal Overshoot Policy"), 2, 0); m_hospolicy = new QComboBox(); m_hospolicy->addItem("When Scrollable", QKineticScroller::OvershootWhenScrollable); m_hospolicy->addItem("Always On", QKineticScroller::OvershootAlwaysOn); m_hospolicy->addItem("Always Off", QKineticScroller::OvershootAlwaysOff); m_hospolicy->setCurrentIndex(m_hospolicy->findData(m_scroller->horizontalOvershootPolicy())); connect(m_hospolicy, SIGNAL(currentIndexChanged(int)), this, SLOT(overshootPolicyChanged(int))); - grid->addWidget(m_hospolicy, 2, 1); + addToGrid(grid, new QLabel("Horizontal Overshoot Policy"), 1, m_hospolicy); - grid->addWidget(new QLabel("Vertical Overshoot Policy"), 3, 0); m_vospolicy = new QComboBox(); m_vospolicy->addItem("When Scrollable", QKineticScroller::OvershootWhenScrollable); m_vospolicy->addItem("Always On", QKineticScroller::OvershootAlwaysOn); m_vospolicy->addItem("Always Off", QKineticScroller::OvershootAlwaysOff); m_vospolicy->setCurrentIndex(m_vospolicy->findData(m_scroller->verticalOvershootPolicy())); connect(m_vospolicy, SIGNAL(currentIndexChanged(int)), this, SLOT(overshootPolicyChanged(int))); - grid->addWidget(m_vospolicy, 3, 1); + addToGrid(grid, new QLabel("Vertical Overshoot Policy"), 1, m_vospolicy); + grp->setLayout(grid); layout->addWidget(grp); grp = new QGroupBox(QLatin1String("Scroll Metrics")); - grid = createMetricsItemGrid(); - grp->setLayout(grid); + grp->setLayout(createMetricsItemGrid()); layout->addWidget(grp); grp = new QGroupBox(QLatin1String("Scroll To")); grid = new QGridLayout(); + grid->setVerticalSpacing(m_smallscreen ? 4 : 2); QSizeF vp = static_cast<HackScroller *>(m_scroller)->viewportSize(); QPointF maxc = static_cast<HackScroller *>(m_scroller)->maximumContentPosition(); @@ -317,16 +330,25 @@ SettingsWidget::SettingsWidget(QKineticScroller *scroller) grid->addWidget(m_scrollx, 0, 1); grid->addWidget(new QLabel(QLatin1String("Y:")), 0, 2); grid->addWidget(m_scrolly, 0, 3); - grid->addWidget(new QLabel(QLatin1String("in")), 0, 4); - grid->addWidget(m_scrolltime, 0, 5); - grid->addWidget(go, 0, 6); + int row = smallscreen ? 1 : 0; + int col = smallscreen ? 0 : 4; + grid->addWidget(new QLabel(QLatin1String("in")), row, col++); + grid->addWidget(m_scrolltime, row, col++); + if (smallscreen) { + grid->addWidget(go, row, col + 1); + } else { + grid->addWidget(go, row, col); + grid->setColumnStretch(5, 1); + grid->setColumnStretch(6, 1); + } grid->setColumnStretch(1, 1); grid->setColumnStretch(3, 1); - grid->setColumnStretch(5, 1); - grid->setColumnStretch(6, 1); grp->setLayout(grid); layout->addWidget(grp); layout->addStretch(100); + + setWidget(view); + setWidgetResizable(true); } void SettingsWidget::enabledChanged(bool on) |
