Commit bcb34491 by Alisa Jung

Assignment 1 task 3 complete

parents
#-------------------------------------------------
#
# Project created by QtCreator 2015-10-31T11:34:59
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloqube
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
RESOURCES += \
helloqube.qrc
<RCC>
<qresource prefix="/">
<file>img/cam_home.png</file>
<file>img/flat.png</file>
<file>img/gouraud.png</file>
<file>img/phong.png</file>
<file>img/wireframe.png</file>
</qresource>
</RCC>
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.setWindowTitle("Hello Cube.");
return a.exec();
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
menuBar = new QMenuBar();
//3.2.1 File Menu
fileMenu = new QMenu("&File");
exitAction = new QAction("E&xit",fileMenu);
// exitAction->setShortcut(QKeySequence::Quit);//original code from assignment. Ctrl+q is not supported on windows.
exitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));//workaround for windows.
connect(exitAction , SIGNAL(triggered ( ) ) , this , SLOT(close ( ) ) ) ;
fileMenu->addAction(exitAction );
menuBar->addMenu(fileMenu );
//3.2.2 Shading Menu
shadingMenu = new QMenu("Shading");
shadeNoneAction = new QAction("None",shadingMenu);
shadeFlatAction = new QAction("Flat",shadingMenu);
shadeGouraudAction = new QAction("Gouraud",shadingMenu);
shadePhongAction = new QAction("Phong",shadingMenu);
shadeNoneAction->setShortcut(QKeySequence(tr("Ctrl+1")));
shadeFlatAction->setShortcut(QKeySequence(tr("Ctrl+2")));
shadeGouraudAction->setShortcut(QKeySequence(tr("Ctrl+3")));
shadePhongAction->setShortcut(QKeySequence(tr("Ctrl+4")));
shadeNoneAction->setCheckable(true);
shadeFlatAction->setCheckable(true);
shadeGouraudAction->setCheckable(true);
shadePhongAction->setCheckable(true);
shadeNoneAction->setIcon(QIcon(":/img/wireframe.png"));
shadeFlatAction->setIcon(QIcon(":/img/flat.png"));
shadeGouraudAction->setIcon(QIcon(":/img/gouraud.png"));
shadePhongAction->setIcon(QIcon(":/img/phong.png"));
shaderGroup = new QActionGroup(shadingMenu);
shaderGroup->addAction(shadeNoneAction);
shaderGroup->addAction(shadeFlatAction);
shaderGroup->addAction(shadeGouraudAction);
shaderGroup->addAction(shadePhongAction);
shadingMenu->addAction(shadeNoneAction);
shadingMenu->addAction(shadeFlatAction);
shadingMenu->addAction(shadeGouraudAction);
shadingMenu->addAction(shadePhongAction);
shadeFlatAction->setChecked(true);
menuBar->addMenu(shadingMenu);
//3.2.3 About Message Box
aboutAction = new QAction("About",menuBar);
connect(aboutAction, SIGNAL(triggered()), this,SLOT(showAboutBox()));
menuBar->addAction(aboutAction);
//3.3 Toolbar
toolBar = new QToolBar("ToolBar",this);
toolBar->addAction(shadeNoneAction);
toolBar->addAction(shadeFlatAction);
toolBar->addAction(shadeGouraudAction);
toolBar->addAction(shadePhongAction);
addToolBar( toolBar);
//3.4 Status Bar
statusBar = new QStatusBar(this);
statusBar->showMessage("test status message");
setStatusBar(statusBar);
setMenuBar(menuBar);
}
MainWindow::~MainWindow()
{
}
void MainWindow::showAboutBox(){
QMessageBox msgBox;
msgBox.setWindowTitle("About Hello Cube!");
msgBox.setText("Written by Alisa");
msgBox.exec();
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QKeySequence>
#include <QMessageBox>
#include <QToolBar>
#include <QStatusBar>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QMenuBar *menuBar;
//Menus
QMenu *fileMenu;
QMenu *shadingMenu;
QMenu *aboutMenu;
//Tool Bar
QToolBar *toolBar;
//Status Bar
QStatusBar *statusBar;
//Actions
QAction *exitAction;
QAction *aboutAction;
QAction *shadeNoneAction;
QAction *shadeFlatAction;
QAction *shadeGouraudAction;
QAction *shadePhongAction;
QActionGroup *shaderGroup;
public slots :
void showAboutBox ( ) ;
};
#endif // MAINWINDOW_H
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