summaryrefslogtreecommitdiffstats
path: root/examples/qwidget-compositor
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-03-15 12:11:34 +0100
committerSamuel Rødal <samuel.rodal@nokia.com>2011-03-15 12:11:34 +0100
commita8214a389a97f11d9817718b5b2d99b5951f9fa7 (patch)
treee2fda0f1fbd4f034ea45b393cf67b48acc09b032 /examples/qwidget-compositor
parent29af027e62bde6b9de425615055775da46605f4b (diff)
Make WaylandSurface a QObject to have a signal API.
Diffstat (limited to 'examples/qwidget-compositor')
-rw-r--r--examples/qwidget-compositor/main.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/examples/qwidget-compositor/main.cpp b/examples/qwidget-compositor/main.cpp
index 659058b43..58c87c85f 100644
--- a/examples/qwidget-compositor/main.cpp
+++ b/examples/qwidget-compositor/main.cpp
@@ -61,6 +61,7 @@ class QWidgetCompositor : public QGLWidget, public WaylandCompositor
class QWidgetCompositor : public QWidget, public WaylandCompositor
#endif
{
+ Q_OBJECT
public:
QWidgetCompositor() : WaylandCompositor(this), m_dragSurface(0) {
setMouseTracking(true);
@@ -73,36 +74,39 @@ public:
}
}
-protected:
-
- void surfaceCreated(WaylandSurface *) {
- update();
- }
-
- void surfaceDestroyed(WaylandSurface *surface) {
+private slots:
+ void surfaceDestroyed(QObject *object) {
+ WaylandSurface *surface = qobject_cast<WaylandSurface *>(object);
m_surfaces.removeAll(surface);
if (m_surfaces.isEmpty())
setInputFocus(0);
update();
}
- void surfaceMapped(WaylandSurface *surface, const QRect &rect) {
+ void surfaceMapped(const QRect &rect) {
+ WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
QPoint pos;
- int index = m_surfaces.indexOf(surface);
- if (index == -1) {
+ if (!m_surfaces.contains(surface)) {
uint px = 1 + (qrand() % (width() - rect.width() - 2));
uint py = 1 + (qrand() % (height() - rect.height() - 2));
pos = QPoint(px, py);
surface->setGeometry(QRect(pos, rect.size()));
m_surfaces.append(surface);
} else {
- m_surfaces[index]->setGeometry(rect);
+ surface->setGeometry(rect);
}
setInputFocus(surface);
update();
}
- void surfaceDamaged(WaylandSurface *surface, const QRect &rect) {
+ void surfaceDamaged(const QRect &rect) {
+ WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
+ surfaceDamaged(surface, rect);
+ }
+
+protected:
+ void surfaceDamaged(WaylandSurface *surface, const QRect &rect)
+ {
#ifdef QT_COMPOSITOR_WAYLAND_GL
Q_UNUSED(surface);
Q_UNUSED(rect);
@@ -112,6 +116,13 @@ protected:
#endif
}
+ void surfaceCreated(WaylandSurface *surface) {
+ connect(surface, SIGNAL(destroyed(QObject *)), this, SLOT(surfaceDestroyed(QObject *)));
+ connect(surface, SIGNAL(mapped(const QRect &)), this, SLOT(surfaceMapped(const QRect &)));
+ connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &)));
+ update();
+ }
+
void paintEvent(QPaintEvent *) {
QPainter p(this);
@@ -243,3 +254,4 @@ int main(int argc, char *argv[])
}
+#include "main.moc"