Skip to content

Commit

Permalink
Refactor|Widgets: Better distinction between Widget and GuiWidget
Browse files Browse the repository at this point in the history
Less need for dynamic_cast.
  • Loading branch information
skyjake committed Feb 26, 2017
1 parent 65e11e7 commit 7d035cf
Show file tree
Hide file tree
Showing 32 changed files with 144 additions and 127 deletions.
Expand Up @@ -149,7 +149,7 @@ DENG_GUI_PIMPL(AudioSettingsDialog)
{
if (!DoomsdayApp::isGameLoaded()) return;

foreach (Widget *w, self().area().childWidgets() + devPopup->content().childWidgets())
foreach (GuiWidget *w, self().area().childWidgets() + devPopup->content().childWidgets())
{
if (ICVarWidget *cv = w->maybeAs<ICVarWidget>())
{
Expand Down
Expand Up @@ -57,7 +57,7 @@ DENG_GUI_PIMPL(NetworkSettingsDialog)

void fetch()
{
foreach (Widget *w, self().area().childWidgets() + devPopup->content().childWidgets())
foreach (GuiWidget *w, self().area().childWidgets() + devPopup->content().childWidgets())
{
if (ICVarWidget *cv = w->maybeAs<ICVarWidget>())
{
Expand Down
Expand Up @@ -126,7 +126,7 @@ DENG_GUI_PIMPL(RendererSettingsDialog)

void fetch()
{
foreach (Widget *child, self().area().childWidgets() + devPopup->content().childWidgets())
foreach (GuiWidget *child, self().area().childWidgets() + devPopup->content().childWidgets())
{
if (ICVarWidget *w = child->maybeAs<ICVarWidget>())
{
Expand Down
Expand Up @@ -178,7 +178,7 @@ DENG2_OBSERVES(PersistentGLWindow, AttributeChange)
fpsMax->setValue(!max ? 35 : max);
}

foreach (Widget *child, self().area().childWidgets())
foreach (GuiWidget *child, self().area().childWidgets())
{
if (ICVarWidget *cw = child->maybeAs<ICVarWidget>())
cw->updateFromCVar();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/dialogs/vrsettingsdialog.cpp
Expand Up @@ -104,7 +104,7 @@ DENG_GUI_PIMPL(VRSettingsDialog)

void fetch()
{
foreach (Widget *child, self().area().childWidgets())
foreach (GuiWidget *child, self().area().childWidgets())
{
if (ICVarWidget *w = child->maybeAs<ICVarWidget>())
{
Expand Down
13 changes: 5 additions & 8 deletions doomsday/apps/client/src/ui/editors/rendererappearanceeditor.cpp
Expand Up @@ -401,7 +401,7 @@ public VariableGroupEditor::IOwner
{
bool const isReadOnly = settings.find(settings.currentProfile()).isReadOnly();

foreach (Widget *child, self().containerWidget().childWidgets())
foreach (GuiWidget *child, self().containerWidget().childWidgets())
{
if (Group *g = child->maybeAs<Group>())
{
Expand All @@ -410,20 +410,17 @@ public VariableGroupEditor::IOwner
g->resetButton().enable(!isReadOnly && g->isOpen());

// Enable or disable settings based on read-onlyness.
foreach (Widget *w, g->content().childWidgets())
foreach (GuiWidget *st, g->content().childWidgets())
{
if (GuiWidget *st = w->maybeAs<GuiWidget>())
{
st->enable(!isReadOnly);
}
st->enable(!isReadOnly);
}
}
}
}

void saveFoldState(PersistentState &toState)
{
foreach (Widget *child, self().containerWidget().childWidgets())
foreach (GuiWidget *child, self().containerWidget().childWidgets())
{
if (Group *g = child->maybeAs<Group>())
{
Expand All @@ -437,7 +434,7 @@ public VariableGroupEditor::IOwner
{
bool gotState = false;

foreach (Widget *child, self().containerWidget().childWidgets())
foreach (GuiWidget *child, self().containerWidget().childWidgets())
{
if (Group *g = child->maybeAs<Group>())
{
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/ui/editors/variablegroupeditor.cpp
Expand Up @@ -81,7 +81,7 @@ DENG2_PIMPL(VariableGroupEditor)

void foldAll(bool fold)
{
foreach (Widget *child, owner->containerWidget().childWidgets())
foreach (GuiWidget *child, owner->containerWidget().childWidgets())
{
if (auto *g = child->maybeAs<VariableGroupEditor>())
{
Expand Down Expand Up @@ -302,7 +302,7 @@ void VariableGroupEditor::commit()

void VariableGroupEditor::fetch()
{
foreach (Widget *child, d->content->childWidgets())
foreach (GuiWidget *child, d->content->childWidgets())
{
if (ICVarWidget *w = child->maybeAs<ICVarWidget>())
{
Expand All @@ -313,7 +313,7 @@ void VariableGroupEditor::fetch()

void VariableGroupEditor::resetToDefaults()
{
foreach (Widget *child, d->content->childWidgets())
foreach (GuiWidget *child, d->content->childWidgets())
{
if (ICVarWidget *w = child->maybeAs<ICVarWidget>())
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/home/homewidget.cpp
Expand Up @@ -352,7 +352,7 @@ DENG_GUI_PIMPL(HomeWidget)
SequentialLayout layout(self().rule().left() - *scrollOffset,
self().rule().top() + *dismissOffset,
ui::Right);
for (Widget *widget : self().childWidgets())
for (GuiWidget *widget : self().childWidgets())
{
if (!widget->behavior().testFlag(Widget::Hidden))
{
Expand Down
Expand Up @@ -180,9 +180,9 @@ DENG2_PIMPL(MultiplayerServerMenuWidget)

void gameReadinessUpdated() override
{
foreach (Widget *w, self().childWidgets())
foreach (GuiWidget *w, self().childWidgets())
{
updateAvailability(w->as<GuiWidget>());
updateAvailability(*w);
}
}

Expand Down
Expand Up @@ -182,9 +182,9 @@ DENG_GUI_PIMPL(PackageContentOptionsWidget)
self().rule().setInput(Rule::Height, layout.height() + self().margins().bottom());

// Configure margins.
for (Widget *w : self().childWidgets())
for (GuiWidget *w : self().childWidgets())
{
w->as<GuiWidget>().margins().set("dialog.gap");
w->margins().set("dialog.gap");
}
contents->margins().setLeftRight("gap");

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -311,7 +311,7 @@ DENG_GUI_PIMPL(PackagesWidget)
bool const highlight = _owner.d->packageStatus->isPackageHighlighted(packageId());
_actions->setVariantItemsEnabled(highlight);

for (Widget *w : _actions->childWidgets())
for (GuiWidget *w : _actions->childWidgets())
{
if (ButtonWidget *button = w->maybeAs<ButtonWidget>())
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/sidebarwidget.cpp
Expand Up @@ -121,7 +121,7 @@ LabelWidget &SidebarWidget::title()
Rule const &SidebarWidget::maximumOfAllGroupFirstColumns() const
{
Rule const *max = nullptr;
foreach (Widget *child, d->container->childWidgets())
foreach (GuiWidget *child, d->container->childWidgets())
{
if (auto *g = child->maybeAs<VariableGroupEditor>())
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -868,7 +868,7 @@ void TaskBarWidget::updateCommandLineLayout()
RuleRectangle &cmdRule = d->console->commandLine().rule();
cmdRule.setInput(Rule::Left, d->console->buttons().rule().right())
.setInput(Rule::Bottom, rule().bottom())
.setInput(Rule::Right, layout.widgets().last()->as<GuiWidget>().rule().left());
.setInput(Rule::Right, layout.widgets().last()->rule().left());

// Just use a plain background for this editor.
d->console->commandLine().set(Background(style().colors().colorf("background")));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/include/de/framework/gridlayout.h
Expand Up @@ -96,7 +96,7 @@ class LIBAPPFW_PUBLIC GridLayout
*/
GridLayout &appendEmpty();

WidgetList widgets() const;
GuiWidgetList widgets() const;
int size() const;
bool isEmpty() const;

Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libappfw/include/de/framework/guirootwidget.h
Expand Up @@ -102,6 +102,8 @@ class LIBAPPFW_PUBLIC GuiRootWidget : public RootWidget

FocusWidget &focusIndicator();

GuiWidget *focus() const;

/**
* Pushes a pointer to the current focused widget to a stack. It can later be
* restored with popFocus().
Expand Down
7 changes: 5 additions & 2 deletions doomsday/sdk/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -151,6 +151,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget

typedef Vertex2TexRgba DefaultVertex;
typedef GLBufferT<DefaultVertex> DefaultVertexBuf;
typedef QList<GuiWidget *> Children;

/**
* Handles events.
Expand Down Expand Up @@ -258,8 +259,8 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
static void destroyLater(GuiWidget *widget);

GuiRootWidget &root() const;
Widget::Children childWidgets() const;
Widget *parentWidget() const;
Children childWidgets() const;
GuiWidget *parentGuiWidget() const;
Style const &style() const;

/**
Expand Down Expand Up @@ -589,6 +590,8 @@ struct GuiWidgetDeleter {
}
};

typedef GuiWidget::Children GuiWidgetList;

template <typename WidgetType>
class UniqueWidgetPtr : public std::unique_ptr<WidgetType, GuiWidgetDeleter<WidgetType>> {
public:
Expand Down
Expand Up @@ -83,7 +83,7 @@ class LIBAPPFW_PUBLIC SequentialLayout
SequentialLayout &append(GuiWidget &widget, Rule const &spaceBefore, AppendMode mode = UpdateMinorAxis);
SequentialLayout &append(Rule const &emptySpace);

WidgetList widgets() const;
GuiWidgetList widgets() const;
int size() const;
bool isEmpty() const;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/include/de/widgets/menuwidget.h
Expand Up @@ -155,7 +155,7 @@ class LIBAPPFW_PUBLIC MenuWidget : public ScrollAreaWidget, public IAssetGroup
*
* @return @c true, if the widget is laid out as part of the menu.
*/
bool isWidgetPartOfMenu(Widget const &widget) const;
bool isWidgetPartOfMenu(GuiWidget const &widget) const;

/**
* Lays out children of the menu according to the grid setup. This should
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/childwidgetorganizer.cpp
Expand Up @@ -383,12 +383,12 @@ DENG2_PIMPL(ChildWidgetOrganizer)

GuiWidget *firstChild() const
{
return &container->childWidgets().first()->as<GuiWidget>();
return container->childWidgets().first();
}

GuiWidget *lastChild() const
{
return &container->childWidgets().last()->as<GuiWidget>();
return container->childWidgets().last();
}

float virtualItemHeight(GuiWidget const *widget) const
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/dialogs/messagedialog.cpp
Expand Up @@ -65,12 +65,12 @@ DENG_GUI_PIMPL(MessageDialog)
layout.setOverrideWidth(rule("dialog.message.width"));

// Put all the widgets into the layout.
foreach (Widget *w, area.childWidgets())
foreach (GuiWidget *w, area.childWidgets())
{
// Individual children can be hidden to exclude them from the layout.
if (behavior == IncludeHidden || !w->behavior().testFlag(Widget::Hidden))
{
layout << w->as<GuiWidget>();
layout << *w;
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/sdk/libappfw/src/gridlayout.cpp
Expand Up @@ -27,7 +27,7 @@ DENG2_PIMPL(GridLayout)
{
typedef QMap<Vector2i, ui::Alignment> CellAlignments;

WidgetList widgets;
GuiWidgetList widgets;
Mode mode;
int maxCols;
int maxRows;
Expand Down Expand Up @@ -606,7 +606,7 @@ GridLayout &GridLayout::appendEmpty()
return *this;
}

WidgetList GridLayout::widgets() const
GuiWidgetList GridLayout::widgets() const
{
return d->widgets;
}
Expand Down Expand Up @@ -663,11 +663,11 @@ Vector2i GridLayout::widgetPos(GuiWidget &widget) const
GuiWidget *GridLayout::at(Vector2i const &cell) const
{
Vector2i pos;
foreach (Widget *w, d->widgets)
foreach (GuiWidget *w, d->widgets)
{
if (pos == cell)
{
if (w) return &w->as<GuiWidget>();
if (w) return w;
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -379,6 +379,11 @@ FocusWidget &GuiRootWidget::focusIndicator()
return *d->focusIndicator;
}

GuiWidget *GuiRootWidget::focus() const
{
return static_cast<GuiWidget *>(RootWidget::focus());
}

void GuiRootWidget::pushFocus()
{
if (!focus()) return;
Expand Down

0 comments on commit 7d035cf

Please sign in to comment.