Skip to content

Commit

Permalink
Refactor|UI|Client: Convenient constructor for LabelWidget with text
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skyjake committed Sep 4, 2013
1 parent 3e3f7ab commit 4440644
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 47 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/include/ui/widgets/labelwidget.h
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/ui/dialogs/aboutdialog.cpp
Expand Up @@ -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;
Expand Down
22 changes: 5 additions & 17 deletions doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp
Expand Up @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions doomsday/client/src/ui/dialogs/coloradjustmentdialog.cpp
Expand Up @@ -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");
Expand Down
9 changes: 2 additions & 7 deletions doomsday/client/src/ui/dialogs/inputsettingsdialog.cpp
Expand Up @@ -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"));
Expand Down
18 changes: 10 additions & 8 deletions doomsday/client/src/ui/widgets/cvarsliderwidget.cpp
Expand Up @@ -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
{
Expand Down
11 changes: 11 additions & 0 deletions doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/widgets/sliderwidget.cpp
Expand Up @@ -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()))
Expand Down

0 comments on commit 4440644

Please sign in to comment.