Commit a0a0d208 authored by Ivan Ilin's avatar Ivan Ilin

UBZLayerController created. Z level implementation restructured

parent a95472cd
...@@ -320,6 +320,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -320,6 +320,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mXmlReader.readNext(); mXmlReader.readNext();
if (mXmlReader.isStartElement()) if (mXmlReader.isStartElement())
{ {
qreal zFromSvg = getZValueFromSvg();
if (mXmlReader.name() == "svg") if (mXmlReader.name() == "svg")
{ {
if (!scene) if (!scene)
...@@ -529,6 +531,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -529,6 +531,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(pixmapItem); scene->addItem(pixmapItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(pixmapItem, zFromSvg);
if (isBackground) if (isBackground)
scene->setAsBackgroundObject(pixmapItem); scene->setAsBackgroundObject(pixmapItem);
...@@ -548,6 +553,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -548,6 +553,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(svgItem); scene->addItem(svgItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(svgItem, zFromSvg);
if (isBackground) if (isBackground)
scene->setAsBackgroundObject(svgItem); scene->setAsBackgroundObject(svgItem);
...@@ -573,6 +581,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -573,6 +581,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(audioItem); scene->addItem(audioItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(audioItem, zFromSvg);
audioItem->show(); audioItem->show();
//force start to load the video and display the first frame //force start to load the video and display the first frame
...@@ -593,6 +604,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -593,6 +604,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(videoItem); scene->addItem(videoItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(videoItem, zFromSvg);
videoItem->show(); videoItem->show();
//force start to load the video and display the first frame //force start to load the video and display the first frame
...@@ -613,6 +627,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -613,6 +627,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(textItem); scene->addItem(textItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(textItem, zFromSvg);
textItem->show(); textItem->show();
} }
} }
...@@ -624,17 +641,27 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -624,17 +641,27 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
scene->addItem(mask); scene->addItem(mask);
scene->registerTool(mask); scene->registerTool(mask);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(mask, zFromSvg);
} }
} }
else if (mXmlReader.name() == "ruler") else if (mXmlReader.name() == "ruler")
{ {
QString ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString();
UBGraphicsRuler *ruler = rulerFromSvg(); UBGraphicsRuler *ruler = rulerFromSvg();
ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString();
if (ruler) if (ruler)
{ {
scene->addItem(ruler); scene->addItem(ruler);
scene->registerTool(ruler); scene->registerTool(ruler);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(ruler, zFromSvg);
} }
} }
else if (mXmlReader.name() == "compass") else if (mXmlReader.name() == "compass")
{ {
...@@ -644,6 +671,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -644,6 +671,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
scene->addItem(compass); scene->addItem(compass);
scene->registerTool(compass); scene->registerTool(compass);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(compass, zFromSvg);
} }
} }
else if (mXmlReader.name() == "protractor") else if (mXmlReader.name() == "protractor")
...@@ -654,6 +684,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -654,6 +684,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
scene->addItem(protractor); scene->addItem(protractor);
scene->registerTool(protractor); scene->registerTool(protractor);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(protractor, zFromSvg);
} }
} }
else if (mXmlReader.name() == "triangle") else if (mXmlReader.name() == "triangle")
...@@ -664,6 +697,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -664,6 +697,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
scene->addItem(triangle); scene->addItem(triangle);
scene->registerTool(triangle); scene->registerTool(triangle);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(triangle, zFromSvg);
} }
} }
else if(mXmlReader.name() == "cache") else if(mXmlReader.name() == "cache")
...@@ -674,6 +710,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -674,6 +710,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(cache); scene->addItem(cache);
scene->registerTool(cache); scene->registerTool(cache);
UBApplication::boardController->notifyCache(true); UBApplication::boardController->notifyCache(true);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(cache, zFromSvg);
} }
} }
else if (mXmlReader.name() == "foreignObject") else if (mXmlReader.name() == "foreignObject")
...@@ -698,6 +737,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -698,6 +737,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(pdfItem); scene->addItem(pdfItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(pdfItem, zFromSvg);
if (isBackground) if (isBackground)
scene->setAsBackgroundObject(pdfItem); scene->setAsBackgroundObject(pdfItem);
...@@ -720,6 +762,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -720,6 +762,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(appleWidgetItem); scene->addItem(appleWidgetItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg);
appleWidgetItem->show(); appleWidgetItem->show();
currentWidget = appleWidgetItem; currentWidget = appleWidgetItem;
...@@ -740,6 +785,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -740,6 +785,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene->addItem(w3cWidgetItem); scene->addItem(w3cWidgetItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg);
w3cWidgetItem->show(); w3cWidgetItem->show();
currentWidget = w3cWidgetItem; currentWidget = w3cWidgetItem;
...@@ -756,6 +804,10 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -756,6 +804,10 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex); maxObjectZIndex = qMax(textItem->zValue(), maxObjectZIndex);
scene->addItem(textItem); scene->addItem(textItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(textItem, zFromSvg);
textItem->show(); textItem->show();
} }
} }
...@@ -2009,6 +2061,17 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g ...@@ -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) void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsItemToSvg(QGraphicsItem* item)
{ {
......
...@@ -134,6 +134,8 @@ class UBSvgSubsetAdaptor ...@@ -134,6 +134,8 @@ class UBSvgSubsetAdaptor
void graphicsItemFromSvg(QGraphicsItem* gItem); void graphicsItemFromSvg(QGraphicsItem* gItem);
qreal getZValueFromSvg();
QXmlStreamReader mXmlReader; QXmlStreamReader mXmlReader;
int mFileVersion; int mFileVersion;
UBDocumentProxy *mProxy; UBDocumentProxy *mProxy;
......
...@@ -62,7 +62,7 @@ struct UBSize ...@@ -62,7 +62,7 @@ struct UBSize
}; };
}; };
// Deprecated. Keep it for backward campability with old versions
struct UBItemLayerType struct UBItemLayerType
{ {
enum Enum enum Enum
...@@ -71,17 +71,37 @@ struct UBItemLayerType ...@@ -71,17 +71,37 @@ struct UBItemLayerType
}; };
}; };
struct itemLayerType
{
enum Enum {
NoLayer = 0
, BackgroundItem
, ObjectItem
, DrawingItem
, ToolItem
, CppTool
, Eraiser
, Curtain
, Pointer
, Cache
};
};
struct UBGraphicsItemData struct UBGraphicsItemData
{ {
enum Enum enum Enum
{ {
ItemLayerType ItemLayerType //Deprecated. Keep it for backward campability with old versions. Use itemLayerType instead
, ItemLocked , ItemLocked
, ItemEditable//for text only , ItemEditable//for text only
, ItemOwnZValue , ItemOwnZValue
, itemLayerType //use instead of deprecated ItemLayerType
}; };
}; };
struct UBGraphicsItemType struct UBGraphicsItemType
{ {
enum Enum enum Enum
......
...@@ -64,6 +64,8 @@ UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsIte ...@@ -64,6 +64,8 @@ UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsIte
mDelegate->frame()->setOperationMode ( UBGraphicsDelegateFrame::Resizing ); 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) void UBGraphicsAudioItem::onStateChanged(Phonon::State newState, Phonon::State oldState)
......
...@@ -76,18 +76,26 @@ void UBGraphicsItemDelegate::init() ...@@ -76,18 +76,26 @@ void UBGraphicsItemDelegate::init()
UBGraphicsItem::assignZValue(mFrame, UBGraphicsScene::toolLayerStart + 1); UBGraphicsItem::assignZValue(mFrame, UBGraphicsScene::toolLayerStart + 1);
mFrame->setFlag(QGraphicsItem::ItemIsSelectable, true); 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; mButtons << mDeleteButton;
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove()));
if (canDuplicate()){ 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())); connect(mDuplicateButton, SIGNAL(clicked(bool)), this, SLOT(duplicate()));
mButtons << mDuplicateButton; 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())); connect(mMenuButton, SIGNAL(clicked()), this, SLOT(showMenu()));
mButtons << mMenuButton; 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(); buildButtons();
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
...@@ -238,10 +246,13 @@ void UBGraphicsItemDelegate::positionHandles() ...@@ -238,10 +246,13 @@ void UBGraphicsItemDelegate::positionHandles()
mDeleteButton->setTransform(tr); mDeleteButton->setTransform(tr);
qreal x = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2; qreal topX = mFrame->rect().left()- mDeleteButton->renderer()->viewBox().width() * mAntiScaleRatio / 2;
qreal y = mFrame->rect().top() - mDeleteButton->renderer()->viewBox().height() * 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()) if (!mDeleteButton->scene())
{ {
...@@ -257,12 +268,18 @@ void UBGraphicsItemDelegate::positionHandles() ...@@ -257,12 +268,18 @@ void UBGraphicsItemDelegate::positionHandles()
lock(isLocked()); lock(isLocked());
for(int i = 1 ; i < mButtons.length(); i++) int i = 1, j = 0, k = 0;
{ while ((i + j) < mButtons.size()) {
DelegateButton* button = mButtons[i]; DelegateButton* button = mButtons[i + j];
button->setTransform(tr); 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()) if (!button->scene())
{ {
button->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene button->setParentItem(mFrame);//update parent for the case the item has been previously removed from scene
...@@ -271,9 +288,7 @@ void UBGraphicsItemDelegate::positionHandles() ...@@ -271,9 +288,7 @@ void UBGraphicsItemDelegate::positionHandles()
} }
button->show(); button->show();
} }
} } else {
else
{
foreach(DelegateButton* button, mButtons) foreach(DelegateButton* button, mButtons)
button->hide(); button->hide();
...@@ -316,7 +331,19 @@ void UBGraphicsItemDelegate::duplicate() ...@@ -316,7 +331,19 @@ void UBGraphicsItemDelegate::duplicate()
UBApplication::boardController->copy(); UBApplication::boardController->copy();
UBApplication::boardController->paste(); 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) void UBGraphicsItemDelegate::lock(bool locked)
{ {
......
...@@ -33,10 +33,11 @@ class DelegateButton: public QGraphicsSvgItem ...@@ -33,10 +33,11 @@ class DelegateButton: public QGraphicsSvgItem
Q_OBJECT Q_OBJECT
public: 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) : QGraphicsSvgItem(fileName, parent)
, mDelegated(pDelegated) , mDelegated(pDelegated)
, mIsTransparentToMouseEvent(false) , mIsTransparentToMouseEvent(false)
, mButtonAlignmentSection(section)
{ {
setAcceptedMouseButtons(Qt::LeftButton); setAcceptedMouseButtons(Qt::LeftButton);
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
...@@ -57,6 +58,9 @@ class DelegateButton: public QGraphicsSvgItem ...@@ -57,6 +58,9 @@ class DelegateButton: public QGraphicsSvgItem
QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this)); QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this));
} }
void setSection(Qt::WindowFrameSection section) {mButtonAlignmentSection = section;}
Qt::WindowFrameSection getSection() const {return mButtonAlignmentSection;}
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
...@@ -80,7 +84,9 @@ class DelegateButton: public QGraphicsSvgItem ...@@ -80,7 +84,9 @@ class DelegateButton: public QGraphicsSvgItem
QGraphicsItem* mDelegated; QGraphicsItem* mDelegated;
bool mIsTransparentToMouseEvent; bool mIsTransparentToMouseEvent;
Qt::WindowFrameSection mButtonAlignmentSection;
signals: signals:
void clicked (bool checked = false); void clicked (bool checked = false);
...@@ -142,6 +148,9 @@ class UBGraphicsItemDelegate : public QObject ...@@ -142,6 +148,9 @@ class UBGraphicsItemDelegate : public QObject
virtual void lock(bool lock); virtual void lock(bool lock);
virtual void duplicate(); virtual void duplicate();
virtual void increaseZLevel() {increaseZLevel(1);}
virtual void decreaseZLevel() {increaseZLevel(-1);}
protected: protected:
virtual void buildButtons() {;} virtual void buildButtons() {;}
virtual void decorateMenu(QMenu *menu); virtual void decorateMenu(QMenu *menu);
...@@ -149,10 +158,15 @@ class UBGraphicsItemDelegate : public QObject ...@@ -149,10 +158,15 @@ class UBGraphicsItemDelegate : public QObject
QGraphicsItem* mDelegated; QGraphicsItem* mDelegated;
//buttons from the top left section of delegate frame
DelegateButton* mDeleteButton; DelegateButton* mDeleteButton;
DelegateButton* mDuplicateButton; DelegateButton* mDuplicateButton;
DelegateButton* mMenuButton; DelegateButton* mMenuButton;
//buttons from the bottom left section of delegate frame
DelegateButton *mZOrderUpButton;
DelegateButton *mZOrderDownButton;
QMenu* mMenu; QMenu* mMenu;
QAction* mLockAction; QAction* mLockAction;
...@@ -171,6 +185,8 @@ protected slots: ...@@ -171,6 +185,8 @@ protected slots:
private: private:
virtual void increaseZLevel(int delta);
QPointF mOffset; QPointF mOffset;
QTransform mPreviousTransform; QTransform mPreviousTransform;
QPointF mPreviousPosition; QPointF mPreviousPosition;
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGraphicsItem* parent) UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGraphicsItem* parent)
: GraphicsPDFItem(renderer, pageNumber, 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 = new UBGraphicsItemDelegate(this,0);
mDelegate->init(); mDelegate->init();
} }
......
...@@ -33,6 +33,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) ...@@ -33,6 +33,7 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent)
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
setTransformationMode(Qt::SmoothTransformation); 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); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
} }
......
...@@ -30,6 +30,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (QGraphicsItem * parent) ...@@ -30,6 +30,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (QGraphicsItem * parent)
, mStroke(0) , mStroke(0)
{ {
// NOOP // NOOP
initialize();
} }
...@@ -40,6 +41,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi ...@@ -40,6 +41,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi
, mStroke(0) , mStroke(0)
{ {
// NOOP // NOOP
initialize();
} }
...@@ -51,6 +53,12 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth) ...@@ -51,6 +53,12 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth)
, mStroke(0) , mStroke(0)
{ {
// NOOP // 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() void UBGraphicsPolygonItem::clearStroke()
......
...@@ -35,6 +35,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem ...@@ -35,6 +35,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
~UBGraphicsPolygonItem(); ~UBGraphicsPolygonItem();
void initialize();
void setColor(const QColor& color); void setColor(const QColor& color);
QColor color() const; QColor color() const;
......
This diff is collapsed.
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "UBItem.h" #include "UBItem.h"
#include "tools/UBGraphicsCurtainItem.h" #include "tools/UBGraphicsCurtainItem.h"
class UBGraphicsPixmapItem; class UBGraphicsPixmapItem;
class UBGraphicsProxyWidget; class UBGraphicsProxyWidget;
class UBGraphicsSvgItem; class UBGraphicsSvgItem;
...@@ -50,11 +49,41 @@ class UBGraphicsCache; ...@@ -50,11 +49,41 @@ class UBGraphicsCache;
const double PI = 4.0 * atan(1.0); 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<itemLayerType::Enum, ItemLayerTypeData> 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 class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
{ {
Q_OBJECT Q_OBJECT
public: public:
// tmp stub for divide addings scene objects from undo mechanism implementation // tmp stub for divide addings scene objects from undo mechanism implementation
void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} void setURStackEnable(bool set = true) {enableUndoRedoStack = set;}
...@@ -323,6 +352,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem ...@@ -323,6 +352,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
private: private:
void setDocumentUpdated(); void setDocumentUpdated();
qreal generateZLevel(QGraphicsItem *item);
qreal mDrawingZIndex; qreal mDrawingZIndex;
qreal mObjectZIndex; qreal mObjectZIndex;
...@@ -376,7 +406,10 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem ...@@ -376,7 +406,10 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBMagnifier *magniferControlViewWidget; UBMagnifier *magniferControlViewWidget;
UBMagnifier *magniferDisplayViewWidget; UBMagnifier *magniferDisplayViewWidget;
UBZLayerController mZLayerController;
}; };
#endif /* UBGRAPHICSSCENE_H_ */ #endif /* UBGRAPHICSSCENE_H_ */
...@@ -37,7 +37,6 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QString& pFilePath, QGraphicsItem* pa ...@@ -37,7 +37,6 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QString& pFilePath, QGraphicsItem* pa
} }
} }
UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* parent) UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* parent)
: QGraphicsSvgItem(parent) : QGraphicsSvgItem(parent)
{ {
...@@ -47,6 +46,8 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem* ...@@ -47,6 +46,8 @@ UBGraphicsSvgItem::UBGraphicsSvgItem(const QByteArray& pFileData, QGraphicsItem*
setSharedRenderer(renderer); setSharedRenderer(renderer);
mFileData = pFileData; mFileData = pFileData;
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
} }
......
...@@ -40,23 +40,11 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) ...@@ -40,23 +40,11 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
mTypeTextHereLabel = tr("<Type Text Here>"); mTypeTextHereLabel = tr("<Type Text Here>");
// 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::ItemLayerType, UBItemLayerType::Object);
// setData(UBGraphicsItemData::ItemEditable, QVariant(true)); // 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::ItemIsSelectable, true);
// setFlag(QGraphicsItem::ItemIsMovable, true); // setFlag(QGraphicsItem::ItemIsMovable, true);
......
...@@ -96,10 +96,10 @@ void UBGraphicsTextItemDelegate::buildButtons() ...@@ -96,10 +96,10 @@ void UBGraphicsTextItemDelegate::buildButtons()
{ {
UBGraphicsItemDelegate::buildButtons(); UBGraphicsItemDelegate::buildButtons();
mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame); mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection);
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame); mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mFrame, Qt::TopLeftSection);
mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame); mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TopLeftSection);
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame); mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mFrame, Qt::TopLeftSection);
connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont())); connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont()));
connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor())); connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor()));
......
...@@ -51,6 +51,8 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl& pVideoFileUrl, QGraphicsIte ...@@ -51,6 +51,8 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl& pVideoFileUrl, QGraphicsIte
mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); 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(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool)));
connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool))); connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool)));
} }
......
...@@ -39,6 +39,7 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType ...@@ -39,6 +39,7 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType
UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this, widgetType); UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this, widgetType);
delegate->init(); delegate->init();
setDelegate(delegate); 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() ...@@ -154,6 +155,8 @@ void UBGraphicsWidgetItem::initialize()
if (mDelegate && mDelegate->frame() && mWebKitWidget->resizable()) if (mDelegate && mDelegate->frame() && mWebKitWidget->resizable())
mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <QtGui> #include <QtGui>
#include "domain/UBGraphicsItemDelegate.h" #include "domain/UBGraphicsItemDelegate.h"
#include "core/UB.h"
class UBGraphicsScene; class UBGraphicsScene;
......
...@@ -48,6 +48,7 @@ UBAbstractDrawRuler::UBAbstractDrawRuler() ...@@ -48,6 +48,7 @@ UBAbstractDrawRuler::UBAbstractDrawRuler()
QDesktopWidget* desktop = UBApplication::desktop(); QDesktopWidget* desktop = UBApplication::desktop();
int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
sPixelsPerMillimeter = qRound(dpiCommon / 25.4f);//because 1inch = 25.4 mm sPixelsPerMillimeter = qRound(dpiCommon / 25.4f);//because 1inch = 25.4 mm
} }
void UBAbstractDrawRuler::create(QGraphicsItem& item) void UBAbstractDrawRuler::create(QGraphicsItem& item)
......
...@@ -33,14 +33,12 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem() ...@@ -33,14 +33,12 @@ UBGraphicsCache::UBGraphicsCache():QGraphicsRectItem()
// Get the board size and pass it to the shape // Get the board size and pass it to the shape
QRect boardRect = UBApplication::boardController->displayView()->rect(); QRect boardRect = UBApplication::boardController->displayView()->rect();
setRect(-15*boardRect.width(), -15*boardRect.height(), 30*boardRect.width(), 30*boardRect.height()); 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(Qt::UserRole, QVariant("Cache"));
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Cache)); //Necessary to set if we want z value to be assigned correctly
} }
UBGraphicsCache::~UBGraphicsCache() UBGraphicsCache::~UBGraphicsCache()
{ {
} }
UBItem* UBGraphicsCache::deepCopy() const UBItem* UBGraphicsCache::deepCopy() const
...@@ -92,8 +90,6 @@ void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *o ...@@ -92,8 +90,6 @@ void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
Q_UNUSED(option); Q_UNUSED(option);
Q_UNUSED(widget); Q_UNUSED(widget);
UBGraphicsItem::assignZValue(this, CACHE_ZVALUE);
painter->setBrush(mMaskColor); painter->setBrush(mMaskColor);
painter->setPen(mMaskColor); painter->setPen(mMaskColor);
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "core/UB.h" #include "core/UB.h"
#define CACHE_ZVALUE 100000
typedef enum typedef enum
{ {
eMaskShape_Circle, eMaskShape_Circle,
......
...@@ -70,6 +70,8 @@ UBGraphicsCompass::UBGraphicsCompass() ...@@ -70,6 +70,8 @@ UBGraphicsCompass::UBGraphicsCompass()
unsetCursor(); 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(UBApplication::boardController, SIGNAL(penColorChanged()), this, SLOT(penColorChanged()));
connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged())); connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged()));
} }
......
...@@ -49,6 +49,8 @@ UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) ...@@ -49,6 +49,8 @@ UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent)
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Tool); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Tool);
setPen(Qt::NoPen); setPen(Qt::NoPen);
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::Curtain)); //Necessary to set if we want z value to be assigned correctly
} }
UBGraphicsCurtainItem::~UBGraphicsCurtainItem() UBGraphicsCurtainItem::~UBGraphicsCurtainItem()
......
...@@ -63,6 +63,7 @@ UBGraphicsProtractor::UBGraphicsProtractor() ...@@ -63,6 +63,7 @@ UBGraphicsProtractor::UBGraphicsProtractor()
mRotateSvgItem->setVisible(false); mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); 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); scale(1.5, 1.5);
} }
......
...@@ -44,6 +44,8 @@ UBGraphicsRuler::UBGraphicsRuler() ...@@ -44,6 +44,8 @@ UBGraphicsRuler::UBGraphicsRuler()
create(*this); create(*this);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly
updateResizeCursor(); updateResizeCursor();
} }
......
...@@ -43,8 +43,8 @@ UBGraphicsTriangle::UBGraphicsTriangle() ...@@ -43,8 +43,8 @@ UBGraphicsTriangle::UBGraphicsTriangle()
mHFlipSvgItem = new QGraphicsSvgItem(":/images/hflipTool.svg", this); mHFlipSvgItem = new QGraphicsSvgItem(":/images/hflipTool.svg", this);
mHFlipSvgItem->setVisible(false); 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 = new QGraphicsSvgItem(":/images/vflipTool.svg", this);
mVFlipSvgItem->setVisible(false); mVFlipSvgItem->setVisible(false);
...@@ -54,6 +54,8 @@ UBGraphicsTriangle::UBGraphicsTriangle() ...@@ -54,6 +54,8 @@ UBGraphicsTriangle::UBGraphicsTriangle()
mRotateSvgItem->setVisible(false); mRotateSvgItem->setVisible(false);
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); 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(); updateResizeCursor();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment