From a0a0d208a7867e4b2c653fc29e6fb2092e72c4e9 Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Thu, 29 Mar 2012 21:07:27 +0300 Subject: [PATCH 01/10] UBZLayerController created. Z level implementation restructured --- src/adaptors/UBSvgSubsetAdaptor.cpp | 63 +++++++++++++++ src/adaptors/UBSvgSubsetAdaptor.h | 2 + src/core/UB.h | 24 +++++- src/domain/UBGraphicsAudioItem.cpp | 2 + src/domain/UBGraphicsItemDelegate.cpp | 53 ++++++++++--- src/domain/UBGraphicsItemDelegate.h | 18 ++++- src/domain/UBGraphicsPDFItem.cpp | 3 +- src/domain/UBGraphicsPixmapItem.cpp | 1 + src/domain/UBGraphicsPolygonItem.cpp | 8 ++ src/domain/UBGraphicsPolygonItem.h | 2 + src/domain/UBGraphicsScene.cpp | 96 +++++++++++++++-------- src/domain/UBGraphicsScene.h | 35 ++++++++- src/domain/UBGraphicsSvgItem.cpp | 3 +- src/domain/UBGraphicsTextItem.cpp | 16 +--- src/domain/UBGraphicsTextItemDelegate.cpp | 8 +- src/domain/UBGraphicsVideoItem.cpp | 2 + src/domain/UBGraphicsWidgetItem.cpp | 3 + src/domain/UBItem.h | 1 + src/tools/UBAbstractDrawRuler.cpp | 1 + src/tools/UBGraphicsCache.cpp | 6 +- src/tools/UBGraphicsCache.h | 2 - src/tools/UBGraphicsCompass.cpp | 2 + src/tools/UBGraphicsCurtainItem.cpp | 2 + src/tools/UBGraphicsProtractor.cpp | 1 + src/tools/UBGraphicsRuler.cpp | 2 + src/tools/UBGraphicsTriangle.cpp | 4 +- 26 files changed, 283 insertions(+), 77 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 00e159a6..95857b3e 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -320,6 +320,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() mXmlReader.readNext(); if (mXmlReader.isStartElement()) { + qreal zFromSvg = getZValueFromSvg(); + if (mXmlReader.name() == "svg") { if (!scene) @@ -529,6 +531,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(pixmapItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(pixmapItem, zFromSvg); + if (isBackground) scene->setAsBackgroundObject(pixmapItem); @@ -548,6 +553,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(svgItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(svgItem, zFromSvg); + if (isBackground) scene->setAsBackgroundObject(svgItem); @@ -573,6 +581,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(audioItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(audioItem, zFromSvg); + audioItem->show(); //force start to load the video and display the first frame @@ -593,6 +604,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(videoItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(videoItem, zFromSvg); + videoItem->show(); //force start to load the video and display the first frame @@ -613,6 +627,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(textItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(textItem, zFromSvg); + textItem->show(); } } @@ -624,17 +641,27 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(mask); scene->registerTool(mask); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(mask, zFromSvg); } } else if (mXmlReader.name() == "ruler") { + + QString ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString(); UBGraphicsRuler *ruler = rulerFromSvg(); + ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString(); if (ruler) { scene->addItem(ruler); scene->registerTool(ruler); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(ruler, zFromSvg); } + } else if (mXmlReader.name() == "compass") { @@ -644,6 +671,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(compass); scene->registerTool(compass); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(compass, zFromSvg); } } else if (mXmlReader.name() == "protractor") @@ -654,6 +684,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(protractor); scene->registerTool(protractor); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(protractor, zFromSvg); } } else if (mXmlReader.name() == "triangle") @@ -664,6 +697,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { scene->addItem(triangle); scene->registerTool(triangle); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(triangle, zFromSvg); } } else if(mXmlReader.name() == "cache") @@ -674,6 +710,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(cache); scene->registerTool(cache); UBApplication::boardController->notifyCache(true); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(cache, zFromSvg); } } else if (mXmlReader.name() == "foreignObject") @@ -698,6 +737,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(pdfItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(pdfItem, zFromSvg); + if (isBackground) scene->setAsBackgroundObject(pdfItem); @@ -720,6 +762,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(appleWidgetItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg); + appleWidgetItem->show(); currentWidget = appleWidgetItem; @@ -740,6 +785,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(w3cWidgetItem); + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg); + w3cWidgetItem->show(); currentWidget = w3cWidgetItem; @@ -756,6 +804,10 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex); scene->addItem(textItem); + + if (zFromSvg != UBZLayerController::errorNum()) + UBGraphicsItem::assignZValue(textItem, zFromSvg); + textItem->show(); } } @@ -2009,6 +2061,17 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g } } +qreal UBSvgSubsetAdaptor::UBSvgSubsetReader::getZValueFromSvg() +{ + qreal result = UBZLayerController::errorNum(); + + QStringRef ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value"); + if (!ubZValue.isNull()) { + result = ubZValue.toString().toFloat(); + } + + return result; +} void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsItemToSvg(QGraphicsItem* item) { diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 89915585..188bba2f 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -134,6 +134,8 @@ class UBSvgSubsetAdaptor void graphicsItemFromSvg(QGraphicsItem* gItem); + qreal getZValueFromSvg(); + QXmlStreamReader mXmlReader; int mFileVersion; UBDocumentProxy *mProxy; diff --git a/src/core/UB.h b/src/core/UB.h index 83a4b456..0d372469 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -62,7 +62,7 @@ struct UBSize }; }; - +// Deprecated. Keep it for backward campability with old versions struct UBItemLayerType { enum Enum @@ -71,17 +71,37 @@ struct UBItemLayerType }; }; +struct itemLayerType +{ + enum Enum { + NoLayer = 0 + , BackgroundItem + , ObjectItem + , DrawingItem + , ToolItem + , CppTool + , Eraiser + , Curtain + , Pointer + , Cache + }; +}; + + struct UBGraphicsItemData { enum Enum { - ItemLayerType + ItemLayerType //Deprecated. Keep it for backward campability with old versions. Use itemLayerType instead , ItemLocked , ItemEditable//for text only , ItemOwnZValue + , itemLayerType //use instead of deprecated ItemLayerType }; }; + + struct UBGraphicsItemType { enum Enum diff --git a/src/domain/UBGraphicsAudioItem.cpp b/src/domain/UBGraphicsAudioItem.cpp index d38e27b7..88bf64c9 100644 --- a/src/domain/UBGraphicsAudioItem.cpp +++ b/src/domain/UBGraphicsAudioItem.cpp @@ -64,6 +64,8 @@ UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsIte mDelegate->frame()->setOperationMode ( UBGraphicsDelegateFrame::Resizing ); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + } void UBGraphicsAudioItem::onStateChanged(Phonon::State newState, Phonon::State oldState) diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 86b93b68..915ce8b9 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -76,18 +76,26 @@ void UBGraphicsItemDelegate::init() UBGraphicsItem::assignZValue(mFrame, UBGraphicsScene::toolLayerStart + 1); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); - mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame); + 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); + 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); + mMenuButton = new DelegateButton(":/images/menu.svg", mDelegated, mFrame, Qt::TopLeftSection); connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu())); mButtons << mMenuButton; + mZOrderUpButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::BottomLeftSection); + connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevel())); + mButtons << mZOrderUpButton; + + mZOrderDownButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::BottomLeftSection); + connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(decreaseZLevel())); + mButtons << mZOrderDownButton; + buildButtons(); foreach(DelegateButton* button, mButtons) @@ -238,10 +246,13 @@ void UBGraphicsItemDelegate::positionHandles() mDeleteButton->setTransform(tr); - qreal x = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; - qreal y = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; + qreal topX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; + qreal topY = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; - mDeleteButton->setPos(x, y); + qreal bottomX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; + qreal bottomY = mFrame->rect().bottom() - mDeleteButton->renderer()->viewBox().height() * mAntiScaleRatio / 2; + + mDeleteButton->setPos(topX, topY); if (!mDeleteButton->scene()) { @@ -257,12 +268,18 @@ void UBGraphicsItemDelegate::positionHandles() lock(isLocked()); - for(int i = 1 ; i < mButtons.length(); i++) - { - DelegateButton* button = mButtons[i]; + int i = 1, j = 0, k = 0; + while ((i + j) < mButtons.size()) { + DelegateButton* button = mButtons[i + j]; button->setTransform(tr); - button->setPos(x + (i * 1.6 * mFrameWidth * mAntiScaleRatio), y); + if (button->getSection() == Qt::TopLeftSection) { + button->setPos(topX + (i++ * 1.6 * mFrameWidth * mAntiScaleRatio), topY); + } else if (button->getSection() == Qt::BottomLeftSection) { + button->setPos(bottomX + (++j * 1.6 * mFrameWidth * mAntiScaleRatio), bottomY); + } else if (button->getSection() == Qt::NoSection) { + ++k; + } if (!button->scene()) { button->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene @@ -271,9 +288,7 @@ void UBGraphicsItemDelegate::positionHandles() } button->show(); } - } - else - { + } else { foreach(DelegateButton* button, mButtons) button->hide(); @@ -316,7 +331,19 @@ void UBGraphicsItemDelegate::duplicate() UBApplication::boardController->copy(); UBApplication::boardController->paste(); } +void UBGraphicsItemDelegate::increaseZLevel(int delta) +{ + qDebug() << delegated()->scene()->items().count(); + +// UBGraphicsItem::assignZValue(delegated(), ) +// int valueCandidate = delegated()->data(UBGraphicsItemData::ItemOwnZValue).toInt(); +// if (delta < 0) { + +// } else if (delta > 0) { + +// } +} void UBGraphicsItemDelegate::lock(bool locked) { diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 9986db6b..737df9bb 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -33,10 +33,11 @@ class DelegateButton: public QGraphicsSvgItem Q_OBJECT public: - DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0) + DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0, Qt::WindowFrameSection section = Qt::NoSection) : QGraphicsSvgItem(fileName, parent) , mDelegated(pDelegated) , mIsTransparentToMouseEvent(false) + , mButtonAlignmentSection(section) { setAcceptedMouseButtons(Qt::LeftButton); setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); @@ -57,6 +58,9 @@ class DelegateButton: public QGraphicsSvgItem QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this)); } + void setSection(Qt::WindowFrameSection section) {mButtonAlignmentSection = section;} + Qt::WindowFrameSection getSection() const {return mButtonAlignmentSection;} + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -80,7 +84,9 @@ class DelegateButton: public QGraphicsSvgItem QGraphicsItem* mDelegated; + bool mIsTransparentToMouseEvent; + Qt::WindowFrameSection mButtonAlignmentSection; signals: void clicked (bool checked = false); @@ -142,6 +148,9 @@ class UBGraphicsItemDelegate : public QObject virtual void lock(bool lock); virtual void duplicate(); + virtual void increaseZLevel() {increaseZLevel(1);} + virtual void decreaseZLevel() {increaseZLevel(-1);} + protected: virtual void buildButtons() {;} virtual void decorateMenu(QMenu *menu); @@ -149,10 +158,15 @@ class UBGraphicsItemDelegate : public QObject QGraphicsItem* mDelegated; + //buttons from the top left section of delegate frame DelegateButton* mDeleteButton; DelegateButton* mDuplicateButton; DelegateButton* mMenuButton; + //buttons from the bottom left section of delegate frame + DelegateButton *mZOrderUpButton; + DelegateButton *mZOrderDownButton; + QMenu* mMenu; QAction* mLockAction; @@ -171,6 +185,8 @@ protected slots: private: + virtual void increaseZLevel(int delta); + QPointF mOffset; QTransform mPreviousTransform; QPointF mPreviousPosition; diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 704ba676..33aa274b 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -26,7 +26,8 @@ UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGraphicsItem* parent) : GraphicsPDFItem(renderer, pageNumber, parent) { - setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); + setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); //deprecated + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::BackgroundItem)); //Necessary to set if we want z value to be assigned correctly mDelegate = new UBGraphicsItemDelegate(this,0); mDelegate->init(); } diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index ceb4fd28..47d001c6 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -33,6 +33,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setTransformationMode(Qt::SmoothTransformation); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index d2e96e25..dcc750c5 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -30,6 +30,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (QGraphicsItem * parent) , mStroke(0) { // NOOP + initialize(); } @@ -40,6 +41,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi , mStroke(0) { // NOOP + initialize(); } @@ -51,6 +53,12 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth) , mStroke(0) { // NOOP + initialize(); +} + +void UBGraphicsPolygonItem::initialize() +{ + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly } void UBGraphicsPolygonItem::clearStroke() diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 66498ef2..22dfe712 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -35,6 +35,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem ~UBGraphicsPolygonItem(); + void initialize(); + void setColor(const QColor& color); QColor color() const; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b20cf7f8..2729d093 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -77,6 +77,45 @@ qreal UBGraphicsScene::toolOffsetPointer = 1100; qreal UBGraphicsScene::toolOffsetCache = 1000;//Didier please define offset you want +qreal UBZLayerController::errorNumber = -20000001.0; + + +UBZLayerController::UBZLayerController() +{ + scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber)); + scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-10000000.0, -10000000.0 )); + scopeMap.insert(itemLayerType::ObjectItem, ItemLayerTypeData(-10000000.0, 0.0 )); + scopeMap.insert(itemLayerType::DrawingItem, ItemLayerTypeData( 0.0, 10000000.0 )); + scopeMap.insert(itemLayerType::ToolItem, ItemLayerTypeData( 10000000.0, 10000100.0 )); + scopeMap.insert(itemLayerType::CppTool, ItemLayerTypeData( 10000100.0, 10000200.0 )); + scopeMap.insert(itemLayerType::Eraiser, ItemLayerTypeData( 10000200.0, 10001000.0 )); + scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 10001000.0, 10001100.0 )); + scopeMap.insert(itemLayerType::Pointer, ItemLayerTypeData( 10001100.0, 10001200.0 )); + scopeMap.insert(itemLayerType::Cache, ItemLayerTypeData( 10001300.0, 10001400.0 )); +} + +qreal UBZLayerController::generateZLevel(itemLayerType::Enum key) +{ + + if (!scopeMap.contains(key)) { + qDebug() << "Number is out of layer scope"; + return errorNumber; + } + + qreal result = scopeMap.value(key).curValue; + qreal top = scopeMap.value(key).topLimit; + + result++; + if (result >= top) { + qDebug() << "new values are finished for the scope" << key; + result = top; + } + + scopeMap[key].curValue = result; + + return result; +} + UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) : UBCoreGraphicsScene(parent) , mEraser(0) @@ -116,6 +155,12 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) mEraser->setZValue(/*toolLayerStart + toolOffsetEraser*/2); mEraser->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); +// mEraser->setData(UBGraphicsItemData::itemLayerType, QVariant(Eraiser)); + +// qreal zval = mZLayerController.generateZLevel((itmeLayerType)mEraser->data(UBGraphicsItemData::itemLayerType).toInt()); +// qreal zval1 = mZLayerController.generateZLevel(Eraiser); +// qreal zval2 = mZLayerController.generateZLevel(Eraiser); +// mEraser->setZValue(zval); mTools << mEraser; addItem(mEraser); @@ -155,8 +200,8 @@ UBGraphicsScene::~UBGraphicsScene() void UBGraphicsScene::selectionChangedProcessing() { if (selectedItems().count()) - UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f')); - + UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " + + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); QList allItemsList = items(); qreal maxZ = 0.; @@ -827,9 +872,6 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem) polygonItem->setColorOnLightBackground(colorOnLightBG); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - -// polygonItem->setZValue(getNextDrawingZIndex()); - UBGraphicsItem::assignZValue(polygonItem, getNextDrawingZIndex()); } @@ -1051,7 +1093,6 @@ UBGraphicsPixmapItem* UBGraphicsScene::addPixmap(const QPixmap& pPixmap, const Q pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); // pixmapItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(pixmapItem, getNextObjectZIndex()); pixmapItem->setPixmap(pPixmap); @@ -1104,7 +1145,6 @@ UBGraphicsVideoItem* UBGraphicsScene::addVideo(const QUrl& pVideoFileUrl, bool s videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); // videoItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(videoItem, getNextObjectZIndex()); addItem(videoItem); @@ -1137,7 +1177,6 @@ UBGraphicsAudioItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool s audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); // audioItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(audioItem, getNextObjectZIndex()); addItem(audioItem); @@ -1204,8 +1243,6 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addW3CWidget(const QUrl& pWidgetUrl, c void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos) { graphicsWidget->setFlag(QGraphicsItem::ItemIsSelectable, true); -// graphicsWidget->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(graphicsWidget, getNextObjectZIndex()); addItem(graphicsWidget); @@ -1267,8 +1304,6 @@ UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPoint svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// svgItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(svgItem, getNextObjectZIndex()); qreal sscale = 1 / UBApplication::boardController->systemScaleFactor(); svgItem->scale(sscale, sscale); @@ -1303,8 +1338,6 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con { UBGraphicsTextItem *textItem = new UBGraphicsTextItem(); textItem->setPlainText(pString); -// textItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(textItem, getNextObjectZIndex()); QFont font = textItem->font(); @@ -1361,8 +1394,6 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const Q UBGraphicsTextItem *textItem = new UBGraphicsTextItem(); textItem->setPlainText(""); textItem->setHtml(pString); -// textItem->setZValue(getNextObjectZIndex()); - UBGraphicsItem::assignZValue(textItem, getNextObjectZIndex()); addItem(textItem); textItem->show(); @@ -1388,6 +1419,8 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) setModified(true); UBCoreGraphicsScene::addItem(item); + UBGraphicsItem::assignZValue(item, generateZLevel(item)); + if (!mTools.contains(item)) ++mItemCount; @@ -1398,8 +1431,10 @@ void UBGraphicsScene::addItems(const QSet& items) { setModified(true); - foreach(QGraphicsItem* item, items) + foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::addItem(item); + UBGraphicsItem::assignZValue(item, generateZLevel(item)); + } mItemCount += items.size(); @@ -1461,7 +1496,7 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground); // item->setZValue(backgroundLayerStart); - UBGraphicsItem::assignZValue(item, backgroundLayerStart); + UBGraphicsItem::assignZValue(item, generateZLevel(item)); if (pAdaptTransformation) { @@ -1565,9 +1600,6 @@ void UBGraphicsScene::addRuler(QPointF center) QRectF rect = ruler->rect(); ruler->setRect(center.x() - rect.width()/2, center.y() - rect.height()/2, rect.width(), rect.height()); -// ruler->setZValue(toolLayerStart + toolOffsetRuler); - UBGraphicsItem::assignZValue(ruler, toolLayerStart + toolOffsetRuler); - ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); addItem(ruler); @@ -1584,9 +1616,6 @@ void UBGraphicsScene::addProtractor(QPointF center) UBGraphicsProtractor* protractor = new UBGraphicsProtractor(); // mem : owned and destroyed by the scene mTools << protractor; -// protractor->setZValue(toolLayerStart + toolOffsetProtractor); - UBGraphicsItem::assignZValue(protractor, toolLayerStart + toolOffsetProtractor); - protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); addItem(protractor); @@ -1605,9 +1634,6 @@ void UBGraphicsScene::addTriangle(QPointF center) UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); // mem : owned and destroyed by the scene mTools << triangle; -// triangle->setZValue(toolLayerStart + toolOffsetProtractor); - UBGraphicsItem::assignZValue(triangle, toolLayerStart + toolOffsetTriangle); - triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); addItem(triangle); @@ -1738,9 +1764,6 @@ void UBGraphicsScene::addCompass(QPointF center) QRectF rect = compass->rect(); compass->setRect(center.x() - rect.width() / 2, center.y() - rect.height() / 2, rect.width(), rect.height()); -// compass->setZValue(toolLayerStart + toolOffsetCompass); - UBGraphicsItem::assignZValue(compass, toolLayerStart + toolOffsetCompass); - compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); compass->setVisible(true); @@ -1772,8 +1795,6 @@ void UBGraphicsScene::addMask(const QPointF ¢er) QRectF rect = UBApplication::boardController->activeScene()->normalizedSceneRect(); rect.setRect(center.x() - rect.width()/4, center.y() - rect.height()/4, rect.width()/2 , rect.height()/2); curtain->setRect(rect); - UBGraphicsItem::assignZValue(curtain, toolLayerStart + toolOffsetCurtain); - curtain->setVisible(true); curtain->setSelected(true); setModified(true); @@ -1992,6 +2013,17 @@ void UBGraphicsScene::setDocumentUpdated() , UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); } +qreal UBGraphicsScene::generateZLevel(QGraphicsItem *item) +{ + qreal result = UBZLayerController::errorNum(); + itemLayerType::Enum type = static_cast(item->data(UBGraphicsItemData::itemLayerType).toInt()); + + if (mZLayerController.validLayerType(type)) { + result = mZLayerController.generateZLevel(type); + } + + return result; +} void UBGraphicsScene::setToolCursor(int tool) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 446bfb93..3d7820ff 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -25,7 +25,6 @@ #include "UBItem.h" #include "tools/UBGraphicsCurtainItem.h" - class UBGraphicsPixmapItem; class UBGraphicsProxyWidget; class UBGraphicsSvgItem; @@ -50,11 +49,41 @@ class UBGraphicsCache; const double PI = 4.0 * atan(1.0); +class UBZLayerController +{ +public: + + struct ItemLayerTypeData { + ItemLayerTypeData() : bottomLimit(0), topLimit(0), curValue(0) {;} + ItemLayerTypeData(qreal bot, qreal top) : bottomLimit(bot), topLimit(top), curValue(bot) {;} + qreal bottomLimit; + qreal topLimit; + qreal curValue; + }; + + typedef QMap ScopeMap; + + UBZLayerController(); + + qreal getBottomLimit(itemLayerType::Enum key) const {return scopeMap.value(key).bottomLimit;} + qreal getTopLimit(itemLayerType::Enum key) const {return scopeMap.value(key).topLimit;} + bool validLayerType(itemLayerType::Enum key) const {return scopeMap.contains(key);} + static qreal errorNum() {return errorNumber;} + + qreal generateZLevel(itemLayerType::Enum key); + + private: + ScopeMap scopeMap; + static qreal errorNumber; + +}; + class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem { Q_OBJECT public: + // tmp stub for divide addings scene objects from undo mechanism implementation void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} @@ -323,6 +352,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem private: void setDocumentUpdated(); + qreal generateZLevel(QGraphicsItem *item); qreal mDrawingZIndex; qreal mObjectZIndex; @@ -376,7 +406,10 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBMagnifier *magniferControlViewWidget; UBMagnifier *magniferDisplayViewWidget; + UBZLayerController mZLayerController; }; + + #endif /* UBGRAPHICSSCENE_H_ */ diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 9d8798ec..a4fe1034 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -37,7 +37,6 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QString& pFilePath, QGraphicsItem* pa } } - UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* parent) : QGraphicsSvgItem(parent) { @@ -47,6 +46,8 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* setSharedRenderer(renderer); mFileData = pFileData; + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 0d01527a..6a47b9eb 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -40,23 +40,11 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) mTypeTextHereLabel = tr(""); -// if (lastUsedTextColor.isValid()) -// { -// setDefaultTextColor(lastUsedTextColor); -// setColorOnDarkBackground(lastUsedTextColor); -// setColorOnLightBackground(lastUsedTextColor); -// } -// else -// { -// QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); -// QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); - -// setColorOnDarkBackground(colorOnDarkBG); -// setColorOnLightBackground(colorOnLightBG); -// } setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); // setData(UBGraphicsItemData::ItemEditable, QVariant(true)); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + setFlag(QGraphicsItem::ItemIsSelectable, true); // setFlag(QGraphicsItem::ItemIsMovable, true); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index ea031cf1..6c6ea66e 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -96,10 +96,10 @@ void UBGraphicsTextItemDelegate::buildButtons() { UBGraphicsItemDelegate::buildButtons(); - mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame); - mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame); - mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame); - mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame); + mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection); + mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame, Qt::TopLeftSection); + mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TopLeftSection); + mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::TopLeftSection); connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont())); connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor())); diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index c1e57e4d..68e53971 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -51,6 +51,8 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl& pVideoFileUrl, QGraphicsIte mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + connect(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool))); } diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 54baebc7..c5144d53 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -39,6 +39,7 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this, widgetType); delegate->init(); setDelegate(delegate); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } @@ -154,6 +155,8 @@ void UBGraphicsWidgetItem::initialize() if (mDelegate && mDelegate->frame() && mWebKitWidget->resizable()) mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 9a318011..e10cd57a 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -17,6 +17,7 @@ #include #include "domain/UBGraphicsItemDelegate.h" +#include "core/UB.h" class UBGraphicsScene; diff --git a/src/tools/UBAbstractDrawRuler.cpp b/src/tools/UBAbstractDrawRuler.cpp index e69aa815..385e55c6 100644 --- a/src/tools/UBAbstractDrawRuler.cpp +++ b/src/tools/UBAbstractDrawRuler.cpp @@ -48,6 +48,7 @@ UBAbstractDrawRuler::UBAbstractDrawRuler() QDesktopWidget* desktop = UBApplication::desktop(); int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; sPixelsPerMillimeter = qRound(dpiCommon / 25.4f);//because 1inch = 25.4 mm + } void UBAbstractDrawRuler::create(QGraphicsItem& item) diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index cff7c43c..be90eb97 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -33,14 +33,12 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem() // Get the board size and pass it to the shape QRect boardRect = UBApplication::boardController->displayView()->rect(); setRect(-15*boardRect.width(), -15*boardRect.height(), 30*boardRect.width(), 30*boardRect.height()); -// setZValue(CACHE_ZVALUE); - UBGraphicsItem::assignZValue(this, CACHE_ZVALUE); setData(Qt::UserRole, QVariant("Cache")); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Cache)); //Necessary to set if we want z value to be assigned correctly } UBGraphicsCache::~UBGraphicsCache() { - } UBItem* UBGraphicsCache::deepCopy() const @@ -92,8 +90,6 @@ void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *o Q_UNUSED(option); Q_UNUSED(widget); - UBGraphicsItem::assignZValue(this, CACHE_ZVALUE); - painter->setBrush(mMaskColor); painter->setPen(mMaskColor); diff --git a/src/tools/UBGraphicsCache.h b/src/tools/UBGraphicsCache.h index 6a8ce4cd..6a27233b 100644 --- a/src/tools/UBGraphicsCache.h +++ b/src/tools/UBGraphicsCache.h @@ -21,8 +21,6 @@ #include "domain/UBItem.h" #include "core/UB.h" -#define CACHE_ZVALUE 100000 - typedef enum { eMaskShape_Circle, diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp index 6e13b125..7d6231a9 100644 --- a/src/tools/UBGraphicsCompass.cpp +++ b/src/tools/UBGraphicsCompass.cpp @@ -70,6 +70,8 @@ UBGraphicsCompass::UBGraphicsCompass() unsetCursor(); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + connect(UBApplication::boardController, SIGNAL(penColorChanged()), this, SLOT(penColorChanged())); connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged())); } diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index a71a224d..e4cde85f 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -49,6 +49,8 @@ UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Tool); setPen(Qt::NoPen); this->setAcceptHoverEvents(true); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Curtain)); //Necessary to set if we want z value to be assigned correctly } UBGraphicsCurtainItem::~UBGraphicsCurtainItem() diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index bafb5689..3267994b 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -63,6 +63,7 @@ UBGraphicsProtractor::UBGraphicsProtractor() mRotateSvgItem->setVisible(false); mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly scale(1.5, 1.5); } diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 2bf27719..53312e11 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -44,6 +44,8 @@ UBGraphicsRuler::UBGraphicsRuler() create(*this); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + updateResizeCursor(); } diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index e5c7fdeb..81956642 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -43,8 +43,8 @@ UBGraphicsTriangle::UBGraphicsTriangle() mHFlipSvgItem = new QGraphicsSvgItem(":/images/hflipTool.svg", this); mHFlipSvgItem->setVisible(false); - mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + mHFlipSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); mVFlipSvgItem = new QGraphicsSvgItem(":/images/vflipTool.svg", this); mVFlipSvgItem->setVisible(false); @@ -54,6 +54,8 @@ UBGraphicsTriangle::UBGraphicsTriangle() mRotateSvgItem->setVisible(false); mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + updateResizeCursor(); } From b36627aeaa1fdc91912605842ca030d0fec7dc05 Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Fri, 30 Mar 2012 20:37:14 +0300 Subject: [PATCH 02/10] Zvalue controller is now finished --- src/adaptors/UBSvgSubsetAdaptor.cpp | 44 +----- src/board/UBBoardController.cpp | 2 - src/core/UB.h | 1 + src/domain/UBGraphicsAudioItem.cpp | 2 - src/domain/UBGraphicsItemDelegate.cpp | 14 +- src/domain/UBGraphicsItemDelegate.h | 2 +- src/domain/UBGraphicsPDFItem.cpp | 4 - src/domain/UBGraphicsPixmapItem.cpp | 2 - src/domain/UBGraphicsPolygonItem.cpp | 3 - src/domain/UBGraphicsScene.cpp | 164 ++++++-------------- src/domain/UBGraphicsScene.h | 27 +--- src/domain/UBGraphicsSvgItem.cpp | 8 +- src/domain/UBGraphicsTextItem.cpp | 2 - src/domain/UBGraphicsVideoItem.cpp | 2 - src/domain/UBGraphicsVideoItemDelegate.cpp | 4 +- src/domain/UBGraphicsWidgetItem.cpp | 1 - src/tools/UBGraphicsCache.cpp | 2 - src/tools/UBGraphicsCompass.cpp | 2 - src/tools/UBGraphicsCurtainItem.cpp | 4 - src/tools/UBGraphicsCurtainItemDelegate.cpp | 1 - src/tools/UBGraphicsProtractor.cpp | 2 - src/tools/UBGraphicsRuler.cpp | 2 - src/tools/UBGraphicsTriangle.cpp | 2 - 23 files changed, 65 insertions(+), 232 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 95857b3e..b39b7d25 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -306,9 +306,6 @@ UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { UBGraphicsScene *scene = 0; - qreal maxDrawingZIndex = 0; - qreal maxObjectZIndex = 0; - UBGraphicsWidgetItem *currentWidget = 0; mFileVersion = 40100; // default to 4.1.0 @@ -481,7 +478,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(polygonItem); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - maxDrawingZIndex = qMax(polygonItem->zValue(), maxDrawingZIndex); polygonItem->show(); } @@ -501,8 +497,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() scene->addItem(polygonItem); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - maxDrawingZIndex = qMax(polygonItem->zValue(), maxDrawingZIndex); - polygonItem->show(); } } @@ -527,8 +521,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(pixmapItem->zValue(), maxObjectZIndex); - scene->addItem(pixmapItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -549,8 +541,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(svgItem->zValue(), maxObjectZIndex); - scene->addItem(svgItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -577,8 +567,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(audioItem->zValue(), maxObjectZIndex); - scene->addItem(audioItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -600,8 +588,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(videoItem->zValue(), maxObjectZIndex); - scene->addItem(videoItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -623,8 +609,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex); - scene->addItem(textItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -733,8 +717,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() pdfItem->setFlag(QGraphicsItem::ItemIsMovable, true); pdfItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(pdfItem->zValue(), maxObjectZIndex); - scene->addItem(pdfItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -758,8 +740,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); - maxObjectZIndex = qMax(appleWidgetItem->zValue(), maxObjectZIndex); - scene->addItem(appleWidgetItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -781,8 +761,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() w3cWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); - maxObjectZIndex = qMax(w3cWidgetItem->zValue(), maxObjectZIndex); - scene->addItem(w3cWidgetItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -802,7 +780,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex); scene->addItem(textItem); if (zFromSvg != UBZLayerController::errorNum()) @@ -856,17 +833,14 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() qWarning() << "error parsing Sankore file " << mXmlReader.errorString(); } - if (scene) - { - scene->setObjectZIndex(maxObjectZIndex); - scene->setDrawingZIndex(maxDrawingZIndex); + if (scene) { scene->setModified(false); } if (annotationGroup) { - if (annotationGroup->polygons().empty()) - delete annotationGroup; + if (annotationGroup->polygons().empty()) + delete annotationGroup; } return scene; @@ -1400,12 +1374,10 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol if (!ubZValue.isNull()) { -// polygonItem->setZValue (ubZValue.toString().toFloat()); UBGraphicsItem::assignZValue(polygonItem, ubZValue.toString().toFloat()); } else { -// polygonItem->setZValue(mGroupZIndex); UBGraphicsItem::assignZValue(polygonItem, mGroupZIndex); } @@ -1509,12 +1481,10 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromLin if (!ubZValue.isNull()) { -// polygonItem->setZValue(ubZValue.toString().toFloat()); UBGraphicsItem::assignZValue(polygonItem, ubZValue.toString().toFloat()); } else { -// polygonItem->setZValue(mGroupZIndex); UBGraphicsItem::assignZValue(polygonItem, mGroupZIndex); } @@ -1663,7 +1633,6 @@ QList UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItem { UBGraphicsPolygonItem* polygonItem = new UBGraphicsPolygonItem(QLineF(points.at(i), points.at(i + 1)), lineWidth); polygonItem->setColor(brushColor); -// polygonItem->setZValue(zValue); UBGraphicsItem::assignZValue(polygonItem, zValue); polygonItem->setColorOnDarkBackground(colorOnDarkBackground); polygonItem->setColorOnLightBackground(colorOnLightBackground); @@ -2008,7 +1977,6 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g if (!ubZValue.isNull()) { -// gItem->setZValue(ubZValue.toString().toFloat()); UBGraphicsItem::assignZValue(gItem, ubZValue.toString().toFloat()); } @@ -2591,7 +2559,6 @@ UBGraphicsRuler* UBSvgSubsetAdaptor::UBSvgSubsetReader::rulerFromSvg() graphicsItemFromSvg(ruler); -// ruler->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetRuler); UBGraphicsItem::assignZValue(ruler, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetRuler); ruler->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2650,7 +2617,6 @@ UBGraphicsCompass* UBSvgSubsetAdaptor::UBSvgSubsetReader::compassFromSvg() graphicsItemFromSvg(compass); - //compass->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCompass); UBGraphicsItem::assignZValue(compass, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCompass); compass->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2715,7 +2681,6 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg() { UBGraphicsProtractor* protractor = new UBGraphicsProtractor(); -// protractor->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetProtractor); UBGraphicsItem::assignZValue(protractor, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetProtractor); protractor->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2786,7 +2751,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() { UBGraphicsTriangle* triangle = new UBGraphicsTriangle(); -// triangle->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle); UBGraphicsItem::assignZValue(triangle, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetTriangle); triangle->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); @@ -2813,8 +2777,6 @@ UBGraphicsTriangle* UBSvgSubsetAdaptor::UBSvgSubsetReader::triangleFromSvg() UBGraphicsCache* UBSvgSubsetAdaptor::UBSvgSubsetReader::cacheFromSvg() { UBGraphicsCache* pCache = new UBGraphicsCache(); - pCache->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCache); -// UBGraphicsItem::assignZValue(pCache, UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCache); pCache->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); graphicsItemFromSvg(pCache); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 5bc5653d..961a2dc3 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1943,8 +1943,6 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint if (gi) { -// gi->setZValue(mActiveScene->getNextObjectZIndex()); - UBGraphicsItem::assignZValue(gi, mActiveScene->getNextObjectZIndex()); mActiveScene->addItem(gi); gi->setPos(gi->pos() + QPointF(50, 50)); } diff --git a/src/core/UB.h b/src/core/UB.h index 0d372469..0ca8d2cd 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -84,6 +84,7 @@ struct itemLayerType , Curtain , Pointer , Cache + , SelectedItem }; }; diff --git a/src/domain/UBGraphicsAudioItem.cpp b/src/domain/UBGraphicsAudioItem.cpp index 88bf64c9..f2d1ab45 100644 --- a/src/domain/UBGraphicsAudioItem.cpp +++ b/src/domain/UBGraphicsAudioItem.cpp @@ -97,8 +97,6 @@ UBItem* UBGraphicsAudioItem::deepCopy() const UBGraphicsAudioItem *copy = new UBGraphicsAudioItem(audioUrl, parentItem()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index b4abe891..3d233923 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -73,8 +73,6 @@ void UBGraphicsItemDelegate::init() { mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame->hide(); -// mFrame->setZValue(UBGraphicsScene::toolLayerStart + 1); - UBGraphicsItem::assignZValue(mFrame, UBGraphicsScene::toolLayerStart + 1); mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); mDeleteButton = new DelegateButton(":/images/close.svg", mDelegated, mFrame, Qt::TopLeftSection); @@ -102,8 +100,6 @@ void UBGraphicsItemDelegate::init() foreach(DelegateButton* button, mButtons) { button->hide(); -// button->setZValue(UBGraphicsScene::toolLayerStart + 2); - UBGraphicsItem::assignZValue(button, UBGraphicsScene::toolLayerStart + 2); button->setFlag(QGraphicsItem::ItemIsSelectable, true); } } @@ -168,18 +164,9 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) if (!mDelegated->isSelected()) { mDelegated->setSelected(true); - - UBGraphicsScene* scene = static_cast(mDelegated->scene()); - qDebug() << mDelegated->zValue(); - qDebug() << scene->currentObjectZIndex(); - -// To investigate. Z value behavior -// if (mDelegated->zValue() < scene->currentObjectZIndex() && !isLocked()) -// mDelegated->setZValue(scene->getNextObjectZIndex()); positionHandles(); - return true; } else @@ -288,6 +275,7 @@ void UBGraphicsItemDelegate::positionHandles() mDelegated->scene()->addItem(button); } button->show(); + button->setZValue(delegated()->zValue()); } } else { foreach(DelegateButton* button, mButtons) diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 59b1b627..b7388665 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -33,7 +33,7 @@ class DelegateButton: public QGraphicsSvgItem Q_OBJECT public: - DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0, Qt::WindowFrameSection section = Qt::NoSection) + DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0, Qt::WindowFrameSection section = Qt::TopLeftSection) : QGraphicsSvgItem(fileName, parent) , mDelegated(pDelegated) , mIsTransparentToMouseEvent(false) diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 33aa274b..aa8c7ea3 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -85,8 +85,6 @@ UBItem* UBGraphicsPDFItem::deepCopy() const UBGraphicsPDFItem *copy = new UBGraphicsPDFItem(mRenderer, mPageNumber, parentItem()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -136,8 +134,6 @@ UBGraphicsPixmapItem* UBGraphicsPDFItem::toPixmapItem() const pixmapItem->setPixmap(pixmap); pixmapItem->setPos(this->pos()); -// pixmapItem->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(pixmapItem, this->zValue()); pixmapItem->setTransform(this->transform()); pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 527c0359..07dc4679 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -103,8 +103,6 @@ UBItem* UBGraphicsPixmapItem::deepCopy() const copy->setPixmap(this->pixmap()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index dcc750c5..7608e20e 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -161,9 +161,6 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con copy->setPen(this->pen()); copy->mHasAlpha = this->mHasAlpha; -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); - copy->setColorOnDarkBackground(this->colorOnDarkBackground()); copy->setColorOnLightBackground(this->colorOnLightBackground()); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 2729d093..bbd4af62 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -61,8 +61,6 @@ #include "core/memcheck.h" -qreal UBGraphicsScene::backgroundLayerStart = -20000000.0; -qreal UBGraphicsScene::objectLayerStart = -10000000.0; qreal UBGraphicsScene::drawingLayerStart = 0.0; qreal UBGraphicsScene::toolLayerStart = 10000000.0; @@ -88,10 +86,12 @@ UBZLayerController::UBZLayerController() scopeMap.insert(itemLayerType::DrawingItem, ItemLayerTypeData( 0.0, 10000000.0 )); scopeMap.insert(itemLayerType::ToolItem, ItemLayerTypeData( 10000000.0, 10000100.0 )); scopeMap.insert(itemLayerType::CppTool, ItemLayerTypeData( 10000100.0, 10000200.0 )); - scopeMap.insert(itemLayerType::Eraiser, ItemLayerTypeData( 10000200.0, 10001000.0 )); - scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 10001000.0, 10001100.0 )); + scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 10000200.0, 10001000.0 )); + scopeMap.insert(itemLayerType::Eraiser, ItemLayerTypeData( 10001000.0, 10001100.0 )); scopeMap.insert(itemLayerType::Pointer, ItemLayerTypeData( 10001100.0, 10001200.0 )); scopeMap.insert(itemLayerType::Cache, ItemLayerTypeData( 10001300.0, 10001400.0 )); + + scopeMap.insert(itemLayerType::SelectedItem, ItemLayerTypeData( 10001000.0, 10001000.0 )); } qreal UBZLayerController::generateZLevel(itemLayerType::Enum key) @@ -107,8 +107,8 @@ qreal UBZLayerController::generateZLevel(itemLayerType::Enum key) result++; if (result >= top) { - qDebug() << "new values are finished for the scope" << key; - result = top; + qDebug() << "new values are over for the scope" << key; + result = top - 1; } scopeMap[key].curValue = result; @@ -145,38 +145,8 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) #endif setDocument(parent); - - mDrawingZIndex = drawingLayerStart; - mObjectZIndex = objectLayerStart; - - mEraser = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene - mEraser->setRect(QRect(0, 0, 0, 0)); - mEraser->setVisible(false); - - mEraser->setZValue(/*toolLayerStart + toolOffsetEraser*/2); - mEraser->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); -// mEraser->setData(UBGraphicsItemData::itemLayerType, QVariant(Eraiser)); - -// qreal zval = mZLayerController.generateZLevel((itmeLayerType)mEraser->data(UBGraphicsItemData::itemLayerType).toInt()); -// qreal zval1 = mZLayerController.generateZLevel(Eraiser); -// qreal zval2 = mZLayerController.generateZLevel(Eraiser); -// mEraser->setZValue(zval); - - mTools << mEraser; - addItem(mEraser); - - mPointer = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene - mPointer->setRect(QRect(0, 0, 20, 20)); - mPointer->setVisible(false); - - mPointer->setPen(Qt::NoPen); - mPointer->setBrush(QBrush(QColor(255, 0, 0, 186))); - - mPointer->setZValue( /*toolLayerStart + toolOffsetPointer*/ 2); - mPointer->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); - - mTools << mPointer; - addItem(mPointer); + createEraiser(); + createPointer(); if (UBApplication::applicationController) { @@ -204,23 +174,14 @@ void UBGraphicsScene::selectionChangedProcessing() + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); QList allItemsList = items(); - qreal maxZ = 0.; for( int i = 0; i < allItemsList.size(); i++ ) { QGraphicsItem *nextItem = allItemsList.at(i); - //Temporary stub. Due to ugly z-order implementation I need to do this (sankore 360) - //z-order behavior should be reimplemented and this stub should be deleted - if (nextItem == mBackgroundObject) - continue; - //Temporary stub end (sankore 360) - if (nextItem->zValue() > maxZ) - maxZ = nextItem->zValue(); - nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); -// nextItem->setZValue(qreal(1)); - } - QList selItemsList = selectedItems(); - for( int i = 0; i < selItemsList.size(); i++ ) { - QGraphicsItem *nextItem = selItemsList.at(i); - nextItem->setZValue(maxZ + 0.0001); + + if (nextItem->isSelected()) { + nextItem->setZValue(mZLayerController.generateZLevel(itemLayerType::SelectedItem)); + } else { + nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); + } } } @@ -449,25 +410,11 @@ void UBGraphicsScene::drawEraser(const QPointF &pPoint, bool isFirstDraw) qreal eraserRadius = eraserWidth / 2; // TODO UB 4.x optimize - no need to do that every time we move it - if (mEraser) - { + if (mEraser) { mEraser->setRect(QRectF(pPoint.x() - eraserRadius, pPoint.y() - eraserRadius, eraserWidth, eraserWidth)); - if(isFirstDraw) - { - qreal maxZ = 0.; - QList allItemsList = items(); - for( int i = 0; i < allItemsList.size(); i++ ) - { - QGraphicsItem *nextItem = allItemsList.at(i); - qreal zValue = nextItem->zValue(); - if (zValue > maxZ) - maxZ = zValue; - nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); - } - - mEraser->setZValue(maxZ + 0.0001); - mEraser->show(); + if(isFirstDraw) { + mEraser->show(); } } } @@ -478,27 +425,12 @@ void UBGraphicsScene::drawPointer(const QPointF &pPoint, bool isFirstDraw) qreal pointerRadius = pointerDiameter / 2; // TODO UB 4.x optimize - no need to do that every time we move it - if (mPointer) - { + if (mPointer) { mPointer->setRect(QRectF(pPoint.x() - pointerRadius, - pPoint.y() - pointerRadius, - pointerDiameter, - pointerDiameter)); - - if(isFirstDraw) - { - qreal maxZ = 0.; - QList allItemsList = items(); - for( int i = 0; i < allItemsList.size(); i++ ) - { - QGraphicsItem *nextItem = allItemsList.at(i); - qreal zValue = nextItem->zValue(); - if (zValue > maxZ) - maxZ = zValue; - nextItem->setZValue(nextItem->data(UBGraphicsItemData::ItemOwnZValue).toReal()); - } - - mPointer->setZValue(maxZ + 0.0001); + pPoint.y() - pointerRadius, + pointerDiameter, + pointerDiameter)); + if(isFirstDraw) { mPointer->show(); } } @@ -735,21 +667,6 @@ void UBGraphicsScene::drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle) setDocumentUpdated(); } - -qreal UBGraphicsScene::getNextDrawingZIndex() -{ - mDrawingZIndex = mDrawingZIndex + 1.0; - return mDrawingZIndex; -} - - -qreal UBGraphicsScene::getNextObjectZIndex() -{ - mObjectZIndex = mObjectZIndex + 1.0; - return mObjectZIndex; -} - - void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) { bool needRepaint = false; @@ -912,9 +829,6 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const UBGraphicsScene* copy = new UBGraphicsScene(this->document()); copy->setBackground(this->isDarkBackground(), this->isCrossedBackground()); - - copy->mDrawingZIndex = this->mDrawingZIndex; - copy->mObjectZIndex = this->mObjectZIndex; copy->setSceneRect(this->sceneRect()); if (this->mNominalSize.isValid()) @@ -1092,7 +1006,6 @@ UBGraphicsPixmapItem* UBGraphicsScene::addPixmap(const QPixmap& pPixmap, const Q pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// pixmapItem->setZValue(getNextObjectZIndex()); pixmapItem->setPixmap(pPixmap); @@ -1144,7 +1057,6 @@ UBGraphicsVideoItem* UBGraphicsScene::addVideo(const QUrl& pVideoFileUrl, bool s videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// videoItem->setZValue(getNextObjectZIndex()); addItem(videoItem); @@ -1176,7 +1088,6 @@ UBGraphicsAudioItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool s audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); -// audioItem->setZValue(getNextObjectZIndex()); addItem(audioItem); @@ -1495,8 +1406,7 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool item->setAcceptedMouseButtons(Qt::NoButton); item->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::FixedBackground); -// item->setZValue(backgroundLayerStart); - UBGraphicsItem::assignZValue(item, generateZLevel(item)); + UBGraphicsItem::assignZValue(item, mZLayerController.generateZLevel(itemLayerType::BackgroundItem)); if (pAdaptTransformation) { @@ -2012,6 +1922,34 @@ void UBGraphicsScene::setDocumentUpdated() document()->setMetaData(UBSettings::documentUpdatedAt , UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); } +void UBGraphicsScene::createEraiser() +{ + mEraser = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene + mEraser->setRect(QRect(0, 0, 0, 0)); + mEraser->setVisible(false); + + mEraser->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); + mEraser->setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Eraiser)); //Necessary to set if we want z value to be assigned correctly + + mTools << mEraser; + addItem(mEraser); + +} +void UBGraphicsScene::createPointer() +{ + mPointer = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene + mPointer->setRect(QRect(0, 0, 20, 20)); + mPointer->setVisible(false); + + mPointer->setPen(Qt::NoPen); + mPointer->setBrush(QBrush(QColor(255, 0, 0, 186))); + + mPointer->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Tool)); + mPointer->setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Pointer)); //Necessary to set if we want z value to be assigned correctly + + mTools << mPointer; + addItem(mPointer); +} qreal UBGraphicsScene::generateZLevel(QGraphicsItem *item) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 3d7820ff..8fa84053 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -181,23 +181,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem return mCrossedBackground; } - void setDrawingZIndex(qreal pDrawingZIndex) - { - mDrawingZIndex = pDrawingZIndex; - } - - void setObjectZIndex(qreal pObjectZIndex) - { - mObjectZIndex = pObjectZIndex; - } - bool hasBackground() { return (mBackgroundObject != 0); } - qreal getNextObjectZIndex(); - void addRuler(QPointF center); void addProtractor(QPointF center); void addCompass(QPointF center); @@ -254,11 +242,6 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void setNominalSize(int pWidth, int pHeight); - qreal currentObjectZIndex() - { - return mObjectZIndex; - } - enum RenderingContext { Screen = 0, NonScreen, PdfExport, Podcast @@ -343,19 +326,17 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void recolorAllItems(); - qreal getNextDrawingZIndex(); - - virtual void drawItems (QPainter * painter, int numItems, + virtual void drawItems (QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[], QWidget * widget = 0); QGraphicsItem* rootItem(QGraphicsItem* item) const; private: void setDocumentUpdated(); - qreal generateZLevel(QGraphicsItem *item); + void createEraiser(); + void createPointer(); - qreal mDrawingZIndex; - qreal mObjectZIndex; + qreal generateZLevel(QGraphicsItem *item); QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mPointer; diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index a4fe1034..5e572b19 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -46,8 +46,6 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* setSharedRenderer(renderer); mFileData = pFileData; - - setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } @@ -62,6 +60,8 @@ void UBGraphicsSvgItem::init() setCacheMode(QGraphicsItem::DeviceCoordinateCache); setMaximumCacheSize(boundingRect().size().toSize() * UB_MAX_ZOOM); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly } @@ -133,8 +133,6 @@ UBItem* UBGraphicsSvgItem::deepCopy() const UBGraphicsSvgItem* copy = new UBGraphicsSvgItem(this->fileData()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -188,8 +186,6 @@ UBGraphicsPixmapItem* UBGraphicsSvgItem::toPixmapItem() const pixmapItem->setPixmap(QPixmap::fromImage(image)); pixmapItem->setPos(this->pos()); -// pixmapItem->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(pixmapItem, this->zValue()); pixmapItem->setTransform(this->transform()); pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 6a47b9eb..f42158f3 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -193,8 +193,6 @@ UBItem* UBGraphicsTextItem::deepCopy() const copy->setHtml(toHtml()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index 68e53971..887fdb7a 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -70,8 +70,6 @@ UBItem* UBGraphicsVideoItem::deepCopy() const UBGraphicsVideoItem *copy = new UBGraphicsVideoItem(videoUrl, parentItem()); copy->setPos(this->pos()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsVideoItemDelegate.cpp b/src/domain/UBGraphicsVideoItemDelegate.cpp index 99ba687b..35620cf0 100644 --- a/src/domain/UBGraphicsVideoItemDelegate.cpp +++ b/src/domain/UBGraphicsVideoItemDelegate.cpp @@ -52,8 +52,7 @@ void UBGraphicsVideoItemDelegate::buildButtons() mMuteButton->hide(); mVideoControl = new DelegateVideoControl(delegated(), mFrame); -// mVideoControl->setZValue(UBGraphicsScene::toolLayerStart + 2); - UBGraphicsItem::assignZValue(mVideoControl, UBGraphicsScene::toolLayerStart + 2); + UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue()); mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); @@ -106,6 +105,7 @@ void UBGraphicsVideoItemDelegate::positionHandles() } mVideoControl->setAntiScale(mAntiScaleRatio); + mVideoControl->setZValue(delegated()->zValue()); mVideoControl->show(); } else diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index c5144d53..899a7714 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -411,7 +411,6 @@ UBItem* UBGraphicsW3CWidgetItem::deepCopy() const UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(mWebKitWidget->widgetUrl(), parentItem()); copy->setPos(this->pos()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/tools/UBGraphicsCache.cpp b/src/tools/UBGraphicsCache.cpp index be90eb97..ae178ea9 100644 --- a/src/tools/UBGraphicsCache.cpp +++ b/src/tools/UBGraphicsCache.cpp @@ -47,8 +47,6 @@ UBItem* UBGraphicsCache::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp index 7d6231a9..f2bc45df 100644 --- a/src/tools/UBGraphicsCompass.cpp +++ b/src/tools/UBGraphicsCompass.cpp @@ -87,8 +87,6 @@ UBItem* UBGraphicsCompass::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index e4cde85f..6f0154d8 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -60,8 +60,6 @@ UBGraphicsCurtainItem::~UBGraphicsCurtainItem() QVariant UBGraphicsCurtainItem::itemChange(GraphicsItemChange change, const QVariant &value) { -// if (change == QGraphicsItem::ItemSelectedHasChanged && QGraphicsRectItem::scene() && isSelected()) -// setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCurtain); QVariant newValue = value; @@ -133,8 +131,6 @@ UBItem* UBGraphicsCurtainItem::deepCopy() const copy->setPos(this->pos()); copy->setBrush(this->brush()); copy->setPen(this->pen()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); copy->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/tools/UBGraphicsCurtainItemDelegate.cpp b/src/tools/UBGraphicsCurtainItemDelegate.cpp index a16685b6..4161c50d 100644 --- a/src/tools/UBGraphicsCurtainItemDelegate.cpp +++ b/src/tools/UBGraphicsCurtainItemDelegate.cpp @@ -52,7 +52,6 @@ bool UBGraphicsCurtainItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *ev if (!mDelegated->isSelected()) { mDelegated->setSelected(true); -// mDelegated->setZValue(UBGraphicsScene::toolLayerStart + UBGraphicsScene::toolOffsetCurtain); positionHandles(); return true; diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index 3267994b..129a1250 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -581,8 +581,6 @@ UBItem* UBGraphicsProtractor::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); copy->mCurrentAngle = this->mCurrentAngle; diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 53312e11..728b5bad 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -76,8 +76,6 @@ UBItem* UBGraphicsRuler::deepCopy() const copy->setPos(this->pos()); copy->setRect(this->rect()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index 81956642..bd4156e0 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -95,8 +95,6 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const copy->setPos(this->pos()); copy->setPolygon(this->polygon()); -// copy->setZValue(this->zValue()); - UBGraphicsItem::assignZValue(copy, this->zValue()); copy->setTransform(this->transform()); // TODO UB 4.7 ... complete all members ? From 56e49c1f5262ce9a87474b7944e825c56c1b6325 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 3 Apr 2012 12:36:51 +0300 Subject: [PATCH 03/10] Fixed screens initialization order and logic. --- src/core/UBApplication.cpp | 3 +-- src/core/UBApplicationController.cpp | 9 +++++---- src/core/UBApplicationController.h | 2 +- src/core/UBDisplayManager.cpp | 12 ------------ src/core/UBDisplayManager.h | 10 +++++----- src/core/UBPreferencesController.cpp | 2 +- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 7c78a086..b8a3e257 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -289,7 +289,6 @@ int UBApplication::exec(const QString& pFileToImport) bool bUseMultiScreen = UBSettings::settings()->appUseMultiscreen->get().toBool(); mainWindow->actionMultiScreen->setChecked(bUseMultiScreen); - applicationController->useMultiScreen(bUseMultiScreen); connect(mainWindow->actionMultiScreen, SIGNAL(triggered(bool)), applicationController, SLOT(useMultiScreen(bool))); connect(mainWindow->actionWidePageSize, SIGNAL(triggered(bool)), boardController, SLOT(setWidePageSize(bool))); connect(mainWindow->actionRegularPageSize, SIGNAL(triggered(bool)), boardController, SLOT(setRegularPageSize(bool))); @@ -299,7 +298,7 @@ int UBApplication::exec(const QString& pFileToImport) connect(mainWindow->actionCopy, SIGNAL(triggered()), applicationController, SLOT(actionCopy())); connect(mainWindow->actionPaste, SIGNAL(triggered()), applicationController, SLOT(actionPaste())); - applicationController->initScreenLayout(); + applicationController->initScreenLayout(bUseMultiScreen); boardController->setupLayout(); if (pFileToImport.length() > 0) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index e2e09375..d54e8610 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -135,14 +135,15 @@ void UBApplicationController::initViewState(int horizontalPosition, int vertical } -void UBApplicationController::initScreenLayout() +void UBApplicationController::initScreenLayout(bool useMultiscreen) { - mDisplayManager->setAsControl(mMainWindow, true); + mDisplayManager->setAsControl(mMainWindow); mDisplayManager->setAsDisplay(mDisplayView); mDisplayManager->setAsPreviousDisplays(mPreviousViews); mDisplayManager->setAsDesktop(mUninoteController->drawingView()); + mDisplayManager->setUseMultiScreen(bMultiScreen); mDisplayManager->adjustScreens(-1); } @@ -343,7 +344,6 @@ void UBApplicationController::showBoard() mirroringEnabled(false); mMainWindow->switchToBoardWidget(); - mDisplayManager->setAsDisplay(mDisplayView); if (UBApplication::boardController) UBApplication::boardController->show(); @@ -353,7 +353,7 @@ void UBApplicationController::showBoard() mUninoteController->hideWindow(); - mDisplayManager->adjustScreens(0); + mMainWindow->show(); emit mainModeChanged(Board); @@ -727,6 +727,7 @@ void UBApplicationController::importFile(const QString& pFilePath) void UBApplicationController::useMultiScreen(bool use) { mDisplayManager->setUseMultiScreen(use); + mDisplayManager->adjustScreens(0); UBSettings::settings()->appUseMultiscreen->set(use); } diff --git a/src/core/UBApplicationController.h b/src/core/UBApplicationController.h index 2bdf6890..4d578b42 100644 --- a/src/core/UBApplicationController.h +++ b/src/core/UBApplicationController.h @@ -51,7 +51,7 @@ class UBApplicationController : public QObject void blackout(); - void initScreenLayout(); + void initScreenLayout(bool useMultiscreen); void closing(); diff --git a/src/core/UBDisplayManager.cpp b/src/core/UBDisplayManager.cpp index 1bffbb26..b22746df 100644 --- a/src/core/UBDisplayManager.cpp +++ b/src/core/UBDisplayManager.cpp @@ -123,11 +123,6 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget, bool init) if(hasControl() && pControlWidget && (pControlWidget != mControlWidget)) { mControlWidget = pControlWidget; - mControlWidget->hide(); - mControlWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex)); - - if (!init) - mControlWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC // mControlWidget->setAttribute(Qt::WA_MacNoShadow); @@ -140,9 +135,6 @@ void UBDisplayManager::setAsDesktop(QWidget* pControlWidget ) if(pControlWidget && (pControlWidget != mControlWidget)) { mDesktopWidget = pControlWidget; - mDesktopWidget->hide(); - mDesktopWidget->setGeometry(mDesktop->screenGeometry(mControlScreenIndex)); -// mDisplayWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC // mControlWidget->setAttribute(Qt::WA_MacNoShadow); @@ -155,9 +147,6 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget) if(pDisplayWidget && (pDisplayWidget != mDisplayWidget)) { mDisplayWidget = pDisplayWidget; - mDisplayWidget->hide(); - mDisplayWidget->setGeometry(mDesktop->screenGeometry(mDisplayScreenIndex)); - mDisplayWidget->showFullScreen(); // !!!! Should be included into Windows after QT recompilation #ifdef Q_WS_MAC // mDisplayWidget->setAttribute(Qt::WA_MacNoShadow); @@ -310,6 +299,5 @@ void UBDisplayManager::setRoleToScreen(DisplayRole role, int screenIndex) void UBDisplayManager::setUseMultiScreen(bool pUse) { mUseMultiScreen = pUse; - adjustScreens(0); } diff --git a/src/core/UBDisplayManager.h b/src/core/UBDisplayManager.h index 33ee9244..f6ca289d 100644 --- a/src/core/UBDisplayManager.h +++ b/src/core/UBDisplayManager.h @@ -33,13 +33,13 @@ class UBDisplayManager : public QObject int numPreviousViews(); - void setAsControl(QWidget* pControlWidget, bool init = false); + void setControlWidget(QWidget* pControlWidget); - void setAsDisplay(QWidget* pDisplayWidget); + void setDisplayWidget(QWidget* pDisplayWidget); - void setAsDesktop(QWidget* pControlWidget); + void setDesktopWidget(QWidget* pControlWidget); - void setAsPreviousDisplays(QList pPreviousViews); + void setPreviousDisplaysWidgets(QList pPreviousViews); bool hasControl() { @@ -77,7 +77,7 @@ class UBDisplayManager : public QObject public slots: - void swapScreens(bool bswap); + void reinitScreens(bool bswap); void adjustScreens(int screen); diff --git a/src/core/UBPreferencesController.cpp b/src/core/UBPreferencesController.cpp index cd5fde30..3968f602 100644 --- a/src/core/UBPreferencesController.cpp +++ b/src/core/UBPreferencesController.cpp @@ -118,7 +118,7 @@ void UBPreferencesController::wire() connect(mPreferencesUI->useExternalBrowserCheckBox, SIGNAL(clicked(bool)), settings->webUseExternalBrowser, SLOT(setBool(bool))); connect(mPreferencesUI->displayBrowserPageCheckBox, SIGNAL(clicked(bool)), settings->webShowPageImmediatelyOnMirroredScreen, SLOT(setBool(bool))); connect(mPreferencesUI->swapControlAndDisplayScreensCheckBox, SIGNAL(clicked(bool)), settings->swapControlAndDisplayScreens, SLOT(setBool(bool))); - connect(mPreferencesUI->swapControlAndDisplayScreensCheckBox, SIGNAL(clicked(bool)), UBApplication::applicationController->displayManager(), SLOT(swapScreens(bool))); + connect(mPreferencesUI->swapControlAndDisplayScreensCheckBox, SIGNAL(clicked(bool)), UBApplication::applicationController->displayManager(), SLOT(reinitScreens(bool))); connect(mPreferencesUI->toolbarAtTopRadioButton, SIGNAL(clicked(bool)), this, SLOT(toolbarPositionChanged(bool))); connect(mPreferencesUI->toolbarAtBottomRadioButton, SIGNAL(clicked(bool)), this, SLOT(toolbarPositionChanged(bool))); From 468145e2ae8f6c4a5ed95a17fd4b67b9927f6c28 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 3 Apr 2012 12:49:40 +0300 Subject: [PATCH 04/10] Hotfix. Fixed merge errors. --- src/core/UBApplicationController.cpp | 16 ++++++++-------- src/core/UBDisplayManager.cpp | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index d54e8610..0ee793e1 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -137,13 +137,13 @@ void UBApplicationController::initViewState(int horizontalPosition, int vertical void UBApplicationController::initScreenLayout(bool useMultiscreen) { - mDisplayManager->setAsControl(mMainWindow); - mDisplayManager->setAsDisplay(mDisplayView); + mDisplayManager->setControlWidget(mMainWindow); + mDisplayManager->setDisplayWidget(mDisplayView); - mDisplayManager->setAsPreviousDisplays(mPreviousViews); - mDisplayManager->setAsDesktop(mUninoteController->drawingView()); + mDisplayManager->setPreviousDisplaysWidgets(mPreviousViews); + mDisplayManager->setDesktopWidget(mUninoteController->drawingView()); - mDisplayManager->setUseMultiScreen(bMultiScreen); + mDisplayManager->setUseMultiScreen(useMultiscreen); mDisplayManager->adjustScreens(-1); } @@ -637,12 +637,12 @@ void UBApplicationController::mirroringEnabled(bool enabled) if (enabled) { mMirror->start(); - mDisplayManager->setAsDisplay(mMirror); + mDisplayManager->setDisplayWidget(mMirror); } else { - mDisplayManager->setAsDisplay(mDisplayView); + mDisplayManager->setDisplayWidget(mDisplayView); mMirror->stop(); } @@ -652,7 +652,7 @@ void UBApplicationController::mirroringEnabled(bool enabled) } else { - mDisplayManager->setAsDisplay(mDisplayView); + mDisplayManager->setDisplayWidget(mDisplayView); } } diff --git a/src/core/UBDisplayManager.cpp b/src/core/UBDisplayManager.cpp index b22746df..1d441adb 100644 --- a/src/core/UBDisplayManager.cpp +++ b/src/core/UBDisplayManager.cpp @@ -118,7 +118,7 @@ int UBDisplayManager::numPreviousViews() } -void UBDisplayManager::setAsControl(QWidget* pControlWidget, bool init) +void UBDisplayManager::setControlWidget(QWidget* pControlWidget) { if(hasControl() && pControlWidget && (pControlWidget != mControlWidget)) { @@ -130,7 +130,7 @@ void UBDisplayManager::setAsControl(QWidget* pControlWidget, bool init) } } -void UBDisplayManager::setAsDesktop(QWidget* pControlWidget ) +void UBDisplayManager::setDesktopWidget(QWidget* pControlWidget ) { if(pControlWidget && (pControlWidget != mControlWidget)) { @@ -142,7 +142,7 @@ void UBDisplayManager::setAsDesktop(QWidget* pControlWidget ) } } -void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget) +void UBDisplayManager::setDisplayWidget(QWidget* pDisplayWidget) { if(pDisplayWidget && (pDisplayWidget != mDisplayWidget)) { @@ -155,7 +155,7 @@ void UBDisplayManager::setAsDisplay(QWidget* pDisplayWidget) } -void UBDisplayManager::setAsPreviousDisplays(QList pPreviousViews) +void UBDisplayManager::setPreviousDisplaysWidgets(QList pPreviousViews) { mPreviousDisplayWidgets = pPreviousViews; } @@ -171,7 +171,7 @@ QRect UBDisplayManager::displayGeometry() return mDesktop->screenGeometry(mDisplayScreenIndex); } -void UBDisplayManager::swapScreens(bool swap) +void UBDisplayManager::reinitScreens(bool swap) { Q_UNUSED(swap); adjustScreens(-1); From e82d5d880d379a2329b914f790e11a859789679e Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 3 Apr 2012 13:33:51 +0300 Subject: [PATCH 05/10] Added the plugin "cffadaprot". It converts Sankore documents to IWB. --- Sankore_3.1.pro | 7 + plugins/cffadaptor/UBCFFAdaptor.pro | 49 + .../cffadaptor/resources/images/soundOn.svg | 9 + plugins/cffadaptor/resources/resources.qrc | 5 + plugins/cffadaptor/src/UBCFFAdaptor.cpp | 1977 +++++++++++++++++ plugins/cffadaptor/src/UBCFFAdaptor.h | 146 ++ plugins/cffadaptor/src/UBCFFAdaptor_global.h | 12 + plugins/cffadaptor/src/UBCFFConstants.h | 378 ++++ plugins/cffadaptor/src/UBGlobals.h | 47 + src/adaptors/UBExportCFF.cpp | 60 + src/adaptors/UBExportCFF.h | 39 + src/adaptors/adaptors.pri | 2 + src/core/UBDocumentManager.cpp | 3 + 13 files changed, 2734 insertions(+) create mode 100644 plugins/cffadaptor/UBCFFAdaptor.pro create mode 100644 plugins/cffadaptor/resources/images/soundOn.svg create mode 100644 plugins/cffadaptor/resources/resources.qrc create mode 100644 plugins/cffadaptor/src/UBCFFAdaptor.cpp create mode 100644 plugins/cffadaptor/src/UBCFFAdaptor.h create mode 100644 plugins/cffadaptor/src/UBCFFAdaptor_global.h create mode 100644 plugins/cffadaptor/src/UBCFFConstants.h create mode 100644 plugins/cffadaptor/src/UBGlobals.h create mode 100644 src/adaptors/UBExportCFF.cpp create mode 100644 src/adaptors/UBExportCFF.h diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index 4fe242a6..7f87beca 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -35,6 +35,7 @@ QT += script QT += xmlpatterns INCLUDEPATH += src +INCLUDEPATH += plugins/cffadaptor/src include($$THIRD_PARTY_PATH/libs.pri) include(src/adaptors/adaptors.pri) @@ -109,6 +110,7 @@ RCC_DIR = $$BUILD_DIR/rcc UI_DIR = $$BUILD_DIR/ui win32 { + LIBS += "-Lplugins/cffadaptor/lib/win32" "-lCFF_Adaptor" RC_FILE = resources/win/sankore.rc CONFIG += qaxcontainer exists(console):CONFIG += console @@ -129,6 +131,7 @@ win32 { } macx { + LIBS += "-Lplugins/cffadaptor/lib/mac" "-lCFF_Adaptor" LIBS += -framework Foundation LIBS += -lcrypto LIBS += -framework AppKit @@ -326,6 +329,7 @@ macx { } linux-g++ { + LIBS += "-Lplugins/cffadaptor/lib/linux" "-lCFF_Adaptor" LIBS += -lcrypto QMAKE_CFLAGS += -fopenmp QMAKE_CXXFLAGS += -fopenmp @@ -341,6 +345,7 @@ linux-g++ { } linux-g++-32 { + LIBS += "-Lplugins/cffadaptor/lib/linux" "-lCFF_Adaptor" LIBS += -lcrypto QMAKE_CFLAGS += -fopenmp QMAKE_CXXFLAGS += -fopenmp @@ -356,6 +361,7 @@ linux-g++-32 { } linux-g++-64 { + LIBS += "-Lplugins/cffadaptor/lib/linux" "-lCFF_Adaptor" LIBS += -lcrypto QMAKE_CFLAGS += -fopenmp QMAKE_CXXFLAGS += -fopenmp @@ -371,6 +377,7 @@ linux-g++-64 { } RESOURCES += resources/sankore.qrc +RESOURCES += plugins/cffadaptor/resources/resources.qrc # When adding a translation here, also add it in the macx part TRANSLATIONS = resources/i18n/sankore_en.ts \ diff --git a/plugins/cffadaptor/UBCFFAdaptor.pro b/plugins/cffadaptor/UBCFFAdaptor.pro new file mode 100644 index 00000000..78f1bf71 --- /dev/null +++ b/plugins/cffadaptor/UBCFFAdaptor.pro @@ -0,0 +1,49 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2012-02-14T13:30:14 +# +#------------------------------------------------- + +win32: SUB_DIR = win32 +macx: SUB_DIR = macx +linux-g++: SUB_DIR = linux +linux-g++-32: SUB_DIR = linux +linux-g++-64: SUB_DIR = linux + +QUAZIP_DIR = "$$PWD/../../../Sankore-ThirdParty/quazip" +ZLIB_DIR = "$$PWD/../../../Sankore-ThirdParty/zlib" + +INCLUDEPATH += src \ + "$$QUAZIP_DIR/quazip-0.3" \ + "$$ZLIB_DIR/1.2.3/include" + +LIBS += "-L$$QUAZIP_DIR/lib/$$SUB_DIR" "-lquazip" + +QT += xml xmlpatterns core +QT += gui +QT += svg + +TARGET = CFF_Adaptor +TEMPLATE = lib +win32{ + CONFIG += dll +} + +DEFINES += UBCFFADAPTOR_LIBRARY +DEFINES += NO_THIRD_PARTY_WARNINGS + +SOURCES += \ + src/UBCFFAdaptor.cpp + +HEADERS +=\ + $$PWD/../../src/globals/UBGlobals.h \ + src/UBCFFAdaptor.h \ + src/UBCFFAdaptor_global.h \ + src/UBCFFConstants.h + +OBJECTS_DIR = $$PWD/objects +MOC_DIR = $$PWD/moc +DESTDIR = $$PWD/lib/$$SUB_DIR + +RESOURCES += \ + resources/resources.qrc diff --git a/plugins/cffadaptor/resources/images/soundOn.svg b/plugins/cffadaptor/resources/images/soundOn.svg new file mode 100644 index 00000000..79d27706 --- /dev/null +++ b/plugins/cffadaptor/resources/images/soundOn.svg @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/plugins/cffadaptor/resources/resources.qrc b/plugins/cffadaptor/resources/resources.qrc new file mode 100644 index 00000000..0a4ec471 --- /dev/null +++ b/plugins/cffadaptor/resources/resources.qrc @@ -0,0 +1,5 @@ + + + images/soundOn.svg + + diff --git a/plugins/cffadaptor/src/UBCFFAdaptor.cpp b/plugins/cffadaptor/src/UBCFFAdaptor.cpp new file mode 100644 index 00000000..6de92d92 --- /dev/null +++ b/plugins/cffadaptor/src/UBCFFAdaptor.cpp @@ -0,0 +1,1977 @@ +#include "UBCFFAdaptor.h" + +#include +#include +#include +#include +#include +#include + +#include "UBGlobals.h" +#include "UBCFFConstants.h" + +THIRD_PARTY_WARNINGS_DISABLE +#include "quazip.h" +#include "quazipfile.h" +#include "quazipfileinfo.h" +THIRD_PARTY_WARNINGS_ENABLE + +UBCFFAdaptor::UBCFFAdaptor() +{} + +bool UBCFFAdaptor::convertUBZToIWB(const QString &from, const QString &to) +{ + qDebug() << "starting converion from" << from << "to" << to; + + QString source = QString(); + if (QFileInfo(from).isDir() && QFile::exists(from)) { + qDebug() << "File specified is dir, continuing convertion"; + source = from; + } else { + source = uncompressZip(from); + if (!source.isNull()) qDebug() << "File specified is zip file. Uncompressed to tmp dir, continuing convertion"; + } + if (source.isNull()) { + qDebug() << "File specified is not a dir or a zip file, stopping covretion"; + return false; + } + + QString tmpDestination = createNewTmpDir(); + if (tmpDestination.isNull()) { + qDebug() << "can't create temp destination folder. Stopping parsing..."; + return false; + } + + UBToCFFConverter tmpConvertrer(source, tmpDestination); + if (!tmpConvertrer) { + qDebug() << "The convertrer class is invalid, stopping conversion. Error message" << tmpConvertrer.lastErrStr(); + return false; + } + if (!tmpConvertrer.parse()) { + return false; + } + + if (!compressZip(tmpDestination, to)) + qDebug() << "error in compression"; + + //Cleanning tmp souces in filesystem + if (!QFileInfo(from).isDir()) + if (!freeDir(source)) + qDebug() << "can't delete tmp directory" << QDir(source).absolutePath() << "try to delete them manually"; + + if (!freeDir(tmpDestination)) + qDebug() << "can't delete tmp directory" << QDir(tmpDestination).absolutePath() << "try to delete them manually"; + + return true; +} + +QString UBCFFAdaptor::uncompressZip(const QString &zipFile) +{ + QuaZip zip(zipFile); + + if(!zip.open(QuaZip::mdUnzip)) { + qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); + return QString(); + } + + zip.setFileNameCodec("UTF-8"); + QuaZipFileInfo info; + QuaZipFile file(&zip); + + //create unique cff document root fodler + QString documentRootFolder = createNewTmpDir(); + + if (documentRootFolder.isNull()) { + qDebug() << "can't create tmp directory for zip file" << zipFile; + return QString(); + } + + QDir rootDir(documentRootFolder); + QFile out; + char c; + bool allOk = true; + for(bool more = zip.goToFirstFile(); more; more=zip.goToNextFile()) { + if(!zip.getCurrentFileInfo(&info)) { + qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); + allOk = false; + break; + } + if(!file.open(QIODevice::ReadOnly)) { + allOk = false; + break; + } + if(file.getZipError()!= UNZ_OK) { + qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); + allOk = false; + break; + } + + QString newFileName = documentRootFolder + "/" + file.getActualFileName(); + + QFileInfo newFileInfo(newFileName); + rootDir.mkpath(newFileInfo.absolutePath()); + + out.setFileName(newFileName); + out.open(QIODevice::WriteOnly); + + while(file.getChar(&c)) + out.putChar(c); + + out.close(); + + if(file.getZipError()!=UNZ_OK) { + qWarning() << "Import failed. Cause: " << zip.getZipError(); + allOk = false; + break; + } + if(!file.atEnd()) { + qWarning() << "Import failed. Cause: read all but not EOF"; + allOk = false; + break; + } + file.close(); + + if(file.getZipError()!=UNZ_OK) { + qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); + allOk = false; + break; + } + } + + if (!allOk) { + out.close(); + file.close(); + zip.close(); + return QString(); + } + + if(zip.getZipError()!=UNZ_OK) { + qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); + return QString(); + } + + return documentRootFolder; +} + +bool UBCFFAdaptor::compressZip(const QString &source, const QString &destination) +{ + QDir toDir = QFileInfo(destination).dir(); + if (!toDir.exists()) + if (!QDir().mkpath(toDir.absolutePath())) { + qDebug() << "can't create destination folder to uncompress file"; + return false; + } + + QuaZip zip(destination); + zip.setFileNameCodec("UTF-8"); + if(!zip.open(QuaZip::mdCreate)) { + qDebug("Export failed. Cause: zip.open(): %d", zip.getZipError()); + return false; + } + + QuaZipFile outZip(&zip); + + QFileInfo sourceInfo(source); + if (sourceInfo.isDir()) { + if (!compressDir(QFileInfo(source).absoluteFilePath(), "", &outZip)) + return false; + } else if (sourceInfo.isFile()) { + if (!compressFile(QFileInfo(source).absoluteFilePath(), "", &outZip)) + return false; + } + + return true; +} + +bool UBCFFAdaptor::compressDir(const QString &dirName, const QString &parentDir, QuaZipFile *outZip) +{ + QFileInfoList dirFiles = QDir(dirName).entryInfoList(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); + QListIterator iter(dirFiles); + while (iter.hasNext()) { + QFileInfo curFile = iter.next(); + + if (curFile.isDir()) { + if (!compressDir(curFile.absoluteFilePath(), parentDir + curFile.fileName() + "/", outZip)) { + qDebug() << "error at compressing dir" << curFile.absoluteFilePath(); + return false; + } + } else if (curFile.isFile()) { + if (!compressFile(curFile.absoluteFilePath(), parentDir, outZip)) { + return false; + } + } + } + + return true; +} + +bool UBCFFAdaptor::compressFile(const QString &fileName, const QString &parentDir, QuaZipFile *outZip) +{ + QFile sourceFile(fileName); + + if(!sourceFile.open(QIODevice::ReadOnly)) { + qDebug() << "Compression of file" << sourceFile.fileName() << " failed. Cause: inFile.open(): " << sourceFile.errorString(); + return false; + } + + if(!outZip->open(QIODevice::WriteOnly, QuaZipNewInfo(parentDir + QFileInfo(fileName).fileName(), sourceFile.fileName()))) { + qDebug() << "Compression of file" << sourceFile.fileName() << " failed. Cause: outFile.open(): " << outZip->getZipError(); + sourceFile.close(); + return false; + } + + outZip->write(sourceFile.readAll()); + if(outZip->getZipError() != UNZ_OK) { + qDebug() << "Compression of file" << sourceFile.fileName() << " failed. Cause: outFile.write(): " << outZip->getZipError(); + + sourceFile.close(); + outZip->close(); + return false; + } + + if(outZip->getZipError() != UNZ_OK) + { + qWarning() << "Compression of file" << sourceFile.fileName() << " failed. Cause: outFile.close(): " << outZip->getZipError(); + + sourceFile.close(); + outZip->close(); + return false; + } + + outZip->close(); + sourceFile.close(); + + return true; +} + +QString UBCFFAdaptor::createNewTmpDir() +{ + int tmpNumber = 0; + QDir systemTmp = QDir::temp(); + + while (true) { + QString dirName = QString("CFF_adaptor_filedata_store%1.%2") + .arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm")) + .arg(tmpNumber++); + if (!systemTmp.exists(dirName)) { + if (systemTmp.mkdir(dirName)) { + QString result = systemTmp.absolutePath() + "/" + dirName; + tmpDirs.append(result); + return result; + } else { + qDebug() << "Can't create temporary dir maybe due to permissions"; + return QString(); + } + } else if (tmpNumber == 10) { + qWarning() << "Import failed. Failed to create temporary file "; + return QString(); + } + tmpNumber++; + } + + return QString(); +} +bool UBCFFAdaptor::deleteDir(const QString& pDirPath) const +{ + if (pDirPath == "" || pDirPath == "." || pDirPath == "..") + return false; + + QDir dir(pDirPath); + + if (dir.exists()) + { + foreach(QFileInfo dirContent, dir.entryInfoList(QDir::Files | QDir::Dirs + | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, QDir::Name)) + { + if (dirContent.isDir()) + { + deleteDir(dirContent.absoluteFilePath()); + } + else + { + if (!dirContent.dir().remove(dirContent.fileName())) + { + return false; + } + } + } + } + + return dir.rmdir(pDirPath); +} +bool UBCFFAdaptor::freeDir(const QString &dir) +{ + bool result = true; + if (!deleteDir(dir)) + result = false; + + tmpDirs.removeAll(QDir(dir).absolutePath()); + + return result; +} +void UBCFFAdaptor::freeTmpDirs() +{ + foreach (QString dir, tmpDirs) + freeDir(dir); +} + +UBCFFAdaptor::~UBCFFAdaptor() +{ + freeTmpDirs(); +} + +UBCFFAdaptor::UBToCFFConverter::UBToCFFConverter(const QString &source, const QString &destination) +{ + sourcePath = source; + destinationPath = destination; + + errorStr = noErrorMsg; + mDataModel = new QDomDocument; + mDocumentToWrite = new QDomDocument; + mDocumentToWrite->setContent(QString("")); + + mIWBContentWriter = new QXmlStreamWriter; + mIWBContentWriter->setAutoFormatting(true); + + iwbSVGItemsAttributes.insert(tIWBImage, iwbSVGImageAttributes); + iwbSVGItemsAttributes.insert(tIWBVideo, iwbSVGVideoAttributes); + iwbSVGItemsAttributes.insert(tIWBText, iwbSVGTextAttributes); + iwbSVGItemsAttributes.insert(tIWBTextArea, iwbSVGTextAreaAttributes); + iwbSVGItemsAttributes.insert(tIWBPolyLine, iwbSVGPolyLineAttributes); + iwbSVGItemsAttributes.insert(tIWBPolygon, iwbSVGPolygonAttributes); + iwbSVGItemsAttributes.insert(tIWBRect, iwbSVGRectAttributes); + iwbSVGItemsAttributes.insert(tIWBLine, iwbSVGLineAttributes); + iwbSVGItemsAttributes.insert(tIWBTspan, iwbSVGTspanAttributes); +} + +bool UBCFFAdaptor::UBToCFFConverter::parse() +{ + if(!isValid()) { + qDebug() << "document metadata is not valid. Can't parse"; + return false; + } + + qDebug() << "begin parsing ubz"; + + QFile outFile(contentIWBFileName()); + if (!outFile.open(QIODevice::WriteOnly| QIODevice::Text)) { + qDebug() << "can't open output file for writing"; + errorStr = "createXMLOutputPatternError"; + return false; + } + + mIWBContentWriter->setDevice(&outFile); + + mIWBContentWriter->writeStartDocument(); + mIWBContentWriter->writeStartElement(tIWBRoot); + + fillNamespaces(); + + mIWBContentWriter->writeAttribute(aIWBVersion, avIWBVersionNo); + + if (!parseMetadata()) { + if (errorStr == noErrorMsg) + errorStr = "MetadataParsingError"; + + outFile.close(); + return false; + } + + if (!parseContent()) { + if (errorStr == noErrorMsg) + errorStr = "ContentParsingError"; + outFile.close(); + return false; + } + + mIWBContentWriter->writeEndElement(); + mIWBContentWriter->writeEndDocument(); + + outFile.close(); + + qDebug() << "finished with success"; + + return true; +} +bool UBCFFAdaptor::UBToCFFConverter::parseMetadata() +{ + int errorLine, errorColumn; + QFile metaDataFile(sourcePath + "/" + fMetadata); + + if (!metaDataFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + errorStr = "can't open" + QFileInfo(sourcePath + "/" + fMetadata).absoluteFilePath(); + qDebug() << errorStr; + return false; + + } else if (!mDataModel->setContent(metaDataFile.readAll(), true, &errorStr, &errorLine, &errorColumn)) { + qWarning() << "Error:Parseerroratline" << errorLine << "," + << "column" << errorColumn << ":" << errorStr; + return false; + } + + QDomElement nextInElement = mDataModel->documentElement(); + + nextInElement = nextInElement.firstChildElement(tDescription); + if (!nextInElement.isNull()) { + + mIWBContentWriter->writeStartElement(iwbNS, tIWBMeta); + mIWBContentWriter->writeAttribute(aIWBName, aCreator); + mIWBContentWriter->writeAttribute(aIWBContent, avCreator); + mIWBContentWriter->writeEndElement(); + + mIWBContentWriter->writeStartElement(iwbNS, tIWBMeta); + mIWBContentWriter->writeAttribute(aIWBName, aOwner); + mIWBContentWriter->writeAttribute(aIWBContent, avOwner); + mIWBContentWriter->writeEndElement(); + + mIWBContentWriter->writeStartElement(iwbNS, tIWBMeta); + mIWBContentWriter->writeAttribute(aIWBName, aDescription); + mIWBContentWriter->writeAttribute(aIWBContent, avDescription); + mIWBContentWriter->writeEndElement(); + + mIWBContentWriter->writeStartElement(iwbNS, tIWBMeta); + mIWBContentWriter->writeAttribute(aIWBName, aAbout); + mIWBContentWriter->writeAttribute(aIWBContent, nextInElement.attribute(aAbout)); + mIWBContentWriter->writeEndElement(); + + nextInElement = nextInElement.firstChildElement(); + while (!nextInElement.isNull()) { + + QString textContent = nextInElement.text(); + if (!textContent.trimmed().isEmpty()) { + if (nextInElement.tagName() == tUBZSize) { //taking main viewbox rect since for CFF specificaton we have static viewbox + QSize tmpSize = getSVGDimentions(nextInElement.text()); + if (!tmpSize.isNull()) { + mSVGSize = tmpSize; + mViewbox.setRect(0,0, tmpSize.width(), tmpSize.height()); + } else { + qDebug() << "can't interpret svg section size"; + errorStr = "InterpretSvgSizeError"; + return false; + } + } else { + mIWBContentWriter->writeStartElement(iwbNS, tIWBMeta); + mIWBContentWriter->writeAttribute(aIWBName, nextInElement.tagName()); + mIWBContentWriter->writeAttribute(aIWBContent, textContent); + mIWBContentWriter->writeEndElement(); + } + + } + nextInElement = nextInElement.nextSiblingElement(); + } + } + + metaDataFile.close(); + return true; +} +bool UBCFFAdaptor::UBToCFFConverter::parseContent() { + + QDir sourceDir(sourcePath); + QStringList fileFilters; + fileFilters << QString(pageAlias + "???." + pageFileExtentionUBZ); + QStringList pageList = sourceDir.entryList(fileFilters, QDir::Files, QDir::Name | QDir::IgnoreCase); + + QDomElement svgDocumentSection = mDataModel->createElementNS(svgIWBNS, ":"+tSvg); + + if (!pageList.count()) { + qDebug() << "can't find any content file"; + errorStr = "ErrorContentFile"; + return false; + } else + { + QDomElement pageset = parsePageset(pageList); + if (pageset.isNull()) + return false; + else + svgDocumentSection.appendChild(pageset); + } + + + svgDocumentSection.setAttribute(aIWBViewBox, rectToIWBAttr(mViewbox)); + svgDocumentSection.setAttribute(aWidth, QString("%1").arg(mViewbox.width())); + svgDocumentSection.setAttribute(aHeight, QString("%1").arg(mViewbox.height())); + + + writeQDomElementToXML(svgDocumentSection); + + + if (!writeExtendedIwbSection()) { + if (errorStr == noErrorMsg) + errorStr = "writeExtendedIwbSectionError"; + return false; + } + + return true; +} + +QDomElement UBCFFAdaptor::UBToCFFConverter::parsePage(const QString &pageFileName) +{ + qDebug() << "begin parsing page" + pageFileName; + mSvgElements.clear(); //clean Svg elements map before parsing new page + + int errorLine, errorColumn; + + QFile pageFile(sourcePath + "/" + pageFileName); + if (!pageFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "can't open file" << pageFileName << "for reading"; + return QDomElement(); + } else if (!mDataModel->setContent(pageFile.readAll(), true, &errorStr, &errorLine, &errorColumn)) { + qWarning() << "Error:Parseerroratline" << errorLine << "," + << "column" << errorColumn << ":" << errorStr; + pageFile.close(); + return QDomElement(); + } + + QDomElement page; + QDomElement group; + + QDomElement nextTopElement = mDataModel->firstChildElement(); + while (!nextTopElement.isNull()) { + QString tagname = nextTopElement.tagName(); + if (tagname == tSvg) { + page = parseSvgPageSection(nextTopElement); + if (page.isNull()) { + qDebug() << "The page is empty."; + pageFile.close(); + return QDomElement(); + } + } else if (tagname == tUBZGroup) { + group = parseGroupPageSection(nextTopElement); + if (group.isNull()) { + qDebug() << "Page doesn't contains any groups."; + pageFile.close(); + return QDomElement(); + } + } + + nextTopElement = nextTopElement.nextSiblingElement(); + } + + pageFile.close(); + + return page.hasChildNodes() ? page : QDomElement(); +} + +QDomElement UBCFFAdaptor::UBToCFFConverter::parsePageset(const QStringList &pageFileNames) +{ + QMultiMap pageList; + int iPageNo = 1; + + QStringListIterator curPage(pageFileNames); + + while (curPage.hasNext()) { + + QString curPageFile = curPage.next(); + QDomElement iterElement = parsePage(curPageFile); + if (!iterElement.isNull()) + { + iterElement.setAttribute(tId, iPageNo); + addSVGElementToResultModel(iterElement, pageList, iPageNo); + iPageNo++; + } + else + return QDomElement(); + } + + + if (!pageList.count()) + return QDomElement(); + + + QDomElement svgPagesetElement = mDocumentToWrite->createElementNS(svgIWBNS,":"+ tIWBPageSet); + + QMapIterator nextSVGElement(pageList); + nextSVGElement.toFront(); + while (nextSVGElement.hasNext()) + svgPagesetElement.appendChild(nextSVGElement.next().value()); + + return svgPagesetElement.hasChildNodes() ? svgPagesetElement : QDomElement(); +} +QDomElement UBCFFAdaptor::UBToCFFConverter::parseSvgPageSection(const QDomElement &element) +{ + //we don't know about page number, so return QDomElement. + + //Parsing top level tag attributes + + //getting current page viewbox to be able to convert coordinates to global viewbox parameter + if (element.hasAttribute(aUBZViewBox)) { + setViewBox(getViewboxRect(element.attribute(aUBZViewBox))); + } + + QMultiMap svgElements; + + QDomElement svgElementPart = mDocumentToWrite->createElementNS(svgIWBNS,":"+ tIWBPage); + + if (element.hasAttribute(aDarkBackground)) { + createBackground(element, svgElements); + } + + //Parsing svg children attributes + // Elements can know about its layer, so it must add result QDomElements to ordrered list. + QDomElement nextElement = element.firstChildElement(); + while (!nextElement.isNull()) { + QString tagName = nextElement.tagName(); + if (tagName == tUBZG) parseSVGGGroup(nextElement, svgElements); + else if (tagName == tUBZImage) parseUBZImage(nextElement, svgElements); + else if (tagName == tUBZVideo) parseUBZVideo(nextElement, svgElements); + else if (tagName == tUBZAudio) parseUBZAudio(nextElement, svgElements); + else if (tagName == tUBZForeignObject) parseForeignObject(nextElement, svgElements); + else if (tagName == tUBZLine) parseUBZLine(nextElement, svgElements); + else if (tagName == tUBZPolygon) parseUBZPolygon(nextElement, svgElements); + else if (tagName == tUBZPolyline) parseUBZPolyline(nextElement, svgElements); + + nextElement = nextElement.nextSiblingElement(); + } + + if (0 == svgElements.count()) + return QDomElement(); + + // to do: + // there we must to sort elements (take elements from list and assign parent ordered like in parseSVGGGroup) + // we returns just element because we don't care about layer. + QMapIterator nextSVGElement(svgElements); + nextSVGElement.toFront(); + while (nextSVGElement.hasNext()) + svgElementPart.appendChild(nextSVGElement.next().value()); + + return svgElementPart.hasChildNodes() ? svgElementPart : QDomElement(); +} + +void UBCFFAdaptor::UBToCFFConverter::writeQDomElementToXML(const QDomNode &node) +{ + if (!node.isNull()) + if (node.isText()) + { + mIWBContentWriter->writeCharacters(node.nodeValue()); + } + else + { + mIWBContentWriter->writeStartElement(node.namespaceURI(), node.toElement().tagName()); + + for (int i = 0; i < node.toElement().attributes().count(); i++) + { + QDomAttr attr = node.toElement().attributes().item(i).toAttr(); + mIWBContentWriter->writeAttribute(attr.name(), attr.value()); + } + QDomNode child = node.firstChild(); + while(!child.isNull()) + { + writeQDomElementToXML(child); + child = child.nextSibling(); + } + + mIWBContentWriter->writeEndElement(); + } +} + +bool UBCFFAdaptor::UBToCFFConverter::writeExtendedIwbSection() +{ + if (!mExtendedElements.count()) { + qDebug() << "extended iwb content list is empty"; + errorStr = "EmptyExtendedIwbSectionContentError"; + return false; + } + QListIterator nextExtendedIwbElement(mExtendedElements); + while (nextExtendedIwbElement.hasNext()) { + writeQDomElementToXML(nextExtendedIwbElement.next()); + //TODO write iwb extended element to mIWBContentWriter + } + + return true; +} + +// extended element options +// editable, background, locked are supported for now + +QDomElement UBCFFAdaptor::UBToCFFConverter::parseGroupPageSection(const QDomElement &element) +{ +// First sankore side implementation needed. TODO in Sankore 1.5 + Q_UNUSED(element) + qDebug() << "parsing ubz group section"; + return QDomElement(); +} + +QString UBCFFAdaptor::UBToCFFConverter::getDstContentFolderName(const QString &elementType) +{ + QString sRet; + QString sDstContentFolderName; + + // widgets must be saved as .png images. + if ((tIWBImage == elementType) || (tUBZForeignObject == elementType)) + sDstContentFolderName = cfImages; + else + if (tIWBVideo == elementType) + sDstContentFolderName = cfVideos; + else + if (tIWBAudio == elementType) + sDstContentFolderName = cfAudios; + + sRet = sDstContentFolderName; + + return sRet; +} + +QString UBCFFAdaptor::UBToCFFConverter::getSrcContentFolderName(QString href) +{ + QString sRet; + + QStringList ls = href.split("/"); + for (int i = 0; i < ls.count()-1; i++) + { + QString sPart = ls.at(i); + if (ubzContentFolders.contains(sPart)) + { + sRet = sPart; + } + } + +// if (0 < ls.count()) +// sRet = ls.at(ls.count()-1); +// +// sRet = href.remove(sRet); +// +// if (sRet.endsWith("/")) +// sRet.remove("/"); + + return sRet; +} + +QString UBCFFAdaptor::UBToCFFConverter::getFileNameFromPath(const QString sPath) +{ + QString sRet; + QStringList sl = sPath.split("/",QString::SkipEmptyParts); + + if (0 < sl.count()) + { + QString name = sl.at(sl.count()-1); + QString extention = getExtentionFromFileName(name); + + if (feWgt == extention) + { + name.remove("{"); + name.remove("}"); + } + + name.remove(name.length()-extention.length(), extention.length()); + name += convertExtention(extention); + + sRet = name; + } + return sRet; +} + +QString UBCFFAdaptor::UBToCFFConverter::getExtentionFromFileName(const QString &filename) +{ + QStringList sl = filename.split("/",QString::SkipEmptyParts); + + if (0 < sl.count()) + { + QString name = sl.at(sl.count()-1); + QStringList tl = name.split("."); + return tl.at(tl.count()-1); + } + return QString(); +} + +QString UBCFFAdaptor::UBToCFFConverter::convertExtention(const QString &ext) +{ + QString sRet; + + if (feSvg == ext) + sRet = fePng; + else + if (feWgt == ext) + sRet = fePng; + else + sRet = ext; + + return sRet; +} + +QString UBCFFAdaptor::UBToCFFConverter::getElementTypeFromUBZ(const QDomElement &element) +{ + QString sRet; + if (tUBZForeignObject == element.tagName()) + { + QString sPath; + if (element.hasAttribute(aUBZType)) + { + if (avUBZText == element.attribute(aUBZType)) + sRet = tIWBTextArea; + else + sRet = element.attribute(aUBZType); + } + else + { + if (element.hasAttribute(aSrc)) + sPath = element.attribute(aSrc); + else + if (element.hasAttribute(aUBZHref)) + sPath = element.attribute(aUBZHref); + + QStringList tsl = sPath.split(".", QString::SkipEmptyParts); + if (0 < tsl.count()) + { + QString elementType = tsl.at(tsl.count()-1); + if (iwbElementImage.contains(elementType)) + sRet = tIWBImage; + else + if (iwbElementAudio.contains(elementType)) + sRet = tIWBAudio; + else + if (iwbElementVideo.contains(elementType)) + sRet = tIWBVideo; + } + } + } + else + sRet = element.tagName(); + + return sRet; +} + +int UBCFFAdaptor::UBToCFFConverter::getElementLayer(const QDomElement &element) +{ + int iRetLayer = 0; + if (element.hasAttribute(aZLayer)) + iRetLayer = (int)element.attribute(aZLayer).toDouble(); + else + iRetLayer = DEFAULT_LAYER; + + return iRetLayer; +} + +bool UBCFFAdaptor::UBToCFFConverter::itIsSupportedFormat(const QString &format) const +{ + bool bRet; + + QStringList tsl = format.split(".", QString::SkipEmptyParts); + if (0 < tsl.count()) + bRet = cffSupportedFileFormats.contains(tsl.at(tsl.count()-1)); + else + bRet = false; + + return bRet; +} + +bool UBCFFAdaptor::UBToCFFConverter::itIsFormatToConvert(const QString &format) const +{ + foreach (QString f, ubzFormatsToConvert.split(",")) + { + if (format == f) + return true; + } + return false; +} + +bool UBCFFAdaptor::UBToCFFConverter::itIsSVGElementAttribute(const QString ItemType, const QString &AttrName) +{ + QString allowedElementAttributes = iwbSVGItemsAttributes[ItemType]; + + allowedElementAttributes.remove("/t"); + allowedElementAttributes.remove(" "); + foreach(QString attr, allowedElementAttributes.split(",")) + { + if (AttrName == attr.trimmed()) + return true; + } + return false; +} + + +bool UBCFFAdaptor::UBToCFFConverter::itIsIWBAttribute(const QString &attribute) const +{ + foreach (QString attr, iwbElementAttributes.split(",")) + { + if (attribute == attr.trimmed()) + return true; + } + return false; +} + +bool UBCFFAdaptor::UBToCFFConverter::itIsUBZAttributeToConvert(const QString &attribute) const +{ + foreach (QString attr, ubzElementAttributesToConvert.split(",")) + { + if (attribute == attr.trimmed()) + return true; + } + return false; +} + +bool UBCFFAdaptor::UBToCFFConverter::ibwAddLine(int x1, int y1, int x2, int y2, QString color, int width, bool isBackground) +{ + bool bRet = true; + + QDomDocument doc; + + QDomElement svgBackgroundCrossPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":line"); + QDomElement iwbBackgroundCrossPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + QString sUUID = QUuid::createUuid().toString().remove("{").remove("}"); + + svgBackgroundCrossPart.setTagName(tIWBLine); + + svgBackgroundCrossPart.setAttribute(aX+"1", x1); + svgBackgroundCrossPart.setAttribute(aY+"1", y1); + svgBackgroundCrossPart.setAttribute(aX+"2", x2); + svgBackgroundCrossPart.setAttribute(aY+"2", y2); + + svgBackgroundCrossPart.setAttribute(aStroke, color); + svgBackgroundCrossPart.setAttribute(aStrokeWidth, width); + + svgBackgroundCrossPart.setAttribute(aID, sUUID); + + if (isBackground) + { + iwbBackgroundCrossPart.setAttribute(aRef, sUUID); + iwbBackgroundCrossPart.setAttribute(aLocked, avTrue); + + addIWBElementToResultModel(iwbBackgroundCrossPart); + } + + addSVGElementToResultModel(svgBackgroundCrossPart, mSvgElements, DEFAULT_BACKGROUND_CROSS_LAYER); + + if (!bRet) + { + qDebug() << "|error at creating crosses on background"; + errorStr = "CreatingCrossedBackgroundParsingError."; + } + + return bRet; +} + +QTransform UBCFFAdaptor::UBToCFFConverter::getTransformFromUBZ(const QDomElement &ubzElement) +{ + QTransform trRet; + + QStringList transformParameters; + + QString ubzTransform = ubzElement.attribute(aTransform); + ubzTransform.remove("matrix"); + ubzTransform.remove("("); + ubzTransform.remove(")"); + + transformParameters = ubzTransform.split(",", QString::SkipEmptyParts); + + if (6 <= transformParameters.count()) + { + QTransform *tr = NULL; + tr = new QTransform(transformParameters.at(0).toDouble(), + transformParameters.at(1).toDouble(), + transformParameters.at(2).toDouble(), + transformParameters.at(3).toDouble(), + transformParameters.at(4).toDouble(), + transformParameters.at(5).toDouble()); + + trRet = *tr; + + delete tr; + } + + if (6 <= transformParameters.count()) + { + QTransform *tr = NULL; + tr = new QTransform(transformParameters.at(0).toDouble(), + transformParameters.at(1).toDouble(), + transformParameters.at(2).toDouble(), + transformParameters.at(3).toDouble(), + transformParameters.at(4).toDouble(), + transformParameters.at(5).toDouble()); + + trRet = *tr; + + delete tr; + } + return trRet; +} + +qreal UBCFFAdaptor::UBToCFFConverter::getAngleFromTransform(const QTransform &tr) +{ + qreal angle = -(atan(tr.m21()/tr.m11())*180/PI); + if (tr.m21() > 0 && tr.m11() < 0) + angle += 180; + else + if (tr.m21() < 0 && tr.m11() < 0) + angle += 180; + return angle; +} + +void UBCFFAdaptor::UBToCFFConverter::setGeometryFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement) +{ + setCoordinatesFromUBZ(ubzElement,iwbElement); + + + +} + +void UBCFFAdaptor::UBToCFFConverter::setCoordinatesFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement) +{ + QTransform tr; + + if (QString() != ubzElement.attribute(aTransform)) + tr = getTransformFromUBZ(ubzElement); + + qreal x = ubzElement.attribute(aX).toDouble(); + qreal y = ubzElement.attribute(aY).toDouble(); + qreal height = ubzElement.attribute(aHeight).toDouble(); + qreal width = ubzElement.attribute(aWidth).toDouble(); + + qreal alpha = getAngleFromTransform(tr); + + QRectF itemRect; + QGraphicsRectItem item; + + item.setRect(0,0, width, height); + item.setTransform(tr); + + item.setTransformOriginPoint(item.boundingRect().center()); + item.setRotation(-alpha); + QMatrix sceneMatrix = item.sceneMatrix(); + + iwbElement.setAttribute(aX, x); + iwbElement.setAttribute(aY, y); + iwbElement.setAttribute(aHeight, height*sceneMatrix.m22()); + iwbElement.setAttribute(aWidth, width*sceneMatrix.m11()); + iwbElement.setAttribute(aTransform, QString("rotate(%1) translate(%2,%3)").arg(alpha) + .arg(sceneMatrix.dx()) + .arg(sceneMatrix.dy())); +} + +bool UBCFFAdaptor::UBToCFFConverter::setContentFromUBZ(const QDomElement &ubzElement, QDomElement &svgElement) +{ + bool bRet = true; + + QString srcPath; + if (tUBZForeignObject != ubzElement.tagName()) + srcPath = ubzElement.attribute(aUBZHref); + else + srcPath = ubzElement.attribute(aSrc); + + QString sSrcContentFolder = getSrcContentFolderName(srcPath); + QString sSrcFileName = sourcePath + "/" + srcPath ; + QString fileExtention = getExtentionFromFileName(sSrcFileName); + QString sDstContentFolder = getDstContentFolderName(ubzElement.tagName()); + QString sDstFileName(QString(QUuid::createUuid().toString()+"."+convertExtention(fileExtention)).remove("{").remove("}")); + + + if (itIsSupportedFormat(fileExtention)) // format is supported and we can copy src. files without changing. + { + sSrcFileName = sourcePath + "/" + sSrcContentFolder + "/" + getFileNameFromPath(srcPath); // some elements must be exported as images, so we take hes existing thumbnails. + + QFile srcFile; + srcFile.setFileName(sSrcFileName); + + QDir dstDocFolder(destinationPath); + + if (!dstDocFolder.exists(sDstContentFolder)) + bRet &= dstDocFolder.mkdir(sDstContentFolder); + + if (bRet) + { + QString dstFilePath = destinationPath+"/"+sDstContentFolder+"/"+sDstFileName; + bRet &= srcFile.copy(dstFilePath); + } + + if (bRet) + { + svgElement.setAttribute(aSVGHref, sDstContentFolder+"/"+sDstFileName); + svgElement.setAttribute(aSVGRequiredExtension, svgRequiredExtensionPrefix+convertExtention(fileExtention)); + } + } + else + if (itIsFormatToConvert(fileExtention)) // we cannot copy that source files. We need to create dst. file from src. file without copy. + { + if (feSvg == fileExtention) + { + QDir dstDocFolder(destinationPath); + + if (!dstDocFolder.exists(sDstContentFolder)) + bRet &= dstDocFolder.mkdir(sDstContentFolder); + + if (bRet) + { + if (feSvg == fileExtention) // svg images must be converted to PNG. + { + QString dstFilePath = destinationPath+"/"+sDstContentFolder+"/"+sDstFileName; + bRet &= createPngFromSvg(sSrcFileName, dstFilePath, getTransformFromUBZ(ubzElement)); + } + else + bRet = false; + } + + if (bRet) + { + svgElement.setAttribute(aSVGHref, sDstContentFolder+"/"+sDstFileName); + svgElement.setAttribute(aSVGRequiredExtension, svgRequiredExtensionPrefix+fePng); + } + } + } + + if (!bRet) + { + qDebug() << "format is not supported by CFF"; + } + + return bRet; +} + +void UBCFFAdaptor::UBToCFFConverter::setCFFTextFromHTMLTextNode(const QDomElement htmlTextNode, QDomElement &iwbElement) +{ + + QDomDocument textDoc; + + QDomElement textParentElement = iwbElement; + + QString textString; + QDomNode htmlPNode = htmlTextNode.firstChild(); + bool bTbreak = false; + + // reads HTML text strings - each string placed in separate

section + while(!htmlPNode.isNull()) + { + // add for split strings + if (bTbreak) + { + bTbreak = false; + + QDomElement tbreakNode = textDoc.createElementNS(svgIWBNS, svgIWBNSPrefix+":"+tIWBTbreak); + textParentElement.appendChild(tbreakNode.cloneNode(true)); + } + + QDomNode spanNode = htmlPNode.firstChild(); + + + while (!spanNode.isNull()) + { + if (spanNode.isText()) + { + QDomText nodeText = textDoc.createTextNode(spanNode.nodeValue()); + textParentElement.appendChild(nodeText.cloneNode(true)); + } + else + if (spanNode.isElement()) + { + QDomElement spanElement = textDoc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBTspan); + if (spanNode.hasAttributes()) + { + int attrCount = spanNode.attributes().count(); + if (0 < attrCount) + { + for (int i = 0; i < attrCount; i++) + { + // html attributes like: style="font-size:40pt; color:"red";". + QStringList cffAttributes = spanNode.attributes().item(i).nodeValue().split(";", QString::SkipEmptyParts); + { + for (int i = 0; i < cffAttributes.count(); i++) + { + QString attr = cffAttributes.at(i).trimmed(); + QStringList AttrVal = attr.split(":", QString::SkipEmptyParts); + if(1 < AttrVal.count()) + { + QString sAttr = ubzAttrNameToCFFAttrName(AttrVal.at(0)); + if (itIsSVGElementAttribute(spanElement.tagName(), sAttr)) + spanElement.setAttribute(sAttr, ubzAttrValueToCFFAttrName(AttrVal.at(1))); + } + } + } + } + } + } + QDomText nodeText = textDoc.createTextNode(spanNode.firstChild().nodeValue()); + spanElement.appendChild(nodeText); + textParentElement.appendChild(spanElement.cloneNode(true)); + } + spanNode = spanNode.nextSibling(); + } + + bTbreak = true; + htmlPNode = htmlPNode.nextSibling(); + } +} + +QString UBCFFAdaptor::UBToCFFConverter::ubzAttrNameToCFFAttrName(QString cffAttrName) +{ + QString sRet = cffAttrName; + if (QString("color") == cffAttrName) + sRet = QString("fill"); + + return sRet; +} +QString UBCFFAdaptor::UBToCFFConverter::ubzAttrValueToCFFAttrName(QString cffValue) +{ + QString sRet = cffValue; + if (QString("text") == cffValue) + sRet = QString("normal"); + + return sRet; +} + +bool UBCFFAdaptor::UBToCFFConverter::setCFFAttribute(const QString &attributeName, const QString &attributeValue, const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement) +{ + bool bRet = true; + bool bNeedsIWBSection = false; + + if (itIsIWBAttribute(attributeName)) + { + if (!((aBackground == attributeName) && (avFalse == attributeValue))) + { + iwbElement.setAttribute(attributeName, attributeValue); + bNeedsIWBSection = true; + } + } + else + if (itIsUBZAttributeToConvert(attributeName)) + { + if (aTransform == attributeName) + { + setGeometryFromUBZ(ubzElement, svgElement); + } + else + if (attributeName.contains(aUBZHref)||attributeName.contains(aSrc)) + { + bRet &= setContentFromUBZ(ubzElement, svgElement); + bNeedsIWBSection = bRet||bNeedsIWBSection; + } + } + else + if (itIsSVGElementAttribute(svgElement.tagName(),attributeName)) + { + svgElement.setAttribute(attributeName, attributeValue); + } + + if (bNeedsIWBSection) + { + if (0 < iwbElement.attributes().count()) + { + + QStringList tl = ubzElement.attribute(aSVGHref).split("/"); + QString id = tl.at(tl.count()-1); + // if element already have an ID, we use it. Else we create new id for element. + if (QString() == id) + id = QUuid::createUuid().toString().remove("{").remove("}"); + + svgElement.setAttribute(aID, id); + iwbElement.setAttribute(aRef, id); + } + } + + return bRet; +} + +bool UBCFFAdaptor::UBToCFFConverter::setCommonAttributesFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement) +{ + bool bRet = true; + + for (int i = 0; i < ubzElement.attributes().count(); i++) + { + QDomNode attribute = ubzElement.attributes().item(i); + QString attributeName = ubzAttrNameToCFFAttrName(attribute.nodeName().remove("ub:")); + + bRet &= setCFFAttribute(attributeName, ubzAttrValueToCFFAttrName(attribute.nodeValue()), ubzElement, iwbElement, svgElement); + if (!bRet) break; + } + return bRet; +} + +void UBCFFAdaptor::UBToCFFConverter::setViewBox(QRect viewbox) +{ + mViewbox |= viewbox; +} + +QDomNode UBCFFAdaptor::UBToCFFConverter::findTextNode(const QDomNode &node) +{ + QDomNode iterNode = node; + + while (!iterNode.isNull()) + { + if (iterNode.isText()) + { + if (!iterNode.isNull()) + return iterNode; + } + else + { + if (!iterNode.firstChild().isNull()) + { + QDomNode foundNode = findTextNode(iterNode.firstChild()); + if (!foundNode.isNull()) + if (foundNode.isText()) + return foundNode; + } + } + if (!iterNode.nextSibling().isNull()) + iterNode = iterNode.nextSibling(); + else + break; + } + return iterNode; +} + +QDomNode UBCFFAdaptor::UBToCFFConverter::findNodeByTagName(const QDomNode &node, QString tagName) +{ + QDomNode iterNode = node; + + while (!iterNode.isNull()) + { + QString t = iterNode.toElement().tagName(); + if (tagName == t) + return iterNode; + else + { + if (!iterNode.firstChildElement().isNull()) + { + QDomNode foundNode = findNodeByTagName(iterNode.firstChildElement(), tagName); + if (!foundNode.isNull()) + if (foundNode.isElement()) + { + if (tagName == foundNode.toElement().tagName()) + return foundNode; + } + else + break; + } + } + + if (!iterNode.nextSibling().isNull()) + iterNode = iterNode.nextSibling(); + else + break; + } + return QDomNode(); + +} + +bool UBCFFAdaptor::UBToCFFConverter::createBackground(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "|creating element background"; + + + QDomDocument doc; + + //QDomElement svgBackgroundElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tUBZImage); + QDomElement svgBackgroundElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBRect); + QDomElement iwbBackgroundElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + + QRect bckRect(mViewbox); + + if (0 <= mViewbox.topLeft().x()) + bckRect.topLeft().setX(0); + + if (0 <= mViewbox.topLeft().y()) + bckRect.topLeft().setY(0); + +// QString backgroundImagePath = createBackgroundImage(element, QSize(bckRect.width(), bckRect.height())); +// if (QString() != backgroundImagePath) + if (QRect() != bckRect) + { + QString sElementID = QUuid::createUuid().toString().remove("{").remove("}"); + + bool darkBackground = (avTrue == element.attribute(aDarkBackground)); + svgBackgroundElementPart.setAttribute(aFill, darkBackground ? "black" : "white"); + svgBackgroundElementPart.setAttribute(aID, sElementID); + svgBackgroundElementPart.setAttribute(aX, bckRect.x()); + svgBackgroundElementPart.setAttribute(aY, bckRect.y()); + svgBackgroundElementPart.setAttribute(aHeight, bckRect.height()); + svgBackgroundElementPart.setAttribute(aWidth, bckRect.width()); + + //svgBackgroundElementPart.setAttribute(aSVGHref, backgroundImagePath); + + iwbBackgroundElementPart.setAttribute(aRef, sElementID); + iwbBackgroundElementPart.setAttribute(aBackground, avTrue); + //iwbBackgroundElementPart.setAttribute(aLocked, avTrue); + + addSVGElementToResultModel(svgBackgroundElementPart, dstSvgList, DEFAULT_BACKGROUND_LAYER); + addIWBElementToResultModel(iwbBackgroundElementPart); + return true; + } + else + { + qDebug() << "|error at creating element background"; + errorStr = "CreatingElementBackgroundParsingError."; + return false; + } +} + +QString UBCFFAdaptor::UBToCFFConverter::createBackgroundImage(const QDomElement &element, QSize size) +{ + QString sRet; + + QString sDstFileName(fIWBBackground); + + bool bDirExists = true; + QDir dstDocFolder(destinationPath); + + if (!dstDocFolder.exists(cfImages)) + bDirExists &= dstDocFolder.mkdir(cfImages); + + QString dstFilePath; + if (bDirExists) + dstFilePath = destinationPath+"/"+cfImages+"/"+sDstFileName; + + if (!QFile().exists(dstFilePath)) + { + QRect rect(0,0, size.width(), size.height()); + + QImage *bckImage = new QImage(size, QImage::Format_RGB888); + + QPainter *painter = new QPainter(bckImage); + + bool darkBackground = (avTrue == element.attribute(aDarkBackground)); + + QColor bCrossColor; + + bCrossColor = darkBackground?QColor(Qt::white):QColor(Qt::blue); + int penAlpha = (int)(255/2); // default Sankore value for transform.m11 < 1 + bCrossColor.setAlpha(penAlpha); + painter->setPen(bCrossColor); + painter->setBrush(darkBackground?QColor(Qt::black):QColor(Qt::white)); + + painter->drawRect(rect); + + if (avTrue == element.attribute(aCrossedBackground)) + { + qreal firstY = ((int) (rect.y () / iCrossSize)) * iCrossSize; + + for (qreal yPos = firstY; yPos <= rect.y () + rect.height (); yPos += iCrossSize) + { + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + } + + qreal firstX = ((int) (rect.x () / iCrossSize)) * iCrossSize; + + for (qreal xPos = firstX; xPos <= rect.x () + rect.width (); xPos += iCrossSize) + { + painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); + } + } + + painter->end(); + painter->save(); + + if (QString() != dstFilePath) + if (bckImage->save(dstFilePath)) + sRet = cfImages+"/"+sDstFileName; + + delete bckImage; + delete painter; + } + else + sRet = cfImages+"/"+sDstFileName; + + return sRet; +} + +bool UBCFFAdaptor::UBToCFFConverter::createPngFromSvg(QString &svgPath, QString &dstPath, QTransform transformation, QSize size) +{ + if (QFile().exists(svgPath)) + { + QImage i(svgPath); + + QSize iSize = (QSize() == size)?QSize(i.size().width()*transformation.m11(), i.size().height()*transformation.m22()):size; + + QImage image(iSize, QImage::Format_ARGB32_Premultiplied); + image.fill(0); + QPainter imagePainter(&image); + QSvgRenderer renderer(svgPath); + renderer.render(&imagePainter); + + return image.save(dstPath); + + } + else + return false; +} + + +bool UBCFFAdaptor::UBToCFFConverter::parseSVGGGroup(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "|parsing g section"; + QDomElement nextElement = element.firstChildElement(); + if (nextElement.isNull()) { + qDebug() << "Empty g element"; + errorStr = "EmptyGSection"; + return false; + } + + QMultiMap svgElements; + + QDomDocument doc; + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBG); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + // Elements can know about its layer, so it must add result QDomElements to ordrered list. + while (!nextElement.isNull()) { + QString tagName = nextElement.tagName(); + if (tagName == tUBZLine) parseUBZLine(nextElement, svgElements); + else if (tagName == tUBZPolygon) parseUBZPolygon(nextElement, svgElements); + else if (tagName == tUBZPolyline) parseUBZPolyline(nextElement, svgElements); + + nextElement = nextElement.nextSiblingElement(); + } + + QList layers; + QMapIterator nextSVGElement(svgElements); + while (nextSVGElement.hasNext()) + layers << nextSVGElement.next().key(); + + qSort(layers); + int layer = layers.at(0); + + nextSVGElement.toFront(); + while (nextSVGElement.hasNext()) + svgElementPart.appendChild(nextSVGElement.next().value()); + + addSVGElementToResultModel(svgElementPart, dstSvgList, layer); + + return true; +} +bool UBCFFAdaptor::UBToCFFConverter::parseUBZImage(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "|parsing image"; + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + addSVGElementToResultModel(svgElementPart, dstSvgList, getElementLayer(element)); + + if (0 < iwbElementPart.attributes().count()) + addIWBElementToResultModel(iwbElementPart); + return true; + } + else + { + qDebug() << "|error at image parsing"; + errorStr = "ImageParsingError"; + return false; + + } +} + +bool UBCFFAdaptor::UBToCFFConverter::parseUBZVideo(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "|parsing video"; + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + QDomElement svgSwitchSection = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBSwitch); + svgSwitchSection.appendChild(svgElementPart); + + // if viewer cannot open that content - it must use that: + QDomElement svgText = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBTextArea); + svgText.setAttribute(aX, svgElementPart.attribute(aX)); + svgText.setAttribute(aY, svgElementPart.attribute(aY)); + svgText.setAttribute(aWidth, svgElementPart.attribute(aWidth)); + svgText.setAttribute(aHeight, svgElementPart.attribute(aHeight)); + svgText.setAttribute(aTransform, svgElementPart.attribute(aTransform)); + + QDomText text = doc.createTextNode("Cannot Open Content"); + svgText.appendChild(text); + + svgSwitchSection.appendChild(svgText); + + addSVGElementToResultModel(svgSwitchSection, dstSvgList, getElementLayer(element)); + + if (0 < iwbElementPart.attributes().count()) + addIWBElementToResultModel(iwbElementPart); + return true; + } + else + { + qDebug() << "|error at video parsing"; + errorStr = "VideoParsingError"; + return false; + } +} + +bool UBCFFAdaptor::UBToCFFConverter::parseUBZAudio(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "|parsing audio"; + + // audio file must be linked to cff item excluding video. + // to do: + // 1 add image for audio element. + // 2 set id for this element + // 3 add section with xlink:href to audio file + // 4 add shild to a section with id of the image + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + //we must create image-containers for audio files + int audioImageDimention = qMin(svgElementPart.attribute(aWidth).toInt(), svgElementPart.attribute(aHeight).toInt()); + QString srcAudioImageFile(sAudioElementImage); + QString elementId = QString(QUuid::createUuid().toString()).remove("{").remove("}"); + QString sDstAudioImageFileName = elementId+"."+fePng; + QString dstAudioImageFilePath = destinationPath+"/"+cfImages+"/"+sDstAudioImageFileName; + QString dstAudioImageRelativePath = cfImages+"/"+sDstAudioImageFileName; + + QFile srcFile(srcAudioImageFile); + + //creating folder for audioImage + QDir dstDocFolder(destinationPath); + bool bRes = true; + if (!dstDocFolder.exists(cfImages)) + bRes &= dstDocFolder.mkdir(cfImages); + + // CFF cannot show SVG images, so we need to convert it to png. + if (bRes && createPngFromSvg(srcAudioImageFile, dstAudioImageFilePath, getTransformFromUBZ(element), QSize(audioImageDimention, audioImageDimention))) + { + QDomElement svgSwitchSection = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBSwitch); + + // first we place content + QDomElement svgASection = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBA); + svgASection.setAttribute(aSVGHref, svgElementPart.attribute(aSVGHref)); + + svgElementPart.setTagName(tIWBImage); + svgElementPart.setAttribute(aSVGHref, dstAudioImageRelativePath); + svgElementPart.setAttribute(aHeight, audioImageDimention); + svgElementPart.setAttribute(aWidth, audioImageDimention); + + svgASection.appendChild(svgElementPart); + + svgSwitchSection.appendChild(svgASection); + + // if viewer cannot open that content - it must use that: + QDomElement svgText = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + tIWBTextArea); + svgText.setAttribute(aX, svgElementPart.attribute(aX)); + svgText.setAttribute(aY, svgElementPart.attribute(aY)); + svgText.setAttribute(aWidth, svgElementPart.attribute(aWidth)); + svgText.setAttribute(aHeight, svgElementPart.attribute(aHeight)); + svgText.setAttribute(aTransform, svgElementPart.attribute(aTransform)); + + QDomText text = doc.createTextNode("Cannot Open Content"); + svgText.appendChild(text); + + svgSwitchSection.appendChild(svgText); + + addSVGElementToResultModel(svgSwitchSection, dstSvgList, getElementLayer(element)); + + if (0 < iwbElementPart.attributes().count()) + addIWBElementToResultModel(iwbElementPart); + return true; + } + return false; + } + else + { + qDebug() << "|error at audio parsing"; + errorStr = "AudioParsingError"; + return false; + } +} + +bool UBCFFAdaptor::UBToCFFConverter::parseForeignObject(const QDomElement &element, QMultiMap &dstSvgList) +{ + + if (element.attribute(aUBZType) == avUBZText) { + return parseUBZText(element, dstSvgList); + } + + qDebug() << "|parsing foreign object"; + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + addSVGElementToResultModel(svgElementPart, dstSvgList, getElementLayer(element)); + if (0 < iwbElementPart.attributes().count()) + addIWBElementToResultModel(iwbElementPart); + return true; + } + else + { + qDebug() << "|error at parsing foreign object"; + errorStr = "ForeignObjectParsingError"; + return false; + } +} + +bool UBCFFAdaptor::UBToCFFConverter::parseUBZText(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "|parsing text"; + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (element.hasChildNodes()) + { + QDomDocument htmlDoc; + htmlDoc.setContent(findTextNode(element).nodeValue()); + QDomNode bodyNode = findNodeByTagName(htmlDoc.firstChildElement(), "body"); + + setCFFTextFromHTMLTextNode(bodyNode.toElement(), svgElementPart); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + QString commonParams; + for (int i = 0; i < bodyNode.attributes().count(); i++) + { + commonParams += " " + bodyNode.attributes().item(i).nodeValue(); + } + commonParams.remove(" "); + commonParams.remove("'"); + + QStringList commonAttributes = commonParams.split(";", QString::SkipEmptyParts); + for (int i = 0; i < commonAttributes.count(); i++) + { + QStringList AttrVal = commonAttributes.at(i).split(":", QString::SkipEmptyParts); + if (1 < AttrVal.count()) + { + QString sAttr = ubzAttrNameToCFFAttrName(AttrVal.at(0)); + QString sVal = ubzAttrValueToCFFAttrName(AttrVal.at(1)); + + setCFFAttribute(sAttr, sVal, element, iwbElementPart, svgElementPart); + } + } + addSVGElementToResultModel(svgElementPart, dstSvgList, getElementLayer(element)); + if (0 < iwbElementPart.attributes().count()) + addIWBElementToResultModel(iwbElementPart); + return true; + } + return false; + } + else + { + qDebug() << "|error at text parsing"; + errorStr = "TextParsingError"; + return false; + } +} + +bool UBCFFAdaptor::UBToCFFConverter::parseUBZPolygon(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "||parsing polygon"; + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + addSVGElementToResultModel(svgElementPart, dstSvgList, getElementLayer(element)); + + if (0 < iwbElementPart.attributes().count()) + { + QString id = QUuid::createUuid().toString().remove("{").remove("}"); + svgElementPart.setAttribute(aID, id); + iwbElementPart.setAttribute(aRef, id); + + addIWBElementToResultModel(iwbElementPart); + } + return true; + } + else + { + qDebug() << "||error at parsing polygon"; + errorStr = "PolygonParsingError"; + return false; + } + +} + +bool UBCFFAdaptor::UBToCFFConverter::parseUBZPolyline(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "||parsing polyline"; + QDomElement resElement; + + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + addSVGElementToResultModel(svgElementPart, dstSvgList, getElementLayer(element)); + + if (0 < iwbElementPart.attributes().count()) + { + QString id = QUuid::createUuid().toString().remove("{").remove("}"); + svgElementPart.setAttribute(aID, id); + iwbElementPart.setAttribute(aRef, id); + + addIWBElementToResultModel(iwbElementPart); + } + return true; + } + else + { + qDebug() << "||error at parsing polygon"; + errorStr = "PolylineParsingError"; + return false; + } + +} + +bool UBCFFAdaptor::UBToCFFConverter::parseUBZLine(const QDomElement &element, QMultiMap &dstSvgList) +{ + qDebug() << "||parsing line"; + QDomElement resElement; + QDomDocument doc; + + QDomElement svgElementPart = doc.createElementNS(svgIWBNS,svgIWBNSPrefix + ":" + getElementTypeFromUBZ(element)); + QDomElement iwbElementPart = doc.createElementNS(iwbNS,iwbNsPrefix + ":" + tElement); + + if (setCommonAttributesFromUBZ(element, iwbElementPart, svgElementPart)) + { + addSVGElementToResultModel(svgElementPart, dstSvgList, getElementLayer(element)); + + if (0 < iwbElementPart.attributes().count()) + { + QString id = QUuid::createUuid().toString().remove("{").remove("}"); + svgElementPart.setAttribute(aID, id); + iwbElementPart.setAttribute(aRef, id); + + addIWBElementToResultModel(iwbElementPart); + } + } + else + { + qDebug() << "||error at parsing polygon"; + errorStr = "LineParsingError"; + return false; + } + return true; +} + +void UBCFFAdaptor::UBToCFFConverter::addSVGElementToResultModel(const QDomElement &element, QMultiMap &dstList, int layer) +{ + int elementLayer = (DEFAULT_LAYER == layer) ? DEFAULT_LAYER : layer; + dstList.setInsertInOrder(true); + QDomElement rootElement = element.cloneNode(true).toElement(); + mDocumentToWrite->firstChildElement().appendChild(rootElement); + dstList.insert(elementLayer, rootElement); +} + +void UBCFFAdaptor::UBToCFFConverter::addIWBElementToResultModel(const QDomElement &element) +{ + QDomElement rootElement = element.cloneNode(true).toElement(); + mDocumentToWrite->firstChildElement().appendChild(rootElement); + mExtendedElements.append(rootElement); +} + +UBCFFAdaptor::UBToCFFConverter::~UBToCFFConverter() +{ + if (mDataModel) + delete mDataModel; + if (mIWBContentWriter) + delete mIWBContentWriter; +} +bool UBCFFAdaptor::UBToCFFConverter::isValid() const +{ + bool result = QFileInfo(sourcePath).exists() + && QFileInfo(sourcePath).isDir() + && errorStr == noErrorMsg; + + if (!result) { + qDebug() << "specified data is not valid"; + errorStr = "ValidateDataError"; + } + + return result; +} + +void UBCFFAdaptor::UBToCFFConverter::fillNamespaces() +{ + mIWBContentWriter->writeDefaultNamespace(svgUBZNS); + mIWBContentWriter->writeNamespace(iwbNS, iwbNsPrefix); + mIWBContentWriter->writeNamespace(svgIWBNS, svgIWBNSPrefix); + mIWBContentWriter->writeNamespace(xlinkNS, xlinkNSPrefix); +} + +QString UBCFFAdaptor::UBToCFFConverter::digitFileFormat(int digit) const +{ + return QString("%1").arg(digit, 3, 10, QLatin1Char('0')); +} +QString UBCFFAdaptor::UBToCFFConverter::contentIWBFileName() const +{ + return destinationPath + "/" + fIWBContent; +} + +//setting SVG dimenitons +QSize UBCFFAdaptor::UBToCFFConverter::getSVGDimentions(const QString &element) +{ + + QStringList dimList; + + dimList = element.split(dimensionsDelimiter1, QString::KeepEmptyParts); + if (dimList.count() != 2) // row unlike 0x0 + return QSize(); + + bool ok; + + int width = dimList.takeFirst().toInt(&ok); + if (!ok || !width) + return QSize(); + + int height = dimList.takeFirst().toInt(&ok); + if (!ok || !height) + return QSize(); + + return QSize(width, height); +} + +//Setting viewbox rectangle +QRect UBCFFAdaptor::UBToCFFConverter::getViewboxRect(const QString &element) const +{ + QStringList dimList; + + dimList = element.split(dimensionsDelimiter2, QString::KeepEmptyParts); + if (dimList.count() != 4) // row unlike 0 0 0 0 + return QRect(); + + bool ok = false; + + int x = dimList.takeFirst().toInt(&ok); + if (!ok || !x) + return QRect(); + + int y = dimList.takeFirst().toInt(&ok); + if (!ok || !y) + return QRect(); + + int width = dimList.takeFirst().toInt(&ok); + if (!ok || !width) + return QRect(); + + int height = dimList.takeFirst().toInt(&ok); + if (!ok || !height) + return QRect(); + + return QRect(x, y, width, height); +} + +QString UBCFFAdaptor::UBToCFFConverter::rectToIWBAttr(const QRect &rect) const +{ + if (rect.isNull()) return QString(); + + return QString("%1 %2 %3 %4").arg(rect.topLeft().x()) + .arg(rect.topLeft().y()) + .arg(rect.width()) + .arg(rect.height()); +} + +UBCFFAdaptor::UBToUBZConverter::UBToUBZConverter() +{ + +} diff --git a/plugins/cffadaptor/src/UBCFFAdaptor.h b/plugins/cffadaptor/src/UBCFFAdaptor.h new file mode 100644 index 00000000..385df3cc --- /dev/null +++ b/plugins/cffadaptor/src/UBCFFAdaptor.h @@ -0,0 +1,146 @@ +#ifndef UBCFFADAPTOR_H +#define UBCFFADAPTOR_H + +#include "UBCFFAdaptor_global.h" + +#include + +class QTransform; +class QDomDocument; +class QDomElement; +class QDomNode; +class QuaZipFile; + +class UBCFFADAPTORSHARED_EXPORT UBCFFAdaptor { + class UBToCFFConverter; + +public: + UBCFFAdaptor(); + ~UBCFFAdaptor(); + + bool convertUBZToIWB(const QString &from, const QString &to); + bool deleteDir(const QString& pDirPath) const; + +private: + QString uncompressZip(const QString &zipFile); + bool compressZip(const QString &source, const QString &destination); + bool compressDir(const QString &dirName, const QString &parentDir, QuaZipFile *outZip); + bool compressFile(const QString &fileName, const QString &parentDir, QuaZipFile *outZip); + + QString createNewTmpDir(); + bool freeDir(const QString &dir); + void freeTmpDirs(); + +private: + QStringList tmpDirs; + +private: + + class UBToCFFConverter { + + static const int DEFAULT_LAYER = -100000; + + public: + UBToCFFConverter(const QString &source, const QString &destination); + ~UBToCFFConverter(); + bool isValid() const; + QString lastErrStr() const {return errorStr;} + bool parse(); + + private: + void fillNamespaces(); + + bool parseMetadata(); + bool parseContent(); + QDomElement parsePageset(const QStringList &pageFileNames); + QDomElement parsePage(const QString &pageFileName); + QDomElement parseSvgPageSection(const QDomElement &element); + void writeQDomElementToXML(const QDomNode &node); + bool writeExtendedIwbSection(); + QDomElement parseGroupPageSection(const QDomElement &element); + + bool createBackground(const QDomElement &element, QMultiMap &dstSvgList); + QString createBackgroundImage(const QDomElement &element, QSize size); + bool createPngFromSvg(QString &svgPath, QString &dstPath, QTransform transformation, QSize size = QSize()); + + bool parseSVGGGroup(const QDomElement &element, QMultiMap &dstSvgList); + bool parseUBZImage(const QDomElement &element, QMultiMap &dstSvgList); + bool parseUBZVideo(const QDomElement &element, QMultiMap &dstSvgList); + bool parseUBZAudio(const QDomElement &element, QMultiMap &dstSvgList); + bool parseForeignObject(const QDomElement &element, QMultiMap &dstSvgList); + bool parseUBZText(const QDomElement &element, QMultiMap &dstSvgList); + + bool parseUBZPolygon(const QDomElement &element, QMultiMap &dstSvgList); + bool parseUBZPolyline(const QDomElement &element, QMultiMap &dstSvgList); + bool parseUBZLine(const QDomElement &element, QMultiMap &dstSvgList); + void addSVGElementToResultModel(const QDomElement &element, QMultiMap &dstList, int layer = DEFAULT_LAYER); + void addIWBElementToResultModel(const QDomElement &element); + + qreal getAngleFromTransform(const QTransform &tr); + QString getDstContentFolderName(const QString &elementType); + QString getSrcContentFolderName(QString href); + QString getFileNameFromPath(QString sPath); + QString getExtentionFromFileName(const QString &filename); + QString convertExtention(const QString &ext); + QString getElementTypeFromUBZ(const QDomElement &element); + + int getElementLayer(const QDomElement &element); + + bool itIsSupportedFormat(const QString &format) const; + bool itIsFormatToConvert(const QString &format) const; + bool itIsSVGElementAttribute(const QString ItemType, const QString &AttrName); + bool itIsIWBAttribute(const QString &attribute) const; + bool itIsUBZAttributeToConvert(const QString &attribute) const; + + bool ibwAddLine(int x1, int y1, int x2, int y2, QString color=QString(), int width=1, bool isBackground=false); + + QTransform getTransformFromUBZ(const QDomElement &ubzElement); + void setGeometryFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement); + void setCoordinatesFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement); + bool setContentFromUBZ(const QDomElement &ubzElement, QDomElement &svgElement); + void setCFFTextFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement); + void setCFFTextFromHTMLTextNode(const QDomElement htmlTextNode, QDomElement &iwbElement); + QString ubzAttrNameToCFFAttrName(QString cffAttrName); + QString ubzAttrValueToCFFAttrName(QString cffAttrValue); + + bool setCFFAttribute(const QString &attributeName, const QString &attributeValue, const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement); + bool setCommonAttributesFromUBZ(const QDomElement &ubzElement, QDomElement &iwbElement, QDomElement &svgElement); + void setViewBox(QRect viewbox); + + QDomNode findTextNode(const QDomNode &node); + QDomNode findNodeByTagName(const QDomNode &node, QString tagName); + + QSize getSVGDimentions(const QString &element); + + inline QRect getViewboxRect(const QString &element) const; + inline QString rectToIWBAttr(const QRect &rect) const; + inline QString digitFileFormat(int num) const; + inline bool strToBool(const QString &in) const {return in == "true";} + QString contentIWBFileName() const; + + private: + QMap iwbSVGItemsAttributes; + QDomDocument *mDataModel; //model for reading indata + QXmlStreamWriter *mIWBContentWriter; //stream to write outdata + QSize mSVGSize; //svg page size + QRect mViewbox; //Main viewbox parameter for CFF + QString sourcePath; // dir with unpacked source data (ubz) + QString destinationPath; //dir with unpacked destination data (iwb) + QDomDocument *mDocumentToWrite; //document for saved QDomElements from mSvgElements and mExtendedElements + QMultiMap mSvgElements; //Saving svg elements to have a sorted by z order list of elements to write; + QList mExtendedElements; //Saving extended options of elements to be able to add them to the end of result iwb document; + mutable QString errorStr; // last error string message + + public: + operator bool() const {return isValid();} + }; + + class UBToUBZConverter { + public: + UBToUBZConverter(); + }; + + +}; + +#endif // UBCFFADAPTOR_H diff --git a/plugins/cffadaptor/src/UBCFFAdaptor_global.h b/plugins/cffadaptor/src/UBCFFAdaptor_global.h new file mode 100644 index 00000000..2fbf871f --- /dev/null +++ b/plugins/cffadaptor/src/UBCFFAdaptor_global.h @@ -0,0 +1,12 @@ +#ifndef UBCFFADAPTOR_GLOBAL_H +#define UBCFFADAPTOR_GLOBAL_H + +#include + +#if defined(UBCFFADAPTOR_LIBRARY) +# define UBCFFADAPTORSHARED_EXPORT Q_DECL_EXPORT +#else +# define UBCFFADAPTORSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // UBCFFADAPTOR_GLOBAL_H diff --git a/plugins/cffadaptor/src/UBCFFConstants.h b/plugins/cffadaptor/src/UBCFFConstants.h new file mode 100644 index 00000000..9d7707ee --- /dev/null +++ b/plugins/cffadaptor/src/UBCFFConstants.h @@ -0,0 +1,378 @@ +#ifndef UBCFFCONSTANTS_H +#define UBCFFCONSTANTS_H + +#define PI 3.1415926535 + +const int DEFAULT_BACKGROUND_LAYER = -20000002; +const int DEFAULT_BACKGROUND_CROSS_LAYER = -20000001; + +// Constant names. Use only them instead const char* in each function + +// Constant fileNames; +const QString fMetadata = "metadata.rdf"; +const QString fIWBContent = "content.xml"; +const QString fIWBBackground = "background.png"; +const QString sAudioElementImage = ":images/soundOn.svg"; + +// Constant messages; +const QString noErrorMsg = "NoError"; + +// Tag names +const QString tDescription = "Description"; +const QString tIWBRoot = "iwb"; +const QString tIWBMeta = "meta"; +const QString tUBZSize = "size"; +const QString tSvg = "svg"; +const QString tIWBPage = "page"; +const QString tIWBPageSet = "pageset"; +const QString tId = "id"; +const QString tElement = "element"; +const QString tUBZGroup = "group"; +const QString tUBZG = "g"; +const QString tUBZPolygon = "polygon"; +const QString tUBZPolyline = "polyline"; +const QString tUBZLine = "line"; +const QString tUBZAudio = "audio"; +const QString tUBZVideo = "video"; +const QString tUBZImage = "image"; +const QString tUBZForeignObject = "foreignObject"; +const QString tUBZTextContent = "itemTextContent"; + +const QString tIWBA = "a"; +const QString tIWBG = "g"; +const QString tIWBSwitch = "switch"; +const QString tIWBImage = "image"; +const QString tIWBVideo = "video"; +const QString tIWBAudio = "audio"; +const QString tIWBText = "text"; +const QString tIWBTextArea = "textarea"; +const QString tIWBPolyLine = "polyline"; +const QString tIWBPolygon = "polygon"; +const QString tIWBFlash = "video"; +const QString tIWBRect = "rect"; +const QString tIWBLine = "line"; +const QString tIWBTbreak = "tbreak"; +const QString tIWBTspan = "tspan"; + +// Attributes names +const QString aIWBVersion = "version"; +const QString aOwner = "owner"; +const QString aDescription = "description"; +const QString aCreator = "creator"; +const QString aAbout = "about"; +const QString aIWBViewBox = "viewbox"; +const QString aUBZViewBox = "viewBox"; +const QString aDarkBackground = "dark-background"; +const QString aBackground = "background"; +const QString aCrossedBackground = "crossed-background"; +const QString aUBZType = "type"; +const QString aUBZUuid = "uuid"; +const QString aFill = "fill"; // IWB attribute contans color to fill + +const QString aID = "id"; // ID of any svg element can be placed in to iwb section +const QString aRef = "ref"; // as reference for applying additional attributes +const QString aSVGHref = "xlink:href"; // reference to file +const QString aIWBHref = "ref"; // reference to element ID +const QString aUBZHref = "href"; +const QString aSrc = "src"; +const QString aSVGRequiredExtension = "requiredExtensions"; + +const QString aX = "x"; +const QString aY = "y"; +const QString aWidth = "width"; +const QString aHeight = "height"; +const QString aStroke = "stroke"; +const QString aStrokeWidth = "stroke-width"; +const QString aPoints = "points"; +const QString aZLayer = "z-value"; +const QString aLayer = "layer"; +const QString aTransform = "transform"; +const QString aLocked = "locked"; +const QString aIWBName = "name"; +const QString aIWBContent = "content"; + + +// Attribute values +const QString avIWBVersionNo = "1.0"; +const QString avUBZText = "text"; +const QString avFalse = "false"; +const QString avTrue = "true"; + +// Namespaces and prefixes +const QString svgRequiredExtensionPrefix = "http://www.imsglobal.org/iwb/"; +const QString dcNS = "http://purl.org/dc/elements/1.1/"; +const QString ubNS = "http://uniboard.mnemis.com/document"; +const QString svgUBZNS = "http://www.imsglobal.org/xsd/iwb_v1p0"; +const QString svgIWBNS = "http://www.w3.org/2000/svg"; +const QString xlinkNS = "http://www.w3.org/1999/xlink"; +const QString iwbNS = "http://www.becta.org.uk/iwb"; +const QString xsiNS = "http://www.w3.org/2001/XMLSchema-instance"; +const QString xsiShemaLocation = "\ +http://www.imsglobal.org/xsd/iwb_v1p0 \ +http://www.imsglobal.org/profile/iwb/iwbv1p0_v1p0.xsd \ +http://www.w3.org/2000/svg http://www.imsglobal.org/profile/iwb/svgsubsetv1p0_v1p0.xsd \ +http://www.w3.org/1999/xlink http://www.imsglobal.org/xsd/w3/1999/xlink.xsd"; +const QString dcNSPrefix = "dc"; +const QString ubNSPrefix = "ub"; +const QString svgIWBNSPrefix = "svg"; +const QString xlinkNSPrefix = "xlink"; +const QString iwbNsPrefix = "iwb"; +const QString xsiPrefix = "xsi"; +const QString xsiSchemaLocationPrefix = "schemaLocation"; + +const QString avOwner = ""; +const QString avCreator = ""; +const QString avDescription = ""; + +//constant symbols and words etc +const QString dimensionsDelimiter1 = "x"; +const QString dimensionsDelimiter2 = " "; +const QString pageAlias = "page"; +const QString pageFileExtentionUBZ = "svg"; + +//content folder names +const QString cfImages = "images"; +const QString cfVideos = "video"; +const QString cfAudios = "audio"; +const QString cfFlash = "flash"; + +//known file extentions +const QString feSvg = "svg"; +const QString feWgt = "wgt"; +const QString fePng = "png"; + +const int iCrossSize = 32; +const int iCrossWidth = 1; + +// Image formats supported by CFF exclude wgt. Wgt is Sankore widget, which is considered as a .png preview. +const QString iwbElementImage(" \ +wgt, \ +jpeg, \ +jpg, \ +bmp, \ +gif, \ +wmf, \ +emf, \ +png, \ +tif, \ +tiff \ +"); + +// Video formats supported by CFF +const QString iwbElementVideo(" \ +mpg, \ +mpeg, \ +swf, \ +"); + +// Audio formats supported by CFF +const QString iwbElementAudio(" \ +mp3, \ +wav \ +"); + +const QString cffSupportedFileFormats(iwbElementImage + iwbElementVideo + iwbElementAudio); +const QString ubzFormatsToConvert("svg"); + + +const QString iwbSVGImageAttributes(" \ +id, \ +xlink:href, \ +x, \ +y, \ +height, \ +width, \ +fill-opacity, \ +requiredExtentions, \ +transform \ +"); + + +const QString iwbSVGAudioAttributes(" \ +id, \ +xlink:href, \ +x, \ +y, \ +height, \ +width, \ +fill-opacity, \ +requiredExtentions, \ +transform \ +"); + +const QString iwbSVGVideoAttributes(" \ +id, \ +xlink:href, \ +x, \ +y, \ +height, \ +width, \ +fill-opacity, \ +requiredExtentions, \ +transform \ +"); + +const QString iwbSVGRectAttributes(" \ +id, \ +x, \ +y, \ +height, \ +width, \ +fill, \ +fill-opacity, \ +stroke, \ +stroke-dasharray, \ +stroke-linecap, \ +stroke-linejoin, \ +stroke-opacity, \ +stroke-width, \ +transform \ +"); + + + +const QString iwbSVGTextAttributes(" \ +id, \ +x, \ +y, \ +fill, \ +font-family, \ +font-size, \ +font-style, \ +font-weight, \ +font-stretch, \ +transform \ +"); + +const QString iwbSVGTextAreaAttributes(" \ +id, \ +x, \ +y, \ +height, \ +width, \ +fill, \ +font-family, \ +font-size, \ +font-style, \ +font-weight, \ +font-stretch, \ +text-align, \ +transform \ +"); + +const QString iwbSVGTspanAttributes(" \ +id, \ +fill, \ +font-family, \ +font-size, \ +font-style, \ +font-weight, \ +font-stretch, \ +text-align, \ +"); + +const QString iwbSVGLineAttributes(" \ +id, \ +x1, \ +y1, \ +x2, \ +y2, \ +stroke, \ +stroke-dasharray, \ +stroke-width, \ +stroke-opacity, \ +stroke-linecap, \ +transform \ +"); + +const QString iwbSVGPolyLineAttributes(" \ +id, \ +points, \ +stroke, \ +stroke-width, \ +stroke-dasharray, \ +stroke-opacity, \ +stroke-linecap, \ +transform \ +"); + +const QString iwbSVGPolygonAttributes(" \ +id, \ +points, \ +fill, \ +fill-opacity, \ +stroke, \ +stroke-dasharray, \ +stroke-width, \ +stroke-linecap, \ +stroke-linejoin, \ +stroke-opacity, \ +stroke-width, \ +transform \ +"); + +// 1 to 1 copy to SVG section +const QString iwbElementAttributes(" \ +background, \ +background-fill, \ +background-posture, \ +flip, \ +freehand, \ +highlight, \ +highlight-fill, \ +list-style-type, \ +list-style-type-fill, \ +locked, \ +replicate, \ +revealer, \ +stroke-lineshape-start, \ +stroke-lineshape-end \ +"); + +// cannot be copied 1 to 1 to SVG section +const QString ubzElementAttributesToConvert(" \ +xlink:href, \ +src, \ +transform \ +"); + +// additional attributes. Have references in SVG section. +const QString svgElementAttributes(" \ +points, \ +fill, \ +fill-opacity, \ +stroke, \ +stroke-dasharray, \ +stroke-linecap, \ +stroke-opacity, \ +stroke-width, \ +stroke_linejoin, \ +requiredExtensions, \ +viewbox, \ +x, \ +y, \ +x1, \ +y1, \ +x2, \ +y2, \ +height, \ +width, \ +font-family, \ +font-size, \ +font-style, \ +font-weight, \ +font-stretch, \ +text-align \ +"); + +const QString ubzContentFolders("audios,videos,images,widgets"); + +struct UBItemLayerType +{ + enum Enum + { + FixedBackground = -2000, Object = -1000, Graphic = 0, Tool = 1000, Control = 2000 + }; +}; + +#endif // UBCFFCONSTANTS_H \ No newline at end of file diff --git a/plugins/cffadaptor/src/UBGlobals.h b/plugins/cffadaptor/src/UBGlobals.h new file mode 100644 index 00000000..adfc677d --- /dev/null +++ b/plugins/cffadaptor/src/UBGlobals.h @@ -0,0 +1,47 @@ +#ifndef UBGLOBALS_H +#define UBGLOBALS_H + +#define DELETEPTR(ptr) if(NULL != ptr){ \ + delete ptr; \ + ptr = NULL; \ + } + +#ifdef Q_WS_WIN + +#define WARNINGS_DISABLE __pragma(warning(push, 0)); +#define WARNINGS_ENABLE __pragma(warning(pop)); + +#ifdef NO_THIRD_PARTY_WARNINGS +// disabling warning level to 0 and save old state +#define THIRD_PARTY_WARNINGS_DISABLE WARNINGS_DISABLE +#else +// just save old state (needs for not empty define) +#define THIRD_PARTY_WARNINGS_DISABLE __pragma(warning(push)); +#endif //#ifdef NO_THIRD_PARTY_WARNINGS +// anyway on WIN +#define THIRD_PARTY_WARNINGS_ENABLE WARNINGS_ENABLE + +#else //#ifdef Q_WS_WIN + +#define WARNINGS_DISABLE _Pragma("GCC diagnostic push"); \ +_Pragma("GCC diagnostic ignored \"-Wunused-parameter\""); \ +_Pragma("GCC diagnostic ignored \"-Wunused-variable\""); \ +_Pragma("GCC diagnostic ignored \"-Wsign-compare\""); + +#define WARNINGS_ENABLE _Pragma("GCC diagnostic pop"); + +#ifdef NO_THIRD_PARTY_WARNINGS +//disabling some warnings +#define THIRD_PARTY_WARNINGS_DISABLE WARNINGS_DISABLE + +#define THIRD_PARTY_WARNINGS_ENABLE WARNINGS_ENABLE +#else +// just save old state (needs for not empty define) +#define THIRD_PARTY_WARNINGS_ENABLE WARNINGS_ENABLE + +#endif //#ifdef NO_THIRD_PARTY_WARNINGS + +#endif //#ifdef Q_WS_WIN + +#endif // UBGLOBALS_H + diff --git a/src/adaptors/UBExportCFF.cpp b/src/adaptors/UBExportCFF.cpp new file mode 100644 index 00000000..741eb871 --- /dev/null +++ b/src/adaptors/UBExportCFF.cpp @@ -0,0 +1,60 @@ +#include "UBExportCFF.h" +#include "UBCFFAdaptor.h" +#include "document/UBDocumentProxy.h" +#include "core/UBDocumentManager.h" +#include "core/UBApplication.h" + + +UBExportCFF::UBExportCFF(QObject *parent) +: UBExportAdaptor(parent) +{ + +} + +UBExportCFF::~UBExportCFF() +{ + +} +QString UBExportCFF::exportName() +{ + return tr("Export to IWB"); +} + +QString UBExportCFF::exportExtention() +{ + return QString(".iwb"); +} + +void UBExportCFF::persist(UBDocumentProxy* pDocument) +{ + QString src = pDocument->persistencePath(); + + if (!pDocument) + return; + + QString filename = askForFileName(pDocument, tr("Export as IWB File")); + + if (filename.length() > 0) + { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + + if (mIsVerbose) + UBApplication::showMessage(tr("Exporting document...")); + + UBCFFAdaptor toIWBExporter; + if (toIWBExporter.convertUBZToIWB(src, filename)) + { + if (mIsVerbose) + UBApplication::showMessage(tr("Export successful.")); + } + else + if (mIsVerbose) + UBApplication::showMessage(tr("Export failed.")); + + + QApplication::restoreOverrideCursor(); + + } + + +} \ No newline at end of file diff --git a/src/adaptors/UBExportCFF.h b/src/adaptors/UBExportCFF.h new file mode 100644 index 00000000..6c7012d6 --- /dev/null +++ b/src/adaptors/UBExportCFF.h @@ -0,0 +1,39 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef UBExportCFF_H_ +#define UBExportCFF_H_ + +#include + +#include "UBExportAdaptor.h" + +#include "frameworks/UBFileSystemUtils.h" + +class UBDocumentProxy; + +class UBExportCFF : public UBExportAdaptor +{ + Q_OBJECT; + +public: + UBExportCFF(QObject *parent = 0); + virtual ~UBExportCFF(); + + virtual QString exportName(); + virtual QString exportExtention(); + virtual void persist(UBDocumentProxy* pDocument); +}; + +#endif /* UBExportCFF_H_ */ \ No newline at end of file diff --git a/src/adaptors/adaptors.pri b/src/adaptors/adaptors.pri index b69d434f..4fc92ce9 100644 --- a/src/adaptors/adaptors.pri +++ b/src/adaptors/adaptors.pri @@ -14,6 +14,7 @@ HEADERS += src/adaptors/UBExportAdaptor.h\ src/adaptors/UBExportWeb.h \ src/adaptors/UBWebPublisher.h \ src/adaptors/UBImportCFF.h \ + src/adaptors/UBExportCFF.h \ src/adaptors/UBCFFSubsetAdaptor.h HEADERS += src/adaptors/publishing/UBDocumentPublisher.h \ @@ -36,6 +37,7 @@ SOURCES += src/adaptors/UBExportAdaptor.cpp\ src/adaptors/UBExportWeb.cpp \ src/adaptors/UBWebPublisher.cpp \ src/adaptors/UBImportCFF.cpp \ + src/adaptors/UBExportCFF.cpp \ src/adaptors/UBCFFSubsetAdaptor.cpp \ src/adaptors/publishing/UBDocumentPublisher.cpp diff --git a/src/core/UBDocumentManager.cpp b/src/core/UBDocumentManager.cpp index 48dd0352..fbe315e2 100644 --- a/src/core/UBDocumentManager.cpp +++ b/src/core/UBDocumentManager.cpp @@ -21,6 +21,7 @@ #include "adaptors/UBExportFullPDF.h" #include "adaptors/UBExportDocument.h" #include "adaptors/UBExportWeb.h" +#include "adaptors/UBExportCFF.h" #include "adaptors/UBWebPublisher.h" #include "adaptors/UBImportDocument.h" #include "adaptors/UBImportPDF.h" @@ -62,6 +63,8 @@ UBDocumentManager::UBDocumentManager(QObject *parent) QString dummyObjects = tr("objects"); QString dummyWidgets = tr("widgets"); + UBExportCFF* cffExporter = new UBExportCFF(this); + mExportAdaptors.append(cffExporter); UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this); mExportAdaptors.append(exportFullPdf); UBExportDocument* exportDocument = new UBExportDocument(this); From cf024b21872d36062790662ea3de6d1786c9e8a8 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 3 Apr 2012 18:50:40 +0300 Subject: [PATCH 06/10] Triangle behaviour fix --- src/board/UBBoardView.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index e9ffde4d..e1d1f0b2 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -54,6 +54,7 @@ #include "tools/UBGraphicsCompass.h" #include "tools/UBGraphicsCache.h" +#include "tools/UBGraphicsTriangle.h" #include "core/memcheck.h" @@ -425,7 +426,8 @@ UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsCompass::Type || movingItem->type() == UBGraphicsPDFItem::Type || movingItem->type() == UBGraphicsPolygonItem::Type - || movingItem->type() == UBGraphicsCache::Type) + || movingItem->type() == UBGraphicsCache::Type + || movingItem->type() == UBGraphicsTriangle::Type) { movingItem = NULL; QGraphicsView::mousePressEvent (event); From 9745c5d058e7d69c09fc9256ff35d47136f85909 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Tue, 3 Apr 2012 19:24:32 +0300 Subject: [PATCH 07/10] Fixed for correctly work on 3 platforms. --- plugins/cffadaptor/UBCFFAdaptor.pro | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/cffadaptor/UBCFFAdaptor.pro b/plugins/cffadaptor/UBCFFAdaptor.pro index 78f1bf71..36ef90fe 100644 --- a/plugins/cffadaptor/UBCFFAdaptor.pro +++ b/plugins/cffadaptor/UBCFFAdaptor.pro @@ -10,14 +10,16 @@ linux-g++: SUB_DIR = linux linux-g++-32: SUB_DIR = linux linux-g++-64: SUB_DIR = linux -QUAZIP_DIR = "$$PWD/../../../Sankore-ThirdParty/quazip" -ZLIB_DIR = "$$PWD/../../../Sankore-ThirdParty/zlib" +THIRD_PARTY_PATH = ../../../Sankore-ThirdParty +QUAZIP_DIR = "$$PWD/../../../Sankore-ThirdParty/quazip/quazip-0.3" -INCLUDEPATH += src \ - "$$QUAZIP_DIR/quazip-0.3" \ - "$$ZLIB_DIR/1.2.3/include" +INCLUDEPATH += src -LIBS += "-L$$QUAZIP_DIR/lib/$$SUB_DIR" "-lquazip" +DEPENDPATH += $$THIRD_PARTY_PATH/quazip/ +INCLUDEPATH += $$THIRD_PARTY_PATH/quazip/ +include($$THIRD_PARTY_PATH/quazip/quazip.pri) + +LIBS += "-L$$THIRD_PARTY_PATH/quazip/lib/$$SUB_DIR" "-lquazip" QT += xml xmlpatterns core QT += gui From 1e67bf6e4a4a3371f14b69860adfd35ce3436d54 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 3 Apr 2012 19:44:34 +0300 Subject: [PATCH 08/10] SANKORE-475 Improve the rendering of the magnifier --- src/board/UBBoardController.cpp | 5 +- src/desktop/UBDesktopAnnotationController.cpp | 1 + src/domain/UBGraphicsScene.cpp | 64 +- src/domain/UBGraphicsScene.h | 7 +- src/gui/UBMagnifer.cpp | 790 +++++++++--------- src/gui/UBMagnifer.h | 193 ++--- 6 files changed, 571 insertions(+), 489 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 961a2dc3..4b54b76b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -664,6 +664,7 @@ void UBBoardController::zoom(const qreal ratio, QPointF scenePoint) UBApplication::applicationController->adjustDisplayView(); emit controlViewportChanged(); + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11()); } @@ -1163,7 +1164,7 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, mControlView->setScene(mActiveScene); mDisplayView->setScene(mActiveScene); - + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11()); pDocumentProxy->setDefaultDocumentSize(mActiveScene->nominalSize()); updatePageSizeState(); @@ -1564,7 +1565,7 @@ void UBBoardController::updateSystemScaleFactor() mControlView->setTransform(scalingTransform); mControlView->horizontalScrollBar()->setValue(viewState.horizontalPosition); mControlView->verticalScrollBar()->setValue(viewState.verticalPostition); -} + mActiveScene->setBackgroundZoomFactor(mControlView->transform().m11());} void UBBoardController::setWidePageSize(bool checked) diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index 9cb92e4b..1f27f607 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -88,6 +88,7 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent) mTransparentDrawingScene = new UBGraphicsScene(0); mTransparentDrawingView->setScene(mTransparentDrawingScene); + mTransparentDrawingScene->setDrawingMode(true); // mRightPalette = UBApplication::boardController->paletteManager()->createDesktopRightPalette(mTransparentDrawingView); //mRightPalette = new UBRightPalette(mTransparentDrawingView); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index bbd4af62..6f7f4d77 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -135,6 +135,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) , enableUndoRedoStack(true) , magniferControlViewWidget(0) , magniferDisplayViewWidget(0) + , mIsDesktopMode(false) { @@ -160,8 +161,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) UBGraphicsScene::~UBGraphicsScene() { - DisposeMagnifierQWidgets(); - if (mCurrentStroke) if (mCurrentStroke->polygons().empty()) delete mCurrentStroke; @@ -711,6 +710,15 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) } } +void UBGraphicsScene::setBackgroundZoomFactor(qreal zoom) +{ + mZoomFactor = zoom; +} + +void UBGraphicsScene::setDrawingMode(bool bModeDesktop) +{ + mIsDesktopMode = bModeDesktop; +} void UBGraphicsScene::recolorAllItems() { @@ -1854,6 +1862,58 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems, } } +void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) +{ + if (mIsDesktopMode) + { + QGraphicsScene::drawBackground (painter, rect); + return; + } + bool darkBackground = isDarkBackground (); + + if (darkBackground) + { + painter->fillRect (rect, QBrush (QColor (Qt::black))); + } + else + { + painter->fillRect (rect, QBrush (QColor (Qt::white))); + } + + if (mZoomFactor > 0.5) + { + QColor bgCrossColor; + + if (darkBackground) + bgCrossColor = UBSettings::crossDarkBackground; + else + bgCrossColor = UBSettings::crossLightBackground; + if (mZoomFactor < 1.0) + { + int alpha = 255 * mZoomFactor / 2; + bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms + } + + painter->setPen (bgCrossColor); + + if (isCrossedBackground()) + { + qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; + + for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) + { + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + } + + qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; + + for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) + { + painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); + } + } + } +} void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 8fa84053..1cdd37e4 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -288,7 +288,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void hideEraser(); void setBackground(bool pIsDark, bool pIsCrossed); - + void setBackgroundZoomFactor(qreal zoom); + void setDrawingMode(bool bModeDesktop); void deselectAllItems(); UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false); @@ -331,6 +332,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem QGraphicsItem* rootItem(QGraphicsItem* item) const; + virtual void drawBackground(QPainter *painter, const QRectF &rect); + private: void setDocumentUpdated(); void createEraiser(); @@ -348,6 +351,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem bool mDarkBackground; bool mCrossedBackground; + bool mIsDesktopMode; + qreal mZoomFactor; bool mIsModified; diff --git a/src/gui/UBMagnifer.cpp b/src/gui/UBMagnifer.cpp index 08285c91..93693797 100644 --- a/src/gui/UBMagnifer.cpp +++ b/src/gui/UBMagnifer.cpp @@ -1,388 +1,402 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include "UBMagnifer.h" - -#include "core/UBApplication.h" -#include "board/UBBoardController.h" -#include "domain/UBGraphicsScene.h" - -#include "core/memcheck.h" - - -UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) - : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) - , mShouldMoveWidget(false) - , mShouldResizeWidget(false) - , inTimer(false) - , borderPen(Qt::darkGray) - , gView(0) - , mView(0) -{ - isCusrsorAlreadyStored = false; - setMouseTracking(true); - - //--------------------------------------------------// - - QPixmap pix(":/images/cursors/resize.png"); - QTransform tr; - tr.rotate(45); - mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); - - //--------------------------------------------------// - - params.sizePercentFromScene = 20; - m_isInteractive = isInteractive; - sClosePixmap = new QPixmap(":/images/close.svg"); - sIncreasePixmap = new QPixmap(":/images/increase.svg"); - sDecreasePixmap = new QPixmap(":/images/decrease.svg"); - mResizeItem = new QPixmap(":/images/resize.svg"); - - if (parent) - { - setAttribute(Qt::WA_NoMousePropagation); - } - else - { - // standalone window - // !!!! Should be included into Windows after QT recompilation -#ifndef Q_WS_WIN -// setAttribute(Qt::WA_TranslucentBackground); - setAttribute(Qt::WA_MacAlwaysShowToolWindow); -#endif -#ifdef Q_WS_MAC - setAttribute(Qt::WA_MacAlwaysShowToolWindow); - setAttribute(Qt::WA_MacNonActivatingToolWindow); - setAttribute(Qt::WA_MacNoShadow); -#endif - } - -} - -UBMagnifier::~UBMagnifier() -{ - if (timerUpdate != 0) - { - killTimer(timerUpdate); - timerUpdate = 0; - } - - if(sClosePixmap) - { - delete sClosePixmap; - sClosePixmap = NULL; - } - - if(sIncreasePixmap) - { - delete sIncreasePixmap; - sIncreasePixmap = NULL; - } - - if(sDecreasePixmap) - { - delete sDecreasePixmap; - sDecreasePixmap = NULL; - } -} - -void UBMagnifier::setSize(qreal percentFromScene) -{ - if(gView == NULL || mView == NULL) return; - - // calculate object size - params.sizePercentFromScene = percentFromScene; - QSize sceneSize = mView->size(); - qreal size = params.sizePercentFromScene * sceneSize.width() / 100; - - QRect currGeom = geometry(); - if(currGeom.width() == currGeom.height()) - { - QPoint newPos = mView->mapFromGlobal(updPointMove); - setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); - } - else - setGeometry(0, 0, size, size); - - // prepare transparent bit mask - QImage mask_img(width(), height(), QImage::Format_Mono); - mask_img.fill(0xff); - QPainter mask_ptr(&mask_img); - mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); - mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); - bmpMask = QBitmap::fromImage(mask_img); - - // prepare general image - pMap = QPixmap(width(), height()); - pMap.fill(Qt::transparent); - pMap.setMask(bmpMask); -} - -void UBMagnifier::setZoom(qreal zoom) -{ - params.zoom = zoom; -} - -void UBMagnifier::paintEvent(QPaintEvent * event) -{ - Q_UNUSED(event); - QPainter painter(this); - - painter.setRenderHint(QPainter::Antialiasing); - painter.setPen(Qt::NoPen); - - if (m_isInteractive) - { - painter.setBrush(QColor(127, 127, 127, 127)); - painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); - - painter.setBrush(QColor(190, 190, 190, 255)); - painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); - - painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); - painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); - painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); - - painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); - } - else - { - painter.setBrush(QColor(127, 127, 127, 127)); - painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); - } - - painter.drawPixmap(0, 0, pMap); -} - -void UBMagnifier::mousePressEvent ( QMouseEvent * event ) -{ - if(m_isInteractive) - { - - QWidget::mousePressEvent(event); - - if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && - event->pos().x() < size().width() - 20 && - event->pos().y() >= size().height() - mResizeItem->height() - 20 && - event->pos().y() < size().height() - - 20) - { - mShouldResizeWidget = true; - } - else - { - mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); - } - - mMousePressPos = event->pos(); - mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); - - event->accept(); - - update(); - } - else - event->ignore(); -} - -void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) -{ - if(m_isInteractive) - { - if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) - { - move(pos() - mMousePressPos + event->pos()); - event->accept(); - - QWidget::mouseMoveEvent(event); - emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); - return; - } - - if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) - { - - QPoint currGlobalPos = event->globalPos(); - qreal cvW = mView->width(); - - qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; - qreal newPercentSize = newXSize * 100 / cvW; - - emit magnifierResized_Signal(newPercentSize); - - event->ignore(); - return; - } - - if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && - event->pos().x() < size().width() - 20 && - event->pos().y() >= size().height() - mResizeItem->height() - 20 && - event->pos().y() < size().height() - - 20 && - isCusrsorAlreadyStored == false - ) - { - mOldCursor = cursor(); - isCusrsorAlreadyStored = true; - setCursor(mResizeCursor); - } - - } - else - event->ignore(); -} - - -void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) -{ - if(m_isInteractive) - { - mShouldMoveWidget = false; - mShouldResizeWidget = false; - - if (event->pos().x() >= size().width() - sClosePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 && - event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) - { - event->accept(); - emit magnifierClose_Signal(); - } - else - if (event->pos().x() >= size().width() - sIncreasePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 && - event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) - { - event->accept(); - emit magnifierZoomIn_Signal(); - } - else - if (event->pos().x() >= size().width() - sDecreasePixmap->width() && - event->pos().x() < size().width()&& - event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 && - event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) - { - event->accept(); - emit magnifierZoomOut_Signal(); - } - else - QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool - } - else - event->ignore(); - -} - -void UBMagnifier::timerEvent(QTimerEvent *e) -{ - if(inTimer) return; - if (e->timerId() == timerUpdate) - { - inTimer = true; - if(!(updPointGrab.isNull())) - grabPoint(updPointGrab); - - if(isCusrsorAlreadyStored) - { - QPoint globalCursorPos = QCursor::pos(); - QPoint cursorPos = mapFromGlobal(globalCursorPos); - if (cursorPos.x() < size().width() - mResizeItem->width() - 20 || - cursorPos.x() > size().width() - 20 || - cursorPos.y() < size().height() - mResizeItem->height() - 20 || - cursorPos.y() > size().height() - - 20 - ) - { - isCusrsorAlreadyStored = false; - setCursor(mOldCursor); - } - - } - - inTimer = false; - } -} - -void UBMagnifier::grabPoint() -{ - QPointF itemPos = gView->mapFromGlobal(updPointGrab); - - qreal zWidth = size().width() / params.zoom; - qreal zWidthHalf = zWidth / 2; - qreal zHeight = size().height() / params.zoom; - qreal zHeightHalf = zHeight / 2; - - int x = itemPos.x() - zWidthHalf; - int y = itemPos.y() - zHeightHalf; - - QPixmap newPixMap(QSize(zWidth,zHeight)); - ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); - UBApplication::boardController->activeScene()->update(); - - pMap.fill(Qt::transparent); - pMap = newPixMap.scaled(QSize(width(), height())); - pMap.setMask(bmpMask); - - update(); -} - -void UBMagnifier::grabPoint(const QPoint &pGrab) -{ - updPointGrab = pGrab; - QPointF itemPos = gView->mapFromGlobal(pGrab); - - qreal zWidth = size().width() / params.zoom; - qreal zWidthHalf = zWidth / 2; - qreal zHeight = size().height() / params.zoom; - qreal zHeightHalf = zHeight / 2; - - int x = itemPos.x() - zWidthHalf; - int y = itemPos.y() - zHeightHalf; - - QPixmap newPixMap(QSize(zWidth,zHeight)); - ((QWidget*)gView)->render(&newPixMap, QPoint(0, 0), QRegion(x, y, zWidth, zHeight)); - UBApplication::boardController->activeScene()->update(); - - pMap.fill(Qt::transparent); - pMap = newPixMap.scaled(QSize(width(), height())); - pMap.setMask(bmpMask); - - update(); -} - -// from global -void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) -{ - updPointGrab = pGrab; - updPointMove = pMove; - - if(needGrab) - grabPoint(pGrab); - - if(needMove) - { - QPoint movePos = mView->mapFromGlobal(pMove); - move(movePos.x() - width()/2, movePos.y() - height()/2); - // move(itemPos.x(), itemPos.y()); - } -} - -void UBMagnifier::setGrabView(QWidget *view) -{ - if (timerUpdate != 0) - killTimer(timerUpdate); - gView = view; - timerUpdate = startTimer(200); -} - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "UBMagnifer.h" + +#include "core/UBApplication.h" +#include "board/UBBoardController.h" +#include "domain/UBGraphicsScene.h" +#include "board/UBBoardView.h" + +#include "core/memcheck.h" + + +UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) + : QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)) + , mShouldMoveWidget(false) + , mShouldResizeWidget(false) + , borderPen(Qt::darkGray) + , gView(0) + , mView(0) +{ + isCusrsorAlreadyStored = false; + setMouseTracking(true); + + //--------------------------------------------------// + + QPixmap pix(":/images/cursors/resize.png"); + QTransform tr; + tr.rotate(45); + mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2); + + //--------------------------------------------------// + + params.sizePercentFromScene = 20; + m_isInteractive = isInteractive; + sClosePixmap = new QPixmap(":/images/close.svg"); + sIncreasePixmap = new QPixmap(":/images/increase.svg"); + sDecreasePixmap = new QPixmap(":/images/decrease.svg"); + mResizeItem = new QPixmap(":/images/resize.svg"); + + if (parent) + { + setAttribute(Qt::WA_NoMousePropagation); + } + else + { + // standalone window + // !!!! Should be included into Windows after QT recompilation +#ifndef Q_WS_WIN +// setAttribute(Qt::WA_TranslucentBackground); + setAttribute(Qt::WA_MacAlwaysShowToolWindow); +#endif +#ifdef Q_WS_MAC + setAttribute(Qt::WA_MacAlwaysShowToolWindow); + setAttribute(Qt::WA_MacNonActivatingToolWindow); + setAttribute(Qt::WA_MacNoShadow); +#endif + } + + connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh())); +} + +UBMagnifier::~UBMagnifier() +{ + if(sClosePixmap) + { + delete sClosePixmap; + sClosePixmap = NULL; + } + + if(sIncreasePixmap) + { + delete sIncreasePixmap; + sIncreasePixmap = NULL; + } + + if(sDecreasePixmap) + { + delete sDecreasePixmap; + sDecreasePixmap = NULL; + } +} + +void UBMagnifier::setSize(qreal percentFromScene) +{ + if(gView == NULL || mView == NULL) return; + + // calculate object size + params.sizePercentFromScene = percentFromScene; + QSize sceneSize = mView->size(); + qreal size = params.sizePercentFromScene * sceneSize.width() / 100; + + QRect currGeom = geometry(); + if(currGeom.width() == currGeom.height()) + { + QPoint newPos = mView->mapFromGlobal(updPointMove); + setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size); + } + else + setGeometry(0, 0, size, size); + + // prepare transparent bit mask + QImage mask_img(width(), height(), QImage::Format_Mono); + mask_img.fill(0xff); + QPainter mask_ptr(&mask_img); + mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) ); + mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width()); + bmpMask = QBitmap::fromImage(mask_img); + + // prepare general image + pMap = QPixmap(width(), height()); + pMap.fill(Qt::transparent); + pMap.setMask(bmpMask); +} + +void UBMagnifier::setZoom(qreal zoom) +{ + params.zoom = zoom; +} + +void UBMagnifier::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + QPainter painter(this); + + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::NoPen); + + if (m_isInteractive) + { + painter.setBrush(QColor(127, 127, 127, 127)); + painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15); + + painter.setBrush(QColor(190, 190, 190, 255)); + painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); + + painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap); + painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap); + painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap); + + painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem); + } + else + { + painter.setBrush(QColor(127, 127, 127, 127)); + painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2); + } + + painter.drawPixmap(0, 0, pMap); +} + +void UBMagnifier::mousePressEvent ( QMouseEvent * event ) +{ + if(m_isInteractive) + { + + QWidget::mousePressEvent(event); + + if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && + event->pos().x() < size().width() - 20 && + event->pos().y() >= size().height() - mResizeItem->height() - 20 && + event->pos().y() < size().height() - - 20) + { + mShouldResizeWidget = true; + } + else + { + mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); + } + + mMousePressPos = event->pos(); + mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x(); + + event->accept(); + + update(); + } + else + event->ignore(); +} + +void UBMagnifier::mouseMoveEvent ( QMouseEvent * event ) +{ + if(m_isInteractive) + { + if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) + { + move(pos() - mMousePressPos + event->pos()); + event->accept(); + + QWidget::mouseMoveEvent(event); + emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 )); + return; + } + + if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton)) + { + + QPoint currGlobalPos = event->globalPos(); + qreal cvW = mView->width(); + + qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2; + qreal newPercentSize = newXSize * 100 / cvW; + + emit magnifierResized_Signal(newPercentSize); + + event->ignore(); + return; + } + + if (event->pos().x() >= size().width() - mResizeItem->width() - 20 && + event->pos().x() < size().width() - 20 && + event->pos().y() >= size().height() - mResizeItem->height() - 20 && + event->pos().y() < size().height() - - 20 && + isCusrsorAlreadyStored == false + ) + { + mOldCursor = cursor(); + isCusrsorAlreadyStored = true; + setCursor(mResizeCursor); + } + + } + else + event->ignore(); +} + + +void UBMagnifier::mouseReleaseEvent(QMouseEvent * event) +{ + if(m_isInteractive) + { + mShouldMoveWidget = false; + mShouldResizeWidget = false; + + if (event->pos().x() >= size().width() - sClosePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 && + event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2) + { + event->accept(); + emit magnifierClose_Signal(); + } + else + if (event->pos().x() >= size().width() - sIncreasePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 && + event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5) + { + event->accept(); + emit magnifierZoomIn_Signal(); + } + else + if (event->pos().x() >= size().width() - sDecreasePixmap->width() && + event->pos().x() < size().width()&& + event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 && + event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6) + { + event->accept(); + emit magnifierZoomOut_Signal(); + } + else + QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool + } + else + event->ignore(); + +} + +void UBMagnifier::slot_refresh() +{ + if(!(updPointGrab.isNull())) + grabPoint(updPointGrab); + + if(isCusrsorAlreadyStored) + { + QPoint globalCursorPos = QCursor::pos(); + QPoint cursorPos = mapFromGlobal(globalCursorPos); + if (cursorPos.x() < size().width() - mResizeItem->width() - 20 || + cursorPos.x() > size().width() - 20 || + cursorPos.y() < size().height() - mResizeItem->height() - 20 || + cursorPos.y() > size().height() - - 20 + ) + { + isCusrsorAlreadyStored = false; + setCursor(mOldCursor); + } + } +} + +void UBMagnifier::grabPoint() +{ + QMatrix transM = UBApplication::boardController->controlView()->matrix(); + QPointF itemPos = gView->mapFromGlobal(updPointGrab); + + qreal zWidth = width() / (params.zoom * transM.m11()); + qreal zWidthHalf = zWidth / 2; + qreal zHeight = height() / (params.zoom * transM.m22()); + qreal zHeightHalf = zHeight / 2; + + + QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); + + + QRect magnifierRect = rect(); + + float x = pfScLtF.x() - zWidthHalf; + float y = pfScLtF.y() - zHeightHalf; + + QPointF leftTop(x,y); + QPointF rightBottom(x + zWidth, y + zHeight); + QRectF srcRect(leftTop, rightBottom); + + QPixmap newPixMap(QSize(width(), height())); + QPainter painter(&newPixMap); + + UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); + painter.end(); + + pMap.fill(Qt::transparent); + pMap = newPixMap.scaled(QSize(width(), height())); + pMap.setMask(bmpMask); + + update(); +} + +void UBMagnifier::grabPoint(const QPoint &pGrab) +{ + QMatrix transM = UBApplication::boardController->controlView()->matrix(); + updPointGrab = pGrab; + QPointF itemPos = gView->mapFromGlobal(pGrab); + + qreal zWidth = width() / (params.zoom * transM.m11()); + qreal zWidthHalf = zWidth / 2; + qreal zHeight = height() / (params.zoom * transM.m22()); + qreal zHeightHalf = zHeight / 2; + + + QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); + + + QRect magnifierRect = rect(); + + float x = pfScLtF.x() - zWidthHalf; + float y = pfScLtF.y() - zHeightHalf; + + QPointF leftTop(x,y); + QPointF rightBottom(x + zWidth, y + zHeight); + QRectF srcRect(leftTop, rightBottom); + + QPixmap newPixMap(QSize(width(), height())); + QPainter painter(&newPixMap); + + UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); + painter.end(); + + // pMap.fill(Qt::transparent); + pMap = newPixMap; + pMap.setMask(bmpMask); + + update(); +} + + + +// from global +void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove) +{ + updPointGrab = pGrab; + updPointMove = pMove; + + if(needGrab) + grabPoint(pGrab); + + if(needMove) + { + QPoint movePos = mView->mapFromGlobal(pMove); + move(movePos.x() - width()/2, movePos.y() - height()/2); + // move(itemPos.x(), itemPos.y()); + } +} + +void UBMagnifier::setGrabView(QWidget *view) +{ + gView = view; + mRefreshTimer.setInterval(40); + mRefreshTimer.start(); +} + diff --git a/src/gui/UBMagnifer.h b/src/gui/UBMagnifer.h index 73a81692..7a118a99 100644 --- a/src/gui/UBMagnifer.h +++ b/src/gui/UBMagnifer.h @@ -1,96 +1,97 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UBMAGNIFIER_H -#define UBMAGNIFIER_H - -#include - -class UBMagnifierParams -{ -public : - int x; - int y; - qreal zoom; - qreal sizePercentFromScene; -}; - -class UBMagnifier : public QWidget -{ - Q_OBJECT - -public: - UBMagnifier(QWidget *parent = 0, bool isInteractive = false); - ~UBMagnifier(); - - void setSize(qreal percentFromScene); - void setZoom(qreal zoom); - - void setGrabView(QWidget *view); - void setMoveView(QWidget *view) {mView = view;} - - void grabPoint(); - void grabPoint(const QPoint &point); - void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); - - UBMagnifierParams params; - -signals: - void magnifierMoved_Signal(QPoint newPos); - void magnifierClose_Signal(); - void magnifierZoomIn_Signal(); - void magnifierZoomOut_Signal(); - void magnifierResized_Signal(qreal newPercentSize); - -protected: - void paintEvent(QPaintEvent *); - void timerEvent(QTimerEvent *); - - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void mouseMoveEvent ( QMouseEvent * event ); - virtual void mouseReleaseEvent ( QMouseEvent * event ); - - QPoint mMousePressPos; - qreal mMousePressDelta; - bool mShouldMoveWidget; - bool mShouldResizeWidget; - - - QPixmap *sClosePixmap; - QPixmap *sIncreasePixmap; - QPixmap *sDecreasePixmap; - QPixmap *mResizeItem; - - bool isCusrsorAlreadyStored; - QCursor mOldCursor; - QCursor mResizeCursor; - -private: - bool inTimer; - bool m_isInteractive; - - int timerUpdate; - QPoint updPointGrab; - QPoint updPointMove; - - QPixmap pMap; - QBitmap bmpMask; - QPen borderPen; - - QWidget *gView; - QWidget *mView; -}; - -#endif // UBMAGNIFIER_H +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef UBMAGNIFIER_H +#define UBMAGNIFIER_H + +#include + +class UBMagnifierParams +{ +public : + int x; + int y; + qreal zoom; + qreal sizePercentFromScene; +}; + +class UBMagnifier : public QWidget +{ + Q_OBJECT + +public: + UBMagnifier(QWidget *parent = 0, bool isInteractive = false); + ~UBMagnifier(); + + void setSize(qreal percentFromScene); + void setZoom(qreal zoom); + + void setGrabView(QWidget *view); + void setMoveView(QWidget *view) {mView = view;} + + void grabPoint(); + void grabPoint(const QPoint &point); + void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true); + + UBMagnifierParams params; + +signals: + void magnifierMoved_Signal(QPoint newPos); + void magnifierClose_Signal(); + void magnifierZoomIn_Signal(); + void magnifierZoomOut_Signal(); + void magnifierResized_Signal(qreal newPercentSize); + +public slots: + void slot_refresh(); + +protected: + void paintEvent(QPaintEvent *); + + virtual void mousePressEvent ( QMouseEvent * event ); + virtual void mouseMoveEvent ( QMouseEvent * event ); + virtual void mouseReleaseEvent ( QMouseEvent * event ); + + QPoint mMousePressPos; + qreal mMousePressDelta; + bool mShouldMoveWidget; + bool mShouldResizeWidget; + + + QPixmap *sClosePixmap; + QPixmap *sIncreasePixmap; + QPixmap *sDecreasePixmap; + QPixmap *mResizeItem; + + bool isCusrsorAlreadyStored; + QCursor mOldCursor; + QCursor mResizeCursor; + +private: + QTimer mRefreshTimer; + bool m_isInteractive; + + QPoint updPointGrab; + QPoint updPointMove; + + QPixmap pMap; + QBitmap bmpMask; + QPen borderPen; + + QWidget *gView; + QWidget *mView; +}; + +#endif // UBMAGNIFIER_H From fc8e70f193e7215c73a4077e8275db6856989970 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 4 Apr 2012 09:26:06 +0200 Subject: [PATCH 09/10] fixed cffexport library path --- Sankore_3.1.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index 7f87beca..a630e889 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -131,7 +131,7 @@ win32 { } macx { - LIBS += "-Lplugins/cffadaptor/lib/mac" "-lCFF_Adaptor" + LIBS += "-Lplugins/cffadaptor/lib/macx" "-lCFF_Adaptor" LIBS += -framework Foundation LIBS += -lcrypto LIBS += -framework AppKit From aad810506c118ce04a48cffc7d739ba6ff5ab45f Mon Sep 17 00:00:00 2001 From: Didier Clerc Date: Wed, 4 Apr 2012 16:02:18 +0200 Subject: [PATCH 10/10] wording --- .../Choisir.wgt/scripts/languages.js | 26 +++++++++---------- .../locales/fr/js/script.js | 4 +-- .../locales/fr/js/script.js | 6 ++--- .../locales/fr/js/script.js | 6 ++--- .../locales/fr/js/script.js | 6 ++--- .../etudier.wgt/locales/fr/js/script.js | 6 ++--- .../locales/fr/script/template2.js | 4 +-- .../locales/fr/scripts/template2.js | 4 +-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/resources/library/interactivities/Choisir.wgt/scripts/languages.js b/resources/library/interactivities/Choisir.wgt/scripts/languages.js index af618b41..071f5c67 100644 --- a/resources/library/interactivities/Choisir.wgt/scripts/languages.js +++ b/resources/library/interactivities/Choisir.wgt/scripts/languages.js @@ -49,23 +49,23 @@ var sankoreLang = { "edit": "Modifier", "display":"Afficher", "question":"La question", - "example_question":"Ceci est un exemple de la question", - "answer":"Ceci est un exemple de la réponse", + "example_question":"Ceci est un exemple de question", + "answer":"Ceci est un exemple de réponse", "q":"Q", - "add_new_question":"Ajouter nouvelle question ...", - "options":"Les options", + "add_new_question":"Ajouter une nouvelle question ...", + "options":"Options", "close":"Fermer", "delete_question":"Supprimer la question", - "delete_answer":"Supprimer réponse", + "delete_answer":"Supprimer la possibilité", "right_answer":"Bonne réponse", - "template_question":"Saisissez votre question ici ...", - "template_answer":"Entrez la réponse ici ...", - "add_answer":"Ajouter une réponse", - "select_text":"Choisissez la bonne réponse", - "options_desc":"Vous pouvez choisir n'importe lequel de ces trois options d'affichage de vos réponses. Voir un court leur description.", - "radio_desc":"Cette option permet de choisir une seule réponse et les réponses sont affichées sous forme de boutons radio.", - "checkbox_desc":"Cette option permet de choisir plusieurs réponses et les réponses sont affichées comme des cases à cocher.", - "select_desc":"Cette option permet de choisir une seule réponse et les réponses sont affichées sous forme de menu déroulant.", + "template_question":"Saisir la question ici ...", + "template_answer":"Saisir la réponse ici ...", + "add_answer":"Ajouter une possibilité", + "select_text":"Choisir la bonne réponse", + "options_desc":"Types de questions", + "radio_desc":"Option 1 : une seule bonne réponse, les possibilités sont affichées sous forme de boutons radio.", + "checkbox_desc":"Option 2 : plusieurs bonnes réponses, les possibilités sont affichées sous forme de cases à cocher.", + "select_desc":"Option 3 : une seule bonne réponse, les possibilités sont affichées sous forme de menu déroulant.", "a":"R" } }; diff --git a/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js b/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js index eeea8c90..d535038b 100644 --- a/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/associer_images.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "Affichage", + display: "Afficher", edit: "Modifier", short_desc: "Sélectionner le numéro «trois».", add: "Nouveau bloc", - enter: "Saisissez la consigne ici ..." + enter: "Saisir la consigne ici ..." }; //main function diff --git a/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js b/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js index 372b4096..26f4b7e2 100644 --- a/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/associer_sounds.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", - short_desc: "Combien de signaux entendez-vous?", + short_desc: "Combien de signaux sonores entendez-vous?", add: "Nouveau bloc", - enter: "Entrez votre description ici ..." + enter: "Saisir votre description ici ..." }; //main function diff --git a/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js b/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js index 58d96a0f..f0f8b5e1 100644 --- a/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/categoriser_images.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", first_desc: "Les nombres impairs", - second_desc: "Même les chiffres", - enter: "Entrez votre nom de la catégorie ici ...", + second_desc: "Les nombres pairs", + enter: "Saisir le nom de la catégorie ici ...", add: "Nouveau bloc" }; diff --git a/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js b/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js index 98619403..01ec59dc 100644 --- a/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/categoriser_text.wgt/locales/fr/js/script.js @@ -1,14 +1,14 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", first_desc: "Fruits", second_desc: "Légumes", - potatoes: "Pommes de terre", + potatoes: "Pomme de terre", carrot: "Carotte", onion: "Oignon", apple: "Pomme", pear: "Poire", - enter: "Entrez votre nom de la catégorie ici ...", + enter: "Saisir le nom de la catégorie ici ...", add: "Nouveau bloc", text: "Texte" }; diff --git a/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js b/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js index 92e22585..d0660316 100644 --- a/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js +++ b/resources/library/interactivities/etudier.wgt/locales/fr/js/script.js @@ -1,9 +1,9 @@ var sankoreLang = { - display: "D'affichage", + display: "Afficher", edit: "Modifier", - text_content: "Ceci est un exemple. Au lieu de ce texte, vous pouvez mettre votre propre contenu.", + text_content: "Ceci est un exemple. Au lieu de ce texte, vous pouvez saisir votre propre texte ou glisser-dŽposer une image, un son.", new_txt: "Nouveau bloc de texte", - new_slide: "C'est une nouvelle diapositive." + new_slide: "Ceci est une nouvelle diapositive." }; //some flags diff --git a/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js b/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js index 14759a5e..717a36c5 100644 --- a/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js +++ b/resources/library/interactivities/ord-phrases.wgt/locales/fr/script/template2.js @@ -26,9 +26,9 @@ function checkResponse() */ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", - example: "il\ns'agit\nd'une\nphrase\nd'exemple" + example: "Cette phrase\nest un\nexemple." }; diff --git a/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js b/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js index 320953b2..9418604a 100644 --- a/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js +++ b/resources/library/interactivities/ord-words.wgt/locales/fr/scripts/template2.js @@ -27,9 +27,9 @@ function checkResponse() */ var sankoreLang = { - view: "D'affichage", + view: "Afficher", edit: "Modifier", - example: "une*longue*,*il*ya*bien*longtemps*..." + example: "Il*y*a*longtemps*,*nous*Žtions*ˆ*la*mer*." }; var word = "";