Commit 62105739 by Kai Westerkamp

added Slots

parent 3b08f256
#include "cubewidget.h" #include "cubewidget.h"
#include <QOpenGLFunctions>
CubeWidget::CubeWidget(QWidget *parent) CubeWidget::CubeWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{ {
...@@ -26,7 +24,7 @@ void CubeWidget::initializeGL () ...@@ -26,7 +24,7 @@ void CubeWidget::initializeGL ()
// enable default shading // enable default shading
glShadeModel(GL_FLAT); showFlat();
// glEnable(GL_LIGHTING); // glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); glEnable(GL_LIGHT0);
...@@ -106,6 +104,40 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd ...@@ -106,6 +104,40 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar ); 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::mousePressEvent(QMouseEvent *event ) {}
void CubeWidget::mouseMoveEvent(QMouseEvent *event ) {} void CubeWidget::mouseMoveEvent(QMouseEvent *event ) {}
void CubeWidget::wheelEvent(QWheelEvent *event ) {} void CubeWidget::wheelEvent(QWheelEvent *event ) {}
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
#include <QtGui> #include <QtGui>
#include <QtOpenGL> #include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
class CubeWidget : public QGLWidget class CubeWidget : public QGLWidget
{ {
Q_OBJECT
protected : protected :
void initializeGL ( ) ; void initializeGL ( ) ;
void paintGL ( ) ; void paintGL ( ) ;
...@@ -23,6 +25,12 @@ public: ...@@ -23,6 +25,12 @@ public:
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
QSize sizeHint() const; QSize sizeHint() const;
public slots:
void showWireframe();
void showFlat();
void showGouraut();
void showPhong();
private: private:
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
}; };
......
...@@ -12,6 +12,10 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -12,6 +12,10 @@ MainWindow::MainWindow(QWidget *parent)
toolBar = new QToolBar("Shading",this); toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this); statusBar = new QStatusBar(this);
//Main Widget
mainWidget = new CubeWidget(this);
setCentralWidget(mainWidget);
//File Menu Actions //File Menu Actions
fileMenu = new QMenu("&File"); fileMenu = new QMenu("&File");
shadingMenu= new QMenu("Shading"); shadingMenu= new QMenu("Shading");
...@@ -26,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -26,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent)
noneAction->setShortcut(QKeySequence("Ctrl+1")); noneAction->setShortcut(QKeySequence("Ctrl+1"));
noneAction->setCheckable(true); noneAction->setCheckable(true);
noneAction->setIcon(QIcon(":/img/wireframe.png")); noneAction->setIcon(QIcon(":/img/wireframe.png"));
connect(noneAction, SIGNAL(triggered()), mainWidget, SLOT(showWireframe()));
shadingGroup->addAction(noneAction); shadingGroup->addAction(noneAction);
flatAction = new QAction("Flat",shadingMenu); flatAction = new QAction("Flat",shadingMenu);
...@@ -33,18 +38,21 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -33,18 +38,21 @@ MainWindow::MainWindow(QWidget *parent)
flatAction->setCheckable(true); flatAction->setCheckable(true);
flatAction->setChecked(true); flatAction->setChecked(true);
flatAction->setIcon(QIcon(":/img/flat.png")); flatAction->setIcon(QIcon(":/img/flat.png"));
connect(flatAction, SIGNAL(triggered()), mainWidget, SLOT(showFlat()));
shadingGroup->addAction(flatAction); shadingGroup->addAction(flatAction);
gouraudAction = new QAction("Gouraud",shadingMenu); gouraudAction = new QAction("Gouraud",shadingMenu);
gouraudAction->setShortcut(QKeySequence("Ctrl+3")); gouraudAction->setShortcut(QKeySequence("Ctrl+3"));
gouraudAction->setCheckable(true); gouraudAction->setCheckable(true);
gouraudAction->setIcon(QIcon(":/img/gouraud.png")); gouraudAction->setIcon(QIcon(":/img/gouraud.png"));
connect(gouraudAction, SIGNAL(triggered()), mainWidget, SLOT(showGouraut()));
shadingGroup->addAction(gouraudAction); shadingGroup->addAction(gouraudAction);
phongAction = new QAction("Phong",shadingMenu); phongAction = new QAction("Phong",shadingMenu);
phongAction->setShortcut(QKeySequence("Ctrl+4" )); phongAction->setShortcut(QKeySequence("Ctrl+4" ));
phongAction->setCheckable(true); phongAction->setCheckable(true);
phongAction->setIcon(QIcon(":/img/phong.png")); phongAction->setIcon(QIcon(":/img/phong.png"));
connect(phongAction, SIGNAL(triggered()), mainWidget, SLOT(showPhong()));
shadingGroup->addAction(phongAction); shadingGroup->addAction(phongAction);
//Other Actions //Other Actions
...@@ -78,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -78,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
statusBar->showMessage("Hello"); statusBar->showMessage("Hello");
setStatusBar(statusBar); 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