From 8f06cfd8a1c4e17248544174baf96f23fc99508f Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 28 Aug 2012 19:15:11 +0300 Subject: [PATCH 01/27] SANKORE-1026 Navigation palette: thumbnails isn't refeshed after application added to the page Improvement of scene update flag setting --- src/domain/UBGraphicsScene.cpp | 16 ++++------------ src/domain/UBGraphicsScene.h | 12 ------------ src/frameworks/UBCoreGraphicsScene.cpp | 4 ++++ src/frameworks/UBCoreGraphicsScene.h | 13 +++++++++++++ 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b4cbfc4e..6d1f5459 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -263,7 +263,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) , mCrossedBackground(false) , mIsDesktopMode(false) , mZoomFactor(1) - , mIsModified(true) , mBackgroundObject(0) , mPreviousWidth(0) , mInputDeviceIsPressed(false) @@ -1564,7 +1563,6 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const Q void UBGraphicsScene::addItem(QGraphicsItem* item) { - setModified(true); UBCoreGraphicsScene::addItem(item); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); @@ -1577,8 +1575,6 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) void UBGraphicsScene::addItems(const QSet& items) { - setModified(true); - foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::addItem(item); UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item)); @@ -1591,7 +1587,6 @@ void UBGraphicsScene::addItems(const QSet& items) void UBGraphicsScene::removeItem(QGraphicsItem* item) { - setModified(true); UBCoreGraphicsScene::removeItem(item); UBApplication::boardController->freezeW3CWidget(item, true); @@ -1603,8 +1598,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) void UBGraphicsScene::removeItems(const QSet& items) { - setModified(true); - foreach(QGraphicsItem* item, items) UBCoreGraphicsScene::removeItem(item); @@ -1762,7 +1755,6 @@ void UBGraphicsScene::addRuler(QPointF center) addItem(ruler); ruler->setVisible(true); - setModified(true); } void UBGraphicsScene::addProtractor(QPointF center) @@ -1780,7 +1772,6 @@ void UBGraphicsScene::addProtractor(QPointF center) protractor->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y()); protractor->setVisible(true); - setModified(true); } void UBGraphicsScene::addTriangle(QPointF center) @@ -1798,7 +1789,6 @@ void UBGraphicsScene::addTriangle(QPointF center) triangle->moveBy(center.x() - itemSceneCenter.x(), center.y() - itemSceneCenter.y()); triangle->setVisible(true); - setModified(true); } void UBGraphicsScene::addMagnifier(UBMagnifierParams params) @@ -1857,6 +1847,7 @@ void UBGraphicsScene::moveMagnifier() { QPoint magnifierPos = QPoint(magniferControlViewWidget->pos().x() + magniferControlViewWidget->size().width() / 2, magniferControlViewWidget->pos().y() + magniferControlViewWidget->size().height() / 2 ); moveMagnifier(magnifierPos, true); + setModified(true); } } @@ -1889,6 +1880,7 @@ void UBGraphicsScene::moveMagnifier(QPoint newPos, bool forceGrab) void UBGraphicsScene::closeMagnifier() { DisposeMagnifierQWidgets(); + setModified(true); } void UBGraphicsScene::zoomInMagnifier() @@ -1906,6 +1898,7 @@ void UBGraphicsScene::zoomOutMagnifier() { magniferControlViewWidget->setZoom(magniferControlViewWidget->params.zoom - 0.5); magniferDisplayViewWidget->setZoom(magniferDisplayViewWidget->params.zoom - 0.5); + setModified(true); } } @@ -1917,6 +1910,7 @@ void UBGraphicsScene::resizedMagnifier(qreal newPercent) magniferControlViewWidget->grabPoint(); magniferDisplayViewWidget->setSize(newPercent); magniferDisplayViewWidget->grabPoint(); + setModified(true); } } @@ -1932,7 +1926,6 @@ void UBGraphicsScene::addCompass(QPointF center) compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); compass->setVisible(true); - setModified(true); } void UBGraphicsScene::addCache() @@ -1962,7 +1955,6 @@ void UBGraphicsScene::addMask(const QPointF ¢er) curtain->setRect(rect); curtain->setVisible(true); curtain->setSelected(true); - setModified(true); } void UBGraphicsScene::setRenderingQuality(UBItem::RenderingQuality pRenderingQuality) diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 738bd429..6f8c8def 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -179,16 +179,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem bool isEmpty() const; - bool isModified() const - { - return mIsModified; - } - - void setModified(bool pModified) - { - mIsModified = pModified; - } - void setDocument(UBDocumentProxy* pDocument); UBDocumentProxy* document() const @@ -380,8 +370,6 @@ public slots: bool mIsDesktopMode; qreal mZoomFactor; - bool mIsModified; - QGraphicsItem* mBackgroundObject; QPointF mPreviousPoint; diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index fd4948ec..7caec260 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -23,6 +23,7 @@ UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) : QGraphicsScene ( parent ) + , mIsModified(true) { //NOOP } @@ -51,6 +52,8 @@ void UBCoreGraphicsScene::addItem(QGraphicsItem* item) if (item->scene() != this) QGraphicsScene::addItem(item); + + setModified(true); } @@ -63,6 +66,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete) delete item; item = 0; } + setModified(true); } bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item) diff --git a/src/frameworks/UBCoreGraphicsScene.h b/src/frameworks/UBCoreGraphicsScene.h index d518db4c..19ed9da9 100644 --- a/src/frameworks/UBCoreGraphicsScene.h +++ b/src/frameworks/UBCoreGraphicsScene.h @@ -33,8 +33,21 @@ class UBCoreGraphicsScene : public QGraphicsScene void removeItemFromDeletion(QGraphicsItem* item); void addItemToDeletion(QGraphicsItem *item); + bool isModified() const + { + return mIsModified; + } + + void setModified(bool pModified) + { + mIsModified = pModified; + } + + private: QSet mItemsToDelete; + + bool mIsModified; }; #endif /* UBCOREGRAPHICSSCENE_H_ */ From 990458d187c109aca0fc2359484b16f040329c17 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Thu, 30 Aug 2012 18:30:49 +0300 Subject: [PATCH 02/27] Removed memory leaks at deletion of UBGraphicsGroupContainerItem. Corrected adding items to group. Corrected group creation. Corrected adding items to scene - items shouldn't be added to itemsToRemove list because that list needs for cleaning undo stack. Improved mechanism of removing "itemsToRemove". Removed wrong deletion of mButtons list from UBGraphicsItemDelegate destructor because that buttons has Frame as parent. Removed possible memory leak in UBBoardController::clearUndoStack. Some items was able not deleted. tmpScene in cffReader not deletes now because ithas a proxy as parent. --- src/adaptors/UBCFFSubsetAdaptor.cpp | 2 -- src/board/UBBoardController.cpp | 3 +- src/domain/UBGraphicsGroupContainerItem.cpp | 33 ++++++++++----------- src/domain/UBGraphicsGroupContainerItem.h | 3 +- src/domain/UBGraphicsItemDelegate.cpp | 3 +- src/domain/UBGraphicsScene.cpp | 2 +- src/frameworks/UBCoreGraphicsScene.cpp | 27 ++++++++++------- 7 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 7eb667b5..097540a7 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -1189,8 +1189,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::persistScenes() UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i); tmpScene->setModified(true); UBThumbnailAdaptor::persistScene(mProxy, tmpScene, i); - delete tmpScene; - mCurrentScene->setModified(false); } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index bcfc1ddd..d2397285 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1515,7 +1515,8 @@ void UBBoardController::ClearUndoStack() } if(!scene) { - mActiveScene->deleteItem(item); + if (!mActiveScene->deleteItem(item)) + delete item; } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index bed3b219..ff4a8bc4 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -28,18 +28,12 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent setUuid(QUuid::createUuid()); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly - - } UBGraphicsGroupContainerItem::~UBGraphicsGroupContainerItem() { - foreach (QGraphicsItem *item, childItems()) - { - removeFromGroup(item); - if (item && item->scene()) - item->scene()->removeItem(item); - } + if (mDelegate) + delete mDelegate; } void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) @@ -83,6 +77,8 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) QTransform newItemTransform(itemTransform); item->setPos(mapFromItem(item, 0, 0)); + + item->scene()->removeItem(item); item->setParentItem(this); // removing position from translation component of the new transform @@ -113,10 +109,12 @@ void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item) { if (!item) { qDebug() << "can't specify the item because of the null pointer"; + return; } - UBGraphicsScene *groupScene = scene(); - if (groupScene) { + UBCoreGraphicsScene *groupScene = corescene(); + if (groupScene) + { groupScene->addItemToDeletion(item); } @@ -170,9 +168,9 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr // } } -UBGraphicsScene *UBGraphicsGroupContainerItem::scene() +UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene() { - UBGraphicsScene *castScene = dynamic_cast(QGraphicsItem::scene()); + UBCoreGraphicsScene *castScene = dynamic_cast(QGraphicsItem::scene()); return castScene; } @@ -218,15 +216,14 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid) void UBGraphicsGroupContainerItem::destroy() { - UBGraphicsScene *groupScene = scene(); + UBCoreGraphicsScene *groupScene = corescene(); - foreach (QGraphicsItem *item, childItems()) { - - if (groupScene) { - groupScene->addItemToDeletion(item); - } + if (groupScene) { + // groupScene->addItemToDeletion(this); + } + foreach (QGraphicsItem *item, childItems()) { pRemoveFromGroup(item); item->setFlag(QGraphicsItem::ItemIsSelectable, true); item->setFlag(QGraphicsItem::ItemIsFocusable, true); diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index 535627eb..00f643d3 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -4,6 +4,7 @@ #include #include "domain/UBItem.h" +#include "frameworks/UBCoreGraphicsScene.h" class UBGraphicsGroupContainerItem : public QGraphicsItem, public UBItem, public UBGraphicsItem { @@ -23,7 +24,7 @@ public: virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} - virtual UBGraphicsScene* scene(); + virtual UBCoreGraphicsScene *corescene(); virtual UBGraphicsGroupContainerItem *deepCopy() const; virtual void copyItemParameters(UBItem *copy) const; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 4abeb1a2..6c0349e4 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -113,7 +113,6 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec , mFlippable(false) , mToolBarUsed(useToolBar) { - // NOOP connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); } @@ -167,7 +166,7 @@ void UBGraphicsItemDelegate::init() UBGraphicsItemDelegate::~UBGraphicsItemDelegate() { - qDeleteAll(mButtons); + disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); // do not release mMimeData. // the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b4cbfc4e..f6a12f95 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1363,6 +1363,7 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList items) { UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); + addItem(groupItem); foreach (QGraphicsItem *item, items) { if (item->type() == UBGraphicsGroupContainerItem::Type) { @@ -1379,7 +1380,6 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QListsetVisible(true); groupItem->setFocus(); diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index fd4948ec..1f306425 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -30,12 +30,23 @@ UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) UBCoreGraphicsScene::~UBCoreGraphicsScene() { //we must delete removed items that are no more in any scene - foreach (const QGraphicsItem* item, mItemsToDelete) + //at groups deleting some items can be added to mItemsToDelete, so we need to use iterators. + if (mItemsToDelete.count()) { - if (item->scene() == NULL || item->scene() == this) + QSet::iterator it = mItemsToDelete.begin(); + QGraphicsItem* item = *it; + do { - delete item; - } + item = *it; + if (item && (item->scene() == NULL || item->scene() == this)) + { + mItemsToDelete.remove(*it); + delete item; + } + + it = mItemsToDelete.begin(); + + }while(mItemsToDelete.count()); } } @@ -46,9 +57,7 @@ void UBCoreGraphicsScene::addItem(QGraphicsItem* item) removeItemFromDeletion(curItem); } } - - mItemsToDelete << item; - + if (item->scene() != this) QGraphicsScene::addItem(item); } @@ -59,9 +68,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete) QGraphicsScene::removeItem(item); if (forceDelete) { - mItemsToDelete.remove(item); - delete item; - item = 0; + deleteItem(item); } } From 0b108d466a0f32c242166fed4d2d9cfbda3087b8 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 31 Aug 2012 10:11:43 +0300 Subject: [PATCH 03/27] Fixed adding items from section to group. --- src/adaptors/UBCFFSubsetAdaptor.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 097540a7..87c83cc4 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -174,9 +174,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &ele QDomElement currentSvgElement = element.firstChildElement(); while (!currentSvgElement.isNull()) { - if (!parseSvgElement(currentSvgElement)) - return false; - + parseSvgElement(currentSvgElement); currentSvgElement = currentSvgElement.nextSiblingElement(); } @@ -187,8 +185,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &ele else { delete mGSectionContainer; - mGSectionContainer = NULL; } + mGSectionContainer = NULL; return true; } From 4b7939b6c3b97e10a82f5e86f5c4c93d7f0388e0 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 31 Aug 2012 11:47:14 +0300 Subject: [PATCH 04/27] Grouped items doesn't manages by mFastAccessItems now. --- src/board/UBBoardController.cpp | 5 +++-- src/domain/UBGraphicsGroupContainerItem.cpp | 6 ++++++ src/domain/UBGraphicsPolygonItem.cpp | 4 ++-- src/domain/UBGraphicsScene.cpp | 11 +++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index d2397285..891591d7 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1482,11 +1482,12 @@ void UBBoardController::ClearUndoStack() UBGraphicsItemUndoCommand *cmd = (UBGraphicsItemUndoCommand*)UBApplication::undoStack->command(i); // go through all added and removed objects, for create list of unique objects + // grouped items will be deleted by groups, so we don't need do delete that items. QSetIterator itAdded(cmd->GetAddedList()); while (itAdded.hasNext()) { QGraphicsItem* item = itAdded.next(); - if( !uniqueItems.contains(item) ) + if( !uniqueItems.contains(item) && !(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type())) uniqueItems.insert(item); } @@ -1494,7 +1495,7 @@ void UBBoardController::ClearUndoStack() while (itRemoved.hasNext()) { QGraphicsItem* item = itRemoved.next(); - if( !uniqueItems.contains(item) ) + if( !uniqueItems.contains(item) && (item->parentItem() && UBGraphicsGroupContainerItem::Type != item->parentItem()->type())) uniqueItems.insert(item); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index ff4a8bc4..1c63d004 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -324,6 +324,12 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item) item->setParentItem(newParent); item->setPos(oldPos); + UBGraphicsScene *Scene = dynamic_cast(item->scene()); + if (Scene) + { + Scene->addItem(item); + } + // removing position from translation component of the new transform if (!item->pos().isNull()) itemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index b21f2760..8e0e6f85 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -67,8 +67,8 @@ void UBGraphicsPolygonItem::clearStroke() if (mStroke!=NULL) { mStroke->remove(this); - if (mStroke->polygons().empty()) - delete mStroke; + //if (mStroke->polygons().empty()) + // delete mStroke; mStroke = NULL; } } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f6a12f95..f5463574 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1374,9 +1374,11 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QListaddToGroup(chItem); + mFastAccessItems.removeAll(item); } } else { groupItem->addToGroup(item); + mFastAccessItems.removeAll(item); } } @@ -1396,6 +1398,15 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QListchildItems().count(); i++) + { + QGraphicsItem *it = qgraphicsitem_cast(groupItem->childItems().at(i)); + if (it) + { + mFastAccessItems.removeAll(it); + } + } + groupItem->setVisible(true); groupItem->setFocus(); From 8b19847c1121b9ca8f93259b0b6c7d2067a0d91e Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 31 Aug 2012 12:18:50 +0300 Subject: [PATCH 05/27] Fixed deletion removed groups. Code was cleaned. Corrections in removing strokes. --- src/board/UBBoardController.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 4 ---- src/domain/UBGraphicsPolygonItem.cpp | 4 ++-- src/domain/UBGraphicsScene.cpp | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 891591d7..3c56d617 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1495,7 +1495,7 @@ void UBBoardController::ClearUndoStack() while (itRemoved.hasNext()) { QGraphicsItem* item = itRemoved.next(); - if( !uniqueItems.contains(item) && (item->parentItem() && UBGraphicsGroupContainerItem::Type != item->parentItem()->type())) + if( !uniqueItems.contains(item) && !(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type())) uniqueItems.insert(item); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 1c63d004..b3e9dec8 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -219,10 +219,6 @@ void UBGraphicsGroupContainerItem::destroy() { UBCoreGraphicsScene *groupScene = corescene(); - if (groupScene) { - // groupScene->addItemToDeletion(this); - } - foreach (QGraphicsItem *item, childItems()) { pRemoveFromGroup(item); item->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 8e0e6f85..b21f2760 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -67,8 +67,8 @@ void UBGraphicsPolygonItem::clearStroke() if (mStroke!=NULL) { mStroke->remove(this); - //if (mStroke->polygons().empty()) - // delete mStroke; + if (mStroke->polygons().empty()) + delete mStroke; mStroke = NULL; } } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f5463574..a982a2d1 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -305,7 +305,10 @@ UBGraphicsScene::~UBGraphicsScene() { if (mCurrentStroke) if (mCurrentStroke->polygons().empty()) + { delete mCurrentStroke; + mCurrentStroke = NULL; + } if (mZLayerController) delete mZLayerController; @@ -433,6 +436,11 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre } } + if (mCurrentStroke && mCurrentStroke->polygons().empty()){ + delete mCurrentStroke; + mCurrentStroke = NULL; + } + return accepted; } @@ -474,6 +482,10 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon); mAddedItems.remove(mpLastPolygon); mCurrentStroke->remove(mpLastPolygon); + if (mCurrentStroke->polygons().empty()){ + delete mCurrentStroke; + mCurrentStroke = NULL; + } removeItem(mpLastPolygon); mPreviousPolygonItems.removeAll(mpLastPolygon); } @@ -2285,6 +2297,11 @@ void UBGraphicsScene::setToolCursor(int tool) { deselectAllItems(); } + + if (mCurrentStroke && mCurrentStroke->polygons().empty()){ + delete mCurrentStroke; + } + mCurrentStroke = NULL; } void UBGraphicsScene::initStroke(){ From 29ef687d41c717e35644fc0f6a976c55c63d0740 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 31 Aug 2012 13:00:30 +0300 Subject: [PATCH 06/27] Useless code removed. --- src/domain/UBGraphicsGroupContainerItem.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index b3e9dec8..10be1c4d 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -216,9 +216,6 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid) void UBGraphicsGroupContainerItem::destroy() { - UBCoreGraphicsScene *groupScene = corescene(); - - foreach (QGraphicsItem *item, childItems()) { pRemoveFromGroup(item); item->setFlag(QGraphicsItem::ItemIsSelectable, true); From 278668b500164563e5da69dcc052dfd7901f77af Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 31 Aug 2012 14:51:58 +0300 Subject: [PATCH 07/27] Another fix for SANKORE-972. --- src/domain/UBGraphicsScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index a982a2d1..47547198 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1615,6 +1615,7 @@ void UBGraphicsScene::addItems(const QSet& items) void UBGraphicsScene::removeItem(QGraphicsItem* item) { setModified(true); + item->setSelected(false); UBCoreGraphicsScene::removeItem(item); UBApplication::boardController->freezeW3CWidget(item, true); @@ -2235,7 +2236,6 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) default: { - item->setSelected(false); UBGraphicsItem *ubgi = dynamic_cast(item); if (0 != ubgi) ubgi->remove(); From 1ce5763adc9d299041de1bb74d23e33ac9675c99 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 12:25:54 +0300 Subject: [PATCH 08/27] SANKORE-1063 --- src/domain/UBGraphicsScene.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 6d1f5459..c25b65f6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1105,9 +1105,10 @@ void UBGraphicsScene::clearItems() if (!item->parentItem()) { - UBGraphicsPolygonItem* pi = qgraphicsitem_cast(item); + bool isPolygon = qgraphicsitem_cast(item) != NULL; + bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - if(!pi && !mTools.contains(item) && !isBackgroundObject(item)) + if(!isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) { removeItem(item); removedItems << item; From 5cec06a62a934a5108152b2140f69c467ab929bf Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 3 Sep 2012 13:00:40 +0300 Subject: [PATCH 09/27] Duplication of Strokes was implemented. --- src/board/UBBoardController.cpp | 10 ++++------ src/domain/UBGraphicsPolygonItem.cpp | 20 +++++++++----------- src/domain/UBGraphicsStrokesGroup.cpp | 13 +++++++------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 3c56d617..66dbc026 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -557,11 +557,10 @@ void UBBoardController::duplicateItem(UBItem *item) UBMimeType::Enum itemMimeType; QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(item->sourceUrl().toLocalFile()); - if(NULL != qgraphicsitem_cast(commonItem)){ - itemMimeType = UBMimeType::Group; - }else{ - itemMimeType = UBFileSystemUtils::mimeTypeFromString(contentTypeHeader); - } + if(NULL != qgraphicsitem_cast(commonItem)) + itemMimeType = UBMimeType::Group; + else + itemMimeType = UBFileSystemUtils::mimeTypeFromString(contentTypeHeader); switch(static_cast(itemMimeType)) { @@ -633,7 +632,6 @@ void UBBoardController::duplicateItem(UBItem *item) QGraphicsItem *gitem = dynamic_cast(item->deepCopy()); if (gitem) { - qDebug() << "Adding a stroke: " << gitem; mActiveScene->addItem(gitem); gitem->setPos(itemPos); mLastCreatedItem = gitem; diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index b21f2760..e5dd4fd7 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -142,14 +142,14 @@ QColor UBGraphicsPolygonItem::color() const UBItem* UBGraphicsPolygonItem::deepCopy() const -{ - UBGraphicsPolygonItem* copy = new UBGraphicsPolygonItem(polygon(), parentItem()); +{ + UBGraphicsPolygonItem* copy = new UBGraphicsPolygonItem(polygon(), 0); + UBGraphicsStroke *stroke = new UBGraphicsStroke(); + copyItemParameters(copy); - copy->mOriginalLine = this->mOriginalLine; - copy->mOriginalWidth = this->mOriginalWidth; - copy->mIsNominalLine = this->mIsNominalLine; + copy->setStroke(stroke); return copy; } @@ -160,17 +160,15 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const UBGraphicsPolygonItem *cp = dynamic_cast(copy); if (cp) { - cp->mOriginalLine = QLineF(); - cp->mOriginalWidth = -1; - cp->mIsNominalLine = false; + cp->mOriginalLine = this->mOriginalLine; + cp->mOriginalWidth = this->mOriginalWidth; + cp->mIsNominalLine = this->mIsNominalLine; - cp->setStroke(this->stroke()); - cp->setStrokesGroup(this->strokesGroup()); + cp->setTransform(transform()); cp->setBrush(this->brush()); cp->setPen(this->pen()); cp->mHasAlpha = this->mHasAlpha; - cp->setColorOnDarkBackground(this->colorOnDarkBackground()); cp->setColorOnLightBackground(this->colorOnLightBackground()); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index a5320924..2f57360f 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -65,29 +65,30 @@ void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) UBItem* UBGraphicsStrokesGroup::deepCopy() const { - UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); + UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); - - QList chl = childItems(); + QList chl = childItems(); foreach(QGraphicsItem *child, chl) { UBGraphicsPolygonItem *polygon = dynamic_cast(child); if (polygon) + { copy->addToGroup(dynamic_cast(polygon->deepCopy())); + polygon->setStrokesGroup(copy); + } } copyItemParameters(copy); - return copy; + return copy; } void UBGraphicsStrokesGroup::copyItemParameters(UBItem *copy) const { UBGraphicsStrokesGroup *cp = dynamic_cast(copy); { - cp->setPos(this->pos()); + cp->setTransform(transform()); - cp->setTransform(this->transform()); cp->setFlag(QGraphicsItem::ItemIsMovable, true); cp->setFlag(QGraphicsItem::ItemIsSelectable, true); cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); From 0b484e2a16cde31e7edfd3395ea63b4ecdc92dbc Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 3 Sep 2012 14:45:41 +0300 Subject: [PATCH 10/27] Item deselected before duplication. --- src/board/UBBoardController.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 66dbc026..c5627842 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -553,6 +553,7 @@ void UBBoardController::duplicateItem(UBItem *item) qreal shifting = UBSettings::settings()->objectFrameWidth; itemPos = commonItem->pos() + QPointF(shifting,shifting); itemSize = commonItem->boundingRect().size(); + commonItem->setSelected(false); } UBMimeType::Enum itemMimeType; From aa54bed95b2ec2cbd3ffa690285103d225e672cb Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 3 Sep 2012 14:59:03 +0300 Subject: [PATCH 11/27] Copied items with unknown type is selected. --- src/board/UBBoardController.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index c5627842..a9600ab6 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -636,6 +636,7 @@ void UBBoardController::duplicateItem(UBItem *item) mActiveScene->addItem(gitem); gitem->setPos(itemPos); mLastCreatedItem = gitem; + gitem->setSelected(true); } return; }break; From e441f2c2f86fed46fd8e174f4b2929f60a09f036 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 15:10:39 +0300 Subject: [PATCH 12/27] SANKORE-1063 The annotations are erased when you select the Erase items --- src/domain/UBGraphicsScene.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index c25b65f6..86d19d34 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1103,16 +1103,14 @@ void UBGraphicsScene::clearItems() { QGraphicsItem* item = itItems.next(); - if (!item->parentItem()) - { - bool isPolygon = qgraphicsitem_cast(item) != NULL; - bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; + bool isGroup = qgraphicsitem_cast(item) != NULL; + bool isPolygon = qgraphicsitem_cast(item) != NULL; + bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - if(!isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) - { - removeItem(item); - removedItems << item; - } + if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) + { + removeItem(item); + removedItems << item; } } From 2a443e618dc70c393c7675285cb2e94a4e4f6815 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 3 Sep 2012 16:33:05 +0300 Subject: [PATCH 13/27] Fixed crash on removing fastAccessItems. --- src/domain/UBGraphicsScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 47547198..5084f660 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1386,7 +1386,7 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QListaddToGroup(chItem); - mFastAccessItems.removeAll(item); + mFastAccessItems.removeAll(chItem); } } else { groupItem->addToGroup(item); From b21e00910831de9df56b828bbf8a5c70ab1016fd Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 3 Sep 2012 16:39:26 +0300 Subject: [PATCH 14/27] Delegate buttons takes mouse press and mouse release events immediately. Fix to Sankore-772. --- src/board/UBBoardView.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index ed75f550..5500ec9b 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -528,6 +528,8 @@ Here we determines cases when items should to get mouse press event at pressing return true; case DelegateButton::Type: + return true; + case UBGraphicsMediaItem::Type: return false; @@ -1123,6 +1125,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) else { if (isUBItem(movingItem) && + DelegateButton::Type != movingItem->type() && QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() && UBToolWidget::Type != movingItem->type() && From 5816a17f576da8c92b32e60996bed5250724fc73 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 16:55:23 +0300 Subject: [PATCH 15/27] SANKORE-98 shutdown after emptying the trashbin --- src/document/UBDocumentController.cpp | 310 +++++++++++++------------- src/document/UBDocumentController.h | 3 + 2 files changed, 163 insertions(+), 150 deletions(-) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 4be9ee0f..af8734e6 100755 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -117,8 +117,11 @@ UBDocumentProxyTreeItem* UBDocumentController::findDocument(UBDocumentProxy* pro void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument) { - if (!proxy) + if (proxy==NULL) + { + setDocument(NULL); return; + } QTreeWidgetItemIterator it(mDocumentUI->documentTreeWidget); @@ -531,6 +534,153 @@ void UBDocumentController::duplicateSelectedItem() } } +void UBDocumentController::moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi) +{ + int index = proxyTi->parent()->indexOfChild(proxyTi); + index --; + + if (index >= 0) + { + if (proxyTi->proxy() == mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true); + } + else + proxyTi->parent()->child(index)->setSelected(true); + } + else if (proxyTi->parent()->childCount() > 1) + { + if (proxyTi->proxy() == mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true); + } + else + proxyTi->parent()->child(1)->setSelected(true); + } + else + { + if (proxyTi->proxy() == mBoardController->selectedDocument()) + { + bool documentFound = false; + for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); + UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); + if (!groupItem->isTrashFolder()) + { + for(int j=0; jchildCount(); j++) + { + if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); + documentFound = true; + break; + } + } + } + if (documentFound) + break; + } + if (!documentFound) + { + UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument(groupTi->groupName()); + selectDocument(document, true); + } + } + else + proxyTi->parent()->setSelected(true); + } + + QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); + proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); + UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); + + proxyTi->parent()->removeChild(proxyTi); + mTrashTi->addChild(proxyTi); + proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); +} + +void UBDocumentController::moveFolderToTrash(UBDocumentGroupTreeItem* groupTi) +{ + bool changeCurrentDocument = false; + for (int i = 0; i < groupTi->childCount(); i++) + { + UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); + if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument()) + { + changeCurrentDocument = true; + break; + } + } + + QList toBeDeleted; + + for (int i = 0; i < groupTi->childCount(); i++) + { + UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); + if (proxyTi && proxyTi->proxy()) + toBeDeleted << proxyTi; + } + + for (int i = 0; i < toBeDeleted.count(); i++) + { + UBDocumentProxyTreeItem* proxyTi = toBeDeleted.at(i); + + showMessage(QString("Deleting %1").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString())); + // Move document to trash + QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); + proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); + UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); + + groupTi->removeChild(proxyTi); + mTrashTi->addChild(proxyTi); + proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); + + showMessage(QString("%1 deleted").arg(groupTi->groupName())); + } + + // dont remove default group + if (!groupTi->isDefaultFolder()) + { + int index = mDocumentUI->documentTreeWidget->indexOfTopLevelItem(groupTi); + + if (index >= 0) + { + mDocumentUI->documentTreeWidget->takeTopLevelItem(index); + } + } + + if (changeCurrentDocument) + { + bool documentFound = false; + for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); + UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); + if (!groupItem->isTrashFolder() && groupItem != groupTi) + { + for(int j=0; jchildCount(); j++) + { + if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); + documentFound = true; + break; + } + } + } + if (documentFound) + break; + } + if (!documentFound) + { + UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument( UBSettings::defaultDocumentGroupName ); + selectDocument(document, true); + } + } + + reloadThumbnails(); +} void UBDocumentController::deleteSelectedItem() { @@ -553,79 +703,19 @@ void UBDocumentController::deleteSelectedItem() { if (proxyTi->parent() != mTrashTi) { - // We have to move document into Trash - // Select another document for processing - // This is for Board, where this document can be selected - int index = proxyTi->parent()->indexOfChild(proxyTi); - index --; - - if (index >= 0) - { - if (proxyTi->proxy() == mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true); - } - else - proxyTi->parent()->child(index)->setSelected(true); - } - else if (proxyTi->parent()->childCount() > 1) - { - if (proxyTi->proxy() == mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true); - } - else - proxyTi->parent()->child(1)->setSelected(true); - } - else - { - if (proxyTi->proxy() == mBoardController->selectedDocument()) - { - bool documentFound = false; - for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) - { - QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); - UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); - if (!groupItem->isTrashFolder()) - { - for(int j=0; jchildCount(); j++) - { - if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); - documentFound = true; - break; - } - } - } - if (documentFound) - break; - } - if (!documentFound) - { - UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument(groupTi->groupName()); - selectDocument(document, true); - } - } - else - proxyTi->parent()->setSelected(true); - } - - QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); - proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); - UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); - - proxyTi->parent()->removeChild(proxyTi); - mTrashTi->addChild(proxyTi); - proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); + moveDocumentToTrash(groupTi, proxyTi); } else { - // We have to physical delete document - // No action with selection required - document from Trash cant be selected in Board - + // We have to physically delete document proxyTi->parent()->removeChild(proxyTi); UBPersistenceManager::persistenceManager()->deleteDocument(proxyTi->proxy()); + + if (mTrashTi->childCount()==0) + selectDocument(NULL); + else + selectDocument(((UBDocumentProxyTreeItem*)mTrashTi->child(0))->proxy()); + reloadThumbnails(); } } } @@ -666,87 +756,7 @@ void UBDocumentController::deleteSelectedItem() if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Folder"), tr("Are you sure you want to remove the folder '%1' and all its content?").arg(groupTi->groupName()))) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - - bool changeCurrentDocument = false; - for (int i = 0; i < groupTi->childCount(); i++) - { - UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); - if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument()) - { - changeCurrentDocument = true; - break; - } - } - - QList toBeDeleted; - - for (int i = 0; i < groupTi->childCount(); i++) - { - UBDocumentProxyTreeItem* proxyTi = dynamic_cast(groupTi->child(i)); - if (proxyTi && proxyTi->proxy()) - toBeDeleted << proxyTi; - } - - for (int i = 0; i < toBeDeleted.count(); i++) - { - UBDocumentProxyTreeItem* proxyTi = toBeDeleted.at(i); - - showMessage(QString("Deleting %1").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString())); - // Move document to trash - QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); - proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); - UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); - - groupTi->removeChild(proxyTi); - mTrashTi->addChild(proxyTi); - proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); - - showMessage(QString("%1 deleted").arg(groupTi->groupName())); - } - - // dont remove default group - if (!groupTi->isDefaultFolder()) - { - int index = mDocumentUI->documentTreeWidget->indexOfTopLevelItem(groupTi); - - if (index >= 0) - { - mDocumentUI->documentTreeWidget->takeTopLevelItem(index); - } - } - - if (changeCurrentDocument) - { - bool documentFound = false; - for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) - { - QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); - UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); - if (!groupItem->isTrashFolder() && groupItem != groupTi) - { - for(int j=0; jchildCount(); j++) - { - if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) - { - selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); - documentFound = true; - break; - } - } - } - if (documentFound) - break; - } - if (!documentFound) - { - UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument( UBSettings::defaultDocumentGroupName ); - selectDocument(document, true); - } - } - - - reloadThumbnails(); - + moveFolderToTrash(groupTi); QApplication::restoreOverrideCursor(); } } diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index d27ca0a6..ac8a113f 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -111,6 +111,9 @@ class UBDocumentController : public UBDocumentContainer bool mToolsPalettePositionned; UBDocumentGroupTreeItem* mTrashTi; + void moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi); + void moveFolderToTrash(UBDocumentGroupTreeItem* groupTi); + private slots: void documentZoomSliderValueChanged (int value); void loadDocumentProxies(); From 687b65658c592b9ddf5b883de627999dda0d19e5 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 3 Sep 2012 17:01:27 +0300 Subject: [PATCH 16/27] Sankore-861 Only standard created annotations change their color --- src/board/UBBoardController.cpp | 15 +++++++++ src/domain/UBGraphicsStrokesGroup.cpp | 48 +++++++++++++++++++++++++++ src/domain/UBGraphicsStrokesGroup.h | 8 +++++ 3 files changed, 71 insertions(+) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index bcfc1ddd..7a14e8d4 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1543,6 +1543,21 @@ void UBBoardController::changeBackground(bool isDark, bool isCrossed) mActiveScene->setBackground(isDark, isCrossed); + foreach (QGraphicsItem *item, mActiveScene->items()) { + if (item->type() == UBGraphicsStrokesGroup::Type) { + UBGraphicsStrokesGroup *curGroup = static_cast(item); + QColor compareColor = curGroup->color(currentIsDark ? UBGraphicsStrokesGroup::colorOnDarkBackground + : UBGraphicsStrokesGroup::colorOnLightBackground); + + if (curGroup->color() == compareColor) { + QColor newColor = curGroup->color(!currentIsDark ? UBGraphicsStrokesGroup::colorOnDarkBackground + : UBGraphicsStrokesGroup::colorOnLightBackground); + curGroup->setColor(newColor); + } + + } + } + updateBackgroundState(); emit backgroundChanged(); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index a5320924..6da869a1 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: From 05f6cc364ff1c559ea59eeafa9835b74ec14947e Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 3 Sep 2012 19:25:42 +0300 Subject: [PATCH 17/27] Additional fix to Sankore-979 - improved cleaning mechanism for items on board. --- src/domain/UBGraphicsGroupContainerItem.cpp | 14 ++++++++++++++ src/domain/UBGraphicsGroupContainerItem.h | 2 ++ src/frameworks/UBCoreGraphicsScene.cpp | 14 +++----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 10be1c4d..95b95af3 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -79,6 +79,8 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) item->setPos(mapFromItem(item, 0, 0)); item->scene()->removeItem(item); + if (corescene()) + corescene()->removeItemFromDeletion(item); item->setParentItem(this); // removing position from translation component of the new transform @@ -225,6 +227,18 @@ void UBGraphicsGroupContainerItem::destroy() { remove(); } +void UBGraphicsGroupContainerItem::clearSource() +{ + foreach(QGraphicsItem *child, childItems()) + { + UBGraphicsItem *item = dynamic_cast(child); + if (item) + { + item->clearSource(); + } + } +} + void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (mDelegate->mousePressEvent(event)) { diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index 00f643d3..e8fa77eb 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -39,6 +39,8 @@ public: virtual void setUuid(const QUuid &pUuid); void destroy(); + virtual void clearSource(); + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index 1f306425..69297da7 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -52,6 +52,8 @@ UBCoreGraphicsScene::~UBCoreGraphicsScene() void UBCoreGraphicsScene::addItem(QGraphicsItem* item) { + addItemToDeletion(item); + if (item->type() == UBGraphicsGroupContainerItem::Type && item->childItems().count()) { foreach (QGraphicsItem *curItem, item->childItems()) { removeItemFromDeletion(curItem); @@ -76,17 +78,7 @@ bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item) { if(mItemsToDelete.contains(item)) { - UBGraphicsItem* item_casted = 0; - switch (item->type()) - { - case UBGraphicsMediaItem::Type: - item_casted = dynamic_cast(item); - break; - case UBGraphicsW3CWidgetItem::Type: - item_casted = dynamic_cast(item); - break; - } - + UBGraphicsItem *item_casted = dynamic_cast(item); if (0 != item_casted) item_casted->clearSource(); From 3a21e07283c4b224ad81425d137d7d1cc9d49e92 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 19:27:15 +0300 Subject: [PATCH 18/27] SANKORE-1063 The annotations are erased when you select the Erase items --- src/domain/UBGraphicsScene.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index a34d8aac..37ab5bef 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1078,12 +1078,9 @@ void UBGraphicsScene::clearItemsAndAnnotations() QSet emptyList; QSet removedItems; - QListIterator itItems(mFastAccessItems); - - while (itItems.hasNext()) + QList sceneItems = items(); + foreach(QGraphicsItem* item, sceneItems) { - QGraphicsItem* item = itItems.next(); - if(!mTools.contains(item) && !isBackgroundObject(item)) { removeItem(item); @@ -1109,12 +1106,9 @@ void UBGraphicsScene::clearItems() QSet emptyList; QSet removedItems; - QListIterator itItems(mFastAccessItems); - - while (itItems.hasNext()) + QList sceneItems = items(); + foreach(QGraphicsItem* item, sceneItems) { - QGraphicsItem* item = itItems.next(); - bool isGroup = qgraphicsitem_cast(item) != NULL; bool isPolygon = qgraphicsitem_cast(item) != NULL; bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; @@ -1143,11 +1137,9 @@ void UBGraphicsScene::clearAnnotations() QSet emptyList; QSet removedItems; - QListIterator itItems(mFastAccessItems); - - while (itItems.hasNext()) + QList sceneItems = items(); + foreach(QGraphicsItem* item, sceneItems) { - QGraphicsItem* item = itItems.next(); UBGraphicsStrokesGroup* pi = qgraphicsitem_cast(item); if (pi) { @@ -1159,7 +1151,6 @@ void UBGraphicsScene::clearAnnotations() // 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); From 678633094d33a5fa15f6f77578447c3d91fe66f6 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 3 Sep 2012 19:48:05 +0300 Subject: [PATCH 19/27] Sankore-861 using recolorAllItemsFunction --- src/board/UBBoardController.cpp | 16 ---------------- src/domain/UBGraphicsScene.cpp | 29 +++++++++++------------------ 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 7a14e8d4..c0be0da8 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1543,28 +1543,12 @@ void UBBoardController::changeBackground(bool isDark, bool isCrossed) mActiveScene->setBackground(isDark, isCrossed); - foreach (QGraphicsItem *item, mActiveScene->items()) { - if (item->type() == UBGraphicsStrokesGroup::Type) { - UBGraphicsStrokesGroup *curGroup = static_cast(item); - QColor compareColor = curGroup->color(currentIsDark ? UBGraphicsStrokesGroup::colorOnDarkBackground - : UBGraphicsStrokesGroup::colorOnLightBackground); - - if (curGroup->color() == compareColor) { - QColor newColor = curGroup->color(!currentIsDark ? UBGraphicsStrokesGroup::colorOnDarkBackground - : UBGraphicsStrokesGroup::colorOnLightBackground); - curGroup->setColor(newColor); - } - - } - } - updateBackgroundState(); emit backgroundChanged(); } } - void UBBoardController::boardViewResized(QResizeEvent* event) { Q_UNUSED(event); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b4cbfc4e..9a89e96b 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -891,25 +891,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; } } From 4ec54ee3a86ceefcdec2b87b8c4a6d212cea76fe Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 3 Sep 2012 20:31:51 +0300 Subject: [PATCH 20/27] Delete group after deletion of last member --- src/domain/UBGraphicsScene.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 018d463c..0f3ecc17 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1600,6 +1600,8 @@ void UBGraphicsScene::addItems(const QSet& items) void UBGraphicsScene::removeItem(QGraphicsItem* item) { + UBGraphicsGroupContainerItem* group = qgraphicsitem_cast(item->parentItem()); + item->setSelected(false); UBCoreGraphicsScene::removeItem(item); UBApplication::boardController->freezeW3CWidget(item, true); @@ -1608,6 +1610,15 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) --mItemCount; mFastAccessItems.removeAll(item); + + if (group) + { + if (group->childItems().empty()) + { + group->Delegate()->remove(); + UBCoreGraphicsScene::removeItemFromDeletion(group); + } + } } void UBGraphicsScene::removeItems(const QSet& items) From e232bbc9009e107796114da3aabd2d3ef0ae1e7e Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 3 Sep 2012 21:49:05 +0300 Subject: [PATCH 21/27] Some changes crash related --- src/domain/UBGraphicsScene.cpp | 29 +++++++++++++++++--------- src/frameworks/UBCoreGraphicsScene.cpp | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0f3ecc17..d5eb8d36 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1099,6 +1099,11 @@ void UBGraphicsScene::clearItemsAndAnnotations() setDocumentUpdated(); } +bool isService(QGraphicsItem *item) { + return (item->type() == UBGraphicsDelegateFrame::Type) + || (item->parentItem() && item->parentItem()->Type == UBGraphicsDelegateFrame::Type); +} + void UBGraphicsScene::clearItems() { deselectAllItems(); @@ -1113,9 +1118,13 @@ void UBGraphicsScene::clearItems() bool isPolygon = qgraphicsitem_cast(item) != NULL; bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) - { + bool inGroup = (item->parentItem() + && (item->parentItem()->type() == UBGraphicsGroupContainerItem::Type)); + + if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) { removeItem(item); + } + if (!inGroup || !isService(item)) { removedItems << item; } } @@ -1611,14 +1620,14 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) mFastAccessItems.removeAll(item); - if (group) - { - if (group->childItems().empty()) - { - group->Delegate()->remove(); - UBCoreGraphicsScene::removeItemFromDeletion(group); - } - } +// if (group) +// { +// if (group->childItems().empty()) +// { +// group->Delegate()->remove(); +// UBCoreGraphicsScene::removeItemFromDeletion(group); +// } +// } } void UBGraphicsScene::removeItems(const QSet& items) 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); From a3be61c15b7886a4d434e6715dc58c158c976742 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 4 Sep 2012 13:00:35 +0300 Subject: [PATCH 22/27] Keyboard under MAX 10.7 --- src/gui/UBKeyboardPalette.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/UBKeyboardPalette.cpp b/src/gui/UBKeyboardPalette.cpp index 3f1fe242..2a496526 100644 --- a/src/gui/UBKeyboardPalette.cpp +++ b/src/gui/UBKeyboardPalette.cpp @@ -60,7 +60,10 @@ UBKeyboardPalette::UBKeyboardPalette(QWidget *parent) createCtrlButtons(); nCurrentLocale = UBSettings::settings()->KeyboardLocale->get().toInt(); - setInput(locales[nCurrentLocale]); + if (nCurrentLocale < 0 || nCurrentLocale >= nLocalesCount) + nCurrentLocale = 0; + if (locales!=NULL) + setInput(locales[nCurrentLocale]); setContentsMargins( 22, 22, 22, 22 ); From eb53715d6c51cb646d8ddce5f3e11327b135d27a Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Tue, 4 Sep 2012 15:28:41 +0300 Subject: [PATCH 23/27] Eraising elements --- src/api/UBWidgetUniboardAPI.cpp | 2 +- src/board/UBBoardController.cpp | 8 +- src/desktop/UBDesktopAnnotationController.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 5 +- src/domain/UBGraphicsItemDelegate.cpp | 19 ++- src/domain/UBGraphicsItemDelegate.h | 1 + src/domain/UBGraphicsScene.cpp | 152 ++++++------------ src/domain/UBGraphicsScene.h | 12 +- src/domain/UBGraphicsTextItemDelegate.cpp | 9 +- src/domain/UBGraphicsTextItemDelegate.h | 1 + src/domain/UBItem.cpp | 43 +++++ src/domain/UBItem.h | 1 + 12 files changed, 136 insertions(+), 119 deletions(-) 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..ea627e3f 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(); } } 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 d5eb8d36..c60257ab 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1071,115 +1071,72 @@ UBItem* UBGraphicsScene::deepCopy() const return sceneDeepCopy(); } -void UBGraphicsScene::clearItemsAndAnnotations() +void UBGraphicsScene::clearContent(clearCase pCase) { - 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(); -} - -bool isService(QGraphicsItem *item) { - return (item->type() == UBGraphicsDelegateFrame::Type) - || (item->parentItem() && item->parentItem()->Type == UBGraphicsDelegateFrame::Type); -} - -void UBGraphicsScene::clearItems() -{ - 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; - - bool inGroup = (item->parentItem() - && (item->parentItem()->type() == UBGraphicsGroupContainerItem::Type)); - - if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) { - removeItem(item); - } - if (!inGroup || !isService(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(); } @@ -1373,8 +1330,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(); @@ -1609,8 +1566,6 @@ void UBGraphicsScene::addItems(const QSet& items) void UBGraphicsScene::removeItem(QGraphicsItem* item) { - UBGraphicsGroupContainerItem* group = qgraphicsitem_cast(item->parentItem()); - item->setSelected(false); UBCoreGraphicsScene::removeItem(item); UBApplication::boardController->freezeW3CWidget(item, true); @@ -1619,15 +1574,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) --mItemCount; mFastAccessItems.removeAll(item); - -// if (group) -// { -// if (group->childItems().empty()) -// { -// group->Delegate()->remove(); -// UBCoreGraphicsScene::removeItemFromDeletion(group); -// } -// } } void UBGraphicsScene::removeItems(const QSet& items) 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/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; From 5f30e45d97918a8b006ed3c6f97588f2b49aef8f Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 4 Sep 2012 17:53:33 +0300 Subject: [PATCH 24/27] SANKORE-523 Changing the languages of the virtual keyboard crashes the software --- src/frameworks/UBPlatformUtils_mac.mm | 5 +++++ src/gui/UBKeyboardPalette_mac.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index 66191a95..d62e9f2e 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; i Date: Tue, 4 Sep 2012 18:04:18 +0300 Subject: [PATCH 25/27] SANKORE-523 Changing the languages of the virtual keyboard crashes the software --- src/frameworks/UBPlatformUtils.h | 40 ++++++++++++++---------- src/frameworks/UBPlatformUtils_linux.cpp | 10 +++--- src/frameworks/UBPlatformUtils_win.cpp | 15 ++++++--- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/frameworks/UBPlatformUtils.h b/src/frameworks/UBPlatformUtils.h index ebac3995..29af417e 100644 --- a/src/frameworks/UBPlatformUtils.h +++ b/src/frameworks/UBPlatformUtils.h @@ -19,6 +19,11 @@ #include #include +#ifdef Q_WS_MACX + #import +#endif + + class QMainWindow; #define SYMBOL_KEYS_COUNT 47 @@ -125,28 +130,31 @@ struct KEYBT class UBKeyboardLocale { public: - UBKeyboardLocale(const QString& _fullName, - const QString& _name, - const QString& _id, - QIcon* _icon, - KEYBT** _symbols) - :fullName(_fullName),name(_name), id(_id), icon(_icon), - constSymbols(NULL), varSymbols(_symbols) - {} - UBKeyboardLocale(const QString& _fullName, - const QString& _name, - const QString& _id, - QIcon* _icon, - KEYBT _symbols[]) - :fullName(_fullName),name(_name), id(_id), icon(_icon), + #ifdef Q_WS_MACX + UBKeyboardLocale(const QString& _fullName, + const QString& _name, + TISInputSourceRef _tisInputSourceRef, + QIcon* _icon, + KEYBT** _symbols) + :fullName(_fullName),name(_name), tisInputSourceRef(_tisInputSourceRef), + icon(_icon),constSymbols(NULL), varSymbols(_symbols) + {} + + TISInputSourceRef tisInputSourceRef; + #else + UBKeyboardLocale(const QString& _fullName, + const QString& _name, + QIcon* _icon, + KEYBT _symbols[]) + :fullName(_fullName),name(_name), icon(_icon), constSymbols(_symbols), varSymbols(NULL) - {} + {} + #endif ~UBKeyboardLocale(); const QString fullName; const QString name; - const QString id; QIcon* icon; KEYBT* operator[] (int index) const { diff --git a/src/frameworks/UBPlatformUtils_linux.cpp b/src/frameworks/UBPlatformUtils_linux.cpp index 8c10c4c9..411d812a 100644 --- a/src/frameworks/UBPlatformUtils_linux.cpp +++ b/src/frameworks/UBPlatformUtils_linux.cpp @@ -399,11 +399,11 @@ void UBPlatformUtils::initializeKeyboardLayouts() { nKeyboardLayouts = 5; keyboardLayouts = new UBKeyboardLocale*[nKeyboardLayouts]; - keyboardLayouts[0] = new UBKeyboardLocale(tr("English"), "en", "", new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); - keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", "", new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); - keyboardLayouts[2] = new UBKeyboardLocale(tr("German"), "de", "", new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); - keyboardLayouts[3] = new UBKeyboardLocale(tr("French"), "fr", "", new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); - keyboardLayouts[4] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", "", new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); + keyboardLayouts[0] = new UBKeyboardLocale(tr("English"), "en", new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); + keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); + keyboardLayouts[2] = new UBKeyboardLocale(tr("German"), "de", new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); + keyboardLayouts[3] = new UBKeyboardLocale(tr("French"), "fr", new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); + keyboardLayouts[4] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); } void UBPlatformUtils::destroyKeyboardLayouts() diff --git a/src/frameworks/UBPlatformUtils_win.cpp b/src/frameworks/UBPlatformUtils_win.cpp index 95a6970e..f7c67f8b 100644 --- a/src/frameworks/UBPlatformUtils_win.cpp +++ b/src/frameworks/UBPlatformUtils_win.cpp @@ -407,11 +407,16 @@ void UBPlatformUtils::initializeKeyboardLayouts() { nKeyboardLayouts = 5; keyboardLayouts = new UBKeyboardLocale*[nKeyboardLayouts]; - keyboardLayouts[0] = new UBKeyboardLocale(tr("English"), "en", "", new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); - keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", "", new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); - keyboardLayouts[2] = new UBKeyboardLocale(tr("French"), "fr", "", new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); - keyboardLayouts[3] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", "", new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); - keyboardLayouts[4] = new UBKeyboardLocale(tr("German"), "de", "", new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); + keyboardLayouts[0] = new UBKeyboardLocale(tr("English"),"en", + new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); + keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", + new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); + keyboardLayouts[2] = new UBKeyboardLocale(tr("French"), "fr", + new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); + keyboardLayouts[3] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", + new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); + keyboardLayouts[4] = new UBKeyboardLocale(tr("German"), "de", + new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); } void UBPlatformUtils::destroyKeyboardLayouts() From 34c6aa28a98b2adef9f35681f0e5fea4908c9341 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 4 Sep 2012 19:58:18 +0300 Subject: [PATCH 26/27] Reversed changed... --- src/frameworks/UBPlatformUtils.h | 40 ++++++++++-------------- src/frameworks/UBPlatformUtils_linux.cpp | 10 +++--- src/frameworks/UBPlatformUtils_win.cpp | 15 +++------ 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/frameworks/UBPlatformUtils.h b/src/frameworks/UBPlatformUtils.h index 29af417e..ebac3995 100644 --- a/src/frameworks/UBPlatformUtils.h +++ b/src/frameworks/UBPlatformUtils.h @@ -19,11 +19,6 @@ #include #include -#ifdef Q_WS_MACX - #import -#endif - - class QMainWindow; #define SYMBOL_KEYS_COUNT 47 @@ -130,31 +125,28 @@ struct KEYBT class UBKeyboardLocale { public: - #ifdef Q_WS_MACX - UBKeyboardLocale(const QString& _fullName, - const QString& _name, - TISInputSourceRef _tisInputSourceRef, - QIcon* _icon, - KEYBT** _symbols) - :fullName(_fullName),name(_name), tisInputSourceRef(_tisInputSourceRef), - icon(_icon),constSymbols(NULL), varSymbols(_symbols) - {} - - TISInputSourceRef tisInputSourceRef; - #else - UBKeyboardLocale(const QString& _fullName, - const QString& _name, - QIcon* _icon, - KEYBT _symbols[]) - :fullName(_fullName),name(_name), icon(_icon), + UBKeyboardLocale(const QString& _fullName, + const QString& _name, + const QString& _id, + QIcon* _icon, + KEYBT** _symbols) + :fullName(_fullName),name(_name), id(_id), icon(_icon), + constSymbols(NULL), varSymbols(_symbols) + {} + UBKeyboardLocale(const QString& _fullName, + const QString& _name, + const QString& _id, + QIcon* _icon, + KEYBT _symbols[]) + :fullName(_fullName),name(_name), id(_id), icon(_icon), constSymbols(_symbols), varSymbols(NULL) - {} - #endif + {} ~UBKeyboardLocale(); const QString fullName; const QString name; + const QString id; QIcon* icon; KEYBT* operator[] (int index) const { diff --git a/src/frameworks/UBPlatformUtils_linux.cpp b/src/frameworks/UBPlatformUtils_linux.cpp index 411d812a..8c10c4c9 100644 --- a/src/frameworks/UBPlatformUtils_linux.cpp +++ b/src/frameworks/UBPlatformUtils_linux.cpp @@ -399,11 +399,11 @@ void UBPlatformUtils::initializeKeyboardLayouts() { nKeyboardLayouts = 5; keyboardLayouts = new UBKeyboardLocale*[nKeyboardLayouts]; - keyboardLayouts[0] = new UBKeyboardLocale(tr("English"), "en", new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); - keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); - keyboardLayouts[2] = new UBKeyboardLocale(tr("German"), "de", new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); - keyboardLayouts[3] = new UBKeyboardLocale(tr("French"), "fr", new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); - keyboardLayouts[4] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); + keyboardLayouts[0] = new UBKeyboardLocale(tr("English"), "en", "", new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); + keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", "", new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); + keyboardLayouts[2] = new UBKeyboardLocale(tr("German"), "de", "", new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); + keyboardLayouts[3] = new UBKeyboardLocale(tr("French"), "fr", "", new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); + keyboardLayouts[4] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", "", new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); } void UBPlatformUtils::destroyKeyboardLayouts() diff --git a/src/frameworks/UBPlatformUtils_win.cpp b/src/frameworks/UBPlatformUtils_win.cpp index f7c67f8b..95a6970e 100644 --- a/src/frameworks/UBPlatformUtils_win.cpp +++ b/src/frameworks/UBPlatformUtils_win.cpp @@ -407,16 +407,11 @@ void UBPlatformUtils::initializeKeyboardLayouts() { nKeyboardLayouts = 5; keyboardLayouts = new UBKeyboardLocale*[nKeyboardLayouts]; - keyboardLayouts[0] = new UBKeyboardLocale(tr("English"),"en", - new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); - keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", - new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); - keyboardLayouts[2] = new UBKeyboardLocale(tr("French"), "fr", - new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); - keyboardLayouts[3] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", - new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); - keyboardLayouts[4] = new UBKeyboardLocale(tr("German"), "de", - new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); + keyboardLayouts[0] = new UBKeyboardLocale(tr("English"), "en", "", new QIcon(":/images/flags/en.png"), ENGLISH_LOCALE); + keyboardLayouts[1] = new UBKeyboardLocale(tr("Russian"), "ru", "", new QIcon(":/images/flags/ru.png"),RUSSIAN_LOCALE); + keyboardLayouts[2] = new UBKeyboardLocale(tr("French"), "fr", "", new QIcon(":/images/flags/fr.png"), FRENCH_LOCALE); + keyboardLayouts[3] = new UBKeyboardLocale(tr("Swiss French"), "fr-CH", "", new QIcon(":/images/flags/fr.png"), SWISS_FRENCH_LOCALE); + keyboardLayouts[4] = new UBKeyboardLocale(tr("German"), "de", "", new QIcon(":/images/flags/de.png"), GERMAN_LOCALE); } void UBPlatformUtils::destroyKeyboardLayouts() From ff6332a66f71cdc4379e2233243848cc521a876c Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Wed, 5 Sep 2012 12:34:04 +0300 Subject: [PATCH 27/27] Virtual Keyboard under Mac OS 10.7: switching locales --- src/frameworks/UBPlatformUtils.h | 5 +++++ src/frameworks/UBPlatformUtils_mac.mm | 25 +++++++++++++++++++++++++ src/gui/UBKeyboardPalette_mac.cpp | 19 +------------------ 3 files changed, 31 insertions(+), 18 deletions(-) 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 d62e9f2e..72dcb75c 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -570,3 +570,28 @@ QString UBPlatformUtils::urlFromClipboard() */ return qsRet; } + + +void UBPlatformUtils::SetMacLocaleByIdentifier(const QString& id) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + 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 (kbds!=NULL) + { + if (CFArrayGetCount(kbds)!=0) + { + TISInputSourceRef klRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, 0); + if (klRef!=NULL) + TISSelectInputSource(klRef); + } + } + [pool drain]; +} diff --git a/src/gui/UBKeyboardPalette_mac.cpp b/src/gui/UBKeyboardPalette_mac.cpp index a8ca7c72..79e48e36 100644 --- a/src/gui/UBKeyboardPalette_mac.cpp +++ b/src/gui/UBKeyboardPalette_mac.cpp @@ -57,23 +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() @@ -108,6 +91,6 @@ void UBKeyboardPalette::onActivated(bool) void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale) { - SetMacLocaleByIdentifier(locale->id); + UBPlatformUtils::SetMacLocaleByIdentifier(locale->id); }