summaryrefslogtreecommitdiffstats
path: root/src/komposeglfullscreenwidget.cpp
blob: 095a1defa0bfd33b619b723b1f02dff5527b4773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// C++ Implementation: komposeglwidget
//
// Description:
//
//
// Author: Hans Oischinger <oisch@sourceforge.net>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "komposeglfullscreenwidget.h"

#include "komposelayout.h"
#include "komposetaskmanager.h"
#include "komposegldesktopwidget.h"
#include <kdebug.h>

#include <GL/gl.h>
#include <GL/glut.h>

KomposeGLFullscreenWidget::KomposeGLFullscreenWidget(QWidget *parent, const char *name) :
    QGLWidget(parent, name)
{
  qDebug("KomposeGLFullscreenWidget::KomposeGLFullscreenWidget()");
  layout = new KomposeLayout( this );

  setWindowState(Qt::WindowMaximized | Qt::WindowActive);
  showFullScreen();
  
  createDesktopWidgets();
}


KomposeGLFullscreenWidget::~KomposeGLFullscreenWidget()
{}

void KomposeGLFullscreenWidget::createDesktopWidgets()
{
  // Create a Widget for every desktop
  for (int i=0; i < KomposeTaskManager::instance()->getNumDesktops(); ++i)
  {
    int row = i / 2;
    int col = i % 2;
    //qDebug("rc %d %d", row, col);
    desktop[i] = new KomposeGLDesktopWidget(i, this);
    layout->add(dynamic_cast<KomposeWidgetInterface*>(desktop[i]));
  }
}

void KomposeGLFullscreenWidget::initializeGL()
{
  // Set up the rendering context, define display lists etc.:
  if( !format().hasOpenGL() )
  {
    qWarning( "KomposeGLFullscreenWidget::initializeGL() - OpenGL not supported!" );
    return;
  }

  if ( !format().doubleBuffer() )
  {
    qWarning( "KomposeGLFullscreenWidget::initializeGL() - Direct rendering enabled !" );
  }
//   glShadeModel(GL_SMOOTH);
// 
//   format().setDirectRendering( true );
//   format().setDoubleBuffer( true );
//   format().setRgba( true );
//   format().setDepth ( false );
//   format().setAccum( false );
//   format().setStencil( false );
//   format().setAlpha( true );

  // Alpha blend
//   glEnable( GL_BLEND );
//   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

  // All smoothing stuff
//   glEnable( GL_POLYGON_SMOOTH );
//   glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST );
//   glEnable( GL_POINT_SMOOTH );
//   glHint( GL_POINT_SMOOTH_HINT, GL_FASTEST );
//   glEnable( GL_LINE_SMOOTH );
//   glHint( GL_LINE_SMOOTH_HINT, GL_FASTEST );

  // Lighting and Depth Test
  glDisable( GL_LIGHTING );
//   glDisable( GL_DEPTH_TEST );
//   glDisable( GL_NORMALIZE );

  glClearColor( 0.0, 0.0, 0.0, 0.0 );
  glClear( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT );

  /*! Setup sizes */
//   glLineWidth( 1.0 );
//   glPointSize( 2.0 );

  setOrthographicProjection();
}

void KomposeGLFullscreenWidget::resizeGL( int w, int h )
{
  // setup viewport, projection etc.:
  setOrthographicProjection();
  layout->arrangeLayout();
}


/*! draw OpenGL scene ( called from Qt ) */
void KomposeGLFullscreenWidget::paintGL()
{
  qDebug("KomposeGLFullscreenWidget::paintGL()");

  glPushMatrix();
  
  // clears the color buffer (this will set the window to black)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Draw Desktop Widgets
  for (int i=0; i < KomposeTaskManager::instance()->getNumDesktops(); ++i)
  {
    // FIXME: Make desktop arrays dynamic or at least avoid KomposeTaskManager::instance()->getNumDesktops() here
    desktop[i]->draw();
  }

  glFlush();
  glPopMatrix();
}


void KomposeGLFullscreenWidget::setOrthographicProjection()
{
  qDebug("KomposeGLFullscreenWidget::setOrthographicProjection() - %dx%d", width(), height());
  glViewport( 0, 0, (GLint)width(), (GLint)height()  );
  // switch to projection mode
  glMatrixMode(GL_PROJECTION);
  // reset matrix
  glLoadIdentity();
  // set a 2D orthographic projection
  gluOrtho2D(0.0, (GLdouble)width(), 0.0, (GLdouble)height());
  // invert the y axis, down is positive
  glScalef(1, -1, 1);
  // mover the origin from the bottom left corner
  // to the upper left corner
  glTranslatef(0, -height(), 0);
  glMatrixMode(GL_MODELVIEW);;
}

// Redirect these functions to QGLWidget

void KomposeGLFullscreenWidget::setGeom ( const QRect &rect )
{
  QGLWidget::setGeometry( rect );
}

void KomposeGLFullscreenWidget::setGeom ( const QSize &size )
{
  QGLWidget::resize( size );
}

QSize KomposeGLFullscreenWidget::getSize() const
{
  return QGLWidget::size();
}

QRect KomposeGLFullscreenWidget::getRect() const
{
  return QGLWidget::rect();
}

void KomposeGLFullscreenWidget::removeChildWidget( KomposeWidgetInterface* obj )
{
  QGLWidget::removeChild((QObject *) obj);
}

#include "komposeglfullscreenwidget.moc"