Merge branch 'OEFUniboard' of github.com:stayonshadow/PrivateBoard into OEFUniboard

preferencesAboutTextFull
Ilia Ryabokon 11 years ago
commit dbafd3272c
  1. 77
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 142
      src/domain/UBGraphicsItemDelegate.cpp
  3. 3
      src/domain/UBGraphicsItemDelegate.h

@ -384,13 +384,15 @@ UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy
UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
qDebug() << "loadScene() : starting reading..."; qDebug() << "loadScene() : starting reading...";
QTime time;
time.start();
mScene = 0; mScene = 0;
UBGraphicsWidgetItem *currentWidget = 0; UBGraphicsWidgetItem *currentWidget = 0;
mFileVersion = 40100; // default to 4.1.0 mFileVersion = 40100; // default to 4.1.0
UBGraphicsStroke* annotationGroup = 0;
UBGraphicsStrokesGroup* strokesGroup = 0; UBGraphicsStrokesGroup* strokesGroup = 0;
UBGraphicsStroke* currentStroke = 0;
while (!mXmlReader.atEnd()) while (!mXmlReader.atEnd())
{ {
@ -514,16 +516,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
} }
else if (mXmlReader.name() == "g") else if (mXmlReader.name() == "g")
{ {
// Create new stroke, if its NULL or already has polygons
if (annotationGroup)
{
if (!annotationGroup->polygons().empty())
annotationGroup = new UBGraphicsStroke();
}
else
annotationGroup = new UBGraphicsStroke();
strokesGroup = new UBGraphicsStrokesGroup(); strokesGroup = new UBGraphicsStrokesGroup();
graphicsItemFromSvg(strokesGroup); graphicsItemFromSvg(strokesGroup);
@ -568,15 +560,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
polygonItem->setUuid(uuidFromSvg); polygonItem->setUuid(uuidFromSvg);
if (annotationGroup)
polygonItem->setStroke(annotationGroup);
if(strokesGroup){
polygonItem->setTransform(strokesGroup->transform());
strokesGroup->addToGroup(polygonItem);
polygonItem->setStrokesGroup(strokesGroup);
}
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
@ -584,10 +567,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if(!mStrokesList.contains(parentId)){ if(!mStrokesList.contains(parentId)){
group = new UBGraphicsStrokesGroup(); group = new UBGraphicsStrokesGroup();
mStrokesList.insert(parentId,group); mStrokesList.insert(parentId,group);
currentStroke = new UBGraphicsStroke();
} }
else else
group = mStrokesList.value(parentId); group = mStrokesList.value(parentId);
polygonItem->setTransform(group->transform());
group->addToGroup(polygonItem);
polygonItem->setStrokesGroup(group);
polygonItem->setStroke(currentStroke);
polygonItem->show(); polygonItem->show();
group->addToGroup(polygonItem); group->addToGroup(polygonItem);
@ -598,33 +587,28 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QList<UBGraphicsPolygonItem*> polygonItems QList<UBGraphicsPolygonItem*> polygonItems
= polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black); = polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black);
QString parentId = QUuid::createUuid().toString();
foreach(UBGraphicsPolygonItem* polygonItem, polygonItems) foreach(UBGraphicsPolygonItem* polygonItem, polygonItems)
{ {
if (annotationGroup)
{
polygonItem->setStroke(annotationGroup);
}
if(strokesGroup){
polygonItem->setTransform(strokesGroup->transform());
strokesGroup->addToGroup(polygonItem);
polygonItem->setStrokesGroup(strokesGroup);
}
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
QString parentId = mXmlReader.attributes().value(mNamespaceUri, "parent").toString();
Q_ASSERT(!parentId.isEmpty());
UBGraphicsStrokesGroup* group; UBGraphicsStrokesGroup* group;
if(!mStrokesList.contains(parentId)){ if(!mStrokesList.contains(parentId)){
group = new UBGraphicsStrokesGroup(); group = new UBGraphicsStrokesGroup();
mStrokesList.insert(parentId,group); mStrokesList.insert(parentId,group);
currentStroke = new UBGraphicsStroke();
} }
else else
group = mStrokesList.value(parentId); group = mStrokesList.value(parentId);
polygonItem->setTransform(group->transform());
group->addToGroup(polygonItem);
polygonItem->setStrokesGroup(group);
polygonItem->setStroke(currentStroke);
polygonItem->show(); polygonItem->show();
group->addToGroup(polygonItem);
} }
} }
else if (mXmlReader.name() == "image") else if (mXmlReader.name() == "image")
@ -985,11 +969,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
if (mXmlReader.name() == "g") if (mXmlReader.name() == "g")
{ {
if (annotationGroup)
{
if (!annotationGroup->polygons().empty())
annotationGroup = 0;
}
mGroupHasInfo = false; mGroupHasInfo = false;
mGroupDarkBackgroundColor = QColor(); mGroupDarkBackgroundColor = QColor();
mGroupLightBackgroundColor = QColor(); mGroupLightBackgroundColor = QColor();
@ -1014,14 +993,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene->setModified(false); mScene->setModified(false);
} }
if (annotationGroup)
{
if (annotationGroup->polygons().empty())
delete annotationGroup;
}
mScene->enableUndoRedoStack(); mScene->enableUndoRedoStack();
qDebug() << "loadScene() : created scene and read file"; qDebug() << "loadScene() : created scene and read file";
qDebug() << "spent milliseconds: " << time.elapsed();
return mScene; return mScene;
} }
@ -1033,7 +1007,6 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup()
QString id = mXmlReader.attributes().value(aId).toString(); QString id = mXmlReader.attributes().value(aId).toString();
id = id.mid(1,id.length()-2); id = id.mid(1,id.length()-2);
qDebug() << id;
bool shouldSkipSubElements = false; bool shouldSkipSubElements = false;
if(mStrokesList.contains(id)) if(mStrokesList.contains(id))
shouldSkipSubElements = true; shouldSkipSubElements = true;
@ -1725,6 +1698,18 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol
if (!svgPoints.isNull()) if (!svgPoints.isNull())
{ {
// int lenght = strlen(svgPoints.toUtf8().constData()) + 1;
// char pippo[lenght];
// memcpy(pippo,svgPoints.toUtf8().constData(),lenght);
// char* localPosition = (char*) &pippo[0];
// do{
// float x = atof(localPosition);
// localPosition = strchr(localPosition,',') + 1;
// float y = atof(localPosition);
// localPosition = strchrnul(localPosition,' ');
// polygon << QPointF(x,y);
// }while(localPosition - pippo > lenght - 5);
QStringList ts = svgPoints.toString().split(QLatin1Char(' '), QStringList ts = svgPoints.toString().split(QLatin1Char(' '),
QString::SkipEmptyParts); QString::SkipEmptyParts);

@ -179,67 +179,114 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
void UBGraphicsItemDelegate::init() void UBGraphicsItemDelegate::init()
{ {
// if (mToolBarUsed)
// mToolBarItem = new UBGraphicsToolBarItem(mDelegated);
// mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio);
// mFrame->hide();
// mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
// mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection);
// mButtons << mDeleteButton;
// connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove()));
// if (canDuplicate()){
// mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection);
// connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate()));
// mButtons << mDuplicateButton;
// }
// mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection);
// connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu()));
// mButtons << mMenuButton;
// mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection);
// mZOrderUpButton->setShowProgressIndicator(true);
// connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp()));
// connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
// mButtons << mZOrderUpButton;
// mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection);
// mZOrderDownButton->setShowProgressIndicator(true);
// connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
// connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
// mButtons << mZOrderDownButton;
// buildButtons();
// foreach(DelegateButton* button, mButtons)
// {
// if (button->getSection() != Qt::TitleBarArea)
// {
// button->hide();
// button->setFlag(QGraphicsItem::ItemIsSelectable, true);
// }
// }
// //Wrapper function. Use it to set correct data() to QGraphicsItem as well
// setFlippable(false);
// setRotatable(false);
}
UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{
if (UBApplication::boardController)
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
}
void UBGraphicsItemDelegate::decorate()
{
if (mToolBarUsed) if (mToolBarUsed)
mToolBarItem = new UBGraphicsToolBarItem(mDelegated); mToolBarItem = new UBGraphicsToolBarItem(mDelegated);
mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); if(!mFrame){
mFrame->hide(); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio);
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mFrame->hide();
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true);
mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection);
mButtons << mDeleteButton; mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection);
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); mButtons << mDeleteButton;
if (canDuplicate()){ connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove()));
mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection); if (canDuplicate()){
connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate())); mDuplicateButton = new DelegateButton(":/images/duplicate.svg", mDelegated, mFrame, Qt::TopLeftSection);
mButtons << mDuplicateButton; connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate()));
} mButtons << mDuplicateButton;
mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); }
connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection);
mButtons << mMenuButton; connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu()));
mButtons << mMenuButton;
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection);
mZOrderUpButton->setShowProgressIndicator(true); mZOrderUpButton->setShowProgressIndicator(true);
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp()));
connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop()));
mButtons << mZOrderUpButton; mButtons << mZOrderUpButton;
mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection);
mZOrderDownButton->setShowProgressIndicator(true); mZOrderDownButton->setShowProgressIndicator(true);
connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown()));
connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom()));
mButtons << mZOrderDownButton; mButtons << mZOrderDownButton;
buildButtons(); buildButtons();
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
{
if (button->getSection() != Qt::TitleBarArea)
{ {
button->hide(); if (button->getSection() != Qt::TitleBarArea)
button->setFlag(QGraphicsItem::ItemIsSelectable, true); {
button->hide();
button->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
} }
} }
//Wrapper function. Use it to set correct data() to QGraphicsItem as well
setFlippable(false);
setRotatable(false);
}
UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{
if (UBApplication::boardController)
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
} }
QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if(change == QGraphicsItem::ItemChildAddedChange){ if (change == QGraphicsItem::ItemSelectedHasChanged) {
}else if (change == QGraphicsItem::ItemSelectedHasChanged) {
bool ok; bool ok;
bool selected = value.toUInt(&ok); bool selected = value.toUInt(&ok);
if (ok) { if (ok) {
@ -687,6 +734,7 @@ bool UBGraphicsItemDelegate::isFlippable()
void UBGraphicsItemDelegate::updateFrame() void UBGraphicsItemDelegate::updateFrame()
{ {
decorate();
if (mFrame && !mFrame->scene() && mDelegated->scene()) if (mFrame && !mFrame->scene() && mDelegated->scene())
{ {
mDelegated->scene()->addItem(mFrame); mDelegated->scene()->addItem(mFrame);

@ -189,7 +189,7 @@ class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject
bool isVisibleOnBoard() const { return mVisible; } bool isVisibleOnBoard() const { return mVisible; }
void setVisibleOnBoard(bool visible) { mVisible = visible; } void setVisibleOnBoard(bool visible) { mVisible = visible; }
bool isShifting() const { return mShifting; } bool isShifting() const { return mShifting; }
void setShifting(bool shifting) { mShifting = shifting; } void setShifting(bool shifting) { mShifting = shifting; }
QList<QGraphicsItem*> itemsOnToolBar() const { return mItemsOnToolBar; } QList<QGraphicsItem*> itemsOnToolBar() const { return mItemsOnToolBar; }
void setItemsOnToolBar(QList<QGraphicsItem*> itemsOnToolBar) { mItemsOnToolBar = itemsOnToolBar;} void setItemsOnToolBar(QList<QGraphicsItem*> itemsOnToolBar) { mItemsOnToolBar = itemsOnToolBar;}
int minWidth() { return mMinWidth; } int minWidth() { return mMinWidth; }
@ -319,6 +319,7 @@ protected slots:
virtual void gotoContentSource(); virtual void gotoContentSource();
private: private:
void decorate();
void updateFrame(); void updateFrame();
void updateButtons(bool showUpdated = false); void updateButtons(bool showUpdated = false);
inline void showHideRecurs(const QVariant &pShow, QGraphicsItem *pItem); inline void showHideRecurs(const QVariant &pShow, QGraphicsItem *pItem);

Loading…
Cancel
Save