Commit f96cd318 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Improve diaglib.


- Fix prototype for glinfo() for Qt 4
- Add more event types and object type flags to event filter.

Change-Id: Ia4160b40486d054e860a339e7b5c9c28695330ae
Reviewed-by: default avatarShawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: default avatarAndy Shaw <andy.shaw@digia.com>
Showing with 57 additions and 6 deletions
...@@ -52,6 +52,8 @@ EventFilter::EventFilter(QObject *p) ...@@ -52,6 +52,8 @@ EventFilter::EventFilter(QObject *p)
void EventFilter::init(EventCategories eventCategories) void EventFilter::init(EventCategories eventCategories)
{ {
m_objectTypes = OtherType | QWidgetType | QWindowType;
if (eventCategories & MouseEvents) { if (eventCategories & MouseEvents) {
m_eventTypes << QEvent::MouseButtonPress << QEvent::MouseButtonRelease m_eventTypes << QEvent::MouseButtonPress << QEvent::MouseButtonRelease
<< QEvent::MouseButtonDblClick << QEvent::NonClientAreaMouseButtonPress << QEvent::MouseButtonDblClick << QEvent::NonClientAreaMouseButtonPress
...@@ -79,6 +81,13 @@ void EventFilter::init(EventCategories eventCategories) ...@@ -79,6 +81,13 @@ void EventFilter::init(EventCategories eventCategories)
m_eventTypes << QEvent::KeyPress << QEvent::KeyRelease << QEvent::ShortcutOverride m_eventTypes << QEvent::KeyPress << QEvent::KeyRelease << QEvent::ShortcutOverride
<< QEvent::Shortcut; << QEvent::Shortcut;
} }
if (eventCategories & FocusEvents) {
m_eventTypes
#if QT_VERSION >= 0x050000
<< QEvent::FocusAboutToChange
#endif
<< QEvent::FocusIn << QEvent::FocusOut;
}
if (eventCategories & GeometryEvents) if (eventCategories & GeometryEvents)
m_eventTypes << QEvent::Move << QEvent::Resize; m_eventTypes << QEvent::Move << QEvent::Resize;
if (eventCategories & PaintEvents) { if (eventCategories & PaintEvents) {
...@@ -88,18 +97,44 @@ void EventFilter::init(EventCategories eventCategories) ...@@ -88,18 +97,44 @@ void EventFilter::init(EventCategories eventCategories)
m_eventTypes << QEvent::Expose; m_eventTypes << QEvent::Expose;
#endif #endif
} }
if (eventCategories & StateChangeEvents) {
m_eventTypes
<< QEvent::WindowStateChange
<< QEvent::WindowBlocked << QEvent::WindowUnblocked
#if QT_VERSION >= 0x050000
<< QEvent::ApplicationStateChange
#endif
<< QEvent::ApplicationActivate << QEvent::ApplicationDeactivate;
}
if (eventCategories & TimerEvents) if (eventCategories & TimerEvents)
m_eventTypes << QEvent::Timer << QEvent::ZeroTimerEvent; m_eventTypes << QEvent::Timer << QEvent::ZeroTimerEvent;
if (eventCategories & ObjectEvents) { if (eventCategories & ObjectEvents) {
m_eventTypes << QEvent::ChildAdded << QEvent::ChildPolished m_eventTypes << QEvent::ChildAdded << QEvent::ChildPolished
<< QEvent::ChildRemoved << QEvent::Create << QEvent::Destroy; << QEvent::ChildRemoved << QEvent::Create << QEvent::Destroy;
} }
if (eventCategories & InputMethodEvents) {
m_eventTypes << QEvent::InputMethod;
#if QT_VERSION >= 0x050000
m_eventTypes << QEvent::InputMethodQuery;
#endif
}
}
static inline bool matchesType(const QObject *o, EventFilter::ObjectTypes types)
{
if (o->isWidgetType())
return types & EventFilter::QWidgetType;
#if QT_VERSION >= 0x050000
if (o->isWindowType())
return types & EventFilter::QWindowType;
#endif
return types & EventFilter::OtherType;
} }
bool EventFilter::eventFilter(QObject *o, QEvent *e) bool EventFilter::eventFilter(QObject *o, QEvent *e)
{ {
static int n = 0; static int n = 0;
if (m_eventTypes.contains(e->type())) { if (matchesType(o, m_objectTypes) && m_eventTypes.contains(e->type())) {
QDebug debug = qDebug().nospace(); QDebug debug = qDebug().nospace();
const QString on = o->objectName(); const QString on = o->objectName();
debug << '#' << n++ << ' ' << o->metaObject()->className(); debug << '#' << n++ << ' ' << o->metaObject()->className();
......
...@@ -52,25 +52,41 @@ public: ...@@ -52,25 +52,41 @@ public:
TabletEvents = 0x00008, TabletEvents = 0x00008,
DragAndDropEvents = 0x00010, DragAndDropEvents = 0x00010,
KeyEvents = 0x00020, KeyEvents = 0x00020,
GeometryEvents = 0x00040, FocusEvents = 0x00040,
PaintEvents = 0x00080, GeometryEvents = 0x00080,
TimerEvents = 0x00100, PaintEvents = 0x00100,
ObjectEvents = 0x00200 StateChangeEvents = 0x00200,
InputMethodEvents = 0x00400,
TimerEvents = 0x00800,
ObjectEvents = 0x01000,
AllEvents = 0xFFFFF
}; };
Q_DECLARE_FLAGS(EventCategories, EventCategory) Q_DECLARE_FLAGS(EventCategories, EventCategory)
enum ObjectType {
QWindowType = 0x1,
QWidgetType = 0x2,
OtherType = 0x4
};
Q_DECLARE_FLAGS(ObjectTypes, ObjectType)
explicit EventFilter(EventCategories eventCategories, QObject *p = 0); explicit EventFilter(EventCategories eventCategories, QObject *p = 0);
explicit EventFilter(QObject *p = 0); explicit EventFilter(QObject *p = 0);
bool eventFilter(QObject *, QEvent *); bool eventFilter(QObject *, QEvent *);
ObjectTypes objectTypes() const { return m_objectTypes; }
void setObjectTypes(ObjectTypes objectTypes) { m_objectTypes = objectTypes; }
private: private:
void init(EventCategories eventCategories); void init(EventCategories eventCategories);
QList<QEvent::Type> m_eventTypes; QList<QEvent::Type> m_eventTypes;
ObjectTypes m_objectTypes;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::EventCategories) Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::EventCategories)
Q_DECLARE_OPERATORS_FOR_FLAGS(EventFilter::ObjectTypes)
} // namespace QtDiag } // namespace QtDiag
......
...@@ -102,7 +102,7 @@ static QString getGlString(GLenum name) ...@@ -102,7 +102,7 @@ static QString getGlString(GLenum name)
return QString(); return QString();
} }
QString glInfo(const QWidget *) QString glInfo(const QObject *)
{ {
return getGlString(GL_VENDOR) + QLatin1Char('\n') + getGlString(GL_RENDERER); return getGlString(GL_VENDOR) + QLatin1Char('\n') + getGlString(GL_RENDERER);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment