core/vgui/impl/qt4/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 //   02.05.2007 Christoph_John@gmx.de ported to QT 4.2.2
00017 //   23.05.2007 Matt Leotta  converted to QT3 compatibility functions to native QT4
00018 // \endverbatim
00019 //-----------------------------------------------------------------------------
00020 #include <vcl_map.h>
00021 #include <vgui/vgui_adaptor.h>
00022 #include <vgui/internals/vgui_adaptor_mixin.h>
00023 #include <vgui/internals/vgui_overlay_helper.h>
00024 
00025 #include <QGLWidget>
00026 #include <QEvent>
00027 #include <QObject>
00028 #include <QTimer>
00029 #include <QWheelEvent>
00030 #include <QMouseEvent>
00031 #include <QKeyEvent>
00032 
00033 class vgui_qt_internal_timer;
00034 
00035 //: OpenGL canvas in QT as a VGUI adaptor
00036 class vgui_qt_adaptor :
00037    public QGLWidget,
00038    public vgui_adaptor,
00039    public vgui_adaptor_mixin
00040 {
00041    Q_OBJECT
00042  public:
00043    vgui_qt_adaptor(QWidget* parent=0);
00044    ~vgui_qt_adaptor();
00045 
00046    void swap_buffers()
00047    {
00048      make_current ();
00049      if (doubleBuffer()) swapBuffers();
00050    }
00051    void make_current() { makeCurrent(); }
00052    void post_redraw()  { updateGL(); }
00053    void post_overlay_redraw();
00054    void post_idle_request();
00055    
00056    void post_timer(float, int );
00057    void kill_timer(int);
00058 
00059    unsigned int get_width()  const { return QGLWidget::width(); }
00060    unsigned int get_height() const { return QGLWidget::height(); }
00061    void bind_popups(vgui_modifier m, vgui_button b)
00062    {
00063       vgui_adaptor_mixin::popup_modifier = m;
00064       vgui_adaptor_mixin::popup_button = b;
00065    }
00066    void get_popup_bindings(vgui_modifier &m, vgui_button &b) const
00067    {
00068       m = vgui_adaptor_mixin::popup_modifier;
00069       b = vgui_adaptor_mixin::popup_button;
00070    }
00071 
00072    void set_default_popup(vgui_menu) {}
00073    vgui_menu get_popup() { return vgui_menu(); }
00074 
00075  public:
00076    void paintGL();
00077    void paintOverlayGL();
00078    void resizeGL(int w, int h);
00079 
00080    void mouseMoveEvent   (QMouseEvent* e);
00081    void mousePressEvent  (QMouseEvent* e);
00082    void mouseReleaseEvent(QMouseEvent* e);
00083    void keyPressEvent    (QKeyEvent*   e);
00084    void keyReleaseEvent  (QKeyEvent*   e);
00085    void wheelEvent       (QWheelEvent* e);
00086 
00087    vgui_event translate(QMouseEvent* e);
00088    vgui_event translate(QKeyEvent* e);
00089    vgui_event translate(QWheelEvent* e);
00090 
00091    static vgui_key translate(Qt::Key k);
00092    static vgui_modifier translate(Qt::KeyboardModifiers m);
00093 
00094    static Qt::Key translate(vgui_key k);
00095    static Qt::KeyboardModifiers translate(vgui_modifier m);
00096 
00097  private:
00098    // pointer to overlay emulation data
00099    vgui_overlay_helper *ovl_helper;
00100    bool dispatch_to_tableau (const vgui_event &event);
00101    bool use_overlay_helper;
00102    bool idle_request_posted_;
00103    QTimer* idle_timer_;
00104    
00105    // map of timers currently in use
00106    vcl_map<int, vgui_qt_internal_timer*>  timers_;
00107 
00108  private slots:
00109    void idle_slot();
00110 
00111  protected:
00112    void windowActivationChange (bool oldActive);
00113    
00114    friend class vgui_qt_internal_timer;
00115 };
00116 
00117 
00118 
00119 //: A helper QObject to trigger numbered timer events 
00120 class vgui_qt_internal_timer: public QObject
00121 {
00122    Q_OBJECT
00123  public:
00124    
00125    vgui_qt_adaptor* adaptor;
00126    int id;
00127    
00128    vgui_qt_internal_timer() : adaptor(0), id(0) {}
00129    vgui_qt_internal_timer(vgui_qt_adaptor* a, int i) : adaptor(a), id(i) {}
00130    
00131  public slots:
00132    void activate(); 
00133 };
00134 
00135 #endif // vgui_qt_adaptor_h_

Generated on Mon Mar 8 05:12:25 2010 for core/vgui by  doxygen 1.5.1