Unstable groups implementation

preferencesAboutTextFull
Ivan Ilyin 13 years ago
parent e1adcda8d9
commit 5e363a3afc
  1. 222
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 1
      src/adaptors/UBSvgSubsetAdaptor.h
  3. 10
      src/board/UBBoardController.cpp
  4. 30
      src/domain/UBGraphicsItemDelegate.cpp
  5. 16
      src/domain/UBGraphicsPolygonItem.cpp
  6. 2
      src/domain/UBGraphicsPolygonItem.h
  7. 49
      src/domain/UBGraphicsScene.cpp
  8. 3
      src/domain/UBGraphicsScene.h
  9. 45
      src/domain/ubgraphicsgroupcontaineritem.cpp
  10. 21
      src/domain/ubgraphicsgroupcontaineritemdelegate.cpp
  11. 4
      src/domain/ubgraphicsgroupcontaineritemdelegate.h

@ -30,6 +30,7 @@
#include "domain/UBAbstractWidget.h" #include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsStroke.h" #include "domain/UBGraphicsStroke.h"
#include "domain/UBGraphicsStrokesGroup.h" #include "domain/UBGraphicsStrokesGroup.h"
#include "domain/ubgraphicsgroupcontaineritem.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "tools/UBGraphicsRuler.h" #include "tools/UBGraphicsRuler.h"
@ -929,8 +930,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement()
bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene()
{ {
if (mScene->isModified()) if (mScene->isModified())
{ {
static int i = 0;
qDebug() << "persist call no is " << ++i;
QBuffer buffer; QBuffer buffer;
buffer.open(QBuffer::WriteOnly); buffer.open(QBuffer::WriteOnly);
mXmlWriter.setDevice(&buffer); mXmlWriter.setDevice(&buffer);
@ -1035,146 +1041,162 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene()
openStroke = 0; openStroke = 0;
} }
UBGraphicsPixmapItem *pixmapItem = qgraphicsitem_cast<UBGraphicsPixmapItem*> (item); UBGraphicsGroupContainerItem *groupItem = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item);
if (pixmapItem && pixmapItem->isVisible()) if (groupItem && groupItem->isVisible())
{ {
pixmapItemToLinkedImage(pixmapItem); qDebug() << "came across the group during the parsing";
continue; continue;
} }
UBGraphicsSvgItem *svgItem = qgraphicsitem_cast<UBGraphicsSvgItem*> (item); parseCommonItems(item);
}
if (svgItem && svgItem->isVisible()) if (openStroke)
{ {
svgItemToLinkedSvg(svgItem); mXmlWriter.writeEndElement();
continue; groupHoldsInfo = false;
} openStroke = 0;
}
UBGraphicsVideoItem *videoItem = qgraphicsitem_cast<UBGraphicsVideoItem*> (item); mXmlWriter.writeEndDocument();
QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1);
QFile file(fileName);
if (videoItem && videoItem->isVisible()) if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{ {
videoItemToLinkedVideo(videoItem); qCritical() << "cannot open " << fileName << " for writing ...";
continue; return false;
} }
file.write(buffer.data());
file.flush();
file.close();
UBGraphicsAudioItem* audioItem = qgraphicsitem_cast<UBGraphicsAudioItem*> (item); }
if (audioItem && audioItem->isVisible()) { else
audioItemToLinkedAudio(audioItem); {
continue; qDebug() << "ignoring unmodified page" << mPageIndex + 1;
} }
UBGraphicsAppleWidgetItem *appleWidgetItem = qgraphicsitem_cast<UBGraphicsAppleWidgetItem*> (item); return true;
}
if (appleWidgetItem && appleWidgetItem->isVisible()) bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::parseCommonItems(QGraphicsItem *item)
{ {
graphicsAppleWidgetToSvg(appleWidgetItem); UBGraphicsPixmapItem *pixmapItem = qgraphicsitem_cast<UBGraphicsPixmapItem*> (item);
continue;
}
UBGraphicsW3CWidgetItem *w3cWidgetItem = qgraphicsitem_cast<UBGraphicsW3CWidgetItem*> (item); if (pixmapItem && pixmapItem->isVisible())
{
pixmapItemToLinkedImage(pixmapItem);
return true;
}
if (w3cWidgetItem && w3cWidgetItem->isVisible()) UBGraphicsSvgItem *svgItem = qgraphicsitem_cast<UBGraphicsSvgItem*> (item);
{
graphicsW3CWidgetToSvg(w3cWidgetItem);
continue;
}
UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*> (item); if (svgItem && svgItem->isVisible())
{
svgItemToLinkedSvg(svgItem);
return true;
}
if (pdfItem && pdfItem->isVisible()) UBGraphicsVideoItem *videoItem = qgraphicsitem_cast<UBGraphicsVideoItem*> (item);
{
pdfItemToLinkedPDF(pdfItem);
continue;
}
UBGraphicsTextItem *textItem = qgraphicsitem_cast<UBGraphicsTextItem*> (item); if (videoItem && videoItem->isVisible())
{
videoItemToLinkedVideo(videoItem);
return true;
}
if (textItem && textItem->isVisible()) UBGraphicsAudioItem* audioItem = qgraphicsitem_cast<UBGraphicsAudioItem*> (item);
{ if (audioItem && audioItem->isVisible()) {
textItemToSvg(textItem); audioItemToLinkedAudio(audioItem);
continue; return true;
} }
UBGraphicsCurtainItem *curtainItem = qgraphicsitem_cast<UBGraphicsCurtainItem*> (item); UBGraphicsAppleWidgetItem *appleWidgetItem = qgraphicsitem_cast<UBGraphicsAppleWidgetItem*> (item);
if (curtainItem && curtainItem->isVisible()) if (appleWidgetItem && appleWidgetItem->isVisible())
{ {
curtainItemToSvg(curtainItem); graphicsAppleWidgetToSvg(appleWidgetItem);
continue; return true;
} }
UBGraphicsRuler *ruler = qgraphicsitem_cast<UBGraphicsRuler*> (item); UBGraphicsW3CWidgetItem *w3cWidgetItem = qgraphicsitem_cast<UBGraphicsW3CWidgetItem*> (item);
if (ruler && ruler->isVisible()) if (w3cWidgetItem && w3cWidgetItem->isVisible())
{ {
rulerToSvg(ruler); graphicsW3CWidgetToSvg(w3cWidgetItem);
continue; return true;
} }
UBGraphicsCache* cache = qgraphicsitem_cast<UBGraphicsCache*>(item); UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*> (item);
if(cache && cache->isVisible())
{
cacheToSvg(cache);
continue;
}
UBGraphicsCompass *compass = qgraphicsitem_cast<UBGraphicsCompass*> (item); if (pdfItem && pdfItem->isVisible())
{
pdfItemToLinkedPDF(pdfItem);
return true;
}
if (compass && compass->isVisible()) UBGraphicsTextItem *textItem = qgraphicsitem_cast<UBGraphicsTextItem*> (item);
{
compassToSvg(compass);
continue;
}
UBGraphicsProtractor *protractor = qgraphicsitem_cast<UBGraphicsProtractor*> (item); if (textItem && textItem->isVisible())
{
textItemToSvg(textItem);
return true;
}
if (protractor && protractor->isVisible()) UBGraphicsCurtainItem *curtainItem = qgraphicsitem_cast<UBGraphicsCurtainItem*> (item);
{
protractorToSvg(protractor);
continue;
}
UBGraphicsTriangle *triangle = qgraphicsitem_cast<UBGraphicsTriangle*> (item); if (curtainItem && curtainItem->isVisible())
{
curtainItemToSvg(curtainItem);
return true;
}
if (triangle && triangle->isVisible()) UBGraphicsRuler *ruler = qgraphicsitem_cast<UBGraphicsRuler*> (item);
{
triangleToSvg(triangle);
continue;
}
}
if (openStroke) if (ruler && ruler->isVisible())
{ {
mXmlWriter.writeEndElement(); rulerToSvg(ruler);
groupHoldsInfo = false; return true;
openStroke = 0; }
}
mXmlWriter.writeEndDocument(); UBGraphicsCache* cache = qgraphicsitem_cast<UBGraphicsCache*>(item);
QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1); if(cache && cache->isVisible())
QFile file(fileName); {
cacheToSvg(cache);
return true;
}
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) UBGraphicsCompass *compass = qgraphicsitem_cast<UBGraphicsCompass*> (item);
{
qCritical() << "cannot open " << fileName << " for writing ...";
return false;
}
file.write(buffer.data());
file.flush();
file.close();
if (compass && compass->isVisible())
{
compassToSvg(compass);
return true;
} }
else
UBGraphicsProtractor *protractor = qgraphicsitem_cast<UBGraphicsProtractor*> (item);
if (protractor && protractor->isVisible())
{ {
qDebug() << "ignoring unmodified page" << mPageIndex + 1; protractorToSvg(protractor);
return true;
}
UBGraphicsTriangle *triangle = qgraphicsitem_cast<UBGraphicsTriangle*> (item);
if (triangle && triangle->isVisible())
{
triangleToSvg(triangle);
return true;
} }
return true; return true;
} }
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo) void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo)
{ {
mXmlWriter.writeStartElement("line"); mXmlWriter.writeStartElement("line");

@ -156,6 +156,7 @@ class UBSvgSubsetAdaptor
UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex); UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
bool persistScene(); bool persistScene();
bool parseCommonItems(QGraphicsItem *item);
virtual ~UBSvgSubsetWriter(){} virtual ~UBSvgSubsetWriter(){}

@ -1235,10 +1235,12 @@ void UBBoardController::ClearUndoStack()
while (itUniq.hasNext()) while (itUniq.hasNext())
{ {
QGraphicsItem* item = itUniq.next(); QGraphicsItem* item = itUniq.next();
UBGraphicsScene *scene = dynamic_cast<UBGraphicsScene*>(item->scene()); if (item->scene()) {
if(!scene) UBGraphicsScene *scene = dynamic_cast<UBGraphicsScene*>(item->scene());
{ if(!scene)
mActiveScene->deleteItem(item); {
mActiveScene->deleteItem(item);
}
} }
} }

@ -236,27 +236,25 @@ void UBGraphicsItemDelegate::setMimeData(QMimeData *mimeData)
bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if((NULL != mMimeData) && ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())) if(mMimeData) {
{ QDrag* mDrag = new QDrag(event->widget());
QDrag* mDrag = new QDrag(event->widget()); mDrag->setMimeData(mMimeData);
mDrag->setMimeData(mMimeData); if (!mDragPixmap.isNull()) {
if (!mDragPixmap.isNull()) { mDrag->setPixmap(mDragPixmap);
mDrag->setPixmap(mDragPixmap); mDrag->setHotSpot(mDragPixmap.rect().center());
mDrag->setHotSpot(mDragPixmap.rect().center());
}
mDrag->exec();
mDragPixmap = QPixmap();
return true;
} }
mDrag->exec();
mDragPixmap = QPixmap();
if(isLocked())
{
event->accept();
return true; return true;
} }
return true; if(isLocked()) {
event->accept();
return true;
} else {
return false;
}
} }
bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event)

