From bafdb949583a3178449f68afe2e2621687e29de7 Mon Sep 17 00:00:00 2001 From: Michael Dominic K Date: Mon, 22 Nov 2010 10:03:00 +0100 Subject: Dynamically register the event number. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Samuel Rødal --- tools/qmeegographicssystemhelper/qmeegoswitchevent.cpp | 12 +++++++++++- tools/qmeegographicssystemhelper/qmeegoswitchevent.h | 12 +++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/qmeegographicssystemhelper/qmeegoswitchevent.cpp b/tools/qmeegographicssystemhelper/qmeegoswitchevent.cpp index b136ce8..22ea0fe 100644 --- a/tools/qmeegographicssystemhelper/qmeegoswitchevent.cpp +++ b/tools/qmeegographicssystemhelper/qmeegoswitchevent.cpp @@ -41,7 +41,9 @@ #include "qmeegoswitchevent.h" -QMeeGoSwitchEvent::QMeeGoSwitchEvent(const QString &graphicsSystemName, QMeeGoSwitchEvent::State s) : QEvent((QEvent::Type) QMeeGoSwitchEvent::SwitchEvent) +static int switchEventNumber = -1; + +QMeeGoSwitchEvent::QMeeGoSwitchEvent(const QString &graphicsSystemName, QMeeGoSwitchEvent::State s) : QEvent(QMeeGoSwitchEvent::eventNumber()) { name = graphicsSystemName; switchState = s; @@ -55,4 +57,12 @@ QString QMeeGoSwitchEvent::graphicsSystemName() const QMeeGoSwitchEvent::State QMeeGoSwitchEvent::state() const { return switchState; +} + +QEvent::Type QMeeGoSwitchEvent::eventNumber() +{ + if (switchEventNumber < 0) + switchEventNumber = QEvent::registerEventType(); + + return (QEvent::Type) switchEventNumber; } \ No newline at end of file diff --git a/tools/qmeegographicssystemhelper/qmeegoswitchevent.h b/tools/qmeegographicssystemhelper/qmeegoswitchevent.h index 2d8371e..0ddbd3d 100644 --- a/tools/qmeegographicssystemhelper/qmeegoswitchevent.h +++ b/tools/qmeegographicssystemhelper/qmeegoswitchevent.h @@ -62,11 +62,6 @@ public: DidSwitch }; - //! The event type id to use to detect this event. - enum Type { - SwitchEvent = QEvent::User + 1024 - }; - //! Constructor for the event. /*! Creates a new event with the given name and the given state. @@ -83,6 +78,13 @@ public: //! Returns the state represented by this event. State state() const; + //! Returns the event type/number for QMeeGoSwitchEvent. + /*! + The type is registered on first access. Use this to detect incoming + QMeeGoSwitchEvents. + */ + QEvent::Type eventNumber(); + private: QString name; State switchState; -- cgit v0.12