diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index ade8c0c71..a872d7c04 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -441,14 +441,22 @@ void ElementScene::setGrid(int x_g, int y_g) { const QDomDocument ElementScene::toXml(bool all_parts) const { // document XML QDomDocument xml_document; - + + //define the size of the element by the upper multiple of 10 + QRectF size= elementSceneGeometricRect(); + int upwidth = (qRound(size.width())/10)*10; + if ((qRound(size.width())%10) >= 5) upwidth+=10; + + int upheight = (qRound(size.height())/10)*10; + if ((qRound(size.height())%10) >= 5) upheight+=10; + // racine du document XML QDomElement root = xml_document.createElement("definition"); root.setAttribute("type", "element"); - root.setAttribute("width", QString("%1").arg(_width * 10)); - root.setAttribute("height", QString("%1").arg(_height * 10)); - root.setAttribute("hotspot_x", QString("%1").arg(_hotspot.x())); - root.setAttribute("hotspot_y", QString("%1").arg(_hotspot.y())); + root.setAttribute("width", QString("%1").arg(upwidth+10)); + root.setAttribute("height", QString("%1").arg(upheight+10)); + root.setAttribute("hotspot_x", QString("%1").arg(-(qRound(size.x())-5))); + root.setAttribute("hotspot_y", QString("%1").arg(-(qRound(size.y())-5))); root.setAttribute("orientation", ori.toString()); root.setAttribute("version", QET::version); if (internal_connections) root.setAttribute("ic", "true"); @@ -556,6 +564,23 @@ QRectF ElementScene::sceneContent() const { return(elementContentBoundingRect(items()).unite(borderRect()).adjusted(-adjustment, -adjustment, adjustment, adjustment)); } +/** + @return the minimum, margin-less rectangle the element can fit into, in scene + coordinates. It is different from itemsBoundingRect() because it is not supposed + to imply any margin. +*/ +QRectF ElementScene::elementSceneGeometricRect() const{ + QRectF esgr; + foreach (QGraphicsItem *qgi, items()) { + if (qgi -> type() == ElementPrimitiveDecorator::Type) continue; + if (qgi -> type() == QGraphicsRectItem::Type) continue; + if (CustomElementPart *cep = dynamic_cast (qgi)) { + esgr |= cep -> sceneGeometricRect(); + } + } + return (esgr); +} + /** @return true si toutes les parties graphiques composant l'element sont integralement contenues dans le rectangle representant les limites de diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index aafec9849..0b80ffceb 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -143,6 +143,7 @@ class ElementScene : public QGraphicsScene { virtual void getPasteArea(const QRectF &); QRectF borderRect() const; QRectF sceneContent() const; + QRectF elementSceneGeometricRect () const; bool borderContainsEveryParts() const; bool containsTerminals() const; QUndoStack &undoStack(); diff --git a/sources/editor/qetelementeditor.cpp b/sources/editor/qetelementeditor.cpp index a8786c2d3..c6095016c 100644 --- a/sources/editor/qetelementeditor.cpp +++ b/sources/editor/qetelementeditor.cpp @@ -449,10 +449,7 @@ void QETElementEditor::slot_updateMenus() { paste_in_area -> setEnabled(clipboard_elmt); // actions dependant de l'etat de la pile d'annulation - save -> setEnabled(!read_only && !ce_scene -> undoStack().isClean() && ce_scene -> borderContainsEveryParts()); - save_as -> setEnabled(ce_scene -> borderContainsEveryParts()); - save_as_file -> setEnabled(ce_scene -> borderContainsEveryParts()); - //if (!ce_scene -> borderContainsEveryParts()) checkElement(); + save -> setEnabled(!read_only && !ce_scene -> undoStack().isClean()); undo -> setEnabled(!read_only && ce_scene -> undoStack().canUndo()); redo -> setEnabled(!read_only && ce_scene -> undoStack().canRedo()); } @@ -1053,10 +1050,6 @@ bool QETElementEditor::slot_saveAsFile() { */ bool QETElementEditor::canClose() { if (ce_scene -> undoStack().isClean()) return(true); - //verification avant d'enregistrer le fichier - if (!ce_scene -> borderContainsEveryParts()) checkElement(); - // si le symbole deborde, echec de la fermeture - if (!ce_scene -> borderContainsEveryParts()) return(false); // demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours QMessageBox::StandardButton answer = QET::MessageBox::question( this,