2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-08-25 03:43:05 +00:00
|
|
|
#ifndef ELEMENT_SCENE_H
|
|
|
|
#define ELEMENT_SCENE_H
|
2015-03-02 20:14:56 +00:00
|
|
|
#include <QtWidgets>
|
2007-06-30 17:41:07 +00:00
|
|
|
#include <QtXml>
|
2007-08-23 15:33:55 +00:00
|
|
|
#include "qgimanager.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "elementcontent.h"
|
2014-06-03 20:21:19 +00:00
|
|
|
#include "diagramcontext.h"
|
2019-01-02 16:56:46 +00:00
|
|
|
#include "nameslist.h"
|
2014-11-04 22:08:42 +00:00
|
|
|
|
2013-02-08 22:05:15 +00:00
|
|
|
class CustomElementPart;
|
|
|
|
class ElementEditionCommand;
|
|
|
|
class ElementPrimitiveDecorator;
|
2007-08-25 03:43:05 +00:00
|
|
|
class QETElementEditor;
|
2014-11-04 22:08:42 +00:00
|
|
|
class ESEventInterface;
|
|
|
|
class QKeyEvent;
|
2007-10-21 16:10:21 +00:00
|
|
|
/**
|
2020-07-28 20:56:41 +02:00
|
|
|
@brief The ElementScene class
|
2012-11-09 21:09:24 +00:00
|
|
|
This class is the canvas allowing the visual edition of an electrial element.
|
2020-07-28 20:56:41 +02:00
|
|
|
It displays the various primitives composing the drawing of the element,
|
|
|
|
the border due to its fixed size and its hotspot.
|
2007-10-21 16:10:21 +00:00
|
|
|
*/
|
2017-07-31 17:41:48 +00:00
|
|
|
class ElementScene : public QGraphicsScene
|
|
|
|
{
|
2014-06-20 20:10:09 +00:00
|
|
|
friend class ChangePropertiesCommand;
|
2007-06-30 17:41:07 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2017-07-31 17:41:48 +00:00
|
|
|
// enum
|
2013-02-08 22:05:20 +00:00
|
|
|
public:
|
2017-07-31 17:41:48 +00:00
|
|
|
enum Behavior { Normal, PasteArea, AddPart };
|
|
|
|
enum ItemOption {
|
2017-08-02 15:26:14 +00:00
|
|
|
SortByZValue = 1,
|
|
|
|
IncludeTerminals = 2,
|
|
|
|
IncludeHelperItems = 4,
|
|
|
|
Selected = 8,
|
|
|
|
NonSelected = 16,
|
|
|
|
SelectedOrNot = 24
|
|
|
|
};
|
2017-08-01 19:37:04 +00:00
|
|
|
Q_DECLARE_FLAGS(ItemOptions, ItemOption)
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2017-07-31 17:41:48 +00:00
|
|
|
// constructors, destructor
|
2007-06-30 17:41:07 +00:00
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
ElementScene(QETElementEditor *, QObject * = nullptr);
|
2017-08-05 02:10:01 +00:00
|
|
|
~ElementScene() override;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
private:
|
2017-07-31 17:41:48 +00:00
|
|
|
ElementScene(const ElementScene &);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2017-10-01 15:25:34 +00:00
|
|
|
// attributes
|
2007-06-30 17:41:07 +00:00
|
|
|
private:
|
2018-03-11 12:59:53 +00:00
|
|
|
NamesList m_names_list; /// List of localized names
|
|
|
|
QString m_informations; /// Extra informations
|
|
|
|
QString m_elmt_type; /// element type
|
2017-10-01 15:25:34 +00:00
|
|
|
DiagramContext m_elmt_kindInfo,
|
2020-07-14 21:51:15 +02:00
|
|
|
m_elmt_information; /// element kind info
|
2017-07-31 17:41:48 +00:00
|
|
|
QGIManager m_qgi_manager;
|
|
|
|
QUndoStack m_undo_stack;
|
2018-03-11 12:59:53 +00:00
|
|
|
|
2017-01-02 18:15:18 +00:00
|
|
|
ESEventInterface *m_event_interface = nullptr;
|
2017-07-31 17:41:48 +00:00
|
|
|
Behavior m_behavior;
|
|
|
|
QETElementEditor *m_element_editor = nullptr;
|
2014-11-04 22:08:42 +00:00
|
|
|
|
2017-08-02 15:26:14 +00:00
|
|
|
QGraphicsRectItem *m_paste_area;
|
2017-07-31 17:41:48 +00:00
|
|
|
QRectF m_defined_paste_area;
|
2018-03-11 12:59:53 +00:00
|
|
|
|
2017-07-31 17:41:48 +00:00
|
|
|
QString m_last_copied;
|
2014-11-04 22:08:42 +00:00
|
|
|
|
2020-07-28 20:56:41 +02:00
|
|
|
/// Decorator item displayed when at least one item is selected
|
2017-01-02 18:15:18 +00:00
|
|
|
ElementPrimitiveDecorator *m_decorator = nullptr;
|
2018-03-11 12:59:53 +00:00
|
|
|
|
|
|
|
int m_x_grid,
|
2020-07-14 21:51:15 +02:00
|
|
|
m_y_grid;
|
2014-11-04 22:08:42 +00:00
|
|
|
|
2018-03-11 12:59:53 +00:00
|
|
|
// methods
|
2007-06-30 17:41:07 +00:00
|
|
|
public:
|
2015-03-02 20:14:56 +00:00
|
|
|
void setEventInterface (ESEventInterface *event_interface);
|
2017-07-31 17:41:48 +00:00
|
|
|
void clearEventInterface();
|
2015-04-18 11:02:10 +00:00
|
|
|
void setBehavior (ElementScene::Behavior);
|
2018-06-30 21:41:27 +00:00
|
|
|
ElementScene::Behavior behavior() const;
|
2014-11-04 22:08:42 +00:00
|
|
|
QPointF snapToGrid(QPointF point);
|
2017-07-31 17:41:48 +00:00
|
|
|
void setNames(const NamesList &);
|
|
|
|
NamesList names() const;
|
|
|
|
QString informations() const;
|
|
|
|
void setInformations(const QString &);
|
|
|
|
QString elementType () const {return m_elmt_type;}
|
|
|
|
DiagramContext elementKindInfo () const {return m_elmt_kindInfo;}
|
2018-03-11 12:59:53 +00:00
|
|
|
DiagramContext elementInformation() const {return m_elmt_information;}
|
2017-07-31 17:41:48 +00:00
|
|
|
virtual int xGrid() const;
|
|
|
|
virtual int yGrid() const;
|
|
|
|
virtual void setGrid(int, int);
|
|
|
|
virtual const QDomDocument toXml(bool = true);
|
|
|
|
virtual QRectF boundingRectFromXml(const QDomDocument &);
|
2020-07-28 20:57:02 +02:00
|
|
|
virtual void fromXml(const QDomDocument &,
|
|
|
|
const QPointF & = QPointF(),
|
|
|
|
bool = true,
|
|
|
|
ElementContent * = nullptr);
|
2017-07-31 17:41:48 +00:00
|
|
|
virtual void reset();
|
|
|
|
virtual QList<CustomElementPart *> primitives() const;
|
2020-07-28 20:57:02 +02:00
|
|
|
virtual QList<QGraphicsItem *>
|
|
|
|
zItems(ItemOptions options = ItemOptions(SortByZValue
|
|
|
|
| IncludeTerminals
|
|
|
|
| SelectedOrNot)) const;
|
2017-07-31 17:41:48 +00:00
|
|
|
virtual ElementContent selectedContent() const;
|
|
|
|
virtual void getPasteArea(const QRectF &);
|
|
|
|
QRectF elementSceneGeometricRect () const;
|
|
|
|
bool containsTerminals() const;
|
|
|
|
QUndoStack &undoStack();
|
|
|
|
QGIManager &qgiManager();
|
|
|
|
static bool clipboardMayContainElement();
|
|
|
|
bool wasCopiedFromThisElement(const QString &);
|
|
|
|
void cut();
|
|
|
|
void copy();
|
|
|
|
QETElementEditor* editor() const;
|
2018-07-19 14:14:31 +00:00
|
|
|
void setElementInfo(const DiagramContext& dc);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
protected:
|
2017-08-05 02:10:01 +00:00
|
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mouseReleaseEvent (QGraphicsSceneMouseEvent *) override;
|
|
|
|
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void keyPressEvent (QKeyEvent *event) override;
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
2014-11-04 22:08:42 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void drawForeground(QPainter *, const QRectF &) override;
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
private:
|
2017-07-31 17:41:48 +00:00
|
|
|
QRectF elementContentBoundingRect(const ElementContent &) const;
|
2017-09-25 17:44:02 +00:00
|
|
|
bool applyInformations(const QDomDocument &);
|
|
|
|
ElementContent loadContent(const QDomDocument &);
|
|
|
|
ElementContent addContent(const ElementContent &);
|
|
|
|
ElementContent addContentAtPos(const ElementContent &, const QPointF &);
|
2017-07-31 17:41:48 +00:00
|
|
|
void addPrimitive(QGraphicsItem *);
|
|
|
|
void initPasteArea();
|
|
|
|
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
|
|
|
QMutex *m_decorator_lock;
|
|
|
|
void centerElementToOrigine();
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
public slots:
|
2017-07-31 17:41:48 +00:00
|
|
|
void slot_select(const ElementContent &);
|
|
|
|
void slot_selectAll();
|
|
|
|
void slot_deselectAll();
|
|
|
|
void slot_invertSelection();
|
|
|
|
void slot_delete();
|
|
|
|
void slot_editNames();
|
|
|
|
void slot_editAuthorInformations();
|
|
|
|
void slot_editProperties();
|
|
|
|
void managePrimitivesGroups();
|
|
|
|
void stackAction(ElementEditionCommand *);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
signals:
|
2020-07-28 20:56:41 +02:00
|
|
|
/// Signal emitted after one or several parts were added
|
2017-07-31 17:41:48 +00:00
|
|
|
void partsAdded();
|
2020-07-28 20:56:41 +02:00
|
|
|
/// Signal emitted after one or several parts were removed
|
2017-07-31 17:41:48 +00:00
|
|
|
void partsRemoved();
|
2020-07-28 20:56:41 +02:00
|
|
|
/// Signal emitted when the zValue of one or several parts change
|
2017-07-31 17:41:48 +00:00
|
|
|
void partsZValueChanged();
|
2020-07-28 20:56:41 +02:00
|
|
|
/// Signal emitted when users have defined the copy/paste area
|
2017-07-31 17:41:48 +00:00
|
|
|
void pasteAreaDefined(const QRectF &);
|
2020-07-28 20:56:41 +02:00
|
|
|
/// Signal emitted when need zoomFit
|
2017-07-31 17:41:48 +00:00
|
|
|
void needZoomFit();
|
2018-03-11 12:59:53 +00:00
|
|
|
void elementInfoChanged();
|
2007-06-30 17:41:07 +00:00
|
|
|
};
|
|
|
|
|
2013-02-08 22:05:20 +00:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-07-28 20:56:41 +02:00
|
|
|
@brief ElementScene::setNames
|
2012-11-09 21:09:24 +00:00
|
|
|
@param nameslist New set of naes for the currently edited element
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2007-12-16 14:05:39 +00:00
|
|
|
inline void ElementScene::setNames(const NamesList &nameslist) {
|
2017-07-31 17:41:48 +00:00
|
|
|
m_names_list = nameslist;
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
2020-07-28 20:56:41 +02:00
|
|
|
@brief ElementScene::names
|
2012-11-09 21:09:24 +00:00
|
|
|
@return the list of names of the currently edited element
|
2007-12-05 21:16:01 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
inline NamesList ElementScene::names() const
|
|
|
|
{
|
2017-07-31 17:41:48 +00:00
|
|
|
return(m_names_list);
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-14 16:28:45 +00:00
|
|
|
/**
|
2020-07-28 20:56:41 +02:00
|
|
|
@brief ElementScene::informations
|
2012-11-09 21:09:24 +00:00
|
|
|
@return extra informations of the currently edited element
|
2010-02-14 16:28:45 +00:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
inline QString ElementScene::informations() const
|
|
|
|
{
|
2017-07-31 17:41:48 +00:00
|
|
|
return(m_informations);
|
2010-02-14 16:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-28 20:56:41 +02:00
|
|
|
@brief ElementScene::setInformations
|
2012-11-09 21:09:24 +00:00
|
|
|
@param infos new extra information for the currently edited element
|
2010-02-14 16:28:45 +00:00
|
|
|
*/
|
|
|
|
inline void ElementScene::setInformations(const QString &infos) {
|
2017-07-31 17:41:48 +00:00
|
|
|
m_informations = infos;
|
2010-02-14 16:28:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
#endif
|