core/vgui/impl/qt/vgui_qt_adaptor.h
Go to the documentation of this file.
00001 #ifndef VGUI_QT_ADAPTOR_H_
00002 #define VGUI_QT_ADAPTOR_H_
00003 
00004 //:
00005 // \file
00006 // \brief OpenGL canvas in QT as a VGUI adaptor
00007 //
00008 // \author
00009 // Joris Schouteden, ESAT, K.U.Leuven
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   24.03.2000 JS  Initial Version, adapted from vgui_gtk_adaptor
00014 //   14.11.2005 Chanop Silpa-Anan  adapted to QT 3.3.5 for X11/Mac
00015 //   17.05.2006 Rowin Heymans      added mousewheel event handling
00016 // \endverbatim
00017 //-----------------------------------------------------------------------------
00018 
00019 #include <vgui/vgui_adaptor.h>
00020 #include <vgui/internals/vgui_adaptor_mixin.h>
00021 #include <vgui/internals/vgui_overlay_helper.h>
00022 
00023 #include <qgl.h>
00024 #include <qevent.h>
00025 #include <qobject.h>
00026 #include <qtimer.h>
00027 
00028 //: OpenGL canvas in QT as a VGUI adaptor
00029 class vgui_qt_adaptor :
00030    public QGLWidget,
00031    public vgui_adaptor,
00032    public vgui_adaptor_mixin
00033 {
00034    Q_OBJECT
00035  public:
00036    vgui_qt_adaptor(QWidget* parent=0, const char* name=0);
00037    ~vgui_qt_adaptor();
00038 
00039    void swap_buffers()
00040    {
00041      make_current ();
00042      if (doubleBuffer()) swapBuffers();
00043    }
00044    void make_current() { makeCurrent(); }
00045    void post_redraw()  { updateGL(); }
00046    void post_overlay_redraw();
00047    void post_idle_request();
00048 
00049    unsigned int get_width()  const { return QGLWidget::width(); }
00050    unsigned int get_height() const { return QGLWidget::height(); }
00051    void bind_popups(vgui_modifier m, vgui_button b)
00052    {
00053       vgui_adaptor_mixin::popup_modifier = m;
00054       vgui_adaptor_mixin::popup_button = b;
00055    }
00056    void get_popup_bindings(vgui_modifier &m, vgui_button &b) const
00057    {
00058       m = vgui_adaptor_mixin::popup_modifier;
00059       b = vgui_adaptor_mixin::popup_button;
00060    }
00061 
00062    void set_default_popup(vgui_menu) {}
00063    vgui_menu get_popup() { return vgui_menu(); }
00064 
00065  public:
00066    void paintGL();
00067    void paintOverlayGL();
00068    void resizeGL(int w, int h);
00069 
00070    void mouseMoveEvent   (QMouseEvent* e);
00071    void mousePressEvent  (QMouseEvent* e);
00072    void mouseReleaseEvent(QMouseEvent* e);
00073    void keyPressEvent    (QKeyEvent*   e);
00074    void keyReleaseEvent  (QKeyEvent*   e);
00075    void wheelEvent       (QWheelEvent* e);
00076 
00077    vgui_event translate(QMouseEvent* e);
00078    vgui_event translate(QKeyEvent* e);
00079    vgui_event translate(QWheelEvent* e);
00080 
00081  private:
00082    // pointer to overlay emulation data
00083    vgui_overlay_helper *ovl_helper;
00084    bool dispatch_to_tableau (const vgui_event &event);
00085    bool use_overlay_helper;
00086    bool idle_request_posted_;
00087    QTimer* idle_timer_;
00088 
00089  private slots:
00090    void idle_slot();
00091 
00092  protected:
00093    void windowActivationChange (bool oldActive);
00094 };
00095 
00096 #endif // VGUI_QT_ADAPTOR_H_