Merge sources dir branch devel to trunk

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2613 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
scorpio810 2013-11-14 10:11:22 +00:00
parent 434849c3eb
commit 971ce1facb
54 changed files with 594 additions and 1152 deletions

View File

@ -64,8 +64,8 @@ DEPENDPATH += .
INCLUDEPATH += sources sources/editor sources/titleblock INCLUDEPATH += sources sources/editor sources/titleblock
# Fichiers sources # Fichiers sources
HEADERS += sources/*.h sources/ui/*.h sources/editor/*.h sources/titleblock/*.h sources/richtext/*.h HEADERS += sources/*.h sources/ui/*.h sources/editor/*.h sources/titleblock/*.h sources/richtext/*.h sources/qetgraphicsitem/*.h
SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp sources/qetgraphicsitem/*.cpp
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
RESOURCES += qelectrotech.qrc RESOURCES += qelectrotech.qrc

View File

@ -18,7 +18,7 @@
#ifndef CONDUCTORAUTONUMEROTATION_H #ifndef CONDUCTORAUTONUMEROTATION_H
#define CONDUCTORAUTONUMEROTATION_H #define CONDUCTORAUTONUMEROTATION_H
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "numerotationcontext.h" #include "numerotationcontext.h"
#include "autonumerotation.h" #include "autonumerotation.h"

View File

@ -6,7 +6,7 @@
#include <QSet> #include <QSet>
#include <QMultiMap> #include <QMultiMap>
#include <QString> #include <QString>
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "diagram.h" #include "diagram.h"
class ConductorAutoNumerotationWidget : public QDialog class ConductorAutoNumerotationWidget : public QDialog

View File

@ -16,7 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "conductorprofile.h" #include "conductorprofile.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "conductorsegmentprofile.h" #include "conductorsegmentprofile.h"
/// Constructeur /// Constructeur

View File

@ -17,7 +17,7 @@
*/ */
#include "conductorpropertieswidget.h" #include "conductorpropertieswidget.h"
#include <QtGui> #include <QtGui>
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "qeticons.h" #include "qeticons.h"
#include "qetapp.h" #include "qetapp.h"

View File

@ -16,21 +16,21 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <math.h> #include <math.h>
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
#include "diagram.h" #include "diagram.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "diagramcontent.h" #include "diagramcontent.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "elementtextitem.h" #include "qetgraphicsitem/elementtextitem.h"
#include "elementsmover.h" #include "elementsmover.h"
#include "elementtextsmover.h" #include "elementtextsmover.h"
#include "exportdialog.h" #include "exportdialog.h"
#include "ghostelement.h" #include "qetgraphicsitem/ghostelement.h"
#include "independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "qetapp.h" #include "qetapp.h"
#include "diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
const int Diagram::xGrid = 10; const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10; const int Diagram::yGrid = 10;
@ -555,7 +555,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
QList<DiagramImageItem *> added_images; QList<DiagramImageItem *> added_images;
foreach (QDomElement image_xml, QET::findInDomElement(root, "images", "image")) { foreach (QDomElement image_xml, QET::findInDomElement(root, "images", "image")) {
DiagramImageItem *dii = new DiagramImageItem (this); DiagramImageItem *dii = new DiagramImageItem ();
dii -> fromXml(image_xml); dii -> fromXml(image_xml);
addItem(dii); addItem(dii);
added_images << dii; added_images << dii;
@ -1256,20 +1256,11 @@ DiagramContent Diagram::selectedContent() {
*/ */
bool Diagram::canRotateSelection() const { bool Diagram::canRotateSelection() const {
foreach(QGraphicsItem * qgi, selectedItems()) { foreach(QGraphicsItem * qgi, selectedItems()) {
if (qgraphicsitem_cast<IndependentTextItem *>(qgi)) { if (qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
return(true); qgraphicsitem_cast<ConductorTextItem *>(qgi) ||
} else if (qgraphicsitem_cast<ElementTextItem *>(qgi)) { qgraphicsitem_cast<DiagramImageItem *>(qgi) ||
return(true); qgraphicsitem_cast<ElementTextItem *>(qgi) ||
} else if (qgraphicsitem_cast<ConductorTextItem *>(qgi)) { qgraphicsitem_cast<Element *>(qgi)) return (true);
return(true);
} else if (Element *e = qgraphicsitem_cast<Element *>(qgi)) {
// l'element est-il pivotable ?
if (e -> orientation().current() != e -> orientation().next()) {
return(true);
}
} else if (qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
return (true);
}
} }
return(false); return(false);
} }

View File

@ -16,16 +16,16 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "diagramcommands.h" #include "diagramcommands.h"
#include "element.h" #include "qetgraphicsitem/element.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "diagram.h" #include "diagram.h"
#include "elementtextitem.h" #include "qetgraphicsitem/elementtextitem.h"
#include "independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "qgimanager.h" #include "qgimanager.h"
#include "diagram.h" #include "diagram.h"
#include "diagramtextitem.h" #include "qetgraphicsitem/diagramtextitem.h"
#include "diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
/** /**
Constructeur Constructeur
@ -630,12 +630,12 @@ 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, const QList<DiagramImageItem *> &images, QUndoCommand *parent) : RotateElementsCommand::RotateElementsCommand(const QList<Element *> &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), images_to_rotate(images),
applied_rotation_angle_(-90.0) applied_rotation_angle_(90.0)
{ {
setText( setText(
QString( QString(
@ -653,14 +653,14 @@ RotateElementsCommand::~RotateElementsCommand() {
/// defait le pivotement /// defait le pivotement
void RotateElementsCommand::undo() { void RotateElementsCommand::undo() {
foreach(Element *e, elements_to_rotate.keys()) { foreach(Element *e, elements_to_rotate) {
rotateElement(e, elements_to_rotate[e]); e -> rotateBy(-applied_rotation_angle_);
} }
foreach(DiagramTextItem *dti, texts_to_rotate) { foreach(DiagramTextItem *dti, texts_to_rotate) {
//ConductorTextItem have a default rotation angle, we apply a specific treatment //ConductorTextItem have a default rotation angle, we apply a specific treatment
if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) { if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) {
cti -> forceRotateByUser(previous_rotate_by_user_[cti]); cti -> forceRotateByUser(previous_rotate_by_user_[cti]);
(cti -> wasRotateByUser()) ? cti -> rotateBy(-appliedRotationAngle()) : (cti -> wasRotateByUser()) ? cti -> rotateBy(-applied_rotation_angle_) :
cti -> parentConductor() -> adjustTextItemPosition(); cti -> parentConductor() -> adjustTextItemPosition();
} }
else {dti -> rotateBy(-applied_rotation_angle_);} else {dti -> rotateBy(-applied_rotation_angle_);}
@ -670,8 +670,8 @@ void RotateElementsCommand::undo() {
/// refait le pivotement /// refait le pivotement
void RotateElementsCommand::redo() { void RotateElementsCommand::redo() {
foreach(Element *e, elements_to_rotate.keys()) { foreach(Element *e, elements_to_rotate) {
rotateElement(e, e -> orientation().next()); e -> rotateBy(applied_rotation_angle_);
} }
foreach(DiagramTextItem *dti, texts_to_rotate) { foreach(DiagramTextItem *dti, texts_to_rotate) {
//we grab the previous rotation by user of each ConductorTextItem //we grab the previous rotation by user of each ConductorTextItem
@ -684,50 +684,6 @@ void RotateElementsCommand::redo() {
foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(applied_rotation_angle_); foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(applied_rotation_angle_);
} }
/**
@return l'angle de rotation applique aux textes
*/
qreal RotateElementsCommand::appliedRotationAngle() const {
return(applied_rotation_angle_);
}
/**
@param angle l'angle de rotation a appliquer aux textes
*/
void RotateElementsCommand::setAppliedRotationAngle(const qreal &angle) {
applied_rotation_angle_ = QET::correctAngle(angle);
}
/**
Passe un element a une orientation donnee, en prenant soin de gerer ses textes enfants
@param element Element a orienter soigneusement
@param orientation Nouvelle orientation de l'element
*/
void RotateElementsCommand::rotateElement(Element *element, QET::Orientation orientation) {
qreal rotation_value = 90.0 * (orientation - element -> orientation().current());
element -> setOrientation(orientation);
element -> update();
if (rotation_value) {
// repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations"
foreach(ElementTextItem *eti, element -> texts()) {
if (!eti -> followParentRotations()) {
// on souhaite pivoter le champ de texte par rapport a son centre
QPointF eti_center = eti -> boundingRect().center();
// pour ce faire, on repere la position de son centre par rapport a son parent
QPointF parent_eti_center_before = eti -> mapToParent(eti_center);
// on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte
eti -> rotateBy(-rotation_value);
// on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent
QPointF parent_eti_center_after = eti -> mapToParent(eti_center);
// on determine la translation a appliquer
QPointF eti_translation = parent_eti_center_before - parent_eti_center_after;
// on applique cette translation
eti -> setPos(eti -> pos() + eti_translation);
}
}
}
}
/** /**
Constructeur Constructeur
@param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action @param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action

View File

@ -19,7 +19,7 @@
#define DIAGRAM_COMMANDS_H #define DIAGRAM_COMMANDS_H
#include <QtGui> #include <QtGui>
#include "borderproperties.h" #include "borderproperties.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "conductorproperties.h" #include "conductorproperties.h"
#include "diagramcontent.h" #include "diagramcontent.h"
#include "titleblockproperties.h" #include "titleblockproperties.h"
@ -330,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 *> &, const QList<DiagramImageItem *> &, QUndoCommand * = 0); RotateElementsCommand(const QList<Element *> &elements, const QList<DiagramTextItem *> &, const QList<DiagramImageItem *> &, QUndoCommand * = 0);
virtual ~RotateElementsCommand(); virtual ~RotateElementsCommand();
private: private:
RotateElementsCommand(const RotateElementsCommand &); RotateElementsCommand(const RotateElementsCommand &);
@ -339,14 +339,11 @@ class RotateElementsCommand : public QUndoCommand {
public: public:
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
qreal appliedRotationAngle() const;
void setAppliedRotationAngle(const qreal &);
static void rotateElement(Element *, QET::Orientation);
// attributes // attributes
private: private:
/// hold rotated elements along with their former orientation /// hold rotated elements along with their former orientation
QHash<Element *, QET::Orientation> elements_to_rotate; QList<Element *> 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 /// images item to be rotated

View File

@ -17,10 +17,10 @@
*/ */
#include "diagramcontent.h" #include "diagramcontent.h"
#include <QGraphicsItem> #include <QGraphicsItem>
#include "element.h" #include "qetgraphicsitem/element.h"
#include "independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
/** /**
Constructeur par defaut. Ne contient rien. Constructeur par defaut. Ne contient rien.

View File

@ -1,323 +0,0 @@
/*
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),
first_move_(false)
{
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
#endif
}
/**
* @brief DiagramImageItem::DiagramImageItem
* @param parent
* @param parent_diagram
*/
DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, Diagram *parent_diagram) :
QGraphicsPixmapItem(pixmap, 0, parent_diagram),
first_move_(false)
{
setTransformOriginPoint(boundingRect().center());
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
#endif
}
/// 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);
}
/**
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 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) {
Q_UNUSED (event);
edit();
}
/**
* @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();
if (first_move_) {
mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton);
}
QPointF expected_pos = e-> scenePos() + mouse_to_origin_movement_;
setPos(expected_pos); // setPos() will snap the expected position to the grid
//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) {
setRotation(QET::correctAngle(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));
}
/**
* @brief DiagramImageItem::setScale
* @param scale the value of @scale must be betwen 1 and 200
*/
void DiagramImageItem::PreviewScale(int scale) {
if (scale >= 1 && scale <= 200) {
qreal new_scale = scale;
new_scale /= 100;
setScale(new_scale);
}
}
/**
* @brief Edit the image with ....
*/
void DiagramImageItem::edit() {
if (diagram() -> isReadOnly()) return;
//the range for scale image and divisor factor
int min_range = 1;
int max_range = 200;
int factor_range = 100;
//the dialog
QDialog property_dialog;
property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title"));
//the main layout
QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog);
//GroupBox for resizer image
QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size"));
dialog_layout -> addWidget(resize_groupe);
QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe);
//slider
QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog);
slider->setRange(min_range, max_range);
qreal scale_= scale();
slider -> setValue(scale_*factor_range);
//spinbox
QSpinBox *spin_box = new QSpinBox(&property_dialog);
spin_box -> setRange(min_range, max_range);
spin_box -> setValue(scale_*factor_range);
spin_box -> setSuffix(" %");
//synchro slider with spinbox
connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
//add slider and spinbox to layout
resize_layout -> addWidget(slider);
resize_layout -> addWidget(spin_box);
//dialog button, box
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dbb);
connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
//dialog is accepted...
if (property_dialog.exec() == QDialog::Accepted) {
qreal new_scale = slider -> value();
new_scale /= factor_range;
if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale));
}
//...or not
else setScale(scale_);
return;
}
void DiagramImageItem::setPixmap(const QPixmap &pixmap) {
QGraphicsPixmapItem::setPixmap(pixmap);
setTransformOriginPoint(boundingRect().center());
}
/**
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);
setScale(e.attribute("size").toDouble());
setRotationAngle(e.attribute("rotation").toDouble());
setPos(e.attribute("x").toDouble(), e.attribute("y").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()));
result.setAttribute("rotation", QString("%1").arg(rotation()));
result.setAttribute("size", QString("%1").arg(scale()));
//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);
}

View File

@ -17,16 +17,16 @@
*/ */
#include "diagramview.h" #include "diagramview.h"
#include "diagram.h" #include "diagram.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
#include "ghostelement.h" #include "qetgraphicsitem/ghostelement.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "conductorpropertieswidget.h" #include "conductorpropertieswidget.h"
#include "conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "elementtextitem.h" #include "qetgraphicsitem/elementtextitem.h"
#include "independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
#include "titleblockpropertieswidget.h" #include "titleblockpropertieswidget.h"
#include "templatelocation.h" #include "templatelocation.h"
#include "qetapp.h" #include "qetapp.h"
@ -144,12 +144,12 @@ void DiagramView::rotateSelection() {
if (scene -> isReadOnly()) return; if (scene -> isReadOnly()) return;
// 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; QList<Element *> elements_to_rotate;
QList<DiagramTextItem *> texts_to_rotate; QList<DiagramTextItem *> texts_to_rotate;
QList<DiagramImageItem *> images_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 << e;
} else if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(item)) { } else if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(item)) {
texts_to_rotate << cti; texts_to_rotate << cti;
} else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(item)) { } else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(item)) {
@ -1294,7 +1294,7 @@ void DiagramView::editImage() {
if (images.count() != 1) return; if (images.count() != 1) return;
DiagramImageItem *image; DiagramImageItem *image;
if ((image = qgraphicsitem_cast<DiagramImageItem *> (images.first()))) { if ((image = qgraphicsitem_cast<DiagramImageItem *> (images.first()))) {
image -> edit(); image -> editProperty();
} }
} }

