Commit d8c00795 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Added Common/Gui/I18nMainWindow.

parent 17ca92ce
......@@ -15,6 +15,7 @@ set( Common_Gui_SOURCES
mvdDatasetCreationProgressDialog.cxx
mvdGLImageWidget.cxx
mvdGui.cxx
mvdI18nMainWindow.cxx
mvdImageModelRenderer.cxx
mvdImageViewManipulator.cxx
mvdMainWindowTitleLoader.cxx
......@@ -41,6 +42,7 @@ set( Common_Gui_HEADERS_MOC
mvdDatasetCreationProgressDialog.h
mvdGLImageWidget.h
# mvdGui.h
mvdI18nMainWindow.h
mvdImageModelRenderer.h
mvdImageViewManipulator.h
mvdMainWindowTitleLoader.h
......
/*=========================================================================
Program: Monteverdi2
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "mvdI18nMainWindow.h"
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QtGui>
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
#include "otbSystem.h"
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdI18nApplication.h"
#include "Core/mvdDatasetModel.h"
//
#include "Gui/mvdAboutDialog.h"
namespace mvd
{
/*
TRANSLATOR mvd::I18nMainWindow
Necessary for lupdate to be aware of C++ namespaces.
Context comment for translator.
*/
/*****************************************************************************/
I18nMainWindow
::I18nMainWindow( QWidget* parent, Qt::WindowFlags flags ) :
QMainWindow( parent, flags )
{
}
/*****************************************************************************/
I18nMainWindow
::~I18nMainWindow()
{
}
/*****************************************************************************/
void
I18nMainWindow
::Initialize()
{
/*
// Default setup.
setObjectName( "mvd::I18nMainWindow" );
setWindowTitle( PROJECT_NAME );
*/
virtual_SetupUI();
// Connect Appllication and MainWindow when selected model is about
// to change.
QObject::connect(
qApp, SIGNAL( AboutToChangeModel( const AbstractModel* ) ),
this, SLOT( OnAboutToChangeModel( const AbstractModel* ) )
);
// Connect Application and MainWindow when selected model has been
// changed.
QObject::connect(
qApp, SIGNAL( ModelChanged( AbstractModel* ) ),
this, SLOT( OnModelChanged( AbstractModel* ) )
);
virtual_ConnectUI();
// Change to NULL model to force emitting GUI signals when GUI is
// instanciated. So, GUI will be initialized and controller-widgets
// disabled.
I18nApplication::Instance()->SetModel( NULL );
}
/*****************************************************************************/
QDockWidget*
I18nMainWindow
::AddWidgetToDock( QWidget* widget,
const QString& dockName,
const QString& dockTitle,
Qt::DockWidgetArea dockArea )
{
// New dock.
QDockWidget* dockWidget = new QDockWidget( dockTitle, this );
// You can use findChild( dockName ) to get dock-widget.
dockWidget->setObjectName( dockName );
dockWidget->setWidget( widget );
// Features.
dockWidget->setFloating( false );
dockWidget->setFeatures(
QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable |
QDockWidget::DockWidgetClosable
);
// Add dock.
addDockWidget( dockArea, dockWidget );
return dockWidget;
}
/*****************************************************************************/
void
I18nMainWindow
::closeEvent( QCloseEvent* event )
{
assert( event!=NULL );
qDebug() << "I18nMainWindow::closeEvent(" << event << ")";
// Ensure there is an application instance.
assert( I18nApplication::ConstInstance()!=NULL );
// Ensure that there is no model or that the existing model is a
// DatasetModel.
assert( I18nApplication::ConstInstance()->GetModel()==
I18nApplication::ConstInstance()->GetModel< DatasetModel >() );
// Get model.
DatasetModel* model =
I18nApplication::Instance()->GetModel< DatasetModel >();
if( model==NULL || !model->IsModified() )
return;
QMessageBox::StandardButton clickedButton = ConfirmSaveQuit( true );
switch( clickedButton )
{
case QMessageBox::Save:
model->Save();
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
// Ignore event: do not close/quit.
event->ignore();
break;
default:
// should never be reached.
assert( false );
break;
}
}
/*****************************************************************************/
/* SLOTS */
/*****************************************************************************/
void
I18nMainWindow
::on_action_Quit_triggered()
{
close();
}
/*****************************************************************************/
void
I18nMainWindow
::on_action_About_activated()
{
AboutDialog aboutDialog( this );
aboutDialog.exec();
}
/*****************************************************************************/
} // end namespace 'mvd'
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __mvdI18nMainWindow_h
#define __mvdI18nMainWindow_h
//
// Configuration include.
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QtGui>
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External class pre-declaration.
namespace
{
}
namespace mvd
{
//
// Internal class pre-declaration.
class AbstractModel;
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class I18nMainWindow
*
* \brief Main-window widget base for the i18n application.
*/
class Monteverdi2_EXPORT I18nMainWindow
: public QMainWindow
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT;
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public types.
public:
//
// Public methods.
public:
/** \brief Destructor. */
virtual ~I18nMainWindow();
/**
*/
void Initialize();
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// SIGNALS.
signals:
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
/** \brief Constructor. */
I18nMainWindow( QWidget* Parent =0, Qt::WindowFlags flags =0 );
/**
*/
virtual void virtual_SetupUI() =0;
/**
*/
virtual void virtual_ConnectUI() =0;
//
// QMainWindow overrides.
void closeEvent( QCloseEvent* event );
//
// Protected attributes.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private nested classes.
private:
//
// Private methods.
private:
/**
*/
QDockWidget*
AddWidgetToDock( QWidget* widget,
const QString& dockName,
const QString& dockTitle,
Qt::DockWidgetArea dockArea );
/**
* \brief Assign model to the controller which is child of given
* dock-widget.
*
* \param dock The dock-widget which is parent of the controller to
* assign model to.
*
* \param model The model to assign to the controller.
*/
inline void SetControllerModel( QDockWidget* dock, AbstractModel* model );
/**
*/
inline QMessageBox::StandardButton ConfirmSaveQuit( bool canBeCancelled );
//
// Private attributes.
private:
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
// Private slots.
private slots:
/**
* \brief Qt auto-connected slot which is called when File/Quit menu
* action is activated.
*/
void on_action_Quit_triggered();
/**
* \brief Qt auto-connected slot which is called when Help/About
* menu action is activated.
*/
void on_action_About_activated();
/**
*/
virtual void OnAboutToChangeModel( const AbstractModel* ) =0;
/**
*/
virtual void OnModelChanged( AbstractModel* ) =0;
};
} // end namespace 'mvd'
/*****************************************************************************/
/* INLINE SECTION */
//
// System includes (sorted by alphabetic order)
#include <cassert>
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
#include "Gui/mvdAbstractModelController.h"
namespace mvd
{
/*****************************************************************************/
inline
void
I18nMainWindow
::SetControllerModel( QDockWidget* dock, AbstractModel* model )
{
assert( dock );
AbstractModelController* controller =
dock->findChild< AbstractModelController* >();
assert( controller!=NULL );
controller->SetModel( model );
}
/*****************************************************************************/
inline
QMessageBox::StandardButton
I18nMainWindow
::ConfirmSaveQuit( bool canBeCancelled )
{
return QMessageBox::question(
this,
tr( PROJECT_NAME ),
tr( "Dataset has been modified.\n"
"Do you want to save settings before quitting?" ),
QMessageBox::Save |
QMessageBox::Discard |
( canBeCancelled ? QMessageBox::Cancel : QMessageBox::NoButton ),
QMessageBox::Save
);
}
} // end namespace 'mvd'
#endif // __I18nMainWindow_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment