[qet] [2446] image item can be rotate (minor bug when dragging a rotated image, but it's better than nothing) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2446
Author: blacksun
Date: 2013-08-24 01:09:06 +0200 (Sat, 24 Aug 2013)
Log Message:
-----------
image item can be rotate (minor bug when dragging a rotated image, but it's better than nothing)
Modified Paths:
--------------
branches/0.4/sources/diagram.cpp
branches/0.4/sources/diagramcommands.cpp
branches/0.4/sources/diagramcommands.h
branches/0.4/sources/diagramimageitem.cpp
branches/0.4/sources/diagramimageitem.h
branches/0.4/sources/diagramview.cpp
Modified: branches/0.4/sources/diagram.cpp
===================================================================
--- branches/0.4/sources/diagram.cpp 2013-08-22 15:08:12 UTC (rev 2445)
+++ branches/0.4/sources/diagram.cpp 2013-08-23 23:09:06 UTC (rev 2446)
@@ -1265,6 +1265,8 @@
if (e -> orientation().current() != e -> orientation().next()) {
return(true);
}
+ } else if (qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
+ return (true);
}
}
return(false);
Modified: branches/0.4/sources/diagramcommands.cpp
===================================================================
--- branches/0.4/sources/diagramcommands.cpp 2013-08-22 15:08:12 UTC (rev 2445)
+++ branches/0.4/sources/diagramcommands.cpp 2013-08-23 23:09:06 UTC (rev 2446)
@@ -623,10 +623,11 @@
@param texts Textes a pivoter
@param parent QUndoCommand parent
*/
-RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, QUndoCommand *parent) :
+RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &texts, const QList<DiagramImageItem *> &images, QUndoCommand *parent) :
QUndoCommand(parent),
elements_to_rotate(elements),
texts_to_rotate(texts),
+ images_to_rotate(images),
applied_rotation_angle_(-90.0)
{
setText(
@@ -635,7 +636,7 @@
"pivoter %1",
"undo caption - %1 is a sentence listing the rotated content"
)
- ).arg(QET::ElementsAndConductorsSentence(elements.count(), 0, texts.count()))
+ ).arg(QET::ElementsAndConductorsSentence(elements.count(), 0, texts.count(), images.count()))
);
}
@@ -657,6 +658,7 @@
}
else {dti -> rotateBy(-applied_rotation_angle_);}
}
+ foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(-applied_rotation_angle_);
}
/// refait le pivotement
@@ -672,6 +674,7 @@
}
dti -> rotateBy(applied_rotation_angle_);
}
+ foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(applied_rotation_angle_);
}
/**
Modified: branches/0.4/sources/diagramcommands.h
===================================================================
--- branches/0.4/sources/diagramcommands.h 2013-08-22 15:08:12 UTC (rev 2445)
+++ branches/0.4/sources/diagramcommands.h 2013-08-23 23:09:06 UTC (rev 2446)
@@ -330,7 +330,7 @@
class RotateElementsCommand : public QUndoCommand {
// constructors, destructor
public:
- RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &, QUndoCommand * = 0);
+ RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, const QList<DiagramTextItem *> &, const QList<DiagramImageItem *> &, QUndoCommand * = 0);
virtual ~RotateElementsCommand();
private:
RotateElementsCommand(const RotateElementsCommand &);
@@ -349,6 +349,8 @@
QHash<Element *, QET::Orientation> elements_to_rotate;
/// text items to be rotated
QList<DiagramTextItem *> texts_to_rotate;
+ /// images item to be rotated
+ QList<DiagramImageItem *> images_to_rotate;
/// angle of rotation to be applied to text items
qreal applied_rotation_angle_;
/// previous state of each conductor text item
Modified: branches/0.4/sources/diagramimageitem.cpp
===================================================================
--- branches/0.4/sources/diagramimageitem.cpp 2013-08-22 15:08:12 UTC (rev 2445)
+++ branches/0.4/sources/diagramimageitem.cpp 2013-08-23 23:09:06 UTC (rev 2446)
@@ -21,8 +21,7 @@
#include "qetapp.h"
DiagramImageItem::DiagramImageItem(Diagram *parent_diagram) :
- QGraphicsPixmapItem(0, parent_diagram),
- rotation_angle_(0.0)
+ QGraphicsPixmapItem(0, parent_diagram)
{
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
@@ -38,7 +37,6 @@
*/
DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, Diagram *parent_diagram) :
QGraphicsPixmapItem(pixmap, 0, parent_diagram),
- rotation_angle_(0.0),
first_move_(false)
{
setCursor(Qt::PointingHandCursor);
@@ -62,22 +60,14 @@
}
/**
- @return l'angle de rotation actuel de ce image
-*/
-qreal DiagramImageItem::rotationAngle() const {
- return(rotation_angle_);
-}
-
-/**
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) {
- qreal applied_rotation = QET::correctAngle(rotation);
- applyRotation(applied_rotation - rotation_angle_);
- rotation_angle_ = applied_rotation;
+void DiagramImageItem::setRotationAngle(const qreal &rotation_angle) {
+ qreal applied_rotation = QET::correctAngle(rotation_angle);
+ applyRotation(applied_rotation - rotation());
}
/**
@@ -88,7 +78,6 @@
*/
void DiagramImageItem::rotateBy(const qreal &added_rotation) {
qreal applied_added_rotation = QET::correctAngle(added_rotation);
- rotation_angle_ = QET::correctAngle(rotation_angle_ + applied_added_rotation);
applyRotation(applied_added_rotation);
}
@@ -295,6 +284,7 @@
*/
void DiagramImageItem::applyRotation(const qreal &angle) {
// un simple appel a QGraphicsPixmapItem::setRotation suffit
+ setTransformOriginPoint(boundingRect().center());
QGraphicsPixmapItem::setRotation(QGraphicsPixmapItem::rotation() + angle);
}
@@ -377,7 +367,7 @@
//write some attribute
result.setAttribute("x", QString("%1").arg(pos().x()));
result.setAttribute("y", QString("%1").arg(pos().y()));
- if (rotationAngle()) result.setAttribute("rotation", QString("%1").arg(rotationAngle()));
+ if (rotation()) result.setAttribute("rotation", QString("%1").arg(rotation()));
//write the pixmap in the xml element after he was been transformed to base64
QByteArray array;
Modified: branches/0.4/sources/diagramimageitem.h
===================================================================
--- branches/0.4/sources/diagramimageitem.h 2013-08-22 15:08:12 UTC (rev 2445)
+++ branches/0.4/sources/diagramimageitem.h 2013-08-23 23:09:06 UTC (rev 2446)
@@ -52,7 +52,6 @@
virtual void setPos(const QPointF &);
virtual void setPos(qreal, qreal);
virtual QPointF pos() const;
- qreal rotationAngle() const;
void setRotationAngle(const qreal &);
void rotateBy(const qreal &);
void edit();
@@ -81,8 +80,6 @@
void setNonFocusable();
private:
- /// angle of rotation of the text field
- qreal rotation_angle_;
bool first_move_;
};
#endif
Modified: branches/0.4/sources/diagramview.cpp
===================================================================
--- branches/0.4/sources/diagramview.cpp 2013-08-22 15:08:12 UTC (rev 2445)
+++ branches/0.4/sources/diagramview.cpp 2013-08-23 23:09:06 UTC (rev 2446)
@@ -145,6 +145,7 @@
// recupere les elements et les champs de texte a pivoter
QHash<Element *, QET::Orientation> elements_to_rotate;
QList<DiagramTextItem *> texts_to_rotate;
+ QList<DiagramImageItem *> images_to_rotate;
foreach (QGraphicsItem *item, scene -> selectedItems()) {
if (Element *e = qgraphicsitem_cast<Element *>(item)) {
elements_to_rotate.insert(e, e -> orientation().current());
@@ -157,12 +158,14 @@
if (eti -> parentItem() && !eti -> parentItem() -> isSelected()) {
texts_to_rotate << eti;
}
+ } else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(item)) {
+ images_to_rotate << dii;
}
}
// effectue les rotations s'il y a quelque chose a pivoter
- if (elements_to_rotate.isEmpty() && texts_to_rotate.isEmpty()) return;
- scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate, texts_to_rotate));
+ if (elements_to_rotate.isEmpty() && texts_to_rotate.isEmpty() && images_to_rotate.isEmpty()) return;
+ scene -> undoStack().push(new RotateElementsCommand(elements_to_rotate, texts_to_rotate, images_to_rotate));
}
void DiagramView::rotateTexts() {