00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "mainwindow.h"
00021 #include "actionsdialog.h"
00022
00023 #include <core/debughelper.h>
00024 #include <engine/game.h>
00025 #include <engine/gameproject.h>
00026 #include <engine/scene.h>
00027 #include <graphics/renderwidget.h>
00028 #include <player/models/gamesmodel.h>
00029
00030 #include <QtGui/QFileDialog>
00031 #include <QtGui/QStatusBar>
00032 #include <QtGui/QApplication>
00033 #include <QtGui/QListView>
00034 #include <QtGui/QVBoxLayout>
00035 #include <QtGui/QPushButton>
00036 #include <QLabel>
00037 #include <QTimer>
00038
00039 using namespace GluonPlayer;
00040
00041 class MainWindow::MainWindowPrivate
00042 {
00043 public:
00044 GluonEngine::GameProject* project;
00045 GluonGraphics::RenderWidget* widget;
00046
00047 QAbstractItemModel* model;
00048
00049 QString title;
00050 QString fileName;
00051
00052 int msecElapsed;
00053 int frameCount;
00054 };
00055
00056 GluonPlayer::MainWindow::MainWindow( int argc, char** argv, QWidget* parent, Qt::WindowFlags flags )
00057 : QMainWindow( parent, flags )
00058 , d( new MainWindowPrivate )
00059 , settings( new QSettings )
00060 {
00061 d->msecElapsed = 0;
00062 d->frameCount = 0;
00063
00064 if( argc > 1 )
00065 {
00066 d->fileName = argv[1];
00067 QTimer::singleShot( 0, this, SLOT( openProject() ) );
00068 }
00069 else
00070 {
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 }
00093
00094 setupUi();
00095
00096 createActions();
00097 createMenus();
00098 createToolBars();
00099 createStatusBar();
00100
00101 loadActions();
00102
00103 resize( 500, 500 );
00104 }
00105
00106 void MainWindow::changeEvent(QEvent *event)
00107 {
00108 QMainWindow::changeEvent(event);
00109 switch (event->type()) {
00110 case QEvent::LanguageChange:
00111 retranslateUi();
00112 break;
00113 default:
00114 break;
00115 }
00116 }
00117
00118 void MainWindow::setupUi()
00119 {
00120 if (objectName().isEmpty())
00121 setObjectName(QString::fromUtf8("MainWindow"));
00122
00123 centralWidget = new QWidget(this);
00124 centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
00125
00126
00127 menuBar = new QMenuBar(this);
00128 menuBar->setObjectName(QString::fromUtf8("menuBar"));
00129 menuBar->setGeometry(QRect(0, 0, 1290, 20));
00130 setMenuBar(menuBar);
00131 mainToolBar = new QToolBar(this);
00132 mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
00133 addToolBar(Qt::TopToolBarArea, mainToolBar);
00134 statusBar = new QStatusBar(this);
00135 statusBar->setObjectName(QString::fromUtf8("statusBar"));
00136 setStatusBar(statusBar);
00137
00138 setWindowTitle("QPatternDB");
00139 setWindowIcon(QIcon(":/images/icon.bmp"));
00140 setWindowIconText("QPatternDB application logo");
00141
00142 loginForm = new LoginForm;
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 setCentralWidget(loginForm);
00155
00156
00157
00158 return;
00159 }
00160
00161 void MainWindow::retranslateUi()
00162 {
00163 setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0,
00164 QApplication::UnicodeUTF8));
00165 return;
00166 }
00167
00168 void MainWindow::activated( QModelIndex index )
00169 {
00170 if( index.isValid() )
00171 {
00172 openProject( d->model->data( index ).toString() );
00173 }
00174 }
00175
00176 void MainWindow::openClicked( bool toggled )
00177 {
00178 Q_UNUSED( toggled )
00179
00180 QString fileName = QFileDialog::getOpenFileName( this, tr( "Select a Project" ), QString(), QString( "*.gluon|Gluon Project Files" ) );
00181 if( !fileName.isEmpty() )
00182 openProject( fileName );
00183 }
00184
00185 void MainWindow::openProject( const QString& fileName )
00186 {
00187 QString file = fileName;
00188 if( file.isEmpty() )
00189 file = d->fileName;
00190
00191 d->widget = new GluonGraphics::RenderWidget( this );
00192 setCentralWidget( d->widget );
00193 connect( GluonEngine::Game::instance(), SIGNAL( painted( int ) ), d->widget, SLOT( updateGL() ) );
00194 connect( GluonEngine::Game::instance(), SIGNAL( painted( int ) ), SLOT( countFrames( int ) ) );
00195 connect( GluonEngine::Game::instance(), SIGNAL( updated( int ) ), SLOT( updateTitle( int ) ) );
00196
00197 QTimer::singleShot( 100, this, SLOT( startGame() ) );
00198
00199 d->fileName = file;
00200 }
00201
00202 void MainWindow::startGame()
00203 {
00204 GluonCore::GluonObjectFactory::instance()->loadPlugins();
00205
00206 d->project = new GluonEngine::GameProject();
00207 d->project->loadFromFile( QUrl( d->fileName ) );
00208
00209 setWindowFilePath( d->fileName );
00210 d->title = windowTitle();
00211
00212 GluonEngine::Game::instance()->setGameProject( d->project );
00213 GluonEngine::Game::instance()->setCurrentScene( d->project->entryPoint() );
00214
00215 GluonEngine::Game::instance()->runGame();
00216 }
00217
00218 void MainWindow::closeEvent( QCloseEvent* event )
00219 {
00220 GluonEngine::Game::instance()->stopGame();
00221 QWidget::closeEvent( event );
00222 }
00223
00224 void MainWindow::updateTitle( int msec )
00225 {
00226 d->msecElapsed += msec;
00227
00228 static int fps = 0;
00229 if( d->msecElapsed > 1000 )
00230 {
00231 fps = d->frameCount;
00232 d->frameCount = 0;
00233 d->msecElapsed = 0;
00234 }
00235
00236 setWindowTitle( d->title + QString( " (%1 FPS)" ).arg( fps ) );
00237 }
00238
00239 void MainWindow::countFrames( int time )
00240 {
00241 Q_UNUSED( time )
00242 d->frameCount++;
00243 }
00244
00245 void MainWindow::createActions()
00246 {
00247
00248 openGameAct = new QAction(QIcon(":/images/open.png"), tr("&Open a game..."), this);
00249 openGameAct->setShortcuts(QKeySequence::Open);
00250 openGameAct->setStatusTip(tr("Open a game"));
00251 openGameAct->setEnabled(false);
00252 connect(openGameAct, SIGNAL(triggered()), SLOT(mOpenGame()));
00253
00254 quitAct = new QAction(QIcon(":/images/quit.png"), tr("&Quit"), this);
00255 quitAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
00256 quitAct->setStatusTip(tr("Exit the application"));
00257 connect(quitAct, SIGNAL(triggered()), SLOT(close()));
00258
00259
00260
00261 showToolBarAct = new QAction(tr("Show &ToolBar"), this);
00262 showToolBarAct->setStatusTip(tr("Toggle the view state of the ToolBar"));
00263 showToolBarAct->setCheckable(true);
00264 showToolBarAct->setChecked(true);
00265 connect(showToolBarAct, SIGNAL(triggered(bool)), SLOT(mShowToolBar(bool)));
00266
00267 showStatusBarAct = new QAction(tr("Show St&atusBar"), this);
00268 showStatusBarAct->setStatusTip(tr("Toggle the view state of the StatusBar"));
00269 showStatusBarAct->setCheckable(true);
00270 showStatusBarAct->setChecked(true);
00271 connect(showStatusBarAct, SIGNAL(triggered(bool)), SLOT(mShowStatusBar(bool)));
00272
00273
00274
00275 loginLogoutAct = new QAction(tr("Login/Logout"), this);
00276 loginLogoutAct->setStatusTip(tr("Login/Logout"));
00277 loginLogoutAct->setCheckable(true);
00278 loginLogoutAct->setChecked(true);
00279 connect(loginLogoutAct, SIGNAL(triggered(bool)), SLOT(mLoginLogout(bool)));
00280
00281 homeAct = new QAction(tr("Home view"), this);
00282 homeAct->setStatusTip(tr("Go to the Home view"));
00283 connect(homeAct, SIGNAL(triggered()), SLOT(mHome()));
00284
00285 detailsAct = new QAction(tr("Details view"), this);
00286 detailsAct->setStatusTip(tr("Go to the Detail view"));
00287 connect(detailsAct, SIGNAL(triggered()), SLOT(mDetails()));
00288
00289 registrationAct = new QAction(tr("Registration view"), this);
00290 registrationAct->setStatusTip(tr("Go to the Registration view"));
00291 connect(registrationAct, SIGNAL(triggered()), SLOT(mRegistration()));
00292
00293 forgottenPasswordAct = new QAction(tr("Forgotten Password Action"), this);
00294 forgottenPasswordAct->setStatusTip(tr("Go to the Forgotten Password Page"));
00295 connect(forgottenPasswordAct, SIGNAL(triggered()), SLOT(mForgottenPassword()));
00296
00297
00298
00299 configureToolBarAct = new QAction(tr("Configure Tool&bar..."), this);
00300 configureToolBarAct->setStatusTip(tr("Configure the toolbar of the application"));
00301 connect(configureToolBarAct, SIGNAL(triggered()), SLOT(mConfigureToolBar()));
00302
00303 configureShortcutsAct = new QAction(tr("Configure S&hortcuts..."), this);
00304 configureShortcutsAct->setStatusTip(tr("Configure the shortcuts of the actions"));
00305 connect(configureShortcutsAct, SIGNAL(triggered()), SLOT(mConfigureShortcuts()));
00306
00307
00308
00309 aboutAct = new QAction(tr("&About"), this);
00310 aboutAct->setStatusTip(tr("Show the extended Qt Player About box"));
00311 connect(aboutAct, SIGNAL(triggered()), SLOT(mAbout()));
00312
00313 aboutQtAct = new QAction(tr("About &Qt"), this);
00314 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
00315 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00316 }
00317
00318 void MainWindow::createMenus()
00319 {
00320
00321 fileMenu = menuBar->addMenu(tr("&File"));
00322 fileMenu->addAction(openGameAct);
00323 fileMenu->addSeparator();
00324 fileMenu->addAction(quitAct);
00325
00326
00327 viewMenu = menuBar->addMenu(tr("&View"));
00328 viewMenu->addAction(showToolBarAct);
00329 viewMenu->addAction(showStatusBarAct);
00330
00331
00332 communityMenu = menuBar->addMenu(tr("&Community"));
00333 communityMenu->addAction(loginLogoutAct);
00334 communityMenu->addAction(homeAct);
00335 communityMenu->addAction(detailsAct);
00336 communityMenu->addAction(registrationAct);
00337 communityMenu->addAction(forgottenPasswordAct);
00338
00339
00340 settingsMenu = menuBar->addMenu(tr("&Settings"));
00341 settingsMenu->addAction(configureShortcutsAct);
00342 settingsMenu->addAction(configureToolBarAct);
00343
00344
00345 helpMenu = menuBar->addMenu(tr("&Help"));
00346 helpMenu->addAction(aboutAct);
00347 helpMenu->addAction(aboutQtAct);
00348 }
00349
00350 void MainWindow::createToolBars()
00351 {
00352
00353 mainToolBar->addAction(openGameAct);
00354
00355
00356 mainToolBar->addAction(loginLogoutAct);
00357 mainToolBar->addAction(homeAct);
00358 mainToolBar->addAction(detailsAct);
00359 mainToolBar->addAction(registrationAct);
00360 mainToolBar->addAction(forgottenPasswordAct);
00361
00362 }
00363
00364 void MainWindow::createStatusBar()
00365 {
00366 statusBar->showMessage(tr("Ready"));
00367 }
00368
00369 void MainWindow::mOpenGame()
00370 {
00371 }
00372
00373 void MainWindow::mShowToolBar(bool checked)
00374 {
00375 mainToolBar->setVisible(checked);
00376 }
00377
00378 void MainWindow::mShowStatusBar(bool checked)
00379 {
00380 statusBar->setVisible(checked);
00381 }
00382
00383 void MainWindow::mLoginLogout(bool checked)
00384 {
00385 }
00386
00387 void MainWindow::mHome()
00388 {
00389 }
00390
00391 void MainWindow::mDetails()
00392 {
00393 }
00394
00395 void MainWindow::mRegistration()
00396 {
00397 }
00398
00399 void MainWindow::mForgottenPassword()
00400 {
00401 }
00402
00403 void MainWindow::mConfigureToolBar()
00404 {
00405 }
00406
00407 void MainWindow::mConfigureShortcuts()
00408 {
00409 ActionsDialog actionsDialog(m_actions, this);
00410 actionsDialog.exec();
00411 }
00412
00413 void MainWindow::mAbout()
00414 {
00415 QMessageBox::about(this, tr("<b>Gluon Extended Qt Player</b>"), \
00416 tr("This is an extended Qt Player application for Gluon games."));
00417 }
00418
00419 void MainWindow::loadActions()
00420 {
00421
00422 qint32 cntr = 0;
00423 QList<QAction *> actions;
00424 actions = findChildren<QAction *>();
00425 foreach (QAction *action, actions) {
00426 if (!action->isSeparator() && !action->text().isEmpty()) {
00427 m_actions.append(action);
00428 } else {
00429 ++cntr;
00430 }
00431 }
00432
00433 cntr = 0;
00434
00435 settings->beginGroup("Action");
00436 foreach (QAction *action, m_actions) {
00437 QString accelText = settings->value(action->text()).toString();
00438 if (!accelText.isEmpty())
00439 m_actions[cntr]->setShortcut(QKeySequence(accelText));
00440 ++cntr;
00441 }
00442 settings->endGroup();
00443 }
00444
00445
00446 #include "mainwindow.moc"