View File

@ -16,7 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "customelementpart.h" #include "customelementpart.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
#include "qetelementeditor.h" #include "qetelementeditor.h"
/// @return le QETElementEditor auquel cet editeur appartient /// @return le QETElementEditor auquel cet editeur appartient

View File

@ -409,39 +409,6 @@ void ChangeNamesCommand::redo() {
editor_scene_ -> setNames(names_after); editor_scene_ -> setNames(names_after);
} }
/**
Constructeur
@param element_scene Element edite
@param before Orientations avant changement
@param after Orientations apres changement
@param parent QUndoCommand parent
*/
ChangeOrientationsCommand::ChangeOrientationsCommand(
ElementScene *element_scene,
const OrientationSet &before,
const OrientationSet &after,
QUndoCommand *parent
) :
ElementEditionCommand(QObject::tr("modification orientations", "undo caption"), element_scene, 0, parent),
ori_before(before),
ori_after(after)
{
}
/// Destructeur
ChangeOrientationsCommand::~ChangeOrientationsCommand() {
}
/// Annule le changement
void ChangeOrientationsCommand::undo() {
editor_scene_ -> setOrientations(ori_before);
}
/// Refait le changement
void ChangeOrientationsCommand::redo() {
editor_scene_ -> setOrientations(ori_after);
}
/** /**
Constructeur Constructeur
@param elmt ElementScene concernee @param elmt ElementScene concernee
@ -565,32 +532,6 @@ void ChangeZValueCommand::applySendBackward(const QList<QGraphicsItem *> &items_
foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++); foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++);
} }
/**
Constructeur
@param elmt ElementScene concernee
@param allow true pour que les connexions internes soient acceptees, false sinon
@param parent QUndoCommand parent
*/
AllowInternalConnectionsCommand::AllowInternalConnectionsCommand(ElementScene *elmt, bool allow, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("modification connexions internes", "undo caption"), elmt, 0, parent),
ic(allow)
{
}
/// Destructeur
AllowInternalConnectionsCommand::~AllowInternalConnectionsCommand() {
}
/// Annule le changement d'autorisation pour les connexions internes
void AllowInternalConnectionsCommand::undo() {
editor_scene_ -> setInternalConnections(!ic);
}
/// Refait le changement d'autorisation pour les connexions internes
void AllowInternalConnectionsCommand::redo() {
editor_scene_ -> setInternalConnections(ic);
}
/** /**
Constructeur Constructeur
@param elmt ElementScene concernee @param elmt ElementScene concernee

View File

@ -248,30 +248,6 @@ class ChangeNamesCommand : public ElementEditionCommand {
NamesList names_after; NamesList names_after;
}; };
/**
This command changes the allowed orientations of an electrical element.
*/
class ChangeOrientationsCommand : public ElementEditionCommand {
// constructors, destructor
public:
ChangeOrientationsCommand(ElementScene *, const OrientationSet &, const OrientationSet &, QUndoCommand * = 0);
virtual ~ChangeOrientationsCommand();
private:
ChangeOrientationsCommand(const ChangeOrientationsCommand &);
// methods
public:
virtual void undo();
virtual void redo();
// attributes
private:
/// Former orientations
OrientationSet ori_before;
/// New orientations
OrientationSet ori_after;
};
/** /**
This command changes the zValue of a set of primitives when editing an This command changes the zValue of a set of primitives when editing an
electrical element. electrical element.
@ -312,29 +288,6 @@ class ChangeZValueCommand : public ElementEditionCommand {
Option option; Option option;
}; };
/**
This command enables or disables internal connections for an electrical
element.
*/
class AllowInternalConnectionsCommand : public ElementEditionCommand {
// constructors, destructor
public:
AllowInternalConnectionsCommand(ElementScene *, bool, QUndoCommand * = 0);
virtual ~AllowInternalConnectionsCommand();
private:
AllowInternalConnectionsCommand(const AllowInternalConnectionsCommand &);
// methods
public:
virtual void undo();
virtual void redo();
// attributes
private:
/// whether internal connections are allowed afterward
bool ic;
};
/** /**
This command changes extra information carried by an electrical element. This command changes extra information carried by an electrical element.
*/ */

View File

