Merge remote-tracking branch 'origin/develop' into claudio-dev

preferencesAboutTextFull
Claudio Valerio 12 years ago
commit 794b41ce32
  1. 8
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 2
      src/api/UBWidgetUniboardAPI.cpp
  3. 29
      src/board/UBBoardController.cpp
  4. 3
      src/board/UBBoardView.cpp
  5. 2
      src/desktop/UBDesktopAnnotationController.cpp
  6. 310
      src/document/UBDocumentController.cpp
  7. 3
      src/document/UBDocumentController.h
  8. 53
      src/domain/UBGraphicsGroupContainerItem.cpp
  9. 5
      src/domain/UBGraphicsGroupContainerItem.h
  10. 20
      src/domain/UBGraphicsItemDelegate.cpp
  11. 1
      src/domain/UBGraphicsItemDelegate.h
  12. 18
      src/domain/UBGraphicsPolygonItem.cpp
  13. 213
      src/domain/UBGraphicsScene.cpp
  14. 24
      src/domain/UBGraphicsScene.h
  15. 61
      src/domain/UBGraphicsStrokesGroup.cpp
  16. 8
      src/domain/UBGraphicsStrokesGroup.h
  17. 5
      src/domain/UBGraphicsTextItemDelegate.cpp
  18. 1
      src/domain/UBGraphicsTextItemDelegate.h
  19. 43
      src/domain/UBItem.cpp
  20. 1
      src/domain/UBItem.h
  21. 44
      src/frameworks/UBCoreGraphicsScene.cpp
  22. 13
      src/frameworks/UBCoreGraphicsScene.h
  23. 5
      src/frameworks/UBPlatformUtils.h
  24. 30
      src/frameworks/UBPlatformUtils_mac.mm
  25. 5
      src/gui/UBKeyboardPalette.cpp
  26. 18
      src/gui/UBKeyboardPalette_mac.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;
}
@ -1189,8 +1187,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::persistScenes()
UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i);
tmpScene->setModified(true);
UBThumbnailAdaptor::persistScene(mProxy, tmpScene, i);
delete tmpScene;
mCurrentScene->setModified(false);
}

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

@ -553,15 +553,15 @@ 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;
QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(item->sourceUrl().toLocalFile());
if(NULL != qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(commonItem)){
itemMimeType = UBMimeType::Group;
}else{
itemMimeType = UBFileSystemUtils::mimeTypeFromString(contentTypeHeader);
}
if(NULL != qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(commonItem))
itemMimeType = UBMimeType::Group;
else
itemMimeType = UBFileSystemUtils::mimeTypeFromString(contentTypeHeader);
switch(static_cast<int>(itemMimeType))
{
@ -633,10 +633,10 @@ void UBBoardController::duplicateItem(UBItem *item)
QGraphicsItem *gitem = dynamic_cast<QGraphicsItem*>(item->deepCopy());
if (gitem)
{
qDebug() << "Adding a stroke: " << gitem;
mActiveScene->addItem(gitem);
gitem->setPos(itemPos);
mLastCreatedItem = gitem;
gitem->setSelected(true);
}
return;
}break;
@ -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();
}
}
@ -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<QGraphicsItem*> 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);
}
}
@ -1515,7 +1516,8 @@ void UBBoardController::ClearUndoStack()
}
if(!scene)
{
mActiveScene->deleteItem(item);
if (!mActiveScene->deleteItem(item))
delete item;
}
}
@ -1549,7 +1551,6 @@ void UBBoardController::changeBackground(bool isDark, bool isCrossed)
}
}
void UBBoardController::boardViewResized(QResizeEvent* event)
{
Q_UNUSED(event);

@ -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() &&

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

@ -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);
@ -524,6 +527,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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder())
{
for(int j=0; j<groupItem->childCount(); 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<UBDocumentProxyTreeItem*>(groupTi->child(i));
if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument())
{
changeCurrentDocument = true;
break;
}
}
QList<UBDocumentProxyTreeItem*> toBeDeleted;
for (int i = 0; i < groupTi->childCount(); i++)
{
UBDocumentProxyTreeItem* proxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder() && groupItem != groupTi)
{
for(int j=0; j<groupItem->childCount(); 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()
{
@ -546,79 +696,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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder())
{
for(int j=0; j<groupItem->childCount(); 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();
}
}
}
@ -659,87 +749,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<UBDocumentProxyTreeItem*>(groupTi->child(i));
if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument())
{
changeCurrentDocument = true;
break;
}
}
QList<UBDocumentProxyTreeItem*> toBeDeleted;
for (int i = 0; i < groupTi->childCount(); i++)
{
UBDocumentProxyTreeItem* proxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder() && groupItem != groupTi)
{
for(int j=0; j<groupItem->childCount(); 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();
}
}

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

