Skip to content

Commit

Permalink
Cleanup|libappfw: Shorter way to access style rules
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 23, 2016
1 parent ed08f04 commit 9b4d51f
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions doomsday/sdk/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -228,6 +228,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
Widget::Children childWidgets() const;
Widget *parentWidget() const;
Style const &style() const;
Rule const &rule(DotPath const &path) const;

/**
* Returns the rule rectangle that defines the placement of the widget on
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libappfw/include/de/framework/guiwidgetprivate.h
Expand Up @@ -122,6 +122,11 @@ class GuiWidgetPrivate : public Private<PublicType>,
return Base::self.style();
}

Rule const &rule(DotPath const &path) const
{
return Base::self.rule(path);
}

void atlasContentRepositioned(Atlas &atlas)
{
if(_observingAtlas == &atlas)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/dialogcontentstylist.cpp
Expand Up @@ -125,7 +125,7 @@ void DialogContentStylist::applyStyle(GuiWidget &w)

if(LineEditWidget *ed = w.maybeAs<LineEditWidget>())
{
ed->rule().setInput(Rule::Width, d->containers.first()->style().rules().rule("editor.width"));
ed->rule().setInput(Rule::Width, d->containers.first()->rule("editor.width"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/dialogs/messagedialog.cpp
Expand Up @@ -62,7 +62,7 @@ DENG_GUI_PIMPL(MessageDialog)
// Simple vertical layout.
SequentialLayout layout(area.contentRule().left(),
area.contentRule().top());
layout.setOverrideWidth(style().rules().rule("dialog.message.width"));
layout.setOverrideWidth(rule("dialog.message.width"));

// Put all the widgets into the layout.
foreach(Widget *w, area.childWidgets())
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -413,6 +413,11 @@ Style const &GuiWidget::style() const
return Style::get();
}

Rule const &GuiWidget::rule(DotPath const &path) const
{
return style().rules().rule(path);
}

Font const &GuiWidget::font() const
{
return style().fonts().font(d->fontId);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/auxbuttonwidget.cpp
Expand Up @@ -34,7 +34,7 @@ DENG_GUI_PIMPL(AuxButtonWidget)
aux->setFont("small");
aux->setTextColor("text");
aux->setSizePolicy(ui::Expand, ui::Fixed);
Rule const &unit = style().rules().rule("unit");
Rule const &unit = rule("unit");
aux->rule()
.setInput(Rule::Right, self.rule().right() - unit)
.setInput(Rule::Top, self.rule().top() + unit)
Expand All @@ -43,7 +43,7 @@ DENG_GUI_PIMPL(AuxButtonWidget)
aux->audienceForStateChange() += this;

self.margins().set("dialog.gap").setLeft("gap");
self.margins().setRight(aux->rule().width() + style().rules().rule("gap"));
self.margins().setRight(aux->rule().width() + rule("gap"));
}

void setAuxBorderColorf(Vector4f const &colorf)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/commandwidget.cpp
Expand Up @@ -42,10 +42,10 @@ DENG_GUI_PIMPL(CommandWidget)
// most 400; never extend outside the view, though.
popup->document().rule().setInput(Rule::Height,
OperatorRule::minimum(
OperatorRule::minimum(style().rules().rule("editor.completion.height"),
OperatorRule::minimum(rule("editor.completion.height"),
popup->document().contentRule().height() +
popup->document().margins().height()),
self.rule().top() - style().rules().rule("gap")));
self.rule().top() - rule("gap")));

self.add(popup);
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libappfw/src/widgets/dialogwidget.cpp
Expand Up @@ -156,8 +156,8 @@ public ChildWidgetOrganizer::IFilter
heading->setFont("heading");
heading->margins()
.setBottom("")
.setTop (style().rules().rule("gap") + style().rules().rule("dialog.gap"))
.setLeft(style().rules().rule("gap") + style().rules().rule("dialog.gap"));
.setTop (rule("gap") + rule("dialog.gap"))
.setLeft(rule("gap") + rule("dialog.gap"));
heading->setSizePolicy(ui::Filled, ui::Expand);
heading->setTextColor("accent");
heading->setImageColor(style().colors().colorf("accent"));
Expand Down Expand Up @@ -220,7 +220,7 @@ public ChildWidgetOrganizer::IFilter
Rule const *maxHeight = holdRef(root().viewHeight());
if(self.openingDirection() == ui::Down)
{
changeRef(maxHeight, *maxHeight - self.anchor().top() - style().rules().rule("gap"));
changeRef(maxHeight, *maxHeight - self.anchor().top() - rule("gap"));
}

// The container's height is limited by the height of the view. Normally
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/widgets/documentpopupwidget.cpp
Expand Up @@ -47,7 +47,7 @@ DocumentPopupWidget::DocumentPopupWidget(ButtonWidget *actionButton, String cons
box->add(actionButton);
actionButton->setSizePolicy(ui::Expand, ui::Expand);

Rule const &gap = style().rules().rule("gap");
Rule const &gap = rule("gap");

box->rule()
.setInput(Rule::Width, d->doc->rule().width())
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/widgets/documentwidget.cpp
Expand Up @@ -272,7 +272,7 @@ void DocumentWidget::setText(String const &styledText)

d->progress->show();

int indSize = style().rules().rule("document.progress").valuei();
int indSize = rule("document.progress").valuei();
setContentSize(Vector2i(indSize, indSize));

d->styledText = styledText;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/gridpopupwidget.cpp
Expand Up @@ -40,7 +40,7 @@ GridPopupWidget::GridPopupWidget(String const &name)
d->stylist.setContainer(*d->container);

// Initialize the layout.
Rule const &gap = style().rules().rule("gap");
Rule const &gap = rule("gap");
d->layout.setLeftTop(d->container->rule().left() + gap,
d->container->rule().top() + gap);
d->layout.setGridSize(2, 0);
Expand Down Expand Up @@ -85,7 +85,7 @@ GridPopupWidget &GridPopupWidget::addSpanning(GuiWidget *widget, int cellSpan)

void GridPopupWidget::commit()
{
Rule const &gap = style().rules().rule("gap");
Rule const &gap = rule("gap");
d->container->rule().setSize(d->layout.width() + gap * 2,
d->layout.height() + gap * 2);
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/sdk/libappfw/src/widgets/notificationareawidget.cpp
Expand Up @@ -61,7 +61,7 @@ DENG_GUI_PIMPL(NotificationAreaWidget)

void updateChildLayout()
{
Rule const &gap = style().rules().rule("unit");
Rule const &gap = rule("unit");

// The children are laid out simply in a row from right to left.
SequentialLayout layout(self.rule().right(), self.rule().top(), ui::Left);
Expand Down Expand Up @@ -93,7 +93,7 @@ DENG_GUI_PIMPL(NotificationAreaWidget)

void hide(TimeDelta const &span = ANIM_SPAN)
{
shift->set(self.rule().height() + style().rules().rule("gap"), span);
shift->set(self.rule().height() + rule("gap"), span);
shift->setStyle(Animation::EaseIn);
}

Expand Down Expand Up @@ -154,14 +154,14 @@ NotificationAreaWidget::NotificationAreaWidget(String const &name)
// Initially the widget is empty.
rule().setSize(Const(0), Const(0));
d->shift->set(style().fonts().font("default").height().valuei() +
style().rules().rule("gap").valuei() * 3);
rule("gap").valuei() * 3);
hide();
}

void NotificationAreaWidget::useDefaultPlacement(RuleRectangle const &area)
{
rule().setInput(Rule::Top, area.top() + style().rules().rule("gap") - shift())
.setInput(Rule::Right, area.right() - style().rules().rule("gap"));
rule().setInput(Rule::Top, area.top() + rule("gap") - shift())
.setInput(Rule::Right, area.right() - rule("gap"));
}

Rule const &NotificationAreaWidget::shift()
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp
Expand Up @@ -257,8 +257,8 @@ DENG_GUI_PIMPL(PopupMenuWidget)
{
bool const useExtraPadding = hasButtonsWithImages();

auto const &padding = style().rules().rule("popup.menu.paddedmargin");
auto const &none = style().rules().rule("popup.menu.margin");
auto const &padding = rule("popup.menu.paddedmargin");
auto const &none = rule("popup.menu.margin");

foreach(Widget *child, self.menu().childWidgets())
{
Expand Down Expand Up @@ -295,7 +295,7 @@ DENG_GUI_PIMPL(PopupMenuWidget)
LabelWidget::ContentLayout layout;
button->contentLayout(layout);
sumInto(padRule, -Const(layout.image.width()) -
style().rules().rule(button->textGap()));
rule(button->textGap()));
}
widget.margins().setLeft(*padRule);
releaseRef(padRule);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/popupwidget.cpp
Expand Up @@ -51,7 +51,7 @@ DENG_GUI_PIMPL(PopupWidget)
Instance(Public *i) : Base(i)
{
// Style.
marker = &style().rules().rule("gap");
marker = &rule("gap");
}

~Instance()
Expand Down Expand Up @@ -360,7 +360,7 @@ GuiWidget::Background PopupWidget::infoStyleBackground() const
return Background(style().colors().colorf("popup.info.background"),
Background::BorderGlow,
style().colors().colorf("popup.info.glow"),
style().rules().rule("glow").valuei());
rule("glow").valuei());
}

bool PopupWidget::handleEvent(Event const &event)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/widgets/progresswidget.cpp
Expand Up @@ -150,7 +150,7 @@ DENG_GUI_PIMPL(ProgressWidget), public Lockable
int const midY = rect.middle().y;
int count = range.size();
Vector4f color = style().colors().colorf(colorId);
int const gap = style().rules().rule("unit").valuei();
int const gap = rule("unit").valuei();
int totalWidth = count * dotSize.x + (count - 1) * gap;

for(int i = 0; i < count; ++i)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libappfw/src/widgets/sliderwidget.cpp
Expand Up @@ -42,7 +42,7 @@ class ValuePopup : public PopupWidget
_edit->setSignalOnEnter(true);
connect(_edit, SIGNAL(enterPressed(QString)), &slider, SLOT(setValueFromText(QString)));
connect(_edit, SIGNAL(enterPressed(QString)), this, SLOT(close()));
_edit->rule().setInput(Rule::Width, slider.style().rules().rule("slider.editor"));
_edit->rule().setInput(Rule::Width, slider.rule("slider.editor"));

_edit->setText(QString::number(slider.value() * slider.displayFactor(), 'f',
slider.precision()));
Expand Down Expand Up @@ -133,7 +133,7 @@ DENG_GUI_PIMPL(SliderWidget)
textColor = style().colors().colorf("text");
invTextColor = style().colors().colorf("inverted.text");

endLabelSize = style().rules().rule("slider.label").valuei();
endLabelSize = rule("slider.label").valuei();

for(int i = 0; i < int(NUM_LABELS); ++i)
{
Expand Down Expand Up @@ -453,7 +453,7 @@ SliderWidget::SliderWidget(String const &name)
: GuiWidget(name), d(new Instance(this))
{
// Default size.
rule().setInput(Rule::Width, style().rules().rule("slider.width"))
rule().setInput(Rule::Width, rule("slider.width"))
.setInput(Rule::Height, OperatorRule::maximum(
style().fonts().font("default").height(),
font().height()) + margins().height());
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/widgets/tabwidget.cpp
Expand Up @@ -144,7 +144,7 @@ DENG_GUI_PIMPL(TabWidget)
selWidth->set(w.rule().width(), span);

selected->rule()
.setInput(Rule::Height, style().rules().rule("halfunit"))
.setInput(Rule::Height, rule("halfunit"))
.setInput(Rule::Top, w.rule().bottom());
}
}
Expand Down

0 comments on commit 9b4d51f

Please sign in to comment.