mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Merge branch 0.4 import image to trunk
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2449 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
33e2dc5c00
commit
0b9adb77d5
@ -46,12 +46,15 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Diagram *parent_diagram) :
|
|||||||
segments(NULL),
|
segments(NULL),
|
||||||
moving_point(false),
|
moving_point(false),
|
||||||
moving_segment(false),
|
moving_segment(false),
|
||||||
previous_z_value(zValue()),
|
|
||||||
modified_path(false),
|
modified_path(false),
|
||||||
has_to_save_profile(false),
|
has_to_save_profile(false),
|
||||||
segments_squares_scale_(1.0),
|
segments_squares_scale_(1.0),
|
||||||
must_highlight_(Conductor::None)
|
must_highlight_(Conductor::None)
|
||||||
{
|
{
|
||||||
|
//set Zvalue at 10 to be upper than the DiagramImageItem
|
||||||
|
setZValue(10);
|
||||||
|
previous_z_value = zValue();
|
||||||
|
|
||||||
// ajout du conducteur a la liste de conducteurs de chacune des deux bornes
|
// ajout du conducteur a la liste de conducteurs de chacune des deux bornes
|
||||||
bool ajout_p1 = terminal1 -> addConductor(this);
|
bool ajout_p1 = terminal1 -> addConductor(this);
|
||||||
bool ajout_p2 = terminal2 -> addConductor(this);
|
bool ajout_p2 = terminal2 -> addConductor(this);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "ghostelement.h"
|
#include "ghostelement.h"
|
||||||
#include "independenttextitem.h"
|
#include "independenttextitem.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
#include "diagramimageitem.h"
|
||||||
|
|
||||||
const int Diagram::xGrid = 10;
|
const int Diagram::xGrid = 10;
|
||||||
const int Diagram::yGrid = 10;
|
const int Diagram::yGrid = 10;
|
||||||
@ -334,6 +335,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
QList<Element *> list_elements;
|
QList<Element *> list_elements;
|
||||||
QList<Conductor *> list_conductors;
|
QList<Conductor *> list_conductors;
|
||||||
QList<DiagramTextItem *> list_texts;
|
QList<DiagramTextItem *> list_texts;
|
||||||
|
QList<DiagramImageItem *> list_images;
|
||||||
|
|
||||||
// Determine les elements a "XMLiser"
|
// Determine les elements a "XMLiser"
|
||||||
foreach(QGraphicsItem *qgi, items()) {
|
foreach(QGraphicsItem *qgi, items()) {
|
||||||
@ -350,6 +352,9 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
} else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(qgi)) {
|
} else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(qgi)) {
|
||||||
if (whole_content) list_texts << iti;
|
if (whole_content) list_texts << iti;
|
||||||
else if (iti -> isSelected()) list_texts << iti;
|
else if (iti -> isSelected()) list_texts << iti;
|
||||||
|
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
|
||||||
|
if (whole_content) list_images << dii;
|
||||||
|
else if (dii -> isSelected()) list_images << dii;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +387,15 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
}
|
}
|
||||||
racine.appendChild(inputs);
|
racine.appendChild(inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save of images
|
||||||
|
if (!list_images.isEmpty()) {
|
||||||
|
QDomElement images = document.createElement("images");
|
||||||
|
foreach (DiagramImageItem *dii, list_images) {
|
||||||
|
images.appendChild(dii -> toXml(document));
|
||||||
|
}
|
||||||
|
racine.appendChild(images);
|
||||||
|
}
|
||||||
|
|
||||||
// on retourne le document XML ainsi genere
|
// on retourne le document XML ainsi genere
|
||||||
return(document);
|
return(document);
|
||||||
@ -536,6 +550,14 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
addIndependentTextItem(iti);
|
addIndependentTextItem(iti);
|
||||||
added_texts << iti;
|
added_texts << iti;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<DiagramImageItem *> added_images;
|
||||||
|
foreach (QDomElement image_xml, QET::findInDomElement(root, "images", "image")) {
|
||||||
|
DiagramImageItem *dii = new DiagramImageItem (this);
|
||||||
|
dii -> fromXml(image_xml);
|
||||||
|
addItem(dii);
|
||||||
|
added_images << dii;
|
||||||
|
}
|
||||||
|
|
||||||
// gere la translation des nouveaux elements et texte si celle-ci est demandee
|
// gere la translation des nouveaux elements et texte si celle-ci est demandee
|
||||||
if (position != QPointF()) {
|
if (position != QPointF()) {
|
||||||
@ -545,6 +567,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
QList<QGraphicsItem *> added_items;
|
QList<QGraphicsItem *> added_items;
|
||||||
foreach (Element *added_element, added_elements) added_items << added_element;
|
foreach (Element *added_element, added_elements) added_items << added_element;
|
||||||
foreach (DiagramTextItem *added_text, added_texts) added_items << added_text;
|
foreach (DiagramTextItem *added_text, added_texts) added_items << added_text;
|
||||||
|
foreach (DiagramImageItem *added_image, added_images) added_items << added_image;
|
||||||
foreach (QGraphicsItem *item, added_items) {
|
foreach (QGraphicsItem *item, added_items) {
|
||||||
QPointF csg = item -> mapToScene(item -> boundingRect()).boundingRect().topLeft();
|
QPointF csg = item -> mapToScene(item -> boundingRect()).boundingRect().topLeft();
|
||||||
qreal px = csg.x();
|
qreal px = csg.x();
|
||||||
@ -566,6 +589,9 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
foreach (DiagramTextItem *added_text, added_texts) {
|
foreach (DiagramTextItem *added_text, added_texts) {
|
||||||
added_text -> setPos(added_text -> pos().x() + diff_x, added_text -> pos().y() + diff_y);
|
added_text -> setPos(added_text -> pos().x() + diff_x, added_text -> pos().y() + diff_y);
|
||||||
}
|
}
|
||||||
|
foreach (DiagramImageItem *added_image, added_images) {
|
||||||
|
added_image -> setPos(added_image -> pos().x() + diff_x, added_image -> pos().y() + diff_y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// chargement de tous les Conducteurs du fichier XML
|
// chargement de tous les Conducteurs du fichier XML
|
||||||
@ -601,6 +627,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
content_ptr -> elements = added_elements.toSet();
|
content_ptr -> elements = added_elements.toSet();
|
||||||
content_ptr -> conductorsToMove = added_conductors.toSet();
|
content_ptr -> conductorsToMove = added_conductors.toSet();
|
||||||
content_ptr -> textFields = added_texts.toSet();
|
content_ptr -> textFields = added_texts.toSet();
|
||||||
|
content_ptr -> images = added_images.toSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -707,6 +734,15 @@ void Diagram::addIndependentTextItem(IndependentTextItem *iti) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Diagram::addDiagramImageItem(DiagramImageItem *dii) {
|
||||||
|
if (!dii || isReadOnly()) return;
|
||||||
|
|
||||||
|
//add image at diagram
|
||||||
|
if (dii -> scene() != this) {
|
||||||
|
addItem(dii);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Enleve un element du schema
|
Enleve un element du schema
|
||||||
@param element Element a enlever
|
@param element Element a enlever
|
||||||
@ -1183,6 +1219,8 @@ DiagramContent Diagram::selectedContent() {
|
|||||||
) {
|
) {
|
||||||
dc.otherConductors << c;
|
dc.otherConductors << c;
|
||||||
}
|
}
|
||||||
|
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(item)) {
|
||||||
|
dc.images << dii;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1227,6 +1265,8 @@ bool Diagram::canRotateSelection() const {
|
|||||||
if (e -> orientation().current() != e -> orientation().next()) {
|
if (e -> orientation().current() != e -> orientation().next()) {
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
} else if (qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
|
||||||
|
return (true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -40,6 +40,7 @@ class IndependentTextItem;
|
|||||||
class QETProject;
|
class QETProject;
|
||||||
class Terminal;
|
class Terminal;
|
||||||
class ConductorTextItem;
|
class ConductorTextItem;
|
||||||
|
class DiagramImageItem;
|
||||||
/**
|
/**
|
||||||
This class represents an electric diagram. It manages its various child
|
This class represents an electric diagram. It manages its various child
|
||||||
elements, conductors and texts and handles their graphic rendering.
|
elements, conductors and texts and handles their graphic rendering.
|
||||||
@ -134,6 +135,7 @@ class Diagram : public QGraphicsScene {
|
|||||||
void addElement(Element *);
|
void addElement(Element *);
|
||||||
void addConductor(Conductor *);
|
void addConductor(Conductor *);
|
||||||
void addIndependentTextItem(IndependentTextItem *);
|
void addIndependentTextItem(IndependentTextItem *);
|
||||||
|
void addDiagramImageItem(DiagramImageItem *);
|
||||||
|
|
||||||
void removeElement(Element *);
|
void removeElement(Element *);
|
||||||
void removeConductor(Conductor *);
|
void removeConductor(Conductor *);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
|
#include "diagramimageitem.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@ -96,6 +97,38 @@ void AddTextCommand::redo() {
|
|||||||
textitem -> setPos(position);
|
textitem -> setPos(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param dia Schema auquel on ajoute une image
|
||||||
|
@param image Image ajoute
|
||||||
|
@param pos Position a laquelle l'image est ajoute
|
||||||
|
@param parent QUndoCommand parent
|
||||||
|
*/
|
||||||
|
AddImageCommand::AddImageCommand(Diagram *dia, DiagramImageItem *image, const QPointF &pos, QUndoCommand *parent):
|
||||||
|
QUndoCommand(QObject::tr("Ajouter une image", "undo caption"), parent),
|
||||||
|
imageitem(image),
|
||||||
|
diagram(dia),
|
||||||
|
position(pos)
|
||||||
|
{
|
||||||
|
diagram -> qgiManager().manage(imageitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Destructor
|
||||||
|
AddImageCommand::~AddImageCommand() {
|
||||||
|
diagram -> qgiManager().release(imageitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Annule l'ajout
|
||||||
|
void AddImageCommand::undo() {
|
||||||
|
diagram -> removeItem(imageitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Refait l'ajout
|
||||||
|
void AddImageCommand::redo() {
|
||||||
|
diagram -> addDiagramImageItem(imageitem);
|
||||||
|
imageitem -> setPos(position - imageitem -> boundingRect().center());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param d Schema auquel on ajoute un conducteur
|
@param d Schema auquel on ajoute un conducteur
|
||||||
@ -176,6 +209,10 @@ void DeleteElementsCommand::undo() {
|
|||||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
foreach(IndependentTextItem *t, removed_content.textFields) {
|
||||||
diagram -> addIndependentTextItem(t);
|
diagram -> addIndependentTextItem(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach(DiagramImageItem *dii, removed_content.images) {
|
||||||
|
diagram -> addItem(dii);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// refait les suppressions
|
/// refait les suppressions
|
||||||
@ -194,6 +231,11 @@ void DeleteElementsCommand::redo() {
|
|||||||
foreach(IndependentTextItem *t, removed_content.textFields) {
|
foreach(IndependentTextItem *t, removed_content.textFields) {
|
||||||
diagram -> removeIndependentTextItem(t);
|
diagram -> removeIndependentTextItem(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//enleve les images
|
||||||
|
foreach(DiagramImageItem *dii, removed_content.images) {
|
||||||
|
diagram -> removeItem(dii);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,7 +352,8 @@ MoveElementsCommand::MoveElementsCommand(
|
|||||||
DiagramContent::Elements |
|
DiagramContent::Elements |
|
||||||
DiagramContent::TextFields |
|
DiagramContent::TextFields |
|
||||||
DiagramContent::ConductorsToUpdate |
|
DiagramContent::ConductorsToUpdate |
|
||||||
DiagramContent::ConductorsToMove
|
DiagramContent::ConductorsToMove |
|
||||||
|
DiagramContent::Images
|
||||||
);
|
);
|
||||||
|
|
||||||
setText(
|
setText(
|
||||||
@ -371,6 +414,11 @@ void MoveElementsCommand::move(const QPointF &actual_movement) {
|
|||||||
foreach(DiagramTextItem *text, content_to_move.textFields) {
|
foreach(DiagramTextItem *text, content_to_move.textFields) {
|
||||||
text -> setPos(text -> pos() + actual_movement);
|
text -> setPos(text -> pos() + actual_movement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deplace les images
|
||||||
|
foreach (DiagramImageItem *dii, content_to_move.images) {
|
||||||
|
dii -> setPos(dii -> pos() + actual_movement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -575,10 +623,11 @@ void ChangeDiagramTextCommand::redo() {
|
|||||||
@param texts Textes a pivoter
|
@param texts Textes a pivoter
|
||||||
@param parent QUndoCommand parent
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, QUndoCommand *parent) :
|
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, const QList<DiagramImageItem *> &images, QUndoCommand *parent) :
|
||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
elements_to_rotate(elements),
|
elements_to_rotate(elements),
|
||||||
texts_to_rotate(texts),
|
texts_to_rotate(texts),
|
||||||
|
images_to_rotate(images),
|
||||||
applied_rotation_angle_(-90.0)
|
applied_rotation_angle_(-90.0)
|
||||||
{
|
{
|
||||||
setText(
|
setText(
|
||||||
@ -587,7 +636,7 @@ RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orienta
|
|||||||
"pivoter %1",
|
"pivoter %1",
|
||||||
"undo caption - %1 is a sentence listing the rotated content"
|
"undo caption - %1 is a sentence listing the rotated content"
|
||||||
)
|
)
|
||||||
).arg(QET::ElementsAndConductorsSentence(elements.count(), 0, texts.count()))
|
).arg(QET::ElementsAndConductorsSentence(elements.count(), 0, texts.count(), images.count()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,6 +658,7 @@ void RotateElementsCommand::undo() {
|
|||||||
}
|
}
|
||||||
else {dti -> rotateBy(-applied_rotation_angle_);}
|
else {dti -> rotateBy(-applied_rotation_angle_);}
|
||||||
}
|
}
|
||||||
|
foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(-applied_rotation_angle_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// refait le pivotement
|
/// refait le pivotement
|
||||||
@ -624,6 +674,7 @@ void RotateElementsCommand::redo() {
|
|||||||
}
|
}
|
||||||
dti -> rotateBy(applied_rotation_angle_);
|
dti -> rotateBy(applied_rotation_angle_);
|
||||||
}
|
}
|
||||||
|
foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(applied_rotation_angle_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,7 @@ class DiagramTextItem;
|
|||||||
class Element;
|
class Element;
|
||||||
class ElementTextItem;
|
class ElementTextItem;
|
||||||
class IndependentTextItem;
|
class IndependentTextItem;
|
||||||
|
class DiagramImageItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This command adds an element to a particular diagram.
|
This command adds an element to a particular diagram.
|
||||||
@ -83,6 +84,33 @@ class AddTextCommand : public QUndoCommand {
|
|||||||
QPointF position;
|
QPointF position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
This command adds an image item to a particular diagram
|
||||||
|
*/
|
||||||
|
class AddImageCommand : public QUndoCommand {
|
||||||
|
//constructors, destructor
|
||||||
|
public:
|
||||||
|
AddImageCommand (Diagram *, DiagramImageItem *, const QPointF &, QUndoCommand * = 0);
|
||||||
|
virtual ~AddImageCommand();
|
||||||
|
private:
|
||||||
|
AddImageCommand(const AddImageCommand &);
|
||||||
|
|
||||||
|
//methods
|
||||||
|
public:
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
private:
|
||||||
|
/// added image item
|
||||||
|
DiagramImageItem *imageitem;
|
||||||
|
/// diagram the image item is added to
|
||||||
|
Diagram *diagram;
|
||||||
|
/// position of the image item on the diagram
|
||||||
|
QPointF position;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This command adds a conductor to a particular diagram.
|
This command adds a conductor to a particular diagram.
|
||||||
*/
|
*/
|
||||||
@ -302,7 +330,7 @@ class ChangeDiagramTextCommand : public QUndoCommand {
|
|||||||
class RotateElementsCommand : public QUndoCommand {
|
class RotateElementsCommand : public QUndoCommand {
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &, QUndoCommand * = 0);
|
RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &, const QList<DiagramImageItem *> &, QUndoCommand * = 0);
|
||||||
virtual ~RotateElementsCommand();
|
virtual ~RotateElementsCommand();
|
||||||
private:
|
private:
|
||||||
RotateElementsCommand(const RotateElementsCommand &);
|
RotateElementsCommand(const RotateElementsCommand &);
|
||||||
@ -321,6 +349,8 @@ class RotateElementsCommand : public QUndoCommand {
|
|||||||
QHash<Element *, QET::Orientation> elements_to_rotate;
|
QHash<Element *, QET::Orientation> elements_to_rotate;
|
||||||
/// text items to be rotated
|
/// text items to be rotated
|
||||||
QList<DiagramTextItem *> texts_to_rotate;
|
QList<DiagramTextItem *> texts_to_rotate;
|
||||||
|
/// images item to be rotated
|
||||||
|
QList<DiagramImageItem *> images_to_rotate;
|
||||||
/// angle of rotation to be applied to text items
|
/// angle of rotation to be applied to text items
|
||||||
qreal applied_rotation_angle_;
|
qreal applied_rotation_angle_;
|
||||||
/// previous state of each conductor text item
|
/// previous state of each conductor text item
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "independenttextitem.h"
|
#include "independenttextitem.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
|
#include "diagramimageitem.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur par defaut. Ne contient rien.
|
Constructeur par defaut. Ne contient rien.
|
||||||
@ -33,6 +34,7 @@ DiagramContent::DiagramContent() {
|
|||||||
DiagramContent::DiagramContent(const DiagramContent &other) :
|
DiagramContent::DiagramContent(const DiagramContent &other) :
|
||||||
elements(other.elements),
|
elements(other.elements),
|
||||||
textFields(other.textFields),
|
textFields(other.textFields),
|
||||||
|
images(other.images),
|
||||||
conductorsToUpdate(other.conductorsToUpdate),
|
conductorsToUpdate(other.conductorsToUpdate),
|
||||||
conductorsToMove(other.conductorsToMove),
|
conductorsToMove(other.conductorsToMove),
|
||||||
otherConductors(other.otherConductors)
|
otherConductors(other.otherConductors)
|
||||||
@ -68,6 +70,7 @@ QList<Conductor *> DiagramContent::conductors(int filter) const {
|
|||||||
void DiagramContent::clear() {
|
void DiagramContent::clear() {
|
||||||
elements.clear();
|
elements.clear();
|
||||||
textFields.clear();
|
textFields.clear();
|
||||||
|
images.clear();
|
||||||
conductorsToUpdate.clear();
|
conductorsToUpdate.clear();
|
||||||
conductorsToMove.clear();
|
conductorsToMove.clear();
|
||||||
otherConductors.clear();
|
otherConductors.clear();
|
||||||
@ -82,6 +85,7 @@ QList<QGraphicsItem *> DiagramContent::items(int filter) const {
|
|||||||
foreach(QGraphicsItem *qgi, conductors(filter)) items_list << qgi;
|
foreach(QGraphicsItem *qgi, conductors(filter)) items_list << qgi;
|
||||||
if (filter & Elements) foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
if (filter & Elements) foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
||||||
if (filter & TextFields) foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
if (filter & TextFields) foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
||||||
|
if (filter & Images) foreach(QGraphicsItem *qgi, images) items_list << qgi;
|
||||||
if (filter & SelectedOnly) {
|
if (filter & SelectedOnly) {
|
||||||
foreach(QGraphicsItem *qgi, items_list) {
|
foreach(QGraphicsItem *qgi, items_list) {
|
||||||
if (!qgi -> isSelected()) items_list.removeOne(qgi);
|
if (!qgi -> isSelected()) items_list.removeOne(qgi);
|
||||||
@ -99,12 +103,14 @@ int DiagramContent::count(int filter) const {
|
|||||||
if (filter & SelectedOnly) {
|
if (filter & SelectedOnly) {
|
||||||
if (filter & Elements) foreach(Element *element, elements) { if (element -> isSelected()) ++ count; }
|
if (filter & Elements) foreach(Element *element, elements) { if (element -> isSelected()) ++ count; }
|
||||||
if (filter & TextFields) foreach(DiagramTextItem *dti, textFields) { if (dti -> isSelected()) ++ count; }
|
if (filter & TextFields) foreach(DiagramTextItem *dti, textFields) { if (dti -> isSelected()) ++ count; }
|
||||||
|
if (filter & Images) foreach(DiagramImageItem *dii, images) { if (dii -> isSelected()) ++ count; }
|
||||||
if (filter & ConductorsToMove) foreach(Conductor *conductor, conductorsToMove) { if (conductor -> isSelected()) ++ count; }
|
if (filter & ConductorsToMove) foreach(Conductor *conductor, conductorsToMove) { if (conductor -> isSelected()) ++ count; }
|
||||||
if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate) { if (conductor -> isSelected()) ++ count; }
|
if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate) { if (conductor -> isSelected()) ++ count; }
|
||||||
if (filter & OtherConductors) foreach(Conductor *conductor, otherConductors) { if (conductor -> isSelected()) ++ count; }
|
if (filter & OtherConductors) foreach(Conductor *conductor, otherConductors) { if (conductor -> isSelected()) ++ count; }
|
||||||
} else {
|
} else {
|
||||||
if (filter & Elements) count += elements.count();
|
if (filter & Elements) count += elements.count();
|
||||||
if (filter & TextFields) count += textFields.count();
|
if (filter & TextFields) count += textFields.count();
|
||||||
|
if (filter & Images) count += images.count();
|
||||||
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
||||||
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
||||||
if (filter & OtherConductors) count += otherConductors.count();
|
if (filter & OtherConductors) count += otherConductors.count();
|
||||||
@ -122,12 +128,14 @@ QString DiagramContent::sentence(int filter) const {
|
|||||||
int elements_count = (filter & Elements) ? elements.count() : 0;
|
int elements_count = (filter & Elements) ? elements.count() : 0;
|
||||||
int conductors_count = conductors(filter).count();
|
int conductors_count = conductors(filter).count();
|
||||||
int textfields_count = (filter & TextFields) ? textFields.count() : 0;
|
int textfields_count = (filter & TextFields) ? textFields.count() : 0;
|
||||||
|
int images_count = (filter & Images) ? images.count() : 0;
|
||||||
|
|
||||||
return(
|
return(
|
||||||
QET::ElementsAndConductorsSentence(
|
QET::ElementsAndConductorsSentence(
|
||||||
elements_count,
|
elements_count,
|
||||||
conductors_count,
|
conductors_count,
|
||||||
textfields_count
|
textfields_count,
|
||||||
|
images_count
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
class Conductor;
|
class Conductor;
|
||||||
class Element;
|
class Element;
|
||||||
class IndependentTextItem;
|
class IndependentTextItem;
|
||||||
|
class DiagramImageItem;
|
||||||
/**
|
/**
|
||||||
This class provides a container that makes the transmission of diagram content
|
This class provides a container that makes the transmission of diagram content
|
||||||
to other functions/methods easier. The different kind of items are made
|
to other functions/methods easier. The different kind of items are made
|
||||||
@ -40,6 +41,7 @@ class DiagramContent {
|
|||||||
enum Filter {
|
enum Filter {
|
||||||
Elements = 1,
|
Elements = 1,
|
||||||
TextFields = 2,
|
TextFields = 2,
|
||||||
|
Images = 3,
|
||||||
ConductorsToMove = 4,
|
ConductorsToMove = 4,
|
||||||
ConductorsToUpdate = 8,
|
ConductorsToUpdate = 8,
|
||||||
OtherConductors = 16,
|
OtherConductors = 16,
|
||||||
@ -52,6 +54,8 @@ class DiagramContent {
|
|||||||
QSet<Element *> elements;
|
QSet<Element *> elements;
|
||||||
/// Hold independent text items
|
/// Hold independent text items
|
||||||
QSet<IndependentTextItem *> textFields;
|
QSet<IndependentTextItem *> textFields;
|
||||||
|
/// Hold image
|
||||||
|
QSet<DiagramImageItem *> images;
|
||||||
/// Hold conductors that would get updated considering electrical elements are moved
|
/// Hold conductors that would get updated considering electrical elements are moved
|
||||||
QSet<Conductor *> conductorsToUpdate;
|
QSet<Conductor *> conductorsToUpdate;
|
||||||
/// Hold conductors that would be moved as is considering electrical elements are moved
|
/// Hold conductors that would be moved as is considering electrical elements are moved
|
||||||
|
381
sources/diagramimageitem.cpp
Normal file
381
sources/diagramimageitem.cpp
Normal file
@ -0,0 +1,381 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2013 QElectroTech Team
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
#include "diagramimageitem.h"
|
||||||
|
#include "diagramcommands.h"
|
||||||
|
#include "qet.h"
|
||||||
|
#include "qetapp.h"
|
||||||
|
|
||||||
|
DiagramImageItem::DiagramImageItem(Diagram *parent_diagram) :
|
||||||
|
QGraphicsPixmapItem(0, parent_diagram)
|
||||||
|
{
|
||||||
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
|
#if QT_VERSION >= 0x040600
|
||||||
|
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
|
#endif
|
||||||
|
//connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DiagramImageItem::DiagramImageItem
|
||||||
|
* @param parent
|
||||||
|
* @param parent_diagram
|
||||||
|
*/
|
||||||
|
DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, Diagram *parent_diagram) :
|
||||||
|
QGraphicsPixmapItem(pixmap, 0, parent_diagram),
|
||||||
|
first_move_(false)
|
||||||
|
{
|
||||||
|
setCursor(Qt::PointingHandCursor);
|
||||||
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
|
#if QT_VERSION >= 0x040600
|
||||||
|
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
|
#endif
|
||||||
|
//connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
DiagramImageItem::~DiagramImageItem() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return le Diagram auquel ce image appartient, ou 0 si ce image n'est
|
||||||
|
rattache a aucun schema
|
||||||
|
*/
|
||||||
|
Diagram *DiagramImageItem::diagram() const {
|
||||||
|
return(qobject_cast<Diagram *>(scene()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Permet de tourner le image a un angle donne de maniere absolue.
|
||||||
|
Un angle de 0 degres correspond a un image horizontal non retourne.
|
||||||
|
@param rotation Nouvel angle de rotation de ce image
|
||||||
|
@see applyRotation
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::setRotationAngle(const qreal &rotation_angle) {
|
||||||
|
qreal applied_rotation = QET::correctAngle(rotation_angle);
|
||||||
|
applyRotation(applied_rotation - rotation());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Permet de tourner le image de maniere relative.
|
||||||
|
L'angle added_rotation est ajoute a l'orientation actuelle du image.
|
||||||
|
@param added_rotation Angle a ajouter a la rotation actuelle
|
||||||
|
@see applyRotation
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::rotateBy(const qreal &added_rotation) {
|
||||||
|
qreal applied_added_rotation = QET::correctAngle(added_rotation);
|
||||||
|
applyRotation(applied_added_rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Traduit en coordonnees de la scene un mouvement / vecteur initialement
|
||||||
|
exprime en coordonnees locales.
|
||||||
|
@param movement Vecteur exprime en coordonnees locales
|
||||||
|
@return le meme vecteur, exprime en coordonnees de la scene
|
||||||
|
*/
|
||||||
|
QPointF DiagramImageItem::mapMovementToScene(const QPointF &movement) const {
|
||||||
|
// on definit deux points en coordonnees locales
|
||||||
|
QPointF local_origin(0.0, 0.0);
|
||||||
|
QPointF local_movement_point(movement);
|
||||||
|
|
||||||
|
// on les mappe sur la scene
|
||||||
|
QPointF scene_origin(mapToScene(local_origin));
|
||||||
|
QPointF scene_movement_point(mapToScene(local_movement_point));
|
||||||
|
|
||||||
|
// on calcule le vecteur represente par ces deux points
|
||||||
|
return(scene_movement_point - scene_origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Traduit en coordonnees locales un mouvement / vecteur initialement
|
||||||
|
exprime en coordonnees de la scene.
|
||||||
|
@param movement Vecteur exprime en coordonnees de la scene
|
||||||
|
@return le meme vecteur, exprime en coordonnees locales
|
||||||
|
*/
|
||||||
|
QPointF DiagramImageItem::mapMovementFromScene(const QPointF &movement) const {
|
||||||
|
// on definit deux points sur la scene
|
||||||
|
QPointF scene_origin(0.0, 0.0);
|
||||||
|
QPointF scene_movement_point(movement);
|
||||||
|
|
||||||
|
// on les mappe sur ce QGraphicsItem
|
||||||
|
QPointF local_origin(mapFromScene(scene_origin));
|
||||||
|
QPointF local_movement_point(mapFromScene(scene_movement_point));
|
||||||
|
|
||||||
|
// on calcule le vecteur represente par ces deux points
|
||||||
|
return(local_movement_point - local_origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Traduit en coordonnees de l'item parent un mouvement / vecteur initialement
|
||||||
|
exprime en coordonnees locales.
|
||||||
|
@param movement Vecteur exprime en coordonnees locales
|
||||||
|
@return le meme vecteur, exprime en coordonnees du parent
|
||||||
|
*/
|
||||||
|
QPointF DiagramImageItem::mapMovementToParent(const QPointF &movement) const {
|
||||||
|
// on definit deux points en coordonnees locales
|
||||||
|
QPointF local_origin(0.0, 0.0);
|
||||||
|
QPointF local_movement_point(movement);
|
||||||
|
|
||||||
|
// on les mappe sur la scene
|
||||||
|
QPointF parent_origin(mapToParent(local_origin));
|
||||||
|
QPointF parent_movement_point(mapToParent(local_movement_point));
|
||||||
|
|
||||||
|
// on calcule le vecteur represente par ces deux points
|
||||||
|
return(parent_movement_point - parent_origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Traduit en coordonnees locales un mouvement / vecteur initialement
|
||||||
|
exprime en coordonnees du parent.
|
||||||
|
@param movement Vecteur exprime en coordonnees du parent
|
||||||
|
@return le meme vecteur, exprime en coordonnees locales
|
||||||
|
*/
|
||||||
|
QPointF DiagramImageItem::mapMovementFromParent(const QPointF &movement) const {
|
||||||
|
// on definit deux points sur le parent
|
||||||
|
QPointF parent_origin(0.0, 0.0);
|
||||||
|
QPointF parent_movement_point(movement);
|
||||||
|
|
||||||
|
// on les mappe sur ce QGraphicsItem
|
||||||
|
QPointF local_origin(mapFromParent(parent_origin));
|
||||||
|
QPointF local_movement_point(mapFromParent(parent_movement_point));
|
||||||
|
|
||||||
|
// on calcule le vecteur represente par ces deux points
|
||||||
|
return(local_movement_point - local_origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Dessine le champ de image.
|
||||||
|
Cette methode delegue simplement le travail a QGraphicsPixmapItem::paint apres
|
||||||
|
avoir desactive l'antialiasing.
|
||||||
|
@param painter Le QPainter a utiliser pour dessiner le champ de image
|
||||||
|
@param option Les options de style pour le champ de image
|
||||||
|
@param widget Le QWidget sur lequel on dessine
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
|
||||||
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
QGraphicsPixmapItem::paint(painter, option, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere la prise de focus du champ de image
|
||||||
|
@param e Objet decrivant la prise de focus
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::focusInEvent(QFocusEvent *e) {
|
||||||
|
QGraphicsPixmapItem::focusInEvent(e);
|
||||||
|
|
||||||
|
// empeche le deplacement du image pendant son edition
|
||||||
|
setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere la perte de focus du champ de image
|
||||||
|
@param e Objet decrivant la perte de focus
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::focusOutEvent(QFocusEvent *e) {
|
||||||
|
QGraphicsPixmapItem::focusOutEvent(e);
|
||||||
|
|
||||||
|
/*// deselectionne le image
|
||||||
|
QTextCursor cursor = textCursor();
|
||||||
|
cursor.clearSelection();
|
||||||
|
setTextCursor(cursor);
|
||||||
|
|
||||||
|
// hack a la con pour etre re-entrant
|
||||||
|
setTextInteractionFlags(Qt::NoTextInteraction);
|
||||||
|
|
||||||
|
// autorise de nouveau le deplacement du image
|
||||||
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
QTimer::singleShot(0, this, SIGNAL(lostFocus()));*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere le clic sur le champ de texte
|
||||||
|
@param e Objet decrivant l'evenement souris
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
|
first_move_ = true;
|
||||||
|
if (e -> modifiers() & Qt::ControlModifier) {
|
||||||
|
setSelected(!isSelected());
|
||||||
|
}
|
||||||
|
QGraphicsItem::mousePressEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere les double-clics sur ce champ de image.
|
||||||
|
@param event un QGraphicsSceneMouseEvent decrivant le double-clic
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
/*if (!(textInteractionFlags() & Qt::imageditable)) {
|
||||||
|
// rend le champ de image editable
|
||||||
|
setTextInteractionFlags(Qt::imageditorInteraction);
|
||||||
|
|
||||||
|
// edite le champ de image
|
||||||
|
setFocus(Qt::MouseFocusReason);
|
||||||
|
} else {
|
||||||
|
QGraphicsPixmapItem::mouseDoubleClickEvent(event);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DiagramImageItem::mouseMoveEvent
|
||||||
|
* Gere les mouvements de souris lies a l'image
|
||||||
|
* @param e Objet decrivant l'evenement souris
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
|
if (isSelected() && e -> buttons() & Qt::LeftButton) {
|
||||||
|
//Image is moving
|
||||||
|
if(diagram()) {
|
||||||
|
if (first_move_) {
|
||||||
|
//It's the first movement, we signal it to parent diagram
|
||||||
|
diagram() -> beginMoveElements(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//we apply the mouse movement
|
||||||
|
QPointF old_pos = pos();
|
||||||
|
setPos(mapToParent(e -> pos()) - matrix().map(e -> buttonDownPos(Qt::LeftButton)));
|
||||||
|
//we calcul the real movement apply by setPos()
|
||||||
|
QPointF effective_movement = pos() - old_pos;
|
||||||
|
|
||||||
|
if (diagram()) {
|
||||||
|
//we signal the real movement apply to diagram,
|
||||||
|
//who he apply to other selected item
|
||||||
|
diagram() -> continueMoveElements(effective_movement);
|
||||||
|
}
|
||||||
|
} else e -> ignore();
|
||||||
|
|
||||||
|
if (first_move_) first_move_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DiagramImageItem::mouseReleaseEvent
|
||||||
|
* Gere le relachement de souris
|
||||||
|
* Cette methode a ete reimplementee pour tenir a jour la liste
|
||||||
|
* des images à deplacer au niveau du schema.
|
||||||
|
* @param e Objet decrivant l'evenement souris
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
|
if (diagram()) {
|
||||||
|
diagram() -> endMoveElements();
|
||||||
|
}
|
||||||
|
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
||||||
|
QGraphicsItem::mouseReleaseEvent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Effectue la rotation du image en elle-meme
|
||||||
|
Pour les DiagramImageItem, la rotation s'effectue autour du point (0, 0).
|
||||||
|
Cette methode peut toutefois etre redefinie dans des classes filles
|
||||||
|
@param angle Angle de la rotation a effectuer
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::applyRotation(const qreal &angle) {
|
||||||
|
// un simple appel a QGraphicsPixmapItem::setRotation suffit
|
||||||
|
setTransformOriginPoint(boundingRect().center());
|
||||||
|
QGraphicsPixmapItem::setRotation(QGraphicsPixmapItem::rotation() + angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la position du champ de image en veillant a ce qu'il
|
||||||
|
reste sur la grille du schema auquel il appartient.
|
||||||
|
@param p Nouvelles coordonnees de l'element
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::setPos(const QPointF &p) {
|
||||||
|
if (p == pos()) return;
|
||||||
|
// pas la peine de positionner sur la grille si l'element n'est pas sur un Diagram
|
||||||
|
if (scene()) {
|
||||||
|
// arrondit l'abscisse a 10 px pres
|
||||||
|
int p_x = qRound(p.x() / (Diagram::xGrid * 1.0)) * Diagram::xGrid;
|
||||||
|
// arrondit l'ordonnee a 10 px pres
|
||||||
|
int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid;
|
||||||
|
QGraphicsPixmapItem::setPos(p_x, p_y);
|
||||||
|
} else QGraphicsPixmapItem::setPos(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la position du champ de image en veillant a ce que l'il
|
||||||
|
reste sur la grille du schema auquel il appartient.
|
||||||
|
@param x Nouvelle abscisse de l'element
|
||||||
|
@param y Nouvelle ordonnee de l'element
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::setPos(qreal x, qreal y) {
|
||||||
|
setPos(QPointF(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return la position du champ de image
|
||||||
|
*/
|
||||||
|
QPointF DiagramImageItem::pos() const {
|
||||||
|
return(QGraphicsPixmapItem::pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rend le champ de image non focusable
|
||||||
|
void DiagramImageItem::setNonFocusable() {
|
||||||
|
setFlag(QGraphicsPixmapItem::ItemIsFocusable, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Edit the image with ....
|
||||||
|
*/
|
||||||
|
void DiagramImageItem::edit() {
|
||||||
|
// waiting
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load the image from this xml element
|
||||||
|
@param e xml element that define an image
|
||||||
|
*/
|
||||||
|
bool DiagramImageItem::fromXml(const QDomElement &e) {
|
||||||
|
if (e.tagName() != "image") return (false);
|
||||||
|
QDomNode image_node = e.firstChild();
|
||||||
|
if (!image_node.isText()) return (false);
|
||||||
|
|
||||||
|
//load xml text image to QByteArray
|
||||||
|
QByteArray array;
|
||||||
|
array = QByteArray::fromBase64(e.text().toAscii());
|
||||||
|
|
||||||
|
//Set QPixmap from the @array
|
||||||
|
QPixmap pixmap;
|
||||||
|
pixmap.loadFromData(array);
|
||||||
|
setPixmap(pixmap);
|
||||||
|
|
||||||
|
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||||
|
if (e.hasAttribute("rotation")) setRotationAngle(e.attribute("rotation").toDouble());
|
||||||
|
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param document Le document XML a utiliser
|
||||||
|
@return L'element XML representant ce champ de texte
|
||||||
|
*/
|
||||||
|
QDomElement DiagramImageItem::toXml(QDomDocument &document) const {
|
||||||
|
QDomElement result = document.createElement("image");
|
||||||
|
//write some attribute
|
||||||
|
result.setAttribute("x", QString("%1").arg(pos().x()));
|
||||||
|
result.setAttribute("y", QString("%1").arg(pos().y()));
|
||||||
|
if (rotation()) result.setAttribute("rotation", QString("%1").arg(rotation()));
|
||||||
|
|
||||||
|
//write the pixmap in the xml element after he was been transformed to base64
|
||||||
|
QByteArray array;
|
||||||
|
QBuffer buffer(&array);
|
||||||
|
buffer.open(QIODevice::ReadWrite);
|
||||||
|
pixmap().save(&buffer, "PNG");
|
||||||
|
QDomText base64 = document.createTextNode(array.toBase64());
|
||||||
|
result.appendChild(base64);
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
85
sources/diagramimageitem.h
Normal file
85
sources/diagramimageitem.h
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2013 QElectroTech Team
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
#ifndef DIAGRAM_IMAGE_ITEM_H
|
||||||
|
#define DIAGRAM_IMAGE_ITEM_H
|
||||||
|
#include <QtGui>
|
||||||
|
#include "diagram.h"
|
||||||
|
/**
|
||||||
|
This class represents a selectable, movable and editable image on a
|
||||||
|
diagram.
|
||||||
|
@see QGraphicsItem::GraphicsItemFlags
|
||||||
|
*/
|
||||||
|
class DiagramImageItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
// constructors, destructor
|
||||||
|
public:
|
||||||
|
DiagramImageItem(Diagram * = 0);
|
||||||
|
DiagramImageItem(const QPixmap &, Diagram * = 0);
|
||||||
|
virtual ~DiagramImageItem();
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
public:
|
||||||
|
enum { Type = UserType + 1007 };
|
||||||
|
|
||||||
|
// methods
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a
|
||||||
|
DiagramImageItem
|
||||||
|
@return the QGraphicsItem type
|
||||||
|
*/
|
||||||
|
virtual int type() const { return Type; }
|
||||||
|
Diagram *diagram() const;
|
||||||
|
|
||||||
|
virtual bool fromXml(const QDomElement &);
|
||||||
|
virtual QDomElement toXml(QDomDocument &) const;
|
||||||
|
|
||||||
|
virtual void setPos(const QPointF &);
|
||||||
|
virtual void setPos(qreal, qreal);
|
||||||
|
virtual QPointF pos() const;
|
||||||
|
void setRotationAngle(const qreal &);
|
||||||
|
void rotateBy(const qreal &);
|
||||||
|
void edit();
|
||||||
|
QPointF mapMovementToScene(const QPointF &) const;
|
||||||
|
QPointF mapMovementFromScene(const QPointF &) const;
|
||||||
|
QPointF mapMovementToParent(const QPointF &) const;
|
||||||
|
QPointF mapMovementFromParent(const QPointF &) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||||
|
void focusInEvent(QFocusEvent *);
|
||||||
|
void focusOutEvent(QFocusEvent *);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *e);
|
||||||
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
void applyRotation(const qreal &);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/// signal emitted when the image field loses focus
|
||||||
|
void lostFocus();
|
||||||
|
/// signal emitted after image was changed
|
||||||
|
void diagramImageChanged(DiagramImageItem *, const QString &, const QString &);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setNonFocusable();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool first_move_;
|
||||||
|
};
|
||||||
|
#endif
|
@ -32,6 +32,8 @@ DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, Diagram *parent_diagram)
|
|||||||
previous_text_(),
|
previous_text_(),
|
||||||
rotation_angle_(0.0)
|
rotation_angle_(0.0)
|
||||||
{
|
{
|
||||||
|
//set Zvalue at 10 to be upper than the DiagramImageItem
|
||||||
|
setZValue(10);
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QETApp::diagramTextsFont());
|
setFont(QETApp::diagramTextsFont());
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
@ -52,6 +54,8 @@ DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent, Dia
|
|||||||
previous_text_(text),
|
previous_text_(text),
|
||||||
rotation_angle_(0.0)
|
rotation_angle_(0.0)
|
||||||
{
|
{
|
||||||
|
//set Zvalue at 10 to be upper than the DiagramImageItem
|
||||||
|
setZValue(10);
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QETApp::diagramTextsFont());
|
setFont(QETApp::diagramTextsFont());
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "conductortextitem.h"
|
#include "conductortextitem.h"
|
||||||
#include "elementtextitem.h"
|
#include "elementtextitem.h"
|
||||||
#include "independenttextitem.h"
|
#include "independenttextitem.h"
|
||||||
|
#include "diagramimageitem.h"
|
||||||
#include "titleblockpropertieswidget.h"
|
#include "titleblockpropertieswidget.h"
|
||||||
#include "templatelocation.h"
|
#include "templatelocation.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
@ -37,6 +38,10 @@
|
|||||||
#include "qeticons.h"
|
#include "qeticons.h"
|
||||||
#include "qetmessagebox.h"
|
#include "qetmessagebox.h"
|
||||||
#include "qtextorientationspinboxwidget.h"
|
#include "qtextorientationspinboxwidget.h"
|
||||||
|
#include <QGraphicsObject>
|
||||||
|
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,10 +49,11 @@
|
|||||||
@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
|
@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
|
||||||
@param parent Le QWidget parent de cette vue de schema
|
@param parent Le QWidget parent de cette vue de schema
|
||||||
*/
|
*/
|
||||||
DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), is_adding_text(false), is_moving_view_(false) {
|
DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent) {
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
setInteractive(true);
|
setInteractive(true);
|
||||||
|
current_behavior = noAction;
|
||||||
|
|
||||||
QString whatsthis = tr(
|
QString whatsthis = tr(
|
||||||
"Ceci est la zone dans laquelle vous concevez vos sch\351mas en y ajoutant"
|
"Ceci est la zone dans laquelle vous concevez vos sch\351mas en y ajoutant"
|
||||||
" des \351l\351ments et en posant des conducteurs entre leurs bornes. Il est"
|
" des \351l\351ments et en posant des conducteurs entre leurs bornes. Il est"
|
||||||
@ -140,6 +146,7 @@ void DiagramView::rotateSelection() {
|
|||||||
// recupere les elements et les champs de texte a pivoter
|
// recupere les elements et les champs de texte a pivoter
|
||||||
QHash<Element *, QET::Orientation> elements_to_rotate;
|
QHash<Element *, QET::Orientation> elements_to_rotate;
|
||||||
QList<DiagramTextItem *> texts_to_rotate;
|
QList<DiagramTextItem *> texts_to_rotate;
|
||||||
|
QList<DiagramImageItem *> images_to_rotate;
|
||||||
foreach (QGraphicsItem *item, scene -> selectedItems()) {
|
foreach (QGraphicsItem *item, scene -> selectedItems()) {
|
||||||
if (Element *e = qgraphicsitem_cast<Element *>(item)) {
|
if (Element *e = qgraphicsitem_cast<Element *>(item)) {
|
||||||
elements_to_rotate.insert(e, e -> orientation().current());
|
elements_to_rotate.insert(e, e -> orientation().current());
|
||||||
@ -152,12 +159,14 @@ void DiagramView::rotateSelection() {
|
|||||||
if (eti -> parentItem() && !eti -> parentItem() -> isSelected()) {
|
if (eti -> parentItem() && !eti -> parentItem() -> isSelected()) {
|
||||||
texts_to_rotate << eti;
|
texts_to_rotate << eti;
|
||||||
}
|
}
|
||||||
|
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(item)) {
|
||||||
|
images_to_rotate << dii;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// effectue les rotations s'il y a quelque chose a pivoter
|
// effectue les rotations s'il y a quelque chose a pivoter
|
||||||
if (elements_to_rotate.isEmpty() && texts_to_rotate.isEmpty()) return;
|
if (elements_to_rotate.isEmpty() && texts_to_rotate.isEmpty() && images_to_rotate.isEmpty()) return;
|
||||||
scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate, texts_to_rotate));
|
scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate, texts_to_rotate, images_to_rotate));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagramView::rotateTexts() {
|
void DiagramView::rotateTexts() {
|
||||||
@ -417,11 +426,16 @@ void DiagramView::mousePressEvent(QMouseEvent *e) {
|
|||||||
switchToVisualisationModeIfNeeded(e);
|
switchToVisualisationModeIfNeeded(e);
|
||||||
fresh_focus_in_ = false;
|
fresh_focus_in_ = false;
|
||||||
}
|
}
|
||||||
if (isInteractive() && !scene -> isReadOnly()) {
|
if (isInteractive() && !scene -> isReadOnly() && current_behavior > noAction && e -> buttons() == Qt::LeftButton) {
|
||||||
if (is_adding_text && e -> buttons() == Qt::LeftButton) {
|
switch (current_behavior) {
|
||||||
addDiagramTextAtPos(mapToScene(e -> pos()));
|
case addingText:
|
||||||
is_adding_text = false;
|
addDiagramTextAtPos(mapToScene(e -> pos()));
|
||||||
|
break;
|
||||||
|
case addingImage:
|
||||||
|
addDiagramImageAtPos(mapToScene(e -> pos()));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
current_behavior = noAction;
|
||||||
}
|
}
|
||||||
// workaround for drag view with hold wheel click and drag mouse
|
// workaround for drag view with hold wheel click and drag mouse
|
||||||
// see also mouseMoveEvent() and mouseReleaseEvent()
|
// see also mouseMoveEvent() and mouseReleaseEvent()
|
||||||
@ -632,7 +646,8 @@ bool DiagramView::hasCopiableItems() {
|
|||||||
foreach(QGraphicsItem *qgi, scene -> selectedItems()) {
|
foreach(QGraphicsItem *qgi, scene -> selectedItems()) {
|
||||||
if (
|
if (
|
||||||
qgraphicsitem_cast<Element *>(qgi) ||
|
qgraphicsitem_cast<Element *>(qgi) ||
|
||||||
qgraphicsitem_cast<IndependentTextItem *>(qgi)
|
qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
|
||||||
|
qgraphicsitem_cast<DiagramImageItem *>(qgi)
|
||||||
) {
|
) {
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -649,7 +664,8 @@ bool DiagramView::hasDeletableItems() {
|
|||||||
if (
|
if (
|
||||||
qgraphicsitem_cast<Element *>(qgi) ||
|
qgraphicsitem_cast<Element *>(qgi) ||
|
||||||
qgraphicsitem_cast<Conductor *>(qgi) ||
|
qgraphicsitem_cast<Conductor *>(qgi) ||
|
||||||
qgraphicsitem_cast<IndependentTextItem *>(qgi)
|
qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
|
||||||
|
qgraphicsitem_cast<DiagramImageItem *>(qgi)
|
||||||
) {
|
) {
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -1143,7 +1159,7 @@ bool DiagramView::event(QEvent *e) {
|
|||||||
bool DiagramView::switchToVisualisationModeIfNeeded(QInputEvent *e) {
|
bool DiagramView::switchToVisualisationModeIfNeeded(QInputEvent *e) {
|
||||||
if (isCtrlShifting(e) && !selectedItemHasFocus()) {
|
if (isCtrlShifting(e) && !selectedItemHasFocus()) {
|
||||||
if (dragMode() != QGraphicsView::ScrollHandDrag) {
|
if (dragMode() != QGraphicsView::ScrollHandDrag) {
|
||||||
is_moving_view_ = true;
|
current_behavior = dragView;
|
||||||
setVisualisationMode();
|
setVisualisationMode();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -1157,9 +1173,9 @@ bool DiagramView::switchToVisualisationModeIfNeeded(QInputEvent *e) {
|
|||||||
otherwise.
|
otherwise.
|
||||||
*/
|
*/
|
||||||
bool DiagramView::switchToSelectionModeIfNeeded(QInputEvent *e) {
|
bool DiagramView::switchToSelectionModeIfNeeded(QInputEvent *e) {
|
||||||
if (is_moving_view_ && !selectedItemHasFocus() && !isCtrlShifting(e)) {
|
if (current_behavior == dragView && !selectedItemHasFocus() && !isCtrlShifting(e)) {
|
||||||
setSelectionMode();
|
setSelectionMode();
|
||||||
is_moving_view_ = false;
|
current_behavior = noAction;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
@ -1201,12 +1217,11 @@ bool DiagramView::selectedItemHasFocus() {
|
|||||||
*/
|
*/
|
||||||
void DiagramView::addText() {
|
void DiagramView::addText() {
|
||||||
if (scene -> isReadOnly()) return;
|
if (scene -> isReadOnly()) return;
|
||||||
is_adding_text = true;
|
current_behavior = addingText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** To edit the text through the htmlEditor
|
||||||
To edit the text through the htmlEditor
|
|
||||||
*/
|
*/
|
||||||
void DiagramView::editText() {
|
void DiagramView::editText() {
|
||||||
if (scene -> isReadOnly()) return;
|
if (scene -> isReadOnly()) return;
|
||||||
@ -1225,6 +1240,50 @@ void DiagramView::editText() {
|
|||||||
else texts_to_edit.at(0)->edit();
|
else texts_to_edit.at(0)->edit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DiagramView::addImage
|
||||||
|
*/
|
||||||
|
void DiagramView::addImage() {
|
||||||
|
if (scene -> isReadOnly()) return;
|
||||||
|
|
||||||
|
QString pathPictures = QDesktopServices::storageLocation ( QDesktopServices::PicturesLocation );
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Selectionner une image..."), pathPictures.toStdString().c_str(), tr("Image Files (*.png *.jpg *.bmp *.svg)"));
|
||||||
|
if(fileName.isEmpty()) {
|
||||||
|
emit ImageAddedCanceled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = image_to_add_.load(fileName);
|
||||||
|
if(!ret){
|
||||||
|
QMessageBox::critical(this, tr("Erreur"), tr("Impossible de charger l'image...D\351soler :("));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
current_behavior = addingImage;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief DiagramView::addDiagramImageAtPos
|
||||||
|
* @param pos
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DiagramImageItem *DiagramView::addDiagramImageAtPos(const QPointF &pos) {
|
||||||
|
|
||||||
|
if (!isInteractive() || scene -> isReadOnly()) return(0);
|
||||||
|
|
||||||
|
// cree un nouveau champ image
|
||||||
|
DiagramImageItem *Imageitem = new DiagramImageItem( QPixmap::fromImage(image_to_add_) );
|
||||||
|
|
||||||
|
// le place a la position pos en gerant l'annulation
|
||||||
|
scene -> undoStack().push(new AddImageCommand(scene, Imageitem, pos));
|
||||||
|
adjustSceneRect();
|
||||||
|
|
||||||
|
// emet le signal ImageAdded
|
||||||
|
emit(ImageAdded(false));
|
||||||
|
|
||||||
|
return(Imageitem);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cree un nouveau champ de texte et le place a la position pos
|
Cree un nouveau champ de texte et le place a la position pos
|
||||||
en gerant l'annulation ; enfin, le signal textAdded est emis.
|
en gerant l'annulation ; enfin, le signal textAdded est emis.
|
||||||
@ -1243,7 +1302,7 @@ IndependentTextItem *DiagramView::addDiagramTextAtPos(const QPointF &pos) {
|
|||||||
|
|
||||||
// emet le signal textAdded
|
// emet le signal textAdded
|
||||||
emit(textAdded(false));
|
emit(textAdded(false));
|
||||||
|
|
||||||
return(iti);
|
return(iti);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ class Conductor;
|
|||||||
class Diagram;
|
class Diagram;
|
||||||
class Element;
|
class Element;
|
||||||
class IndependentTextItem;
|
class IndependentTextItem;
|
||||||
|
class DiagramImageItem;
|
||||||
class QETDiagramEditor;
|
class QETDiagramEditor;
|
||||||
/**
|
/**
|
||||||
This class provides a widget to render an electric diagram in an editable,
|
This class provides a widget to render an electric diagram in an editable,
|
||||||
@ -37,6 +38,8 @@ class DiagramView : public QGraphicsView {
|
|||||||
DiagramView(Diagram * = 0, QWidget * = 0);
|
DiagramView(Diagram * = 0, QWidget * = 0);
|
||||||
virtual ~DiagramView();
|
virtual ~DiagramView();
|
||||||
|
|
||||||
|
enum behavior {noAction, addingText, addingImage, dragView};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiagramView(const DiagramView &);
|
DiagramView(const DiagramView &);
|
||||||
|
|
||||||
@ -47,13 +50,13 @@ class DiagramView : public QGraphicsView {
|
|||||||
QAction *paste_here;
|
QAction *paste_here;
|
||||||
QAction *find_element_;
|
QAction *find_element_;
|
||||||
QPoint paste_here_pos;
|
QPoint paste_here_pos;
|
||||||
bool is_adding_text;
|
behavior current_behavior;
|
||||||
bool is_moving_view_; ///< Indicate whether the visualisation mode has been enabled due to mouse/keyboard interactions
|
|
||||||
bool fresh_focus_in_; ///< Indicate the focus was freshly gained
|
bool fresh_focus_in_; ///< Indicate the focus was freshly gained
|
||||||
ElementsLocation next_location_;
|
ElementsLocation next_location_;
|
||||||
QPoint next_position_;
|
QPoint next_position_;
|
||||||
QPointF reference_view_;
|
QPointF reference_view_;
|
||||||
QPointF center_view_;
|
QPointF center_view_;
|
||||||
|
QImage image_to_add_;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
@ -71,7 +74,9 @@ class DiagramView : public QGraphicsView {
|
|||||||
bool hasDeletableItems();
|
bool hasDeletableItems();
|
||||||
void addText();
|
void addText();
|
||||||
void editText();
|
void editText();
|
||||||
|
void addImage();
|
||||||
IndependentTextItem *addDiagramTextAtPos(const QPointF &);
|
IndependentTextItem *addDiagramTextAtPos(const QPointF &);
|
||||||
|
DiagramImageItem *addDiagramImageAtPos(const QPointF &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
||||||
@ -120,6 +125,10 @@ class DiagramView : public QGraphicsView {
|
|||||||
void editElementRequired(const ElementsLocation &);
|
void editElementRequired(const ElementsLocation &);
|
||||||
/// Signal emitted when users want to edit and/or duplicate an existing title block template
|
/// Signal emitted when users want to edit and/or duplicate an existing title block template
|
||||||
void editTitleBlockTemplate(const QString &, bool);
|
void editTitleBlockTemplate(const QString &, bool);
|
||||||
|
/// Signal emitted after a image was added
|
||||||
|
void ImageAdded(bool);
|
||||||
|
/// Signal emmitted fater windows selection image have been canceled
|
||||||
|
void ImageAddedCanceled(bool);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void selectNothing();
|
void selectNothing();
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "independenttextitem.h"
|
#include "independenttextitem.h"
|
||||||
|
#include "diagramimageitem.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@ -138,6 +139,13 @@ void ElementsMover::continueMovement(const QPointF &movement) {
|
|||||||
if (movement_driver_ && text_field == movement_driver_) continue;
|
if (movement_driver_ && text_field == movement_driver_) continue;
|
||||||
text_field -> setPos(text_field -> pos() + movement);
|
text_field -> setPos(text_field -> pos() + movement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//deplace les images
|
||||||
|
foreach(DiagramImageItem *dii, moved_content_.images) {
|
||||||
|
if (movement_driver_ && dii == movement_driver_) continue;
|
||||||
|
dii -> setPos(dii -> pos() + movement);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,10 +196,11 @@ bool QET::attributeIsAReal(const QDomElement &e, QString nom_attribut, qreal *re
|
|||||||
@param elements_count nombre d'elements
|
@param elements_count nombre d'elements
|
||||||
@param conductors_count nombre de conducteurs
|
@param conductors_count nombre de conducteurs
|
||||||
@param texts_count nombre de champs de texte
|
@param texts_count nombre de champs de texte
|
||||||
|
@param images_count nombre d'images
|
||||||
@return la proposition decrivant le nombre d'elements, de conducteurs et de
|
@return la proposition decrivant le nombre d'elements, de conducteurs et de
|
||||||
textes
|
textes
|
||||||
*/
|
*/
|
||||||
QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_count, int texts_count) {
|
QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_count, int texts_count, int images_count) {
|
||||||
QString text;
|
QString text;
|
||||||
if (elements_count) {
|
if (elements_count) {
|
||||||
text += QObject::tr(
|
text += QObject::tr(
|
||||||
@ -207,13 +208,15 @@ QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_co
|
|||||||
"part of a sentence listing the content of a diagram",
|
"part of a sentence listing the content of a diagram",
|
||||||
elements_count
|
elements_count
|
||||||
);
|
);
|
||||||
if (conductors_count && texts_count) {
|
if ((conductors_count && texts_count) ||
|
||||||
|
(conductors_count && images_count) ||
|
||||||
|
(texts_count && images_count)) {
|
||||||
text += QObject::tr(
|
text += QObject::tr(
|
||||||
", ",
|
", ",
|
||||||
"separator between elements and conductors in a sentence "
|
"separator between elements and conductors in a sentence "
|
||||||
"listing the content of a diagram"
|
"listing the content of a diagram"
|
||||||
);
|
);
|
||||||
} else if (conductors_count || texts_count) {
|
} else if (conductors_count || texts_count || images_count) {
|
||||||
text += QObject::tr(
|
text += QObject::tr(
|
||||||
" et ",
|
" et ",
|
||||||
"separator between elements and conductors (or texts) in a "
|
"separator between elements and conductors (or texts) in a "
|
||||||
@ -228,7 +231,14 @@ QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_co
|
|||||||
"part of a sentence listing the content of a diagram",
|
"part of a sentence listing the content of a diagram",
|
||||||
conductors_count
|
conductors_count
|
||||||
);
|
);
|
||||||
if (texts_count) {
|
if (texts_count && images_count) {
|
||||||
|
text += QObject::tr(
|
||||||
|
", ",
|
||||||
|
"separator between elements and conductors in a sentence "
|
||||||
|
"listing the content of a diagram"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (texts_count || images_count) {
|
||||||
text += QObject::tr(
|
text += QObject::tr(
|
||||||
" et ",
|
" et ",
|
||||||
"separator between conductors and texts in a sentence listing "
|
"separator between conductors and texts in a sentence listing "
|
||||||
@ -243,6 +253,21 @@ QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_co
|
|||||||
"part of a sentence listing the content of a diagram",
|
"part of a sentence listing the content of a diagram",
|
||||||
texts_count
|
texts_count
|
||||||
);
|
);
|
||||||
|
if (images_count) {
|
||||||
|
text += QObject::tr(
|
||||||
|
" et ",
|
||||||
|
"separator between conductors and texts in a sentence listing "
|
||||||
|
"the content of a diagram"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (images_count) {
|
||||||
|
text += QObject::tr(
|
||||||
|
"%n image(s)",
|
||||||
|
"part of a sentence listing the content of a diagram",
|
||||||
|
images_count
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return(text);
|
return(text);
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ namespace QET {
|
|||||||
bool orthogonalProjection(const QPointF &, const QLineF &, QPointF * = 0);
|
bool orthogonalProjection(const QPointF &, const QLineF &, QPointF * = 0);
|
||||||
bool attributeIsAnInteger(const QDomElement &, QString , int * = NULL);
|
bool attributeIsAnInteger(const QDomElement &, QString , int * = NULL);
|
||||||
bool attributeIsAReal(const QDomElement &, QString , qreal * = NULL);
|
bool attributeIsAReal(const QDomElement &, QString , qreal * = NULL);
|
||||||
QString ElementsAndConductorsSentence(int, int, int = 0);
|
QString ElementsAndConductorsSentence(int, int, int = 0, int = 0);
|
||||||
QList<QDomElement> findInDomElement(const QDomElement &, const QString &);
|
QList<QDomElement> findInDomElement(const QDomElement &, const QString &);
|
||||||
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
|
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
|
||||||
QList<QChar> forbiddenCharacters();
|
QList<QChar> forbiddenCharacters();
|
||||||
|
@ -216,6 +216,7 @@ void QETDiagramEditor::actions() {
|
|||||||
add_text = new QAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte"), this);
|
add_text = new QAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte"), this);
|
||||||
add_edittext = new QAction(QET::Icons::EditText, tr("\311diter le champ de texte"), this);
|
add_edittext = new QAction(QET::Icons::EditText, tr("\311diter le champ de texte"), this);
|
||||||
add_column = new QAction(QET::Icons::EditTableInsertColumnRight, tr("Ajouter une colonne"), this);
|
add_column = new QAction(QET::Icons::EditTableInsertColumnRight, tr("Ajouter une colonne"), this);
|
||||||
|
add_image = new QAction(QET::Icons::adding_image, tr("Ajouter une image"), this);
|
||||||
remove_column = new QAction(QET::Icons::EditTableDeleteColumn, tr("Enlever une colonne"), this);
|
remove_column = new QAction(QET::Icons::EditTableDeleteColumn, tr("Enlever une colonne"), this);
|
||||||
add_row = new QAction(QET::Icons::EditTableInsertRowUnder, tr("Ajouter une ligne"), this);
|
add_row = new QAction(QET::Icons::EditTableInsertRowUnder, tr("Ajouter une ligne"), this);
|
||||||
remove_row = new QAction(QET::Icons::EditTableDeleteRow, tr("Enlever une ligne"), this);
|
remove_row = new QAction(QET::Icons::EditTableDeleteRow, tr("Enlever une ligne"), this);
|
||||||
@ -337,6 +338,7 @@ void QETDiagramEditor::actions() {
|
|||||||
|
|
||||||
// traitements speciaux
|
// traitements speciaux
|
||||||
add_text -> setCheckable(true);
|
add_text -> setCheckable(true);
|
||||||
|
add_image -> setCheckable(true);
|
||||||
windowed_view_mode -> setCheckable(true);
|
windowed_view_mode -> setCheckable(true);
|
||||||
tabbed_view_mode -> setCheckable(true);
|
tabbed_view_mode -> setCheckable(true);
|
||||||
mode_selection -> setCheckable(true);
|
mode_selection -> setCheckable(true);
|
||||||
@ -399,6 +401,7 @@ void QETDiagramEditor::actions() {
|
|||||||
connect(infos_diagram, SIGNAL(triggered()), this, SLOT(editCurrentDiagramProperties()));
|
connect(infos_diagram, SIGNAL(triggered()), this, SLOT(editCurrentDiagramProperties()));
|
||||||
connect(add_text, SIGNAL(triggered()), this, SLOT(slot_addText()) );
|
connect(add_text, SIGNAL(triggered()), this, SLOT(slot_addText()) );
|
||||||
connect(add_edittext, SIGNAL(triggered()), this, SLOT(slot_editText()) );
|
connect(add_edittext, SIGNAL(triggered()), this, SLOT(slot_editText()) );
|
||||||
|
connect(add_image, SIGNAL(triggered()), this, SLOT(slot_addImage()) );
|
||||||
connect(add_column, SIGNAL(triggered()), this, SLOT(slot_addColumn()) );
|
connect(add_column, SIGNAL(triggered()), this, SLOT(slot_addColumn()) );
|
||||||
connect(remove_column, SIGNAL(triggered()), this, SLOT(slot_removeColumn()) );
|
connect(remove_column, SIGNAL(triggered()), this, SLOT(slot_removeColumn()) );
|
||||||
connect(add_row, SIGNAL(triggered()), this, SLOT(slot_addRow()) );
|
connect(add_row, SIGNAL(triggered()), this, SLOT(slot_addRow()) );
|
||||||
@ -514,7 +517,7 @@ void QETDiagramEditor::menus() {
|
|||||||
menu_affichage -> addAction(zoom_content);
|
menu_affichage -> addAction(zoom_content);
|
||||||
menu_affichage -> addAction(zoom_fit);
|
menu_affichage -> addAction(zoom_fit);
|
||||||
menu_affichage -> addAction(zoom_reset);
|
menu_affichage -> addAction(zoom_reset);
|
||||||
|
|
||||||
// menu Fenetres
|
// menu Fenetres
|
||||||
slot_updateWindowsMenu();
|
slot_updateWindowsMenu();
|
||||||
}
|
}
|
||||||
@ -562,6 +565,7 @@ void QETDiagramEditor::toolbar() {
|
|||||||
diagram_bar -> addAction(infos_diagram);
|
diagram_bar -> addAction(infos_diagram);
|
||||||
diagram_bar -> addAction(conductor_reset);
|
diagram_bar -> addAction(conductor_reset);
|
||||||
diagram_bar -> addAction(add_text);
|
diagram_bar -> addAction(add_text);
|
||||||
|
diagram_bar -> addAction(add_image);
|
||||||
|
|
||||||
// ajout de la barre d'outils a la fenetre principale
|
// ajout de la barre d'outils a la fenetre principale
|
||||||
addToolBar(Qt::TopToolBarArea, main_bar);
|
addToolBar(Qt::TopToolBarArea, main_bar);
|
||||||
@ -1150,6 +1154,7 @@ void QETDiagramEditor::slot_updateActions() {
|
|||||||
remove_column -> setEnabled(editable_diagram);
|
remove_column -> setEnabled(editable_diagram);
|
||||||
add_row -> setEnabled(editable_diagram);
|
add_row -> setEnabled(editable_diagram);
|
||||||
remove_row -> setEnabled(editable_diagram);
|
remove_row -> setEnabled(editable_diagram);
|
||||||
|
add_image ->setEnabled(editable_diagram);
|
||||||
|
|
||||||
//display the beta feature only in debug mode
|
//display the beta feature only in debug mode
|
||||||
#ifdef QT_NO_DEBUG
|
#ifdef QT_NO_DEBUG
|
||||||
@ -1193,8 +1198,8 @@ void QETDiagramEditor::slot_updateComplexActions() {
|
|||||||
// actions ayant aussi besoin d'items (elements, conducteurs, textes, ...) selectionnes
|
// actions ayant aussi besoin d'items (elements, conducteurs, textes, ...) selectionnes
|
||||||
bool copiable_items = dv ? (dv -> hasCopiableItems()) : false;
|
bool copiable_items = dv ? (dv -> hasCopiableItems()) : false;
|
||||||
bool deletable_items = dv ? (dv -> hasDeletableItems()) : false;
|
bool deletable_items = dv ? (dv -> hasDeletableItems()) : false;
|
||||||
cut -> setEnabled(editable_diagram && copiable_items);
|
cut -> setEnabled(editable_diagram);
|
||||||
copy -> setEnabled(copiable_items);
|
copy -> setEnabled(editable_diagram);
|
||||||
delete_selection -> setEnabled(editable_diagram && deletable_items);
|
delete_selection -> setEnabled(editable_diagram && deletable_items);
|
||||||
rotate_selection -> setEnabled(editable_diagram && dv -> diagram() -> canRotateSelection());
|
rotate_selection -> setEnabled(editable_diagram && dv -> diagram() -> canRotateSelection());
|
||||||
selection_prop -> setEnabled(deletable_items);
|
selection_prop -> setEnabled(deletable_items);
|
||||||
@ -1482,11 +1487,20 @@ void QETDiagramEditor::slot_resetConductors() {
|
|||||||
Ajoute un texte au schema courant
|
Ajoute un texte au schema courant
|
||||||
*/
|
*/
|
||||||
void QETDiagramEditor::slot_addText() {
|
void QETDiagramEditor::slot_addText() {
|
||||||
|
add_image -> setChecked(false);
|
||||||
if (DiagramView *dv = currentDiagram()) {
|
if (DiagramView *dv = currentDiagram()) {
|
||||||
dv -> addText();
|
dv -> addText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
Ajoute une image au schema courant
|
||||||
|
*/
|
||||||
|
void QETDiagramEditor::slot_addImage() {
|
||||||
|
add_text -> setChecked(false);
|
||||||
|
if (DiagramView *dv = currentDiagram()) {
|
||||||
|
dv -> addImage();
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
to Edit en text through the html editor
|
to Edit en text through the html editor
|
||||||
*/
|
*/
|
||||||
@ -1754,6 +1768,8 @@ void QETDiagramEditor::diagramWasAdded(DiagramView *dv) {
|
|||||||
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
|
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
|
||||||
connect(dv, SIGNAL(textAdded(bool)), add_text, SLOT(setChecked(bool)));
|
connect(dv, SIGNAL(textAdded(bool)), add_text, SLOT(setChecked(bool)));
|
||||||
connect(dv, SIGNAL(textAdded(bool)), add_edittext, SLOT(setChecked(bool)));
|
connect(dv, SIGNAL(textAdded(bool)), add_edittext, SLOT(setChecked(bool)));
|
||||||
|
connect(dv, SIGNAL(ImageAdded(bool)), add_image, SLOT(setChecked(bool)));
|
||||||
|
connect(dv, SIGNAL(ImageAddedCanceled(bool)), add_image, SLOT(setChecked(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,6 +124,7 @@ class QETDiagramEditor : public QETMainWindow {
|
|||||||
void slot_resetConductors();
|
void slot_resetConductors();
|
||||||
void slot_addText();
|
void slot_addText();
|
||||||
void slot_editText();
|
void slot_editText();
|
||||||
|
void slot_addImage();
|
||||||
void setWindowedMode();
|
void setWindowedMode();
|
||||||
void setTabbedMode();
|
void setTabbedMode();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
@ -215,7 +216,7 @@ class QETDiagramEditor : public QETMainWindow {
|
|||||||
QAction *cascade_window; ///< Show MDI subwindows as cascade
|
QAction *cascade_window; ///< Show MDI subwindows as cascade
|
||||||
QAction *prev_window; ///< Switch to the previous document
|
QAction *prev_window; ///< Switch to the previous document
|
||||||
QAction *next_window; ///< Switch to the next document
|
QAction *next_window; ///< Switch to the next document
|
||||||
|
QAction *add_image; ///< Tool to add an independent image item on diagrams
|
||||||
private:
|
private:
|
||||||
QMdiArea workspace;
|
QMdiArea workspace;
|
||||||
QSignalMapper windowMapper;
|
QSignalMapper windowMapper;
|
||||||
|
@ -152,6 +152,7 @@ namespace QET {
|
|||||||
QIcon ZoomIn;
|
QIcon ZoomIn;
|
||||||
QIcon ZoomOriginal;
|
QIcon ZoomOriginal;
|
||||||
QIcon ZoomOut;
|
QIcon ZoomOut;
|
||||||
|
QIcon adding_image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +222,7 @@ void QET::Icons::initIcons() {
|
|||||||
EditClear .addFile(":/ico/16x16/edit-clear.png");
|
EditClear .addFile(":/ico/16x16/edit-clear.png");
|
||||||
EditClear .addFile(":/ico/22x22/edit-clear.png");
|
EditClear .addFile(":/ico/22x22/edit-clear.png");
|
||||||
EditText .addFile(":/ico/22x22/names.png");
|
EditText .addFile(":/ico/22x22/names.png");
|
||||||
|
adding_image .addFile(":/ico/22x22/insert-image.png");
|
||||||
|
|
||||||
if (rtl) {
|
if (rtl) {
|
||||||
EditClearLocationBar.addPixmap(QPixmap(":/ico/16x16/edit-clear-locationbar-ltr.png").transformed(reverse));
|
EditClearLocationBar.addPixmap(QPixmap(":/ico/16x16/edit-clear-locationbar-ltr.png").transformed(reverse));
|
||||||
|
@ -161,6 +161,7 @@ namespace QET {
|
|||||||
extern QIcon ZoomIn;
|
extern QIcon ZoomIn;
|
||||||
extern QIcon ZoomOriginal;
|
extern QIcon ZoomOriginal;
|
||||||
extern QIcon ZoomOut;
|
extern QIcon ZoomOut;
|
||||||
|
extern QIcon adding_image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -60,8 +60,8 @@ void QGIManager::release(QGraphicsItem *qgi) {
|
|||||||
if (!qgi_manager.contains(qgi)) return;
|
if (!qgi_manager.contains(qgi)) return;
|
||||||
-- qgi_manager[qgi];
|
-- qgi_manager[qgi];
|
||||||
if (qgi_manager[qgi] <= 0 && !(scene -> items().contains(qgi))) {
|
if (qgi_manager[qgi] <= 0 && !(scene -> items().contains(qgi))) {
|
||||||
qgi_manager.remove(qgi);
|
|
||||||
delete qgi;
|
delete qgi;
|
||||||
|
qgi_manager.remove(qgi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user