2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2014-01-29 18:37:45 +00:00
|
|
|
Copyright 2006-2014 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
|
2007-06-30 17:41:07 +00:00
|
|
|
#include <QtGui>
|
|
|
|
#include <QtXml>
|
|
|
|
#include "nameslistwidget.h"
|
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"
|
2013-02-08 22:05:15 +00:00
|
|
|
class CustomElementPart;
|
|
|
|
class ElementEditionCommand;
|
|
|
|
class ElementPrimitiveDecorator;
|
2007-08-25 03:43:05 +00:00
|
|
|
class QETElementEditor;
|
2007-06-30 17:41:07 +00:00
|
|
|
class PartLine;
|
2009-04-03 19:30:25 +00:00
|
|
|
class PartRectangle;
|
2007-06-30 17:41:07 +00:00
|
|
|
class PartEllipse;
|
|
|
|
class PartPolygon;
|
2007-07-10 22:54:22 +00:00
|
|
|
class PartArc;
|
2007-10-21 16:10:21 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class is the canvas allowing the visual edition of an electrial element.
|
|
|
|
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
|
|
|
*/
|
2007-08-25 03:43:05 +00:00
|
|
|
class ElementScene : public QGraphicsScene {
|
2007-06-30 17:41:07 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
// enum
|
2013-02-08 22:05:20 +00:00
|
|
|
public:
|
2009-04-03 19:30:25 +00:00
|
|
|
enum Behavior { Normal, Line, Rectangle, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
|
2013-02-08 22:05:20 +00:00
|
|
|
enum ItemOption {
|
|
|
|
SortByZValue = 1,
|
|
|
|
IncludeTerminals = 2,
|
|
|
|
IncludeHelperItems = 4,
|
|
|
|
Selected = 8,
|
|
|
|
NonSelected = 16,
|
|
|
|
SelectedOrNot = 24
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(ItemOptions, ItemOption);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-06-30 17:41:07 +00:00
|
|
|
public:
|
2007-08-25 03:43:05 +00:00
|
|
|
ElementScene(QETElementEditor *, QObject * = 0);
|
|
|
|
virtual ~ElementScene();
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
private:
|
2007-08-25 03:43:05 +00:00
|
|
|
ElementScene(const ElementScene &);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2007-06-30 17:41:07 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// List of localized names
|
2007-06-30 17:41:07 +00:00
|
|
|
NamesList _names;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Extra informations
|
2010-02-14 16:28:45 +00:00
|
|
|
QString informations_;
|
2014-06-03 20:21:19 +00:00
|
|
|
/// element type
|
|
|
|
QString m_elmt_type;
|
|
|
|
/// element kind info
|
|
|
|
DiagramContext m_elmt_kindInfo;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// QGraphicsItem manager
|
2007-08-23 15:33:55 +00:00
|
|
|
QGIManager qgi_manager;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Undo stack
|
2007-08-23 21:06:15 +00:00
|
|
|
QUndoStack undo_stack;
|
2009-11-29 22:20:09 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
fsi_pos (first selected item pos) : Position of the forst selected item: used
|
|
|
|
to cancel mouse movements; also used to handle movements using keybard
|
|
|
|
arrwows.
|
2009-11-29 22:20:09 +00:00
|
|
|
*/
|
2007-09-21 11:48:37 +00:00
|
|
|
QPointF fsi_pos;
|
2009-04-03 19:30:25 +00:00
|
|
|
QPointF moving_press_pos;
|
|
|
|
bool moving_parts_;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Variables related to drawing
|
2007-06-30 17:41:07 +00:00
|
|
|
Behavior behavior;
|
|
|
|
PartLine *current_line;
|
2009-04-03 19:30:25 +00:00
|
|
|
PartRectangle *current_rectangle;
|
2007-06-30 17:41:07 +00:00
|
|
|
PartEllipse *current_ellipse;
|
|
|
|
PartPolygon *current_polygon;
|
2007-07-10 22:54:22 +00:00
|
|
|
PartArc *current_arc;
|
2007-08-25 03:43:05 +00:00
|
|
|
QETElementEditor *element_editor;
|
2007-06-30 17:41:07 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Variables to manage the paste area on the scene
|
2009-04-03 19:30:25 +00:00
|
|
|
QGraphicsRectItem *paste_area_;
|
|
|
|
QRectF defined_paste_area_;
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Variables to handle copy/paste with offset
|
2009-04-03 19:30:25 +00:00
|
|
|
QString last_copied_;
|
|
|
|
|
2013-02-08 22:05:15 +00:00
|
|
|
/// Decorator item displayed when at least one item is selected
|
|
|
|
ElementPrimitiveDecorator *decorator_;
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
///< Size of the horizontal grid step
|
2009-04-03 19:30:25 +00:00
|
|
|
int x_grid;
|
2012-11-09 21:09:24 +00:00
|
|
|
///< Size of the vertical grid step
|
2009-04-03 19:30:25 +00:00
|
|
|
int y_grid;
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-06-30 17:41:07 +00:00
|
|
|
public:
|
2007-12-16 14:05:39 +00:00
|
|
|
void setNames(const NamesList &);
|
2007-06-30 17:41:07 +00:00
|
|
|
NamesList names() const;
|
2007-12-09 10:54:59 +00:00
|
|
|
bool internalConnections();
|
|
|
|
void setInternalConnections(bool);
|
2010-02-14 16:28:45 +00:00
|
|
|
QString informations() const;
|
|
|
|
void setInformations(const QString &);
|
2014-06-03 20:21:19 +00:00
|
|
|
QString elementType () const {return m_elmt_type;}
|
|
|
|
DiagramContext elementKindInfo () const {return m_elmt_kindInfo;}
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int xGrid() const;
|
|
|
|
virtual int yGrid() const;
|
|
|
|
virtual void setGrid(int, int);
|
2013-09-21 13:09:23 +00:00
|
|
|
virtual const QDomDocument toXml(bool = true);
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual QRectF boundingRectFromXml(const QDomDocument &);
|
|
|
|
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
|
2007-12-09 12:00:11 +00:00
|
|
|
virtual void reset();
|
2013-02-08 22:05:15 +00:00
|
|
|
virtual QList<CustomElementPart *> primitives() const;
|
2013-02-08 22:05:20 +00:00
|
|
|
virtual QList<QGraphicsItem *> zItems(ItemOptions options = ItemOptions(SortByZValue | IncludeTerminals | SelectedOrNot)) const;
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual ElementContent selectedContent() const;
|
|
|
|
virtual void getPasteArea(const QRectF &);
|
2013-07-28 00:23:10 +00:00
|
|
|
QRectF elementSceneGeometricRect () const;
|
2009-06-01 02:05:20 +00:00
|
|
|
bool containsTerminals() const;
|
2007-08-23 15:33:55 +00:00
|
|
|
QUndoStack &undoStack();
|
|
|
|
QGIManager &qgiManager();
|
2009-04-03 19:30:25 +00:00
|
|
|
static bool clipboardMayContainElement();
|
|
|
|
bool wasCopiedFromThisElement(const QString &);
|
|
|
|
void cut();
|
|
|
|
void copy();
|
|
|
|
void paste();
|
2013-09-17 20:14:30 +00:00
|
|
|
void contextMenu (QContextMenuEvent *event);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
|
|
|
virtual void drawForeground(QPainter *, const QRectF &);
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual void endCurrentBehavior(const QGraphicsSceneMouseEvent *);
|
|
|
|
|
|
|
|
private:
|
2013-02-08 22:05:15 +00:00
|
|
|
QRectF elementContentBoundingRect(const ElementContent &) const;
|
2009-04-03 19:30:25 +00:00
|
|
|
bool applyInformations(const QDomDocument &, QString * = 0);
|
|
|
|
ElementContent loadContent(const QDomDocument &, QString * = 0);
|
|
|
|
ElementContent addContent(const ElementContent &, QString * = 0);
|
|
|
|
ElementContent addContentAtPos(const ElementContent &, const QPointF &, QString * = 0);
|
2013-02-08 22:05:15 +00:00
|
|
|
void addPrimitive(QGraphicsItem *);
|
2009-04-03 19:30:25 +00:00
|
|
|
void initPasteArea();
|
|
|
|
void snapToGrid(QPointF &);
|
|
|
|
bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
|
2012-05-11 21:38:50 +00:00
|
|
|
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
2013-02-08 22:05:15 +00:00
|
|
|
QMutex *decorator_lock_;
|
2013-09-21 13:09:23 +00:00
|
|
|
void centerElementToOrigine();
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void slot_move();
|
|
|
|
void slot_addLine();
|
2009-04-03 19:30:25 +00:00
|
|
|
void slot_addRectangle();
|
2007-06-30 17:41:07 +00:00
|
|
|
void slot_addCircle();
|
|
|
|
void slot_addEllipse();
|
|
|
|
void slot_addPolygon();
|
|
|
|
void slot_addText();
|
|
|
|
void slot_addArc();
|
|
|
|
void slot_addTerminal();
|
|
|
|
void slot_addTextField();
|
2009-04-18 18:08:54 +00:00
|
|
|
void slot_select(const ElementContent &);
|
2007-06-30 17:41:07 +00:00
|
|
|
void slot_selectAll();
|
|
|
|
void slot_deselectAll();
|
|
|
|
void slot_invertSelection();
|
|
|
|
void slot_delete();
|
|
|
|
void slot_editNames();
|
2010-02-14 16:28:45 +00:00
|
|
|
void slot_editAuthorInformations();
|
2014-06-03 20:21:19 +00:00
|
|
|
void slot_editProperties();
|
2007-10-07 18:52:01 +00:00
|
|
|
void slot_bringForward();
|
|
|
|
void slot_raise();
|
|
|
|
void slot_lower();
|
|
|
|
void slot_sendBackward();
|
2013-02-08 22:05:15 +00:00
|
|
|
void managePrimitivesGroups();
|
|
|
|
void stackAction(ElementEditionCommand *);
|
2007-06-30 17:41:07 +00:00
|
|
|
|
|
|
|
signals:
|
2007-12-16 14:05:39 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Signal emitted when the scene requires the element editor to switch back to
|
|
|
|
normal mode.
|
2007-12-16 14:05:39 +00:00
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
void needNormalMode();
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Signal emitted after one or several parts were added
|
2007-11-07 20:23:24 +00:00
|
|
|
void partsAdded();
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Signal emitted after one or several parts were removed
|
2007-11-07 20:23:24 +00:00
|
|
|
void partsRemoved();
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Signal emitted when the zValue of one or several parts change
|
2007-11-07 20:23:24 +00:00
|
|
|
void partsZValueChanged();
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Signal emitted when users have defined the copy/paste area
|
2009-04-03 19:30:25 +00:00
|
|
|
void pasteAreaDefined(const QRectF &);
|
2013-09-21 13:09:23 +00:00
|
|
|
/// Signal emitted when need zoomFit
|
|
|
|
void needZoomFit();
|
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
|
|
|
/**
|
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) {
|
2007-06-30 17:41:07 +00:00
|
|
|
_names = nameslist;
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
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
|
|
|
*/
|
2007-08-25 03:43:05 +00:00
|
|
|
inline NamesList ElementScene::names() const {
|
2007-06-30 17:41:07 +00:00
|
|
|
return(_names);
|
|
|
|
}
|
|
|
|
|
2010-02-14 16:28:45 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return extra informations of the currently edited element
|
2010-02-14 16:28:45 +00:00
|
|
|
*/
|
|
|
|
inline QString ElementScene::informations() const {
|
|
|
|
return(informations_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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) {
|
|
|
|
informations_ = infos;
|
|
|
|
}
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
#endif
|