Skip to content

Commit

Permalink
UI|Client|DialogWidget: Added an optional heading for dialogs
Browse files Browse the repository at this point in the history
Any dialog can now have a heading. MessageDialog still uses its own
title label to display an even larger title.

Todo for later: The dialog heading could be used for tab switching.
  • Loading branch information
skyjake committed Sep 2, 2013
1 parent 6cb0046 commit 9b68e50
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
4 changes: 4 additions & 0 deletions doomsday/client/data/defaultstyle.pack/fonts.dei
Expand Up @@ -63,6 +63,10 @@ font title inherits default {
weight: light
}

font heading inherits title {
size $: gui.scale(default.size, 1.2)
}

group editor {
font plaintext inherits default {}
font hint inherits default {
Expand Down
8 changes: 7 additions & 1 deletion doomsday/client/include/ui/widgets/dialogwidget.h
Expand Up @@ -56,7 +56,7 @@ class DialogWidget : public PopupWidget

enum Flag {
DefaultFlags = 0,
Buttonless = 0x1 ///< No space is reserved for buttons in the bottom.
WithHeading = 0x1 ///< Dialog has a heading above the content area.
};
Q_DECLARE_FLAGS(Flags, Flag)

Expand Down Expand Up @@ -105,6 +105,12 @@ class DialogWidget : public PopupWidget

Modality modality() const;

/**
* If the dialog was created using the WithHeading flag, this will return the
* label used for the dialog heading.
*/
LabelWidget &heading();

ScrollAreaWidget &area();

MenuWidget &buttons();
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/ui/dialogs/coloradjustmentdialog.cpp
Expand Up @@ -74,8 +74,9 @@ DENG_GUI_PIMPL(ColorAdjustmentDialog)
};

ColorAdjustmentDialog::ColorAdjustmentDialog(String const &name)
: DialogWidget(name), d(new Instance(this))
: DialogWidget(name, WithHeading), d(new Instance(this))
{
heading().setText(tr("Color Adjustments"));
buttons().items()
<< new DialogButtonItem(DialogWidget::Default | DialogWidget::Accept, tr("Close"))
<< new DialogButtonItem(DialogWidget::Action, tr("Reset to Defaults"),
Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/src/ui/dialogs/videosettingsdialog.cpp
Expand Up @@ -127,8 +127,10 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
};

VideoSettingsDialog::VideoSettingsDialog(String const &name)
: DialogWidget(name), d(new Instance(this))
: DialogWidget(name, WithHeading), d(new Instance(this))
{
heading().setText(tr("Video Settings"));

// Toggles for video/window options.
d->fullscreen->setText(tr("Fullscreen"));
d->fullscreen->setAction(new CommandAction("togglefullscreen"));
Expand Down
58 changes: 52 additions & 6 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -85,6 +85,7 @@ DENG2_OBSERVES(ui::Data, Removal)
Modality modality;
Flags flags;
ScrollAreaWidget *area;
LabelWidget *heading;
MenuWidget *buttons;
QEventLoop subloop;
Animation glow;
Expand All @@ -96,6 +97,7 @@ DENG2_OBSERVES(ui::Data, Removal)
: Base(i),
modality(Modal),
flags(dialogFlags),
heading(0),
needButtonUpdate(false),
animatingGlow(false)
{
Expand Down Expand Up @@ -125,7 +127,26 @@ DENG2_OBSERVES(ui::Data, Removal)
.setInput(Rule::Top, self.rule().top())
.setInput(Rule::Width, area->contentRule().width() + area->margins().width());

if(!flags.testFlag(Buttonless))
// Will a title be included?
if(flags & WithHeading)
{
heading = new LabelWidget;
heading->setFont("heading");
heading->margins().setBottom("");
heading->setSizePolicy(ui::Expand, ui::Expand);
heading->setTextColor("accent");
heading->setAlignment(ui::AlignLeft);
heading->setTextLineAlignment(ui::AlignLeft);
container->add(heading);

heading->rule()
.setInput(Rule::Top, self.rule().top())
.setInput(Rule::Left, self.rule().left());

area->rule().setInput(Rule::Top, heading->rule().bottom());
}

//if(!flags.testFlag(Buttonless))
{
area->rule().setInput(Rule::Height, container->rule().height() -
buttons->rule().height() + area->margins().bottom());
Expand All @@ -139,14 +160,23 @@ DENG2_OBSERVES(ui::Data, Removal)
container->rule().setInput(Rule::Width, OperatorRule::maximum(area->rule().width(),
buttons->rule().width()));
}
else

if(flags.testFlag(WithHeading))
{
area->rule().setInput(Rule::Height,
container->rule().height()
- heading->rule().height()
- buttons->rule().height()
+ area->margins().bottom());
}
/*else
{
area->rule().setInput(Rule::Height, container->rule().height() + area->margins().height());
container->rule().setInput(Rule::Width, area->rule().width());
}
}*/

container->add(area);
if(!flags.testFlag(Buttonless))
//if(!flags.testFlag(Buttonless))
{
container->add(buttons);
}
Expand All @@ -157,7 +187,7 @@ DENG2_OBSERVES(ui::Data, Removal)
{
// The container's height is limited by the height of the view. Normally
// the dialog tries to show the full height of the content area.
if(!flags.testFlag(Buttonless))
if(!flags.testFlag(WithHeading))
{
self.content().rule().setInput(Rule::Height,
OperatorRule::minimum(root().viewHeight(),
Expand All @@ -166,13 +196,23 @@ DENG2_OBSERVES(ui::Data, Removal)
buttons->rule().height()));
}
else
{
self.content().rule().setInput(Rule::Height,
OperatorRule::minimum(root().viewHeight(),
heading->rule().height() +
area->contentRule().height() +
area->margins().bottom() +
buttons->rule().height()));
}

/*else
{
// A blank container widget acts as the popup content parent.
self.content().rule().setInput(Rule::Height,
OperatorRule::minimum(root().viewHeight(),
area->contentRule().height() +
area->margins().height()));
}
}*/
}

void contextItemAdded(ui::Data::Pos, ui::Item const &)
Expand Down Expand Up @@ -349,6 +389,12 @@ DialogWidget::Modality DialogWidget::modality() const
return d->modality;
}

LabelWidget &DialogWidget::heading()
{
DENG2_ASSERT(d->heading != 0);
return *d->heading;
}

ScrollAreaWidget &DialogWidget::area()
{
return *d->area;
Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/src/ui/widgets/popupwidget.cpp
Expand Up @@ -144,7 +144,10 @@ DENG_GUI_PIMPL(PopupWidget)
case ui::Left:
self.rule()
.setInput(Rule::Right, *anchorX - *marker)
.setInput(Rule::Top, *anchorY - self.rule().height() / 2);
.setInput(Rule::Top, OperatorRule::clamped(
*anchorY - self.rule().height() / 2,
self.margins().top(),
self.root().viewHeight() - self.rule().height() - self.margins().bottom()));
break;

case ui::Right:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -51,7 +51,7 @@ static uint POS_PANEL = 0;
static uint POS_UNLOAD = 1;
static uint POS_GAME_SEPARATOR = 2;
static uint POS_VIDEO_SETTINGS = 3;
static uint POS_UPDATER_SETTINGS = 5;
static uint POS_UPDATER_SETTINGS = 4;

DENG_GUI_PIMPL(TaskBarWidget),
public IGameChangeObserver
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/src/updater/updatersettingsdialog.cpp
Expand Up @@ -199,8 +199,10 @@ DENG2_OBSERVES(ToggleWidget, Toggle)
};

UpdaterSettingsDialog::UpdaterSettingsDialog(Mode mode, String const &name)
: DialogWidget(name), d(new Instance(this, mode))
{}
: DialogWidget(name, WithHeading), d(new Instance(this, mode))
{
heading().setText(tr("Updater Settings"));
}

void UpdaterSettingsDialog::applyAndCheckNow()
{
Expand Down

0 comments on commit 9b68e50

Please sign in to comment.