Skip to content

Commit

Permalink
Fixed|UI: Widget improvements, ui::Data non-const access to items
Browse files Browse the repository at this point in the history
Fixed issues in ChoiceWidget where the state of the button was not
updated in every situation (adding/removing/updating items).

DialogWidget sets a default action for Yes and No roles, too.

LineEditWidget also eats Shift modifier events when focused.
  • Loading branch information
skyjake committed Sep 9, 2013
1 parent a7e5a97 commit 84af052
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/framework/data.h
Expand Up @@ -85,6 +85,8 @@ class Data

virtual Item *take(Pos pos) = 0;

virtual Item &at(Pos pos) = 0;

virtual Item const &at(Pos pos) const = 0;

/**
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/ui/framework/listdata.h
Expand Up @@ -36,6 +36,7 @@ class ListData : public Data
~ListData();

de::dsize size() const;
Item &at(Pos pos);
Item const &at(Pos pos) const;
Pos find(Item const &item) const;
Pos findData(QVariant const &data) const;
Expand Down
6 changes: 6 additions & 0 deletions doomsday/client/src/ui/framework/listdata.cpp
Expand Up @@ -35,6 +35,12 @@ dsize ListData::size() const
return _items.size();
}

Item &ListData::at(Data::Pos pos)
{
DENG2_ASSERT(pos < size());
return *_items[pos];
}

Item const &ListData::at(Pos pos) const
{
DENG2_ASSERT(pos < size());
Expand Down
38 changes: 25 additions & 13 deletions doomsday/client/src/ui/widgets/choicewidget.cpp
Expand Up @@ -26,7 +26,8 @@ using namespace ui;
DENG_GUI_PIMPL(ChoiceWidget),
DENG2_OBSERVES(Data, Addition),
DENG2_OBSERVES(Data, Removal),
DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation),
DENG2_OBSERVES(ContextWidgetOrganizer, WidgetUpdate)
{
/**
* Items in the choice's popup uses this as action to change the selected
Expand Down Expand Up @@ -68,6 +69,7 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
choices->menu().items().audienceForAddition += this;
choices->menu().items().audienceForRemoval += this;
choices->menu().organizer().audienceForWidgetCreation += this;
choices->menu().organizer().audienceForWidgetUpdate += this;
self.add(choices);

self.setAction(new SignalAction(thisPublic, SLOT(openPopup())));
Expand All @@ -92,6 +94,15 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
}
}

void widgetUpdatedForItem(GuiWidget &, ui::Item const &item)
{
if(isValidSelection() && &item == &self.selectedItem())
{
// Make sure the button is up to date, too.
updateButtonWithItem(self.selectedItem());
}
}

Data const &items() const
{
return choices->menu().items();
Expand Down Expand Up @@ -127,10 +138,7 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
selected--;
}

if(!isValidSelection())
{
updateButtonWithSelection();
}
updateButtonWithSelection();
}

void updateItemHighlight()
Expand All @@ -145,19 +153,23 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
}
}

void updateButtonWithItem(ui::Item const &item)
{
self.setText(item.label());

ActionItem const *act = dynamic_cast<ActionItem const *>(&item);
if(act)
{
self.setImage(act->image());
}
}

void updateButtonWithSelection()
{
// Update the main button.
if(isValidSelection())
{
ui::Item const &item = items().at(selected);
self.setText(item.label());

ActionItem const *act = dynamic_cast<ActionItem const *>(&item);
if(act)
{
self.setImage(act->image());
}
updateButtonWithItem(items().at(selected));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -251,11 +251,11 @@ DENG2_OBSERVES(ui::Data, Removal)
ButtonWidget &but = widget.as<ButtonWidget>();
if(!i->action())
{
if(i->role().testFlag(Accept))
if(i->role() & (Accept | Yes))
{
but.setAction(new SignalAction(thisPublic, SLOT(accept())));
}
else if(i->role().testFlag(Reject))
else if(i->role() & (Reject | No))
{
but.setAction(new SignalAction(thisPublic, SLOT(reject())));
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/lineeditwidget.cpp
Expand Up @@ -392,7 +392,7 @@ bool LineEditWidget::handleEvent(Event const &event)
KeyEvent const &key = event.as<KeyEvent>();

if(key.qtKey() == Qt::Key_Control || key.qtKey() == Qt::Key_Alt ||
key.qtKey() == Qt::Key_Meta)
key.qtKey() == Qt::Key_Meta || key.qtKey() == Qt::Key_Shift)
{
// Modifier keys alone will be eaten when focused.
return true;
Expand Down

0 comments on commit 84af052

Please sign in to comment.