Commit 62105739 by Kai Westerkamp

added Slots

parent 3b08f256
#include "cubewidget.h"
#include <QOpenGLFunctions>
CubeWidget::CubeWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
......@@ -26,7 +24,7 @@ void CubeWidget::initializeGL ()
// enable default shading
glShadeModel(GL_FLAT);
showFlat();
// glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
......@@ -106,6 +104,40 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
void CubeWidget::showWireframe()
{
qDebug("show Wireframe");
glShadeModel(GL_FLAT);
glPolygoneMode(GL_FRONT, GL_LINE);
}
void CubeWidget::showFlat()
{
qDebug("show Flat");
glShadeModel(GL_FLAT);
glPolygoneMode(GL_FRONT, GL_FILL);
}
void CubeWidget::showGouraut()
{
qDebug("show Gouraut");
glShadeModel(GL_SMOOTH);
glPolygoneMode(GL_FRONT, GL_FILL);
}
void CubeWidget::showPhong()
{
qDebug("show Phong");
showFlat();
}
void CubeWidget::setTessellation(int t)
{
}
void CubeWidget::mousePressEvent(QMouseEvent *event ) {}
void CubeWidget::mouseMoveEvent(QMouseEvent *event ) {}
void CubeWidget::wheelEvent(QWheelEvent *event ) {}
......@@ -3,12 +3,14 @@
#include <QtGui>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
class CubeWidget : public QGLWidget
{
Q_OBJECT
protected :
void initializeGL ( ) ;
void paintGL ( ) ;
......@@ -23,6 +25,12 @@ public:
QSize minimumSizeHint() const;
QSize sizeHint() const;
public slots:
void showWireframe();
void showFlat();
void showGouraut();
void showPhong();
private:
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
};
......
......@@ -12,6 +12,10 @@ MainWindow::MainWindow(QWidget *parent)
toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this);
//Main Widget
mainWidget = new CubeWidget(this);
setCentralWidget(mainWidget);
//File Menu Actions
fileMenu = new QMenu("&File");
shadingMenu= new QMenu("Shading");
......@@ -26,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent)
noneAction->setShortcut(QKeySequence("Ctrl+1"));
noneAction->setCheckable(true);
noneAction->setIcon(QIcon(":/img/wireframe.png"));
connect(noneAction, SIGNAL(triggered()), mainWidget, SLOT(showWireframe()));
shadingGroup->addAction(noneAction);
flatAction = new QAction("Flat",shadingMenu);
......@@ -33,18 +38,21 @@ MainWindow::MainWindow(QWidget *parent)
flatAction->setCheckable(true);
flatAction->setChecked(true);
flatAction->setIcon(QIcon(":/img/flat.png"));
connect(flatAction, SIGNAL(triggered()), mainWidget, SLOT(showFlat()));
shadingGroup->addAction(flatAction);
gouraudAction = new QAction("Gouraud",shadingMenu);
gouraudAction->setShortcut(QKeySequence("Ctrl+3"));
gouraudAction->setCheckable(true);
gouraudAction->setIcon(QIcon(":/img/gouraud.png"));
connect(gouraudAction, SIGNAL(triggered()), mainWidget, SLOT(showGouraut()));
shadingGroup->addAction(gouraudAction);
phongAction = new QAction("Phong",shadingMenu);
phongAction->setShortcut(QKeySequence("Ctrl+4" ));
phongAction->setCheckable(true);
phongAction->setIcon(QIcon(":/img/phong.png"));
connect(phongAction, SIGNAL(triggered()), mainWidget, SLOT(showPhong()));
shadingGroup->addAction(phongAction);
//Other Actions
......@@ -78,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
statusBar->showMessage("Hello");
setStatusBar(statusBar);
//Main Widget
mainWidget = new CubeWidget(this);
setCentralWidget(mainWidget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment