[qet] [2398] element editor: start work to define automatically the size of element

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2398
Author:   blacksun
Date:     2013-07-28 02:23:10 +0200 (Sun, 28 Jul 2013)
Log Message:
-----------
element editor: start work to define automatically the size of element

Modified Paths:
--------------
    trunk/sources/editor/elementscene.cpp
    trunk/sources/editor/elementscene.h
    trunk/sources/editor/qetelementeditor.cpp

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2013-07-27 07:45:35 UTC (rev 2397)
+++ trunk/sources/editor/elementscene.cpp	2013-07-28 00:23:10 UTC (rev 2398)
@@ -441,14 +441,22 @@
 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");
@@ -557,6 +565,23 @@
 }
 
 /**
+	@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 <CustomElementPart*> (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
 	l'element.

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2013-07-27 07:45:35 UTC (rev 2397)
+++ trunk/sources/editor/elementscene.h	2013-07-28 00:23:10 UTC (rev 2398)
@@ -143,6 +143,7 @@
 	virtual void getPasteArea(const QRectF &);
 	QRectF borderRect() const;
 	QRectF sceneContent() const;
+	QRectF elementSceneGeometricRect () const;
 	bool borderContainsEveryParts() const;
 	bool containsTerminals() const;
 	QUndoStack &undoStack();

Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp	2013-07-27 07:45:35 UTC (rev 2397)
+++ trunk/sources/editor/qetelementeditor.cpp	2013-07-28 00:23:10 UTC (rev 2398)
@@ -449,10 +449,7 @@
 	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::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,


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/