From 9ce0ca8700a9319d8c07909b65e4eb71478d02dc Mon Sep 17 00:00:00 2001 From: skyjake Date: Sun, 17 Feb 2013 20:06:36 +0200 Subject: [PATCH] Refactor|libdeng2|libshell: Events are passed by reference to widgets --- .../libdeng2/include/de/widgets/rootwidget.h | 2 +- doomsday/libdeng2/include/de/widgets/widget.h | 4 ++-- doomsday/libdeng2/src/widgets/rootwidget.cpp | 2 +- doomsday/libdeng2/src/widgets/widget.cpp | 4 ++-- doomsday/libdeng2/widgets.pri | 2 -- .../libshell/include/de/shell/choicewidget.h | 2 +- .../include/de/shell/commandlinewidget.h | 2 +- .../libshell/include/de/shell/dialogwidget.h | 2 +- .../libshell/include/de/shell/lineeditwidget.h | 2 +- doomsday/libshell/include/de/shell/logwidget.h | 2 +- doomsday/libshell/include/de/shell/menuwidget.h | 2 +- doomsday/libshell/include/de/shell/textwidget.h | 2 +- doomsday/libshell/src/choicewidget.cpp | 12 ++++++------ doomsday/libshell/src/commandlinewidget.cpp | 12 ++++++------ doomsday/libshell/src/dialogwidget.cpp | 8 ++++---- doomsday/libshell/src/lineeditwidget.cpp | 12 ++++++------ doomsday/libshell/src/logwidget.cpp | 8 ++++---- doomsday/libshell/src/menuwidget.cpp | 16 ++++++++-------- doomsday/libshell/src/textwidget.cpp | 14 +++++++------- .../tools/shell/shell-gui/src/qtrootwidget.cpp | 6 ++---- .../tools/shell/shell-text/src/aboutdialog.cpp | 4 ++-- .../tools/shell/shell-text/src/aboutdialog.h | 2 +- .../tools/shell/shell-text/src/cursesapp.cpp | 6 ++---- 23 files changed, 61 insertions(+), 67 deletions(-) diff --git a/doomsday/libdeng2/include/de/widgets/rootwidget.h b/doomsday/libdeng2/include/de/widgets/rootwidget.h index 0666529d3a..fcbc99ab00 100644 --- a/doomsday/libdeng2/include/de/widgets/rootwidget.h +++ b/doomsday/libdeng2/include/de/widgets/rootwidget.h @@ -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(); diff --git a/doomsday/libdeng2/include/de/widgets/widget.h b/doomsday/libdeng2/include/de/widgets/widget.h index 8d62a2dc35..df7cd92885 100644 --- a/doomsday/libdeng2/include/de/widgets/widget.h +++ b/doomsday/libdeng2/include/de/widgets/widget.h @@ -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(); @@ -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); diff --git a/doomsday/libdeng2/src/widgets/rootwidget.cpp b/doomsday/libdeng2/src/widgets/rootwidget.cpp index 06bf818d11..23bd2e34b6 100644 --- a/doomsday/libdeng2/src/widgets/rootwidget.cpp +++ b/doomsday/libdeng2/src/widgets/rootwidget.cpp @@ -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)) { diff --git a/doomsday/libdeng2/src/widgets/widget.cpp b/doomsday/libdeng2/src/widgets/widget.cpp index b310f6ed5d..ac4b168c59 100644 --- a/doomsday/libdeng2/src/widgets/widget.cpp +++ b/doomsday/libdeng2/src/widgets/widget.cpp @@ -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; @@ -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; diff --git a/doomsday/libdeng2/widgets.pri b/doomsday/libdeng2/widgets.pri index 0645c26496..ba111b63f7 100644 --- a/doomsday/libdeng2/widgets.pri +++ b/doomsday/libdeng2/widgets.pri @@ -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 \ @@ -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 \ diff --git a/doomsday/libshell/include/de/shell/choicewidget.h b/doomsday/libshell/include/de/shell/choicewidget.h index 75749f7da6..ab08fa8322 100644 --- a/doomsday/libshell/include/de/shell/choicewidget.h +++ b/doomsday/libshell/include/de/shell/choicewidget.h @@ -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(); diff --git a/doomsday/libshell/include/de/shell/commandlinewidget.h b/doomsday/libshell/include/de/shell/commandlinewidget.h index a71b2952f7..0c52bf42ae 100644 --- a/doomsday/libshell/include/de/shell/commandlinewidget.h +++ b/doomsday/libshell/include/de/shell/commandlinewidget.h @@ -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); diff --git a/doomsday/libshell/include/de/shell/dialogwidget.h b/doomsday/libshell/include/de/shell/dialogwidget.h index 48a5a4e3ef..cdb59b53e7 100644 --- a/doomsday/libshell/include/de/shell/dialogwidget.h +++ b/doomsday/libshell/include/de/shell/dialogwidget.h @@ -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); diff --git a/doomsday/libshell/include/de/shell/lineeditwidget.h b/doomsday/libshell/include/de/shell/lineeditwidget.h index 35a808d996..ec1c32e538 100644 --- a/doomsday/libshell/include/de/shell/lineeditwidget.h +++ b/doomsday/libshell/include/de/shell/lineeditwidget.h @@ -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); diff --git a/doomsday/libshell/include/de/shell/logwidget.h b/doomsday/libshell/include/de/shell/logwidget.h index 3d55b7bdde..83494b6447 100644 --- a/doomsday/libshell/include/de/shell/logwidget.h +++ b/doomsday/libshell/include/de/shell/logwidget.h @@ -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: /** diff --git a/doomsday/libshell/include/de/shell/menuwidget.h b/doomsday/libshell/include/de/shell/menuwidget.h index 23ada840b5..fc3bd3e483 100644 --- a/doomsday/libshell/include/de/shell/menuwidget.h +++ b/doomsday/libshell/include/de/shell/menuwidget.h @@ -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(); diff --git a/doomsday/libshell/include/de/shell/textwidget.h b/doomsday/libshell/include/de/shell/textwidget.h index faaab37862..b852fbfedd 100644 --- a/doomsday/libshell/include/de/shell/textwidget.h +++ b/doomsday/libshell/include/de/shell/textwidget.h @@ -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; diff --git a/doomsday/libshell/src/choicewidget.cpp b/doomsday/libshell/src/choicewidget.cpp index 4e94bdb857..88c8fb96cf 100644 --- a/doomsday/libshell/src/choicewidget.cpp +++ b/doomsday/libshell/src/choicewidget.cpp @@ -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(ev); - if(!event->text().isEmpty() || event->key() == Qt::Key_Enter) + KeyEvent const &event = static_cast(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); } @@ -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; diff --git a/doomsday/libshell/src/commandlinewidget.cpp b/doomsday/libshell/src/commandlinewidget.cpp index d1752e2681..7b847a5c82 100644 --- a/doomsday/libshell/src/commandlinewidget.cpp +++ b/doomsday/libshell/src/commandlinewidget.cpp @@ -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(event); + DENG2_ASSERT(event.type() == Event::KeyPress); + KeyEvent const &ev = static_cast(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(); @@ -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); diff --git a/doomsday/libshell/src/dialogwidget.cpp b/doomsday/libshell/src/dialogwidget.cpp index 7aa2566164..e634539207 100644 --- a/doomsday/libshell/src/dialogwidget.cpp +++ b/doomsday/libshell/src/dialogwidget.cpp @@ -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(event); - if(ev->key() == Qt::Key_Escape) + KeyEvent const &ev = static_cast(event); + if(ev.key() == Qt::Key_Escape) { reject(); return true; diff --git a/doomsday/libshell/src/lineeditwidget.cpp b/doomsday/libshell/src/lineeditwidget.cpp index ea3cfbdf83..9a5d26a382 100644 --- a/doomsday/libshell/src/lineeditwidget.cpp +++ b/doomsday/libshell/src/lineeditwidget.cpp @@ -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(event); + DENG2_ASSERT(event.type() == Event::KeyPress); + KeyEvent const &ev = static_cast(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) diff --git a/doomsday/libshell/src/logwidget.cpp b/doomsday/libshell/src/logwidget.cpp index 7271227940..6feb4cf26b 100644 --- a/doomsday/libshell/src/logwidget.cpp +++ b/doomsday/libshell/src/logwidget.cpp @@ -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(event); + KeyEvent const &ev = static_cast(event); - switch(ev->key()) + switch(ev.key()) { case Qt::Key_PageUp: d->visibleOffset += 5; diff --git a/doomsday/libshell/src/menuwidget.cpp b/doomsday/libshell/src/menuwidget.cpp index 92aeafce90..8af43d1d3d 100644 --- a/doomsday/libshell/src/menuwidget.cpp +++ b/doomsday/libshell/src/menuwidget.cpp @@ -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(event); + KeyEvent const &ev = static_cast(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) @@ -412,7 +412,7 @@ bool MenuWidget::handleEvent(Event const *event) } } - if(ev->text() == " ") + if(ev.text() == " ") { itemAction(d->cursor).trigger(); close(); @@ -426,7 +426,7 @@ bool MenuWidget::handleEvent(Event const *event) return true; } - if(ev->text().isEmpty()) + if(ev.text().isEmpty()) { if(d->closable) { @@ -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; diff --git a/doomsday/libshell/src/textwidget.cpp b/doomsday/libshell/src/textwidget.cpp index b274632fef..761dfb0033 100644 --- a/doomsday/libshell/src/textwidget.cpp +++ b/doomsday/libshell/src/textwidget.cpp @@ -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(event) != 0); + DENG2_ASSERT(dynamic_cast(&event) != 0); - KeyEvent const *keyEvent = static_cast(event); + KeyEvent const &keyEvent = static_cast(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())) diff --git a/doomsday/tools/shell/shell-gui/src/qtrootwidget.cpp b/doomsday/tools/shell/shell-gui/src/qtrootwidget.cpp index 6ba69012df..64f363a842 100644 --- a/doomsday/tools/shell/shell-gui/src/qtrootwidget.cpp +++ b/doomsday/tools/shell/shell-gui/src/qtrootwidget.cpp @@ -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 { @@ -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) diff --git a/doomsday/tools/shell/shell-text/src/aboutdialog.cpp b/doomsday/tools/shell/shell-text/src/aboutdialog.cpp index 8f94c7230f..65f3149d8a 100644 --- a/doomsday/tools/shell/shell-text/src/aboutdialog.cpp +++ b/doomsday/tools/shell/shell-text/src/aboutdialog.cpp @@ -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; diff --git a/doomsday/tools/shell/shell-text/src/aboutdialog.h b/doomsday/tools/shell/shell-text/src/aboutdialog.h index 411d06aa07..df81f657cf 100644 --- a/doomsday/tools/shell/shell-text/src/aboutdialog.h +++ b/doomsday/tools/shell/shell-text/src/aboutdialog.h @@ -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 diff --git a/doomsday/tools/shell/shell-text/src/cursesapp.cpp b/doomsday/tools/shell/shell-text/src/cursesapp.cpp index b24294b9e1..bbd17e6b7a 100644 --- a/doomsday/tools/shell/shell-text/src/cursesapp.cpp +++ b/doomsday/tools/shell/shell-text/src/cursesapp.cpp @@ -347,8 +347,7 @@ DENG2_PIMPL(CursesApp) if(code) { - KeyEvent ev(code, mods); - rootWidget->processEvent(&ev); + rootWidget->processEvent(KeyEvent(code, mods)); } } else @@ -377,8 +376,7 @@ DENG2_PIMPL(CursesApp) } } - KeyEvent ev(keyStr); - rootWidget->processEvent(&ev); + rootWidget->processEvent(KeyEvent(keyStr)); } }