Eraising elements

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent e232bbc900
commit eb53715d6c
  1. 2
      src/api/UBWidgetUniboardAPI.cpp
  2. 8
      src/board/UBBoardController.cpp
  3. 2
      src/desktop/UBDesktopAnnotationController.cpp
  4. 5
      src/domain/UBGraphicsGroupContainerItem.cpp
  5. 19
      src/domain/UBGraphicsItemDelegate.cpp
  6. 1
      src/domain/UBGraphicsItemDelegate.h
  7. 152
      src/domain/UBGraphicsScene.cpp
  8. 12
      src/domain/UBGraphicsScene.h
  9. 9
      src/domain/UBGraphicsTextItemDelegate.cpp
  10. 1
      src/domain/UBGraphicsTextItemDelegate.h
  11. 43
      src/domain/UBItem.cpp
  12. 1
      src/domain/UBItem.h

@ -250,7 +250,7 @@ void UBWidgetUniboardAPI::eraseLineTo(const qreal x, const qreal y, const qreal
void UBWidgetUniboardAPI::clear() void UBWidgetUniboardAPI::clear()
{ {
if (mScene) if (mScene)
mScene->clearItemsAndAnnotations(); mScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations);
} }

@ -683,7 +683,7 @@ void UBBoardController::clearScene()
if (mActiveScene) if (mActiveScene)
{ {
freezeW3CWidgets(true); freezeW3CWidgets(true);
mActiveScene->clearItemsAndAnnotations(); mActiveScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations);
updateActionStates(); updateActionStates();
} }
} }
@ -694,7 +694,7 @@ void UBBoardController::clearSceneItems()
if (mActiveScene) if (mActiveScene)
{ {
freezeW3CWidgets(true); freezeW3CWidgets(true);
mActiveScene->clearItems(); mActiveScene->clearContent(UBGraphicsScene::clearItems);
updateActionStates(); updateActionStates();
} }
} }
@ -704,7 +704,7 @@ void UBBoardController::clearSceneAnnotation()
{ {
if (mActiveScene) if (mActiveScene)
{ {
mActiveScene->clearAnnotations(); mActiveScene->clearContent(UBGraphicsScene::clearAnnotations);
updateActionStates(); updateActionStates();
} }
} }
@ -713,7 +713,7 @@ void UBBoardController::clearSceneBackground()
{ {
if (mActiveScene) if (mActiveScene)
{ {
mActiveScene->clearBackground(); mActiveScene->clearContent(UBGraphicsScene::clearBackground);
updateActionStates(); updateActionStates();
} }
} }

@ -274,7 +274,7 @@ void UBDesktopAnnotationController::eraseDesktopAnnotations()
{ {
if (mTransparentDrawingScene) if (mTransparentDrawingScene)
{ {
mTransparentDrawingScene->clearAnnotations(); mTransparentDrawingScene->clearContent(UBGraphicsScene::clearAnnotations);
} }
} }

@ -78,7 +78,10 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
QTransform newItemTransform(itemTransform); QTransform newItemTransform(itemTransform);
item->setPos(mapFromItem(item, 0, 0)); item->setPos(mapFromItem(item, 0, 0));
item->scene()->removeItem(item); if (item->scene()) {
item->scene()->removeItem(item);
}
if (corescene()) if (corescene())
corescene()->removeItemFromDeletion(item); corescene()->removeItemFromDeletion(item);
item->setParentItem(this); item->setParentItem(this);