@ -38,7 +38,6 @@
*/ */
ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
QGraphicsScene(parent), QGraphicsScene(parent),
internal_connections(false),
qgi_manager(this), qgi_manager(this),
element_editor(editor), element_editor(editor),
decorator_(0) decorator_(0)
@ -415,9 +414,9 @@ const QDomDocument ElementScene::toXml(bool all_parts) {
root.setAttribute("height", QString("%1").arg(upheight)); root.setAttribute("height", QString("%1").arg(upheight));
root.setAttribute("hotspot_x", QString("%1").arg(-(qRound(size.x() - (xmargin/2))))); root.setAttribute("hotspot_x", QString("%1").arg(-(qRound(size.x() - (xmargin/2)))));
root.setAttribute("hotspot_y", QString("%1").arg(-(qRound(size.y() - (ymargin/2))))); root.setAttribute("hotspot_y", QString("%1").arg(-(qRound(size.y() - (ymargin/2)))));
root.setAttribute("orientation", ori.toString()); root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet
root.setAttribute("version", QET::version); root.setAttribute("version", QET::version);
if (internal_connections) root.setAttribute("ic", "true"); root.setAttribute("ic", "true"); //we keep the internal connection for compatibility with previous version of qet
// noms de l'element // noms de l'element
root.appendChild(_names.toXml(xml_document)); root.appendChild(_names.toXml(xml_document));
@ -663,58 +662,6 @@ void ElementScene::slot_delete() {
emit(selectionChanged()); emit(selectionChanged());
} }
/**
Lance un dialogue pour editer les noms de cete element
*/
void ElementScene::slot_editOrientations() {
bool is_read_only = element_editor && element_editor -> isReadOnly();
// cree un dialogue
QDialog dialog_ori(element_editor);
dialog_ori.setModal(true);
#ifdef Q_WS_MAC
dialog_ori.setWindowFlags(Qt::Sheet);
#endif
dialog_ori.setMinimumSize(400, 260);
dialog_ori.setWindowTitle(tr("\311diter les orientations", "window title"));
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_ori);
// ajoute un champ explicatif au dialogue
QLabel *information_label = new QLabel(tr("L'orientation par d\351faut est l'orientation dans laquelle s'effectue la cr\351ation de l'\351l\351ment."));
information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
information_label -> setWordWrap(true);
dialog_layout -> addWidget(information_label);
// ajoute un OrientationSetWidget au dialogue
OrientationSetWidget *ori_widget = new OrientationSetWidget();
ori_widget -> setOrientationSet(ori);
ori_widget -> setReadOnly(is_read_only);
dialog_layout -> addWidget(ori_widget);
// ajoute une case a cocher pour les connexions internes
QCheckBox *ic_checkbox = new QCheckBox(tr("Autoriser les connexions internes"));
ic_checkbox -> setChecked(internal_connections);
ic_checkbox -> setDisabled(is_read_only);
dialog_layout -> addWidget(ic_checkbox);
dialog_layout -> addStretch();
// ajoute deux boutons au dialogue
QDialogButtonBox *dialog_buttons = new QDialogButtonBox(is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dialog_buttons);
connect(dialog_buttons, SIGNAL(accepted()), &dialog_ori, SLOT(accept()));
connect(dialog_buttons, SIGNAL(rejected()), &dialog_ori, SLOT(reject()));
// lance le dialogue
if (dialog_ori.exec() == QDialog::Accepted && !is_read_only) {
OrientationSet new_ori = ori_widget -> orientationSet();
if (new_ori != ori) {
undoStack().push(new ChangeOrientationsCommand(this, ori, new_ori));
}
if (ic_checkbox -> isChecked() != internal_connections) {
undoStack().push(new AllowInternalConnectionsCommand(this, ic_checkbox -> isChecked()));
}
}
}
/** /**
Lance un dialogue pour editer les informations complementaires de cet Lance un dialogue pour editer les informations complementaires de cet
element. Concretement, ce champ libre est destine a accueillir des informations element. Concretement, ce champ libre est destine a accueillir des informations
@ -980,17 +927,6 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document, QString *
return(false); return(false);
} }
// orientations
internal_connections = (root.attribute("ic") == "true");
// connexions internes
if (!ori.fromString(root.attribute("orientation"))) {
if (error_message) {
*error_message = tr("Les orientations ne sont pas valides.", "error message");
}
return(false);
}
// extrait les noms de la definition XML // extrait les noms de la definition XML
_names.fromXml(root); _names.fromXml(root);

View File

@ -20,7 +20,6 @@
#include <QtGui> #include <QtGui>
#include <QtXml> #include <QtXml>
#include "nameslistwidget.h" #include "nameslistwidget.h"
#include "orientationsetwidget.h"
#include "qgimanager.h" #include "qgimanager.h"
#include "elementcontent.h" #include "elementcontent.h"
class CustomElementPart; class CustomElementPart;
@ -65,10 +64,6 @@ class ElementScene : public QGraphicsScene {
private: private:
/// List of localized names /// List of localized names
NamesList _names; NamesList _names;
/// Set of orientations
OrientationSet ori;
/// whether internal connections (i.e. connections between terminals of a same element) are accepted
bool internal_connections;
/// Extra informations /// Extra informations
QString informations_; QString informations_;
/// QGraphicsItem manager /// QGraphicsItem manager
@ -112,8 +107,6 @@ class ElementScene : public QGraphicsScene {
public: public:
void setNames(const NamesList &); void setNames(const NamesList &);
NamesList names() const; NamesList names() const;
OrientationSet orientations();
void setOrientations(const OrientationSet &);
bool internalConnections(); bool internalConnections();
void setInternalConnections(bool); void setInternalConnections(bool);
QString informations() const; QString informations() const;
@ -178,7 +171,6 @@ class ElementScene : public QGraphicsScene {
void slot_invertSelection(); void slot_invertSelection();
void slot_delete(); void slot_delete();
void slot_editNames(); void slot_editNames();
void slot_editOrientations();
void slot_editAuthorInformations(); void slot_editAuthorInformations();
void slot_bringForward(); void slot_bringForward();
void slot_raise(); void slot_raise();
@ -222,34 +214,6 @@ inline NamesList ElementScene::names() const {
return(_names); return(_names);
} }
/**
@return the orientation set of the currently edited element
*/
inline OrientationSet ElementScene::orientations() {
return(ori);
}
/**
@param orientation_set the new orientation set for the currently edited element
*/
inline void ElementScene::setOrientations(const OrientationSet &orientation_set) {
ori = orientation_set;
}
/**
@return whether internal connections are accepted
*/
inline bool ElementScene::internalConnections() {
return(internal_connections);
}
/**
@param ic true for internal connections to be accepted, false otherwise
*/
inline void ElementScene::setInternalConnections(bool ic) {
internal_connections = ic;
}
/** /**
@return extra informations of the currently edited element @return extra informations of the currently edited element
*/ */

View File

