2011-12-25 21:19:32 +00:00
# include "mainwindow.h"
2012-01-08 10:31:01 +00:00
# include <QApplication>
# include <QMenuBar>
2012-01-23 23:45:33 +00:00
# include <QMenu>
2012-02-20 21:17:13 +00:00
# include <QIcon>
2012-04-11 19:59:50 +00:00
# include <QToolBar>
2012-01-08 10:31:01 +00:00
# include <QFileDialog>
2012-01-23 23:45:33 +00:00
# include <QTabWidget>
2012-02-28 13:45:11 +00:00
# include <QTranslator>
# include <QLocale>
2012-04-09 08:33:13 +00:00
# include <QMessageBox>
2012-01-08 10:31:01 +00:00
2012-04-29 15:14:37 +00:00
# include "basepreview.h"
2012-01-26 23:08:09 +00:00
# include "formatmosphere.h"
# include "formclouds.h"
# include "formlighting.h"
# include "formsky.h"
2012-01-22 18:39:42 +00:00
# include "formterrain.h"
2012-01-26 23:08:09 +00:00
# include "formtextures.h"
2011-12-25 21:19:32 +00:00
# include "formwater.h"
2012-01-06 16:09:03 +00:00
# include "formrender.h"
2012-01-26 23:08:09 +00:00
2012-01-10 20:51:27 +00:00
# include "dialogrender.h"
2012-01-26 23:08:09 +00:00
# include "dialogwanderer.h"
2011-12-25 21:19:32 +00:00
2012-01-29 17:39:56 +00:00
# include "../lib_paysages/main.h"
2012-01-24 13:16:20 +00:00
# include "../lib_paysages/auto.h"
2012-01-27 14:47:08 +00:00
# include "../lib_paysages/scenery.h"
2012-01-05 18:39:17 +00:00
int main ( int argc , char * * argv )
2011-12-25 21:19:32 +00:00
{
2012-02-28 13:45:11 +00:00
MainWindow * window ;
2012-02-12 16:57:29 +00:00
int result ;
2012-04-28 13:36:37 +00:00
2012-01-05 18:39:17 +00:00
paysagesInit ( ) ;
2011-12-25 21:19:32 +00:00
2012-01-05 18:39:17 +00:00
QApplication app ( argc , argv ) ;
2012-04-28 13:36:37 +00:00
2012-02-28 13:45:11 +00:00
QTranslator qtTranslator ;
QTranslator myTranslator ;
2012-04-28 13:36:37 +00:00
2012-02-28 13:45:11 +00:00
if ( myTranslator . load ( " paysages_ " + QLocale : : system ( ) . name ( ) , " ./i18n " ) )
{
app . installTranslator ( & myTranslator ) ;
qtTranslator . load ( " qt_ " + QLocale : : system ( ) . name ( ) ) ;
app . installTranslator ( & qtTranslator ) ;
}
else
{
qtTranslator . load ( " qt_en " ) ;
app . installTranslator ( & qtTranslator ) ;
}
2012-04-29 15:14:37 +00:00
BasePreview : : initDrawers ( ) ;
2012-02-28 13:45:11 +00:00
window = new MainWindow ( ) ;
window - > show ( ) ;
2012-01-05 18:39:17 +00:00
2012-02-12 16:57:29 +00:00
result = app . exec ( ) ;
2012-04-28 13:36:37 +00:00
2012-04-30 19:25:30 +00:00
BasePreview : : stopDrawers ( ) ;
2012-02-28 13:45:11 +00:00
delete window ;
2012-04-28 13:36:37 +00:00
2012-02-12 16:57:29 +00:00
paysagesQuit ( ) ;
return result ;
2011-12-25 21:19:32 +00:00
}
2012-01-05 18:39:17 +00:00
MainWindow : : MainWindow ( QWidget * parent ) :
2012-04-28 13:36:37 +00:00
QMainWindow ( parent )
2011-12-25 21:19:32 +00:00
{
2012-01-26 22:30:20 +00:00
BaseForm * form ;
2012-01-05 18:39:17 +00:00
QTabWidget * tabs ;
2012-04-11 19:59:50 +00:00
QToolBar * toolbar ;
2012-04-28 13:36:37 +00:00
2012-01-05 18:39:17 +00:00
tabs = new QTabWidget ( this ) ;
2012-01-26 22:30:20 +00:00
form = new FormTerrain ( tabs ) ;
2012-02-28 13:45:11 +00:00
tabs - > addTab ( form , tr ( " Terrain " ) ) ;
2012-01-26 22:30:20 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ;
2012-01-26 23:08:09 +00:00
form = new FormTextures ( tabs ) ;
2012-02-28 13:45:11 +00:00
tabs - > addTab ( form , tr ( " Textures " ) ) ;
2012-01-26 23:08:09 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ;
2012-01-26 22:30:20 +00:00
form = new FormWater ( tabs ) ;
2012-02-28 13:45:11 +00:00
tabs - > addTab ( form , tr ( " Water " ) ) ;
2012-01-26 22:30:20 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ;
form = new FormSky ( tabs ) ;
2012-02-28 13:45:11 +00:00
tabs - > addTab ( form , tr ( " Sky " ) ) ;
2012-01-26 22:30:20 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ;
2012-03-18 21:00:50 +00:00
form = new FormAtmosphere ( tabs ) ;
tabs - > addTab ( form , tr ( " Atmosphere " ) ) ;
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ;
2012-01-26 23:08:09 +00:00
form = new FormClouds ( tabs ) ;
2012-02-28 13:45:11 +00:00
tabs - > addTab ( form , tr ( " Clouds " ) ) ;
2012-01-26 23:08:09 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ;
2012-03-08 15:10:25 +00:00
/*form = new FormLighting(tabs);
2012-02-28 13:45:11 +00:00
tabs - > addTab ( form , tr ( " Lighting " ) ) ;
2012-03-08 15:10:25 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) ) ; */
2012-01-26 23:08:09 +00:00
2012-04-02 19:38:59 +00:00
_form_render = new FormRender ( tabs ) ;
tabs - > addTab ( _form_render , tr ( " Render " ) ) ;
2012-01-05 18:39:17 +00:00
2012-04-11 19:59:50 +00:00
toolbar = new QToolBar ( this ) ;
toolbar - > setOrientation ( Qt : : Vertical ) ;
toolbar - > setAllowedAreas ( Qt : : LeftToolBarArea ) ;
toolbar - > setMovable ( false ) ;
toolbar - > setFloatable ( false ) ;
toolbar - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
toolbar - > toggleViewAction ( ) - > setEnabled ( false ) ;
toolbar - > setIconSize ( QSize ( 32 , 32 ) ) ;
addToolBar ( Qt : : LeftToolBarArea , toolbar ) ;
2012-04-28 13:36:37 +00:00
2012-04-11 19:59:50 +00:00
toolbar - > addAction ( QIcon ( " images/new.png " ) , tr ( " &New " ) , this , SLOT ( fileNew ( ) ) ) - > setShortcut ( QKeySequence ( tr ( " Crtl+N " ) ) ) ;
toolbar - > addAction ( QIcon ( " images/save.png " ) , tr ( " &Save " ) , this , SLOT ( fileSave ( ) ) ) - > setShortcut ( QKeySequence ( tr ( " Crtl+S " ) ) ) ;
toolbar - > addAction ( QIcon ( " images/load.png " ) , tr ( " &Load " ) , this , SLOT ( fileLoad ( ) ) ) - > setShortcut ( QKeySequence ( tr ( " Crtl+L " ) ) ) ;
toolbar - > addAction ( QIcon ( " images/explore.png " ) , tr ( " &Explore (F2) " ) , this , SLOT ( explore3D ( ) ) ) - > setShortcut ( QKeySequence ( tr ( " F2 " ) ) ) ;
toolbar - > addAction ( QIcon ( " images/render.png " ) , tr ( " &Quick \n render (F5) " ) , this , SLOT ( quickPreview ( ) ) ) - > setShortcut ( QKeySequence ( tr ( " F5 " ) ) ) ;
toolbar - > addAction ( QIcon ( " images/about.png " ) , tr ( " &About " ) , this , SLOT ( showAboutDialog ( ) ) ) ;
2012-06-02 09:46:24 +00:00
2012-01-05 18:39:17 +00:00
setCentralWidget ( tabs ) ;
2012-01-16 21:29:21 +00:00
setWindowTitle ( " Paysages 3D " ) ;
2012-02-20 21:17:13 +00:00
setWindowIcon ( QIcon ( " images/logo_32.png " ) ) ;
2011-12-25 21:19:32 +00:00
}
2012-01-08 10:31:01 +00:00
2012-06-02 09:46:24 +00:00
bool MainWindow : : event ( QEvent * event )
{
if ( event - > type ( ) = = QEvent : : WindowActivate )
{
BasePreview : : reviveAll ( ) ;
}
return QMainWindow : : event ( event ) ;
}
2012-01-10 20:51:27 +00:00
void MainWindow : : refreshAll ( )
{
QList < BaseForm * > list_forms = this - > findChildren < BaseForm * > ( " _base_form_ " ) ;
for ( int i = 0 ; i < list_forms . size ( ) ; i + + )
{
list_forms [ i ] - > revertConfig ( ) ;
}
}
2012-01-08 10:31:01 +00:00
void MainWindow : : fileNew ( )
{
2012-04-16 19:24:46 +00:00
if ( QMessageBox : : question ( this , tr ( " Paysages 3D - New scenery " ) , tr ( " Do you want to start a new scenery ? Any unsaved changes will be lost. " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : Yes )
2012-04-16 18:28:40 +00:00
{
autoGenRealisticLandscape ( 0 ) ;
autoSetDaytime ( 8 , 30 ) ;
refreshAll ( ) ;
}
2012-01-08 10:31:01 +00:00
}
void MainWindow : : fileSave ( )
{
2012-04-16 19:24:46 +00:00
QString filepath = QFileDialog : : getSaveFileName ( this , tr ( " Paysages 3D - Choose a file to save the scenery " ) , QString ( ) , tr ( " Paysages 3D Scenery (*.p3d) " ) ) ;
2012-01-10 20:51:27 +00:00
if ( ! filepath . isNull ( ) )
{
2012-04-16 19:24:46 +00:00
if ( ! filepath . toLower ( ) . endsWith ( " .p3d " ) )
{
filepath = filepath . append ( " .p3d " ) ;
}
2012-04-28 13:36:37 +00:00
FileOperationResult result = paysagesSave ( ( char * ) filepath . toStdString ( ) . c_str ( ) ) ;
switch ( result )
{
case FILE_OPERATION_OK :
break ;
case FILE_OPERATION_IOERROR :
QMessageBox : : critical ( this , tr ( " Paysages 3D - File saving error " ) , tr ( " Can't write specified file : %1 " ) . arg ( filepath ) ) ;
break ;
default :
QMessageBox : : critical ( this , tr ( " Paysages 3D - File saving error " ) , tr ( " Unexpected error while saving file : %1 " ) . arg ( filepath ) ) ;
}
2012-01-10 20:51:27 +00:00
}
2012-01-08 10:31:01 +00:00
}
void MainWindow : : fileLoad ( )
{
2012-04-16 19:24:46 +00:00
if ( QMessageBox : : question ( this , tr ( " Paysages 3D - Load scenery " ) , tr ( " Do you want to load a scenery from file ? Any unsaved changes will be lost. " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) = = QMessageBox : : Yes )
2012-01-10 20:51:27 +00:00
{
2012-04-16 19:24:46 +00:00
QString filepath = QFileDialog : : getOpenFileName ( this , tr ( " Paysages 3D - Choose a scenery file to load " ) , QString ( ) , tr ( " Paysages 3D Scenery (*.p3d) " ) ) ;
2012-04-16 18:28:40 +00:00
if ( ! filepath . isNull ( ) )
{
2012-04-28 13:36:37 +00:00
FileOperationResult result = paysagesLoad ( ( char * ) filepath . toStdString ( ) . c_str ( ) ) ;
switch ( result )
{
case FILE_OPERATION_OK :
refreshAll ( ) ;
break ;
case FILE_OPERATION_IOERROR :
QMessageBox : : critical ( this , tr ( " Paysages 3D - File loading error " ) , tr ( " Can't read specified file : %1 " ) . arg ( filepath ) ) ;
break ;
case FILE_OPERATION_APP_MISMATCH :
QMessageBox : : critical ( this , tr ( " Paysages 3D - File loading error " ) , tr ( " This file doesn't look like a Paysages 3D file : %1 " ) . arg ( filepath ) ) ;
break ;
case FILE_OPERATION_VERSION_MISMATCH :
QMessageBox : : critical ( this , tr ( " Paysages 3D - File loading error " ) , tr ( " This file was created with an incompatible Paysages 3D version : %1 " ) . arg ( filepath ) ) ;
break ;
default :
QMessageBox : : critical ( this , tr ( " Paysages 3D - File loading error " ) , tr ( " Unexpected error while loading file : %1 " ) . arg ( filepath ) ) ;
}
2012-04-16 18:28:40 +00:00
}
2012-01-10 20:51:27 +00:00
}
}
2012-04-05 17:47:43 +00:00
void MainWindow : : showAboutDialog ( )
{
2012-05-01 10:43:33 +00:00
QMessageBox : : about ( this , tr ( " Paysages 3D " ) , tr ( " A 3D landscape editing and rendering software. \n \n Authors : \n Programming - Michael Lemaire \n \n Credits : \n Qt - http://qt.nokia.com/ \n DevIL - http://openil.sourceforge.net/ \n GLib - http://www.gtk.org/ \n " ) ) ;
2012-04-05 17:47:43 +00:00
}
2012-01-10 20:51:27 +00:00
void MainWindow : : quickPreview ( )
{
2012-04-02 19:38:59 +00:00
_form_render - > startQuickRender ( ) ;
2012-01-08 10:31:01 +00:00
}
2012-01-26 23:08:09 +00:00
void MainWindow : : explore3D ( )
{
2012-01-27 14:47:08 +00:00
CameraDefinition camera ;
2012-04-12 20:20:57 +00:00
int result ;
2012-01-27 14:47:08 +00:00
sceneryGetCamera ( & camera ) ;
2012-01-31 11:20:52 +00:00
DialogWanderer * dialog = new DialogWanderer ( this , & camera , true ) ;
2012-04-12 20:20:57 +00:00
result = dialog - > exec ( ) ;
2012-04-28 13:36:37 +00:00
2012-01-26 23:08:09 +00:00
delete dialog ;
2012-04-28 13:36:37 +00:00
2012-04-12 20:20:57 +00:00
if ( result = = QDialog : : Accepted )
{
scenerySetCamera ( & camera ) ;
refreshAll ( ) ;
}
2012-01-26 23:08:09 +00:00
}