Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
grapa_alisa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alisa Jung
grapa_alisa
Commits
61eb172b
Commit
61eb172b
authored
Nov 15, 2015
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
view switch works
parent
194f25be
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
18 deletions
+80
-18
controller.cpp
helloqube/controller.cpp
+48
-5
controller.h
helloqube/controller.h
+12
-3
mainwindow.cpp
helloqube/mainwindow.cpp
+8
-8
myglwidget.cpp
helloqube/myglwidget.cpp
+7
-1
myglwidget.h
helloqube/myglwidget.h
+5
-1
No files found.
helloqube/controller.cpp
View file @
61eb172b
...
...
@@ -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
;
currentWidget
Index
=
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
();
}
}
...
...
helloqube/controller.h
View file @
61eb172b
...
...
@@ -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
helloqube/mainwindow.cpp
View file @
61eb172b
...
...
@@ -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
);
...
...
helloqube/myglwidget.cpp
View file @
61eb172b
...
...
@@ -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
...
...
helloqube/myglwidget.h
View file @
61eb172b
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment