Skip to content

Commit

Permalink
UI|Client|DialogWidget: Buttonless dialogs
Browse files Browse the repository at this point in the history
Normally space is reserved for a row of buttons in the bottom of a
dialog. With the Buttonless flag, the buttons menu is left out from
the dialog.
  • Loading branch information
skyjake committed Aug 27, 2013
1 parent 6b1dac8 commit 06b0d16
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
9 changes: 8 additions & 1 deletion doomsday/client/include/ui/widgets/dialogwidget.h
Expand Up @@ -54,6 +54,12 @@ class DialogWidget : public PopupWidget
NonModal
};

enum Flag {
DefaultFlags = 0,
Buttonless = 0x1 ///< No space is reserved for buttons in the bottom.
};
Q_DECLARE_FLAGS(Flags, Flag)

enum RoleFlag {
None = 0,
Default = 0x1, ///< Pressing Space or Enter will activate this.
Expand Down Expand Up @@ -95,7 +101,7 @@ class DialogWidget : public PopupWidget
};

public:
DialogWidget(de::String const &name = "");
DialogWidget(de::String const &name = "", Flags const &flags = DefaultFlags);

Modality modality() const;

Expand Down Expand Up @@ -156,6 +162,7 @@ public slots:

typedef DialogWidget::ButtonItem DialogButtonItem;

Q_DECLARE_OPERATORS_FOR_FLAGS(DialogWidget::Flags)
Q_DECLARE_OPERATORS_FOR_FLAGS(DialogWidget::RoleFlags)

#endif // DENG_CLIENT_DIALOGWIDGET_H
73 changes: 51 additions & 22 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -83,6 +83,7 @@ DENG2_OBSERVES(ui::Context, Addition),
DENG2_OBSERVES(ui::Context, Removal)
{
Modality modality;
Flags flags;
ScrollAreaWidget *area;
MenuWidget *buttons;
QEventLoop subloop;
Expand All @@ -91,7 +92,12 @@ DENG2_OBSERVES(ui::Context, Removal)
float normalGlow;
bool animatingGlow;

Instance(Public *i) : Base(i), modality(Modal), needButtonUpdate(false), animatingGlow(false)
Instance(Public *i, Flags const &dialogFlags)
: Base(i),
modality(Modal),
flags(dialogFlags),
needButtonUpdate(false),
animatingGlow(false)
{
// Initialize the border glow.
normalGlow = self.style().colors().colorf("glow").w;
Expand All @@ -117,33 +123,56 @@ DENG2_OBSERVES(ui::Context, Removal)
area->rule()
.setInput(Rule::Left, self.rule().left())
.setInput(Rule::Top, self.rule().top())
.setInput(Rule::Width, area->contentRule().width() + area->margins().width())
.setInput(Rule::Height, container->rule().height() - buttons->rule().height() +
area->margins().bottom());

// Buttons below the area.
buttons->rule()
.setInput(Rule::Top, area->rule().bottom() - area->margins().bottom()) // overlap margins
.setInput(Rule::Right, self.rule().right());

// A blank container widget acts as the popup content parent.
container->rule().setInput(Rule::Width, OperatorRule::maximum(area->rule().width(),
buttons->rule().width()));
.setInput(Rule::Width, area->contentRule().width() + area->margins().width());

if(!flags.testFlag(Buttonless))
{
area->rule().setInput(Rule::Height, container->rule().height() -
buttons->rule().height() + area->margins().bottom());

// Buttons below the area.
buttons->rule()
.setInput(Rule::Top, area->rule().bottom() - area->margins().bottom()) // overlap margins
.setInput(Rule::Right, self.rule().right());

// A blank container widget acts as the popup content parent.
container->rule().setInput(Rule::Width, OperatorRule::maximum(area->rule().width(),
buttons->rule().width()));
}
else
{
area->rule().setInput(Rule::Height, container->rule().height() + area->margins().height());
container->rule().setInput(Rule::Width, area->rule().width());
}

container->add(area);
container->add(buttons);
if(!flags.testFlag(Buttonless))
{
container->add(buttons);
}
self.setContent(container);
}

void updateContentHeight()
{
// 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.

self.content().rule().setInput(Rule::Height,
OperatorRule::minimum(root().viewHeight(),
area->contentRule().height() +
area->margins().bottom() +
buttons->rule().height()));
if(!flags.testFlag(Buttonless))
{
self.content().rule().setInput(Rule::Height,
OperatorRule::minimum(root().viewHeight(),
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::Context::Pos, ui::Item const &)
Expand Down Expand Up @@ -291,8 +320,8 @@ DENG2_OBSERVES(ui::Context, Removal)
}
};

DialogWidget::DialogWidget(String const &name)
: PopupWidget(name), d(new Instance(this))
DialogWidget::DialogWidget(String const &name, Flags const &flags)
: PopupWidget(name), d(new Instance(this, flags))
{
setOpeningDirection(ui::NoDirection);

Expand Down

0 comments on commit 06b0d16

Please sign in to comment.