2014-01-29 19:31:34 +00:00
/*
Copyright 2006 - 2014 The QElectroTech Team
This file is part of QElectroTech .
QElectroTech 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 .
QElectroTech 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 for more details .
You should have received a copy of the GNU General Public License
along with QElectroTech . If not , see < http : //www.gnu.org/licenses/>.
*/
2012-06-29 05:21:41 +00:00
# include "projectconfigpages.h"
# include "qeticons.h"
# include "qetproject.h"
# include "borderpropertieswidget.h"
# include "conductorpropertieswidget.h"
2012-07-01 21:54:07 +00:00
# include "diagramcontextwidget.h"
2012-06-29 05:21:41 +00:00
# include "titleblockpropertieswidget.h"
# include <QtGui>
2014-01-18 19:04:39 +00:00
# include "ui/reportpropertiewidget.h"
2014-04-11 09:51:21 +00:00
# include "ui/xrefpropertieswidget.h"
2012-06-29 05:21:41 +00:00
/**
Constructor
@ param project Project this page is editing .
@ param parent Parent QWidget
*/
ProjectConfigPage : : ProjectConfigPage ( QETProject * project , QWidget * parent ) :
ConfigPage ( parent ) ,
project_ ( project )
{
}
/**
Destructor
*/
ProjectConfigPage : : ~ ProjectConfigPage ( ) {
}
/**
@ return the project being edited by this page
*/
QETProject * ProjectConfigPage : : project ( ) const {
return ( project_ ) ;
}
/**
Set \ a new_project as the project being edited by this page .
@ param read_values True to read values from the project into widgets before setting them read only accordingly , false otherwise . Defaults to true .
@ return the former project
*/
QETProject * ProjectConfigPage : : setProject ( QETProject * new_project , bool read_values ) {
if ( new_project = = project_ ) return ( project_ ) ;
QETProject * former_project = project_ ;
project_ = new_project ;
if ( project_ & & read_values ) {
readValuesFromProject ( ) ;
adjustReadOnly ( ) ;
}
return ( former_project ) ;
}
/**
Apply the configuration after user input
*/
void ProjectConfigPage : : applyConf ( ) {
if ( ! project_ | | project_ - > isReadOnly ( ) ) return ;
applyProjectConf ( ) ;
}
/**
Initialize the page by calling initWidgets ( ) and initLayout ( ) . Also call
readValuesFromProject ( ) and adjustReadOnly ( ) if a non - zero project has been
set . Typically , you should call this function in your subclass constructor .
*/
void ProjectConfigPage : : init ( ) {
initWidgets ( ) ;
initLayout ( ) ;
if ( project_ ) {
readValuesFromProject ( ) ;
adjustReadOnly ( ) ;
}
}
/**
Constructor
@ param project Project this page is editing .
@ param parent Parent QWidget
*/
ProjectMainConfigPage : : ProjectMainConfigPage ( QETProject * project , QWidget * parent ) :
ProjectConfigPage ( project , parent )
{
init ( ) ;
}
/**
Destructor
*/
ProjectMainConfigPage : : ~ ProjectMainConfigPage ( ) {
}
/**
@ return the title for this page
*/
QString ProjectMainConfigPage : : title ( ) const {
return ( tr ( " G \351 n \351 ral " , " configuration page title " ) ) ;
}
/**
@ return the icon for this page
*/
QIcon ProjectMainConfigPage : : icon ( ) const {
return ( QET : : Icons : : Settings ) ;
}
/**
Apply the configuration after user input
*/
void ProjectMainConfigPage : : applyProjectConf ( ) {
2012-07-07 19:45:32 +00:00
bool modified_project = false ;
QString new_title = title_value_ - > text ( ) ;
if ( project_ - > title ( ) ! = new_title ) {
project_ - > setTitle ( new_title ) ;
modified_project = true ;
}
DiagramContext new_properties = project_variables_ - > context ( ) ;
if ( project_ - > projectProperties ( ) ! = new_properties ) {
project_ - > setProjectProperties ( new_properties ) ;
modified_project = true ;
}
if ( modified_project ) {
project_ - > setModified ( true ) ;
}
2012-06-29 05:21:41 +00:00
}
/**
@ return the project title entered by the user
*/
QString ProjectMainConfigPage : : projectTitle ( ) const {
return ( title_value_ - > text ( ) ) ;
}
/**
Initialize widgets displayed by the page .
*/
void ProjectMainConfigPage : : initWidgets ( ) {
title_label_ = new QLabel ( tr ( " Titre du projet \240 : " , " label when configuring " ) ) ;
title_value_ = new QLineEdit ( ) ;
2012-07-02 06:34:40 +00:00
title_information_ = new QLabel ( tr ( " Ce titre sera disponible pour tous les sch \351 mas de ce projet en tant que %projecttitle. " , " informative label " ) ) ;
2012-07-01 21:54:07 +00:00
project_variables_label_ = new QLabel (
tr (
2012-07-02 06:34:40 +00:00
" Vous pouvez d \351 finir ci-dessous des propri \351 t \351 s personnalis \351 es qui seront disponibles pour tous les sch \351 mas de ce projet (typiquement pour les cartouches). " ,
2012-07-01 21:54:07 +00:00
" informative label "
)
) ;
2012-07-02 06:34:40 +00:00
project_variables_label_ - > setWordWrap ( true ) ;
2012-07-01 21:54:07 +00:00
project_variables_ = new DiagramContextWidget ( ) ;
project_variables_ - > setContext ( DiagramContext ( ) ) ;
2012-06-29 05:21:41 +00:00
}
/**
Initialize the layout of this page .
*/
void ProjectMainConfigPage : : initLayout ( ) {
QVBoxLayout * main_layout0 = new QVBoxLayout ( ) ;
QHBoxLayout * title_layout0 = new QHBoxLayout ( ) ;
title_layout0 - > addWidget ( title_label_ ) ;
title_layout0 - > addWidget ( title_value_ ) ;
main_layout0 - > addLayout ( title_layout0 ) ;
2012-07-02 06:34:40 +00:00
main_layout0 - > addWidget ( title_information_ ) ;
main_layout0 - > addSpacing ( 10 ) ;
2012-07-01 21:54:07 +00:00
main_layout0 - > addWidget ( project_variables_label_ ) ;
main_layout0 - > addWidget ( project_variables_ ) ;
2012-06-29 05:21:41 +00:00
setLayout ( main_layout0 ) ;
}
/**
Read properties from the edited project then fill widgets with them .
*/
void ProjectMainConfigPage : : readValuesFromProject ( ) {
title_value_ - > setText ( project_ - > title ( ) ) ;
2012-07-01 21:54:07 +00:00
project_variables_ - > setContext ( project_ - > projectProperties ( ) ) ;
2012-06-29 05:21:41 +00:00
}
/**
Set the content of this page read only if the project is read only ,
editable if the project is editable .
*/
void ProjectMainConfigPage : : adjustReadOnly ( ) {
bool is_read_only = project_ - > isReadOnly ( ) ;
title_value_ - > setReadOnly ( is_read_only ) ;
}
/**
Constructor
@ param project Project this page is editing .
@ param parent Parent QWidget
*/
ProjectNewDiagramConfigPage : : ProjectNewDiagramConfigPage ( QETProject * project , QWidget * parent ) :
ProjectConfigPage ( project , parent )
{
init ( ) ;
}
/**
Destructor
*/
ProjectNewDiagramConfigPage : : ~ ProjectNewDiagramConfigPage ( ) {
}
/**
@ return the title for this page
*/
QString ProjectNewDiagramConfigPage : : title ( ) const {
return ( tr ( " Nouveau sch \351 ma " , " project configuration page title " ) ) ;
}
/**
@ return the icon for this page
*/
QIcon ProjectNewDiagramConfigPage : : icon ( ) const {
return ( QET : : Icons : : NewDiagram ) ;
}
/**
Apply the configuration after user input
*/
void ProjectNewDiagramConfigPage : : applyProjectConf ( ) {
2012-07-07 19:45:32 +00:00
bool modified_project = false ;
2014-07-11 16:45:18 +00:00
BorderProperties new_border_prop = border_ - > properties ( ) ;
2012-07-07 19:45:32 +00:00
if ( project_ - > defaultBorderProperties ( ) ! = new_border_prop ) {
2014-07-11 16:45:18 +00:00
project_ - > setDefaultBorderProperties ( border_ - > properties ( ) ) ;
2012-07-07 19:45:32 +00:00
modified_project = true ;
}
2014-07-12 13:14:47 +00:00
TitleBlockProperties new_tbt_prop = titleblock_ - > properties ( ) ;
2012-07-07 19:45:32 +00:00
if ( project_ - > defaultTitleBlockProperties ( ) ! = new_tbt_prop ) {
2014-07-12 13:14:47 +00:00
project_ - > setDefaultTitleBlockProperties ( titleblock_ - > properties ( ) ) ;
2012-07-07 19:45:32 +00:00
modified_project = true ;
}
2014-07-17 09:20:21 +00:00
ConductorProperties new_conductor_prop = conductor_ - > properties ( ) ;
2012-07-07 19:45:32 +00:00
if ( project_ - > defaultConductorProperties ( ) ! = new_conductor_prop ) {
2014-07-17 09:20:21 +00:00
project_ - > setDefaultConductorProperties ( conductor_ - > properties ( ) ) ;
2012-07-07 19:45:32 +00:00
modified_project = true ;
}
2014-01-18 19:04:39 +00:00
QString new_report_prop = report_ - > ReportProperties ( ) ;
if ( project_ - > defaultReportProperties ( ) ! = new_report_prop ) {
project_ - > setDefaultReportProperties ( new_report_prop ) ;
modified_project = true ;
}
2014-04-11 09:51:21 +00:00
2014-07-03 08:52:14 +00:00
QHash < QString , XRefProperties > new_xref_properties = xref_ - > properties ( ) ;
if ( project_ - > defaultXRefProperties ( ) ! = new_xref_properties ) {
2014-04-11 09:51:21 +00:00
project_ - > setDefaultXRefProperties ( new_xref_properties ) ;
modified_project = true ;
}
2012-07-07 19:45:32 +00:00
if ( modified_project ) {
project_ - > setModified ( modified_project ) ;
}
2012-06-29 05:21:41 +00:00
}
/**
Initialize widgets displayed by the page .
*/
void ProjectNewDiagramConfigPage : : initWidgets ( ) {
informative_label_ = new QLabel (
tr (
" Propri \351 t \351 s \340 utiliser lors de l'ajout d'un nouveau sch \351 ma au projet : " ,
" explicative label "
)
) ;
2014-04-11 09:51:21 +00:00
border_ = new BorderPropertiesWidget ( BorderProperties ( ) ) ;
2012-06-29 05:21:41 +00:00
titleblock_ = new TitleBlockPropertiesWidget ( TitleBlockProperties ( ) , true ) ;
2014-04-11 09:51:21 +00:00
conductor_ = new ConductorPropertiesWidget ( ) ;
conductor_ - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
report_ = new ReportPropertieWidget ( " _ " ) ;
2014-07-03 08:52:14 +00:00
xref_ = new XRefPropertiesWidget ( ) ;
2012-06-29 05:21:41 +00:00
}
/**
Initialize the layout of this page .
*/
void ProjectNewDiagramConfigPage : : initLayout ( ) {
2014-01-18 19:04:39 +00:00
// main tab widget
QTabWidget * tab_widget = new QTabWidget ( this ) ;
QWidget * diagram_widget = new QWidget ( ) ;
QVBoxLayout * diagram_layout = new QVBoxLayout ( diagram_widget ) ;
diagram_layout - > addWidget ( border_ ) ;
diagram_layout - > addWidget ( titleblock_ ) ;
2014-04-11 09:51:21 +00:00
tab_widget - > addTab ( diagram_widget , tr ( " Sch \351 ma " ) ) ;
tab_widget - > addTab ( conductor_ , tr ( " Conducteur " ) ) ;
tab_widget - > addTab ( report_ , tr ( " Report de folio " ) ) ;
tab_widget - > addTab ( xref_ , tr ( " R \351 f \351 rence crois \351 es " ) ) ;
2014-01-18 19:04:39 +00:00
2012-06-29 05:21:41 +00:00
QVBoxLayout * vlayout1 = new QVBoxLayout ( ) ;
2014-01-18 19:04:39 +00:00
vlayout1 - > addWidget ( tab_widget ) ;
2012-06-29 05:21:41 +00:00
setLayout ( vlayout1 ) ;
}
/**
Read properties from the edited project then fill widgets with them .
*/
void ProjectNewDiagramConfigPage : : readValuesFromProject ( ) {
2014-07-11 16:45:18 +00:00
border_ - > setProperties ( project_ - > defaultBorderProperties ( ) ) ;
2014-07-17 09:20:21 +00:00
conductor_ - > setProperties ( project_ - > defaultConductorProperties ( ) ) ;
2014-07-12 13:14:47 +00:00
titleblock_ - > setProperties ( project_ - > defaultTitleBlockProperties ( ) ) ;
2014-04-11 09:51:21 +00:00
report_ - > setReportProperties ( project_ - > defaultReportProperties ( ) ) ;
2014-07-03 08:52:14 +00:00
xref_ - > setProperties ( project_ - > defaultXRefProperties ( ) ) ;
2012-06-29 05:21:41 +00:00
}
/**
editable if the project is editable .
*/
void ProjectNewDiagramConfigPage : : adjustReadOnly ( ) {
bool is_read_only = project_ - > isReadOnly ( ) ;
2014-04-11 09:51:21 +00:00
border_ - > setReadOnly ( is_read_only ) ;
2012-06-29 05:21:41 +00:00
titleblock_ - > setReadOnly ( is_read_only ) ;
2014-04-11 09:51:21 +00:00
conductor_ - > setReadOnly ( is_read_only ) ;
xref_ - > setReadOnly ( is_read_only ) ;
2012-06-29 05:21:41 +00:00
}