Skip to content

Commit

Permalink
libappfw: Focus is hidden if the focused widget becomes invisible
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 28, 2016
1 parent 85318a6 commit f7d806a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/include/de/widgets/focuswidget.h
Expand Up @@ -36,7 +36,7 @@ class LIBAPPFW_PUBLIC FocusWidget : public LabelWidget
public:
FocusWidget(de::String const &name = "focus");

void startFlashing();
void startFlashing(GuiWidget const *reference = nullptr);
void stopFlashing();

protected slots:
Expand Down
9 changes: 6 additions & 3 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -184,10 +184,13 @@ DENG2_PIMPL(GuiRootWidget)
if(GuiWidget *w = focused->maybeAs<GuiWidget>())
{
focusIndicator->rule().setRect(w->rule());
focusIndicator->startFlashing();
if(w->attributes().testFlag(GuiWidget::FocusHidden))
if(!w->attributes().testFlag(GuiWidget::FocusHidden))
{
focusIndicator->hide();
focusIndicator->startFlashing(w);
}
else
{
focusIndicator->stopFlashing();
}
}
else
Expand Down
17 changes: 13 additions & 4 deletions doomsday/sdk/libappfw/src/widgets/focuswidget.cpp
Expand Up @@ -27,6 +27,7 @@ static TimeDelta FLASH_SPAN = .3;
DENG2_PIMPL(FocusWidget)
{
QTimer flashing;
SafeWidgetPtr<GuiWidget const> reference;

Instance(Public *i) : Base(i)
{
Expand All @@ -39,17 +40,24 @@ DENG2_PIMPL(FocusWidget)

void flash()
{
// Flashing depends on the reference widget's visibility.
float const maxOpacity = (reference? reference->visibleOpacity() : 1.f);
if(reference)
{
self.show(reference->isVisible());
}

if(self.opacity().target() == 0)
{
self.setOpacity(.8f, FLASH_SPAN + .1, .1);
self.setOpacity(.8f * maxOpacity, FLASH_SPAN + .1, .1);
}
else if(self.opacity().target() > .5f)
{
self.setOpacity(.2f, FLASH_SPAN);
self.setOpacity(.2f * maxOpacity, FLASH_SPAN);
}
else
{
self.setOpacity(.8f, FLASH_SPAN);
self.setOpacity(.8f * maxOpacity, FLASH_SPAN);
}
}
};
Expand All @@ -61,8 +69,9 @@ FocusWidget::FocusWidget(String const &name)
connect(&d->flashing, SIGNAL(timeout()), this, SLOT(updateFlash()));
}

void FocusWidget::startFlashing()
void FocusWidget::startFlashing(GuiWidget const *reference)
{
d->reference.reset(reference);
show();
if(!d->flashing.isActive())
{
Expand Down

0 comments on commit f7d806a

Please sign in to comment.