mainwindow.cpp Example File
animation/sub-attaq/mainwindow.cpp
#include "mainwindow.h"
#include "graphicsscene.h"
#include <QGraphicsView>
#include <QApplication>
#include <QMenu>
#include <QMenuBar>
#include <QLayout>
#ifndef QT_NO_OPENGL
# include <QtOpenGL/QtOpenGL>
#endif
MainWindow::MainWindow() : QMainWindow(0)
{
QMenu *file = menuBar()->addMenu(tr("&File"));
QAction *newAction = file->addAction(tr("New Game"));
newAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N));
QAction *quitAction = file->addAction(tr("Quit"));
quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
if (QApplication::arguments().contains("-fullscreen")) {
scene = new GraphicsScene(0, 0, 750, 400, GraphicsScene::Small);
setWindowState(Qt::WindowFullScreen);
} else {
scene = new GraphicsScene(0, 0, 880, 630);
layout()->setSizeConstraint(QLayout::SetFixedSize);
}
view = new QGraphicsView(scene, this);
view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
scene->setupScene(newAction, quitAction);
#ifndef QT_NO_OPENGL
QGLWidget *glWidget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
if (glWidget->context()->isValid()) {
view->setViewport(glWidget);
} else {
qWarning("Unable to create an Open GL context with sample buffers, not using Open GL.");
delete glWidget;
}
#endif
setCentralWidget(view);
}