From 4440644a7b5492fe17a4ffb7dfe4c8aeacd346e4 Mon Sep 17 00:00:00 2001 From: skyjake Date: Wed, 4 Sep 2013 10:57:11 +0300 Subject: [PATCH] Refactor|UI|Client: Convenient constructor for LabelWidget with text A static constructor method that sets the label text and optionally adds it to a parent widget. Also, CVarSliderWidget only gets its range from the cvar info at construction time, afterwards it can be modified. --- .../client/include/ui/widgets/labelwidget.h | 3 +++ .../client/src/ui/dialogs/aboutdialog.cpp | 3 +-- .../src/ui/dialogs/audiosettingsdialog.cpp | 22 +++++-------------- .../src/ui/dialogs/coloradjustmentdialog.cpp | 14 +++--------- .../src/ui/dialogs/inputsettingsdialog.cpp | 9 ++------ .../src/ui/widgets/cvarsliderwidget.cpp | 18 ++++++++------- .../client/src/ui/widgets/labelwidget.cpp | 11 ++++++++++ .../client/src/ui/widgets/sliderwidget.cpp | 4 ++-- 8 files changed, 37 insertions(+), 47 deletions(-) diff --git a/doomsday/client/include/ui/widgets/labelwidget.h b/doomsday/client/include/ui/widgets/labelwidget.h index 5ecf6cd749..1a60121020 100644 --- a/doomsday/client/include/ui/widgets/labelwidget.h +++ b/doomsday/client/include/ui/widgets/labelwidget.h @@ -155,6 +155,9 @@ class LabelWidget : public GuiWidget void contentLayout(ContentLayout &layout); +public: + static LabelWidget *newWithText(de::String const &label, GuiWidget *parent = 0); + protected: void glInit(); void glDeinit(); diff --git a/doomsday/client/src/ui/dialogs/aboutdialog.cpp b/doomsday/client/src/ui/dialogs/aboutdialog.cpp index 71df91d934..33281df2b7 100644 --- a/doomsday/client/src/ui/dialogs/aboutdialog.cpp +++ b/doomsday/client/src/ui/dialogs/aboutdialog.cpp @@ -69,10 +69,9 @@ AboutDialog::AboutDialog() : DialogWidget("about"), d(new Instance(this)) logo->setSizePolicy(ui::Fixed, ui::Expand); // Set up the contents of the widget. - LabelWidget *title = new LabelWidget; + LabelWidget *title = LabelWidget::newWithText(DOOMSDAY_NICENAME); title->margins().set(""); title->setFont("title"); - title->setText(DOOMSDAY_NICENAME); title->setSizePolicy(ui::Fixed, ui::Expand); VersionInfo version; diff --git a/doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp b/doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp index f29e1ed5a2..f8154b69b0 100644 --- a/doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp +++ b/doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp @@ -71,33 +71,21 @@ AudioSettingsDialog::AudioSettingsDialog(String const &name) { heading().setText(tr("Audio Settings")); - LabelWidget *sfxVolLabel = new LabelWidget; - sfxVolLabel->setText(tr("SFX Volume:")); - area().add(sfxVolLabel); - - LabelWidget *musicVolLabel = new LabelWidget; - musicVolLabel->setText(tr("Music Volume:")); - area().add(musicVolLabel); - - LabelWidget *rvbVolLabel = new LabelWidget; - rvbVolLabel->setText(tr("Reverb Volume:")); - area().add(rvbVolLabel); + LabelWidget *sfxVolLabel = LabelWidget::newWithText(tr("SFX Volume:"), &area()); + LabelWidget *musicVolLabel = LabelWidget::newWithText(tr("Music Volume:"), &area()); + LabelWidget *rvbVolLabel = LabelWidget::newWithText(tr("Reverb Volume:"), &area()); d->sound3D->setText(tr("3D Effects & Reverb")); d->sound16bit->setText(tr("16-bit Resampling")); - LabelWidget *rateLabel = new LabelWidget; - rateLabel->setText(tr("Resampling:")); - area().add(rateLabel); + LabelWidget *rateLabel = LabelWidget::newWithText(tr("Resampling:"), &area()); d->sampleRate->items() << new ChoiceItem(tr("1x @ 11025 Hz"), 11025) << new ChoiceItem(tr("2x @ 22050 Hz"), 22050) << new ChoiceItem(tr("4x @ 44100 Hz"), 44100); - LabelWidget *musSrcLabel = new LabelWidget; - musSrcLabel->setText(tr("Preferred Music:")); - area().add(musSrcLabel); + LabelWidget *musSrcLabel = LabelWidget::newWithText(tr("Preferred Music:"), &area()); d->musicSource->items() << new ChoiceItem(tr("MUS lumps"), MUSP_MUS) diff --git a/doomsday/client/src/ui/dialogs/coloradjustmentdialog.cpp b/doomsday/client/src/ui/dialogs/coloradjustmentdialog.cpp index 95c6de47df..e4a6d86a8b 100644 --- a/doomsday/client/src/ui/dialogs/coloradjustmentdialog.cpp +++ b/doomsday/client/src/ui/dialogs/coloradjustmentdialog.cpp @@ -35,20 +35,12 @@ DENG_GUI_PIMPL(ColorAdjustmentDialog) { ScrollAreaWidget &area = self.area(); - LabelWidget *gammaLabel = new LabelWidget; - gammaLabel->setText(tr("Gamma:")); + LabelWidget *gammaLabel = LabelWidget::newWithText(tr("Gamma:"), &area); + LabelWidget *contrastLabel = LabelWidget::newWithText(tr("Contrast:"), &area); + LabelWidget *brightnessLabel = LabelWidget::newWithText(tr("Brightness:"), &area); - LabelWidget *contrastLabel = new LabelWidget; - contrastLabel->setText(tr("Contrast:")); - - LabelWidget *brightnessLabel = new LabelWidget; - brightnessLabel->setText(tr("Brightness:")); - - area.add(gammaLabel); area.add(gamma = new CVarSliderWidget("vid-gamma")); - area.add(contrastLabel); area.add(contrast = new CVarSliderWidget("vid-contrast")); - area.add(brightnessLabel); area.add(brightness = new CVarSliderWidget("vid-bright")); Rule const &sliderWidth = style().rules().rule("coloradjustment.slider"); diff --git a/doomsday/client/src/ui/dialogs/inputsettingsdialog.cpp b/doomsday/client/src/ui/dialogs/inputsettingsdialog.cpp index 017e804d6a..d33d824431 100644 --- a/doomsday/client/src/ui/dialogs/inputsettingsdialog.cpp +++ b/doomsday/client/src/ui/dialogs/inputsettingsdialog.cpp @@ -96,13 +96,8 @@ InputSettingsDialog::InputSettingsDialog(String const &name) d->syncMouse->setText(tr("Uniform Mouse Axis Sensitivity")); - LabelWidget *mouseXLabel = new LabelWidget; - mouseXLabel->setText(_E(1) + tr("Mouse X")); - area().add(mouseXLabel); - - LabelWidget *mouseYLabel = new LabelWidget; - mouseYLabel->setText(_E(1) + tr("Mouse Y")); - area().add(mouseYLabel); + LabelWidget *mouseXLabel = LabelWidget::newWithText(_E(1) + tr("Mouse X"), &area()); + LabelWidget *mouseYLabel = LabelWidget::newWithText(_E(1) + tr("Mouse Y"), &area()); mouseXLabel->margins().setTop(style().rules().rule("gap")); mouseYLabel->margins().setTop(style().rules().rule("gap")); diff --git a/doomsday/client/src/ui/widgets/cvarsliderwidget.cpp b/doomsday/client/src/ui/widgets/cvarsliderwidget.cpp index 1403b9deae..fd005a23fc 100644 --- a/doomsday/client/src/ui/widgets/cvarsliderwidget.cpp +++ b/doomsday/client/src/ui/widgets/cvarsliderwidget.cpp @@ -39,23 +39,25 @@ CVarSliderWidget::CVarSliderWidget(char const *cvarPath) : d(new Instance) d->cvar = cvarPath; updateFromCVar(); + // Default range and precision for floating point variables (may be altered later). + if(d->var()->type == CVT_FLOAT) + { + if(!(d->var()->flags & (CVF_NO_MIN | CVF_NO_MAX))) + { + setRange(Rangef(d->var()->min, d->var()->max)); + } + setPrecision(2); + } + connect(this, SIGNAL(valueChangedByUser(double)), this, SLOT(setCVarValueFromWidget())); } void CVarSliderWidget::updateFromCVar() { - /// @todo Pick a reasonable step value. - float step = 0; - cvar_t *var = d->var(); if(var->type == CVT_FLOAT) { - if(!(var->flags & (CVF_NO_MIN | CVF_NO_MAX))) - { - setRange(Rangef(var->min, var->max), step); - } setValue(CVar_Float(var)); - setPrecision(2); } else { diff --git a/doomsday/client/src/ui/widgets/labelwidget.cpp b/doomsday/client/src/ui/widgets/labelwidget.cpp index abd6fe362c..a47d78447e 100644 --- a/doomsday/client/src/ui/widgets/labelwidget.cpp +++ b/doomsday/client/src/ui/widgets/labelwidget.cpp @@ -557,6 +557,17 @@ void LabelWidget::contentLayout(LabelWidget::ContentLayout &layout) d->contentPlacement(layout); } +LabelWidget *LabelWidget::newWithText(String const &label, GuiWidget *parent) +{ + LabelWidget *w = new LabelWidget; + w->setText(label); + if(parent) + { + parent->add(w); + } + return w; +} + void LabelWidget::glInit() { d->glInit(); diff --git a/doomsday/client/src/ui/widgets/sliderwidget.cpp b/doomsday/client/src/ui/widgets/sliderwidget.cpp index 49ad652d68..2637523a4d 100644 --- a/doomsday/client/src/ui/widgets/sliderwidget.cpp +++ b/doomsday/client/src/ui/widgets/sliderwidget.cpp @@ -419,8 +419,8 @@ DENG_GUI_PIMPL(SliderWidget) { Rectanglei const rect = contentRect(); - qDebug() << "click step:" << clickStep() << "value:" << value << "range:" - << range.asText() << "new value:" << value - clickStep(); + //qDebug() << "click step:" << clickStep() << "value:" << value << "range:" + // << range.asText() << "new value:" << value - clickStep(); // Maybe a click on the start/end label? if(rect.contains(ev.pos()))