[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gluon] player/qt: Refactor the Qt player for preparing as a
From:       Laszlo Papp <ext-laszlo.papp () nokia ! com>
Date:       2011-11-01 3:15:08
Message-ID: 20111101031508.A4418A60C4 () git ! kde ! org
[Download RAW message or body]

Git commit e357f2927460f18cef52f7e6e5c8c938c8d9820e by Laszlo Papp.
Committed on 31/10/2011 at 21:29.
Pushed by lpapp into branch 'master'.

Refactor the Qt player for preparing as a command line tool only in the future

There are no icons and desktop files installed anymore for this command line
util, and the primary purpose is mostly for debugging from now on.. It does not
use the player library either for now, thus it is as minimalistic as possible.

M  +3    -16   player/qt/CMakeLists.txt
M  +85   -14   player/qt/main.cpp
D  +0    -200  player/qt/mainwindow.cpp
D  +0    -54   player/qt/mainwindow.h

http://commits.kde.org/gluon/e357f2927460f18cef52f7e6e5c8c938c8d9820e

diff --git a/player/qt/CMakeLists.txt b/player/qt/CMakeLists.txt
index efd26cc..f5cb767 100644
--- a/player/qt/CMakeLists.txt
+++ b/player/qt/CMakeLists.txt
@@ -2,14 +2,13 @@ cmake_minimum_required(VERSION 2.8)
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} \
${GLUON_INPUT_INCLUDES} ${GLUON_GRAPHICS_INCLUDES})  
+qt4_generate_moc(main.cpp ${CMAKE_CURRENT_BINARY_DIR}/main.moc)
+
 set(qtplayer_SRCS
     main.cpp
-    mainwindow.cpp
+    ${CMAKE_CURRENT_BINARY_DIR}/main.moc
 )
 
-
-qt4_automoc(${qtplayer_SRCS})
-
 if(APPLE)
     add_executable(gluon_qtplayer MACOSX_BUNDLE ${qtplayer_SRCS})
 
@@ -52,16 +51,4 @@ if(NOT APPLE)
         DESTINATION ${BIN_INSTALL_DIR}
         COMPONENT gluonqtplayer
     )
-
-    install(FILES
-        gluon_qtplayer.desktop
-
-        DESTINATION ${SHARE_INSTALL_DIR}/applications
-        COMPONENT gluonqtplayer
-    )
-
-    if(NOT PLAYER_ICONS_INSTALLED)
-        add_subdirectory(../icons icons)
-        set(PLAYER_ICONS_INSTALLED TRUE)
-    endif()
 endif()
