Commit 61eb172b by Alisa Jung

view switch works

parent 194f25be
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
Controller::Controller() Controller::Controller()
{ {
modeCamera = true; modeCamera = true;
currentWidgetIndex = 0;
} }
Controller::~Controller(){ Controller::~Controller(){
...@@ -15,8 +16,50 @@ void Controller::initActions(QAction *cam, QAction *manipulate){ ...@@ -15,8 +16,50 @@ void Controller::initActions(QAction *cam, QAction *manipulate){
modeManipulateAction = manipulate; modeManipulateAction = manipulate;
} }
void Controller::initWidget(MyGLWidget *w){ void Controller::initViewWidgets(MyGLWidget *allViews[4], QWidget *two, QWidget *four, QGridLayout* layout){
currentWidget = w; for (int i = 0; i < 4; i++){
views[i] = allViews[i];//Are you kidding me c++?
}
currentWidgetIndex = 0;
doubleViewWidget = two;
quadViewWidget = four;
viewLayout = layout;
}
void Controller::showSingleView(){
viewLayout = new QGridLayout();
viewLayout->removeWidget(quadViewWidget);
viewLayout->removeWidget(doubleViewWidget);
viewLayout->addWidget(views[0],0,0);
for (int i = 1; i < 4; i++){
views[i]->hide();
}
views[0]->show();
currentWidgetIndex = 0;
}
void Controller::showDoubleView(){
viewLayout = new QGridLayout();
viewLayout->removeWidget(quadViewWidget);
viewLayout->removeWidget(views[0]);
viewLayout->addWidget(doubleViewWidget);
for (int i = 2; i < 4; i++){
views[i]->hide();
}
for (int i = 0; i < 2; i++){
views[i]->show();
}
if (currentWidgetIndex > 1) currentWidgetIndex = 0;
}
void Controller::showQuadView(){
viewLayout = new QGridLayout();
viewLayout->removeWidget(doubleViewWidget);
viewLayout->removeWidget(views[0]);
viewLayout->addWidget(quadViewWidget);
for (int i = 0; i < 4; i++){
views[i]->show();
}
} }
...@@ -55,7 +98,7 @@ void Controller::processMousePressEvent(QMouseEvent *event, MyGLWidget *widget){ ...@@ -55,7 +98,7 @@ void Controller::processMousePressEvent(QMouseEvent *event, MyGLWidget *widget){
leftButtonPressed = true; leftButtonPressed = true;
lastClickPosition = event->pos(); lastClickPosition = event->pos();
} }
currentWidget = widget; currentWidgetIndex = widget->getIndex();
} }
void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){ void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){
...@@ -82,8 +125,8 @@ void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){ ...@@ -82,8 +125,8 @@ void Controller::processMouseMoveEvent(QMouseEvent *event, MyGLWidget *widget){
} }
void Controller::resetCamera(){ void Controller::resetCamera(){
if (currentWidget){ if (views[currentWidgetIndex]){
currentWidget->resetCamera(); views[currentWidgetIndex]->resetCamera();
} }
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <QDebug> #include <QDebug>
#include <QObject> #include <QObject>
#include <QAction> #include <QAction>
#include <QGridLayout>
class MyGLWidget; class MyGLWidget;
...@@ -25,8 +26,7 @@ public: ...@@ -25,8 +26,7 @@ public:
~Controller(); ~Controller();
void initActions(QAction* cam, QAction* manipulate); void initActions(QAction* cam, QAction* manipulate);
void initWidget(MyGLWidget* w); void initViewWidgets(MyGLWidget* views[4], QWidget* doubleViews, QWidget* quadViews, QGridLayout* layout);
//processes input and might call follow up functions in widget //processes input and might call follow up functions in widget
void processMousePressEvent(QMouseEvent* event, MyGLWidget* widget); void processMousePressEvent(QMouseEvent* event, MyGLWidget* widget);
...@@ -41,7 +41,12 @@ private: ...@@ -41,7 +41,12 @@ private:
QAction *modeCameraAction; QAction *modeCameraAction;
QAction *modeManipulateAction; QAction *modeManipulateAction;
MyGLWidget* currentWidget; int currentWidgetIndex;
QWidget* quadViewWidget;
QWidget* doubleViewWidget;
MyGLWidget* views[4];
QGridLayout* viewLayout;
bool modeCamera; bool modeCamera;
...@@ -60,6 +65,10 @@ public slots: ...@@ -60,6 +65,10 @@ public slots:
void switchToModeManipulate(); void switchToModeManipulate();
void resetCamera(); void resetCamera();
void showSingleView();
void showDoubleView();
void showQuadView();
}; };
#endif // CONTROLLER_H #endif // CONTROLLER_H
...@@ -78,13 +78,12 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -78,13 +78,12 @@ MainWindow::MainWindow(QWidget *parent)
//4.0 Widget //Assignment 2: Multiple Widgets. //4.0 Widget //Assignment 2: Multiple Widgets.
qDebug("widgets..."); qDebug("widgets...");
controller = new Controller(); controller = new Controller();
myGLWidget = new MyGLWidget(controller, true, QQuaternion(),this); myGLWidget = new MyGLWidget(0,controller, true, QQuaternion(),this);
setCentralWidget(myGLWidget); setCentralWidget(myGLWidget);
controller->initWidget(myGLWidget);
viewFront = new MyGLWidget(controller, false, QQuaternion(),this); viewFront = new MyGLWidget(1,controller, false, QQuaternion(),this);
viewLeft = new MyGLWidget(controller, false, QQuaternion::fromAxisAndAngle(0,1,0,90),this);//TODO check rotations. viewLeft = new MyGLWidget(2,controller, false, QQuaternion::fromAxisAndAngle(0,1,0,90),this);//TODO check rotations.
viewTop = new MyGLWidget(controller, false, QQuaternion::fromAxisAndAngle(1,0,0,90),this); viewTop = new MyGLWidget(3,controller, false, QQuaternion::fromAxisAndAngle(1,0,0,90),this);
viewSplitter1 = new QSplitter; viewSplitter1 = new QSplitter;
viewSplitter1->addWidget(myGLWidget); viewSplitter1->addWidget(myGLWidget);
...@@ -127,6 +126,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -127,6 +126,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(shadePhongAction,SIGNAL(triggered(bool)),allWidgets[i],SLOT(shadePhongSlot())); connect(shadePhongAction,SIGNAL(triggered(bool)),allWidgets[i],SLOT(shadePhongSlot()));
connect(tesselationSlider,SIGNAL(valueChanged(int)),allWidgets[i],SLOT(setTessellation(int))); connect(tesselationSlider,SIGNAL(valueChanged(int)),allWidgets[i],SLOT(setTessellation(int)));
} }
controller->initViewWidgets(allWidgets,viewSplitter1,viewSplitter3,viewLayout);
//reset Camera button //reset Camera button
...@@ -179,7 +179,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -179,7 +179,7 @@ MainWindow::MainWindow(QWidget *parent)
singleViewAction->setCheckable(true); singleViewAction->setCheckable(true);
singleViewAction->setChecked(true); singleViewAction->setChecked(true);
singleViewAction->setShortcut(QKeySequence(Qt::Key_1)); singleViewAction->setShortcut(QKeySequence(Qt::Key_1));
//TODO connect slot connect(singleViewAction,SIGNAL(triggered(bool)),controller, SLOT(showSingleView()));
viewMenu->addAction(singleViewAction); viewMenu->addAction(singleViewAction);
viewMenu->setDefaultAction(singleViewAction); viewMenu->setDefaultAction(singleViewAction);
viewGroup->addAction(singleViewAction); viewGroup->addAction(singleViewAction);
...@@ -188,7 +188,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -188,7 +188,7 @@ MainWindow::MainWindow(QWidget *parent)
dualViewAction->setIcon(QIcon(":/grapa-a2-iconset/view-dual.png")); dualViewAction->setIcon(QIcon(":/grapa-a2-iconset/view-dual.png"));
dualViewAction->setCheckable(true); dualViewAction->setCheckable(true);
dualViewAction->setShortcut(QKeySequence(Qt::Key_2)); dualViewAction->setShortcut(QKeySequence(Qt::Key_2));
//TODO connect slot connect(dualViewAction,SIGNAL(triggered(bool)),controller, SLOT(showDoubleView()));
viewMenu->addAction(dualViewAction); viewMenu->addAction(dualViewAction);
viewGroup->addAction(dualViewAction); viewGroup->addAction(dualViewAction);
...@@ -196,7 +196,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -196,7 +196,7 @@ MainWindow::MainWindow(QWidget *parent)
quadViewAction->setIcon(QIcon(":/grapa-a2-iconset/viewports.png")); quadViewAction->setIcon(QIcon(":/grapa-a2-iconset/viewports.png"));
quadViewAction->setCheckable(true); quadViewAction->setCheckable(true);
quadViewAction->setShortcut(QKeySequence(Qt::Key_4)); quadViewAction->setShortcut(QKeySequence(Qt::Key_4));
//TODO connect slot connect(quadViewAction,SIGNAL(triggered(bool)),controller, SLOT(showQuadView()));
viewMenu->addAction(quadViewAction); viewMenu->addAction(quadViewAction);
viewGroup->addAction(quadViewAction); viewGroup->addAction(quadViewAction);
......
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
//QGLShaderProgram *MyGLWidget::phongShader; //QGLShaderProgram *MyGLWidget::phongShader;
MyGLWidget::MyGLWidget(Controller* c, bool isPerspective, QQuaternion initialRotation, QWidget *parent) MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion initialRotation, QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{ {
this->index = index;
MyGLWidget::modeCamera = true; MyGLWidget::modeCamera = true;
tesselation = 1; tesselation = 1;
qubeRotation = QQuaternion(); qubeRotation = QQuaternion();
...@@ -31,6 +32,11 @@ MyGLWidget::~MyGLWidget() ...@@ -31,6 +32,11 @@ MyGLWidget::~MyGLWidget()
//In helloGL example: nothing needs cleaning up. //In helloGL example: nothing needs cleaning up.
} }
//0 = perspective, 1 = front, 2 = left, 3 = top. Hardcoded on construction.
int MyGLWidget::getIndex(){
return index;
}
/* /*
* From Example * From Example
* We provide size hint functions to ensure that * We provide size hint functions to ensure that
......
...@@ -21,7 +21,7 @@ class MyGLWidget : public QGLWidget ...@@ -21,7 +21,7 @@ class MyGLWidget : public QGLWidget
public: public:
//Pass initial camera rotation and isPerspective = false for fixed views //Pass initial camera rotation and isPerspective = false for fixed views
MyGLWidget(Controller* c, bool isPerspective, QQuaternion initalRotation, QWidget *parent = 0); MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion initalRotation, QWidget *parent = 0);
~MyGLWidget(); ~MyGLWidget();
//From HelloGL example. //From HelloGL example.
...@@ -38,6 +38,8 @@ class MyGLWidget : public QGLWidget ...@@ -38,6 +38,8 @@ class MyGLWidget : public QGLWidget
void initShaderStuff(); void initShaderStuff();
int getIndex();
protected: protected:
//4.1 Core Functionality //4.1 Core Functionality
void initializeGL(); void initializeGL();
...@@ -52,6 +54,8 @@ protected: ...@@ -52,6 +54,8 @@ protected:
Controller* controller; Controller* controller;
private: private:
int index;//hardcoding ftw. for easier access in controller. 0 = perspective, 1 = front, 2 = left, 3 = top
//tesselation slider //tesselation slider
int tesselation; int tesselation;
bool isPerspective; bool isPerspective;
......
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