@ -189,18 +189,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi
QGraphicsPolygonItem::paint(painter, option, widget); QGraphicsPolygonItem::paint(painter, option, widget);
} }
//QPainterPath UBGraphicsPolygonItem::shape() const QPainterPath UBGraphicsPolygonItem::shape() const
//{ {
// QPainterPath path; QPainterPath path;
// path.addRect(boundingRect()); path.addRect(boundingRect());
// return path; return path;
//// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); // static QPainterPath shapePath = QGraphicsPolygonItem::shape();
//// return shapePath; // return shapePath;
//} }
UBGraphicsScene* UBGraphicsPolygonItem::scene() UBGraphicsScene* UBGraphicsPolygonItem::scene()

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

@ -294,9 +294,15 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
} }
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(groupButtonProcessing())); connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState()));
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(groupButtonClicked())); // just a stub don't treat as a result code
// static int i = 0;
// i++;
// if (i == 1) {
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(groupButtonClicked()));
// qDebug() << "the connect is accepted";
// }
} }
UBGraphicsScene::~UBGraphicsScene() UBGraphicsScene::~UBGraphicsScene()
@ -315,7 +321,7 @@ void UBGraphicsScene::selectionChangedProcessing()
UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is "
+ QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f'));
} }
void UBGraphicsScene::groupButtonProcessing() void UBGraphicsScene::updateGroupButtonState()
{ {
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; QAction *groupAction = UBApplication::mainWindow->actionGroupItems;
QList<QGraphicsItem*> selItems = selectedItems(); QList<QGraphicsItem*> selItems = selectedItems();
@ -351,11 +357,18 @@ void UBGraphicsScene::groupButtonClicked()
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
foreach (QGraphicsItem *item, selItems) { foreach (QGraphicsItem *item, selItems) {
item->setSelected(false); if (item->type() == UBGraphicsGroupContainerItem::Type) {
item->setFlag(QGraphicsItem::ItemIsSelectable, false); QList<QGraphicsItem*> childItems = item->childItems();
item->setFlag( QGraphicsItem::ItemIsMovable, false); UBGraphicsGroupContainerItem *currentGroup = dynamic_cast<UBGraphicsGroupContainerItem*>(item);
item->setFlag(QGraphicsItem::ItemIsFocusable); if (currentGroup) {
groupItem->addToGroup(item); currentGroup->destroy();
}
foreach (QGraphicsItem *chItem, childItems) {
groupItem->addToGroup(chItem);
}
} else {
groupItem->addToGroup(item);
}
} }
addItem(groupItem); addItem(groupItem);
@ -375,26 +388,6 @@ void UBGraphicsScene::groupButtonClicked()
} }
} }
void UBGraphicsScene::processGroupItems()
{
qDebug() << "processing grouping items";
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
foreach (QGraphicsItem *item, selectedItems()) {
item->setSelected(false);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
item->setFlag( QGraphicsItem::ItemIsMovable, false);
item->setFlag(QGraphicsItem::ItemIsFocusable, true);
groupItem->addToGroup(item);
}
addItem(groupItem);
// groupItem->setPos(50, 50);
groupItem->setVisible(true);
groupItem->setFocus();
qDebug() << groupItem->boundingRect();
}
// MARK: - // MARK: -
// MARK: Mouse/Tablet events handling // MARK: Mouse/Tablet events handling

