From aedebaf2dbb371c68fcebc75afd92a787299e1b4 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Sun, 29 Jan 2017 18:35:06 -0500 Subject: [PATCH 1/3] 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. --- src/core/UB.h | 1 + src/domain/UBGraphicsItemDelegate.cpp | 17 +++++++++++++++++ src/domain/UBGraphicsItemDelegate.h | 2 ++ src/domain/UBGraphicsPixmapItem.cpp | 2 ++ src/domain/UBGraphicsSvgItem.cpp | 2 ++ 5 files changed, 24 insertions(+) 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()); } From 881a1d5011ed57b1564018add6fc92823456e321 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Sun, 30 Apr 2017 15:55:05 -0400 Subject: [PATCH 2/3] Add ability to undo/redo setting image as background --- src/domain/UBGraphicsItemDelegate.cpp | 14 ++++++++++++++ .../UBGraphicsItemTransformUndoCommand.cpp | 19 ++++++++++++++++++- .../UBGraphicsItemTransformUndoCommand.h | 5 ++++- src/domain/UBGraphicsScene.cpp | 15 +++++++++++++++ src/domain/UBGraphicsScene.h | 1 + 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index c21b9bd1..99dec7cb 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -596,16 +596,30 @@ void UBGraphicsItemDelegate::showHide(bool 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); } } diff --git a/src/domain/UBGraphicsItemTransformUndoCommand.cpp b/src/domain/UBGraphicsItemTransformUndoCommand.cpp index fad0a3af..f280fd5b 100644 --- a/src/domain/UBGraphicsItemTransformUndoCommand.cpp +++ b/src/domain/UBGraphicsItemTransformUndoCommand.cpp @@ -30,12 +30,14 @@ #include "UBGraphicsItemTransformUndoCommand.h" #include "UBResizableGraphicsItem.h" #include "domain/UBItem.h" +#include "domain/UBGraphicsScene.h" #include "core/memcheck.h" UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem, const QPointF& prevPos, const QTransform& prevTransform, const qreal& prevZValue, - const QSizeF& prevSize):UBUndoCommand() + const QSizeF& prevSize, bool setToBackground) + : UBUndoCommand() { mItem = pItem; mPreviousTransform = prevTransform; @@ -52,6 +54,8 @@ UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphics if (resizableItem) mCurrentSize = resizableItem->size(); + + mSetToBackground = setToBackground; } UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand() @@ -61,6 +65,13 @@ UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand() void UBGraphicsItemTransformUndoCommand::undo() { + if (mSetToBackground) { + UBGraphicsScene* scene = dynamic_cast(mItem->scene()); + if (scene && scene->isBackgroundObject(mItem)) { + scene->unsetBackgroundObject(); + } + } + mItem->setPos(mPreviousPosition); mItem->setTransform(mPreviousTransform); mItem->setZValue(mPreviousZValue); @@ -73,6 +84,12 @@ void UBGraphicsItemTransformUndoCommand::undo() void UBGraphicsItemTransformUndoCommand::redo() { + if (mSetToBackground) { + UBGraphicsScene* scene = dynamic_cast(mItem->scene()); + if (scene) + scene->setAsBackgroundObject(mItem); + } + mItem->setPos(mCurrentPosition); mItem->setTransform(mCurrentTransform); mItem->setZValue(mCurrentZValue); diff --git a/src/domain/UBGraphicsItemTransformUndoCommand.h b/src/domain/UBGraphicsItemTransformUndoCommand.h index da67efad..9cd6b93a 100644 --- a/src/domain/UBGraphicsItemTransformUndoCommand.h +++ b/src/domain/UBGraphicsItemTransformUndoCommand.h @@ -42,7 +42,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand const QPointF& prevPos, const QTransform& prevTransform, const qreal& prevZValue, - const QSizeF& prevSize = QSizeF()); + const QSizeF& prevSize = QSizeF(), + bool setToBackground = false); virtual ~UBGraphicsItemTransformUndoCommand(); virtual int getType() const { return UBUndoType::undotype_GRAPHICITEMTRANSFORM; } @@ -63,6 +64,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand qreal mPreviousZValue; qreal mCurrentZValue; + bool mSetToBackground; + }; #endif /* UBGRAPHICSITEMTRANSFORMUNDOCOMMAND_H_ */ diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 162eba9d..efd58c41 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1983,6 +1983,21 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool 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) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 74577250..544aa34c 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -174,6 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void addGroup(UBGraphicsGroupContainerItem *groupItem); QGraphicsItem* setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation = false, bool expand = false); + void unsetBackgroundObject(); QGraphicsItem* backgroundObject() const { From 0d7d9b0424c230266bbad2a15e1aa0cca8fcd735 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Sun, 30 Apr 2017 16:09:26 -0400 Subject: [PATCH 3/3] Don't show the properties page (in library pane) for interactivities, applications and animations --- src/gui/UBFeaturesWidget.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index fe3520c7..b826ed02 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -174,7 +174,12 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) // } else if (feature.getType() == FEATURE_SEARCH) { // 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); mActionBar->setCurrentState( IN_PROPERTIES ); }