Skip to content

Commit

Permalink
Refactor|libdeng2|libshell: Events are passed by reference to widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 17, 2013
1 parent fbdb8cf commit 9ce0ca8
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 67 deletions.
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/widgets/rootwidget.h
Expand Up @@ -80,7 +80,7 @@ class DENG2_PUBLIC RootWidget : public Widget
*
* @return @c true, if event was eaten.
*/
bool processEvent(Event const *event);
bool processEvent(Event const &event);

void initialize();

Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/include/de/widgets/widget.h
Expand Up @@ -115,7 +115,7 @@ class DENG2_PUBLIC Widget
String uniqueName(String const &name) const;
void notifyTree(void (Widget::*notifyFunc)());
void notifyTreeReversed(void (Widget::*notifyFunc)());
bool dispatchEvent(Event const *event, bool (Widget::*memberFunc)(Event const *));
bool dispatchEvent(Event const &event, bool (Widget::*memberFunc)(Event const &));

// Events.
virtual void initialize();
Expand All @@ -125,7 +125,7 @@ class DENG2_PUBLIC Widget
virtual void update();
virtual void drawIfVisible();
virtual void draw();
virtual bool handleEvent(Event const *event);
virtual bool handleEvent(Event const &event);

public:
static void setFocusCycle(WidgetList const &order);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/widgets/rootwidget.cpp
Expand Up @@ -130,7 +130,7 @@ void RootWidget::draw()
Rule::markRulesValid(); // All done for this frame.
}

bool RootWidget::processEvent(Event const *event)
bool RootWidget::processEvent(Event const &event)
{
if(focus() && focus()->handleEvent(event))
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/src/widgets/widget.cpp
Expand Up @@ -276,7 +276,7 @@ void Widget::notifyTreeReversed(void (Widget::*notifyFunc)())
}
}

bool Widget::dispatchEvent(Event const *event, bool (Widget::*memberFunc)(Event const *))
bool Widget::dispatchEvent(Event const &event, bool (Widget::*memberFunc)(Event const &))
{
// Hidden widgets do not get events.
if(isHidden()) return false;
Expand Down Expand Up @@ -343,7 +343,7 @@ void Widget::drawIfVisible()
void Widget::draw()
{}

bool Widget::handleEvent(Event const *)
bool Widget::handleEvent(Event const &)
{
// Event is not handled.
return false;
Expand Down
2 changes: 0 additions & 2 deletions doomsday/libdeng2/widgets.pri
Expand Up @@ -3,7 +3,6 @@ HEADERS += \
include/de/AnimationVector \
include/de/DelegateRule \
include/de/ConstantRule \
include/de/Event \
include/de/OperatorRule \
include/de/RuleRectangle \
include/de/RootWidget \
Expand All @@ -15,7 +14,6 @@ HEADERS += \
include/de/widgets/animationvector.h \
include/de/widgets/constantrule.h \
include/de/widgets/delegaterule.h \
include/de/widgets/event.h \
include/de/widgets/operatorrule.h \
include/de/widgets/rulerectangle.h \
include/de/widgets/rootwidget.h \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/choicewidget.h
Expand Up @@ -63,7 +63,7 @@ class LIBSHELL_PUBLIC ChoiceWidget : public LabelWidget
void focusLost();
void focusGained();
void draw();
bool handleEvent(Event const *event);
bool handleEvent(Event const &event);

protected slots:
void updateSelectionFromMenu();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/commandlinewidget.h
Expand Up @@ -35,7 +35,7 @@ class LIBSHELL_PUBLIC CommandLineWidget : public LineEditWidget
CommandLineWidget(String const &name = "");
virtual ~CommandLineWidget();

bool handleEvent(Event const *event);
bool handleEvent(Event const &event);

signals:
void commandEntered(de::String command);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/dialogwidget.h
Expand Up @@ -48,7 +48,7 @@ class LIBSHELL_PUBLIC DialogWidget : public TextWidget

// Events.
void draw();
bool handleEvent(Event const *event);
bool handleEvent(Event const &event);

public slots:
void accept(int result = 1);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/lineeditwidget.h
Expand Up @@ -95,7 +95,7 @@ class LIBSHELL_PUBLIC LineEditWidget : public TextWidget
void viewResized();
void update();
void draw();
bool handleEvent(Event const *event);
bool handleEvent(Event const &event);

signals:
void enterPressed(de::String text);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/logwidget.h
Expand Up @@ -40,7 +40,7 @@ class LIBSHELL_PUBLIC LogWidget : public TextWidget
LogSink &logSink();

void draw();
bool handleEvent(Event const *event);
bool handleEvent(Event const &event);

public slots:
/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/menuwidget.h
Expand Up @@ -117,7 +117,7 @@ class LIBSHELL_PUBLIC MenuWidget : public TextWidget

// Events.
void draw();
bool handleEvent(Event const *);
bool handleEvent(Event const &);

public slots:
void open();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libshell/include/de/shell/textwidget.h
Expand Up @@ -121,7 +121,7 @@ class LIBSHELL_PUBLIC TextWidget : public QObject, public Widget
/**
* Checks actions and triggers them when suitable event is received.
*/
bool handleEvent(Event const *event);
bool handleEvent(Event const &event);

private:
struct Instance;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/libshell/src/choicewidget.cpp
Expand Up @@ -142,16 +142,16 @@ void ChoiceWidget::draw()
TextCanvas::Char('>', attribs()));
}

