48 QGraphicsScene(parent),
49 m_elmt_type(
"simple"),
51 m_element_editor(editor)
53 setItemIndexMethod(QGraphicsScene::NoIndex);
61 setItemIndexMethod(NoIndex);
101 QPointF event_pos = e -> scenePos();
102 if (!(e -> modifiers() & Qt::ControlModifier))
107 current_rect.moveCenter(event_pos);
112 QGraphicsScene::mouseMoveEvent(e);
130 QGraphicsScene::mousePressEvent(e);
156 QGraphicsScene::mouseReleaseEvent(e);
174 QGraphicsScene::mouseDoubleClickEvent(event);
197 if(selectedItems().size() == 1)
202 if(t->textInteractionFlags() & Qt::TextEditorInteraction)
204 QGraphicsScene::keyPressEvent(event);
209 QGraphicsObject *qgo = selectedItems().first()->toGraphicsObject();
212 QPointF original_pos = qgo->pos();
213 QPointF p = qgo->pos();
214 int k =
event->key();
215 if(k == Qt::Key_Right)
217 else if (k == Qt::Key_Left)
219 else if (k == Qt::Key_Up)
221 else if (k == Qt::Key_Down)
226 undo->setText(
tr(
"Déplacer une primitive"));
234 QGraphicsScene::keyPressEvent(event);
244 QGraphicsScene::contextMenuEvent(event);
245 if(event->isAccepted())
262 p -> setRenderHint(QPainter::Antialiasing,
false);
263 p -> setRenderHint(QPainter::TextAntialiasing,
true);
264 p -> setRenderHint(QPainter::SmoothPixmapTransform,
false);
267 pen.setCosmetic(
true);
269 p -> setBrush(Qt::NoBrush);
270 p -> drawLine(-20, 0, 20, 0);
271 p -> drawLine(0, -20, 0, 20);
287 event_interface->
init();
354 if (!size.contains(0,0) && all_parts)
362 int upwidth = ((qRound(size.width())/10)*10)+10;
363 if ((qRound(size.width())%10) > 6) upwidth+=10;
365 int upheight = ((qRound(size.height())/10)*10)+10;
366 if ((qRound(size.height())%10) > 6) upheight+=10;
369 int xmargin = qRound(upwidth - size.width());
370 int ymargin = qRound(upheight - size.height());
373 QDomDocument xml_document;
376 QDomElement root = xml_document.createElement(
"definition");
377 root.setAttribute(
"type",
"element");
378 root.setAttribute(
"width", QString(
"%1").arg(upwidth));
379 root.setAttribute(
"height", QString(
"%1").arg(upheight));
380 root.setAttribute(
"hotspot_x", QString(
"%1").arg(-(qRound(size.x() - (xmargin/2)))));
381 root.setAttribute(
"hotspot_y", QString(
"%1").arg(-(qRound(size.y() - (ymargin/2)))));
382 root.setAttribute(
"orientation",
"dyyy");
387 QDomElement uuid = xml_document.createElement(
"uuid");
388 uuid.setAttribute(
"uuid", QUuid::createUuid().toString());
389 root.appendChild(uuid);
396 QDomElement kindInfo = xml_document.createElement(
"kindInformations");
398 root.appendChild(kindInfo);
403 QDomElement element_info = xml_document.createElement(
"elementInformations");
405 root.appendChild(element_info);
409 QDomElement informations_element = xml_document.createElement(
"informations");
410 root.appendChild(informations_element);
411 informations_element.appendChild(xml_document.createTextNode(
informations()));
413 QDomElement description = xml_document.createElement(
"description");
416 foreach(QGraphicsItem *qgi,
zItems())
419 if (!all_parts && !qgi -> isSelected())
continue;
422 if (ce -> isUseless())
continue;
423 description.appendChild(ce ->
toXml(xml_document));
426 root.appendChild(description);
428 xml_document.appendChild(root);
429 return(xml_document);
439 if (loaded_content.isEmpty())
return(QRectF());
445 qDeleteAll(loaded_content);
447 return(bounding_rect);
468 if (consider_informations) {
475 if (position != QPointF())
481 *content_ptr = loaded_content;
492 foreach (QGraphicsItem *qgi, items()) {
494 if (qgi->type() == QGraphicsRectItem::Type)
continue;
497 esgr |= cep -> sceneGeometricRect();
508 foreach(QGraphicsItem *qgi,items()) {
509 if (qgraphicsitem_cast<PartTerminal *>(qgi)) {
534 QString clipboard_text = QApplication::clipboard() -> text().trimmed();
535 bool may_be_element = clipboard_text.startsWith(
"<definition") && clipboard_text.endsWith(
"</definition>");
536 return(may_be_element);
554 QList<QGraphicsItem *> cut_content = selectedItems();
565 QClipboard *clipboard = QApplication::clipboard();
568 QString clipboard_content =
toXml(
false).toString(4);
571 if (clipboard -> supportsSelection()) {
572 clipboard -> setText(clipboard_content, QClipboard::Selection);
574 clipboard -> setText(clipboard_content);
606 QList<QGraphicsItem*> items_list;
607 for (QGraphicsItem *qgi : content)
614 foreach(QGraphicsItem *qgi, items_list)
615 qgi -> setSelected(
true);
618 emit(selectionChanged());
642 foreach(QGraphicsItem *qgi, items()) qgi -> setSelected(!qgi -> isSelected());
644 emit(selectionChanged());
652 QList<QGraphicsItem *> selected_items = selectedItems();
653 if (selected_items.isEmpty())
return;
660 emit(selectionChanged());
673 dialog_author.setModal(
true);
675 dialog_author.setWindowFlags(Qt::Sheet);
677 dialog_author.setMinimumSize(400, 260);
678 dialog_author.setWindowTitle(
tr(
"Éditer les informations sur l'auteur",
"window title"));
679 QVBoxLayout *dialog_layout =
new QVBoxLayout(&dialog_author);
682 QLabel *information_label =
new QLabel(
tr(
"Vous pouvez utiliser ce champ libre pour mentionner les auteurs de l'élément, sa licence, ou tout autre renseignement que vous jugerez utile."));
683 information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
684 information_label -> setWordWrap(
true);
685 dialog_layout -> addWidget(information_label);
688 QTextEdit *text_field =
new QTextEdit();
689 text_field -> setAcceptRichText(
false);
691 text_field -> setReadOnly(is_read_only);
692 dialog_layout -> addWidget(text_field);
695 QDialogButtonBox *dialog_buttons =
new QDialogButtonBox(is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok |
QDialogButtonBox::Cancel);
696 dialog_layout -> addWidget(dialog_buttons);
697 connect(dialog_buttons, SIGNAL(accepted()), &dialog_author, SLOT(accept()));
698 connect(dialog_buttons, SIGNAL(rejected()), &dialog_author, SLOT(reject()));
701 if (dialog_author.exec() == QDialog::Accepted && !is_read_only) {
702 QString new_infos = text_field -> toPlainText().remove(QChar(13));
738 dialog_.setModal(
true);
739 dialog_.setMinimumSize(400, 330);
740 dialog_.setWindowTitle(
tr(
"Éditer les noms",
"window title"));
742 dialog_.
setInformationText(
tr(
"Vous pouvez spécifier le nom de l'élément dans plusieurs langues."));
748 if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->
isEmpty())
761 QList<CustomElementPart *> primitives_list;
762 foreach (QGraphicsItem *item, items()) {
764 primitives_list << primitive;
767 return(primitives_list);
777 return(QList<QGraphicsItem *>());
781 QList<QGraphicsItem *> all_items_list(items());
782 QMutableListIterator<QGraphicsItem *> i(all_items_list);
787 while (i.hasNext()) {
788 if (i.next() -> isSelected() != keep_selected) {
794 QList<QGraphicsItem *> terminals;
795 QList<QGraphicsItem *> helpers;
796 for (i.toFront(); i.hasNext(); ) {
798 QGraphicsItem *qgi = i.value();
801 qgi -> type() == QGraphicsRectItem::Type ||
807 else if (qgraphicsitem_cast<PartTerminal *>(qgi)) {
820 all_items_list += terminals;
823 all_items_list += helpers;
825 return(all_items_list);
833 foreach(QGraphicsItem *qgi,
zItems()) {
834 if (qgi -> isSelected()) content << qgi;
862 QList<QGraphicsItem*> items_list;
863 for (QGraphicsItem *qgi : items())
869 for (QGraphicsItem *qgi : items_list)
885 QRectF bounding_rect;
886 foreach(QGraphicsItem *qgi, content) {
889 if (qgi -> type() == QGraphicsRectItem::Type)
continue;
890 bounding_rect |= qgi -> sceneBoundingRect();
892 return(bounding_rect);
905 QDomElement root = xml_document.documentElement();
907 if (root.tagName() !=
"definition" || root.attribute(
"type") !=
"element")
911 m_elmt_type = root.attribute(
"link_type",
"simple");
921 for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
922 QDomElement elmt = node.toElement();
923 if (elmt.isNull())
continue;
924 if (elmt.tagName() ==
"informations") {
956 QDomElement root = xml_document.documentElement();
958 if (root.tagName() !=
"definition" || root.attribute(
"type") !=
"element")
959 return(loaded_parts);
962 for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling())
964 QDomElement elmts = node.toElement();
968 if (elmts.tagName() ==
"description")
971 for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling())
973 QDomElement qde = n.toElement();
992 if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep))
1010 return(loaded_parts);
1019 foreach(QGraphicsItem *part, content) {
1036 QPointF offset = pos - bounding_rect.topLeft();
1039 foreach(QGraphicsItem *part, content) {
1040 part -> setPos(part -> pos() + offset);
1051 if (!primitive)
return;
1062 QPen paste_area_pen;
1063 paste_area_pen.setStyle(Qt::DashDotLine);
1064 paste_area_pen.setColor(QColor(30, 56, 86, 255));
1066 QBrush paste_area_brush;
1067 paste_area_brush.setStyle(Qt::SolidPattern);
1068 paste_area_brush.setColor(QColor(90, 167, 255, 64));
1090 return(item1-> zValue() < item2 -> zValue());
1100 int center_x = qRound(size.center().x());
1101 int center_y = qRound(size.center().y());
1104 int move_x = center_x - (center_x %10);
1105 if (center_x < 0) move_x -= 10;
1106 int move_y = center_y - (center_y %10);
1107 if (center_y < 0) move_y -= 10;
1110 foreach (QGraphicsItem *qgi, items()) {
1112 if (qgi -> type() == QGraphicsRectItem::Type)
continue;
1114 qgi -> setSelected(
false);
1115 qgi -> moveBy(-(move_x), -(move_y));
1141 if (selected_items.size() <= 1)
1147 for(QGraphicsItem *qgi : selected_items)
1150 qgi->setSelected(
true);
1163 if (command -> elementScene()) {
1164 if (command -> elementScene() !=
this)
return;
1166 command -> setElementScene(
this);
1169 if (!command -> elementView()) {
1170 foreach (QGraphicsView *view, views()) {
1171 if (
ElementView *element_view = dynamic_cast<ElementView *>(view)) {
1172 command -> setElementView(element_view);
void setEventInterface(ESEventInterface *event_interface)
ElementScene::setEventInterface Set a new event interface.
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
virtual void fromXml(const QDomDocument &, const QPointF &=QPointF(), bool=true, ElementContent *=nullptr)
void mousePressEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mousePressEvent.
void setInformationText(const QString &text)
void drawForeground(QPainter *, const QRectF &) override
virtual void fromXml(const QDomElement &)=0
DiagramContext m_elmt_kindInfo
element type
void slot_deselectAll()
ElementScene::slot_deselectAll deselect all item.
void elementInfoChanged()
void setBehavior(ElementScene::Behavior)
ElementScene::setBehavior Modifie the current behavior of this scene.
void fromXml(const QDomElement &, const QHash< QString, QString > &=QHash< QString, QString >())
void slot_editAuthorInformations()
QMutex * m_decorator_lock
void partsRemoved()
Signal emitted after one or several parts were removed.
virtual QRectF boundingRectFromXml(const QDomDocument &)
void slot_selectAll()
ElementScene::slot_selectAll Select all items.
QGIManager m_qgi_manager
element kind info
void init()
ESEventInterface::init Init this event interface.
void slot_editProperties()
ElementScene::slot_editProperties Open dialog to edit the element properties.
QString informations() const
bool wasCopiedFromThisElement(const QString &)
NameListWidget * namelistWidget() const
NameListDialog::namelistWidget.
void release(QGraphicsItem *)
void stackAction(ElementEditionCommand *)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseReleaseEvent.
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *)
The PartDynamicTextField class This class represents an editable dynamic text field which may be used...
void fromTextFieldXml(const QDomElement &dom_element)
PartDynamicTextField::fromTextFieldXml Setup this text from the xml definition of a text field (The x...
ElementContent loadContent(const QDomDocument &)
ElementScene::loadContent.
virtual const QDomDocument toXml(bool=true)
ElementScene::toXml Export this element as a xml file.
QDomElement toXml(QDomDocument &, const QHash< QString, QString > &=QHash< QString, QString >()) const
virtual void setGrid(int, int)
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
void addPrimitive(QGraphicsItem *)
void slot_select(const ElementContent &)
ElementScene::slot_select Select the item in content, every others items in the scene are deselected...
QGIManager & qgiManager()
QRectF elementContentBoundingRect(const ElementContent &) const
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
ElementScene::mouseDoubleClickEvent.
~ElementScene() override
ElementScene::~ElementScene.
ESEventInterface * m_event_interface
void pasteAreaDefined(const QRectF &)
Signal emitted when users have defined the copy/paste area.
QETElementEditor * editor() const
const QString version
QElectroTech version (as string, used to mark projects and elements XML documents) ...
void managePrimitivesGroups()
ElementScene::managePrimitivesGroups Ensure the decorator is adequately shown, hidden or updated so i...
The NameListDialog class Provide a dialog for let user define localized string;.
void needZoomFit()
Signal emitted when need zoomFit.
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
void fromXml(const QDomElement &, const QString &="property")
void partsAdded()
Signal emitted after one or several parts were added.
ElementScene(QETElementEditor *, QObject *=nullptr)
virtual void reset()
ElementScene::reset Remove all QGraphicsItems in the scene and clear the undo stack.
static bool clipboardMayContainElement()
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
ElementScene::contextMenuEvent Display the context menu event, only if behavior are Normal...
void keyPressEvent(QKeyEvent *event) override
ElementScene::keyPressEvent manage key press event.
virtual int yGrid() const
friend class ChangePropertiesCommand
bool containsTerminals() const
void clearEventInterface()
ElementScene::clearEventInterface Clear the current event interface.
bool applyInformations(const QDomDocument &)
The PartPolygon class This class represents a polygon primitive which may be used to compose the draw...
virtual ElementContent selectedContent() const
virtual QList< CustomElementPart * > primitives() const
QString m_elmt_type
Extra informations.
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
ElementScene::mouseMoveEvent.
void toXml(QDomElement &, const QString &="property") const
DiagramContext m_elmt_information
virtual QList< QGraphicsItem * > zItems(ItemOptions options=ItemOptions(SortByZValue|IncludeTerminals|SelectedOrNot)) const
QRectF m_defined_paste_area
void centerElementToOrigine()
ElementScene::centerElementToOrigine try to center better is possible the element to the scene (the c...
virtual void getPasteArea(const QRectF &)
virtual bool isFinish() const
QETElementEditor * m_element_editor
ElementContent addContentAtPos(const ElementContent &, const QPointF &)
The PartArc class This class represents an elliptical arc primitive which may be used to compose the ...
virtual int xGrid() const
QList< QGraphicsItem * > ElementContent
The PartEllipse class This class represents an ellipse primitive which may be used to compose the dra...
void setInformations(const QString &)
QPointF snapToGrid(QPointF point)
ElementPrimitiveDecorator * m_decorator
Decorator item displayed when at least one item is selected.
QRectF elementSceneGeometricRect() const
void slot_editNames()
ElementScene::slot_editNames Launch a dialog for edit the names of the edited element.
ElementScene::Behavior behavior() const
void setElementInfo(const DiagramContext &dc)
QGraphicsRectItem * m_paste_area
ElementContent addContent(const ElementContent &)
void slot_invertSelection()