Skip to content

Commit

Permalink
Widgets|libappfw: CommandWidget focus cannot be cycled when it has text
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 27, 2016
1 parent 7d551c7 commit f7ad2f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
7 changes: 6 additions & 1 deletion doomsday/sdk/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -209,6 +209,11 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
*/
EatAllMouseEvents = 0x40,

/**
* When the widget is in focus, this will prevent cycling focus away with Tab.
*/
FocusCyclingDisabled = 0x80,

DefaultAttributes = RetainStatePersistently | AnimateOpacityWhenEnabledOrDisabled
};
Q_DECLARE_FLAGS(Attributes, Attribute)
Expand Down Expand Up @@ -334,7 +339,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
* @param attr Attribute(s) to modify.
* @param op Flag operation.
*/
void setAttribute(Attributes const &attr, FlagOp op = SetFlags);
void setAttribute(Attributes const &attr, FlagOpArg op = SetFlags);

/**
* Returns the current widget attributes.
Expand Down
9 changes: 5 additions & 4 deletions doomsday/sdk/libappfw/include/de/widgets/commandwidget.h
Expand Up @@ -41,9 +41,10 @@ class LIBAPPFW_PUBLIC CommandWidget : public LineEditWidget
PopupWidget &autocompletionPopup();

// Events.
void focusGained();
void focusLost();
bool handleEvent(Event const &event);
void focusGained() override;
void focusLost() override;
bool handleEvent(Event const &event) override;
void update() override;

public slots:
/**
Expand Down Expand Up @@ -74,7 +75,7 @@ public slots:
*/
void showAutocompletionPopup(String const &completionsText);

void autoCompletionEnded(bool accepted);
void autoCompletionEnded(bool accepted) override;

signals:
void gotFocus();
Expand Down
5 changes: 3 additions & 2 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -610,7 +610,7 @@ void GuiWidget::removeEventHandler(IEventHandler *handler)
d->eventHandlers.removeOne(handler);
}

void GuiWidget::setAttribute(Attributes const &attr, FlagOp op)
void GuiWidget::setAttribute(Attributes const &attr, FlagOpArg op)
{
applyFlagOperation(d->attribs, attr, op);
}
Expand Down Expand Up @@ -756,7 +756,8 @@ bool GuiWidget::handleEvent(Event const &event)
if (hasFocus() && event.isKey())
{
KeyEvent const &key = event.as<KeyEvent>();
if (key.isKeyDown() && key.ddKey() == DDKEY_TAB)
if (key.isKeyDown() && key.ddKey() == DDKEY_TAB &&
!attributes().testFlag(FocusCyclingDisabled))
{
if (auto *focus = d->findNextWidgetToFocus(
key.modifiers().testFlag(KeyEvent::Shift)? Backward : Forward))
Expand Down
15 changes: 11 additions & 4 deletions doomsday/sdk/libappfw/src/widgets/commandwidget.cpp
Expand Up @@ -81,9 +81,9 @@ bool CommandWidget::handleEvent(Event const &event)
KeyEvent const &key = event.as<KeyEvent>();

if (d->allowReshow &&
isSuggestingCompletion() &&
key.qtKey() == Qt::Key_Tab && !d->popup->isOpen() &&
suggestedCompletions().size() > 1)
isSuggestingCompletion() &&
key.qtKey() == Qt::Key_Tab && !d->popup->isOpen() &&
suggestedCompletions().size() > 1)
{
// The completion popup has been manually dismissed, but the editor is
// still in autocompletion mode. Let's just reopen the popup with its
Expand Down Expand Up @@ -116,7 +116,7 @@ bool CommandWidget::handleEvent(Event const &event)

if (hasFocus())
{
// All Tab keys are eaten by a focused console command widget.
// All Tab keys are eaten by a focused command widget.
if (event.isKey() && event.as<KeyEvent>().ddKey() == DDKEY_TAB)
{
return true;
Expand All @@ -131,6 +131,13 @@ bool CommandWidget::handleEvent(Event const &event)
return false;
}

void CommandWidget::update()
{
LineEditWidget::update();

setAttribute(FocusCyclingDisabled, !text().isEmpty());
}

void CommandWidget::dismissContentToHistory()
{
d->history.goToLatest();
Expand Down

0 comments on commit f7ad2f6

Please sign in to comment.