@ -322,7 +322,6 @@ ElementContent ElementView::pasteWithOffset(const QDomDocument &xml_document) {
// on applique le decalage qui convient // on applique le decalage qui convient
final_pasted_content_bounding_rect = applyMovement( final_pasted_content_bounding_rect = applyMovement(
pasted_content_bounding_rect, pasted_content_bounding_rect,
QETElementEditor::pasteMovement(),
QETElementEditor::pasteOffset() QETElementEditor::pasteOffset()
); );
} }
@ -483,20 +482,10 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) {
@param movement Orientation du decalage a appliquer @param movement Orientation du decalage a appliquer
@param offset Decalage a appliquer @param offset Decalage a appliquer
*/ */
QRectF ElementView::applyMovement(const QRectF &start, const QET::OrientedMovement &movement, const QPointF &offset) { QRectF ElementView::applyMovement(const QRectF &start, const QPointF &offset) {
// calcule le decalage a appliquer a partir de l'offset indique et du mouvement // calcule le decalage a appliquer a partir de l'offset
QPointF final_offset; QPointF final_offset;
if (movement == QET::ToNorthEast || movement == QET::ToEast || movement == QET::ToSouthEast) {
final_offset.rx() = start.width() + offset.x(); final_offset.rx() = start.width() + offset.x();
} else if (movement == QET::ToNorthWest || movement == QET::ToWest || movement == QET::ToSouthWest) {
final_offset.rx() = -start.width() - offset.x();
}
if (movement == QET::ToNorthWest || movement == QET::ToNorth || movement == QET::ToNorthEast) {
final_offset.ry() = -start.height() - offset.y();
} else if (movement == QET::ToSouthWest || movement == QET::ToSouth || movement == QET::ToSouthEast) {
final_offset.ry() = start.height() + offset.y();
}
// applique le decalage ainsi calcule // applique le decalage ainsi calcule
return(start.translated(final_offset)); return(start.translated(final_offset));

View File

@ -19,6 +19,7 @@
#define ELEMENT_VIEW_H #define ELEMENT_VIEW_H
#include <QGraphicsView> #include <QGraphicsView>
#include "elementscene.h" #include "elementscene.h"
/** /**
This class provides a widget to render an ElementScene instance, i.e. the This class provides a widget to render an ElementScene instance, i.e. the
edition class for electrical elements. edition class for electrical elements.
@ -50,7 +51,7 @@ class ElementView : public QGraphicsView {
virtual void drawBackground(QPainter *, const QRectF &); virtual void drawBackground(QPainter *, const QRectF &);
private: private:
QRectF applyMovement(const QRectF &, const QET::OrientedMovement &, const QPointF &); QRectF applyMovement(const QRectF &, const QPointF &);
public slots: public slots:
void setVisualisationMode(); void setVisualisationMode();

View File

@ -145,7 +145,6 @@ void QETElementEditor::setupActions() {
zoom_fit = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351"), this); zoom_fit = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351"), this);
zoom_reset = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom"), this); zoom_reset = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom"), this);
edit_names = new QAction(QET::Icons::Names, tr("\311diter les noms"), this); edit_names = new QAction(QET::Icons::Names, tr("\311diter les noms"), this);
edit_ori = new QAction(QET::Icons::Orientations, tr("\311diter les orientations"), this);
edit_author = new QAction(QET::Icons::UserInformations, tr("\311diter les informations sur l'auteur"), this); edit_author = new QAction(QET::Icons::UserInformations, tr("\311diter les informations sur l'auteur"), this);
edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), this); edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), this);
edit_lower = new QAction(QET::Icons::Lower, tr("\311loigner"), this); edit_lower = new QAction(QET::Icons::Lower, tr("\311loigner"), this);
@ -204,7 +203,6 @@ void QETElementEditor::setupActions() {
zoom_reset -> setShortcut(QKeySequence(tr("Ctrl+0"))); zoom_reset -> setShortcut(QKeySequence(tr("Ctrl+0")));
edit_names -> setShortcut(QKeySequence(tr("Ctrl+E"))); edit_names -> setShortcut(QKeySequence(tr("Ctrl+E")));
edit_ori -> setShortcut(QKeySequence(tr("Ctrl+T")));
edit_author -> setShortcut(tr("Ctrl+Y")); edit_author -> setShortcut(tr("Ctrl+Y"));
edit_raise -> setShortcut(QKeySequence(tr("Ctrl+Shift+Up"))); edit_raise -> setShortcut(QKeySequence(tr("Ctrl+Shift+Up")));
@ -235,7 +233,6 @@ void QETElementEditor::setupActions() {
connect(zoom_reset, SIGNAL(triggered()), ce_view, SLOT(zoomReset())); connect(zoom_reset, SIGNAL(triggered()), ce_view, SLOT(zoomReset()));
connect(edit_delete, SIGNAL(triggered()), ce_scene, SLOT(slot_delete())); connect(edit_delete, SIGNAL(triggered()), ce_scene, SLOT(slot_delete()));
connect(edit_names, SIGNAL(triggered()), ce_scene, SLOT(slot_editNames())); connect(edit_names, SIGNAL(triggered()), ce_scene, SLOT(slot_editNames()));
connect(edit_ori, SIGNAL(triggered()), ce_scene, SLOT(slot_editOrientations()));
connect(edit_author, SIGNAL(triggered()), ce_scene, SLOT(slot_editAuthorInformations())); connect(edit_author, SIGNAL(triggered()), ce_scene, SLOT(slot_editAuthorInformations()));
connect(edit_forward, SIGNAL(triggered()), ce_scene, SLOT(slot_bringForward())); connect(edit_forward, SIGNAL(triggered()), ce_scene, SLOT(slot_bringForward()));
connect(edit_raise, SIGNAL(triggered()), ce_scene, SLOT(slot_raise())); connect(edit_raise, SIGNAL(triggered()), ce_scene, SLOT(slot_raise()));
@ -318,7 +315,6 @@ void QETElementEditor::setupActions() {
view_toolbar -> addAction(zoom_fit); view_toolbar -> addAction(zoom_fit);
view_toolbar -> addAction(zoom_reset); view_toolbar -> addAction(zoom_reset);
element_toolbar -> addAction(edit_names); element_toolbar -> addAction(edit_names);
element_toolbar -> addAction(edit_ori);
depth_toolbar -> addAction(edit_forward); depth_toolbar -> addAction(edit_forward);
depth_toolbar -> addAction(edit_raise); depth_toolbar -> addAction(edit_raise);
depth_toolbar -> addAction(edit_lower); depth_toolbar -> addAction(edit_lower);
@ -393,7 +389,6 @@ void QETElementEditor::setupMenus() {
edit_menu -> addAction(edit_delete); edit_menu -> addAction(edit_delete);
edit_menu -> addSeparator(); edit_menu -> addSeparator();
edit_menu -> addAction(edit_names); edit_menu -> addAction(edit_names);
edit_menu -> addAction(edit_ori);
edit_menu -> addAction(edit_author); edit_menu -> addAction(edit_author);
edit_menu -> addSeparator(); edit_menu -> addSeparator();
edit_menu -> addAction(edit_forward); edit_menu -> addAction(edit_forward);
@ -1238,14 +1233,6 @@ QPointF QETElementEditor::pasteOffset() {
return(paste_offset); return(paste_offset);
} }
/**
@return Le type de mouvement a effectuer lors d'un copier/coller avec
decalage.
*/
QET::OrientedMovement QETElementEditor::pasteMovement() {
return(QET::ToEast);
}
/** /**
Demande a l'utilisateur d'ouvrir un fichier sense etre un element. Demande a l'utilisateur d'ouvrir un fichier sense etre un element.
@param parent QWidget parent du dialogue d'ouverture de fichier @param parent QWidget parent du dialogue d'ouverture de fichier

View File

@ -71,7 +71,7 @@ class QETElementEditor : public QETMainWindow {
QAction *selectall, *deselectall, *inv_select; QAction *selectall, *deselectall, *inv_select;
QAction *cut, *copy, *paste, *paste_in_area, *paste_from_file, *paste_from_elmt; QAction *cut, *copy, *paste, *paste_in_area, *paste_from_file, *paste_from_elmt;
QAction *undo, *redo; QAction *undo, *redo;
QAction *edit_delete, *edit_size_hs, *edit_names, *edit_ori, *edit_author; QAction *edit_delete, *edit_size_hs, *edit_names, *edit_author;
QAction *edit_raise, *edit_lower, *edit_backward, *edit_forward; QAction *edit_raise, *edit_lower, *edit_backward, *edit_forward;
/// actions for the "display" menu /// actions for the "display" menu
QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset; QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset;
@ -93,7 +93,6 @@ class QETElementEditor : public QETMainWindow {
// methods // methods
public: public:
void setNames(const NamesList &); void setNames(const NamesList &);
void setOrientations(const OrientationSet &orientation_set);
OrientationSet orientations() const; OrientationSet orientations() const;
void setLocation(const ElementsLocation &); void setLocation(const ElementsLocation &);
ElementsLocation location() const; ElementsLocation location() const;
@ -111,7 +110,6 @@ class QETElementEditor : public QETMainWindow {
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();
static QPointF pasteOffset(); static QPointF pasteOffset();
static QET::OrientedMovement pasteMovement();
static QString getOpenElementFileName(QWidget * = 0, const QString & = QString()); static QString getOpenElementFileName(QWidget * = 0, const QString & = QString());
void contextMenu(QContextMenuEvent *event); void contextMenu(QContextMenuEvent *event);
@ -160,20 +158,6 @@ inline void QETElementEditor::setNames(const NamesList &nameslist) {
ce_scene -> setNames(nameslist); ce_scene -> setNames(nameslist);
} }
/**
@param orientation_set the new set of orientations for the currently edited element
*/
inline void QETElementEditor::setOrientations(const OrientationSet &orientation_set) {
ce_scene -> setOrientations(orientation_set);
}
/**
@param the set of orientations for the currently edited element
*/
inline OrientationSet QETElementEditor::orientations() const {
return(ce_scene -> orientations());
}
/** /**
@return the location of the currently edited element @return the location of the currently edited element
*/ */

View File

@ -17,7 +17,7 @@
*/ */
#include "elementscategorieslist.h" #include "elementscategorieslist.h"
#include "qetapp.h" #include "qetapp.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
#include "elementscollection.h" #include "elementscollection.h"
#include "elementscategory.h" #include "elementscategory.h"
#include "elementdefinition.h" #include "elementdefinition.h"

View File

@ -2,7 +2,7 @@
#include "elementscollection.h" #include "elementscollection.h"
#include "elementscategory.h" #include "elementscategory.h"
#include "elementdefinition.h" #include "elementdefinition.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
/** /**
Construct a cache for elements collections. Construct a cache for elements collections.

View File

@ -16,13 +16,13 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "elementsmover.h" #include "elementsmover.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "diagram.h" #include "diagram.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "element.h" #include "qetgraphicsitem/element.h"
#include "independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
/** /**
Constructeur Constructeur

View File

@ -21,7 +21,7 @@
#include "diagram.h" #include "diagram.h"
#include "elementscategory.h" #include "elementscategory.h"
#include "elementscollectioncache.h" #include "elementscollectioncache.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
#include "fileelementscollection.h" #include "fileelementscollection.h"
#include "fileelementdefinition.h" #include "fileelementdefinition.h"
#include "qeticons.h" #include "qeticons.h"

View File

@ -16,12 +16,12 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "elementtextsmover.h" #include "elementtextsmover.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "elementtextitem.h" #include "qetgraphicsitem/elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "element.h" #include "qetgraphicsitem/element.h"
#include "independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
/** /**
Constructeur Constructeur

View File

@ -20,8 +20,7 @@
#include "elementscategorieswidget.h" #include "elementscategorieswidget.h"
#include "elementscategorieslist.h" #include "elementscategorieslist.h"
#include "nameslistwidget.h" #include "nameslistwidget.h"
#include "orientationsetwidget.h" #include "qetgraphicsitem/element.h"
#include "element.h"
#include "qetelementeditor.h" #include "qetelementeditor.h"
#include "qet.h" #include "qet.h"
#include "qetapp.h" #include "qetapp.h"
@ -52,7 +51,6 @@ NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
addPage(buildStep1()); addPage(buildStep1());
addPage(buildStep2()); addPage(buildStep2());
addPage(buildStep3()); addPage(buildStep3());
addPage(buildStep4());
setFixedSize(705, 325); setFixedSize(705, 325);
} }
@ -96,7 +94,7 @@ bool NewElementWizard::preselectCategory(ElementsCategory *category) {
QWizardPage *NewElementWizard::buildStep1() { QWizardPage *NewElementWizard::buildStep1() {
QWizardPage *page = new QWizardPage(); QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Category); page -> setProperty("WizardState", Category);
page -> setTitle(tr("\311tape 1/4 : Cat\351gorie parente", "wizard page title")); page -> setTitle(tr("\311tape 1/3 : Cat\351gorie parente", "wizard page title"));
page -> setSubTitle(tr("S\351lectionnez une cat\351gorie dans laquelle enregistrer le nouvel \351l\351ment.", "wizard page subtitle")); page -> setSubTitle(tr("S\351lectionnez une cat\351gorie dans laquelle enregistrer le nouvel \351l\351ment.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
@ -113,7 +111,7 @@ QWizardPage *NewElementWizard::buildStep1() {
QWizardPage *NewElementWizard::buildStep2() { QWizardPage *NewElementWizard::buildStep2() {
QWizardPage *page = new QWizardPage(); QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Filename); page -> setProperty("WizardState", Filename);
page -> setTitle(tr("\311tape 2/4 : Nom du fichier", "wizard page title")); page -> setTitle(tr("\311tape 2/3 : Nom du fichier", "wizard page title"));
page -> setSubTitle(tr("Indiquez le nom du fichier dans lequel enregistrer le nouvel \351l\351ment.", "wizard page subtitle")); page -> setSubTitle(tr("Indiquez le nom du fichier dans lequel enregistrer le nouvel \351l\351ment.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
@ -136,7 +134,7 @@ QWizardPage *NewElementWizard::buildStep2() {
QWizardPage *NewElementWizard::buildStep3() { QWizardPage *NewElementWizard::buildStep3() {
QWizardPage *page = new QWizardPage(); QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Names); page -> setProperty("WizardState", Names);
page -> setTitle(tr("\311tape 3/4 : Noms de l'\351l\351ment", "wizard page title")); page -> setTitle(tr("\311tape 3/3 : Noms de l'\351l\351ment", "wizard page title"));
page -> setSubTitle(tr("Indiquez le ou les noms de l'\351l\351ment.", "wizard page subtitle")); page -> setSubTitle(tr("Indiquez le ou les noms de l'\351l\351ment.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
@ -150,33 +148,17 @@ QWizardPage *NewElementWizard::buildStep3() {
return(page); return(page);
} }
/**
Met en place l'etape 4 : orientations possibles pour le nouvel element
*/
QWizardPage *NewElementWizard::buildStep4() {
QWizardPage *page = new QWizardPage();
page -> setProperty("WizardState", Orientations);
page -> setTitle(tr("\311tape 4/4 : Orientations", "wizard page title"));
page -> setSubTitle(tr("Indiquez les orientations possibles pour le nouvel \351l\351ment.", "wizard page subtitle"));
QVBoxLayout *layout = new QVBoxLayout();
orientation_set = new OrientationSetWidget();
layout -> addWidget(orientation_set);
layout -> addSpacing(25);
page -> setLayout(layout);
return(page);
}
/// @return true si l'etape en cours est validee, false sinon /// @return true si l'etape en cours est validee, false sinon
bool NewElementWizard::validateCurrentPage() { bool NewElementWizard::validateCurrentPage() {
WizardState wizard_state = static_cast<WizardState>(currentPage() -> property("WizardState").toInt()); WizardState wizard_state = static_cast<WizardState>(currentPage() -> property("WizardState").toInt());
if (wizard_state == Category) return(validStep1()); if (wizard_state == Category) return(validStep1());
else if (wizard_state == Filename) return(validStep2()); else if (wizard_state == Filename) return(validStep2());
else if (wizard_state == Names) return(element_names -> checkOneName()); // il doit y avoir au moins un nom else if (wizard_state == Names) {
else if (wizard_state == Orientations) { // must have one name minimum
if (element_names -> checkOneName())
createNewElement(); createNewElement();
return(true); return true;
} }
else return(true); else return(true);
} }
@ -259,7 +241,6 @@ bool NewElementWizard::validStep2() {
void NewElementWizard::createNewElement() { void NewElementWizard::createNewElement() {
QETElementEditor *edit_new_element = new QETElementEditor(parentWidget()); QETElementEditor *edit_new_element = new QETElementEditor(parentWidget());
edit_new_element -> setNames(element_names -> names()); edit_new_element -> setNames(element_names -> names());
edit_new_element -> setOrientations(orientation_set -> orientationSet());
ElementsLocation new_element_location = chosen_category -> location(); ElementsLocation new_element_location = chosen_category -> location();
new_element_location.addToPath(chosen_file); new_element_location.addToPath(chosen_file);

View File

@ -21,7 +21,6 @@
class ElementsCategoriesWidget; class ElementsCategoriesWidget;
class ElementsCategory; class ElementsCategory;
class NamesListWidget; class NamesListWidget;
class OrientationSetWidget;
class QFileNameEdit; class QFileNameEdit;
/** /**
This class provides a wizard dialog enabling users to to specify the basic This class provides a wizard dialog enabling users to to specify the basic
@ -31,9 +30,6 @@ class QFileNameEdit;
- the category the element should be saved to - the category the element should be saved to
- the filename the element should be saved to - the filename the element should be saved to
- localized names - localized names
- dimensions
- hotspot position
- allowed and default orientations
*/ */
class NewElementWizard : public QWizard { class NewElementWizard : public QWizard {
Q_OBJECT Q_OBJECT
@ -53,11 +49,10 @@ class NewElementWizard : public QWizard {
// attributes // attributes
private: private:
enum WizardState { Category, Filename, Names, Dimensions, Orientations }; enum WizardState { Category, Filename, Names };
ElementsCategoriesWidget *categories_list; ElementsCategoriesWidget *categories_list;
QFileNameEdit *qle_filename; QFileNameEdit *qle_filename;
NamesListWidget *element_names; NamesListWidget *element_names;
OrientationSetWidget *orientation_set;
WizardState current_state; WizardState current_state;
QString chosen_file; QString chosen_file;
ElementsCategory *chosen_category; ElementsCategory *chosen_category;
@ -67,7 +62,6 @@ class NewElementWizard : public QWizard {
QWizardPage *buildStep1(); QWizardPage *buildStep1();
QWizardPage *buildStep2(); QWizardPage *buildStep2();
QWizardPage *buildStep3(); QWizardPage *buildStep3();
QWizardPage *buildStep4();
bool validStep1(); bool validStep1();
bool validStep2(); bool validStep2();
bool validateCurrentPage(); bool validateCurrentPage();

View File

@ -22,9 +22,9 @@
#include "qetproject.h" #include "qetproject.h"
#include "diagram.h" #include "diagram.h"
#include "element.h" #include "qetgraphicsitem/element.h"
#include "diagramcontent.h" #include "diagramcontent.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
class QETProject; class QETProject;
class Diagram; class Diagram;

View File

@ -1,171 +0,0 @@
/*
Copyright 2006-2012 Xavier Guerrin
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 "orientationsetwidget.h"
#include "qeticons.h"
/**
Constructeur
@param parent QWidget parent
*/
OrientationSetWidget::OrientationSetWidget(QWidget *parent) : QWidget(parent) {
default_radios = new QButtonGroup(this);
#define MK_COMBO_BOX(a) a##_orientation = new QComboBox();\
a##_orientation -> addItem(QET::Icons::Allowed, tr("Possible"), "y");\
a##_orientation -> addItem(QET::Icons::Forbidden,tr("Impossible"), "n");\
connect(a##_orientation, SIGNAL(activated(int)), this, SLOT(updateOrientationSet()));\
a##_default = new QRadioButton();
// 4 combo box, 4 boutons radios
MK_COMBO_BOX(north)
MK_COMBO_BOX(east)
MK_COMBO_BOX(south)
MK_COMBO_BOX(west)
#undef MK_COMBO_BOX
default_radios -> addButton(north_default, QET::North);
default_radios -> addButton(east_default, QET::East);
default_radios -> addButton(south_default, QET::South);
default_radios -> addButton(west_default, QET::West);
connect(default_radios, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(slot_defaultChanged(QAbstractButton *)));
// petites icones symbolisant les orientations
QLabel *north_pixmap = new QLabel(tr("Nord :"));
north_pixmap -> setPixmap(QET::Icons::North.pixmap(16, 16));
QLabel *east_pixmap = new QLabel(tr("Est :"));
east_pixmap -> setPixmap(QET::Icons::East.pixmap(16, 16));
QLabel *south_pixmap = new QLabel(tr("Sud :"));
south_pixmap -> setPixmap(QET::Icons::South.pixmap(16, 16));
QLabel *west_pixmap = new QLabel(tr("Ouest :"));
west_pixmap -> setPixmap(QET::Icons::West.pixmap(16, 16));
QGridLayout *qgl = new QGridLayout(this);
qgl -> addWidget(new QLabel(tr("Par d\351faut")), 0, 3);
qgl -> addWidget(north_pixmap, 1, 0);
qgl -> addWidget(new QLabel(tr("Nord :")), 1, 1);
qgl -> addWidget(north_orientation, 1, 2);
qgl -> addWidget(north_default, 1, 3, Qt::AlignHCenter);
qgl -> addWidget(east_pixmap, 2, 0);
qgl -> addWidget(new QLabel(tr("Est :")), 2, 1);
qgl -> addWidget(east_orientation, 2, 2);
qgl -> addWidget(east_default, 2, 3, Qt::AlignHCenter);
qgl -> addWidget(south_pixmap, 3, 0);
qgl -> addWidget(new QLabel(tr("Sud :")), 3, 1);
qgl -> addWidget(south_orientation, 3, 2);
qgl -> addWidget(south_default, 3, 3, Qt::AlignHCenter);
qgl -> addWidget(west_pixmap, 4, 0);
qgl -> addWidget(new QLabel(tr("Ouest :")), 4, 1);
qgl -> addWidget(west_orientation, 4, 2);
qgl -> addWidget(west_default, 4, 3, Qt::AlignHCenter);
// les combobox s'etendent autant que possible
qgl -> setColumnStretch(2, 1);
// l'orientation par defaut par defaut est le Nord
north_default -> setChecked(true);
slot_defaultChanged(north_default);
}
/**
@return l'OrientationSet
*/
OrientationSet OrientationSetWidget::orientationSet() const {
return(ori);
}
/**
@param os l'OrientationSet a editer
*/
void OrientationSetWidget::setOrientationSet(const OrientationSet &os) {
ori = os;
updateForm();
}
/**
@return true si ce widget est en lecture seule, false sinon
*/
bool OrientationSetWidget::isReadOnly() const {
return(!north_orientation -> isEnabled());
}
/**
@param ro true pour passer ce widget en lecture seule, false sinon
*/
void OrientationSetWidget::setReadOnly(bool ro) {
north_orientation -> setDisabled(ro);
east_orientation -> setDisabled(ro);
south_orientation -> setDisabled(ro);
west_orientation -> setDisabled(ro);
north_default -> setDisabled(ro);
east_default -> setDisabled(ro);
south_default -> setDisabled(ro);
west_default -> setDisabled(ro);
}
/**
Slot gerant le changement d'orientation par defaut.
L'orientation concernee affiche alors "Possible" et ce statut devient
impossible a modifier.
*/
void OrientationSetWidget::slot_defaultChanged(QAbstractButton *button) {
if (button == north_default) north_orientation -> setCurrentIndex(0);
else if (button == east_default) east_orientation -> setCurrentIndex(0);
else if (button == south_default) south_orientation -> setCurrentIndex(0);
else if (button == west_default) west_orientation -> setCurrentIndex(0);
north_orientation -> setEnabled(button != north_default);
east_orientation -> setEnabled(button != east_default);
south_orientation -> setEnabled(button != south_default);
west_orientation -> setEnabled(button != west_default);
updateOrientationSet();
}
/**
Met a jour les donnees de la classe a partir du dialogue
*/
void OrientationSetWidget::updateOrientationSet() {
ori.setNorth(!north_orientation -> currentIndex());
ori.setEast (!east_orientation -> currentIndex());
ori.setSouth(!south_orientation -> currentIndex());
ori.setWest (!west_orientation -> currentIndex());
ori.setDefaultOrientation(static_cast<QET::Orientation>(default_radios -> checkedId()));
}
/**
Met a jour le dialogue a partir des donnees de la classe
*/
void OrientationSetWidget::updateForm() {
north_orientation -> setCurrentIndex(ori.north() ? 0 : 1);
east_orientation -> setCurrentIndex(ori.east() ? 0 : 1);
south_orientation -> setCurrentIndex(ori.south() ? 0 : 1);
west_orientation -> setCurrentIndex(ori.west() ? 0 : 1);
QRadioButton *default_button = NULL;
switch(ori.defaultOrientation()) {
case QET::North: default_button = north_default; break;
case QET::East : default_button = east_default ; break;
case QET::South: default_button = south_default; break;
case QET::West : default_button = west_default ; break;
}
if (default_button != NULL) {
default_button -> setChecked(true);
slot_defaultChanged(default_button);
}
}

View File

@ -1,63 +0,0 @@
/*
Copyright 2006-2012 Xavier Guerrin
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 ORIENTATION_SET_WIDGET_H
#define ORIENTATION_SET_WIDGET_H
#include <QtGui>
#include "orientationset.h"
/**
Widget to edit an OrientationSet.
@see OrientationSet
*/
class OrientationSetWidget : public QWidget {
Q_OBJECT
// constructors, destructor
public:
OrientationSetWidget(QWidget * = 0);
virtual ~OrientationSetWidget() {};
private:
OrientationSetWidget(const OrientationSetWidget &);
// attributes
private:
OrientationSet ori;
QComboBox *north_orientation;
QComboBox *east_orientation;
QComboBox *south_orientation;
QComboBox *west_orientation;
QRadioButton *north_default;
QRadioButton *east_default;
QRadioButton *south_default;
QRadioButton *west_default;
QButtonGroup *default_radios;
// methods
public:
OrientationSet orientationSet() const;
void setOrientationSet(const OrientationSet &);
bool isReadOnly() const;
void setReadOnly(bool);
private:
void updateForm();
public slots:
void slot_defaultChanged(QAbstractButton *);
void updateOrientationSet();
};
#endif

View File

@ -20,10 +20,10 @@
#include "diagramcontent.h" #include "diagramcontent.h"
#include "diagramview.h" #include "diagramview.h"
#include "diagram.h" #include "diagram.h"
#include "element.h" #include "qetgraphicsitem/element.h"
#include "elementspanelwidget.h" #include "elementspanelwidget.h"
#include "conductorpropertieswidget.h" #include "conductorpropertieswidget.h"
#include "customelement.h" #include "qetgraphicsitem/customelement.h"
#include "qetproject.h" #include "qetproject.h"
#include "projectview.h" #include "projectview.h"
#include "recentfiles.h" #include "recentfiles.h"

View File

@ -702,7 +702,9 @@ void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) {
@return true si l'attribut "orientation" est valide, false sinon @return true si l'attribut "orientation" est valide, false sinon
*/ */
bool CustomElement::validOrientationAttribute(const QDomElement &e) { bool CustomElement::validOrientationAttribute(const QDomElement &e) {
return(ori.fromString(e.attribute("orientation"))); int ori = e.attribute("orientation").toInt();
if(ori >= 0 && ori <=3) return true;
return false;
} }
/** /**

View File

@ -0,0 +1,222 @@
/*
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"
/**
* @brief DiagramImageItem::DiagramImageItem
* Constructor without pixmap
* @param parent_item the parent graphics item
*/
DiagramImageItem::DiagramImageItem(QetGraphicsItem *parent_item):
QetGraphicsItem(parent_item)
{
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
#endif
}
/**
* @brief DiagramImageItem::DiagramImageItem
* Constructor with pixmap
* @param pixmap the pixmap to be draw
* @param parent_item the parent graphic item
*/
DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, QetGraphicsItem *parent_item):
QetGraphicsItem(parent_item),
pixmap_(pixmap)
{
setTransformOriginPoint(boundingRect().center());
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
#endif
}
/**
* @brief DiagramImageItem::~DiagramImageItem
* Destructor
*/
DiagramImageItem::~DiagramImageItem() {
}
/**
* @brief DiagramImageItem::paint
* Draw the pixmap.
* @param painter the Qpainter to use for draw the pixmap
* @param option the style option
* @param widget the QWidget where we draw the pixmap
*/
void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter -> drawPixmap(pixmap_.rect(),pixmap_);
if (isSelected()) {
painter -> save();
// Annulation des renderhints
painter -> setRenderHint(QPainter::Antialiasing, false);
painter -> setRenderHint(QPainter::TextAntialiasing, false);
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
// Dessin du cadre de selection en noir a partir du boundingrect
QPen t(Qt::black);
t.setStyle(Qt::DashLine);
painter -> setPen(t);
painter -> drawRect(boundingRect());
painter -> restore();
}
}
/**
* @brief DiagramImageItem::setScale
* @param scale the value of @scale must be betwen 1 and 200
*/
void DiagramImageItem::PreviewScale(int scale) {
if (scale >= 1 && scale <= 200) {
qreal new_scale = scale;
new_scale /= 100;
setScale(new_scale);
}
}
/**
* @brief Edit the image with ....
*/
void DiagramImageItem::editProperty() {
if (diagram() -> isReadOnly()) return;
//the range for scale image and divisor factor
int min_range = 1;
int max_range = 200;
int factor_range = 100;
//the dialog
QDialog property_dialog;
property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title"));
//the main layout
QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog);
//GroupBox for resizer image
QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size"));
dialog_layout -> addWidget(resize_groupe);
QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe);
//slider
QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog);
slider->setRange(min_range, max_range);
qreal scale_= scale();
slider -> setValue(scale_*factor_range);
//spinbox
QSpinBox *spin_box = new QSpinBox(&property_dialog);
spin_box -> setRange(min_range, max_range);
spin_box -> setValue(scale_*factor_range);
spin_box -> setSuffix(" %");
//synchro slider with spinbox
connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
//add slider and spinbox to layout
resize_layout -> addWidget(slider);
resize_layout -> addWidget(spin_box);
//dialog button, box
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dbb);
connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
//dialog is accepted...
if (property_dialog.exec() == QDialog::Accepted) {
qreal new_scale = slider -> value();
new_scale /= factor_range;
if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale));
}
//...or not
else setScale(scale_);
return;
}
/**
* @brief DiagramImageItem::setPixmap
* Set the new pixmap to be draw
* @param pixmap the new pixmap
*/
void DiagramImageItem::setPixmap(const QPixmap &pixmap) {
pixmap_ = pixmap;
setTransformOriginPoint(boundingRect().center());
}
/**
* @brief DiagramImageItem::boundingRect
* the outer bounds of the item as a rectangle,
* if no pixmap are set, return a default QRectF
* @return a QRectF represent the bounding rectangle
*/
QRectF DiagramImageItem::boundingRect() const {
if (!pixmap_.isNull()) {
return (QRectF(pixmap_.rect()));
} else {
QRectF bound;
return (bound);
}
}
/**
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 image to QByteArray
QByteArray array;
array = QByteArray::fromBase64(e.text().toAscii());
//Set QPixmap from the @array
QPixmap pixmap;
pixmap.loadFromData(array);
setPixmap(pixmap);
setScale(e.attribute("size").toDouble());
applyRotation(e.attribute("rotation").toDouble());
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
return (true);
}
/**
@param document Le document XML a utiliser
@return L'element XML representant l'image
*/
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()));
result.setAttribute("rotation", QString("%1").arg(rotation()));
result.setAttribute("size", QString("%1").arg(scale()));
//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);
}

