mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
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:
@@ -442,13 +442,21 @@ 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 <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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user