handle drag and drop of text (html work to)

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2585 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2013-10-26 11:46:59 +00:00
parent f091659c35
commit a21b1782d2
2 changed files with 23 additions and 3 deletions

View File

@@ -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));

View File

@@ -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;