* -*-c++-*- Producer - Copyright (C) 2001-2004  Don Burns
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
 */
#ifndef PRODUCER_QTRENDERSURFACE
#define PRODUCER_QTRENDERSURFACE

// For name clashes when Producer/Math is included with Qt, but that doesn't including anything significant itself
// and it is included _AFTER_ Qt stuff for heaven's sake!
#define QT_CLEAN_NAMESPACE

#include <qgl.h>

#include <Producer/RenderSurface>

namespace Producer {

class QtRenderSurface : public RenderSurface
{
public:
  QtRenderSurface( QWidget * parent = 0, char const * name = 0, QGLWidget const * shareWidget = 0, WFlags f = 0 ) :
    RenderSurface(),
    m_GLWidget(parent,name,shareWidget,f)
    {}

  QtRenderSurface( QGLContext * context, QWidget * parent, char const * name = 0, QGLWidget const * shareWidget = 0, WFlags f = 0 ) :
    RenderSurface(),
    m_GLWidget(context,parent,name,shareWidget,f)
    {}

  QtRenderSurface( const QGLFormat & format, QWidget * parent = 0, char const * name = 0, QGLWidget const * shareWidget = 0, WFlags f = 0 ) :
    RenderSurface(),
    m_GLWidget(format,parent,name,shareWidget,f)
    {}

  QGLWidget const * getQGLWidget() const { return m_GLWidget; }
  QGLWidget       * getQGLWidget()       { return m_GLWidget; }

  virtual bool realize()
  {
    m_GLWidget->show();
    return true;
  }

  virtual void makeCurrent()
  {
    m_GLWidget->makeCurrent();
  }

  virtual void swapBuffers()
  {
    m_GLWidget->swapBuffers();
  }

  virtual void sync( int divisor=1 )
  {
    // do nothing
  }

  virtual void setWindowRectangle( int x, int y, unsigned int width, unsigned int height, bool resize=true )
  {
    m_GLWidget->move( QPoint(x,y) );
    m_GLWidget->resize(width,height);
  }

  virtual void getWindowRectangle( int &x, int &y, unsigned int &width, unsigned int &height ) const
  {
    x      = m_GLWidget->x();
    y      = m_GLWidget->y();
    width  = m_GLWidget->width();
    height = m_GLWidget->height();
  }

  virtual void getScreenSize( unsigned int &width, unsigned int &height ) const
  {

  }

  // \see Producer::RenderSurface::run
  virtual void run()
  {
    // what to do?
  }

protected:
  virtual ~QtRenderSurface() {}

  QGLWidget  * m_GLWidget;
}; // class QtRenderSurface

} // namespace Producer

#endif // QtRenderSurface_h
