Skip to content

Commit

Permalink
Widgets|libappfw: ToggleWidget configurable with no icon
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 19, 2017
1 parent 6117fd5 commit 076006f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
10 changes: 9 additions & 1 deletion doomsday/sdk/libappfw/include/de/widgets/togglewidget.h
Expand Up @@ -34,6 +34,12 @@ class LIBAPPFW_PUBLIC ToggleWidget : public ButtonWidget
Q_OBJECT

public:
enum Flag {
DefaultFlags = 0,
WithoutIndicator = 0x1,
};
Q_DECLARE_FLAGS(Flags, Flag)

enum ToggleState {
Active,
Inactive
Expand All @@ -45,7 +51,7 @@ class LIBAPPFW_PUBLIC ToggleWidget : public ButtonWidget
DENG2_DEFINE_AUDIENCE2(Toggle, void toggleStateChanged(ToggleWidget &toggle))

public:
ToggleWidget(String const &name = String());
ToggleWidget(Flags const &flags = DefaultFlags, String const &name = String());

/**
* Sets the toggle state of the widget.
Expand Down Expand Up @@ -73,6 +79,8 @@ class LIBAPPFW_PUBLIC ToggleWidget : public ButtonWidget
DENG2_PRIVATE(d)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(ToggleWidget::Flags)

} // namespace de

#endif // LIBAPPFW_TOGGLEWIDGET_H
25 changes: 16 additions & 9 deletions doomsday/sdk/libappfw/src/widgets/togglewidget.cpp
Expand Up @@ -114,13 +114,12 @@ DENG2_OBSERVES(ButtonWidget, Press)
ToggleProceduralImage *procImage; // not owned
bool hasBeenUpdated = false;

Impl(Public *i)
: Base(i),
state(Inactive),
procImage(new ToggleProceduralImage(*i))
Impl(Public *i, Flags const &flags)
: Base(i)
, state(Inactive)
, procImage(!(flags & WithoutIndicator)? new ToggleProceduralImage(*i) : nullptr)
{
self().setImage(procImage); // base class owns it

if (procImage) self().setImage(procImage); // base class owns it
self().audienceForPress() += this;
}

Expand All @@ -137,7 +136,9 @@ DENG2_OBSERVES(ButtonWidget, Press)

DENG2_AUDIENCE_METHOD(ToggleWidget, Toggle)

ToggleWidget::ToggleWidget(String const &name) : ButtonWidget(name), d(new Impl(this))
ToggleWidget::ToggleWidget(Flags const &flags, String const &name)
: ButtonWidget(name)
, d(new Impl(this, flags))
{
setTextAlignment(ui::AlignRight);
setTextLineAlignment(ui::AlignLeft);
Expand All @@ -148,7 +149,10 @@ void ToggleWidget::setToggleState(ToggleState state, bool notify)
if (d->state != state)
{
d->state = state;
d->procImage->setState(state, hasBeenUpdated());
if (d->procImage)
{
d->procImage->setState(state, hasBeenUpdated());
}

if (notify)
{
Expand All @@ -165,7 +169,10 @@ ToggleWidget::ToggleState ToggleWidget::toggleState() const

void ToggleWidget::finishAnimation()
{
d->procImage->finishAnimation();
if (d->procImage)
{
d->procImage->finishAnimation();
}
}

} // namespace de
6 changes: 4 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/variabletogglewidget.cpp
Expand Up @@ -79,11 +79,13 @@ DENG2_OBSERVES(ToggleWidget, Toggle )
};

VariableToggleWidget::VariableToggleWidget(Variable &variable, String const &name)
: ToggleWidget(name), d(new Impl(this, variable))
: ToggleWidget(DefaultFlags, name)
, d(new Impl(this, variable))
{}

VariableToggleWidget::VariableToggleWidget(String const &label, Variable &variable, String const &name)
: ToggleWidget(name), d(new Impl(this, variable))
: ToggleWidget(DefaultFlags, name)
, d(new Impl(this, variable))
{
setText(label);
}
Expand Down

0 comments on commit 076006f

Please sign in to comment.