2011-12-25 21:19:32 +00:00
# include "mainwindow.h"
2013-06-09 16:08:01 +00:00
# include "ui_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-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-12-14 16:16:09 +00:00
# include <QSplashScreen>
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 "formclouds.h"
2012-11-25 21:53:01 +00:00
# include "formatmosphere.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
2013-05-05 16:42:55 +00:00
# include "terrain/mainterrainform.h"
2012-01-10 20:51:27 +00:00
# include "dialogrender.h"
2012-06-08 12:54:57 +00:00
# include "dialogexplorer.h"
2011-12-25 21:19:32 +00:00
2013-04-17 12:29:51 +00:00
# include "rendering/main.h"
2013-10-29 20:28:59 +00:00
# include "Scenery.h"
2012-06-27 10:30:00 +00:00
# include "tools.h"
2012-01-05 18:39:17 +00:00
2013-06-20 21:18:15 +00:00
MainWindow * MainWindow : : _instance = NULL ;
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-12-14 16:16:09 +00:00
QSplashScreen * splash ;
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
QApplication app ( argc , argv ) ;
2012-04-28 13:36:37 +00:00
2013-04-17 12:29:51 +00:00
splash = new QSplashScreen ( QPixmap ( getDataPath ( " images/logo_256.png " ) ) ) ;
2012-12-14 16:16:09 +00:00
splash - > show ( ) ;
2012-02-28 13:45:11 +00:00
QTranslator qtTranslator ;
QTranslator myTranslator ;
2012-04-28 13:36:37 +00:00
2013-06-16 17:06:10 +00:00
if ( myTranslator . load ( " paysages_ " + QLocale : : system ( ) . name ( ) , " ./data/i18n " ) | | myTranslator . load ( " paysages_ " + QLocale : : system ( ) . name ( ) , " /usr/share/paysages3d/i18n " ) )
2012-02-28 13:45:11 +00:00
{
app . installTranslator ( & myTranslator ) ;
qtTranslator . load ( " qt_ " + QLocale : : system ( ) . name ( ) ) ;
app . installTranslator ( & qtTranslator ) ;
}
else
{
qtTranslator . load ( " qt_en " ) ;
app . installTranslator ( & qtTranslator ) ;
}
2012-12-24 15:15:40 +00:00
//splash->showMessage(app.tr("Preloading..."), Qt::AlignCenter, Qt::white);
2012-12-14 16:16:09 +00:00
app . processEvents ( ) ;
paysagesInit ( ) ;
2012-04-29 15:14:37 +00:00
BasePreview : : initDrawers ( ) ;
2012-12-09 17:49:28 +00:00
2012-02-28 13:45:11 +00:00
window = new MainWindow ( ) ;
2013-06-09 16:20:25 +00:00
window - > show ( ) ;
//window->showMaximized();
2012-12-14 16:16:09 +00:00
splash - > finish ( window ) ;
delete splash ;
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
}
2013-06-20 21:18:15 +00:00
MainWindow : : MainWindow ( ) :
QMainWindow ( ) ,
2013-06-09 16:08:01 +00:00
ui ( new Ui : : MainWindow )
2011-12-25 21:19:32 +00:00
{
2013-06-20 21:18:15 +00:00
_instance = this ;
2013-06-09 16:08:01 +00:00
ui - > setupUi ( this ) ;
2012-04-28 13:36:37 +00:00
2013-06-09 16:08:01 +00:00
BaseForm * form ;
2012-01-26 22:30:20 +00:00
2013-06-09 16:08:01 +00:00
connect ( ui - > action_explore , SIGNAL ( triggered ( ) ) , this , SLOT ( explore3D ( ) ) ) ;
connect ( ui - > action_quick_render , SIGNAL ( triggered ( ) ) , this , SLOT ( quickPreview ( ) ) ) ;
connect ( ui - > action_final_render , SIGNAL ( triggered ( ) ) , this , SLOT ( finalRender ( ) ) ) ;
2013-08-17 16:08:37 +00:00
connect ( ui - > action_last_render , SIGNAL ( triggered ( ) ) , this , SLOT ( showLastRender ( ) ) ) ;
2013-06-09 16:08:01 +00:00
connect ( ui - > action_file_new , SIGNAL ( triggered ( ) ) , this , SLOT ( fileNew ( ) ) ) ;
connect ( ui - > action_file_save , SIGNAL ( triggered ( ) ) , this , SLOT ( fileSave ( ) ) ) ;
connect ( ui - > action_file_load , SIGNAL ( triggered ( ) ) , this , SLOT ( fileLoad ( ) ) ) ;
connect ( ui - > action_about , SIGNAL ( triggered ( ) ) , this , SLOT ( showAboutDialog ( ) ) ) ;
2013-05-05 16:42:55 +00:00
2013-06-09 16:08:01 +00:00
form = new FormWater ( ui - > tabs ) ;
ui - > tabs - > addTab ( form , QIcon ( getDataPath ( " images/tab_water.png " ) ) , tr ( " Water " ) ) ;
2012-08-26 13:06:42 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) , Qt : : QueuedConnection ) ;
2012-07-05 18:14:51 +00:00
_forms . append ( form ) ;
2012-01-26 22:30:20 +00:00
2013-06-09 16:08:01 +00:00
form = new FormAtmosphere ( ui - > tabs ) ;
ui - > tabs - > addTab ( form , QIcon ( getDataPath ( " images/tab_atmosphere.png " ) ) , tr ( " Atmosphere " ) ) ;
2012-08-26 13:06:42 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) , Qt : : QueuedConnection ) ;
2012-07-05 18:14:51 +00:00
_forms . append ( form ) ;
2012-03-18 21:00:50 +00:00
2013-06-09 16:08:01 +00:00
form = new FormClouds ( ui - > tabs ) ;
ui - > tabs - > addTab ( form , QIcon ( getDataPath ( " images/tab_clouds.png " ) ) , tr ( " Clouds " ) ) ;
2012-08-26 13:06:42 +00:00
QObject : : connect ( form , SIGNAL ( configApplied ( ) ) , this , SLOT ( refreshAll ( ) ) , Qt : : QueuedConnection ) ;
2012-07-05 18:14:51 +00:00
_forms . append ( form ) ;
2012-01-26 23:08:09 +00:00
2013-06-09 16:08:01 +00:00
_form_render = new FormRender ( ui - > tabs ) ;
ui - > tabs - > addTab ( _form_render , QIcon ( getDataPath ( " images/tab_render.png " ) ) , tr ( " Render " ) ) ;
2012-07-05 18:14:51 +00:00
_forms . append ( _form_render ) ;
2012-01-05 18:39:17 +00:00
2013-06-23 20:21:42 +00:00
ui - > tabs - > setCurrentIndex ( 0 ) ;
2013-06-09 16:08:01 +00:00
// TODO Decide this according to platform / screen size
2013-08-17 15:04:48 +00:00
ui - > toolBar - > hide ( ) ;
2013-06-09 16:20:25 +00:00
ui - > tool_panel - > hide ( ) ;
2013-08-17 15:04:48 +00:00
//ui->menuBar->hide();
2012-12-09 17:49:28 +00:00
2012-06-27 10:30:00 +00:00
scenerySetCustomDataCallback ( MainWindow : : guiSaveCallback , MainWindow : : guiLoadCallback , this ) ;
2012-12-09 17:49:28 +00:00
2013-06-16 21:01:22 +00:00
// FIXME AutoPreset has already been called by paysagesInit but we need to redo it here because
// the auto apply on FormRender overwrites the camera. Delete this when the render form is no longer a BaseForm.
sceneryAutoPreset ( 0 ) ;
2012-06-26 19:36:50 +00:00
refreshAll ( ) ;
2011-12-25 21:19:32 +00:00
}
2012-01-08 10:31:01 +00:00
2013-06-09 16:08:01 +00:00
MainWindow : : ~ MainWindow ( )
{
delete ui ;
}
2012-06-02 09:46:24 +00:00
bool MainWindow : : event ( QEvent * event )
{
if ( event - > type ( ) = = QEvent : : WindowActivate )
{
BasePreview : : reviveAll ( ) ;
}
2012-12-09 17:49:28 +00:00
2012-06-02 09:46:24 +00:00
return QMainWindow : : event ( event ) ;
}
2012-01-10 20:51:27 +00:00
void MainWindow : : refreshAll ( )
{
2012-06-27 10:30:00 +00:00
logDebug ( " [MainWindow] Refreshing whole UI " ) ;
2012-12-09 17:49:28 +00:00
2012-06-25 20:11:15 +00:00
// Refresh all tabs
2012-07-05 18:14:51 +00:00
for ( int i = 0 ; i < _forms . size ( ) ; i + + )
2012-01-10 20:51:27 +00:00
{
2012-07-05 18:14:51 +00:00
_forms [ i ] - > revertConfig ( ) ;
2012-01-10 20:51:27 +00:00
}
2012-12-09 17:49:28 +00:00
2012-06-25 20:11:15 +00:00
// Refresh preview OSD
2013-04-27 19:41:57 +00:00
CameraDefinition * camera = cameraCreateDefinition ( ) ;
2012-06-26 19:36:50 +00:00
PreviewOsd * osd = PreviewOsd : : getInstance ( QString ( " geolocation " ) ) ;
osd - > clearItems ( ) ;
2013-04-27 19:41:57 +00:00
sceneryGetCamera ( camera ) ;
2012-06-27 09:48:55 +00:00
PreviewOsdItem * item = osd - > newItem ( 50 , 50 ) ;
2013-04-27 19:41:57 +00:00
item - > drawCamera ( camera ) ;
2012-06-27 09:48:55 +00:00
item - > setToolTip ( QString ( tr ( " Camera " ) ) ) ;
2013-04-27 19:41:57 +00:00
cameraDeleteDefinition ( camera ) ;
2013-06-20 21:18:15 +00:00
emit refreshed ( ) ;
2012-01-10 20:51:27 +00:00
}
2013-06-20 20:21:09 +00:00
void MainWindow : : openTab ( int position )
{
ui - > tabs - > setCurrentIndex ( position ) ;
}
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
{
2013-06-16 21:01:22 +00:00
sceneryAutoPreset ( 0 ) ;
2012-04-16 18:28:40 +00:00
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 ( )
{
2013-05-09 17:13:04 +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-project.org/ \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
2013-06-09 16:08:01 +00:00
void MainWindow : : finalRender ( )
{
_form_render - > startRender ( ) ;
}
void MainWindow : : showLastRender ( )
{
_form_render - > showRender ( ) ;
}
2012-01-26 23:08:09 +00:00
void MainWindow : : explore3D ( )
{
2013-04-27 19:41:57 +00:00
CameraDefinition * camera ;
2012-04-12 20:20:57 +00:00
int result ;
2012-01-27 14:47:08 +00:00
2013-04-27 19:41:57 +00:00
camera = cameraCreateDefinition ( ) ;
sceneryGetCamera ( camera ) ;
2012-01-27 14:47:08 +00:00
2013-04-27 19:41:57 +00:00
DialogExplorer * dialog = new DialogExplorer ( 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 )
{
2013-04-27 19:41:57 +00:00
scenerySetCamera ( camera ) ;
2012-04-12 20:20:57 +00:00
refreshAll ( ) ;
}
2013-04-27 19:41:57 +00:00
cameraDeleteDefinition ( camera ) ;
2012-01-26 23:08:09 +00:00
}
2012-06-27 10:30:00 +00:00
void MainWindow : : guiSaveCallback ( PackStream * stream , void * data )
{
2013-04-27 19:41:57 +00:00
( ( MainWindow * ) data ) - > guiSave ( stream ) ;
2012-06-27 10:30:00 +00:00
}
void MainWindow : : guiLoadCallback ( PackStream * stream , void * data )
{
2013-04-27 19:41:57 +00:00
( ( MainWindow * ) data ) - > guiLoad ( stream ) ;
2012-06-27 10:30:00 +00:00
}
void MainWindow : : guiSave ( PackStream * stream )
{
// Save all tabs status
2012-07-05 18:14:51 +00:00
for ( int i = 0 ; i < _forms . size ( ) ; i + + )
2012-06-27 10:30:00 +00:00
{
2012-07-05 18:14:51 +00:00
_forms [ i ] - > savePack ( stream ) ;
2012-06-27 10:30:00 +00:00
}
}
void MainWindow : : guiLoad ( PackStream * stream )
{
// Load all tabs status
2012-07-05 18:14:51 +00:00
for ( int i = 0 ; i < _forms . size ( ) ; i + + )
2012-06-27 10:30:00 +00:00
{
2012-07-05 18:14:51 +00:00
_forms [ i ] - > loadPack ( stream ) ;
2012-06-27 10:30:00 +00:00
}
}