diff --git a/resources/forms/mainWindow.ui b/resources/forms/mainWindow.ui index 7704a319..f8c9ba81 100644 --- a/resources/forms/mainWindow.ui +++ b/resources/forms/mainWindow.ui @@ -69,6 +69,7 @@ + @@ -1633,6 +1634,21 @@ Import old Sankore or Uniboard documents + + + false + + + + :/images/toolbar/library.png:/images/toolbar/library.png + + + Gtorup items + + + Erase Content + + diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index c383588a..74bd37bc 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -440,7 +440,9 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsPolygonItem::Type || movingItem->type() == UBGraphicsCache::Type || movingItem->type() == UBGraphicsTriangle::Type - || movingItem == this->scene()->backgroundObject()) + || movingItem == this->scene()->backgroundObject() + || movingItem->group()) + { movingItem = NULL; QGraphicsView::mousePressEvent (event); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 7608e20e..8f6850ce 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -185,6 +185,19 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi QGraphicsPolygonItem::paint(painter, option, widget); } +QPainterPath UBGraphicsPolygonItem::shape() const +{ + + QPainterPath path; + path.addRect(boundingRect()); + + return path; + +// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); + +// return shapePath; +} + UBGraphicsScene* UBGraphicsPolygonItem::scene() { diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 22dfe712..8477ebe9 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -115,6 +115,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem protected: void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); + QPainterPath shape () const; + private: diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 9cdbb279..b7626211 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -30,6 +30,7 @@ #include "core/UBPersistenceManager.h" #include "gui/UBMagnifer.h" +#include "gui/UBMainWindow.h" #include "tools/UBGraphicsRuler.h" #include "tools/UBGraphicsProtractor.h" @@ -54,6 +55,7 @@ #include "UBGraphicsWidgetItem.h" #include "UBGraphicsPDFItem.h" #include "UBGraphicsTextItem.h" +#include "domain/ubgraphicsgroupcontaineritem.h" #include "UBAppleWidget.h" #include "UBW3CWidget.h" @@ -157,9 +159,6 @@ qreal UBZLayerController::changeZLevelTo(QGraphicsItem *item, moveDestination de while (iCurElement.hasNext() && iCurElement.peekNext().value()->data(UBGraphicsItemData::ItemOwnZValue).toReal() == nextZ) { UBGraphicsItem::assignZValue(iCurElement.next().value(), nextZ); } - - item->scene()->clearSelection(); - item->setSelected(true); } } @@ -289,6 +288,9 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) } connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); + connect(this, SIGNAL(selectionChanged()), this, SLOT(enableGroupingButton())); + + connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(processGroupItems())); } UBGraphicsScene::~UBGraphicsScene() @@ -307,6 +309,36 @@ void UBGraphicsScene::selectionChangedProcessing() UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); } +void UBGraphicsScene::enableGroupingButton() +{ + QAction *groupAction = UBApplication::mainWindow->actionGroupItems; + + if (selectedItems().count() > 1) { + groupAction->setEnabled(true); + } else { + groupAction->setEnabled(false); + } +} +void UBGraphicsScene::processGroupItems() +{ + qDebug() << "processing grouping items"; + + UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); + + foreach (QGraphicsItem *item, selectedItems()) { + item->setSelected(false); + item->setFlag(QGraphicsItem::ItemIsSelectable, false); + item->setFlag( QGraphicsItem::ItemIsMovable, false); + item->setFlag(QGraphicsItem::ItemIsFocusable); + groupItem->addToGroup(item); + } + + addItem(groupItem); +// groupItem->setPos(50, 50); + groupItem->setVisible(true); + groupItem->setFocus(); + qDebug() << groupItem->boundingRect(); +} // MARK: - // MARK: Mouse/Tablet events handling @@ -1916,6 +1948,14 @@ void UBGraphicsScene::setOwnZlevel(QGraphicsItem *item) { item->setZValue(item->data(UBGraphicsItemData::ItemOwnZValue).toReal()); } +void UBGraphicsScene::groupItems(QList &itemList) +{ + foreach (QGraphicsItem *item, itemList) { + qDebug() << "selected item found"; + item->setSelected(false); + } +} + qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 96794931..ae2bb8e1 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -287,6 +287,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem void setSelectedZLevel(QGraphicsItem *item); void setOwnZlevel(QGraphicsItem *item); + + void groupItems(QList &itemList); public slots: void hideEraser(); @@ -303,6 +305,8 @@ public slots: void setToolCursor(int tool); void selectionChangedProcessing(); + void enableGroupingButton(); + void processGroupItems(); void moveMagnifier(QPoint newPos); void closeMagnifier(); diff --git a/src/domain/domain.pri b/src/domain/domain.pri index a2d126ac..c43c490b 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -23,7 +23,9 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsAudioItem.h \ src/domain/UBGraphicsAudioItemDelegate.h \ src/domain/UBAbstractUndoCommand.h\ - src/domain/UBAngleWidget.h + src/domain/UBAngleWidget.h \ + src/domain/ubgraphicsgroupcontaineritem.h \ + src/domain/ubgraphicsgroupcontaineritemdelegate.h HEADERS += src/domain/UBGraphicsItemDelegate.h \ src/domain/UBGraphicsVideoItemDelegate.h \ @@ -56,7 +58,9 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsAudioItem.cpp \ src/domain/UBGraphicsAudioItemDelegate.cpp \ src/domain/UBAbstractUndoCommand.cpp \ - src/domain/UBAngleWidget.cpp + src/domain/UBAngleWidget.cpp \ + src/domain/ubgraphicsgroupcontaineritem.cpp \ + src/domain/ubgraphicsgroupcontaineritemdelegate.cpp SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ src/domain/UBGraphicsVideoItemDelegate.cpp \ diff --git a/src/domain/ubgraphicsgroupcontaineritem.cpp b/src/domain/ubgraphicsgroupcontaineritem.cpp new file mode 100644 index 00000000..0a706099 --- /dev/null +++ b/src/domain/ubgraphicsgroupcontaineritem.cpp @@ -0,0 +1,86 @@ +#include "ubgraphicsgroupcontaineritem.h" + +#include + +#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(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); +} diff --git a/src/domain/ubgraphicsgroupcontaineritem.h b/src/domain/ubgraphicsgroupcontaineritem.h new file mode 100644 index 00000000..193a3ca7 --- /dev/null +++ b/src/domain/ubgraphicsgroupcontaineritem.h @@ -0,0 +1,32 @@ +#ifndef UBGRAPHICSGROUPCONTAINERITEM_H +#define UBGRAPHICSGROUPCONTAINERITEM_H + +#include + +#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 diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp new file mode 100644 index 00000000..31ce0dfa --- /dev/null +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp @@ -0,0 +1,58 @@ +#include "ubgraphicsgroupcontaineritemdelegate.h" + +#include + +#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(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()); +} diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.h b/src/domain/ubgraphicsgroupcontaineritemdelegate.h new file mode 100644 index 00000000..ad46276a --- /dev/null +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.h @@ -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