View File

@ -18,18 +18,20 @@
#ifndef DIAGRAM_IMAGE_ITEM_H #ifndef DIAGRAM_IMAGE_ITEM_H
#define DIAGRAM_IMAGE_ITEM_H #define DIAGRAM_IMAGE_ITEM_H
#include <QtGui> #include <QtGui>
#include "diagram.h" #include "qetgraphicsitem.h"
/** /**
This class represents a selectable, movable and editable image on a This class represents a selectable, movable and editable image on a
diagram. diagram.
@see QGraphicsItem::GraphicsItemFlags @see QGraphicsItem::GraphicsItemFlags
*/ */
class DiagramImageItem : public QObject, public QGraphicsPixmapItem { class DiagramImageItem : public QetGraphicsItem {
Q_OBJECT Q_OBJECT
// constructors, destructor // constructors, destructor
public: public:
DiagramImageItem(Diagram * = 0); DiagramImageItem(QetGraphicsItem * = 0);
DiagramImageItem(const QPixmap &, Diagram * = 0); DiagramImageItem(const QPixmap &pixmap, QetGraphicsItem * = 0);
virtual ~DiagramImageItem(); virtual ~DiagramImageItem();
// attributes // attributes
@ -44,35 +46,22 @@ class DiagramImageItem : public QObject, public QGraphicsPixmapItem {
@return the QGraphicsItem type @return the QGraphicsItem type
*/ */
virtual int type() const { return Type; } virtual int type() const { return Type; }
Diagram *diagram() const;
virtual bool fromXml(const QDomElement &); virtual bool fromXml(const QDomElement &);
virtual QDomElement toXml(QDomDocument &) const; virtual QDomElement toXml(QDomDocument &) const;
virtual void editProperty();
virtual void setPos(const QPointF &);
virtual void setPos(qreal, qreal);
void setRotationAngle(const qreal &);
void rotateBy(const qreal &);
void edit();
void setPixmap(const QPixmap &pixmap); void setPixmap(const QPixmap &pixmap);
virtual QRectF boundingRect() const;
protected: protected:
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
void mousePressEvent(QGraphicsSceneMouseEvent *e);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
void applyRotation(const qreal &);
signals: signals:
/// signal emitted after image was changed
void diagramImageChanged(DiagramImageItem *, const QString &, const QString &);
private slots: private slots:
void PreviewScale(int); void PreviewScale(int);
private: protected:
bool first_move_; QPixmap pixmap_;
QPointF mouse_to_origin_movement_;
}; };
#endif #endif

View File

@ -27,11 +27,9 @@
Constructeur pour un element sans scene ni parent Constructeur pour un element sans scene ni parent
*/ */
Element::Element(QGraphicsItem *parent, Diagram *scene) : Element::Element(QGraphicsItem *parent, Diagram *scene) :
QObject(), QetGraphicsItem(parent),
QGraphicsItem(parent, scene),
internal_connections_(false), internal_connections_(false),
must_highlight_(false), must_highlight_(false)
first_move_(true)
{ {
setZValue(10); setZValue(10);
} }
@ -72,9 +70,7 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
Diagram *dia = diagram(); Diagram *dia = diagram();
if (dia && options -> levelOfDetail == 1.0 && widget) { if (dia && options -> levelOfDetail == 1.0 && widget) {
// calcule la rotation qu'a subi l'element // calcule la rotation qu'a subi l'element
qreal applied_rotation = 90.0 * (ori.current() - ori.defaultOrientation()); qreal applied_rotation = 90.0 * orientation();
while (applied_rotation < 360.0) applied_rotation += 360.0;
while (applied_rotation > 360.0) applied_rotation -= 360.0;
if (applied_rotation == 90.0) painter -> translate(1.0, -1.0); if (applied_rotation == 90.0) painter -> translate(1.0, -1.0);
else if (applied_rotation == 180.0) painter -> translate(-1.0, -1.0); else if (applied_rotation == 180.0) painter -> translate(-1.0, -1.0);
else if (applied_rotation == 270.0) painter -> translate(-1.0, 1.0); else if (applied_rotation == 270.0) painter -> translate(-1.0, 1.0);
@ -169,25 +165,38 @@ QPixmap Element::pixmap() {
} }
/** /**
Permet de specifier l'orientation de l'element * @brief Element::rotateBy
@param o la nouvelle orientation de l'objet * this methode is redefined for handle child item
@return true si l'orientation a pu etre appliquee, false sinon * @param angle
*/ */
bool Element::setOrientation(QET::Orientation o) { void Element::rotateBy(const qreal &angle) {
// verifie que l'orientation demandee est acceptee qreal applied_angle = QET::correctAngle(angle);
if (!ori.accept(o)) return(false); applyRotation(applied_angle + rotation());
prepareGeometryChange();
// rotation en consequence et rafraichissement de l'element graphique //update the path of conductor
qreal rotation_value = 90.0 * (o - ori.current());
rotate(rotation_value);
ori.setCurrent(o);
update();
foreach(QGraphicsItem *qgi, childItems()) { foreach(QGraphicsItem *qgi, childItems()) {
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) { if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
p -> updateConductor(); p -> updateConductor();
} }
} }
return(true);
// repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations"
foreach(ElementTextItem *eti, texts()) {
if (!eti -> followParentRotations()) {
// on souhaite pivoter le champ de texte par rapport a son centre
QPointF eti_center = eti -> boundingRect().center();
// pour ce faire, on repere la position de son centre par rapport a son parent
QPointF parent_eti_center_before = eti -> mapToParent(eti_center);
// on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte
eti -> rotateBy(-applied_angle);
// on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent
QPointF parent_eti_center_after = eti -> mapToParent(eti_center);
// on determine la translation a appliquer
QPointF eti_translation = parent_eti_center_before - parent_eti_center_after;
// on applique cette translation
eti -> setPos(eti -> pos() + eti_translation);
}
}
} }
/*** Methodes protegees ***/ /*** Methodes protegees ***/
@ -276,95 +285,6 @@ void Element::updatePixmap() {
paint(&p, 0); paint(&p, 0);
} }
/**
Change la position de l'element en veillant a ce que l'element
reste sur la grille du Diagram auquel il appartient.
@param p Nouvelles coordonnees de l'element
*/
void Element::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;
QGraphicsItem::setPos(p_x, p_y);
} else QGraphicsItem::setPos(p);
}
/**
Change la position de l'element en veillant a ce que l'element
reste sur la grille du Diagram auquel il appartient.
@param x Nouvelle abscisse de l'element
@param y Nouvelle ordonnee de l'element
*/
void Element::setPos(qreal x, qreal y) {
setPos(QPointF(x, y));
}
/**
Gere le clic sur l'element
@param e Objet decrivant l'evenement souris
*/
void Element::mousePressEvent(QGraphicsSceneMouseEvent *e) {
first_move_ = true;
if (e -> modifiers() & Qt::ControlModifier) {
setSelected(!isSelected());
}
QGraphicsItem::mousePressEvent(e);
}
/**
Gere les mouvements de souris lies a l'element
@param e Objet decrivant l'evenement souris
*/
void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
if (isSelected() && e -> buttons() & Qt::LeftButton) {
// l'element est en train d'etre deplace
Diagram *diagram_ptr = diagram();
if (diagram_ptr) {
if (first_move_) {
// il s'agit du premier mouvement du deplacement, on le signale
// au schema parent
diagram_ptr -> beginMoveElements(this);
}
}
// on applique le mouvement impose par la souris
QPointF old_pos = pos();
setPos(mapToParent(e -> pos()) - matrix().map(e -> buttonDownPos(Qt::LeftButton)));
// on calcule le mouvement reellement applique par setPos()
QPointF effective_movement = pos() - old_pos;
if (diagram_ptr) {
// on signale le mouvement ainsi applique au schema parent, qui
// l'appliquera aux autres items selectionnes selon son bon vouloir
diagram_ptr -> continueMoveElements(effective_movement);
}
} else e -> ignore();
if (first_move_) {
first_move_ = false;
}
}
/**
Gere le relachement de souris
Cette methode a ete reimplementee pour tenir a jour la liste des elements
et conducteurs a deplacer au niveau du schema.
*/
void Element::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
if (Diagram *diagram_ptr = diagram()) {
diagram_ptr -> endMoveElements();
}
if (!(e -> modifiers() & Qt::ControlModifier)) {
QGraphicsItem::mouseReleaseEvent(e);
}
}
/** /**
Permet de savoir si un element XML (QDomElement) represente bien un element Permet de savoir si un element XML (QDomElement) represente bien un element
@param e Le QDomElement a valide @param e Le QDomElement a valide
@ -462,11 +382,11 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
// orientation // orientation
bool conv_ok; bool conv_ok;
int read_ori = e.attribute("orientation").toInt(&conv_ok); int read_ori = e.attribute("orientation").toInt(&conv_ok);
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation(); if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
if (handle_inputs_rotation) { if (handle_inputs_rotation) {
RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori); rotateBy(90*read_ori);
} else { } else {
setOrientation((QET::Orientation)read_ori); applyRotation(90*read_ori);
} }
return(true); return(true);
} }
@ -488,7 +408,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
// position, selection et orientation // position, selection et orientation
element.setAttribute("x", QString("%1").arg(pos().x())); element.setAttribute("x", QString("%1").arg(pos().x()));
element.setAttribute("y", QString("%1").arg(pos().y())); element.setAttribute("y", QString("%1").arg(pos().y()));
element.setAttribute("orientation", QString("%1").arg(ori.current())); element.setAttribute("orientation", QString("%1").arg(orientation()));
/* recupere le premier id a utiliser pour les bornes de cet element */ /* recupere le premier id a utiliser pour les bornes de cet element */
int id_terminal = 0; int id_terminal = 0;
@ -522,8 +442,3 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
return(element); return(element);
} }
/// @return le Diagram auquel cet element appartient, ou 0 si cet element est independant
Diagram *Element::diagram() const {
return(qobject_cast<Diagram *>(scene()));
}

