diff --git a/editor/customelementeditor.cpp b/editor/customelementeditor.cpp index 04c59ed0c..f1da3ca18 100644 --- a/editor/customelementeditor.cpp +++ b/editor/customelementeditor.cpp @@ -34,8 +34,7 @@ void CustomElementEditor::setupActions() { deselectall = new QAction( tr("D\351s\351lectionner tout"), this); inv_select = new QAction( tr("Inverser la s\351lection"), this); edit_delete = new QAction(QIcon(":/ico/delete.png"), tr("&Supprimer"), this); - edit_size = new QAction( tr("Modifier la taille"), this); - edit_hotspot = new QAction( tr("Modifier le point de saisie"), this); + edit_size_hs = new QAction( tr("\311diter la taille et le point de saisie"), this); edit_names = new QAction( tr("\311diter les noms"), this); edit_ori = new QAction(QIcon(":/ico/orientations.png"), tr("\311diter les orientations"), this); move = new QAction(QIcon(":/ico/select.png"), tr("D\351placer un objet"), this); @@ -48,10 +47,6 @@ void CustomElementEditor::setupActions() { add_terminal = new QAction(QIcon(":/ico/terminal.png"), tr("Ajouter une borne"), this); add_textfield = new QAction(QIcon(":/ico/textfield.png"), tr("Ajouter un champ de texte"), this); - edit_delete -> setEnabled(false); - edit_size -> setEnabled(false); - edit_hotspot -> setEnabled(false); - selectall -> setShortcut(QKeySequence::SelectAll); deselectall -> setShortcut(QKeySequence(tr("Ctrl+Shift+A"))); inv_select -> setShortcut(QKeySequence(tr("Ctrl+I"))); @@ -66,8 +61,7 @@ void CustomElementEditor::setupActions() { connect(deselectall, SIGNAL(triggered()), ce_scene, SLOT(slot_deselectAll())); connect(inv_select, SIGNAL(triggered()), ce_scene, SLOT(slot_invertSelection())); connect(edit_delete, SIGNAL(triggered()), ce_scene, SLOT(slot_delete())); - connect(edit_size, SIGNAL(triggered()), ce_scene, SLOT(slot_editSize())); - connect(edit_hotspot, SIGNAL(triggered()), ce_scene, SLOT(slot_editHotSpot())); + connect(edit_size_hs, SIGNAL(triggered()), ce_scene, SLOT(slot_editSizeHotSpot())); connect(edit_names, SIGNAL(triggered()), ce_scene, SLOT(slot_editNames())); connect(edit_ori, SIGNAL(triggered()), ce_scene, SLOT(slot_editOrientations())); connect(move, SIGNAL(triggered()), ce_scene, SLOT(slot_move())); @@ -156,8 +150,7 @@ void CustomElementEditor::setupMenus() { edit_menu -> addAction(edit_delete); edit_menu -> addSeparator(); edit_menu -> addAction(edit_names); - edit_menu -> addAction(edit_size); - edit_menu -> addAction(edit_hotspot); + edit_menu -> addAction(edit_size_hs); edit_menu -> addAction(edit_ori); menuBar() -> addMenu(file_menu); @@ -341,8 +334,7 @@ void CustomElementEditor::setReadOnly(bool ro) { ce_view -> setInteractive(!ro); // active / desactive l'edition de la taille, du hotspot, des noms et des orientations - edit_size -> setEnabled(!ro); - edit_hotspot -> setEnabled(!ro); + edit_size_hs -> setEnabled(!ro); edit_names -> setEnabled(!ro); edit_ori -> setEnabled(!ro); } diff --git a/editor/customelementeditor.h b/editor/customelementeditor.h index 30d871dd2..d05fed012 100644 --- a/editor/customelementeditor.h +++ b/editor/customelementeditor.h @@ -29,7 +29,7 @@ class CustomElementEditor : public QMainWindow { QAction *new_element, *open, *save, *save_as, *quit; /// actions du menu edition QAction *selectall, *deselectall, *inv_select; - QAction *edit_delete, *edit_size, *edit_hotspot, *edit_names, *edit_ori; + QAction *edit_delete, *edit_size_hs, *edit_names, *edit_ori; /// barre d'outils QToolBar *parts_toolbar; /// actions de la barre d'outils diff --git a/editor/editorscene.cpp b/editor/editorscene.cpp index 54053c91c..905c78657 100644 --- a/editor/editorscene.cpp +++ b/editor/editorscene.cpp @@ -8,6 +8,7 @@ #include "parttext.h" #include "parttextfield.h" #include "partarc.h" +#include "hotspoteditor.h" #define GRILLE_X 10 #define GRILLE_Y 10 @@ -397,12 +398,42 @@ void EditorScene::slot_delete() { } } -void EditorScene::slot_editSize() { - -} - -void EditorScene::slot_editHotSpot() { - +void EditorScene::slot_editSizeHotSpot() { + // cree un dialogue + QDialog dialog_sh; + dialog_sh.setModal(true); + dialog_sh.setMinimumSize(400, 230); + dialog_sh.setWindowTitle(tr("\311diter la taille et le point de saisie")); + QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_sh); + + // ajoute un HotspotEditor au dialogue + HotspotEditor *hotspot_editor = new HotspotEditor(); + hotspot_editor -> setElementWidth(static_cast(width() / 10)); + hotspot_editor -> setElementHeight(static_cast(height() / 10)); + hotspot_editor -> setHotspot(hotspot()); + hotspot_editor -> setOldHotspot(hotspot()); + hotspot_editor -> setPartsRect(itemsBoundingRect()); + hotspot_editor -> setPartsRectEnabled(true); + dialog_layout -> addWidget(hotspot_editor); + + // ajoute deux boutons au dialogue + QDialogButtonBox *dialog_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + dialog_layout -> addWidget(dialog_buttons); + connect(dialog_buttons, SIGNAL(accepted()), &dialog_sh, SLOT(accept())); + connect(dialog_buttons, SIGNAL(rejected()), &dialog_sh, SLOT(reject())); + + // lance le dialogue + if (dialog_sh.exec() == QDialog::Accepted) { + setWidth(hotspot_editor -> elementWidth()); + setHeight(hotspot_editor -> elementHeight()); + setHotspot(hotspot_editor -> hotspot()); + if (hotspot_editor -> mustTranslateParts()) { + QPoint translation = hotspot_editor -> offsetParts(); + foreach(QGraphicsItem *qgi, items()) { + qgi -> translate(translation.x(), translation.y()); + } + } + } } void EditorScene::slot_editOrientations() { diff --git a/editor/editorscene.h b/editor/editorscene.h index 2a20db8fb..49b85fc29 100644 --- a/editor/editorscene.h +++ b/editor/editorscene.h @@ -81,8 +81,7 @@ class EditorScene : public QGraphicsScene { void slot_deselectAll(); void slot_invertSelection(); void slot_delete(); - void slot_editSize(); - void slot_editHotSpot(); + void slot_editSizeHotSpot(); void slot_editNames(); void slot_editOrientations(); diff --git a/editor/partterminal.cpp b/editor/partterminal.cpp index 4a547b9a7..507d089f1 100644 --- a/editor/partterminal.cpp +++ b/editor/partterminal.cpp @@ -34,8 +34,8 @@ const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("terminal"); // ecrit la position de la borne - xml_element.setAttribute("x", QString("%1").arg(pos().x())); - xml_element.setAttribute("y", QString("%1").arg(pos().y())); + xml_element.setAttribute("x", QString("%1").arg(scenePos().x())); + xml_element.setAttribute("y", QString("%1").arg(scenePos().y())); // ecrit l'orientation de la borne xml_element.setAttribute("orientation", orientationToString(_orientation)); diff --git a/editor/parttext.cpp b/editor/parttext.cpp index a49e8fb3f..e5641fc86 100644 --- a/editor/parttext.cpp +++ b/editor/parttext.cpp @@ -27,8 +27,8 @@ void PartText::fromXml(const QDomElement &xml_element) { const QDomElement PartText::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("text"); - xml_element.setAttribute("x", QString("%1").arg(pos().x())); - xml_element.setAttribute("y", QString("%1").arg(pos().y())); + xml_element.setAttribute("x", QString("%1").arg((scenePos() + margin()).x())); + xml_element.setAttribute("y", QString("%1").arg((scenePos() + margin()).y())); xml_element.setAttribute("text", toPlainText()); xml_element.setAttribute("size", font().pointSize()); return(xml_element); diff --git a/editor/parttextfield.cpp b/editor/parttextfield.cpp index 8e9a88842..3cb9b0ab9 100644 --- a/editor/parttextfield.cpp +++ b/editor/parttextfield.cpp @@ -30,8 +30,8 @@ void PartTextField::fromXml(const QDomElement &xml_element) { const QDomElement PartTextField::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("input"); - xml_element.setAttribute("x", QString("%1").arg(pos().x())); - xml_element.setAttribute("y", QString("%1").arg(pos().y())); + xml_element.setAttribute("x", QString("%1").arg((scenePos() + margin()).x())); + xml_element.setAttribute("y", QString("%1").arg((scenePos() + margin()).y())); xml_element.setAttribute("text", toPlainText()); xml_element.setAttribute("size", font().pointSize()); if (follow_parent_rotations) xml_element.setAttribute("rotate", "false"); diff --git a/hotspoteditor.cpp b/hotspoteditor.cpp new file mode 100644 index 000000000..65177d8de --- /dev/null +++ b/hotspoteditor.cpp @@ -0,0 +1,276 @@ +#include "hotspoteditor.h" + +/** + Constructeur + @param parent QWidget parent de cet editeur de hotspot +*/ +HotspotEditor::HotspotEditor(QWidget *parent) : + QWidget(parent), + parts_rect_enabled(false) +{ + sb_width = new QSpinBox(); + sb_width -> setMinimum(1); + sb_width -> setValue(3); + sb_width -> setSuffix(tr(" \32710 px")); + sb_height = new QSpinBox(); + sb_height -> setMinimum(1); + sb_height -> setValue(7); + sb_height -> setSuffix(tr(" \32710 px")); + + sb_hotspot_x = new QSpinBox(); + sb_hotspot_x -> setValue(15); + sb_hotspot_x -> setSuffix(tr(" px")); + sb_hotspot_x -> setSingleStep(10); + sb_hotspot_y = new QSpinBox(); + sb_hotspot_y -> setValue(35); + sb_hotspot_y -> setSuffix(tr(" px")); + sb_hotspot_y -> setSingleStep(10); + + 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((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); + + hotspot_sync = new QCheckBox(tr("D\351placer l'\351l\351ment avec le hotspot")); + hotspot_sync -> setChecked(true); + + 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())); + connect(hotspot_sync, SIGNAL(stateChanged(int)), this, SLOT(updateScene())); + + QGridLayout *grid_layout = new QGridLayout(); + grid_layout -> addWidget(new QLabel(tr("Dimensions")), 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("Hotspot")), 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\351e :")), 5, 0); + grid_layout -> addWidget(sb_hotspot_y, 5, 1); + grid_layout -> setSpacing(3); + + QHBoxLayout *hlayout = new QHBoxLayout(); + hlayout -> addLayout(grid_layout); + hlayout -> addWidget(diagram_view); + + vlayout = new QVBoxLayout(this); + vlayout -> setSpacing(0); + vlayout -> addLayout(hlayout); + + updateScene(); + updateHotspotLimits(); +} + +/// @param w Nouvelle largeur de l'element, en dizaines de pixels +void HotspotEditor::setElementWidth(uint w) { + sb_width -> setValue(w); +} + +/// @param h Nouvelle hauteur de l'element, en dizaines de pixels +void HotspotEditor::setElementHeight(uint h) { + sb_height -> setValue(h); +} + +/// @return la Largeur de l'element en dizaines de pixels +uint HotspotEditor::elementWidth10px() const { + return(sb_width -> value()); +} + +/// @return la hauteur de l'element en dizaines de pixels +uint HotspotEditor::elementHeight10px() const { + return(sb_height -> value()); +} + +/// @return la Largeur de l'element en dizaines de pixels +uint HotspotEditor::elementWidth() const { + return(sb_width -> value() * 10); +} + +/// @return la hauteur de l'element en dizaines de pixels +uint HotspotEditor::elementHeight() const { + return(sb_height -> value() * 10); +} + +/// @param size La nouvelle taille de l'element, en dizaines de pixels +void HotspotEditor::setElementSize(const QSize &size) { + setElementWidth(size.width()); + setElementWidth(size.height()); +} + +/// @return la taille de l'element, en dizaines de pixels +QSize HotspotEditor::elementSize10px() const { + return(QSize(elementWidth10px(), elementHeight10px())); +} + +/// @return la taille de l'element, en dizaines de pixels +QSize HotspotEditor::elementSize() const { + return(QSize(elementWidth(), elementHeight())); +} + +/// @param hs Nouvelle position du hotspot +void HotspotEditor::setHotspot(const QPoint &hs) { + sb_hotspot_x -> setValue(hs.x()); + sb_hotspot_y -> setValue(hs.y()); +} + +/// @return les coordonnees du hotspot de l'element +QPoint HotspotEditor::hotspot() const { + return(QPoint(sb_hotspot_x -> value(), sb_hotspot_y -> value())); +} + +/// @param o_h l'ancien hotspot en cas d'edition du hotspot +void HotspotEditor::setOldHotspot(const QPoint &o_h) { + old_hotspot = o_h; +} + +/// @return l'ancien hotspot en cas d'edition du hotspot +QPoint HotspotEditor::oldHotspot() const { + return(old_hotspot); +} + +/** + Specifie le rectangle delimitant les parties de l'element + @param rect rectangle delimitant les parties de l'element +*/ +void HotspotEditor::setPartsRect(const QRectF &rect) { + parts_rect = rect; +} + +/// @return le rectangle delimitant les parties de l'element +QRectF HotspotEditor::partsRect() const { + return(parts_rect); +} + +/** + @param a true pour activer l'affichage du rectangle representant l'element, + false pour le desactiver +*/ +void HotspotEditor::setPartsRectEnabled(bool a) { + if (a != parts_rect_enabled) { + if (a) vlayout -> addWidget(hotspot_sync); + else vlayout -> removeWidget(hotspot_sync); + } + parts_rect_enabled = a; + updateScene(); +} + +/** + @return true si l'affichage du rectangle representant l'element est active, + false sinon +*/ +bool HotspotEditor::partsRectEnabled() { + return(parts_rect_enabled); +} + +/// @return true s'il sera necessaire d'appliquer une translation aux parties de l'elements +bool HotspotEditor::mustTranslateParts() const { + // il sera necessaire d'appliquer une translation aux parties de l'elements + // si le hotspot a ete change et si l'element ne suit pas le hotspot + bool hotspot_change = !old_hotspot.isNull() && old_hotspot != hotspot(); + return(hotspot_change && !hotspot_sync -> isChecked()); +} + +/// @return La translation a faire subir aux parties de l'element apres l'edition du hotspot +QPoint HotspotEditor::offsetParts() const { + // si le hotspot n'a pas ete change ou si l'element doit suivre le hotspot, + // il n'est pas necessaire d'appliquer une translation aux parties de + // l'elements + if (!mustTranslateParts()) return(QPoint(0,0)); + else return(old_hotspot - hotspot()); +} + +/** + Met a jour le schema +*/ +void HotspotEditor::updateScene() { + // nettoie la scene + 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; + + // dessin du cadre representant les dimensions de l'element + diagram_scene -> addRect(QRectF(margin_x, margin_y, elmt_width, elmt_height)); + + // dessin des deux segments representant le point de saisie de l'element + 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); + + // dessin eventuel du rectangle representant l'element + if (parts_rect_enabled) { + QPen element_pen(Qt::blue); + QRectF parts_rect_to_draw; + + + + if (!hotspot_sync -> isChecked() && !old_hotspot.isNull()) { + // coordonnees de l'ancien hotspot sur le schema + QPointF current_old_hotspotf(margin_x + old_hotspot.x(), margin_y + old_hotspot.y()); + QPoint current_old_hotspot(current_old_hotspotf.toPoint()); + + // laisse l'element en place par rapport au coin superieur gauche + parts_rect_to_draw = parts_rect.translated(current_old_hotspot); + } else { + // coordonnees du nouveau hotspot sur le schema + QPointF current_hotspotf(line_hotspot_y -> line().x1(), line_hotspot_x -> line().y1()); + QPoint current_hotspot(current_hotspotf.toPoint()); + + // deplace l'element en meme temps que le hotspot + parts_rect_to_draw = parts_rect.translated(current_hotspot); + } + QGraphicsRectItem *rect_element = diagram_scene -> addRect(parts_rect_to_draw, element_pen); + rect_element -> setZValue(5); + } + + diagram_scene -> setSceneRect(QRect(0, 0, elmt_width + (2 * margin_x) + 15, elmt_height + (2 * margin_y))); + diagram_scene -> update(); +} + +/** + Met a jour les limites des QSpinBox +*/ +void HotspotEditor::updateHotspotLimits() { + sb_hotspot_x -> setMaximum(sb_width -> value() * 10); + sb_hotspot_y -> setMaximum(sb_height -> value() * 10); +} diff --git a/hotspoteditor.h b/hotspoteditor.h new file mode 100644 index 000000000..a416ead95 --- /dev/null +++ b/hotspoteditor.h @@ -0,0 +1,56 @@ +#ifndef HOTSPOT_EDITOR_H +#define HOTSPOT_EDITOR_H +#include +#include "diagram.h" +class HotspotEditor : public QWidget { + Q_OBJECT + + // constructeurs, destructeur + public: + HotspotEditor(QWidget * = 0); + virtual ~HotspotEditor() {}; + + private: + HotspotEditor(const HotspotEditor &); + + // attributs + private: + QSpinBox *sb_width; + QSpinBox *sb_height; + QSpinBox *sb_hotspot_x; + QSpinBox *sb_hotspot_y; + QCheckBox *hotspot_sync; + Diagram *diagram_scene; + QGraphicsView *diagram_view; + QRectF parts_rect; + QPoint old_hotspot; + bool parts_rect_enabled; + QVBoxLayout *vlayout; + + // methodes + public: + void setElementWidth(uint); + void setElementHeight(uint); + uint elementWidth10px() const; + uint elementWidth() const; + uint elementHeight10px() const; + uint elementHeight() const; + void setElementSize(const QSize &); + QSize elementSize10px() const; + QSize elementSize() const; + void setHotspot(const QPoint &); + QPoint hotspot() const; + void setOldHotspot(const QPoint &); + QPoint oldHotspot() const; + void setPartsRect(const QRectF &); + QRectF partsRect() const; + void setPartsRectEnabled(bool); + bool partsRectEnabled(); + bool mustTranslateParts() const; + QPoint offsetParts() const; + + public slots: + void updateScene(); + void updateHotspotLimits(); +}; +#endif diff --git a/newelementwizard.cpp b/newelementwizard.cpp index 33c8044cd..d72ffecc4 100644 --- a/newelementwizard.cpp +++ b/newelementwizard.cpp @@ -3,7 +3,7 @@ #include "elementscategorieslist.h" #include "nameslistwidget.h" #include "orientationsetwidget.h" -#include "diagram.h" +#include "hotspoteditor.h" #include "element.h" #include "customelementeditor.h" @@ -193,73 +193,14 @@ void NewElementWizard::buildStep3() { */ void NewElementWizard::buildStep4() { step4 = new QWidget(this); - sb_width = new QSpinBox(); - sb_width -> setMinimum(1); - sb_width -> setValue(3); - sb_width -> setSuffix(tr(" \32710 px")); - sb_height = new QSpinBox(); - sb_height -> setMinimum(1); - sb_height -> setValue(7); - sb_height -> setSuffix(tr(" \32710 px")); - - sb_hotspot_x = new QSpinBox(); - sb_hotspot_x -> setValue(15); - sb_hotspot_x -> setSuffix(tr(" px")); - sb_hotspot_x -> setSingleStep(10); - sb_hotspot_y = new QSpinBox(); - sb_hotspot_y -> setValue(35); - sb_hotspot_y -> setSuffix(tr(" px")); - sb_hotspot_y -> setSingleStep(10); - - 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((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())); - + QVBoxLayout *step4_layout = new QVBoxLayout(step4); QLabel *explication = new QLabel(tr("\311tape 4/5 : Saisissez les dimensions du nouvel \351l\351ment ainsi que la position du hotspot (point de saisie de l'\351l\351ment \340 la souris) en consid\351rant que l'\351l\351ment est dans son orientation par d\351faut.")); explication -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter); explication -> setWordWrap(true); - - QGridLayout *grid_layout = new QGridLayout(); - grid_layout -> addWidget(new QLabel(tr("Dimensions")), 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("Hotspot")), 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\351e :")), 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); - - - QVBoxLayout *step4_layout = new QVBoxLayout(); step4_layout -> addWidget(explication); - step4_layout -> addLayout(step4_hlayout); - step4 -> setLayout(step4_layout); - - updateScene(); - updateHotspotLimits(); + hotspot_editor = new HotspotEditor(); + step4_layout -> addWidget(hotspot_editor, 0); + step4_layout -> setSpacing(0); } /** @@ -348,7 +289,7 @@ bool NewElementWizard::validStep3() { @return true si l'etape est validee, false sinon */ bool NewElementWizard::validStep4() { - // les contraintes imposees par les widgets sont suffisantes + // l'editeur de hotspot se charge deja de valider tout ca return(true); } @@ -363,61 +304,13 @@ bool NewElementWizard::validStep5() { return(true); } -/** - Met a jour le schema de l'etape 4 -*/ -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; - diagram_scene -> addRect(QRectF(margin_x, margin_y, elmt_width, elmt_height)); - 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); - diagram_scene -> setSceneRect(QRect(0, 0, elmt_width + (2 * margin_x) + 15, elmt_height + (2 * margin_y))); - diagram_scene -> update(); -} - -/** - Met a jour les limites des QSpinBox de l'etape 4 -*/ -void NewElementWizard::updateHotspotLimits() { - sb_hotspot_x -> setMaximum(sb_width -> value() * 10); - sb_hotspot_y -> setMaximum(sb_height -> value() * 10); -} - /** Cree le nouvel element */ void NewElementWizard::createNewElement() { CustomElementEditor *edit_new_element = new CustomElementEditor(parentWidget()); - edit_new_element -> setSize(QSize(sb_width -> value() * 10, sb_height -> value() * 10)); - edit_new_element -> setHotspot(QPoint(sb_hotspot_x -> value(), sb_hotspot_y -> value())); + edit_new_element -> setSize(hotspot_editor -> elementSize()); + edit_new_element -> setHotspot(hotspot_editor -> hotspot()); edit_new_element -> setNames(element_names -> names()); edit_new_element -> setOrientations(orientation_set -> orientationSet()); edit_new_element -> setFileName(chosen_file); diff --git a/newelementwizard.h b/newelementwizard.h index fdf6fa971..99df61eff 100644 --- a/newelementwizard.h +++ b/newelementwizard.h @@ -15,7 +15,7 @@ class ElementsCategoriesWidget; class NamesListWidget; class OrientationSetWidget; -class Diagram; +class HotspotEditor; class NewElementWizard : public QDialog { Q_OBJECT @@ -34,21 +34,12 @@ class NewElementWizard : public QDialog { QWidget *step1, *step2, *step3, *step4, *step5; ElementsCategoriesWidget* categories_list; QLineEdit *qle_filename; - QSpinBox *sb_width; - QSpinBox *sb_height; - QSpinBox *sb_hotspot_x; - QSpinBox *sb_hotspot_y; NamesListWidget *element_names; OrientationSetWidget *orientation_set; + HotspotEditor *hotspot_editor; QPushButton *button_previous; QPushButton *button_next; WizardState current_state; - QGraphicsView *diagram_view; - Diagram *diagram_scene; - QComboBox *north_orientation; - QComboBox *east_orientation; - QComboBox *south_orientation; - QComboBox *west_orientation; QString chosen_file; // methodes @@ -68,7 +59,5 @@ class NewElementWizard : public QDialog { public slots: void previous(); void next(); - void updateScene(); - void updateHotspotLimits(); }; #endif diff --git a/qelectrotech.pro b/qelectrotech.pro index 4957048e8..ba2a2b6b7 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -53,7 +53,8 @@ HEADERS += aboutqet.h \ editor/partarc.h \ editor/arceditor.h \ editor/parttextfield.h \ - editor/textfieldeditor.h + editor/textfieldeditor.h \ + hotspoteditor.h SOURCES += aboutqet.cpp \ borderinset.cpp \ conducer.cpp \ @@ -100,7 +101,8 @@ SOURCES += aboutqet.cpp \ editor/partarc.cpp \ editor/arceditor.cpp \ editor/parttextfield.cpp \ - editor/textfieldeditor.cpp + editor/textfieldeditor.cpp \ + hotspoteditor.cpp RESOURCES += qelectrotech.qrc TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts QT += xml