Read code is better than explanation.
/**
@return Le rectangle delimitant le contour de l'element
*/
QRectF Element::boundingRect() const {
return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), dimensions));
}
/**
Definit la taille de l'element sur le schema. Les tailles doivent etre
des multiples de 10 ; si ce n'est pas le cas, les dimensions indiquees
seront arrrondies aux dizaines superieures.
@param wid Largeur de l'element
@param hei Hauteur de l'element
@return La taille finale de l'element
*/
QSize Element::setSize(int wid, int hei) {
prepareGeometryChange();
// chaque dimension indiquee est arrondie a la dizaine superieure
while (wid % 10) ++ wid;
while (hei % 10) ++ hei;
// les dimensions finales sont conservees et retournees
return(dimensions = QSize(wid, hei));
}
/**
@return la taille de l'element sur le schema
*/
QSize Element::size() const {
return(dimensions);
}
/**
Definit le hotspot de l'element par rapport au coin superieur gauche de son rectangle delimitant.
Necessite que la taille ait deja ete definie
@param hs Coordonnees du hotspot
*/
QPoint Element::setHotspot(QPoint hs) {
// la taille doit avoir ete definie
prepareGeometryChange();
if (dimensions.isNull()) hotspot_coord = QPoint(0, 0);
else {
// les coordonnees indiquees ne doivent pas depasser les dimensions de l'element
int hsx = qMin(hs.x(), dimensions.width());
int hsy = qMin(hs.y(), dimensions.height());
hotspot_coord = QPoint(hsx, hsy);
}
return(hotspot_coord);
}
/**
* @brief ElementScene::toXml
* Export this element as a xml file
* @param all_parts (true by default) if true, export the entire element in xml,
* if false, only export the selected parts.
* @return an xml document that describe the element.
*/
const QDomDocument ElementScene::toXml(bool all_parts)
{
QRectF size= elementSceneGeometricRect();
//if the element doesn't contains the origin point of the scene
//we move the element to the origin for solve this default before saving
if (!size.contains(0,0) && all_parts)
{
centerElementToOrigine();
//recalcul the size after movement
size= elementSceneGeometricRect();
}
//define the size of the element by the upper multiple of 10
int upwidth = ((qRound(size.width())/10)*10)+10;
if ((qRound(size.width())%10) > 6) upwidth+=10;
int upheight = ((qRound(size.height())/10)*10)+10;
if ((qRound(size.height())%10) > 6) upheight+=10;
//the margin between the real size of the element and the rectangle that delimits
int xmargin = qRound(upwidth - size.width());
int ymargin = qRound(upheight - size.height());
// document XML
QDomDocument xml_document;
//Root of xml document
QDomElement root = xml_document.createElement("definition");
root.setAttribute("type", "element");
root.setAttribute("width", QString("%1").arg(upwidth));
root.setAttribute("height", QString("%1").arg(upheight));
root.setAttribute("hotspot_x", QString("%1").arg(-(qRound(size.x() - (xmargin/2)))));
root.setAttribute("hotspot_y", QString("%1").arg(-(qRound(size.y() - (ymargin/2)))));
root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet
root.setAttribute("version", QET::version);
root.setAttribute("link_type", m_elmt_type);
"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."