diff --git a/player/qt/main.cpp b/player/qt/main.cpp
index f62c83a..672d03b 100644
--- a/player/qt/main.cpp
+++ b/player/qt/main.cpp
@@ -1,7 +1,6 @@
 /******************************************************************************
  * This file is part of the Gluon Development Platform
- * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl>
- * Copyright (c) 2010 Laszlo Papp <lpapp@kde.org>
+ * Copyright (c) 2011 Laszlo Papp <lpapp@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,27 +17,99 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "mainwindow.h"
+#include <engine/game.h>
+#include <engine/gameproject.h>
+#include <graphics/renderwidget.h>
+
+#include <input/inputmanager.h>
 
 #include <QtGui/QApplication>
 
-#include <QtCore/QFile>
+#include <QtCore/QFileInfo>
 #include <QtCore/QDebug>
+#include <QtCore/QString>
+#include <QtCore/QTimer>
+
+class Player : public QObject
+{
+    Q_OBJECT
+
+    public:
+        explicit Player(const QString &fileName, QObject *parent = 0) : \
QObject(parent), m_fileName(fileName) {} +        ~Player() { delete m_renderWidget; \
} +
+    public slots:
+        void openProject() {
+            m_renderWidget = new GluonGraphics::RenderWidget( );
+            m_renderWidget->installEventFilter(this);
+            m_renderWidget->setFocus();
+
+            connect( GluonEngine::Game::instance(), SIGNAL( painted( int ) ), \
m_renderWidget, SLOT( updateGL() ) ); +
+            GluonInput::InputManager::instance()->setFilteredObject( m_renderWidget \
); +            QTimer::singleShot(100, this, SLOT(startGame()));
+        }
+
+        void startGame() {
+            GluonCore::GluonObjectFactory::instance()->loadPlugins();
+
+            m_gameProject = new GluonEngine::GameProject();
+            m_gameProject->loadFromFile( m_fileName );
+
+            GluonEngine::Game::instance()->setGameProject( m_gameProject );
+            GluonEngine::Game::instance()->setCurrentScene( \
m_gameProject->entryPoint() ); +
+            m_renderWidget->show();
+            GluonEngine::Game::instance()->runGame();
+            QApplication::instance()->exit();
+        }
+
+        bool eventFilter(QObject *obj, QEvent *event) {
+            if (obj == m_renderWidget) {
+                if (event->type() == QEvent::Close) {
+                    GluonEngine::Game::instance()->stopGame();
+                    QApplication::instance()->quit();
+                    return true;
+                }
+            } else {
+                QObject::eventFilter(obj, event);
+            }
+            return false;
+        }
+
+    private:
+        QString m_fileName;
+        GluonEngine::GameProject* m_gameProject;
+        GluonGraphics::RenderWidget* m_renderWidget;
+};
+
+#include "main.moc"
 
 int main( int argc, char** argv )
 {
-    if( argc > 1 && !QFile::exists( argv[1] ) )
+    if( argc > 1 )
     {
-        qDebug() << "File does not exist:" << argv[1];
-        return 1;
-    }
+        if (!QFile::exists( argv[1] )) {
+            qDebug() << "File does not exist:" << argv[1];
+            return 1;
+        }
 
-    QApplication app( argc, argv );
-    app.setOrganizationName( "KDE Gluon" );
-    app.setApplicationName( "Gluon Player" );
+        QApplication app( argc, argv );
 
-    GluonPlayer::MainWindow window( argc, argv );
-    window.show();
+        QFileInfo fi = QFileInfo( argv[1] );
+        QString fileName;
+        if( fi.isRelative() )
+            fileName = fi.canonicalFilePath();
+        else
+            fileName = argv[1];
+        
+        Player player(fileName);
+        QTimer::singleShot(0, &player, SLOT(openProject()));
 
-    return app.exec();
+        return app.exec();
+    }
+    else
+    {
+        qDebug() << "Usage:" << argv[0] << "<gameproject>";
+    }
 }
diff --git a/player/qt/mainwindow.cpp b/player/qt/mainwindow.cpp
deleted file mode 100644
index 76e9cf0..0000000
--- a/player/qt/mainwindow.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-/******************************************************************************
- * This file is part of the Gluon Development Platform
- * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl>
- * Copyright (c) 2010 Laszlo Papp <lpapp@kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "mainwindow.h"
-
-#include <input/inputmanager.h>
-
-#include <engine/game.h>
-#include <engine/gameproject.h>
-#include <engine/scene.h>
-#include <graphics/renderwidget.h>
-#include <core/directoryprovider.h>
-
-#include <QtGui/QFileDialog>
-#include <QtGui/QStatusBar>
-#include <QtGui/QApplication>
-#include <QtGui/QVBoxLayout>
-#include <QtGui/QPushButton>
-#include <QtGui/QLabel>
-#include <QtGui/QListWidget>
-#include <QtCore/QTimer>
-
-using namespace GluonPlayer;
-
-class MainWindow::MainWindowPrivate
-{
-    public:
-        GluonEngine::GameProject* project;
-        GluonGraphics::RenderWidget* widget;
-        QListWidget* listWidget;
-
-        QString title;
-        QString fileName;
-
-        int msecElapsed;
-        int frameCount;
-};
-
-GluonPlayer::MainWindow::MainWindow( int argc, char** argv, QWidget* parent, \
                Qt::WindowFlags flags )
-    : QMainWindow( parent, flags )
-    , d( new MainWindowPrivate )
-{
-    d->msecElapsed = 0;
-    d->frameCount = 0;
-
-    if( argc > 1 )
-    {
-        QFileInfo fi = QFileInfo( argv[1] );
-        if( fi.isRelative() )
-            d->fileName = fi.canonicalFilePath();
-        else
-            d->fileName = argv[1];
-        QTimer::singleShot( 0, this, SLOT( openProject() ) );
-    }
-    else
-    {
-        QWidget* base = new QWidget( this );
-        QVBoxLayout* layout = new QVBoxLayout();
-        base->setLayout( layout );
-        setCentralWidget( base );
-
-        QLabel* header = new QLabel( tr( "Please select a Project" ), base );
-        header->setAlignment( Qt::AlignCenter );
-        QFont font;
-        font.setBold( true );
-        header->setFont( font );
-        layout->addWidget( header );
-
-        d->listWidget = new QListWidget( base );
-        layout->addWidget( d->listWidget );
-        connect( d->listWidget, SIGNAL( activated( QModelIndex ) ), SLOT( activated( \
                QModelIndex ) ) );
-
-        QPushButton* button = new QPushButton( tr( "Open other project..." ), base \
                );
-        layout->addWidget( button );
-        connect( button, SIGNAL( clicked( bool ) ), SLOT( openClicked( bool ) ) );
-        loadGamesList();
-    }
-    resize( 500, 500 );
-}
-
-MainWindow::~MainWindow()
-{
-    delete d;
-}
-
-void MainWindow::activated( QModelIndex index )
-{
-    if( index.isValid() )
-    {
-        openProject( d->listWidget->currentItem()->text() );
-    }
-}
-
-void MainWindow::openClicked( bool /* toggled */ )
-{
-    QString fileName = QFileDialog::getOpenFileName( this, tr( "Select a Project" ), \
                QString(), tr( "Gluon Project Files (%1)" ).arg( \
                GluonEngine::projectFilename ) );
-    if( !fileName.isEmpty() )
-        openProject( fileName );
-}
-
-void MainWindow::openProject( const QString& fileName )
-{
-    QString file = fileName;
-    if( file.isEmpty() )
-        file = d->fileName;
-
-    d->widget = new GluonGraphics::RenderWidget( this );
-    setCentralWidget( d->widget );
-    connect( GluonEngine::Game::instance(), SIGNAL( painted( int ) ), d->widget, \
                SLOT( updateGL() ) );
-    connect( GluonEngine::Game::instance(), SIGNAL( painted( int ) ), SLOT( \
                countFrames( int ) ) );
-    connect( GluonEngine::Game::instance(), SIGNAL( updated( int ) ), SLOT( \
                updateTitle( int ) ) );
-
-    GluonInput::InputManager::instance()->setFilteredObject( d->widget );
-    QTimer::singleShot( 100, this, SLOT( startGame() ) );
-
-    d->fileName = file;
-}
-
-void MainWindow::startGame()
-{
-    GluonCore::GluonObjectFactory::instance()->loadPlugins();
-
-    d->project = new GluonEngine::GameProject();
-    d->project->loadFromFile( d->fileName );
-
-    setWindowFilePath( d->fileName );
-    d->title = windowTitle();
-
-    GluonEngine::Game::instance()->setGameProject( d->project );
-    GluonEngine::Game::instance()->setCurrentScene( d->project->entryPoint() );
-
-    d->widget->setFocus();
-    GluonEngine::Game::instance()->runGame();
-    QApplication::instance()->exit();
-}
-
-void MainWindow::closeEvent( QCloseEvent* event )
-{
-    GluonEngine::Game::instance()->stopGame();
-    QWidget::closeEvent( event );
-}
-
-void MainWindow::updateTitle( int msec )
-{
-    d->msecElapsed += msec;
-
-    static int fps = 0;
-    if( d->msecElapsed > 1000 )
-    {
-        fps = d->frameCount;
-        d->frameCount = 0;
-        d->msecElapsed = 0;
-    }
-
-    setWindowTitle( d->title + QString( " (%1 FPS)" ).arg( fps ) );
-}
-
-void MainWindow::countFrames( int /* time */ )
-{
-    d->frameCount++;
-}
-
-void MainWindow::loadGamesList()
-{
-    QDir m_dir;
-    m_dir.cd( GluonCore::DirectoryProvider::instance()->dataDirectory() + \
                "/gluon/games" );
-    QStringList gameDirNameList = m_dir.entryList( QStringList() << QString( '*' + \
                GluonEngine::projectSuffix ), QDir::Dirs | QDir::NoDotAndDotDot );
-    foreach( const QString & gameDirName, gameDirNameList )
-    {
-        QDir gameDir = m_dir;
-        gameDir.cd( gameDirName );
-        QStringList gluonProjectFiles = gameDir.entryList( QStringList( \
                GluonEngine::projectFilename ) );
-        if( !gluonProjectFiles.isEmpty() )
-        {
-            QString projectFileName = gameDir.absoluteFilePath( \
                gluonProjectFiles.at( 0 ) );
-            GluonEngine::GameProject project;
-            project.loadFromFile( projectFileName );
-            d->listWidget->addItem( projectFileName );
-        }
-    }
-}
-
-#include "mainwindow.moc"
diff --git a/player/qt/mainwindow.h b/player/qt/mainwindow.h
deleted file mode 100644
index e032ce2..0000000
--- a/player/qt/mainwindow.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/******************************************************************************
- * This file is part of the Gluon Development Platform
- * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl>
- * Copyright (c) 2010 Laszlo Papp <lpapp@kde.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef GLUON_QTPLAYER_MAINWINDOW_H
-#define GLUON_QTPLAYER_MAINWINDOW_H
-
-#include <QtGui/QMainWindow>
-
-class QModelIndex;
-
-namespace GluonPlayer
-{
-    class MainWindow : public QMainWindow
-    {
-            Q_OBJECT
-        public:
-            MainWindow( int argc, char** argv, QWidget* parent = 0, Qt::WindowFlags \
                flags = 0 );
-            virtual ~MainWindow();
-            virtual void closeEvent( QCloseEvent* event );
-
-        public slots:
-            void openProject( const QString& fileName = QString() );
-            void updateTitle( int msec );
-            void activated( QModelIndex index );
-            void openClicked( bool );
-            void startGame();
-            void countFrames( int );
-
-        private:
-            class MainWindowPrivate;
-            MainWindowPrivate* d;
-
-            void loadGamesList();
-    };
-}
-
-#endif // GLUON_QTPLAYER_MAINWINDOW_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic