Add "set as background" to frame menu for images

Images (UBGraphicsPixmapitem and UBGraphicsSvgItem) can be set as
background via the menu on their frame. Currently, the image is first
centered and un-transformed before being set as background.

The option in the frame appears for any UBGraphicsItem for which
`data(UBGraphicsItemData::ItemCanBeSetAsBackground)` is true.

This is (currently) only enabled for image items.
preferencesAboutTextFull
Craig Watson 8 years ago
parent ee5ad4a142
commit aedebaf2db
  1. 1
      src/core/UB.h
  2. 17
      src/domain/UBGraphicsItemDelegate.cpp
  3. 2
      src/domain/UBGraphicsItemDelegate.h
  4. 2
      src/domain/UBGraphicsPixmapItem.cpp
  5. 2
      src/domain/UBGraphicsSvgItem.cpp

@ -137,6 +137,7 @@ struct UBGraphicsItemData
//Duplicating delegate's functions to make possible working with pure QGraphicsItem //Duplicating delegate's functions to make possible working with pure QGraphicsItem
, ItemFlippable // (bool) , ItemFlippable // (bool)
, ItemRotatable // (bool) , ItemRotatable // (bool)
, ItemCanBeSetAsBackground
}; };
}; };

@ -596,6 +596,18 @@ void UBGraphicsItemDelegate::showHide(bool show)
emit showOnDisplayChanged(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() void UBGraphicsItemDelegate::gotoContentSource()
{ {
@ -681,6 +693,11 @@ void UBGraphicsItemDelegate::decorateMenu(QMenu* menu)
showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off); showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off);
mShowOnDisplayAction->setIcon(showIcon); 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)) if (testUBFlags(GF_SHOW_CONTENT_SOURCE))
{ {
mGotoContentSourceAction = menu->addAction(tr("Go to Content Source"), this, SLOT(gotoContentSource())); mGotoContentSourceAction = menu->addAction(tr("Go to Content Source"), this, SLOT(gotoContentSource()));

@ -343,6 +343,7 @@ class UBGraphicsItemDelegate : public QObject
QAction* mLockAction; QAction* mLockAction;
QAction* mShowOnDisplayAction; QAction* mShowOnDisplayAction;
QAction* mSetAsBackgroundAction;
QAction* mGotoContentSourceAction; QAction* mGotoContentSourceAction;
UBGraphicsDelegateFrame* mFrame; UBGraphicsDelegateFrame* mFrame;
@ -354,6 +355,7 @@ class UBGraphicsItemDelegate : public QObject
UBGraphicsToolBarItem* mToolBarItem; UBGraphicsToolBarItem* mToolBarItem;
protected slots: protected slots:
virtual void setAsBackground();
virtual void gotoContentSource(); virtual void gotoContentSource();
private: private:

@ -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 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);
setData(UBGraphicsItemData::ItemCanBeSetAsBackground, true);
setUuid(QUuid::createUuid()); //more logical solution is in creating uuid for element in element's constructor setUuid(QUuid::createUuid()); //more logical solution is in creating uuid for element in element's constructor
} }

@ -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::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
setData(UBGraphicsItemData::ItemCanBeSetAsBackground, true);
setUuid(QUuid::createUuid()); setUuid(QUuid::createUuid());
} }

Loading…
Cancel
Save