@ -387,12 +387,25 @@ void UBGraphicsItemDelegate::remove(bool canUndo)
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene()); UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
if (scene) if (scene)
{ {
foreach(DelegateButton* button, mButtons) // bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control;
scene->removeItem(button); // showHide(shownOnDisplay);
// updateFrame();
// updateButtons();
if (mFrame && !mFrame->scene() && mDelegated->scene())
{
mDelegated->scene()->addItem(mFrame);
}
mFrame->setAntiScale(mAntiScaleRatio);
mFrame->positionHandles();
updateButtons(true);
foreach(DelegateButton* button, mButtons) {
scene->removeItem(button);
}
scene->removeItem(mFrame); scene->removeItem(mFrame);
/* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */
UBGraphicsWebView *mDelegated_casted = dynamic_cast<UBGraphicsWebView*>(mDelegated); UBGraphicsWebView *mDelegated_casted = dynamic_cast<UBGraphicsWebView*>(mDelegated);
if (mDelegated_casted) if (mDelegated_casted)
mDelegated_casted->setHtml(QString()); mDelegated_casted->setHtml(QString());

@ -244,6 +244,7 @@ class UBGraphicsItemDelegate : public QObject
UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; }
qreal antiScaleRatio() const { return mAntiScaleRatio; } qreal antiScaleRatio() const { return mAntiScaleRatio; }
virtual void update() {positionHandles();}
signals: signals:
void showOnDisplayChanged(bool shown); void showOnDisplayChanged(bool shown);

@ -1071,115 +1071,72 @@ UBItem* UBGraphicsScene::deepCopy() const
return sceneDeepCopy(); return sceneDeepCopy();
} }
void UBGraphicsScene::clearItemsAndAnnotations() void UBGraphicsScene::clearContent(clearCase pCase)
{ {
deselectAllItems();
QSet<QGraphicsItem*> emptyList;
QSet<QGraphicsItem*> removedItems;
QList<QGraphicsItem*> sceneItems = items();
foreach(QGraphicsItem* item, sceneItems)
{
if(!mTools.contains(item) && !isBackgroundObject(item))
{
removeItem(item);
removedItems << item;
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
update(sceneRect());
if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList);
UBApplication::undoStack->push(uc);
}
setDocumentUpdated();
}
bool isService(QGraphicsItem *item) {
return (item->type() == UBGraphicsDelegateFrame::Type)
|| (item->parentItem() && item->parentItem()->Type == UBGraphicsDelegateFrame::Type);
}
void UBGraphicsScene::clearItems()
{
deselectAllItems();
QSet<QGraphicsItem*> emptyList;
QSet<QGraphicsItem*> removedItems; QSet<QGraphicsItem*> removedItems;
QList<QGraphicsItem*> sceneItems = items(); switch (pCase) {
foreach(QGraphicsItem* item, sceneItems) case clearBackground :
{ removeItem(mBackgroundObject);
bool isGroup = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item) != NULL; removedItems << mBackgroundObject;
bool isPolygon = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item) != NULL; break;
bool isStrokesGroup = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item) != NULL;
case clearItemsAndAnnotations :
bool inGroup = (item->parentItem() case clearItems :
&& (item->parentItem()->type() == UBGraphicsGroupContainerItem::Type)); case clearAnnotations :
foreach(QGraphicsItem* item, items()) {
if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) {
removeItem(item); bool isGroup = item->type() == UBGraphicsGroupContainerItem::Type;
} bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type;
if (!inGroup || !isService(item)) {
removedItems << item; UBGraphicsGroupContainerItem *itemGroup = item->parentItem()
} ? qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem())
} : 0;
UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item);
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint if (!curDelegate) {
update(sceneRect()); continue;
}
if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList);
UBApplication::undoStack->push(uc);
}
setDocumentUpdated(); bool shouldDelete = false;
} switch (static_cast<int>(pCase)) {
case clearAnnotations :
shouldDelete = isStrokesGroup;
break;
case clearItems :
shouldDelete = !isGroup && !isBackgroundObject(item) && !isStrokesGroup;
break;
case clearItemsAndAnnotations:
shouldDelete = !isGroup && !isBackgroundObject(item);
break;
}
void UBGraphicsScene::clearAnnotations() if(shouldDelete) {
{ if (itemGroup) {
QSet<QGraphicsItem*> emptyList; itemGroup->removeFromGroup(item);
QSet<QGraphicsItem*> removedItems; if (itemGroup->childItems().count() == 1) {
itemGroup->destroy();
}
itemGroup->Delegate()->update();
}
QList<QGraphicsItem*> sceneItems = items(); curDelegate->remove(false);
foreach(QGraphicsItem* item, sceneItems) removedItems << item;
{ }
UBGraphicsStrokesGroup* pi = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item);
if (pi)
{
removeItem(item);
removedItems << item;
} }
break;
} }
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
update(sceneRect()); update(sceneRect());
if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet<QGraphicsItem*>());
UBApplication::undoStack->push(uc); UBApplication::undoStack->push(uc);
} }
setDocumentUpdated(); if (pCase == clearBackground) {
}
void UBGraphicsScene::clearBackground()
{
if(mBackgroundObject){
removeItem(mBackgroundObject);
if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, mBackgroundObject, NULL);
UBApplication::undoStack->push(uc);
}
mBackgroundObject = 0; mBackgroundObject = 0;
} }
update(sceneRect());
setDocumentUpdated(); setDocumentUpdated();
} }
@ -1373,8 +1330,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con
UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *> items) UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *> items)
{ {
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
addItem(groupItem);
addItem(groupItem);
foreach (QGraphicsItem *item, items) { foreach (QGraphicsItem *item, items) {
if (item->type() == UBGraphicsGroupContainerItem::Type) { if (item->type() == UBGraphicsGroupContainerItem::Type) {
QList<QGraphicsItem*> childItems = item->childItems(); QList<QGraphicsItem*> childItems = item->childItems();
@ -1609,8 +1566,6 @@ void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
void UBGraphicsScene::removeItem(QGraphicsItem* item) void UBGraphicsScene::removeItem(QGraphicsItem* item)
{ {
UBGraphicsGroupContainerItem* group = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem());
item->setSelected(false); item->setSelected(false);
UBCoreGraphicsScene::removeItem(item); UBCoreGraphicsScene::removeItem(item);
UBApplication::boardController->freezeW3CWidget(item, true); UBApplication::boardController->freezeW3CWidget(item, true);
@ -1619,15 +1574,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
--mItemCount; --mItemCount;
mFastAccessItems.removeAll(item); mFastAccessItems.removeAll(item);
// if (group)
// {
// if (group->childItems().empty())
// {
// group->Delegate()->remove();
// UBCoreGraphicsScene::removeItemFromDeletion(group);
// }
// }
} }
void UBGraphicsScene::removeItems(const QSet<QGraphicsItem*>& items) void UBGraphicsScene::removeItems(const QSet<QGraphicsItem*>& items)

@ -101,6 +101,13 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
public: public:
enum clearCase {
clearItemsAndAnnotations = 0
, clearAnnotations
, clearItems
, clearBackground
};
// tmp stub for divide addings scene objects from undo mechanism implementation // tmp stub for divide addings scene objects from undo mechanism implementation
void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} void setURStackEnable(bool set = true) {enableUndoRedoStack = set;}
bool isURStackIsEnabled(){ return enableUndoRedoStack;} bool isURStackIsEnabled(){ return enableUndoRedoStack;}
@ -114,10 +121,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsScene* sceneDeepCopy() const; UBGraphicsScene* sceneDeepCopy() const;
void clearItemsAndAnnotations(); void clearContent(clearCase pCase = clearItemsAndAnnotations);
void clearItems();
void clearAnnotations();
void clearBackground();
bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0);
bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0);

@ -263,6 +263,11 @@ void UBGraphicsTextItemDelegate::setEditable(bool editable)
mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false)); mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false));
} }
} }
void UBGraphicsTextItemDelegate::remove(bool canUndo)
{
UBGraphicsItemDelegate::remove(canUndo);
}
bool UBGraphicsTextItemDelegate::isEditable() bool UBGraphicsTextItemDelegate::isEditable()
{ {
return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool(); return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool();
@ -419,8 +424,8 @@ QVariant UBGraphicsTextItemDelegate::itemChange(QGraphicsItem::GraphicsItemChang
QTextCursor c = delegated()->textCursor(); QTextCursor c = delegated()->textCursor();
if (c.hasSelection()) if (c.hasSelection())
{ {
c.clearSelection(); c.clearSelection();
delegated()->setTextCursor(c); delegated()->setTextCursor(c);
} }
} }
} }