View File

@ -19,16 +19,15 @@
#define ELEMENT_H #define ELEMENT_H
#include <QtGui> #include <QtGui>
#include "terminal.h" #include "terminal.h"
#include "orientationset.h" #include "qetgraphicsitem.h"
class Diagram; class Diagram;
class ElementTextItem; class ElementTextItem;
/** /**
This is the base class for electrical elements. This is the base class for electrical elements.
*/ */
class Element : public QObject, public QGraphicsItem { class Element : public QetGraphicsItem {
Q_OBJECT Q_OBJECT
Q_INTERFACES(QGraphicsItem)
// constructors, destructor // constructors, destructor
public: public:
@ -43,14 +42,6 @@ class Element : public QObject, public QGraphicsItem {
enum { Type = UserType + 1000 }; enum { Type = UserType + 1000 };
protected: protected:
/**
Hold orientations for the element :
* allowed orientations
* current orientation
* default orientation
@see OrientationSet
*/
OrientationSet ori;
private: private:
QSize dimensions; QSize dimensions;
@ -87,7 +78,6 @@ class Element : public QObject, public QGraphicsItem {
virtual QString typeId() const = 0; virtual QString typeId() const = 0;
/// @return the human name for this element /// @return the human name for this element
virtual QString name() const = 0; virtual QString name() const = 0;
Diagram *diagram() const;
virtual bool isHighlighted() const; virtual bool isHighlighted() const;
virtual void setHighlighted(bool); virtual void setHighlighted(bool);
@ -105,13 +95,10 @@ class Element : public QObject, public QGraphicsItem {
void select(); void select();
void deselect(); void deselect();
// position-related methods
void setPos(const QPointF &);
void setPos(qreal, qreal);
// methods related to internal connections // methods related to internal connections
bool internalConnections(); bool internalConnections();
void setInternalConnections(bool); void setInternalConnections(bool);
virtual void rotateBy(const qreal &);
// methods related to XML import/export // methods related to XML import/export
static bool valideXml(QDomElement &); static bool valideXml(QDomElement &);
@ -119,19 +106,14 @@ class Element : public QObject, public QGraphicsItem {
virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const; virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
// orientation-related methods // orientation-related methods
bool setOrientation(QET::Orientation o); int orientation() const;
const OrientationSet &orientation() const;
protected: protected:
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
void mousePressEvent(QGraphicsSceneMouseEvent *);
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
private: private:
bool internal_connections_; bool internal_connections_;
bool must_highlight_; bool must_highlight_;
bool first_move_;
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
void updatePixmap(); void updatePixmap();
@ -157,10 +139,14 @@ inline void Element::setInternalConnections(bool ic) {
/** /**
Indicate the current orientation of this element Indicate the current orientation of this element
O = 0°
1 = 90°
2 = 180°
3 = 270°
@return the current orientation of this element @return the current orientation of this element
*/ */
inline const OrientationSet & Element::orientation() const { inline int Element::orientation() const {
return(ori); return(QET::correctAngle(rotation())/90);
} }
#endif #endif

View File

@ -86,11 +86,11 @@ bool GhostElement::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr,
// orientation // orientation
bool conv_ok; bool conv_ok;
int read_ori = e.attribute("orientation").toInt(&conv_ok); int read_ori = e.attribute("orientation").toInt(&conv_ok);
if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation(); if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
if (handle_inputs_rotation) { if (handle_inputs_rotation) {
RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori); rotateBy(90*read_ori);
} else { } else {
setOrientation((QET::Orientation)read_ori); applyRotation(90*read_ori);
} }
return(true); return(true);
} }

View File

@ -0,0 +1,155 @@
/*
Copyright 2006-2013 The 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 "qetgraphicsitem.h"
/**
* @brief QetGraphicsItem::QetGraphicsItem Default constructor
* @param uuid, uuid of the item
* @param diagram, diagram aka QGraphicsScene of the item
* @param parent, Parent Item
*/
QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent):
QGraphicsObject(parent),
first_move_(true)
{
}
QetGraphicsItem::~QetGraphicsItem()
{}
void QetGraphicsItem::editProperty(){}
/**
* @brief QetGraphicsItem::diagram
*return the diagram of this item
*/
Diagram* QetGraphicsItem::diagram() const{
return(qobject_cast<Diagram *>(scene()));
}
/**
* @brief QetGraphicsItem::setPos
*set the position of the item to p
* @param p the new position of item
*/
void QetGraphicsItem::setPos(const QPointF &p) {
if (p == pos()) return;
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;
QGraphicsItem::setPos(p_x, p_y);
} else QGraphicsItem::setPos(p);
}
/**
* @brief QetGraphicsItem::setPos
*set the position of the item
* @param x new abscisse of item
* @param y new ordonne of item
*/
void QetGraphicsItem::setPos(qreal x, qreal y) {
setPos(QPointF(x, y));
}
/**
Permet de tourner l'item 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 QetGraphicsItem::rotateBy(const qreal &added_rotation) {
qreal applied_added_rotation = QET::correctAngle(added_rotation + rotation());
applyRotation(applied_added_rotation);
}
/**
Effectue la rotation de l'item en lui même
Cette methode peut toutefois etre redefinie dans des classes filles
@param angle Angle de la rotation a effectuer
*/
void QetGraphicsItem::applyRotation(const qreal &angle) {
setRotation(QET::correctAngle(angle));
}
/**
* @brief QetGraphicsItem::mousePressEvent
*handle the mouse click
* @param e
*/
void QetGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {
first_move_ = true;
if (e -> modifiers() & Qt::ControlModifier) {
setSelected(!isSelected());
}
QGraphicsItem::mousePressEvent(e);
}
/**
* @brief QetGraphicsItem::mouseDoubleClickEvent
*handle the mouse double click
* @param e
*/
void QetGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
Q_UNUSED (e);
editProperty();
}
/**
* @brief QetGraphicsItem::mouseMoveEvent
*handle mouse movement
* @param e
*/
void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
if (isSelected() && e -> buttons() & Qt::LeftButton) {
//Item is moving
if(diagram() && 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();
if (first_move_) {
mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton);
}
QPointF expected_pos = e -> scenePos() + mouse_to_origin_movement_;
setPos(expected_pos); // setPos() will snap the expected position to the grid
//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 QetGraphicsItem::mouseReleaseEvent
*handle mouse release click
* @param e
*/
void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
if (diagram()) diagram() -> endMoveElements();
if (!(e -> modifiers() & Qt::ControlModifier)) QGraphicsItem::mouseReleaseEvent(e);
}

View File

@ -0,0 +1,58 @@
/*
Copyright 2006-2013 The 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 QETGRAPHICSITEM_H
#define QETGRAPHICSITEM_H
#include "diagram.h"
class QetGraphicsItem : public QGraphicsObject {
Q_OBJECT
public:
//constructor destructor
QetGraphicsItem(QGraphicsItem *parent = 0);
virtual ~QetGraphicsItem() = 0;
//abstarct methode
virtual void editProperty ();
//public methode
Diagram* diagram() const;
virtual void setPos(const QPointF &p);
virtual void setPos(qreal x, qreal y);
virtual void rotateBy(const qreal &);
virtual void applyRotation(const qreal &);
signals:
public slots:
//protected method
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
protected:
bool first_move_;
QPointF mouse_to_origin_movement_;
};
#endif // QETGRAPHICSITEM_H

View File

@ -17,8 +17,8 @@
*/ */
#include "terminal.h" #include "terminal.h"
#include "diagram.h" #include "diagram.h"
#include "element.h" #include "qetgraphicsitem/element.h"
#include "conductor.h" #include "qetgraphicsitem/conductor.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "qetapp.h" #include "qetapp.h"
@ -131,13 +131,12 @@ Terminal::~Terminal() {
QET::Orientation Terminal::orientation() const { QET::Orientation Terminal::orientation() const {
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) { if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
// orientations actuelle et par defaut de l'element // orientations actuelle et par defaut de l'element
QET::Orientation ori_cur = elt -> orientation().current(); int ori_cur = elt -> orientation();
QET::Orientation ori_def = elt -> orientation().defaultOrientation(); if (ori_cur == 0) return(ori_);
if (ori_cur == ori_def) return(ori_);
else { else {
// calcul l'angle de rotation implique par l'orientation de l'element parent // calcul l'angle de rotation implique par l'orientation de l'element parent
// angle de rotation de la borne sur la scene, divise par 90 // angle de rotation de la borne sur la scene, divise par 90
int angle = ori_cur - ori_def + ori_; int angle = ori_cur + ori_;
while (angle >= 4) angle -= 4; while (angle >= 4) angle -= 4;
return((QET::Orientation)angle); return((QET::Orientation)angle);
} }
@ -213,9 +212,8 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
qreal applied_rotation = 0.0; qreal applied_rotation = 0.0;
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) { if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
// orientations actuelle et par defaut de l'element // orientations actuelle et par defaut de l'element
QET::Orientation ori_cur = elt -> orientation().current(); int ori_cur = elt -> orientation();
QET::Orientation ori_def = elt -> orientation().defaultOrientation(); applied_rotation = QET::correctAngle(90.0 * ori_cur);
applied_rotation = QET::correctAngle(90.0 * (ori_cur - ori_def));
} }
if (applied_rotation == 90.0) p -> translate(1.0, -1.0); if (applied_rotation == 90.0) p -> translate(1.0, -1.0);
else if (applied_rotation == 180.0) p -> translate(-1.0, -1.0); else if (applied_rotation == 180.0) p -> translate(-1.0, -1.0);