diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 0e2a54f1..b86e7aa1 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -250,7 +250,7 @@ void UBWidgetUniboardAPI::eraseLineTo(const qreal x, const qreal y, const qreal void UBWidgetUniboardAPI::clear() { if (mScene) - mScene->clearItemsAndAnnotations(); + mScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations); } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index a9600ab6..3fd87fe3 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -683,7 +683,7 @@ void UBBoardController::clearScene() if (mActiveScene) { freezeW3CWidgets(true); - mActiveScene->clearItemsAndAnnotations(); + mActiveScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations); updateActionStates(); } } @@ -694,7 +694,7 @@ void UBBoardController::clearSceneItems() if (mActiveScene) { freezeW3CWidgets(true); - mActiveScene->clearItems(); + mActiveScene->clearContent(UBGraphicsScene::clearItems); updateActionStates(); } } @@ -704,7 +704,7 @@ void UBBoardController::clearSceneAnnotation() { if (mActiveScene) { - mActiveScene->clearAnnotations(); + mActiveScene->clearContent(UBGraphicsScene::clearAnnotations); updateActionStates(); } } @@ -713,7 +713,7 @@ void UBBoardController::clearSceneBackground() { if (mActiveScene) { - mActiveScene->clearBackground(); + mActiveScene->clearContent(UBGraphicsScene::clearBackground); updateActionStates(); } } @@ -1551,7 +1551,6 @@ void UBBoardController::changeBackground(bool isDark, bool isCrossed) } } - void UBBoardController::boardViewResized(QResizeEvent* event) { Q_UNUSED(event); diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index e86dca46..b95b433d 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -274,7 +274,7 @@ void UBDesktopAnnotationController::eraseDesktopAnnotations() { if (mTransparentDrawingScene) { - mTransparentDrawingScene->clearAnnotations(); + mTransparentDrawingScene->clearContent(UBGraphicsScene::clearAnnotations); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 95b95af3..818eb88e 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -78,7 +78,10 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) QTransform newItemTransform(itemTransform); item->setPos(mapFromItem(item, 0, 0)); - item->scene()->removeItem(item); + if (item->scene()) { + item->scene()->removeItem(item); + } + if (corescene()) corescene()->removeItemFromDeletion(item); item->setParentItem(this); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 6c0349e4..d5620d12 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -387,12 +387,25 @@ void UBGraphicsItemDelegate::remove(bool canUndo) UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); if (scene) { - foreach(DelegateButton* button, mButtons) - scene->removeItem(button); +// bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; +// 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); - /* 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(mDelegated); if (mDelegated_casted) mDelegated_casted->setHtml(QString()); diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index c782c94b..01ef854b 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -244,6 +244,7 @@ class UBGraphicsItemDelegate : public QObject UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } qreal antiScaleRatio() const { return mAntiScaleRatio; } + virtual void update() {positionHandles();} signals: void showOnDisplayChanged(bool shown); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 018d463c..0cdb2ae6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -902,25 +902,18 @@ void UBGraphicsScene::recolorAllItems() view->setViewportUpdateMode(QGraphicsView::NoViewportUpdate); } - for(int i = 0; i < mFastAccessItems.size(); i++) - { - UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast (mFastAccessItems.at(i)); - - if (polygonItem) - { - QColor color; - - if (mDarkBackground) - { - color = polygonItem->colorOnDarkBackground(); - } - else - { - color = polygonItem->colorOnLightBackground(); + bool currentIslight = isLightBackground(); + foreach (QGraphicsItem *item, items()) { + if (item->type() == UBGraphicsStrokesGroup::Type) { + UBGraphicsStrokesGroup *curGroup = static_cast(item); + QColor compareColor = curGroup->color(currentIslight ? UBGraphicsStrokesGroup::colorOnDarkBackground + : UBGraphicsStrokesGroup::colorOnLightBackground); + + if (curGroup->color() == compareColor) { + QColor newColor = curGroup->color(!currentIslight ? UBGraphicsStrokesGroup::colorOnDarkBackground + : UBGraphicsStrokesGroup::colorOnLightBackground); + curGroup->setColor(newColor); } - - polygonItem->setColor(color); - continue; } } @@ -1071,106 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const return sceneDeepCopy(); } -void UBGraphicsScene::clearItemsAndAnnotations() -{ - deselectAllItems(); - - QSet emptyList; - QSet removedItems; - - QList 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(); -} - -void UBGraphicsScene::clearItems() +void UBGraphicsScene::clearContent(clearCase pCase) { - deselectAllItems(); - - QSet emptyList; QSet removedItems; - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - bool isGroup = qgraphicsitem_cast(item) != NULL; - bool isPolygon = qgraphicsitem_cast(item) != NULL; - bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - - if(!isGroup && !isPolygon && !isStrokesGroup && !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); - } + switch (pCase) { + case clearBackground : + removeItem(mBackgroundObject); + removedItems << mBackgroundObject; + break; + + case clearItemsAndAnnotations : + case clearItems : + case clearAnnotations : + foreach(QGraphicsItem* item, items()) { + + bool isGroup = item->type() == UBGraphicsGroupContainerItem::Type; + bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; + + UBGraphicsGroupContainerItem *itemGroup = item->parentItem() + ? qgraphicsitem_cast(item->parentItem()) + : 0; + UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); + if (!curDelegate) { + continue; + } - setDocumentUpdated(); -} + bool shouldDelete = false; + switch (static_cast(pCase)) { + case clearAnnotations : + shouldDelete = isStrokesGroup; + break; + case clearItems : + shouldDelete = !isGroup && !isBackgroundObject(item) && !isStrokesGroup; + break; + case clearItemsAndAnnotations: + shouldDelete = !isGroup && !isBackgroundObject(item); + break; + } -void UBGraphicsScene::clearAnnotations() -{ - QSet emptyList; - QSet removedItems; + if(shouldDelete) { + if (itemGroup) { + itemGroup->removeFromGroup(item); + if (itemGroup->childItems().count() == 1) { + itemGroup->destroy(); + } + itemGroup->Delegate()->update(); + } - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - UBGraphicsStrokesGroup* pi = qgraphicsitem_cast(item); - if (pi) - { - removeItem(item); - removedItems << item; + curDelegate->remove(false); + removedItems << item; + } } + break; } // 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); + UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet()); UBApplication::undoStack->push(uc); } - setDocumentUpdated(); -} - -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); - } + if (pCase == clearBackground) { mBackgroundObject = 0; } - update(sceneRect()); setDocumentUpdated(); } @@ -1364,8 +1323,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList items) { UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); - addItem(groupItem); + addItem(groupItem); foreach (QGraphicsItem *item, items) { if (item->type() == UBGraphicsGroupContainerItem::Type) { QList childItems = item->childItems(); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 6f8c8def..0dedb9c1 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -101,6 +101,13 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem public: + enum clearCase { + clearItemsAndAnnotations = 0 + , clearAnnotations + , clearItems + , clearBackground + }; + // tmp stub for divide addings scene objects from undo mechanism implementation void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} bool isURStackIsEnabled(){ return enableUndoRedoStack;} @@ -114,10 +121,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsScene* sceneDeepCopy() const; - void clearItemsAndAnnotations(); - void clearItems(); - void clearAnnotations(); - void clearBackground(); + void clearContent(clearCase pCase = clearItemsAndAnnotations); bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index 2f57360f..e9993375 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -32,6 +32,54 @@ void UBGraphicsStrokesGroup::setUuid(const QUuid &pUuid) UBItem::setUuid(pUuid); setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene } +void UBGraphicsStrokesGroup::setColor(const QColor &color, colorType pColorType) +{ + //TODO Implement common mechanism of managing groups, drop UBGraphicsStroke if it's obsolete + //Using casting for the moment + foreach (QGraphicsItem *item, childItems()) { + if (item->type() == UBGraphicsPolygonItem::Type) { + UBGraphicsPolygonItem *curPolygon = static_cast(item); + + switch (pColorType) { + case currentColor : + curPolygon->setColor(color); + break; + case colorOnLightBackground : + curPolygon->setColorOnLightBackground(color); + break; + case colorOnDarkBackground : + curPolygon->setColorOnDarkBackground(color); + break; + } + } + } +} + +QColor UBGraphicsStrokesGroup::color(colorType pColorType) const +{ + QColor result; + + foreach (QGraphicsItem *item, childItems()) { + if (item->type() == UBGraphicsPolygonItem::Type) { + UBGraphicsPolygonItem *curPolygon = static_cast(item); + + switch (pColorType) { + case currentColor : + result = curPolygon->color(); + break; + case colorOnLightBackground : + result = curPolygon->colorOnLightBackground(); + break; + case colorOnDarkBackground : + result = curPolygon->colorOnDarkBackground(); + break; + } + + } + } + + return result; +} void UBGraphicsStrokesGroup::mousePressEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/domain/UBGraphicsStrokesGroup.h b/src/domain/UBGraphicsStrokesGroup.h index b2310773..2c286d11 100644 --- a/src/domain/UBGraphicsStrokesGroup.h +++ b/src/domain/UBGraphicsStrokesGroup.h @@ -11,6 +11,12 @@ class UBGraphicsStrokesGroup : public QObject, public QGraphicsItemGroup, public { Q_OBJECT public: + enum colorType { + currentColor = 0 + , colorOnLightBackground + , colorOnDarkBackground + }; + UBGraphicsStrokesGroup(QGraphicsItem* parent = 0); ~UBGraphicsStrokesGroup(); virtual UBItem* deepCopy() const; @@ -23,6 +29,8 @@ public: return Type; } virtual void setUuid(const QUuid &pUuid); + void setColor(const QColor &color, colorType pColorType = currentColor); + QColor color(colorType pColorType = currentColor) const; protected: diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 6e7e730e..9f7b5fdb 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -263,6 +263,11 @@ void UBGraphicsTextItemDelegate::setEditable(bool editable) mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false)); } } +void UBGraphicsTextItemDelegate::remove(bool canUndo) +{ + UBGraphicsItemDelegate::remove(canUndo); +} + bool UBGraphicsTextItemDelegate::isEditable() { return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool(); @@ -419,8 +424,8 @@ QVariant UBGraphicsTextItemDelegate::itemChange(QGraphicsItem::GraphicsItemChang QTextCursor c = delegated()->textCursor(); if (c.hasSelection()) { - c.clearSelection(); - delegated()->setTextCursor(c); + c.clearSelection(); + delegated()->setTextCursor(c); } } } diff --git a/src/domain/UBGraphicsTextItemDelegate.h b/src/domain/UBGraphicsTextItemDelegate.h index 26b3ba9b..2cf6f447 100644 --- a/src/domain/UBGraphicsTextItemDelegate.h +++ b/src/domain/UBGraphicsTextItemDelegate.h @@ -46,6 +46,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate public slots: void contentsChanged(); virtual void setEditable(bool); + virtual void remove(bool canUndo); protected: virtual void buildButtons(); diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 9d999a94..10d3d6ce 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -17,6 +17,15 @@ #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() : mUuid(QUuid()) , mRenderingQuality(UBItem::RenderingQualityNormal) @@ -44,3 +53,37 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item) { return item->data(UBGraphicsItemData::ItemRotatable).toBool(); } + +UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) +{ + UBGraphicsItemDelegate *result = 0; + + switch (static_cast(pItem->type())) { + case UBGraphicsPixmapItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsTextItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsSvgItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsMediaItem::Type: + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsStrokesGroup::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsGroupContainerItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsWidgetItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsCurtainItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + } + + return result; +} diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 99c3e6a6..ca8a0f3b 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -108,6 +108,7 @@ public: static bool isRotatable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item); + static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual void remove() = 0; diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index b39eef0d..28dd6a9f 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -73,6 +73,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete) QGraphicsScene::removeItem(item); if (forceDelete) { + qDebug() << "force delete is " << forceDelete; deleteItem(item); } setModified(true); diff --git a/src/frameworks/UBPlatformUtils.h b/src/frameworks/UBPlatformUtils.h index ebac3995..46acb6f6 100644 --- a/src/frameworks/UBPlatformUtils.h +++ b/src/frameworks/UBPlatformUtils.h @@ -171,6 +171,7 @@ class UBPlatformUtils static int nKeyboardLayouts; static UBKeyboardLocale** keyboardLayouts; + public: static void init(); static void destroy(); @@ -192,6 +193,10 @@ public: static UBKeyboardLocale** getKeyboardLayouts(int& nCount); static QString urlFromClipboard(); static QStringList availableTranslations(); + +#ifdef Q_WS_MAC + static void SetMacLocaleByIdentifier(const QString& id); +#endif }; diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index 66191a95..72dcb75c 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -440,6 +440,9 @@ void UBPlatformUtils::initializeKeyboardLayouts() int count = CFArrayGetCount(kbds); QList result; + qDebug() << "initializeKeyboardLayouts"; + qDebug() << "Found system locales: " << count; + for(int i=0; iKeyboardLocale->get().toInt(); - setInput(locales[nCurrentLocale]); + if (nCurrentLocale < 0 || nCurrentLocale >= nLocalesCount) + nCurrentLocale = 0; + if (locales!=NULL) + setInput(locales[nCurrentLocale]); setContentsMargins( 22, 22, 22, 22 ); diff --git a/src/gui/UBKeyboardPalette_mac.cpp b/src/gui/UBKeyboardPalette_mac.cpp index 3b179c36..79e48e36 100644 --- a/src/gui/UBKeyboardPalette_mac.cpp +++ b/src/gui/UBKeyboardPalette_mac.cpp @@ -57,22 +57,6 @@ void UBKeyboardPalette::createCtrlButtons() ctrlButtons[8] = new UBLocaleButton(this); } -void SetMacLocaleByIdentifier(const QString& id) -{ - const char * strName = id.toAscii().data(); - CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); - - CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceID }; - CFStringRef values[] = { kTISCategoryKeyboardInputSource, iName }; - CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 2, NULL, NULL); - CFArrayRef kbds = TISCreateInputSourceList(dict, true); - if (CFArrayGetCount(kbds)!=0) - { - TISInputSourceRef klRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, 0); - if (klRef!=NULL) - TISSelectInputSource(klRef); - } -} void UBKeyboardPalette::checkLayout() @@ -107,6 +91,6 @@ void UBKeyboardPalette::onActivated(bool) void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale) { - SetMacLocaleByIdentifier(locale->id); + UBPlatformUtils::SetMacLocaleByIdentifier(locale->id); }