bool ChoiceWidget::handleEvent(Event const *ev)
bool ChoiceWidget::handleEvent(Event const &ev)
{
if(ev->type() == Event::KeyPress)
if(ev.type() == Event::KeyPress)
{
KeyEvent const *event = static_cast<KeyEvent const *>(ev);
if(!event->text().isEmpty() || event->key() == Qt::Key_Enter)
KeyEvent const &event = static_cast<KeyEvent const &>(ev);
if(!event.text().isEmpty() || event.key() == Qt::Key_Enter)
{
DENG2_ASSERT(!isOpen());

if(event->text().isEmpty() || event->text() == " ")
if(event.text().isEmpty() || event.text() == " ")
{
d->menu->setCursor(d->selection);
}
Expand All @@ -161,7 +161,7 @@ bool ChoiceWidget::handleEvent(Event const *ev)
int curs = d->selection;
for(int i = 0; i < d->items.size(); ++i)
{
if(d->items[i].startsWith(event->text(), Qt::CaseInsensitive))
if(d->items[i].startsWith(event.text(), Qt::CaseInsensitive))
{
curs = i;
break;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/libshell/src/commandlinewidget.cpp
Expand Up @@ -112,19 +112,19 @@ CommandLineWidget::~CommandLineWidget()
delete d;
}

bool CommandLineWidget::handleEvent(Event const *event)
bool CommandLineWidget::handleEvent(Event const &event)
{
// There are only key press events.
DENG2_ASSERT(event->type() == Event::KeyPress);
KeyEvent const *ev = static_cast<KeyEvent const *>(event);
DENG2_ASSERT(event.type() == Event::KeyPress);
KeyEvent const &ev = static_cast<KeyEvent const &>(event);

bool eaten = true;

// Control char?
if(ev->text().isEmpty())
if(ev.text().isEmpty())
{
// Override the editor's normal Enter handling.
if(ev->key() == Qt::Key_Enter)
if(ev.key() == Qt::Key_Enter)
{
d->updateCommandFromEditor();

Expand Down Expand Up @@ -160,7 +160,7 @@ bool CommandLineWidget::handleEvent(Event const *event)
if(!eaten)
{
// History navigation.
switch(ev->key())
switch(ev.key())
{
case Qt::Key_Up:
d->navigateHistory(-1);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libshell/src/dialogwidget.cpp
Expand Up @@ -85,12 +85,12 @@ void DialogWidget::draw()
targetCanvas().drawLineRect(pos);
}

bool DialogWidget::handleEvent(Event const *event)
bool DialogWidget::handleEvent(Event const &event)
{
if(event->type() == Event::KeyPress)
if(event.type() == Event::KeyPress)
{
KeyEvent const *ev = static_cast<KeyEvent const *>(event);
if(ev->key() == Qt::Key_Escape)
KeyEvent const &ev = static_cast<KeyEvent const &>(event);
if(ev.key() == Qt::Key_Escape)
{
reject();
return true;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/libshell/src/lineeditwidget.cpp
Expand Up @@ -358,23 +358,23 @@ void LineEditWidget::draw()
targetCanvas().draw(buf, pos.topLeft);
}

bool LineEditWidget::handleEvent(Event const *event)
bool LineEditWidget::handleEvent(Event const &event)
{
// There are only key press events.
DENG2_ASSERT(event->type() == Event::KeyPress);
KeyEvent const *ev = static_cast<KeyEvent const *>(event);
DENG2_ASSERT(event.type() == Event::KeyPress);
KeyEvent const &ev = static_cast<KeyEvent const &>(event);

bool eaten = true;

// Insert text?
if(!ev->text().isEmpty())
if(!ev.text().isEmpty())
{
d->insert(ev->text());
d->insert(ev.text());
}
else
{
// Control character.
eaten = handleControlKey(ev->key());
eaten = handleControlKey(ev.key());
}

if(eaten)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libshell/src/logwidget.cpp
Expand Up @@ -239,13 +239,13 @@ void LogWidget::draw()
d->sink.unlock();
}

bool LogWidget::handleEvent(Event const *event)
bool LogWidget::handleEvent(Event const &event)
{
if(event->type() != Event::KeyPress) return false;
if(event.type() != Event::KeyPress) return false;

KeyEvent const *ev = static_cast<KeyEvent const *>(event);
KeyEvent const &ev = static_cast<KeyEvent const &>(event);

switch(ev->key())
switch(ev.key())
{
case Qt::Key_PageUp:
d->visibleOffset += 5;
Expand Down
16 changes: 8 additions & 8 deletions doomsday/libshell/src/menuwidget.cpp
Expand Up @@ -351,18 +351,18 @@ void MenuWidget::draw()
targetCanvas().draw(buf, pos.topLeft);
}

bool MenuWidget::handleEvent(Event const *event)
bool MenuWidget::handleEvent(Event const &event)
{
if(!itemCount()) return false;

if(event->type() != Event::KeyPress) return false;
if(event.type() != Event::KeyPress) return false;

KeyEvent const *ev = static_cast<KeyEvent const *>(event);
KeyEvent const &ev = static_cast<KeyEvent const &>(event);

// Check menu-related control keys.
if(ev->text().isEmpty())
if(ev.text().isEmpty())
{
switch(ev->key())
switch(ev.key())
{
case Qt::Key_Up:
if(d->cursor == 0)
Expand Down Expand Up @@ -412,7 +412,7 @@ bool MenuWidget::handleEvent(Event const *event)
}
}

if(ev->text() == " ")
if(ev.text() == " ")
{
itemAction(d->cursor).trigger();
close();
Expand All @@ -426,7 +426,7 @@ bool MenuWidget::handleEvent(Event const *event)
return true;
}

if(ev->text().isEmpty())
if(ev.text().isEmpty())
{
if(d->closable)
{
Expand All @@ -441,7 +441,7 @@ bool MenuWidget::handleEvent(Event const *event)
for(int i = 0; i < d->items.size(); ++i)
{
int idx = (d->cursor + i + 1) % d->items.size();
if(d->items[idx].action->label().startsWith(ev->text(), Qt::CaseInsensitive))
if(d->items[idx].action->label().startsWith(ev.text(), Qt::CaseInsensitive))
{
setCursor(idx);
return true;
Expand Down
14 changes: 7 additions & 7 deletions doomsday/libshell/src/textwidget.cpp
Expand Up @@ -134,29 +134,29 @@ void TextWidget::removeAction(Action &action)
d->actions.removeAll(&action);
}

bool TextWidget::handleEvent(Event const *event)
bool TextWidget::handleEvent(Event const &event)
{
// We only support KeyEvents.
if(event->type() == Event::KeyPress)
if(event.type() == Event::KeyPress)
{
DENG2_ASSERT(dynamic_cast<KeyEvent const *>(event) != 0);
DENG2_ASSERT(dynamic_cast<KeyEvent const *>(&event) != 0);

KeyEvent const *keyEvent = static_cast<KeyEvent const *>(event);
KeyEvent const &keyEvent = static_cast<KeyEvent const &>(event);

foreach(Action *act, d->actions)
{
// Event will be used by actions.
if(act->tryTrigger(*keyEvent)) return true;
if(act->tryTrigger(keyEvent)) return true;
}

// Focus navigation.
if((keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Down) &&
if((keyEvent.key() == Qt::Key_Tab || keyEvent.key() == Qt::Key_Down) &&
hasFocus() && !focusNext().isEmpty())
{
if(d->navigateFocus(root(), focusNext()))
return true;
}
if((keyEvent->key() == Qt::Key_Backtab || keyEvent->key() == Qt::Key_Up) &&
if((keyEvent.key() == Qt::Key_Backtab || keyEvent.key() == Qt::Key_Up) &&
hasFocus() && !focusPrev().isEmpty())
{
if(d->navigateFocus(root(), focusPrev()))
Expand Down
6 changes: 2 additions & 4 deletions doomsday/tools/shell/shell-gui/src/qtrootwidget.cpp
Expand Up @@ -152,8 +152,7 @@ void QtRootWidget::keyPressEvent(QKeyEvent *ev)
if(!ev->text().isEmpty() && ev->text()[0].isPrint() &&
!ev->modifiers().testFlag(CONTROL_MOD))
{
KeyEvent event(ev->text());
eaten = d->root.processEvent(&event);
eaten = d->root.processEvent(KeyEvent(ev->text()));
}
else
{
Expand Down Expand Up @@ -188,8 +187,7 @@ void QtRootWidget::keyPressEvent(QKeyEvent *ev)
}
}

KeyEvent event(key, mods);
eaten = d->root.processEvent(&event);
eaten = d->root.processEvent(KeyEvent(key, mods));
}

if(eaten)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/tools/shell/shell-text/src/aboutdialog.cpp
Expand Up @@ -41,9 +41,9 @@ AboutDialog::AboutDialog()
rule().setSize(Const(40), label->rule().height());
}

bool AboutDialog::handleEvent(Event const *event)
bool AboutDialog::handleEvent(Event const &event)
{
if(event->type() == Event::KeyPress)
if(event.type() == Event::KeyPress)
{
accept();
return true;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tools/shell/shell-text/src/aboutdialog.h
Expand Up @@ -29,7 +29,7 @@ class AboutDialog : public de::shell::DialogWidget
public:
AboutDialog();

bool handleEvent(de::Event const *event);
bool handleEvent(de::Event const &event);
};

#endif // ABOUTDIALOG_H

0 comments on commit 9ce0ca8

Please sign in to comment.