@ -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,13 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
QTransform newItemTransform(itemTransform);
item->setPos(mapFromItem(item, 0, 0));
if (item->scene()) {
item->scene()->removeItem(item);
}
if (corescene())
corescene()->removeItemFromDeletion(item);
item->setParentItem(this);
// removing position from translation component of the new transform
@ -113,10 +114,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 +173,9 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr
// }
}
UBGraphicsScene *UBGraphicsGroupContainerItem::scene()
UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene()
{
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(QGraphicsItem::scene());
UBCoreGraphicsScene *castScene = dynamic_cast<UBCoreGraphicsScene*>(QGraphicsItem::scene());
return castScene;
}
@ -218,15 +221,7 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid)
void UBGraphicsGroupContainerItem::destroy() {
UBGraphicsScene *groupScene = scene();
foreach (QGraphicsItem *item, childItems()) {
if (groupScene) {
groupScene->addItemToDeletion(item);
}
pRemoveFromGroup(item);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
item->setFlag(QGraphicsItem::ItemIsFocusable, true);
@ -235,6 +230,18 @@ void UBGraphicsGroupContainerItem::destroy() {
remove();
}
void UBGraphicsGroupContainerItem::clearSource()
{
foreach(QGraphicsItem *child, childItems())
{
UBGraphicsItem *item = dynamic_cast<UBGraphicsItem *>(child);
if (item)
{
item->clearSource();
}
}
}
void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mousePressEvent(event)) {
@ -327,6 +334,12 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item)
item->setParentItem(newParent);
item->setPos(oldPos);
UBGraphicsScene *Scene = dynamic_cast<UBGraphicsScene *>(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());

@ -4,6 +4,7 @@
#include <QGraphicsItem>
#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;
@ -38,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);

