[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/libs/kgllib
From: Rivo Laks <rivolaks () hot ! ee>
Date: 2009-06-28 14:59:39
Message-ID: 1246201179.681323.19408.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 988716 by rivol:
Remove the fugly #define protected public hack.
GLWidget now makes some QGLWidget's protected methods public (a bit ugly also, but less than the #define
hack and should also work in Win). Event sending is done through QApplication::notify().
M +7 -2 core/kgllib/glwidget.cpp
M +22 -19 core/kgllib/glwidget.h
M +22 -7 extras/kgllib/widgetproxy.cpp
M +2 -0 extras/kgllib/widgetproxy.h
--- trunk/playground/libs/kgllib/core/kgllib/glwidget.cpp #988715:988716
@@ -3,7 +3,7 @@
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
+ * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
@@ -11,7 +11,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -134,6 +134,11 @@
return mTextRenderer;
}
+void GLWidget::glInit()
+{
+ QGLWidget::glInit();
+}
+
void GLWidget::initializeGL()
{
initializeGL(0); // 0 means default renderer
--- trunk/playground/libs/kgllib/core/kgllib/glwidget.h #988715:988716
@@ -3,7 +3,7 @@
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
+ * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
@@ -11,7 +11,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -78,6 +78,26 @@
**/
bool glInitialized() const { return mGLInitialized; }
+ /**
+ * Called when the widget is resized. Base implementation:
+ * @li sets up a new viewport, covering the entire widget
+ * @li updates @ref camera's aspect and applies the camera
+ **/
+ virtual void resizeGL(int width, int height);
+ /**
+ * Called when the widget needs to be painted. Base implementation:
+ * @li updates @ref fpsCounter
+ * @li clears color and possibly depth buffer is @ref automaticClear is true
+ * @li applies @ref camera
+ *
+ * Note that applications are preferred to use @ref render() instead. If
+ * you do your OpenGL rendering in this method then some functionality
+ * provided by this class will not work (e.g. fps display).
+ **/
+ virtual void paintGL();
+
+ virtual void glInit();
+
public Q_SLOTS:
void toggleShowFps();
void toggleWireframeMode();
@@ -100,23 +120,6 @@
**/
virtual void initializeGL(Renderer* r);
/**
- * Called when the widget is resized. Base implementation:
- * @li sets up a new viewport, covering the entire widget
- * @li updates @ref camera's aspect and applies the camera
- **/
- virtual void resizeGL(int width, int height);
- /**
- * Called when the widget needs to be painted. Base implementation:
- * @li updates @ref fpsCounter
- * @li clears color and possibly depth buffer is @ref automaticClear is true
- * @li applies @ref camera
- *
- * Note that applications are preferred to use @ref render() instead. If
- * you do your OpenGL rendering in this method then some functionality
- * provided by this class will not work (e.g. fps display).
- **/
- virtual void paintGL();
- /**
* Called from @ref paintGL() when the widget needs to be painted. This is
* the method that you should reimplement to do your rendering.
* Base implementation does nothing, so you needn't call it from your
--- trunk/playground/libs/kgllib/extras/kgllib/widgetproxy.cpp #988715:988716
@@ -15,10 +15,6 @@
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// I know, this is ugly as hell. But we need access to some of the GLWidget's
-// protected methods (paintGL() and resizeGL()) and I don't want to make
-// GLWidget aware of the proxy (e.g. make proxy GLWidget's friend) either.
-#define protected public
#include "widgetproxy.h"
#include "glwidget.h"
@@ -30,6 +26,7 @@
#include <QVBoxLayout>
#include <QGraphicsProxyWidget>
#include <QtDebug>
+#include <QApplication>
namespace KGLLib
@@ -76,6 +73,7 @@
WidgetProxy::WidgetProxy(GLWidget* w, QWidget* parent) : QGraphicsView(parent)
{
+ mEventIsBeingForwarded = false;
mGLWidget = w;
if (!mGLWidget->glInitialized()) {
qDebug() << "Initing glWidget";
@@ -115,6 +113,10 @@
bool WidgetProxy::event(QEvent* event)
{
+ if (mEventIsBeingForwarded) {
+ return false;
+ }
+
//qDebug() << "WidgetProxy::event() event" << event->type();
// We treat graphicsview stuff as being "above" the GL widget, so the
// events are usually first sent to the QGV and if it ignores them, then
@@ -126,11 +128,24 @@
return true;
}
//qDebug() << "WidgetProxy::event(): fwding to GL";
- return mGLWidget->event(event);
+ return forwardEvent(event);
}
+bool WidgetProxy::forwardEvent(QEvent* event)
+{
+ mEventIsBeingForwarded = true;
+ bool ret = qApp->notify(mGLWidget, event);
+ mEventIsBeingForwarded = false;
+
+ return ret;
+}
+
bool WidgetProxy::viewportEvent(QEvent* event)
{
+ if (mEventIsBeingForwarded) {
+ return false;
+ }
+
//qDebug() << "WidgetProxy::viewportEvent() event" << event->type();
// For mouse and wheel events, if there is no QGV item under the cursor,
// then the event gets forwarded to GL widget.
@@ -151,7 +166,7 @@
// a widget). The reason is that if we'd send them only to the GL
// widget then QGV's cursor changing mechanism won't work when mouse
// leaves a widget with custom cursor.
- mGLWidget->event(event);
+ forwardEvent(event);
event->ignore();
} else if (event->type() == QEvent::ShowToParent) {
// We intercept show/hide events of viewport widget to show/hide
@@ -177,7 +192,7 @@
scene()->setFocusItem(0);
//qDebug() << "WidgetProxy::handleMouseEvent(): forwarding event";
// Forward the event to GL widget.
- return mGLWidget->event(event);
+ return forwardEvent(event);
}
return false;
}
--- trunk/playground/libs/kgllib/extras/kgllib/widgetproxy.h #988715:988716
@@ -52,11 +52,13 @@
virtual bool viewportEvent(QEvent* event);
bool handleMouseEvent(QEvent* event, const QPoint& pos);
+ bool forwardEvent(QEvent* event);
private:
class Scene;
GLWidget* mGLWidget;
+ bool mEventIsBeingForwarded;
};
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic