mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-30 07:40:51 +01:00
Element editor : hover a primitve will highlight it with a blue halo
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3694 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -45,30 +45,36 @@ ESEventAddArc::~ESEventAddArc() {
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddArc::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
bool ESEventAddArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event -> button() == Qt::LeftButton)
|
||||
{
|
||||
if(!m_running) m_running = true;
|
||||
QPointF pos = m_scene->snapToGrid(event -> scenePos());
|
||||
|
||||
//create new arc
|
||||
if (!m_arc) {
|
||||
m_arc = new PartArc(m_editor, 0, m_scene);
|
||||
m_arc -> setRect(QRectF(pos, pos));
|
||||
m_arc -> setAngle(90);
|
||||
//create new arc
|
||||
if (!m_arc)
|
||||
{
|
||||
m_arc = new PartArc(m_editor);
|
||||
m_scene -> addItem(m_arc);
|
||||
m_arc -> setPos(pos);
|
||||
m_arc -> setProperty("startAngle", 0);
|
||||
m_arc -> setProperty("spanAngle", 1440);
|
||||
m_arc -> setProperty("antialias", true);
|
||||
m_origin = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
//Add arc to scene
|
||||
//At this point, m_arc is finish, we add it with an undo command
|
||||
m_arc -> setRect(m_arc->rect().normalized());
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Arc"), m_scene, m_arc));
|
||||
|
||||
//Set m_arc to nullptr for create new ellipse at next mouse press
|
||||
//Set m_arc to nullptr for create new ellipse at next mouse press
|
||||
m_arc = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -120,67 +126,78 @@ bool ESEventAddArc::keyPressEvent(QKeyEvent *event) {
|
||||
* @brief ESEventAddArc::updateArc
|
||||
* Redraw the arc with curent value
|
||||
*/
|
||||
void ESEventAddArc::updateArc() {
|
||||
|
||||
void ESEventAddArc::updateArc()
|
||||
{
|
||||
qreal width = (m_mouse_pos.x() - m_origin.x())*2;
|
||||
if (width < 0) width *= -1;
|
||||
qreal height = (m_mouse_pos.y() - m_origin.y())*2;
|
||||
if (height < 0) height *= -1;
|
||||
|
||||
QPointF pos_ = m_origin;
|
||||
QPointF pos_ = m_arc -> mapFromScene(m_origin);
|
||||
|
||||
//Draw arc inverted
|
||||
if (m_inverted) {
|
||||
if (m_inverted)
|
||||
{
|
||||
//Adjust the start angle to be snapped at the origin point of draw
|
||||
if (m_mouse_pos.y() > m_origin.y()) {
|
||||
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
if (m_mouse_pos.y() > m_origin.y())
|
||||
{
|
||||
if (m_mouse_pos.x() > m_origin.x())
|
||||
{
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(180);
|
||||
m_arc->setStartAngle(2880);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
pos_.rx() -= width/2;
|
||||
m_arc->setStartAngle(90);
|
||||
m_arc->setStartAngle(1440);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
else
|
||||
{
|
||||
if (m_mouse_pos.x() > m_origin.x())
|
||||
{
|
||||
pos_.ry() -= height;
|
||||
pos_.rx() -= width/2;
|
||||
m_arc->setStartAngle(270);
|
||||
m_arc->setStartAngle(4320);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
pos_.rx() -= width;
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Draw arc non inverted
|
||||
else {
|
||||
//Adjust the start angle to be snapped at the origin point of draw
|
||||
if (m_mouse_pos.y() > m_origin.y()) {
|
||||
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
//Draw arc non inverted
|
||||
else
|
||||
{
|
||||
//Adjust the start angle to be snapped at the origin point of draw
|
||||
if (m_mouse_pos.y() > m_origin.y())
|
||||
{
|
||||
if (m_mouse_pos.x() > m_origin.x())
|
||||
{
|
||||
pos_.rx() -= width/2;
|
||||
m_arc->setStartAngle(0);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
pos_.rx() -= width;
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(270);
|
||||
m_arc->setStartAngle(4320);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_mouse_pos.x() > m_origin.x()) {
|
||||
else
|
||||
{
|
||||
if (m_mouse_pos.x() > m_origin.x())
|
||||
{
|
||||
pos_.ry() -= height/2;
|
||||
m_arc->setStartAngle(90);
|
||||
m_arc->setStartAngle(1440);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
pos_.rx() -= width/2;
|
||||
pos_.ry() -= height;
|
||||
m_arc->setStartAngle(180);
|
||||
m_arc->setStartAngle(2880);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,19 +50,20 @@ bool ESEventAddEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if(!m_running) m_running = true;
|
||||
QPointF pos = m_scene->snapToGrid(event -> scenePos());
|
||||
|
||||
//create new ellpise
|
||||
//create new ellpise
|
||||
if (!m_ellipse) {
|
||||
m_ellipse = new PartEllipse(m_editor, 0, m_scene);
|
||||
m_ellipse -> setRect(QRectF(pos, pos));
|
||||
m_origin = pos;
|
||||
m_ellipse = new PartEllipse(m_editor);
|
||||
m_scene -> addItem(m_ellipse);
|
||||
m_ellipse -> setPos(pos);
|
||||
m_origin = m_new_pos = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
//Add ellipse to scene
|
||||
m_ellipse -> setRect(m_ellipse -> rect().normalized());
|
||||
//Add ellipse to scene
|
||||
m_ellipse -> setRect(m_ellipse -> rect().normalized());
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Ellipse"), m_scene, m_ellipse));
|
||||
|
||||
//Set m_ellipse to nullptr for create new ellipse at next mouse press
|
||||
//Set m_ellipse to nullptr for create new ellipse at next mouse press
|
||||
m_ellipse = nullptr;
|
||||
|
||||
return true;
|
||||
@@ -79,15 +80,16 @@ bool ESEventAddEllipse::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
updateHelpCross(event -> scenePos());
|
||||
if (!m_ellipse) return false;
|
||||
|
||||
QPointF mouse_pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
QPointF pos = m_scene -> snapToGrid(event -> scenePos());
|
||||
if (pos == m_new_pos) return true;
|
||||
m_new_pos = pos;
|
||||
|
||||
qreal width = (mouse_pos.x() - m_origin.x())*2;
|
||||
qreal height = (mouse_pos.y() - m_origin.y())*2;
|
||||
qreal width = (m_new_pos.x() - m_origin.x())*2;
|
||||
qreal height = (m_new_pos.y() - m_origin.y())*2;
|
||||
//calculates the position of the rectangle so that its center is at position (0,0) of m_ellipse
|
||||
QPointF center(-width/2, -height/2);
|
||||
|
||||
QPointF pos(m_origin.x() - width/2,
|
||||
m_origin.y() - height/2);
|
||||
|
||||
m_ellipse -> setRect(QRectF(pos, QSizeF(width, height)));
|
||||
m_ellipse -> setRect(QRectF(center, QSizeF(width, height)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class ESEventAddEllipse : public ESEventInterface
|
||||
|
||||
private:
|
||||
PartEllipse *m_ellipse;
|
||||
QPointF m_origin;
|
||||
QPointF m_origin, m_new_pos;
|
||||
};
|
||||
|
||||
#endif // ESEVENTADDELLIPSE_H
|
||||
|
||||
@@ -57,8 +57,10 @@ bool ESEventAddLine::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
|
||||
//Create new line
|
||||
if (!m_line) {
|
||||
m_line = new PartLine(m_editor, 0, m_scene);
|
||||
m_line -> setLine(QLineF(pos, pos));
|
||||
m_line = new PartLine(m_editor);
|
||||
m_scene -> addItem(m_line);
|
||||
m_line -> setP1(pos);
|
||||
m_line -> setP2(pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ bool ESEventAddPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
|
||||
//create new polygon
|
||||
if (!m_polygon) {
|
||||
m_polygon = new PartPolygon(m_editor, 0, m_scene);
|
||||
m_polygon = new PartPolygon(m_editor);
|
||||
m_scene -> addItem(m_polygon);
|
||||
m_polygon -> addPoint(pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,23 +44,29 @@ ESEventAddRect::~ESEventAddRect() {
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddRect::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
bool ESEventAddRect::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event -> button() == Qt::LeftButton)
|
||||
{
|
||||
if(!m_running) m_running = true;
|
||||
QPointF pos = m_scene->snapToGrid(event -> scenePos());
|
||||
|
||||
//create new rectangle
|
||||
if (!m_rect) {
|
||||
m_rect = new PartRectangle(m_editor, 0, m_scene);
|
||||
//create new rectangle, pos isn't define,
|
||||
//so m_rect.pos = 0,0 , that mean event.scenePos is in same coordinate of item
|
||||
//we don't need to map point for m_rect
|
||||
if (!m_rect)
|
||||
{
|
||||
m_rect = new PartRectangle(m_editor);
|
||||
m_scene -> addItem(m_rect);
|
||||
m_rect -> setRect(QRectF(pos, pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Add rectangle to scene
|
||||
//Add rectangle to scene
|
||||
m_rect -> setRect(m_rect -> rect().normalized());
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Rectangle"), m_scene, m_rect));
|
||||
|
||||
//Set m_rect to nullptr for create new rectangle at next mouse press
|
||||
//Set m_rect to nullptr for create new rectangle at next mouse press
|
||||
m_rect = nullptr;
|
||||
|
||||
return true;
|
||||
@@ -77,7 +83,7 @@ bool ESEventAddRect::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
updateHelpCross(event -> scenePos());
|
||||
if (!m_rect) return false;
|
||||
|
||||
QRectF rect(m_rect -> rect().topLeft(), m_scene->snapToGrid(event -> scenePos()));
|
||||
QRectF rect(m_rect->rectTopLeft(), m_scene->snapToGrid(event -> scenePos()));
|
||||
m_rect -> setRect(rect);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define ESEVENTADDRECT_H
|
||||
|
||||
#include "eseventinterface.h"
|
||||
#include <QPointF>
|
||||
|
||||
class ElementScene;
|
||||
class PartRectangle;
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
ESEventAddTerminal::ESEventAddTerminal(ElementScene *scene) :
|
||||
ESEventInterface(scene)
|
||||
{
|
||||
m_terminal = new PartTerminal(m_editor, 0, m_scene);
|
||||
m_terminal = new PartTerminal(m_editor);
|
||||
m_scene -> addItem(m_terminal);
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
@@ -63,7 +64,8 @@ bool ESEventAddTerminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
|
||||
//Set new terminal with same rotation
|
||||
Qet::Orientation ori = m_terminal -> orientation();
|
||||
m_terminal = new PartTerminal(m_editor, 0, m_scene);
|
||||
m_terminal = new PartTerminal(m_editor);
|
||||
m_scene -> addItem(m_terminal);
|
||||
m_terminal -> setOrientation(ori);
|
||||
m_terminal -> setPos(m_scene -> snapToGrid(event -> scenePos()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user