element editor: start work to define automatically the size of element

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2398 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2013-07-28 00:23:10 +00:00
parent 8d77d7040b
commit ef124bbdeb
3 changed files with 32 additions and 13 deletions

View File

@@ -442,13 +442,21 @@ const QDomDocument ElementScene::toXml(bool all_parts) const {
// document XML // document XML
QDomDocument xml_document; 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 // racine du document XML
QDomElement root = xml_document.createElement("definition"); QDomElement root = xml_document.createElement("definition");
root.setAttribute("type", "element"); root.setAttribute("type", "element");
root.setAttribute("width", QString("%1").arg(_width * 10)); root.setAttribute("width", QString("%1").arg(upwidth+10));
root.setAttribute("height", QString("%1").arg(_height * 10)); root.setAttribute("height", QString("%1").arg(upheight+10));
root.setAttribute("hotspot_x", QString("%1").arg(_hotspot.x())); root.setAttribute("hotspot_x", QString("%1").arg(-(qRound(size.x())-5)));
root.setAttribute("hotspot_y", QString("%1").arg(_hotspot.y())); root.setAttribute("hotspot_y", QString("%1").arg(-(qRound(size.y())-5)));
root.setAttribute("orientation", ori.toString()); root.setAttribute("orientation", ori.toString());
root.setAttribute("version", QET::version); root.setAttribute("version", QET::version);
if (internal_connections) root.setAttribute("ic", "true"); 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(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 <CustomElementPart*> (qgi)) {
esgr |= cep -> sceneGeometricRect();
}
}
return (esgr);
}
/** /**
@return true si toutes les parties graphiques composant l'element sont @return true si toutes les parties graphiques composant l'element sont
integralement contenues dans le rectangle representant les limites de integralement contenues dans le rectangle representant les limites de

View File

@@ -143,6 +143,7 @@ class ElementScene : public QGraphicsScene {
virtual void getPasteArea(const QRectF &); virtual void getPasteArea(const QRectF &);
QRectF borderRect() const; QRectF borderRect() const;
QRectF sceneContent() const; QRectF sceneContent() const;
QRectF elementSceneGeometricRect () const;
bool borderContainsEveryParts() const; bool borderContainsEveryParts() const;
bool containsTerminals() const; bool containsTerminals() const;
QUndoStack &undoStack(); QUndoStack &undoStack();

View File

@@ -449,10 +449,7 @@ void QETElementEditor::slot_updateMenus() {
paste_in_area -> setEnabled(clipboard_elmt); paste_in_area -> setEnabled(clipboard_elmt);
// actions dependant de l'etat de la pile d'annulation // actions dependant de l'etat de la pile d'annulation
save -> setEnabled(!read_only && !ce_scene -> undoStack().isClean() && ce_scene -> borderContainsEveryParts()); save -> setEnabled(!read_only && !ce_scene -> undoStack().isClean());
save_as -> setEnabled(ce_scene -> borderContainsEveryParts());
save_as_file -> setEnabled(ce_scene -> borderContainsEveryParts());
//if (!ce_scene -> borderContainsEveryParts()) checkElement();
undo -> setEnabled(!read_only && ce_scene -> undoStack().canUndo()); undo -> setEnabled(!read_only && ce_scene -> undoStack().canUndo());
redo -> setEnabled(!read_only && ce_scene -> undoStack().canRedo()); redo -> setEnabled(!read_only && ce_scene -> undoStack().canRedo());
} }
@@ -1053,10 +1050,6 @@ bool QETElementEditor::slot_saveAsFile() {
*/ */
bool QETElementEditor::canClose() { bool QETElementEditor::canClose() {
if (ce_scene -> undoStack().isClean()) return(true); 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 // demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours
QMessageBox::StandardButton answer = QET::MessageBox::question( QMessageBox::StandardButton answer = QET::MessageBox::question(
this, this,