@ -305,9 +305,8 @@ public slots:
void setToolCursor(int tool); void setToolCursor(int tool);
void selectionChangedProcessing(); void selectionChangedProcessing();
void groupButtonProcessing(); void updateGroupButtonState();
void groupButtonClicked(); void groupButtonClicked();
void processGroupItems();
void moveMagnifier(QPoint newPos); void moveMagnifier(QPoint newPos);
void closeMagnifier(); void closeMagnifier();

@ -46,6 +46,12 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
return; return;
} }
//setting item flags to given item
item->setSelected(false);
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
item->setFlag( QGraphicsItem::ItemIsMovable, false);
item->setFlag(QGraphicsItem::ItemIsFocusable, true);
QTransform newItemTransform(itemTransform); QTransform newItemTransform(itemTransform);
item->setPos(mapFromItem(item, 0, 0)); item->setPos(mapFromItem(item, 0, 0));
item->setParentItem(this); item->setParentItem(this);
@ -130,20 +136,24 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr
QWidget *widget) QWidget *widget)
{ {
Q_UNUSED(widget); Q_UNUSED(widget);
if (option->state & QStyle::State_Selected) { Q_UNUSED(painter);
painter->setBrush(Qt::NoBrush); Q_UNUSED(option);
QPen tmpPen;
qreal tmpPenWidth = 1.0; // we would not use paint smth for the moment
tmpPen.setWidth(tmpPenWidth); // if (option->state & QStyle::State_Selected) {
tmpPen.setColor(Qt::lightGray); // painter->setBrush(Qt::NoBrush);
painter->setPen(tmpPen); // QPen tmpPen;
painter->drawRect(itemsBoundingRect.adjusted(tmpPenWidth / 2, tmpPenWidth / 2, -tmpPenWidth / 2, -tmpPenWidth / 2)); // qreal tmpPenWidth = 1.0;
} // tmpPen.setWidth(tmpPenWidth);
// tmpPen.setColor(Qt::lightGray);
// painter->setPen(tmpPen);
// painter->drawRect(itemsBoundingRect.adjusted(tmpPenWidth / 2, tmpPenWidth / 2, -tmpPenWidth / 2, -tmpPenWidth / 2));
// }
} }
UBGraphicsScene *UBGraphicsGroupContainerItem::scene() UBGraphicsScene *UBGraphicsGroupContainerItem::scene()
{ {
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(scene()); UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(QGraphicsItem::scene());
return castScene; return castScene;
} }
@ -178,7 +188,12 @@ void UBGraphicsGroupContainerItem::destroy() {
item->setFlag(QGraphicsItem::ItemIsFocusable, true); item->setFlag(QGraphicsItem::ItemIsFocusable, true);
} }
mDelegate->remove(true); remove();
if (scene()) {
qDebug() << "scene is well casted";
scene()->removeItem(this);
}
} }
void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@ -186,9 +201,12 @@ void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *eve
if (mDelegate->mousePressEvent(event)) { if (mDelegate->mousePressEvent(event)) {
//NOOP //NOOP
} else { } else {
QGraphicsItem::mousePressEvent(event);
QGraphicsItem::mousePressEvent(event);
setSelected(true); setSelected(true);
} }
} }
void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
@ -198,11 +216,12 @@ void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *even
} else { } else {
QGraphicsItem::mouseMoveEvent(event); QGraphicsItem::mouseMoveEvent(event);
} }
} }
void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
mDelegate->mouseReleaseEvent(event); // mDelegate->mouseReleaseEvent(event);
QGraphicsItem::mouseReleaseEvent(event); QGraphicsItem::mouseReleaseEvent(event);
} }

@ -46,3 +46,24 @@ void UBGraphicsGroupContainerItemDelegate::buildButtons()
{ {
UBGraphicsItemDelegate::buildButtons(); UBGraphicsItemDelegate::buildButtons();
} }
bool UBGraphicsGroupContainerItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
return false;
}
bool UBGraphicsGroupContainerItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
return false;
}
bool UBGraphicsGroupContainerItemDelegate::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
return false;
}

@ -17,6 +17,10 @@ protected:
virtual void decorateMenu(QMenu *menu); virtual void decorateMenu(QMenu *menu);
virtual void buildButtons(); virtual void buildButtons();
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private: private:
DelegateButton *mDestroyGroupButton; DelegateButton *mDestroyGroupButton;
}; };

Loading…
Cancel
Save