Commit 61eb172b by Alisa Jung

view switch works

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