Commit 2429d666 authored by Craig Watson's avatar Craig Watson

Merge branch 'feature_set-image-as-background' into 1.4-dev

This adds an option to the menu of an image's frame, to set the image as
background. Undo and redo functions were also implemented.

This also removes the display of the "properties" page in the library
pane when clicking on an application, interactivity or flash animation.
For now, it was kept for other items such as images and videos.
parents ee5ad4a1 0d7d9b04
...@@ -137,6 +137,7 @@ struct UBGraphicsItemData ...@@ -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,32 @@ void UBGraphicsItemDelegate::showHide(bool show) ...@@ -596,6 +596,32 @@ void UBGraphicsItemDelegate::showHide(bool show)
emit showOnDisplayChanged(show); emit showOnDisplayChanged(show);
} }
/**
* @brief Set delegate as background for the scene, replacing any existing background.
*/
void UBGraphicsItemDelegate::setAsBackground()
{
UBGraphicsScene* scene = castUBGraphicsScene();
QGraphicsItem* item = delegated();
if (scene && item) {
startUndoStep();
item->resetTransform();
item->setPos(item->sceneBoundingRect().width()/-2., item->sceneBoundingRect().height()/-2.);
scene->setAsBackgroundObject(item);
UBGraphicsItemTransformUndoCommand *uc =
new UBGraphicsItemTransformUndoCommand(mDelegated,
mPreviousPosition,
mPreviousTransform,
mPreviousZValue,
mPreviousSize,
true);
UBApplication::undoStack->push(uc);
}
}
void UBGraphicsItemDelegate::gotoContentSource() void UBGraphicsItemDelegate::gotoContentSource()
{ {
...@@ -681,6 +707,11 @@ void UBGraphicsItemDelegate::decorateMenu(QMenu* menu) ...@@ -681,6 +707,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 ...@@ -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 ...@@ -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:
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
#include "UBGraphicsItemTransformUndoCommand.h" #include "UBGraphicsItemTransformUndoCommand.h"
#include "UBResizableGraphicsItem.h" #include "UBResizableGraphicsItem.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem, UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem,
const QPointF& prevPos, const QTransform& prevTransform, const qreal& prevZValue, const QPointF& prevPos, const QTransform& prevTransform, const qreal& prevZValue,
const QSizeF& prevSize):UBUndoCommand() const QSizeF& prevSize, bool setToBackground)
: UBUndoCommand()
{ {
mItem = pItem; mItem = pItem;
mPreviousTransform = prevTransform; mPreviousTransform = prevTransform;
...@@ -52,6 +54,8 @@ UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphics ...@@ -52,6 +54,8 @@ UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphics
if (resizableItem) if (resizableItem)
mCurrentSize = resizableItem->size(); mCurrentSize = resizableItem->size();
mSetToBackground = setToBackground;
} }
UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand() UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand()
...@@ -61,6 +65,13 @@ UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand() ...@@ -61,6 +65,13 @@ UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand()
void UBGraphicsItemTransformUndoCommand::undo() void UBGraphicsItemTransformUndoCommand::undo()
{ {
if (mSetToBackground) {
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mItem->scene());
if (scene && scene->isBackgroundObject(mItem)) {
scene->unsetBackgroundObject();
}
}
mItem->setPos(mPreviousPosition); mItem->setPos(mPreviousPosition);
mItem->setTransform(mPreviousTransform); mItem->setTransform(mPreviousTransform);
mItem->setZValue(mPreviousZValue); mItem->setZValue(mPreviousZValue);
...@@ -73,6 +84,12 @@ void UBGraphicsItemTransformUndoCommand::undo() ...@@ -73,6 +84,12 @@ void UBGraphicsItemTransformUndoCommand::undo()
void UBGraphicsItemTransformUndoCommand::redo() void UBGraphicsItemTransformUndoCommand::redo()
{ {
if (mSetToBackground) {
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mItem->scene());
if (scene)
scene->setAsBackgroundObject(mItem);
}
mItem->setPos(mCurrentPosition); mItem->setPos(mCurrentPosition);
mItem->setTransform(mCurrentTransform); mItem->setTransform(mCurrentTransform);
mItem->setZValue(mCurrentZValue); mItem->setZValue(mCurrentZValue);
......
...@@ -42,7 +42,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand ...@@ -42,7 +42,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand
const QPointF& prevPos, const QPointF& prevPos,
const QTransform& prevTransform, const QTransform& prevTransform,
const qreal& prevZValue, const qreal& prevZValue,
const QSizeF& prevSize = QSizeF()); const QSizeF& prevSize = QSizeF(),
bool setToBackground = false);
virtual ~UBGraphicsItemTransformUndoCommand(); virtual ~UBGraphicsItemTransformUndoCommand();
virtual int getType() const { return UBUndoType::undotype_GRAPHICITEMTRANSFORM; } virtual int getType() const { return UBUndoType::undotype_GRAPHICITEMTRANSFORM; }
...@@ -63,6 +64,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand ...@@ -63,6 +64,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand
qreal mPreviousZValue; qreal mPreviousZValue;
qreal mCurrentZValue; qreal mCurrentZValue;
bool mSetToBackground;
}; };
#endif /* UBGRAPHICSITEMTRANSFORMUNDOCOMMAND_H_ */ #endif /* UBGRAPHICSITEMTRANSFORMUNDOCOMMAND_H_ */
...@@ -61,6 +61,8 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) ...@@ -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
} }
......
...@@ -1983,6 +1983,21 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool ...@@ -1983,6 +1983,21 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool
return item; return item;
} }
void UBGraphicsScene::unsetBackgroundObject()
{
if (!mBackgroundObject)
return;
mBackgroundObject->setFlag(QGraphicsItem::ItemIsSelectable, true);
mBackgroundObject->setFlag(QGraphicsItem::ItemIsMovable, true);
mBackgroundObject->setAcceptedMouseButtons(Qt::LeftButton);
// Item zLayer and Layer Type should be set by the caller of this function, as
// it may depend on the object type, where it was before, etc.
mBackgroundObject = 0;
}
QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio) QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio)
{ {
......
...@@ -174,6 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem ...@@ -174,6 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void addGroup(UBGraphicsGroupContainerItem *groupItem); void addGroup(UBGraphicsGroupContainerItem *groupItem);
QGraphicsItem* setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation = false, bool expand = false); QGraphicsItem* setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation = false, bool expand = false);
void unsetBackgroundObject();
QGraphicsItem* backgroundObject() const QGraphicsItem* backgroundObject() const
{ {
......
...@@ -87,6 +87,8 @@ void UBGraphicsSvgItem::init() ...@@ -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());
} }
......
...@@ -174,7 +174,12 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current) ...@@ -174,7 +174,12 @@ void UBFeaturesWidget::currentSelected(const QModelIndex &current)
// } else if (feature.getType() == FEATURE_SEARCH) { // } else if (feature.getType() == FEATURE_SEARCH) {
// centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView); // centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturesWebView);
} else { }
// Don't show the properties page for interactivities, applications and animations
else if (feature.getType() != FEATURE_INTERACTIVE
&& feature.getType() != FEATURE_INTERNAL
&& feature.getType() != FEATURE_FLASH)
{
centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList); centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList);
mActionBar->setCurrentState( IN_PROPERTIES ); mActionBar->setCurrentState( IN_PROPERTIES );
} }
......
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