From eb601333552300de9ea33a9e9a93db153aaa2da9 Mon Sep 17 00:00:00 2001 From: Nicolas Nenon Date: Fri, 8 Nov 2013 14:31:56 +0100 Subject: [PATCH] Issue Sankore 1554 --- src/adaptors/UBSvgSubsetAdaptor.cpp | 1 + src/board/UBBoardView.cpp | 25 +------------------------ src/domain/UBGraphicsScene.cpp | 16 ++++++++++++++++ src/domain/UBGraphicsScene.h | 1 + src/domain/UBGraphicsTextItem.cpp | 17 ++++++++++++++--- src/domain/UBGraphicsTextItem.h | 4 ++-- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 34ac821c..9462d4da 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -29,6 +29,7 @@ #include #include +#include #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsPixmapItem.h" diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index ed5fabc5..68856255 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -497,30 +497,7 @@ void UBBoardView::handleItemsSelection(QGraphicsItem *item) // only with UB items. if ((UBGraphicsItemType::UserTypesCount > item->type()) && (item->type() > QGraphicsItem::UserType)) { - // if Item can be selected at mouse press - then we need to deselect all other items. - foreach(QGraphicsItem *iter_item, scene()->selectedItems()) - { - if (iter_item != item) - { - iter_item->setSelected(false); - } - } - } - } - }else{ - // Deselect the other items - foreach(QGraphicsItem* it, scene()->selectedItems()){ - UBGraphicsGroupContainerItem* pGroup = dynamic_cast(it); - if(NULL != pGroup){ - foreach(QGraphicsItem* pGIt, pGroup->childItems()){ - UBGraphicsTextItem* pTxt = dynamic_cast(pGIt); - if(NULL != pTxt){ - // We must clear the text selection - QTextCursor t = pTxt->textCursor(); - t.clearSelection(); - pTxt->setTextCursor(t); - } - } + scene()->deselectAllItemsExcept(item); } } } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index e6e1859b..6b5d78f6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1685,6 +1685,22 @@ void UBGraphicsScene::deselectAllItems() if (mSelectionFrame) { mSelectionFrame->setEnclosedItems(QList()); } + UBGraphicsTextItem* textItem = dynamic_cast(gi); + if(textItem) + textItem->activateTextEditor(false); + } +} + +void UBGraphicsScene::deselectAllItemsExcept(QGraphicsItem* item) +{ + foreach(QGraphicsItem* eachItem,selectedItems()){ + if(eachItem != item){ + eachItem->setSelected(false); + + UBGraphicsTextItem* textItem = dynamic_cast(eachItem); + if(textItem) + textItem->activateTextEditor(false); + } } } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index af489271..9d8b5caf 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -317,6 +317,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void clearSelectionFrame(); UBBoardView *controlView(); void notifyZChanged(QGraphicsItem *item, qreal zValue); + void deselectAllItemsExcept(QGraphicsItem* graphicsItem); public slots: void updateSelectionFrame(); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index cb9e4a64..77cab71e 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -47,6 +47,7 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) , mMultiClickState(0) , mLastMousePressTime(QTime::currentTime()) , mTypeTextHereLabel(tr("")) + , isActivatedTextEditor(true) { setDelegate(new UBGraphicsTextItemDelegate(this, 0)); @@ -152,6 +153,7 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) if (mMultiClickState == 1) { + activateTextEditor(true); QGraphicsTextItem::mousePressEvent(event); setFocus(); } @@ -373,8 +375,17 @@ void UBGraphicsTextItem::documentSizeChanged(const QSizeF & newSize) resize(newSize.width(), newSize.height()); } -void UBGraphicsTextItem::setHtml(const QString &text) +void UBGraphicsTextItem::activateTextEditor(bool activate) { - QGraphicsTextItem::setHtml(text); - setTextInteractionFlags(Qt::NoTextInteraction); + qDebug() << textInteractionFlags(); + + this->isActivatedTextEditor = activate; + + if(!activate){ + setTextInteractionFlags(Qt::TextSelectableByMouse); + }else{ + setTextInteractionFlags(Qt::TextEditorInteraction); + } + + qDebug() << textInteractionFlags(); } diff --git a/src/domain/UBGraphicsTextItem.h b/src/domain/UBGraphicsTextItem.h index 5d96c315..806b2112 100644 --- a/src/domain/UBGraphicsTextItem.h +++ b/src/domain/UBGraphicsTextItem.h @@ -94,8 +94,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); - void setHtml(const QString &text); - + void activateTextEditor(bool activate); void setSelected(bool selected); QString mTypeTextHereLabel; @@ -126,6 +125,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes QColor mColorOnDarkBackground; QColor mColorOnLightBackground; + bool isActivatedTextEditor; }; #endif /* UBGRAPHICSTEXTITEM_H_ */