diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 40e613afc..b4941f53d 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -232,6 +232,8 @@ void DiagramView::dragEnterEvent(QDragEnterEvent *e) { e -> acceptProposedAction(); } else if (e -> mimeData() -> hasFormat("application/x-qet-titleblock-uri")) { e -> acceptProposedAction(); + } else if (e -> mimeData() -> hasText()) { + e -> acceptProposedAction(); } else { e -> ignore(); } @@ -264,6 +266,8 @@ void DiagramView::dropEvent(QDropEvent *e) { handleElementDrop(e); } else if (e -> mimeData() -> hasFormat("application/x-qet-titleblock-uri")) { handleTitleBlockDrop(e); + } else if (e -> mimeData() -> hasText()) { + handleTextDrop(e); } } @@ -300,6 +304,18 @@ void DiagramView::handleTitleBlockDrop(QDropEvent *e) { } } +/** + * @brief DiagramView::handleTextDrop + *handle the drop of text, html markup are automatically detected. + * @param e the QDropEvent describing the current drag'n drop + */ +void DiagramView::handleTextDrop(QDropEvent *e) { + if (e -> mimeData() -> hasText()) { + if (e -> mimeData() -> hasHtml()) addDiagramTextAtPos(e->pos()) -> setHtml(e -> mimeData() -> text()); + else addDiagramTextAtPos(e -> pos(), e -> mimeData() -> text()); + } +} + /** Set the Diagram in visualisation mode */ @@ -1311,11 +1327,14 @@ DiagramImageItem *DiagramView::addDiagramImageAtPos(const QPointF &pos) { @param pos Position du champ de texte ajoute @return le champ de texte ajoute */ -IndependentTextItem *DiagramView::addDiagramTextAtPos(const QPointF &pos) { +IndependentTextItem *DiagramView::addDiagramTextAtPos(const QPointF &pos, const QString text) { if (!isInteractive() || scene -> isReadOnly()) return(0); // cree un nouveau champ de texte - IndependentTextItem *iti = new IndependentTextItem("_"); + IndependentTextItem *iti; + if (text.isEmpty()) { + iti = new IndependentTextItem("_"); + } else iti = new IndependentTextItem(text); // le place a la position pos en gerant l'annulation scene -> undoStack().push(new AddTextCommand(scene, iti, pos)); diff --git a/sources/diagramview.h b/sources/diagramview.h index 2325b0294..ab3465a18 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -76,7 +76,7 @@ class DiagramView : public QGraphicsView { void editText(); void addImage(); void editImage(); - IndependentTextItem *addDiagramTextAtPos(const QPointF &); + IndependentTextItem *addDiagramTextAtPos(const QPointF &, const QString text = 0); DiagramImageItem *addDiagramImageAtPos(const QPointF &); protected: @@ -102,6 +102,7 @@ class DiagramView : public QGraphicsView { void dropEvent(QDropEvent *); void handleElementDrop(QDropEvent *); void handleTitleBlockDrop(QDropEvent *); + void handleTextDrop(QDropEvent *); QRectF viewedSceneRect() const; bool mustIntegrateElement(const ElementsLocation &) const; bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const;