mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Basic Primitive shapes added (line,rectangle,ellipse). Default style dashed.
Pending work: 1. DXF Export 2. XML Import / Export 3. Properties Edit option (line style/colour/weight) 4. Debugging required git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2873 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include "factory/elementfactory.h"
|
||||
#include "qetgraphicsitem/qetshapeitem.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -451,16 +452,43 @@ void DiagramView::mousePressEvent(QMouseEvent *e) {
|
||||
break;
|
||||
case addingText:
|
||||
addDiagramTextAtPos(mapToScene(e -> pos()));
|
||||
current_behavior = noAction;
|
||||
break;
|
||||
case addingImage:
|
||||
addDiagramImageAtPos(mapToScene(e -> pos()));
|
||||
current_behavior = noAction;
|
||||
break;
|
||||
case addingLine:
|
||||
if (!rubber_band) {
|
||||
rubber_band_origin = mapToScene(e -> pos());
|
||||
rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
}
|
||||
rubber_band->setGeometry(QRectF(rubber_band_origin, QSize()).toRect());
|
||||
rubber_band->show();
|
||||
break;
|
||||
case addingRectangle:
|
||||
if (!rubber_band) {
|
||||
rubber_band_origin = mapToScene(e -> pos());
|
||||
rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
}
|
||||
rubber_band->setGeometry(QRectF(rubber_band_origin, QSize()).toRect());
|
||||
rubber_band->show();
|
||||
break;
|
||||
case addingEllipse:
|
||||
if (!rubber_band) {
|
||||
rubber_band_origin = mapToScene(e -> pos());
|
||||
rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
|
||||
}
|
||||
rubber_band->setGeometry(QRectF(rubber_band_origin, QSize()).toRect());
|
||||
rubber_band->show();
|
||||
break;
|
||||
case dragView:
|
||||
current_behavior = noAction;
|
||||
break;
|
||||
default:
|
||||
current_behavior = noAction;
|
||||
break;
|
||||
}
|
||||
current_behavior = noAction;
|
||||
}
|
||||
// workaround for drag view with hold wheel click and drag mouse
|
||||
// see also mouseMoveEvent() and mouseReleaseEvent()
|
||||
@@ -484,6 +512,9 @@ void DiagramView::mouseMoveEvent(QMouseEvent *e) {
|
||||
center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center();
|
||||
return;
|
||||
}
|
||||
if ((e -> buttons() & Qt::LeftButton) &&
|
||||
(current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse))
|
||||
rubber_band -> setGeometry(QRectF(rubber_band_origin, mapToScene(e->pos())).normalized().toRect());
|
||||
QGraphicsView::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
@@ -496,6 +527,30 @@ void DiagramView::mouseReleaseEvent(QMouseEvent *e) {
|
||||
setCursor(Qt::ArrowCursor);
|
||||
return;
|
||||
}
|
||||
if (current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse) {
|
||||
QRectF rec = QRectF(rubber_band_origin, mapToScene(e->pos())).normalized();
|
||||
if (current_behavior == addingLine) {
|
||||
QetShapeItem *line;
|
||||
if (rubber_band_origin == rec.topLeft() || rubber_band_origin == rec.bottomRight())
|
||||
line = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Line, false);
|
||||
else
|
||||
line = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Line, true);
|
||||
scene -> addItem(line);
|
||||
emit(LineAdded(false));
|
||||
} else if (current_behavior == addingRectangle) {
|
||||
QetShapeItem *rect = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Rectangle);
|
||||
scene -> addItem(rect);
|
||||
emit(RectangleAdded(false));
|
||||
} else { // ellipse
|
||||
QetShapeItem *ellipse = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Ellipse);
|
||||
scene -> addItem(ellipse);
|
||||
emit(EllipseAdded(false));
|
||||
}
|
||||
rubber_band -> hide();
|
||||
rubber_band = 0;
|
||||
current_behavior = noAction;
|
||||
}
|
||||
|
||||
QGraphicsView::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
@@ -1194,6 +1249,27 @@ void DiagramView::addImage() {
|
||||
current_behavior = addingImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramView::addLine
|
||||
*/
|
||||
void DiagramView::addLine() {
|
||||
current_behavior = addingLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramView::addRectangle
|
||||
*/
|
||||
void DiagramView::addRectangle() {
|
||||
current_behavior = addingRectangle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramView::addEllipse
|
||||
*/
|
||||
void DiagramView::addEllipse() {
|
||||
current_behavior = addingEllipse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramView::editImage
|
||||
* open edit image dialog if only one image is selected
|
||||
|
||||
@@ -38,7 +38,7 @@ class DiagramView : public QGraphicsView {
|
||||
DiagramView(Diagram * = 0, QWidget * = 0);
|
||||
virtual ~DiagramView();
|
||||
|
||||
enum behavior {noAction, addingText, addingImage, dragView};
|
||||
enum behavior {noAction, addingText, addingImage, addingLine, addingRectangle, addingEllipse, dragView};
|
||||
|
||||
private:
|
||||
DiagramView(const DiagramView &);
|
||||
@@ -57,6 +57,8 @@ class DiagramView : public QGraphicsView {
|
||||
QPointF reference_view_;
|
||||
QPointF center_view_;
|
||||
QImage image_to_add_;
|
||||
QRubberBand *rubber_band;
|
||||
QPointF rubber_band_origin;
|
||||
|
||||
// methods
|
||||
public:
|
||||
@@ -75,6 +77,9 @@ class DiagramView : public QGraphicsView {
|
||||
void addText();
|
||||
void editText();
|
||||
void addImage();
|
||||
void addLine();
|
||||
void addRectangle();
|
||||
void addEllipse();
|
||||
void editImage();
|
||||
IndependentTextItem *addDiagramTextAtPos(const QPointF &, const QString &text = 0);
|
||||
DiagramImageItem *addDiagramImageAtPos(const QPointF &);
|
||||
@@ -129,6 +134,12 @@ class DiagramView : public QGraphicsView {
|
||||
void editTitleBlockTemplate(const QString &, bool);
|
||||
/// Signal emitted after a image was added
|
||||
void ImageAdded(bool);
|
||||
/// Signal emitted after a line was added
|
||||
void LineAdded(bool);
|
||||
/// Signal emitted after a rectangle was added
|
||||
void RectangleAdded(bool);
|
||||
/// Signal emitted after a ellipse was added
|
||||
void EllipseAdded(bool);
|
||||
/// Signal emmitted fater windows selection image have been canceled
|
||||
void ImageAddedCanceled(bool);
|
||||
/// Signal emmitted when diagram must be show
|
||||
|
||||
@@ -217,6 +217,9 @@ void QETDiagramEditor::actions() {
|
||||
add_text = new QAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte"), this);
|
||||
add_column = new QAction(QET::Icons::EditTableInsertColumnRight, tr("Ajouter une colonne"), this);
|
||||
add_image = new QAction(QET::Icons::adding_image, tr("Ajouter une image"), this);
|
||||
add_line = new QAction(QET::Icons::PartLine, tr("Ajouter une line"), this);
|
||||
add_rectangle = new QAction(QET::Icons::PartRectangle, tr("Ajouter une rectangle"), this);
|
||||
add_ellipse = new QAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse"), this);
|
||||
remove_column = new QAction(QET::Icons::EditTableDeleteColumn, tr("Enlever une colonne"), this);
|
||||
add_row = new QAction(QET::Icons::EditTableInsertRowUnder, tr("Ajouter une ligne"), this);
|
||||
remove_row = new QAction(QET::Icons::EditTableDeleteRow, tr("Enlever une ligne"), this);
|
||||
@@ -341,6 +344,9 @@ void QETDiagramEditor::actions() {
|
||||
// traitements speciaux
|
||||
add_text -> setCheckable(true);
|
||||
add_image -> setCheckable(true);
|
||||
add_line -> setCheckable(true);
|
||||
add_rectangle -> setCheckable(true);
|
||||
add_ellipse -> setCheckable(true);
|
||||
windowed_view_mode -> setCheckable(true);
|
||||
tabbed_view_mode -> setCheckable(true);
|
||||
mode_selection -> setCheckable(true);
|
||||
@@ -403,6 +409,9 @@ void QETDiagramEditor::actions() {
|
||||
connect(infos_diagram, SIGNAL(triggered()), this, SLOT(editCurrentDiagramProperties()));
|
||||
connect(add_text, SIGNAL(triggered()), this, SLOT(slot_addText()) );
|
||||
connect(add_image, SIGNAL(triggered()), this, SLOT(slot_addImage()) );
|
||||
connect(add_line, SIGNAL(triggered()), this, SLOT(slot_addLine()) );
|
||||
connect(add_rectangle, SIGNAL(triggered()), this, SLOT(slot_addRectangle()) );
|
||||
connect(add_ellipse, SIGNAL(triggered()), this, SLOT(slot_addEllipse()) );
|
||||
connect(add_column, SIGNAL(triggered()), this, SLOT(slot_addColumn()) );
|
||||
connect(remove_column, SIGNAL(triggered()), this, SLOT(slot_removeColumn()) );
|
||||
connect(add_row, SIGNAL(triggered()), this, SLOT(slot_addRow()) );
|
||||
@@ -568,6 +577,9 @@ void QETDiagramEditor::toolbar() {
|
||||
diagram_bar -> addAction(conductor_reset);
|
||||
diagram_bar -> addAction(add_text);
|
||||
diagram_bar -> addAction(add_image);
|
||||
diagram_bar -> addAction(add_line);
|
||||
diagram_bar -> addAction(add_rectangle);
|
||||
diagram_bar -> addAction(add_ellipse);
|
||||
|
||||
// ajout de la barre d'outils a la fenetre principale
|
||||
addToolBar(Qt::TopToolBarArea, main_bar);
|
||||
@@ -1519,7 +1531,10 @@ void QETDiagramEditor::slot_resetConductors() {
|
||||
Ajoute un texte au schema courant
|
||||
*/
|
||||
void QETDiagramEditor::slot_addText() {
|
||||
add_image -> setChecked(false);
|
||||
add_image -> setChecked(false);
|
||||
add_line -> setChecked(false);
|
||||
add_rectangle -> setChecked(false);
|
||||
add_ellipse -> setChecked(false);
|
||||
if (DiagramView *dv = currentDiagram()) {
|
||||
dv -> addText();
|
||||
}
|
||||
@@ -1528,12 +1543,45 @@ void QETDiagramEditor::slot_addText() {
|
||||
Ajoute une image au schema courant
|
||||
*/
|
||||
void QETDiagramEditor::slot_addImage() {
|
||||
add_text -> setChecked(false);
|
||||
add_text -> setChecked(false);
|
||||
add_line -> setChecked(false);
|
||||
add_rectangle -> setChecked(false);
|
||||
add_ellipse -> setChecked(false);
|
||||
if (DiagramView *dv = currentDiagram()) {
|
||||
dv -> addImage();
|
||||
}
|
||||
}
|
||||
|
||||
void QETDiagramEditor::slot_addLine() {
|
||||
add_text -> setChecked(false);
|
||||
add_image -> setChecked(false);
|
||||
add_rectangle -> setChecked(false);
|
||||
add_ellipse -> setChecked(false);
|
||||
if (DiagramView *dv = currentDiagram()) {
|
||||
dv -> addLine();
|
||||
}
|
||||
}
|
||||
|
||||
void QETDiagramEditor::slot_addRectangle() {
|
||||
add_text -> setChecked(false);
|
||||
add_image -> setChecked(false);
|
||||
add_line -> setChecked(false);
|
||||
add_ellipse -> setChecked(false);
|
||||
if (DiagramView *dv = currentDiagram()) {
|
||||
dv -> addRectangle();
|
||||
}
|
||||
}
|
||||
|
||||
void QETDiagramEditor::slot_addEllipse() {
|
||||
add_text -> setChecked(false);
|
||||
add_image -> setChecked(false);
|
||||
add_line -> setChecked(false);
|
||||
add_rectangle -> setChecked(false);
|
||||
if (DiagramView *dv = currentDiagram()) {
|
||||
dv -> addEllipse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETDiagramEditor::slot_editSelection
|
||||
* edit the selected item if he can be edited and if only one item is selected
|
||||
@@ -1846,6 +1894,9 @@ void QETDiagramEditor::diagramWasAdded(DiagramView *dv) {
|
||||
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
|
||||
connect(dv, SIGNAL(textAdded(bool)), add_text, SLOT(setChecked(bool)));
|
||||
connect(dv, SIGNAL(ImageAdded(bool)), add_image, SLOT(setChecked(bool)));
|
||||
connect(dv, SIGNAL(LineAdded(bool)), add_line, SLOT(setChecked(bool)));
|
||||
connect(dv, SIGNAL(RectangleAdded(bool)), add_rectangle, SLOT(setChecked(bool)));
|
||||
connect(dv, SIGNAL(EllipseAdded(bool)), add_ellipse, SLOT(setChecked(bool)));
|
||||
connect(dv, SIGNAL(ImageAddedCanceled(bool)), add_image, SLOT(setChecked(bool)));
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,9 @@ class QETDiagramEditor : public QETMainWindow {
|
||||
void slot_resetConductors();
|
||||
void slot_addText();
|
||||
void slot_addImage();
|
||||
void slot_addLine();
|
||||
void slot_addRectangle();
|
||||
void slot_addEllipse();
|
||||
void slot_editSelection();
|
||||
void setWindowedMode();
|
||||
void setTabbedMode();
|
||||
@@ -219,6 +222,9 @@ class QETDiagramEditor : public QETMainWindow {
|
||||
QAction *prev_window; ///< Switch to the previous document
|
||||
QAction *next_window; ///< Switch to the next document
|
||||
QAction *add_image; ///< Tool to add an independent image item on diagrams
|
||||
QAction *add_line; ///< Tool to add an independent line shape item on diagrams
|
||||
QAction *add_rectangle; ///< Tool to add an independent rectangle shape item on diagrams
|
||||
QAction *add_ellipse; ///< Tool to add an independent ellipse shape item on diagrams
|
||||
QAction *edit_selection; ///< To edit selected item
|
||||
|
||||
private:
|
||||
|
||||
45
sources/qetgraphicsitem/qetshapeitem.cpp
Normal file
45
sources/qetgraphicsitem/qetshapeitem.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "qetshapeitem.h"
|
||||
|
||||
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
|
||||
QetGraphicsItem(parent),
|
||||
_shapeStyle(Qt::DashLine),
|
||||
_lineAngle(lineAngle)
|
||||
{
|
||||
_shapeType = type;
|
||||
_boundingRect = QRectF(p1, p2);
|
||||
}
|
||||
|
||||
QetShapeItem::~QetShapeItem()
|
||||
{
|
||||
}
|
||||
|
||||
void QetShapeItem::setStyle(Qt::PenStyle newStyle)
|
||||
{
|
||||
_shapeStyle = newStyle;
|
||||
}
|
||||
|
||||
QRectF QetShapeItem::boundingRect() const
|
||||
{
|
||||
return _boundingRect;
|
||||
}
|
||||
|
||||
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
QRectF rec = boundingRect();
|
||||
QPen pen(Qt::black);
|
||||
pen.setStyle(_shapeStyle);
|
||||
painter->setPen(pen);
|
||||
switch(_shapeType) {
|
||||
case Line:
|
||||
if (_lineAngle)
|
||||
painter -> drawLine(rec.topRight(), rec.bottomLeft());
|
||||
else
|
||||
painter -> drawLine(rec.topLeft(), rec.bottomRight());
|
||||
break;
|
||||
case Rectangle:
|
||||
painter -> drawRect(rec);
|
||||
break;
|
||||
default: //(case Ellipse:)
|
||||
painter ->drawEllipse(rec);
|
||||
}
|
||||
}
|
||||
35
sources/qetgraphicsitem/qetshapeitem.h
Normal file
35
sources/qetgraphicsitem/qetshapeitem.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef QETSHAPEITEM_H
|
||||
#define QETSHAPEITEM_H
|
||||
|
||||
#include "qetgraphicsitem.h"
|
||||
|
||||
class QetShapeItem : public QetGraphicsItem
|
||||
{
|
||||
public:
|
||||
|
||||
enum ShapeType {
|
||||
Line,
|
||||
Rectangle,
|
||||
Ellipse
|
||||
};
|
||||
|
||||
QetShapeItem(QPointF, QPointF, ShapeType, bool lineAngle = false, QGraphicsItem *parent = 0);
|
||||
virtual ~QetShapeItem();
|
||||
|
||||
private:
|
||||
ShapeType _shapeType;
|
||||
Qt::PenStyle _shapeStyle;
|
||||
QRectF _boundingRect;
|
||||
bool _lineAngle; // false if line from topleft corner to bottomright corner
|
||||
// and true if line from topright corner to bottomleft corner
|
||||
|
||||
void setStyle(Qt::PenStyle);
|
||||
virtual void editProperty() {}
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
QRectF boundingRect() const;
|
||||
|
||||
};
|
||||
|
||||
#endif // QETSHAPEITEM_H
|
||||
Reference in New Issue
Block a user