parent
0eed7eef6b
commit
9bd20fdba6
@ -0,0 +1,86 @@ |
||||
#include "ubgraphicsgroupcontaineritem.h" |
||||
|
||||
#include <QtGui> |
||||
|
||||
#include "domain/UBGraphicsItemDelegate.h" |
||||
#include "domain/ubgraphicsgroupcontaineritemdelegate.h" |
||||
#include "domain/UBGraphicsScene.h" |
||||
|
||||
UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent) |
||||
: QGraphicsItemGroup(parent) |
||||
{ |
||||
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); |
||||
|
||||
mDelegate = new UBGraphicsGroupContainerItemDelegate(this, 0); |
||||
mDelegate->init(); |
||||
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); |
||||
setFlag(QGraphicsItem::ItemIsSelectable, true); |
||||
setFlag(QGraphicsItem::ItemIsMovable, true); |
||||
|
||||
UBGraphicsGroupContainerItem::setAcceptHoverEvents(true); |
||||
|
||||
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
|
||||
} |
||||
|
||||
|
||||
UBGraphicsScene *UBGraphicsGroupContainerItem::scene() |
||||
{ |
||||
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(scene()); |
||||
|
||||
return castScene; |
||||
} |
||||
UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const |
||||
{ |
||||
|
||||
UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem(parentItem()); |
||||
|
||||
copy->setPos(this->pos()); |
||||
copy->setTransform(this->transform()); |
||||
copy->setFlag(QGraphicsItem::ItemIsMovable, true); |
||||
copy->setFlag(QGraphicsItem::ItemIsSelectable, true); |
||||
copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); |
||||
copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); |
||||
copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable
|
||||
|
||||
// copy->resize(this->size());
|
||||
|
||||
return copy; |
||||
} |
||||
void UBGraphicsGroupContainerItem::remove() |
||||
{ |
||||
if (mDelegate) |
||||
mDelegate->remove(); |
||||
} |
||||
|
||||
|
||||
void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
||||
{ |
||||
if (mDelegate->mousePressEvent(event)) { |
||||
//NOOP
|
||||
} else { |
||||
QGraphicsItemGroup::mousePressEvent(event); |
||||
setSelected(true); |
||||
} |
||||
} |
||||
|
||||
void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
||||
{ |
||||
if (mDelegate->mouseMoveEvent(event)) { |
||||
// NOOP;
|
||||
} else { |
||||
QGraphicsItemGroup::mouseMoveEvent(event); |
||||
} |
||||
} |
||||
|
||||
void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
||||
{ |
||||
mDelegate->mouseReleaseEvent(event); |
||||
QGraphicsItemGroup::mouseReleaseEvent(event); |
||||
} |
||||
|
||||
QVariant UBGraphicsGroupContainerItem::itemChange(GraphicsItemChange change, const QVariant &value) |
||||
{ |
||||
QVariant newValue = mDelegate->itemChange(change, value); |
||||
return QGraphicsItemGroup::itemChange(change, newValue); |
||||
} |
@ -0,0 +1,32 @@ |
||||
#ifndef UBGRAPHICSGROUPCONTAINERITEM_H |
||||
#define UBGRAPHICSGROUPCONTAINERITEM_H |
||||
|
||||
#include <QGraphicsItem> |
||||
|
||||
#include "domain/UBItem.h" |
||||
|
||||
class UBGraphicsGroupContainerItem : public QGraphicsItemGroup, public UBItem, public UBGraphicsItem |
||||
{ |
||||
|
||||
public: |
||||
UBGraphicsGroupContainerItem (QGraphicsItem *parent = 0); |
||||
virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} |
||||
|
||||
virtual UBGraphicsScene* scene(); |
||||
virtual UBGraphicsGroupContainerItem *deepCopy() const; |
||||
virtual void remove(); |
||||
|
||||
|
||||
protected: |
||||
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); |
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
||||
|
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); |
||||
|
||||
private: |
||||
|
||||
}; |
||||
|
||||
#endif // UBGRAPHICSGROUPCONTAINERITEM_H
|
@ -0,0 +1,58 @@ |
||||
#include "ubgraphicsgroupcontaineritemdelegate.h" |
||||
|
||||
#include <QtGui> |
||||
|
||||
#include "UBGraphicsScene.h" |
||||
#include "gui/UBResources.h" |
||||
|
||||
#include "domain/UBGraphicsDelegateFrame.h" |
||||
#include "domain/ubgraphicsgroupcontaineritem.h" |
||||
|
||||
#include "core/memcheck.h" |
||||
#include "board/UBBoardController.h" |
||||
|
||||
UBGraphicsGroupContainerItemDelegate::UBGraphicsGroupContainerItemDelegate(QGraphicsItem *pDelegated, QObject *parent) : |
||||
UBGraphicsItemDelegate(pDelegated, parent), mDestroyGroupButton(0) |
||||
|
||||
{ |
||||
|
||||
} |
||||
|
||||
UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItemDelegate::delegated() |
||||
{ |
||||
return dynamic_cast<UBGraphicsGroupContainerItem*>(mDelegated); |
||||
} |
||||
|
||||
void UBGraphicsGroupContainerItemDelegate::decorateMenu(QMenu *menu) |
||||
{ |
||||
mLockAction = menu->addAction(tr("Locked"), this, SLOT(lock(bool))); |
||||
QIcon lockIcon; |
||||
lockIcon.addPixmap(QPixmap(":/images/locked.svg"), QIcon::Normal, QIcon::On); |
||||
lockIcon.addPixmap(QPixmap(":/images/unlocked.svg"), QIcon::Normal, QIcon::Off); |
||||
mLockAction->setIcon(lockIcon); |
||||
mLockAction->setCheckable(true); |
||||
|
||||
mShowOnDisplayAction = mMenu->addAction(tr("Visible on Extended Screen"), this, SLOT(showHide(bool))); |
||||
mShowOnDisplayAction->setCheckable(true); |
||||
|
||||
QIcon showIcon; |
||||
showIcon.addPixmap(QPixmap(":/images/eyeOpened.svg"), QIcon::Normal, QIcon::On); |
||||
showIcon.addPixmap(QPixmap(":/images/eyeClosed.svg"), QIcon::Normal, QIcon::Off); |
||||
mShowOnDisplayAction->setIcon(showIcon); |
||||
} |
||||
|
||||
void UBGraphicsGroupContainerItemDelegate::buildButtons() |
||||
{ |
||||
UBGraphicsItemDelegate::buildButtons(); |
||||
|
||||
mDestroyGroupButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection); |
||||
|
||||
mButtons << mDestroyGroupButton; |
||||
|
||||
connect(mDestroyGroupButton, SIGNAL(clicked()), this, SLOT(destroyGroup())); |
||||
} |
||||
|
||||
void UBGraphicsGroupContainerItemDelegate::destroyGroup() |
||||
{ |
||||
castUBGraphicsScene()->destroyItemGroup(delegated()); |
||||
} |
@ -0,0 +1,29 @@ |
||||
#ifndef UBGRAPHICSGROUPCONTAINERITEMDELEGATE_H |
||||
#define UBGRAPHICSGROUPCONTAINERITEMDELEGATE_H |
||||
|
||||
#include "domain/UBGraphicsItemDelegate.h" |
||||
|
||||
class UBGraphicsGroupContainerItem; |
||||
|
||||
class UBGraphicsGroupContainerItemDelegate : public UBGraphicsItemDelegate |
||||
{ |
||||
public: |
||||
UBGraphicsGroupContainerItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0); |
||||
|
||||
UBGraphicsGroupContainerItem *delegated(); |
||||
|
||||
protected: |
||||
virtual void decorateMenu(QMenu *menu); |
||||
virtual void buildButtons(); |
||||
|
||||
|
||||
|
||||
|
||||
private slots: |
||||
void destroyGroup(); |
||||
|
||||
private: |
||||
DelegateButton *mDestroyGroupButton; |
||||
}; |
||||
|
||||
#endif // UBGRAPHICSGROUPCONTAINERITEMDELEGATE_H
|
Loading…
Reference in new issue