28 QGraphicsView(scene, parent),
30 offset_paste_count_(0)
32 grabGesture(Qt::PinchGesture);
33 setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
35 setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
36 setResizeAnchor(QGraphicsView::AnchorUnderMouse);
37 setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
57 QSize viewport_size = viewport() -> size();
60 QTransform view_to_scene = viewportTransform().inverted();
63 QPointF scene_left_top = view_to_scene.map(QPointF(0.0, 0.0));
64 QPointF scene_right_bottom = view_to_scene.map(QPointF(viewport_size.width(), viewport_size.height()));
67 return(QRectF(scene_left_top, scene_right_bottom));
75 QGraphicsView::setScene(s);
83 setDragMode(ScrollHandDrag);
84 setInteractive(
false);
92 setDragMode(RubberBandDrag);
102 scale(4.0/3.0, 4.0/3.0);
134 fitInView(sceneRect(), Qt::KeepAspectRatio);
152 QRectF esgr =
m_scene -> elementSceneGeometricRect();
153 QRectF vpbr = mapToScene(
this -> viewport()->rect()).boundingRect();
154 QRectF new_scene_rect = vpbr.adjusted(-vpbr.width()/3, -vpbr.height()/3, vpbr.width()/3, vpbr.height()/3);
155 setSceneRect(new_scene_rect.united(esgr));
164 setSceneRect(
m_scene -> elementSceneGeometricRect());
198 QString clipboard_text = QApplication::clipboard() -> text();
199 if (clipboard_text.isEmpty())
return;
201 QDomDocument document_xml;
202 if (!document_xml.setContent(clipboard_text))
return;
204 if (
m_scene -> wasCopiedFromThisElement(clipboard_text)) {
209 QRectF pasted_content_bounding_rect =
m_scene -> boundingRectFromXml(document_xml);
210 if (pasted_content_bounding_rect.isEmpty())
return;
222 QString clipboard_text = QApplication::clipboard() -> text();
223 if (clipboard_text.isEmpty())
return;
225 QDomDocument document_xml;
226 if (!document_xml.setContent(clipboard_text))
return;
228 QRectF pasted_content_bounding_rect =
m_scene -> boundingRectFromXml(document_xml);
229 if (pasted_content_bounding_rect.isEmpty())
return;
244 QString clipboard_text = QApplication::clipboard() -> text();
247 QDomDocument document_xml;
248 if (!document_xml.setContent(clipboard_text))
return(
ElementContent());
251 return(
paste(document_xml, position));
259 QRectF used_rect(to_paste);
263 used_rect.moveCenter(mapToScene(mapFromGlobal(QCursor::pos())));
265 used_rect.moveCenter(QPointF(0.0, 0.0));
277 QDomDocument xml_document;
282 return(
paste(xml_document, target_rect.topLeft()));
294 m_scene -> fromXml(xml_document, pos,
false, &content_pasted);
297 if (content_pasted.count()) {
300 m_scene -> undoStack().push(undo_object);
302 return(content_pasted);
314 QRectF pasted_content_bounding_rect =
m_scene -> boundingRectFromXml(xml_document);
315 if (pasted_content_bounding_rect.isEmpty())
return(content_pasted);
318 QRectF final_pasted_content_bounding_rect;
323 final_pasted_content_bounding_rect = pasted_content_bounding_rect;
335 pasted_content_bounding_rect,
344 if (content_pasted.count()) {
348 m_scene -> undoStack().push(undo_object);
350 return(content_pasted);
359 if (e->buttons() == Qt::MidButton)
361 setCursor( (Qt::ClosedHandCursor));
365 QGraphicsView::mousePressEvent(e);
373 if (e->buttons() == Qt::MidButton)
375 QScrollBar *h = horizontalScrollBar();
376 QScrollBar *v = verticalScrollBar();
379 h -> setValue(h -> value() + pos.x());
380 v -> setValue(v -> value() + pos.y());
383 QGraphicsView::mouseMoveEvent(e);
391 if (e -> button() == Qt::MidButton) {
392 setCursor(Qt::ArrowCursor);
396 QGraphicsView::mouseReleaseEvent(e);
406 return(settings.value(
"diagramview/gestures",
false).toBool());
417 if (e -> modifiers() & Qt::ControlModifier)
420 QGraphicsView::wheelEvent(e);
435 if (e->type() == QEvent::Gesture)
438 return(QGraphicsView::event(e));
448 if (QGesture *gesture =
event->gesture(Qt::PinchGesture)) {
449 QPinchGesture *pinch =
static_cast<QPinchGesture *
>(gesture);
450 if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged){
451 qreal value = gesture->property(
"scaleFactor").toReal();
472 p -> setRenderHint(QPainter::Antialiasing,
false);
473 p -> setRenderHint(QPainter::TextAntialiasing,
true);
474 p -> setRenderHint(QPainter::SmoothPixmapTransform,
false);
477 p -> setPen(Qt::NoPen);
478 p -> setBrush(Qt::white);
482 qreal zoom_factor = matrix().m11();
485 int drawn_x_grid = 1;
486 int drawn_y_grid = 1;
487 bool draw_grid =
true;
488 bool draw_cross =
false;
490 if (zoom_factor < (4.0/3.0)) {
492 }
else if (zoom_factor < 4.0) {
495 }
else if (zoom_factor < 8.0) {
499 }
else if (zoom_factor < 10.0) {
512 pen.setCosmetic(
true);
514 p -> setBrush(Qt::NoBrush);
515 qreal limite_x = r.x() + r.width();
516 qreal limite_y = r.y() + r.height();
518 int g_x = (int)ceil(r.x());
519 while (g_x % drawn_x_grid) ++ g_x;
520 int g_y = (int)ceil(r.y());
521 while (g_y % drawn_y_grid) ++ g_y;
523 for (
int gx = g_x ; gx < limite_x ; gx += drawn_x_grid) {
524 for (
int gy = g_y ; gy < limite_y ; gy += drawn_y_grid) {
526 if (!(gx % 10) && !(gy % 10)) {
527 p -> drawLine(QLineF(gx - 0.25, gy, gx + 0.25, gy));
528 p -> drawLine(QLineF(gx, gy - 0.25, gx, gy + 0.25));
530 p -> drawPoint(gx, gy);
533 p -> drawPoint(gx, gy);
549 QPointF final_offset;
550 final_offset.rx() = start.width() + offset.x();
553 return(start.translated(final_offset));
QRectF viewedSceneRect() const
ElementScene * scene() const
void wheelEvent(QWheelEvent *) override
ElementView::wheelEvent.
void setScene(ElementScene *)
void modeChanged()
Signal emitted after the mode changed.
void mouseReleaseEvent(QMouseEvent *) override
ElementView::mouseReleaseEvent Manage event release click mouse.
void setVisualisationMode()
bool gestures() const
ElementView::gestures.
void resetSceneRect()
ElementView::resetSceneRect reset le sceneRect (zone du schéma visualisée par l'ElementView) afin que...
virtual void setGrid(int, int)
bool gestureEvent(QGestureEvent *event)
ElementView::gestureEvent.
void adjustSceneRect()
ElementView::adjustSceneRect Adjust the scenRect, so that he include all primitives of element plus t...
~ElementView() override
Destructeur.
void mousePressEvent(QMouseEvent *) override
void getPasteArea(const QRectF &)
ElementContent pasteAreaDefined(const QRectF &)
static QPointF pasteOffset()
void drawBackground(QPainter *, const QRectF &) override
ElementView(ElementScene *, QWidget *=nullptr)
QPointF start_top_left_corner_
QList< QGraphicsItem * > ElementContent
ElementContent pasteWithOffset(const QDomDocument &)
QRectF applyMovement(const QRectF &, const QPointF &)
void mouseMoveEvent(QMouseEvent *) override
ElementView::mouseMoveEvent Manage the event move mouse.
bool event(QEvent *event) override
QString to_paste_in_area_
friend class PastePartsCommand