// --------------------------------------------------------------------------
// qMini,
// a minimal Qt/OpenGL app to extend
//
// Copyright(C) 2011
// Tamy Boubekeur
//                                                                            
// All rights reserved.                                                       
//                                                                            
// This program is free software; you can redistribute it and/or modify       
// it under the terms of the GNU General Public License as published by       
// the Free Software Foundation; either version 2 of the License, or          
// (at your option) any later version.                                        
//                                                                            
// This program 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 General Public License (http://www.gnu.org/licenses/gpl.txt)           
// for more details.                                                          
//                                                                          
// --------------------------------------------------------------------------

#include "GLViewer.h"
#include <QApplication>
#include <QCoreApplication>
#include <QAction>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QDir>
#include <QGLFormat>
#include <QPixmap>
#include <QSplashScreen>
#include <QString>
#include <string>


using namespace std;

int main (int argc, char **argv) {
    QApplication qMini ( argc, argv );
    if (QGLFormat::hasOpenGL() == false) {
        qWarning ("This system has no OpenGL support.");
        return -1;
    }
    QIcon icon (":/images/star.png");
    QMainWindow * window = new QMainWindow ();
    GLViewer * viewer = new GLViewer;
    if (argc > 1) {
        string fullName;
        if (argv[1][0] == '/')
            fullName = string (argv [1]);
        else
            fullName = string (qPrintable (QDir::currentPath ())) + "/" + string (argv [1]);
        viewer->open (QString (fullName.c_str ()));
    }
    window->setCentralWidget (viewer);
    viewer->setMinimumSize (200, 200);
    window->setWindowIcon (icon);
    window->setWindowTitle ("qMini - By Tamy Boubekeur");
    window->showMaximized ();
    window->show();
    QAction * fileQuitAction = new QAction (QPixmap(":/resources/exit.png"), "Quit", window);
    fileQuitAction->setShortcut (window->tr ("Ctrl+Q"));
    window->connect (fileQuitAction, SIGNAL (activated()) , qApp, SLOT (closeAllWindows()));
    QActionGroup * fileActionGroup = new QActionGroup (window);
    fileActionGroup->addAction (fileQuitAction);
    QMenu * fileMenu = window->menuBar ()->addMenu (window->tr ("File"));;
    fileMenu->addActions (fileActionGroup->actions ());

    qMini.connect (&qMini, SIGNAL (lastWindowClosed()), &qMini, SLOT (quit()));

    return qMini.exec ();
}
