Grouping items available

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent 0eed7eef6b
commit 9bd20fdba6
  1. 16
      resources/forms/mainWindow.ui
  2. 4
      src/board/UBBoardView.cpp
  3. 13
      src/domain/UBGraphicsPolygonItem.cpp
  4. 2
      src/domain/UBGraphicsPolygonItem.h
  5. 46
      src/domain/UBGraphicsScene.cpp
  6. 4
      src/domain/UBGraphicsScene.h
  7. 8
      src/domain/domain.pri
  8. 86
      src/domain/ubgraphicsgroupcontaineritem.cpp
  9. 32
      src/domain/ubgraphicsgroupcontaineritem.h
  10. 58
      src/domain/ubgraphicsgroupcontaineritemdelegate.cpp
  11. 29
      src/domain/ubgraphicsgroupcontaineritemdelegate.h

@ -69,6 +69,7 @@
<addaction name="actionForward"/>
<addaction name="separator"/>
<addaction name="actionErase"/>
<addaction name="actionGroupItems"/>
<addaction name="actionBoard"/>
<addaction name="actionTutorial"/>
<addaction name="actionWeb"/>
@ -1633,6 +1634,21 @@
<string>Import old Sankore or Uniboard documents</string>
</property>
</action>
<action name="actionGroupItems">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../sankore.qrc">
<normaloff>:/images/toolbar/library.png</normaloff>:/images/toolbar/library.png</iconset>
</property>
<property name="text">
<string>Gtorup items</string>
</property>
<property name="toolTip">
<string>Erase Content</string>
</property>
</action>
</widget>
<resources>
<include location="../sankore.qrc"/>

@ -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);

@ -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()
{

@ -115,6 +115,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
QPainterPath shape () const;
private:

@ -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<QGraphicsItem *> &itemList)
{
foreach (QGraphicsItem *item, itemList) {
qDebug() << "selected item found";
item->setSelected(false);
}
}
qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest)
{

@ -287,6 +287,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void setSelectedZLevel(QGraphicsItem *item);
void setOwnZlevel(QGraphicsItem *item);
void groupItems(QList<QGraphicsItem *> &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();

@ -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 \

@ -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…
Cancel
Save