Skip to content

Commit

Permalink
UI|Home: Keep action buttons hidden until needed
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 27, 2016
1 parent 2126926 commit 75c8f83
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions doomsday/apps/client/src/ui/home/homeitemwidget.cpp
Expand Up @@ -19,6 +19,7 @@
#include "ui/home/homeitemwidget.h"

#include <de/SequentialLayout>
#include <QTimer>

using namespace de;

Expand Down Expand Up @@ -66,6 +67,7 @@ DENG_GUI_PIMPL(HomeItemWidget)
DotPath selectedBgColor { "background" };
DotPath textColor { "text" };
DotPath selectedTextColor { "text" };
QTimer buttonHideTimer;

Instance(Public *i) : Base(i)
{
Expand All @@ -82,6 +84,12 @@ DENG_GUI_PIMPL(HomeItemWidget)

background->setBehavior(Focusable);
background->addEventHandler(new ClickHandler(self));

buttonHideTimer.setSingleShot(true);
QObject::connect(&buttonHideTimer, &QTimer::timeout, [this] ()
{
for(auto *btn : buttons) btn->hide();
});
}

~Instance()
Expand All @@ -106,6 +114,12 @@ DENG_GUI_PIMPL(HomeItemWidget)
{
if(!buttonsWidth) return;

if(show)
{
buttonHideTimer.stop();
for(auto *button : buttons) button->show();
}

TimeDelta const SPAN = .5;
if(show)
{
Expand All @@ -114,6 +128,8 @@ DENG_GUI_PIMPL(HomeItemWidget)
else
{
labelRightMargin->set(-rule("halfunit"), SPAN);
buttonHideTimer.setInterval(SPAN.asMilliSeconds());
buttonHideTimer.start();
}
}

Expand Down Expand Up @@ -169,16 +185,19 @@ LabelWidget &HomeItemWidget::label()

void HomeItemWidget::setSelected(bool selected)
{
d->selected = selected;
if(selected)
{
d->showButtons(true);
}
else
if(d->selected != selected)
{
d->showButtons(false);
d->selected = selected;
if(selected)
{
d->showButtons(true);
}
else
{
d->showButtons(false);
}
d->updateColors();
}
d->updateColors();
}

bool HomeItemWidget::isSelected() const
Expand Down Expand Up @@ -211,5 +230,6 @@ void HomeItemWidget::addButton(ButtonWidget *button)

d->buttons << button;
d->label->add(button);
button->hide();
d->updateButtonLayout();
}

0 comments on commit 75c8f83

Please sign in to comment.