2007-04-04 02:13:14 +00:00
# include "newelementwizard.h"
# include "elementscategorieswidget.h"
2007-04-06 02:47:25 +00:00
# include "elementscategorieslist.h"
2007-04-13 11:50:16 +00:00
# include "nameslistwidget.h"
2007-04-07 02:37:57 +00:00
# include "diagram.h"
2007-04-07 19:25:38 +00:00
# include "element.h"
2007-04-04 02:13:14 +00:00
2007-04-07 19:25:38 +00:00
/**
Constructeur
@ param parent QWidget parent de ce dialogue
@ param f flags pour le dialogue
*/
2007-04-04 02:13:14 +00:00
NewElementWizard : : NewElementWizard ( QWidget * parent , Qt : : WindowFlags f ) : QDialog ( parent , f ) {
2007-04-07 02:37:57 +00:00
setFixedSize ( 480 , 280 ) ;
2007-04-04 02:13:14 +00:00
QVBoxLayout * dialog_layout = new QVBoxLayout ( ) ;
setLayout ( dialog_layout ) ;
2007-04-06 02:47:25 +00:00
// chaines de caracteres utilisees sur les boutons
str_next = QString ( tr ( " Suivant " ) ) ;
str_previous = QString ( tr ( " Pr \351 c \351 dent " ) ) ;
str_finish = QString ( tr ( " Valider " ) ) ;
2007-04-04 02:13:14 +00:00
2007-04-06 02:47:25 +00:00
buildStep1 ( ) ;
buildStep2 ( ) ;
buildStep3 ( ) ;
buildStep4 ( ) ;
buildStep5 ( ) ;
2007-04-04 02:13:14 +00:00
// dialogue itself
setWindowTitle ( tr ( " Cr \351 er un nouvel \351 l \351 ment : Assistant " ) ) ;
2007-04-06 02:47:25 +00:00
dialog_layout - > addWidget ( step1 ) ;
dialog_layout - > addWidget ( step2 ) ;
dialog_layout - > addWidget ( step3 ) ;
dialog_layout - > addWidget ( step4 ) ;
dialog_layout - > addWidget ( step5 ) ;
step2 - > hide ( ) ;
step3 - > hide ( ) ;
step4 - > hide ( ) ;
step5 - > hide ( ) ;
2007-04-04 02:13:14 +00:00
// boutons
QDialogButtonBox * boutons = new QDialogButtonBox ( QDialogButtonBox : : Cancel ) ;
2007-04-06 02:47:25 +00:00
button_previous = new QPushButton ( str_previous , this ) ;
2007-04-04 02:13:14 +00:00
button_previous - > setEnabled ( false ) ;
2007-04-06 02:47:25 +00:00
button_next = new QPushButton ( str_next , this ) ;
2007-04-04 02:13:14 +00:00
boutons - > addButton ( button_previous , QDialogButtonBox : : ActionRole ) ;
boutons - > addButton ( button_next , QDialogButtonBox : : ActionRole ) ;
connect ( button_previous , SIGNAL ( released ( ) ) , this , SLOT ( previous ( ) ) ) ;
connect ( button_next , SIGNAL ( released ( ) ) , this , SLOT ( next ( ) ) ) ;
connect ( boutons , SIGNAL ( rejected ( ) ) , this , SLOT ( accept ( ) ) ) ;
dialog_layout - > addWidget ( boutons ) ;
2007-04-06 02:47:25 +00:00
current_state = Category ;
2007-04-04 02:13:14 +00:00
}
2007-04-07 19:25:38 +00:00
/**
Destructeur
*/
2007-04-04 02:13:14 +00:00
NewElementWizard : : ~ NewElementWizard ( ) {
}
2007-04-07 19:25:38 +00:00
/**
Passe a l ' etape precedente
*/
2007-04-04 02:13:14 +00:00
void NewElementWizard : : previous ( ) {
switch ( current_state ) {
2007-04-05 01:13:14 +00:00
case Category :
2007-04-06 02:47:25 +00:00
return ;
case Filename :
current_state = Category ;
step1 - > show ( ) ;
step2 - > hide ( ) ;
2007-04-04 02:13:14 +00:00
button_previous - > setEnabled ( false ) ;
2007-04-06 02:47:25 +00:00
break ;
case Names :
current_state = Filename ;
step2 - > show ( ) ;
step3 - > hide ( ) ;
break ;
case Dimensions :
current_state = Names ;
step3 - > show ( ) ;
step4 - > hide ( ) ;
button_next - > setText ( str_next ) ;
break ;
case Orientations :
current_state = Dimensions ;
step4 - > show ( ) ;
step5 - > hide ( ) ;
button_next - > setText ( str_next ) ;
2007-04-04 02:13:14 +00:00
}
}
2007-04-07 19:25:38 +00:00
/**
Passe a l ' etape suivante
*/
2007-04-04 02:13:14 +00:00
void NewElementWizard : : next ( ) {
switch ( current_state ) {
2007-04-06 02:47:25 +00:00
case Category :
if ( ! validStep1 ( ) ) return ;
current_state = Filename ;
step1 - > hide ( ) ;
step2 - > show ( ) ;
button_previous - > setEnabled ( true ) ;
break ;
case Filename :
if ( ! validStep2 ( ) ) return ;
current_state = Names ;
step2 - > hide ( ) ;
step3 - > show ( ) ;
break ;
case Names :
if ( ! validStep3 ( ) ) return ;
current_state = Dimensions ;
step3 - > hide ( ) ;
step4 - > show ( ) ;
break ;
2007-04-04 02:13:14 +00:00
case Dimensions :
2007-04-06 02:47:25 +00:00
if ( ! validStep4 ( ) ) return ;
current_state = Orientations ;
step4 - > hide ( ) ;
step5 - > show ( ) ;
button_next - > setText ( str_finish ) ;
2007-04-04 02:13:14 +00:00
button_previous - > setEnabled ( true ) ;
break ;
2007-04-06 02:47:25 +00:00
case Orientations :
if ( ! validStep5 ( ) ) return ;
2007-04-07 19:25:38 +00:00
createNewElement ( ) ;
2007-04-04 02:13:14 +00:00
}
}
2007-04-06 02:47:25 +00:00
/**
Met en place l ' etape 1 : Categorie
*/
void NewElementWizard : : buildStep1 ( ) {
step1 = new QWidget ( this ) ;
QVBoxLayout * step1_layout = new QVBoxLayout ( ) ;
2007-04-07 19:25:38 +00:00
QLabel * explication = new QLabel ( tr ( " \311 tape 1/5 : S \351 lectionnez une cat \351 gorie dans laquelle enregistrer le nouvel \351 l \351 ment. " ) ) ;
explication - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
explication - > setWordWrap ( true ) ;
step1_layout - > addWidget ( explication ) ;
2007-04-06 02:47:25 +00:00
categories_list = new ElementsCategoriesWidget ( ) ;
step1_layout - > addWidget ( categories_list ) ;
step1 - > setLayout ( step1_layout ) ;
}
/**
Met en place l ' etape 2 : Nom du fichier
*/
void NewElementWizard : : buildStep2 ( ) {
step2 = new QWidget ( this ) ;
QVBoxLayout * step2_layout = new QVBoxLayout ( ) ;
2007-04-07 19:25:38 +00:00
QLabel * explication1 = new QLabel ( tr ( " \311 tape 2/5 : Indiquez le nom du fichier dans lequel enregistrer le nouvel \351 l \351 ment. " ) ) ;
explication1 - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
explication1 - > setWordWrap ( true ) ;
QLabel * explication2 = new QLabel ( tr ( " Vous n' \352 tes pas oblig \351 de pr \351 ciser l'extension *.elmt. Elle sera ajout \351 e automatiquement. " ) ) ;
explication2 - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
explication2 - > setWordWrap ( true ) ;
step2_layout - > addWidget ( explication1 ) ;
2007-04-06 02:47:25 +00:00
step2_layout - > addWidget ( qle_filename = new QLineEdit ( ) ) ;
2007-04-07 19:25:38 +00:00
step2_layout - > addWidget ( explication2 ) ;
step2_layout - > addSpacing ( 100 ) ;
2007-04-06 02:47:25 +00:00
step2 - > setLayout ( step2_layout ) ;
}
/**
Met en place l ' etape 3 : Noms de l ' element
*/
void NewElementWizard : : buildStep3 ( ) {
step3 = new QWidget ( this ) ;
QVBoxLayout * step3_layout = new QVBoxLayout ( ) ;
2007-04-07 19:25:38 +00:00
QLabel * explication = new QLabel ( tr ( " \311 tape 3/5 : Indiquez le ou les noms de l' \351 l \351 ment. " ) ) ;
explication - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
explication - > setWordWrap ( true ) ;
step3_layout - > addWidget ( explication ) ;
2007-04-13 11:50:16 +00:00
element_names = new NamesListWidget ( ) ;
2007-04-13 15:48:00 +00:00
NamesList hash_name ;
hash_name . addName ( QLocale : : system ( ) . name ( ) . left ( 2 ) , tr ( " Nom du nouvel \351 l \351 ment " ) ) ;
2007-04-07 02:37:57 +00:00
element_names - > setNames ( hash_name ) ;
step3_layout - > addWidget ( element_names ) ;
2007-04-06 02:47:25 +00:00
step3 - > setLayout ( step3_layout ) ;
}
/**
Met en place l ' etape 4 : Dimensions et Hotspot
*/
void NewElementWizard : : buildStep4 ( ) {
step4 = new QWidget ( this ) ;
2007-04-07 02:37:57 +00:00
sb_width = new QSpinBox ( ) ;
sb_width - > setMinimum ( 1 ) ;
sb_width - > setValue ( 3 ) ;
sb_width - > setSuffix ( tr ( " \327 10 px " ) ) ;
sb_height = new QSpinBox ( ) ;
sb_height - > setMinimum ( 1 ) ;
sb_height - > setValue ( 7 ) ;
sb_height - > setSuffix ( tr ( " \327 10 px " ) ) ;
sb_hotspot_x = new QSpinBox ( ) ;
sb_hotspot_x - > setValue ( 15 ) ;
sb_hotspot_x - > setSuffix ( tr ( " px " ) ) ;
2007-04-15 19:14:19 +00:00
sb_hotspot_x - > setSingleStep ( 10 ) ;
2007-04-07 02:37:57 +00:00
sb_hotspot_y = new QSpinBox ( ) ;
sb_hotspot_y - > setValue ( 35 ) ;
sb_hotspot_y - > setSuffix ( tr ( " px " ) ) ;
2007-04-15 19:14:19 +00:00
sb_hotspot_y - > setSingleStep ( 10 ) ;
2007-04-07 02:37:57 +00:00
diagram_scene = new Diagram ( ) ;
diagram_scene - > border_and_inset . setNbColumns ( 4 ) ;
diagram_scene - > border_and_inset . setColumnsHeight ( 140 ) ;
diagram_scene - > border_and_inset . displayInset ( false ) ;
diagram_view = new QGraphicsView ( diagram_scene ) ;
diagram_view - > setMaximumSize (
static_cast < int > ( ( 5 * diagram_scene - > border_and_inset . columnsWidth ( ) ) + ( 3 * MARGIN ) ) ,
300
) ;
diagram_view - > setTransformationAnchor ( QGraphicsView : : AnchorUnderMouse ) ;
diagram_view - > setResizeAnchor ( QGraphicsView : : AnchorUnderMouse ) ;
diagram_view - > setAlignment ( Qt : : AlignLeft | Qt : : AlignTop ) ;
connect ( sb_width , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateHotspotLimits ( ) ) ) ;
connect ( sb_height , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateHotspotLimits ( ) ) ) ;
connect ( sb_width , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateScene ( ) ) ) ;
connect ( sb_height , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateScene ( ) ) ) ;
connect ( sb_hotspot_x , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateScene ( ) ) ) ;
connect ( sb_hotspot_y , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateScene ( ) ) ) ;
2007-04-06 02:47:25 +00:00
2007-04-07 19:25:38 +00:00
QLabel * explication = new QLabel ( tr ( " \311 tape 4/5 : Saisissez les dimensions du nouvel \351 l \351 ment ainsi que la position du hotspot (point de saisie de l' \351 l \351 ment \340 la souris) en consid \351 rant que l' \351 l \351 ment est dans son orientation par d \351 faut. " ) ) ;
explication - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
explication - > setWordWrap ( true ) ;
2007-04-06 02:47:25 +00:00
QGridLayout * grid_layout = new QGridLayout ( ) ;
2007-04-07 02:37:57 +00:00
grid_layout - > addWidget ( new QLabel ( tr ( " <span style= \" text-decoration:underline; \" >Dimensions</span> " ) ) , 0 , 0 ) ;
grid_layout - > addWidget ( new QLabel ( tr ( " Largeur : " ) ) , 1 , 0 ) ;
grid_layout - > addWidget ( sb_width , 1 , 1 ) ;
grid_layout - > addWidget ( new QLabel ( tr ( " Hauteur : " ) ) , 2 , 0 ) ;
grid_layout - > addWidget ( sb_height , 2 , 1 ) ;
grid_layout - > addWidget ( new QLabel ( tr ( " <span style= \" text-decoration:underline; \" >Hotspot</span> " ) ) , 3 , 0 ) ;
grid_layout - > addWidget ( new QLabel ( tr ( " Abscisse : " ) ) , 4 , 0 ) ;
grid_layout - > addWidget ( sb_hotspot_x , 4 , 1 ) ;
grid_layout - > addWidget ( new QLabel ( tr ( " Ordonn \351 e : " ) ) , 5 , 0 ) ;
grid_layout - > addWidget ( sb_hotspot_y , 5 , 1 ) ;
QHBoxLayout * step4_hlayout = new QHBoxLayout ( ) ;
step4_hlayout - > addLayout ( grid_layout ) ;
step4_hlayout - > addWidget ( diagram_view ) ;
2007-04-06 02:47:25 +00:00
QVBoxLayout * step4_layout = new QVBoxLayout ( ) ;
2007-04-07 19:25:38 +00:00
step4_layout - > addWidget ( explication ) ;
2007-04-07 02:37:57 +00:00
step4_layout - > addLayout ( step4_hlayout ) ;
2007-04-06 02:47:25 +00:00
step4 - > setLayout ( step4_layout ) ;
2007-04-07 02:37:57 +00:00
updateScene ( ) ;
updateHotspotLimits ( ) ;
2007-04-06 02:47:25 +00:00
}
/**
Met en place l ' etape 5 : orientations possibles pour le nouvel element
*/
void NewElementWizard : : buildStep5 ( ) {
step5 = new QWidget ( this ) ;
2007-04-07 19:25:38 +00:00
QLabel * explication = new QLabel ( tr ( " \311 tape 5/5 : Indiquez les orientations possibles pour le nouvel \351 l \351 ment. " ) ) ;
explication - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
explication - > setWordWrap ( true ) ;
# define MK_COMBO_BOX(a) a##_orientation = new QComboBox(); \
a # # _orientation - > addItem ( tr ( " Par d \351 faut " ) , " d " ) ; \
a # # _orientation - > addItem ( tr ( " Possible " ) , " y " ) ; \
a # # _orientation - > addItem ( tr ( " Impossible " ) , " n " ) ;
// 4 combo box
MK_COMBO_BOX ( north )
MK_COMBO_BOX ( east )
MK_COMBO_BOX ( south )
MK_COMBO_BOX ( west )
# undef MK_COMBO_BOX
east_orientation - > setCurrentIndex ( 1 ) ;
south_orientation - > setCurrentIndex ( 1 ) ;
west_orientation - > setCurrentIndex ( 1 ) ;
QGridLayout * qgl = new QGridLayout ( ) ;
qgl - > addWidget ( new QLabel ( tr ( " Nord : " ) ) , 0 , 0 ) ;
qgl - > addWidget ( north_orientation , 0 , 1 ) ;
qgl - > addWidget ( new QLabel ( tr ( " Est : " ) ) , 1 , 0 ) ;
qgl - > addWidget ( east_orientation , 1 , 1 ) ;
qgl - > addWidget ( new QLabel ( tr ( " Sud : " ) ) , 2 , 0 ) ;
qgl - > addWidget ( south_orientation , 2 , 1 ) ;
qgl - > addWidget ( new QLabel ( tr ( " Ouest : " ) ) , 3 , 0 ) ;
qgl - > addWidget ( west_orientation , 3 , 1 ) ;
2007-04-06 02:47:25 +00:00
QVBoxLayout * step5_layout = new QVBoxLayout ( ) ;
2007-04-07 19:25:38 +00:00
step5_layout - > addWidget ( explication ) ;
step5_layout - > addLayout ( qgl ) ;
step5_layout - > addSpacing ( 75 ) ;
2007-04-06 02:47:25 +00:00
step5 - > setLayout ( step5_layout ) ;
}
2007-04-07 19:25:38 +00:00
/**
Valide l ' etape 1
@ return true si l ' etape est validee , false sinon
*/
2007-04-06 02:47:25 +00:00
bool NewElementWizard : : validStep1 ( ) {
// il doit y avoir une categorie selectionnee
bool step1_ok = categories_list - > elementsCategoriesList ( ) . selectedCategoryPath ( ) ! = QString ( ) ;
if ( ! step1_ok ) {
QMessageBox : : critical (
this ,
tr ( " Erreur " ) ,
tr ( " Vous devez s \351 lectionner une cat \351 gorie. " )
) ;
}
return ( step1_ok ) ;
}
2007-04-07 19:25:38 +00:00
/**
Valide l ' etape 2
@ return true si l ' etape est validee , false sinon
*/
2007-04-06 02:47:25 +00:00
bool NewElementWizard : : validStep2 ( ) {
QString dir_path = categories_list - > elementsCategoriesList ( ) . selectedCategoryPath ( ) ;
QString file_name = qle_filename - > text ( ) ;
// un nom doit avoir ete entre
if ( file_name = = QString ( ) ) {
QMessageBox : : critical (
this ,
tr ( " Erreur " ) ,
tr ( " Vous devez entrer un nom de fichier " )
) ;
return ( false ) ;
}
2007-04-07 02:37:57 +00:00
if ( ! file_name . endsWith ( " .elmt " ) ) file_name + = " .elmt " ;
2007-04-06 02:47:25 +00:00
// le fichier existe peut etre deja
if ( QFileInfo ( dir_path + " / " + file_name ) . exists ( ) ) {
QMessageBox : : StandardButton answer = QMessageBox : : question (
this ,
" \311 craser le fichier ? " ,
" Le fichier existe d \351 j \340 . Souhaitez-vous l' \351 craser ? " ,
QMessageBox : : Yes | QMessageBox : : No | QMessageBox : : Cancel ,
QMessageBox : : No
) ;
return ( answer = = QMessageBox : : Yes ) ;
2007-04-04 02:13:14 +00:00
}
2007-04-06 02:47:25 +00:00
return ( true ) ;
2007-04-04 02:13:14 +00:00
}
2007-04-06 02:47:25 +00:00
2007-04-07 19:25:38 +00:00
/**
Valide l ' etape 3
@ return true si l ' etape est validee , false sinon
*/
2007-04-06 02:47:25 +00:00
bool NewElementWizard : : validStep3 ( ) {
2007-04-07 19:25:38 +00:00
// il doit y avoir au moins un nom
2007-04-07 02:37:57 +00:00
return ( element_names - > checkOneName ( ) ) ;
2007-04-06 02:47:25 +00:00
}
2007-04-07 19:25:38 +00:00
/**
Valide l ' etape 4
@ return true si l ' etape est validee , false sinon
*/
2007-04-06 02:47:25 +00:00
bool NewElementWizard : : validStep4 ( ) {
2007-04-07 19:25:38 +00:00
// les contraintes imposees par les widgets sont suffisantes
2007-04-06 02:47:25 +00:00
return ( true ) ;
}
2007-04-07 19:25:38 +00:00
/**
Valide l ' etape 5
Cette fonction s ' assure qu ' il y ait toujours exactement une orientation
" par defaut "
@ return true si l ' etape est validee , false sinon
*/
2007-04-06 02:47:25 +00:00
bool NewElementWizard : : validStep5 ( ) {
2007-04-07 19:25:38 +00:00
int nb_orientations = 0 ;
if ( ! north_orientation - > currentIndex ( ) ) + + nb_orientations ;
if ( ! east_orientation - > currentIndex ( ) ) + + nb_orientations ;
if ( ! south_orientation - > currentIndex ( ) ) + + nb_orientations ;
if ( ! west_orientation - > currentIndex ( ) ) + + nb_orientations ;
if ( nb_orientations ! = 1 ) {
QMessageBox : : critical (
this ,
tr ( " Erreur " ) ,
tr ( " Il doit y avoir exactement une orientation par d \351 faut. " )
) ;
return ( false ) ;
}
2007-04-06 02:47:25 +00:00
return ( true ) ;
}
2007-04-07 19:25:38 +00:00
/**
Met a jour le schema de l ' etape 4
*/
2007-04-07 02:37:57 +00:00
void NewElementWizard : : updateScene ( ) {
foreach ( QGraphicsItem * qgi , diagram_scene - > items ( ) ) {
diagram_scene - > removeItem ( qgi ) ;
delete qgi ;
}
int elmt_width = sb_width - > value ( ) * 10 ;
int elmt_height = sb_height - > value ( ) * 10 ;
int hotspot_x = sb_hotspot_x - > value ( ) ;
int hotspot_y = sb_hotspot_y - > value ( ) ;
int margin_x = 10 ;
int margin_y = 30 ;
2007-04-15 19:14:19 +00:00
diagram_scene - > addRect ( QRectF ( margin_x , margin_y , elmt_width , elmt_height ) ) ;
2007-04-07 02:37:57 +00:00
QPen hotspot_pen ( Qt : : red ) ;
QGraphicsLineItem * line_hotspot_x = diagram_scene - > addLine (
QLine (
margin_x ,
margin_y + hotspot_y ,
margin_x + elmt_width ,
margin_y + hotspot_y
) ,
hotspot_pen
) ;
QGraphicsLineItem * line_hotspot_y = diagram_scene - > addLine (
QLine (
margin_x + hotspot_x ,
margin_y ,
margin_x + hotspot_x ,
margin_y + elmt_height
) ,
hotspot_pen
) ;
line_hotspot_x - > setZValue ( 10 ) ;
line_hotspot_y - > setZValue ( 10 ) ;
2007-04-15 19:14:19 +00:00
diagram_scene - > setSceneRect ( QRect ( 0 , 0 , elmt_width + ( 2 * margin_x ) + 15 , elmt_height + ( 2 * margin_y ) ) ) ;
diagram_scene - > update ( ) ;
2007-04-07 02:37:57 +00:00
}
2007-04-07 19:25:38 +00:00
/**
Met a jour les limites des QSpinBox de l ' etape 4
*/
2007-04-07 02:37:57 +00:00
void NewElementWizard : : updateHotspotLimits ( ) {
sb_hotspot_x - > setMaximum ( sb_width - > value ( ) * 10 ) ;
sb_hotspot_y - > setMaximum ( sb_height - > value ( ) * 10 ) ;
}
2007-04-07 19:25:38 +00:00
/**
Cree le nouvel element
*/
void NewElementWizard : : createNewElement ( ) {
/// @todo
QMessageBox : : warning ( this , " Creation de l'element " , " Not Implemented Yet " ) ;
}