@ -46,6 +46,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
public slots: public slots:
void contentsChanged(); void contentsChanged();
virtual void setEditable(bool); virtual void setEditable(bool);
virtual void remove(bool canUndo);
protected: protected:
virtual void buildButtons(); virtual void buildButtons();

@ -17,6 +17,15 @@
#include "core/memcheck.h" #include "core/memcheck.h"
#include "domain/UBGraphicsPixmapItem.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsStrokesGroup.h"
#include "domain/UBGraphicsGroupContainerItem.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "tools/UBGraphicsCurtainItem.h"
UBItem::UBItem() UBItem::UBItem()
: mUuid(QUuid()) : mUuid(QUuid())
, mRenderingQuality(UBItem::RenderingQualityNormal) , mRenderingQuality(UBItem::RenderingQualityNormal)
@ -44,3 +53,37 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item)
{ {
return item->data(UBGraphicsItemData::ItemRotatable).toBool(); return item->data(UBGraphicsItemData::ItemRotatable).toBool();
} }
UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem)
{
UBGraphicsItemDelegate *result = 0;
switch (static_cast<int>(pItem->type())) {
case UBGraphicsPixmapItem::Type :
result = (static_cast<UBGraphicsPixmapItem*>(pItem))->Delegate();
break;
case UBGraphicsTextItem::Type :
result = (static_cast<UBGraphicsTextItem*>(pItem))->Delegate();
break;
case UBGraphicsSvgItem::Type :
result = (static_cast<UBGraphicsSvgItem*>(pItem))->Delegate();
break;
case UBGraphicsMediaItem::Type:
result = (static_cast<UBGraphicsMediaItem*>(pItem))->Delegate();
break;
case UBGraphicsStrokesGroup::Type :
result = (static_cast<UBGraphicsStrokesGroup*>(pItem))->Delegate();
break;
case UBGraphicsGroupContainerItem::Type :
result = (static_cast<UBGraphicsGroupContainerItem*>(pItem))->Delegate();
break;
case UBGraphicsWidgetItem::Type :
result = (static_cast<UBGraphicsWidgetItem*>(pItem))->Delegate();
break;
case UBGraphicsCurtainItem::Type :
result = (static_cast<UBGraphicsCurtainItem*>(pItem))->Delegate();
break;
}
return result;
}

@ -108,6 +108,7 @@ public:
static bool isRotatable(QGraphicsItem *item); static bool isRotatable(QGraphicsItem *item);
static bool isFlippable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item);
static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem);
virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual UBGraphicsItemDelegate *Delegate() const = 0;
virtual void remove() = 0; virtual void remove() = 0;

Loading…
Cancel
Save