@ -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
}
@ -388,9 +387,22 @@ void UBGraphicsItemDelegate::remove(bool canUndo)
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(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() */

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

@ -143,13 +143,13 @@ 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<UBGraphicsPolygonItem*>(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());

@ -263,7 +263,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
, mCrossedBackground(false)
, mIsDesktopMode(false)
, mZoomFactor(1)
, mIsModified(true)
, mBackgroundObject(0)
, mPreviousWidth(0)
, mInputDeviceIsPressed(false)
@ -305,7 +304,10 @@ UBGraphicsScene::~UBGraphicsScene()
{
if (mCurrentStroke)
if (mCurrentStroke->polygons().empty())
{
delete mCurrentStroke;
mCurrentStroke = NULL;
}
if (mZLayerController)
delete mZLayerController;
@ -433,6 +435,11 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
}
}
if (mCurrentStroke && mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
mCurrentStroke = NULL;
}
return accepted;
}
@ -474,6 +481,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);
}
@ -891,25 +902,18 @@ void UBGraphicsScene::recolorAllItems()
view->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
}
for(int i = 0; i < mFastAccessItems.size(); i++)
{
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*> (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<UBGraphicsStrokesGroup*>(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;
}
}
@ -1060,116 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const
return sceneDeepCopy();
}
void UBGraphicsScene::clearItemsAndAnnotations()
{
deselectAllItems();
QSet<QGraphicsItem*> emptyList;
QSet<QGraphicsItem*> removedItems;
QListIterator<QGraphicsItem*> itItems(mFastAccessItems);
while (itItems.hasNext())
{
QGraphicsItem* item = itItems.next();
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<QGraphicsItem*> emptyList;
QSet<QGraphicsItem*> removedItems;
QListIterator<QGraphicsItem*> itItems(mFastAccessItems);
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<UBGraphicsGroupContainerItem*>(item->parentItem())
: 0;
UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item);
if (!curDelegate) {
continue;
}
while (itItems.hasNext())
{
QGraphicsItem* item = itItems.next();
bool shouldDelete = false;
switch (static_cast<int>(pCase)) {
case clearAnnotations :
shouldDelete = isStrokesGroup;
break;
case clearItems :
shouldDelete = !isGroup && !isBackgroundObject(item) && !isStrokesGroup;
break;
case clearItemsAndAnnotations:
shouldDelete = !isGroup && !isBackgroundObject(item);
break;
}
if (!item->parentItem())
{
UBGraphicsPolygonItem* pi = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if(shouldDelete) {
if (itemGroup) {
itemGroup->removeFromGroup(item);
if (itemGroup->childItems().count() == 1) {
itemGroup->destroy();
}
itemGroup->Delegate()->update();
}
if(!pi && !mTools.contains(item) && !isBackgroundObject(item))
{
removeItem(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<QGraphicsItem*>());
UBApplication::undoStack->push(uc);
}
setDocumentUpdated();
}
void UBGraphicsScene::clearAnnotations()
{
QSet<QGraphicsItem*> emptyList;
QSet<QGraphicsItem*> removedItems;
QListIterator<QGraphicsItem*> itItems(mFastAccessItems);
while (itItems.hasNext())
{
QGraphicsItem* item = itItems.next();
UBGraphicsStrokesGroup* pi = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item);
if (pi)
{
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::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,6 +1324,7 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
{
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
addItem(groupItem);
foreach (QGraphicsItem *item, items) {
if (item->type() == UBGraphicsGroupContainerItem::Type) {
QList<QGraphicsItem*> childItems = item->childItems();
@ -1373,13 +1334,14 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
}
foreach (QGraphicsItem *chItem, childItems) {
groupItem->addToGroup(chItem);
mFastAccessItems.removeAll(chItem);
}
} else {
groupItem->addToGroup(item);
mFastAccessItems.removeAll(item);
}
}
addItem(groupItem);
groupItem->setVisible(true);
groupItem->setFocus();
@ -1396,6 +1358,15 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
void UBGraphicsScene::addGroup(UBGraphicsGroupContainerItem *groupItem)
{
addItem(groupItem);
for (int i = 0; i < groupItem->childItems().count(); i++)
{
QGraphicsItem *it = qgraphicsitem_cast<QGraphicsItem *>(groupItem->childItems().at(i));
if (it)
{
mFastAccessItems.removeAll(it);
}
}
groupItem->setVisible(true);
groupItem->setFocus();
@ -1564,7 +1535,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 +1547,6 @@ void UBGraphicsScene::addItem(QGraphicsItem* item)
void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
{
setModified(true);
foreach(QGraphicsItem* item, items) {
UBCoreGraphicsScene::addItem(item);
UBGraphicsItem::assignZValue(item, mZLayerController->generateZLevel(item));
@ -1591,7 +1559,7 @@ void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
void UBGraphicsScene::removeItem(QGraphicsItem* item)
{
setModified(true);
item->setSelected(false);
UBCoreGraphicsScene::removeItem(item);
UBApplication::boardController->freezeW3CWidget(item, true);
@ -1603,8 +1571,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
void UBGraphicsScene::removeItems(const QSet<QGraphicsItem*>& items)
{
setModified(true);
foreach(QGraphicsItem* item, items)
UBCoreGraphicsScene::removeItem(item);
@ -1762,7 +1728,6 @@ void UBGraphicsScene::addRuler(QPointF center)
addItem(ruler);
ruler->setVisible(true);
setModified(true);
}
void UBGraphicsScene::addProtractor(QPointF center)
@ -1780,7 +1745,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 +1762,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 +1820,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 +1853,7 @@ void UBGraphicsScene::moveMagnifier(QPoint newPos, bool forceGrab)
void UBGraphicsScene::closeMagnifier()
{
DisposeMagnifierQWidgets();
setModified(true);
}
void UBGraphicsScene::zoomInMagnifier()
@ -1906,6 +1871,7 @@ void UBGraphicsScene::zoomOutMagnifier()
{
magniferControlViewWidget->setZoom(magniferControlViewWidget->params.zoom - 0.5);
magniferDisplayViewWidget->setZoom(magniferDisplayViewWidget->params.zoom - 0.5);
setModified(true);
}
}
@ -1917,6 +1883,7 @@ void UBGraphicsScene::resizedMagnifier(qreal newPercent)
magniferControlViewWidget->grabPoint();
magniferDisplayViewWidget->setSize(newPercent);
magniferDisplayViewWidget->grabPoint();
setModified(true);
}
}
@ -1932,7 +1899,6 @@ void UBGraphicsScene::addCompass(QPointF center)
compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool));
compass->setVisible(true);
setModified(true);
}
void UBGraphicsScene::addCache()
@ -1962,7 +1928,6 @@ void UBGraphicsScene::addMask(const QPointF &center)
curtain->setRect(rect);
curtain->setVisible(true);
curtain->setSelected(true);
setModified(true);
}
void UBGraphicsScene::setRenderingQuality(UBItem::RenderingQuality pRenderingQuality)
@ -2212,7 +2177,6 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
default:
{
item->setSelected(false);
UBGraphicsItem *ubgi = dynamic_cast<UBGraphicsItem*>(item);
if (0 != ubgi)
ubgi->remove();
@ -2274,6 +2238,11 @@ void UBGraphicsScene::setToolCursor(int tool)
{
deselectAllItems();
}
if (mCurrentStroke && mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
}
mCurrentStroke = NULL;
}
void UBGraphicsScene::initStroke(){

@ -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);
@ -179,16 +183,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 +374,6 @@ public slots:
bool mIsDesktopMode;
qreal mZoomFactor;
bool mIsModified;
QGraphicsItem* mBackgroundObject;
QPointF mPreviousPoint;

@ -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<UBGraphicsPolygonItem *>(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<UBGraphicsPolygonItem *>(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)
{
@ -65,29 +113,30 @@ void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
UBItem* UBGraphicsStrokesGroup::deepCopy() const
{
UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup();
UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup();
QList<QGraphicsItem*> chl = childItems();
QList<QGraphicsItem*> chl = childItems();
foreach(QGraphicsItem *child, chl)
{
UBGraphicsPolygonItem *polygon = dynamic_cast<UBGraphicsPolygonItem*>(child);
if (polygon)
{
copy->addToGroup(dynamic_cast<QGraphicsItem*>(polygon->deepCopy()));
polygon->setStrokesGroup(copy);
}
}
copyItemParameters(copy);
return copy;
return copy;
}
void UBGraphicsStrokesGroup::copyItemParameters(UBItem *copy) const
{
UBGraphicsStrokesGroup *cp = dynamic_cast<UBGraphicsStrokesGroup*>(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));

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

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

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

@ -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<int>(pItem->type())) {
case UBGraphicsPixmapItem::Type :
result = (static_cast<UBGraphicsPixmapItem*>(pItem))->Delegate();
break;
case UBGraphicsTextItem::Type :
result = (static_cast<UBGraphicsTextItem*>(pItem))->Delegate();
break;
case UBGraphicsSvgItem::Type :
result = (static_cast<UBGraphicsSvgItem*>(pItem))->Delegate();
break;
case UBGraphicsMediaItem::Type:
result = (static_cast<UBGraphicsMediaItem*>(pItem))->Delegate();
break;
case UBGraphicsStrokesGroup::Type :
result = (static_cast<UBGraphicsStrokesGroup*>(pItem))->Delegate();
break;
case UBGraphicsGroupContainerItem::Type :
result = (static_cast<UBGraphicsGroupContainerItem*>(pItem))->Delegate();
break;
case UBGraphicsWidgetItem::Type :
result = (static_cast<UBGraphicsWidgetItem*>(pItem))->Delegate();
break;
case UBGraphicsCurtainItem::Type :
result = (static_cast<UBGraphicsCurtainItem*>(pItem))->Delegate();
break;
}
return result;
}

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

@ -23,6 +23,7 @@
UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent)
: QGraphicsScene ( parent )
, mIsModified(true)
{
//NOOP
}
@ -30,27 +31,40 @@ 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<QGraphicsItem *>::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());
}
}
void UBCoreGraphicsScene::addItem(QGraphicsItem* item)
{
addItemToDeletion(item);
if (item->type() == UBGraphicsGroupContainerItem::Type && item->childItems().count()) {
foreach (QGraphicsItem *curItem, item->childItems()) {
removeItemFromDeletion(curItem);
}
}
mItemsToDelete << item;
if (item->scene() != this)
QGraphicsScene::addItem(item);
setModified(true);
}
@ -59,27 +73,17 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete)
QGraphicsScene::removeItem(item);
if (forceDelete)
{
mItemsToDelete.remove(item);
delete item;
item = 0;
qDebug() << "force delete is " << forceDelete;
deleteItem(item);
}
setModified(true);
}
bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item)
{
if(mItemsToDelete.contains(item))
{
UBGraphicsItem* item_casted = 0;
switch (item->type())
{
case UBGraphicsMediaItem::Type:
item_casted = dynamic_cast<UBGraphicsMediaItem*>(item);
break;
case UBGraphicsW3CWidgetItem::Type:
item_casted = dynamic_cast<UBGraphicsWidgetItem*>(item);
break;
}
UBGraphicsItem *item_casted = dynamic_cast<UBGraphicsItem *>(item);
if (0 != item_casted)
item_casted->clearSource();

@ -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<QGraphicsItem*> mItemsToDelete;
bool mIsModified;
};
#endif /* UBCOREGRAPHICSSCENE_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
};

@ -440,6 +440,9 @@ void UBPlatformUtils::initializeKeyboardLayouts()
int count = CFArrayGetCount(kbds);
QList<UBKeyboardLocale*> result;
qDebug() << "initializeKeyboardLayouts";
qDebug() << "Found system locales: " << count;
for(int i=0; i<count; i++)
{
TISInputSourceRef keyLayoutRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);
@ -530,6 +533,8 @@ void UBPlatformUtils::initializeKeyboardLayouts()
const QString resName = ":/images/flags/" + name + ".png";
QIcon *iconLang = new QIcon(resName);
qDebug() << "Locale: " << ID << ", name: " << name;
result.append(new UBKeyboardLocale(fullName, name, ID, iconLang, keybt));
}
@ -565,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];
}

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

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

Loading…
Cancel
Save