diff --git a/src/core/UB.h b/src/core/UB.h index bb197d95..0b9e285c 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -137,6 +137,7 @@ struct UBGraphicsItemData //Duplicating delegate's functions to make possible working with pure QGraphicsItem , ItemFlippable // (bool) , ItemRotatable // (bool) + , ItemCanBeSetAsBackground }; }; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index f7f76f5c..c21b9bd1 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -596,6 +596,18 @@ void UBGraphicsItemDelegate::showHide(bool show) emit showOnDisplayChanged(show); } +void UBGraphicsItemDelegate::setAsBackground() +{ + UBGraphicsScene* scene = castUBGraphicsScene(); + QGraphicsItem* item = delegated(); + + if (scene && item) { + item->resetTransform(); + item->setPos(item->sceneBoundingRect().width()/-2., item->sceneBoundingRect().height()/-2.); + + scene->setAsBackgroundObject(item); + } +} void UBGraphicsItemDelegate::gotoContentSource() { @@ -681,6 +693,11 @@ void UBGraphicsItemDelegate::decorateMenu(QMenu* menu) showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off); mShowOnDisplayAction->setIcon(showIcon); + if (delegated()->data(UBGraphicsItemData::ItemCanBeSetAsBackground).toBool()) { + mSetAsBackgroundAction = mMenu->addAction(tr("Set as background"), this, SLOT(setAsBackground())); + mSetAsBackgroundAction->setCheckable(false); + } + if (testUBFlags(GF_SHOW_CONTENT_SOURCE)) { mGotoContentSourceAction = menu->addAction(tr("Go to Content Source"), this, SLOT(gotoContentSource())); diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index ef9f1e0f..ad249dc1 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -343,6 +343,7 @@ class UBGraphicsItemDelegate : public QObject QAction* mLockAction; QAction* mShowOnDisplayAction; + QAction* mSetAsBackgroundAction; QAction* mGotoContentSourceAction; UBGraphicsDelegateFrame* mFrame; @@ -354,6 +355,7 @@ class UBGraphicsItemDelegate : public QObject UBGraphicsToolBarItem* mToolBarItem; protected slots: + virtual void setAsBackground(); virtual void gotoContentSource(); private: diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 6a5e6072..b5dacc78 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -61,6 +61,8 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + setData(UBGraphicsItemData::ItemCanBeSetAsBackground, true); + setUuid(QUuid::createUuid()); //more logical solution is in creating uuid for element in element's constructor } diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 81f81333..90c188ab 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -87,6 +87,8 @@ void UBGraphicsSvgItem::init() setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + setData(UBGraphicsItemData::ItemCanBeSetAsBackground, true); + setUuid(QUuid::createUuid()); }