From a60439302cb638ba20a5f6a8485076dd63feb5f4 Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Wed, 2 May 2012 12:00:52 +0200 Subject: [PATCH 01/15] Sankore smart button --- src/core/UB.h | 3 +- src/domain/UBGraphicsPolygonItem.cpp | 16 ++--- src/domain/UBGraphicsPolygonItem.h | 2 +- src/domain/UBGraphicsScene.cpp | 66 ++++++++++++++++++--- src/domain/UBGraphicsScene.h | 3 +- src/domain/ubgraphicsgroupcontaineritem.cpp | 9 +++ src/domain/ubgraphicsgroupcontaineritem.h | 8 +++ src/tools/UBGraphicsCompass.cpp | 1 + src/tools/UBGraphicsProtractor.cpp | 1 + src/tools/UBGraphicsProtractor.h | 2 +- src/tools/UBGraphicsRuler.cpp | 3 +- src/tools/UBGraphicsTriangle.cpp | 1 + 12 files changed, 95 insertions(+), 20 deletions(-) diff --git a/src/core/UB.h b/src/core/UB.h index 0ca8d2cd..86eaa5d9 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -123,7 +123,8 @@ struct UBGraphicsItemType StrokeItemType, TriangleItemType, MagnifierItemType, - cacheItemType + cacheItemType, + groupContainerType }; }; diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index f05dd1e9..1e5a8c52 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -184,18 +184,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi QGraphicsPolygonItem::paint(painter, option, widget); } -QPainterPath UBGraphicsPolygonItem::shape() const -{ +//QPainterPath UBGraphicsPolygonItem::shape() const +//{ - QPainterPath path; - path.addRect(boundingRect()); +// QPainterPath path; +// path.addRect(boundingRect()); - return path; +// return path; -// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); +//// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); -// return shapePath; -} +//// return shapePath; +//} UBGraphicsScene* UBGraphicsPolygonItem::scene() diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 2934b66b..4ca98294 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -115,7 +115,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem protected: void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); - QPainterPath shape () const; +// QPainterPath shape () const; private: diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 1494ce85..c7fa1ff8 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -65,6 +65,9 @@ #include "core/memcheck.h" +const QString groupText = "Group items"; +const QString ungroupText = "Ungroup items"; + qreal UBZLayerController::errorNumber = -20000001.0; UBZLayerController::UBZLayerController(QGraphicsScene *scene) : @@ -291,9 +294,9 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) } connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); - connect(this, SIGNAL(selectionChanged()), this, SLOT(enableGroupingButton())); + connect(this, SIGNAL(selectionChanged()), this, SLOT(groupButtonProcessing())); - connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(processGroupItems())); + connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(groupButtonClicked())); } UBGraphicsScene::~UBGraphicsScene() @@ -312,15 +315,65 @@ 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() +void UBGraphicsScene::groupButtonProcessing() { QAction *groupAction = UBApplication::mainWindow->actionGroupItems; + QList selItems = selectedItems(); + int selCount = selItems.count(); - if (selectedItems().count() > 1) { - groupAction->setEnabled(true); - } else { + if (selCount < 1) { groupAction->setEnabled(false); + groupAction->setText(groupText); + + } else if (selCount == 1) { + if (selItems.first()->type() == UBGraphicsGroupContainerItem::Type) { + groupAction->setEnabled(true); + groupAction->setText(ungroupText); + } else { + groupAction->setEnabled(false); + } + + } else if (selCount > 1) { + groupAction->setEnabled(true); + groupAction->setText(groupText); + } +} +void UBGraphicsScene::groupButtonClicked() +{ + QAction *groupAction = UBApplication::mainWindow->actionGroupItems; + QList selItems = selectedItems(); + if (!selItems.count()) { + qDebug() << "Got grouping request when there is no any selected item on the scene"; + return; } + + if (groupAction->text() == groupText) { //The only way to get information from item, considering using smth else + UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); + + foreach (QGraphicsItem *item, selItems) { + item->setSelected(false); + item->setFlag(QGraphicsItem::ItemIsSelectable, false); + item->setFlag( QGraphicsItem::ItemIsMovable, false); + item->setFlag(QGraphicsItem::ItemIsFocusable); + groupItem->addToGroup(item); + } + + addItem(groupItem); + groupItem->setVisible(true); + groupItem->setFocus(); + + } else if (groupAction->text() == ungroupText) { + //Considering one selected item and it's a group + if (selItems.count() > 1) { + qDebug() << "can't make sense of ungrouping more then one item. Grouping action should be performed for that purpose"; + return; + } + UBGraphicsGroupContainerItem *currentGroup = dynamic_cast(selItems.first()); + if (currentGroup) { + currentGroup->destroy(); + } + } + } void UBGraphicsScene::processGroupItems() { @@ -432,7 +485,6 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre return accepted; } - bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure) { bool accepted = false; diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 4b9d946f..4e531204 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -305,7 +305,8 @@ public slots: void setToolCursor(int tool); void selectionChangedProcessing(); - void enableGroupingButton(); + void groupButtonProcessing(); + void groupButtonClicked(); void processGroupItems(); void moveMagnifier(QPoint newPos); diff --git a/src/domain/ubgraphicsgroupcontaineritem.cpp b/src/domain/ubgraphicsgroupcontaineritem.cpp index 0a706099..3099e288 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.cpp +++ b/src/domain/ubgraphicsgroupcontaineritem.cpp @@ -53,6 +53,15 @@ void UBGraphicsGroupContainerItem::remove() mDelegate->remove(); } +void UBGraphicsGroupContainerItem::destroy() { + + foreach (QGraphicsItem *item, childItems()) { + removeFromGroup(item); + item->setFlag(QGraphicsItem::ItemIsSelectable, true); + } + + mDelegate->remove(true); +} void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/domain/ubgraphicsgroupcontaineritem.h b/src/domain/ubgraphicsgroupcontaineritem.h index 193a3ca7..87cc38ab 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.h +++ b/src/domain/ubgraphicsgroupcontaineritem.h @@ -15,6 +15,14 @@ public: virtual UBGraphicsScene* scene(); virtual UBGraphicsGroupContainerItem *deepCopy() const; virtual void remove(); + enum { Type = UBGraphicsItemType::groupContainerType }; + + virtual int type() const + { + return Type; + } + + void destroy(); protected: diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp index f2bc45df..c0386d1a 100644 --- a/src/tools/UBGraphicsCompass.cpp +++ b/src/tools/UBGraphicsCompass.cpp @@ -71,6 +71,7 @@ UBGraphicsCompass::UBGraphicsCompass() unsetCursor(); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + setFlag(QGraphicsItem::ItemIsSelectable, false); connect(UBApplication::boardController, SIGNAL(penColorChanged()), this, SLOT(penColorChanged())); connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged())); diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index e73f0d02..f00bf275 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -64,6 +64,7 @@ UBGraphicsProtractor::UBGraphicsProtractor() mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + setFlag(QGraphicsItem::ItemIsSelectable, false); scale(1.5, 1.5); } diff --git a/src/tools/UBGraphicsProtractor.h b/src/tools/UBGraphicsProtractor.h index 0d704126..7eb79963 100644 --- a/src/tools/UBGraphicsProtractor.h +++ b/src/tools/UBGraphicsProtractor.h @@ -28,7 +28,7 @@ class UBGraphicsScene; class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipseItem, public UBItem { - Q_OBJECT; + Q_OBJECT public: UBGraphicsProtractor (); diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 27bcc713..720b7b22 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -46,7 +46,8 @@ UBGraphicsRuler::UBGraphicsRuler() setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly - updateResizeCursor(); + setFlag(QGraphicsItem::ItemIsSelectable, false); + updateResizeCursor(); } void UBGraphicsRuler::updateResizeCursor() diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index bd4156e0..ef946af7 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -55,6 +55,7 @@ UBGraphicsTriangle::UBGraphicsTriangle() mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly + setFlag(QGraphicsItem::ItemIsSelectable, false); updateResizeCursor(); } From f4fffe47ceb5ce77e06ab071e98539d8e5a2b36c Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Mon, 7 May 2012 11:17:49 +0200 Subject: [PATCH 02/15] unstable but fresh changes multiple selection and grouping --- src/board/UBBoardView.cpp | 5 ++--- src/board/UBBoardView.h | 1 + src/domain/UBGraphicsItemDelegate.h | 2 +- src/domain/UBGraphicsScene.cpp | 1 - src/domain/UBGraphicsWidgetItem.cpp | 6 ++++++ src/domain/UBGraphicsWidgetItem.h | 2 ++ src/domain/ubgraphicsgroupcontaineritem.cpp | 6 ++++++ src/domain/ubgraphicsgroupcontaineritem.h | 2 +- .../ubgraphicsgroupcontaineritemdelegate.cpp | 17 ----------------- .../ubgraphicsgroupcontaineritemdelegate.h | 4 ---- 10 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 3dd30148..a1315084 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -516,8 +516,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) } } -QSet mJustSelectedItems; - void UBBoardView::mouseMoveEvent (QMouseEvent *event) { @@ -563,7 +561,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) || item->type() == UBGraphicsPixmapItem::Type || item->type() == UBGraphicsVideoItem::Type || item->type() == UBGraphicsAudioItem::Type - || item->type() == UBGraphicsSvgItem::Type) { + || item->type() == UBGraphicsSvgItem::Type + || item->type() == UBGraphicsTextItem::Type) { if (!mJustSelectedItems.contains(item)) { item->setSelected(true); diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index a0d0e838..21bc12b8 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -125,6 +125,7 @@ class UBBoardView : public QGraphicsView QMouseEvent *suspendedMousePressEvent; UBRubberBand *mUBRubberBand; + QSet mJustSelectedItems; private slots: diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index f560b546..cc3c8e3b 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -4,7 +4,7 @@ * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This prograscenem is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index c7fa1ff8..496338ab 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1784,7 +1784,6 @@ QGraphicsItem* UBGraphicsScene::scaleToFitDocumentSize(QGraphicsItem* item, bool return item; } - void UBGraphicsScene::addRuler(QPointF center) { UBGraphicsRuler* ruler = new UBGraphicsRuler(); // mem : owned and destroyed by the scene diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 13487641..af71898c 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -91,6 +91,12 @@ void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) mDelegate->hoverLeaveEvent(event); UBGraphicsProxyWidget::hoverLeaveEvent(event); } +void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + qDebug() << "hover move catched"; + UBGraphicsProxyWidget::hoverMoveEvent(event); +} + bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event) { diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 2b73b5bc..2d29d30c 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -87,6 +87,8 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + virtual bool eventFilter(QObject *obj, QEvent *event); diff --git a/src/domain/ubgraphicsgroupcontaineritem.cpp b/src/domain/ubgraphicsgroupcontaineritem.cpp index 3099e288..9f71cd94 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.cpp +++ b/src/domain/ubgraphicsgroupcontaineritem.cpp @@ -63,6 +63,12 @@ void UBGraphicsGroupContainerItem::destroy() { mDelegate->remove(true); } +void UBGraphicsGroupContainerItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + qDebug() << "hover move group"; + QGraphicsItemGroup::hoverMoveEvent(event); +} + void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (mDelegate->mousePressEvent(event)) { diff --git a/src/domain/ubgraphicsgroupcontaineritem.h b/src/domain/ubgraphicsgroupcontaineritem.h index 87cc38ab..c2dc73d7 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.h +++ b/src/domain/ubgraphicsgroupcontaineritem.h @@ -26,7 +26,7 @@ public: protected: - + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp index ff763520..43286df6 100644 --- a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp @@ -44,21 +44,4 @@ void UBGraphicsGroupContainerItemDelegate::decorateMenu(QMenu *menu) void UBGraphicsGroupContainerItemDelegate::buildButtons() { UBGraphicsItemDelegate::buildButtons(); - - mDestroyGroupButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection); - - mButtons << mDestroyGroupButton; - - connect(mDestroyGroupButton, SIGNAL(clicked()), (UBGraphicsGroupContainerItemDelegate*)this, SLOT(destroyGroup())); -} - -void UBGraphicsGroupContainerItemDelegate::destroyGroup() -{ - qDebug() << "got an event"; - foreach (QGraphicsItem *item, delegated()->childItems()) { - delegated()->removeFromGroup(item); - item->setFlag(QGraphicsItem::ItemIsSelectable, true); - } - - remove(true); } diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.h b/src/domain/ubgraphicsgroupcontaineritemdelegate.h index 7160bb00..56a525f8 100644 --- a/src/domain/ubgraphicsgroupcontaineritemdelegate.h +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.h @@ -17,10 +17,6 @@ protected: virtual void decorateMenu(QMenu *menu); virtual void buildButtons(); - -private slots: - void destroyGroup(); - private: DelegateButton *mDestroyGroupButton; }; From 4150279b9fb146089106ef4a36e8db2cea914951 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Tue, 8 May 2012 14:41:04 +0300 Subject: [PATCH 03/15] Implemented removing selected items from favorite --- src/gui/UBFeaturesActionBar.cpp | 6 ++++++ src/gui/UBFeaturesActionBar.h | 2 ++ src/gui/UBFeaturesWidget.cpp | 27 ++++++++++++++++++++++++--- src/gui/UBFeaturesWidget.h | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 8311bfc9..7d1f092d 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -77,6 +77,7 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder())); + connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite())); // Build the default toolbar mLayout->addWidget(mpFavoriteBtn); @@ -175,6 +176,11 @@ void UBFeaturesActionBar::onActionFavorite() emit addElementsToFavorite(); } +void UBFeaturesActionBar::onActionRemoveFavorite() +{ + emit removeElementsFromFavorite(); +} + /* void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event) { diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 7aec99a9..deea070f 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -31,10 +31,12 @@ signals: void addToFavorite( const QMimeData &data ); void removeFromFavorite( const QMimeData &data ); void addElementsToFavorite(); + void removeElementsFromFavorite(); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); void onActionFavorite(); + void onActionRemoveFavorite(); protected: //void dragMoveEvent(QDragMoveEvent *event); void dragEnterEvent( QDragEnterEvent *event ); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 7a71b555..a8380a69 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -121,7 +121,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) ); connect( mActionBar, SIGNAL( addToFavorite(const QMimeData &) ), this, SLOT( addToFavorite(const QMimeData &) ) ); connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) ); - connect ( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) ); + connect( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) ); + connect( mActionBar, SIGNAL( removeElementsFromFavorite() ), this, SLOT ( removeElementsFromFavorite() ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) ); @@ -348,6 +349,25 @@ void UBFeaturesWidget::addElementsToFavorite() model->invalidate(); } +void UBFeaturesWidget::removeElementsFromFavorite() +{ + QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes(); + //qSort( selected.begin(), selected.end(), qGreater() ); + QList items; + for ( int i = 0; i < selected.size(); ++i ) + { + UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value(); + items.append( feature.getFullPath() ); + } + foreach ( QUrl url, items ) + { + controller->removeFromFavorite( url ); + featuresModel->deleteFavoriteItem( url.toString() ); + } + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + model->invalidate(); +} + void UBFeaturesWidget::switchToListView() { stackedWidget->setCurrentIndex(ID_LISTVIEW); @@ -435,7 +455,7 @@ void UBFeaturesListView::dropEvent( QDropEvent *event ) { event->setDropAction( Qt::MoveAction ); } - QListView::dropEvent( event ); + QListView::dropEvent( event ); } @@ -854,7 +874,7 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path ) { for ( int i = 0; i < featuresList->size(); ++i ) { - if ( !QString::compare( featuresList->at(i).getUrl(), path, Qt::CaseInsensitive ) && + if ( !QString::compare( featuresList->at(i).getFullPath().toString(), path, Qt::CaseInsensitive ) && !QString::compare( featuresList->at(i).getVirtualPath(), "/root/favorites", Qt::CaseInsensitive ) ) { removeRow( i, QModelIndex() ); @@ -889,6 +909,7 @@ bool UBFeaturesModel::removeRow( int row, const QModelIndex & parent ) return true; } + Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const { Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index); diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 85aaebbd..6050fc33 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -102,6 +102,7 @@ private slots: void onDisplayMetadata( QMap ); void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray); void addElementsToFavorite(); + void removeElementsFromFavorite(); protected: bool eventFilter(QObject *target, QEvent *event); }; @@ -209,6 +210,8 @@ public: bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRow(int row, const QModelIndex &parent = QModelIndex()); + //bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); + //bool insertRow(int row, const QModelIndex &parent = QModelIndex()); Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } From cfa100d2d8f7d2470ac7dab7e3a71c87b9ef21d6 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Tue, 8 May 2012 17:15:23 +0300 Subject: [PATCH 04/15] Implemented adding to favorite from properties page --- src/gui/UBFeaturesWidget.cpp | 31 +++++++++++++++++++++++++------ src/gui/UBFeaturesWidget.h | 3 +-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index a8380a69..bc675a9f 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -337,13 +337,25 @@ void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUr void UBFeaturesWidget::addElementsToFavorite() { - QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes(); - for ( int i = 0; i < selected.size(); ++i ) + if ( currentStackedWidget == ID_PROPERTIES ) { - UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value(); - UBFeature elem = controller->addToFavorite( feature.getFullPath() ); - if ( !elem.getVirtualPath().isEmpty() && !elem.getVirtualPath().isNull() ) - featuresModel->addItem( elem ); + UBFeature feature = featureProperties->getCurrentElement(); + if ( feature != UBFeature() && !UBApplication::isFromWeb( feature.getFullPath().toString() ) ) + { + UBFeature elem = controller->addToFavorite( feature.getFullPath() ); + featuresModel->addItem( elem ); + } + } + else if ( currentStackedWidget == ID_LISTVIEW ) + { + QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes(); + for ( int i = 0; i < selected.size(); ++i ) + { + UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value(); + UBFeature elem = controller->addToFavorite( feature.getFullPath() ); + if ( !elem.getVirtualPath().isEmpty() && !elem.getVirtualPath().isNull() ) + featuresModel->addItem( elem ); + } } QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); model->invalidate(); @@ -629,6 +641,13 @@ void UBFeatureProperties::showEvent (QShowEvent *event ) adaptSize(); } +UBFeature UBFeatureProperties::getCurrentElement() const +{ + if ( mpElement ) + return *mpElement; + return UBFeature(); +} + void UBFeatureProperties::adaptSize() { if( NULL != mpOrigPixmap ) diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 6050fc33..0fafc7d9 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -152,8 +152,7 @@ public: ~UBFeatureProperties(); void showElement(const UBFeature &elem); - - + UBFeature getCurrentElement() const; protected: void resizeEvent(QResizeEvent *event); void showEvent(QShowEvent *event); From 7b40574a5be8ff74c41a093380c38a7d7890ee0e Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Wed, 9 May 2012 11:00:15 +0200 Subject: [PATCH 05/15] Backup of the strokes as object --- src/board/UBBoardView.cpp | 4 +- src/board/UBDrawingController.cpp | 10 +- src/board/UBDrawingController.h | 2 + src/domain/UBGraphicsPolygonItem.cpp | 7 +- src/domain/UBGraphicsPolygonItem.h | 4 + src/domain/UBGraphicsScene.cpp | 202 +++++++++++++++++---------- src/domain/UBGraphicsStrokesGroup.h | 5 + src/frameworks/UBGeometryUtils.cpp | 3 +- 8 files changed, 159 insertions(+), 78 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 3dd30148..05c16943 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -50,6 +50,7 @@ #include "domain/UBGraphicsVideoItem.h" #include "domain/UBGraphicsAudioItem.h" #include "domain/UBGraphicsSvgItem.h" +#include "domain/UBGraphicsStrokesGroup.h" #include "document/UBDocumentProxy.h" @@ -563,7 +564,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) || item->type() == UBGraphicsPixmapItem::Type || item->type() == UBGraphicsVideoItem::Type || item->type() == UBGraphicsAudioItem::Type - || item->type() == UBGraphicsSvgItem::Type) { + || item->type() == UBGraphicsSvgItem::Type + || item->type() == UBGraphicsStrokesGroup::Type) { if (!mJustSelectedItems.contains(item)) { item->setSelected(true); diff --git a/src/board/UBDrawingController.cpp b/src/board/UBDrawingController.cpp index 2390cded..e03ef408 100644 --- a/src/board/UBDrawingController.cpp +++ b/src/board/UBDrawingController.cpp @@ -45,7 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent) , mActiveRuler(NULL) , mStylusTool((UBStylusTool::Enum)-1) , mLatestDrawingTool((UBStylusTool::Enum)-1) - //, mDrawingMode(eDrawingMode_Vector) + , mDrawingMode(DRAWING_MODE) { connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged())); @@ -106,10 +106,16 @@ void UBDrawingController::setStylusTool(int tool) mStylusTool = (UBStylusTool::Enum)tool; + if(eDrawingMode_Vector == DRAWING_MODE){ + mDrawingMode = eDrawingMode_Vector; + } + if (mStylusTool == UBStylusTool::Pen) UBApplication::mainWindow->actionPen->setChecked(true); - else if (mStylusTool == UBStylusTool::Eraser) + else if (mStylusTool == UBStylusTool::Eraser){ UBApplication::mainWindow->actionEraser->setChecked(true); + mDrawingMode = eDrawingMode_Artistic; + } else if (mStylusTool == UBStylusTool::Marker) UBApplication::mainWindow->actionMarker->setChecked(true); else if (mStylusTool == UBStylusTool::Selector) diff --git a/src/board/UBDrawingController.h b/src/board/UBDrawingController.h index 302800dd..21d4f78d 100644 --- a/src/board/UBDrawingController.h +++ b/src/board/UBDrawingController.h @@ -27,6 +27,8 @@ typedef enum{ eDrawingMode_Vector }eDrawingMode; +#define DRAWING_MODE eDrawingMode_Artistic + class UBDrawingController : public QObject { Q_OBJECT; diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index f05dd1e9..9c6dee10 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -39,6 +39,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi , mOriginalWidth(-1) , mIsNominalLine(false) , mStroke(0) + , mpGroup(NULL) { // NOOP initialize(); @@ -77,6 +78,10 @@ UBGraphicsPolygonItem::~UBGraphicsPolygonItem() clearStroke(); } +void UBGraphicsPolygonItem::setStrokesGroup(UBGraphicsStrokesGroup *group) +{ + mpGroup = group; +} void UBGraphicsPolygonItem::setStroke(UBGraphicsStroke* stroke) { @@ -156,7 +161,7 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con copy->mIsNominalLine = false; copy->setStroke(this->stroke()); - copy->setGroup(this->group()); + copy->setStrokesGroup(this->strokesGroup()); copy->setBrush(this->brush()); copy->setPen(this->pen()); copy->mHasAlpha = this->mHasAlpha; diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 2934b66b..851092b2 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -19,6 +19,7 @@ #include "core/UB.h" #include "UBItem.h" +#include "UBGraphicsStrokesGroup.h" class UBItem; class UBGraphicsScene; @@ -37,6 +38,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem void initialize(); + void setStrokesGroup(UBGraphicsStrokesGroup* group); + UBGraphicsStrokesGroup* strokesGroup() const{return mpGroup;} void setColor(const QColor& color); QColor color() const; @@ -132,6 +135,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem QColor mColorOnLightBackground; UBGraphicsStroke* mStroke; + UBGraphicsStrokesGroup* mpGroup; }; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 1494ce85..f6f10436 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -567,7 +567,7 @@ bool UBGraphicsScene::inputDeviceRelease() } }else if (mCurrentStroke) { - if(eDrawingMode_Vector == dc->drawingMode()){ + if(eDrawingMode_Vector == DRAWING_MODE){ UBGraphicsStrokesGroup* pStrokes = new UBGraphicsStrokesGroup(); // Remove the strokes that were just drawn here and replace them by a stroke item @@ -575,6 +575,7 @@ bool UBGraphicsScene::inputDeviceRelease() mPreviousPolygonItems.removeAll(poly); removeItem(poly); UBCoreGraphicsScene::removeItemFromDeletion(poly); + poly->setStrokesGroup(pStrokes); pStrokes->addToGroup(poly); } @@ -756,114 +757,169 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) eraserPathVar.addPolygon(eraserPolygon); const QPainterPath eraserPath = eraserPathVar; + // Get all the items that are intersecting with the eraser path QList collidItems = items(eraserBoundingRect, Qt::IntersectsItemBoundingRect); - QSet toBeAddedItems; - QSet toBeRemovedItems; - - int collidItemsSize = collidItems.size(); + if(eDrawingMode_Vector == UBDrawingController::drawingController()->drawingMode()){ + // NOTE: I decided to reuse the 'artistic' eraser all the time in order to have a better eraser + // For this reason, the following code is not used but we will keep it for now, in case of + // futur requirements. + foreach(QGraphicsItem* poly, collidItems){ + UBGraphicsStrokesGroup* pGroup = dynamic_cast(poly); + if(NULL != pGroup){ + // TODO: Ungroup the item, put back the polygons on the scene, deal with the + // eraser's bounding rect, remove the polygons that must be removed + // then create new groups. + + // Get all substrokes and verify if they are part of the eraserpath then deal with it + foreach(QGraphicsItem* item, poly->childItems()){ + UBGraphicsPolygonItem* polygon = dynamic_cast(item); + if(NULL != polygon){ + if(eraserBoundingRect.intersects(polygon->boundingRect())){ + pGroup->removeFromGroup(polygon); + removeItem(polygon); + } + } + } + } + } - toBeAddedItems.reserve(collidItemsSize); - toBeRemovedItems.reserve(collidItemsSize); + }else{ + QSet toBeAddedItems; + QSet toBeRemovedItems; + int collidItemsSize = collidItems.size(); + toBeAddedItems.reserve(collidItemsSize); + toBeRemovedItems.reserve(collidItemsSize); - if (mShouldUseOMP) - { -#pragma omp parallel for - for (int i = 0; i < collidItemsSize; i++) + if (mShouldUseOMP) { - UBGraphicsPolygonItem *collidingPolygonItem - = qgraphicsitem_cast (collidItems.at(i)); - - if (collidingPolygonItem) + #pragma omp parallel for + for (int i = 0; i < collidItemsSize; i++) { - if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) - { -#pragma omp critical - toBeRemovedItems << collidingPolygonItem; - } - else - { - QPolygonF collidingPolygon = collidingPolygonItem->polygon(); - QPainterPath collidingPath; - collidingPath.addPolygon(collidingPolygon); + UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast(collidItems.at(i)); - QPainterPath croppedPath = collidingPath.subtracted(eraserPath); - QPainterPath croppedPathSimplified = croppedPath.simplified(); + if (NULL != collidingPolygonItem) + { + UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); - if (croppedPath == collidingPath) + if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) { - // NOOP - } - else if (croppedPathSimplified.isEmpty()) - { -#pragma omp critical + #pragma omp critical + // Put the entire polygon into the remove list toBeRemovedItems << collidingPolygonItem; } else { - foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) + // Here we get the polygon of the colliding item + QPolygonF collidingPolygon = collidingPolygonItem->polygon(); + QPainterPath collidingPath; + collidingPath.addPolygon(collidingPolygon); + + // Then we substract the eraser path to the polygon and we simplify it + QPainterPath croppedPath = collidingPath.subtracted(eraserPath); + QPainterPath croppedPathSimplified = croppedPath.simplified(); + + if (croppedPath == collidingPath) { - UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); -#pragma omp critical - toBeAddedItems << croppedPolygonItem; + // NOOP + } + else if (croppedPathSimplified.isEmpty()) + { + #pragma omp critical + // Put the entire polygon into the remove list if the eraser removes all its visible content + toBeRemovedItems << collidingPolygonItem; + } + else + { + // Then we convert the remaining path to a list of polygons that will be converted in + // UBGraphicsPolygonItems and added to the scene + foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) + { + UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); + #pragma omp critical + // Add this new polygon to the 'added' list + toBeAddedItems << croppedPolygonItem; + if(NULL != pGroup){ + croppedPolygonItem->setStrokesGroup(pGroup); + } + } + #pragma omp critical + // Remove the original polygonitem because it has been replaced by many smaller polygons + toBeRemovedItems << collidingPolygonItem; } -#pragma omp critical - toBeRemovedItems << collidingPolygonItem; } } } } - } - else - { - for (int i = 0; i < collidItemsSize; i++) + else { - UBGraphicsPolygonItem *collidingPolygonItem - = qgraphicsitem_cast (collidItems.at(i)); - - if (collidingPolygonItem) + for (int i = 0; i < collidItemsSize; i++) { - if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) - { - toBeRemovedItems << collidingPolygonItem; - } - else - { - QPolygonF collidingPolygon = collidingPolygonItem->polygon(); - QPainterPath collidingPath; - collidingPath.addPolygon(collidingPolygon); + UBGraphicsPolygonItem *collidingPolygonItem + = qgraphicsitem_cast (collidItems.at(i)); - QPainterPath croppedPath = collidingPath.subtracted(eraserPath); - QPainterPath croppedPathSimplified = croppedPath.simplified(); - - if (croppedPath == collidingPath) - { - // NOOP - } - else if (croppedPathSimplified.isEmpty()) + if (collidingPolygonItem) + { + if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) { toBeRemovedItems << collidingPolygonItem; } else { - foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) + QPolygonF collidingPolygon = collidingPolygonItem->polygon(); + QPainterPath collidingPath; + collidingPath.addPolygon(collidingPolygon); + + QPainterPath croppedPath = collidingPath.subtracted(eraserPath); + QPainterPath croppedPathSimplified = croppedPath.simplified(); + + if (croppedPath == collidingPath) { - UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); - toBeAddedItems << croppedPolygonItem; + // NOOP } + else if (croppedPathSimplified.isEmpty()) + { + toBeRemovedItems << collidingPolygonItem; + } + else + { + foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) + { + UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); + toBeAddedItems << croppedPolygonItem; + } - toBeRemovedItems << collidingPolygonItem; + toBeRemovedItems << collidingPolygonItem; + } } } } } - } - addItems(toBeAddedItems); - mAddedItems += toBeAddedItems; + addItems(toBeAddedItems); + mAddedItems += toBeAddedItems; - removeItems(toBeRemovedItems); - mRemovedItems += toBeRemovedItems; + if(eDrawingMode_Vector == DRAWING_MODE){ + foreach(QGraphicsItem* item, toBeAddedItems){ + UBGraphicsPolygonItem* poly = dynamic_cast(item); + if(NULL != poly && NULL != poly->strokesGroup()){ + poly->strokesGroup()->addToGroup(poly); + } + } + } + + removeItems(toBeRemovedItems); + mRemovedItems += toBeRemovedItems; + + if(eDrawingMode_Vector == DRAWING_MODE){ + foreach(QGraphicsItem* item, toBeRemovedItems){ + UBGraphicsPolygonItem* poly = dynamic_cast(item); + if(NULL != poly && NULL != poly->strokesGroup()){ + poly->strokesGroup()->removeFromGroup(poly); + } + } + } + } mPreviousPoint = pEndPoint; } diff --git a/src/domain/UBGraphicsStrokesGroup.h b/src/domain/UBGraphicsStrokesGroup.h index 7eecd900..0d117c3a 100644 --- a/src/domain/UBGraphicsStrokesGroup.h +++ b/src/domain/UBGraphicsStrokesGroup.h @@ -16,6 +16,11 @@ public: virtual UBItem* deepCopy() const; virtual void remove(); virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} + enum { Type = UBGraphicsItemType::StrokeItemType }; + virtual int type() const + { + return Type; + } protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/frameworks/UBGeometryUtils.cpp b/src/frameworks/UBGeometryUtils.cpp index 68c6f1b5..22bfda50 100644 --- a/src/frameworks/UBGeometryUtils.cpp +++ b/src/frameworks/UBGeometryUtils.cpp @@ -198,8 +198,9 @@ QRectF UBGeometryUtils::lineToInnerRect(const QLineF& pLine, const qreal& pWidth qreal centerX = (pLine.x1() + pLine.x2()) / 2; qreal centerY = (pLine.y1() + pLine.y2()) / 2; + // Please put a fucking comment here qreal side = sqrt((pWidth * pWidth) / 2); - qreal halfSide = side / 2; + qreal halfSide = side / 2; return QRectF(centerX - halfSide, centerY - halfSide, side, side); } From 8176e0986331dfa99720dea1ec3453188e15373d Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Wed, 9 May 2012 15:45:23 +0200 Subject: [PATCH 06/15] Sankore groups elements are now interactable --- src/board/UBBoardView.cpp | 3 +- src/domain/UBGraphicsItemDelegate.cpp | 24 +++- src/domain/UBGraphicsItemDelegate.h | 5 +- src/domain/UBGraphicsScene.cpp | 4 +- src/domain/UBGraphicsWidgetItem.cpp | 1 - src/domain/ubgraphicsgroupcontaineritem.cpp | 132 ++++++++++++++++++-- src/domain/ubgraphicsgroupcontaineritem.h | 10 +- 7 files changed, 152 insertions(+), 27 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index a1315084..c5b739d0 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -50,6 +50,7 @@ #include "domain/UBGraphicsVideoItem.h" #include "domain/UBGraphicsAudioItem.h" #include "domain/UBGraphicsSvgItem.h" +#include "domain/ubgraphicsgroupcontaineritem.h" #include "document/UBDocumentProxy.h" @@ -435,7 +436,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsCache::Type || movingItem->type() == UBGraphicsTriangle::Type || movingItem == this->scene()->backgroundObject() - || movingItem->group()) + || (movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type)) { movingItem = NULL; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index c081d40e..ad6ccb56 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -40,6 +40,7 @@ #include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsAudioItem.h" #include "domain/UBGraphicsVideoItem.h" +#include "domain/ubgraphicsgroupcontaineritem.h" #include "web/UBWebController.h" @@ -217,10 +218,9 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) startUndoStep(); - if (!mDelegated->isSelected()) + if (!delegated()->isSelected()) { - mDelegated->setSelected(true); - positionHandles(); + delegated()->setSelected(true); return true; } else @@ -262,7 +262,7 @@ bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) { Q_UNUSED(event); - if( mDelegated->isSelected() ) + if( delegated()->isSelected() ) { // event->accept(); return true; @@ -310,6 +310,18 @@ void UBGraphicsItemDelegate::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) // } } +QGraphicsItem *UBGraphicsItemDelegate::delegated() +{ + QGraphicsItem *curDelegate = 0; + if (mDelegated->parentItem() && mDelegated->parentItem()->type() == UBGraphicsGroupContainerItem::Type) { + curDelegate = mDelegated->parentItem(); // considering delegated item as an item's group which contains everything + } else { + curDelegate = mDelegated; + } + + return curDelegate; +} + void UBGraphicsItemDelegate::positionHandles() { if (mDelegated->isSelected()) { @@ -363,7 +375,7 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible) void UBGraphicsItemDelegate::remove(bool canUndo) { // QGraphicsScene* scene = mDelegated->scene(); - UBGraphicsScene* scene = (UBGraphicsScene*)(mDelegated->scene()); + UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); if (scene) { foreach(DelegateButton* button, mButtons) @@ -699,4 +711,4 @@ void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsI path.addRoundedRect(rect(), 10, 10); painter->fillPath(path, brush()); -} \ No newline at end of file +} diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index d24c7562..2aeedfe4 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -121,10 +121,7 @@ class UBGraphicsItemDelegate : public QObject void printMessage(const QString &mess) {qDebug() << mess;} - QGraphicsItem* delegated() - { - return mDelegated; - } + QGraphicsItem* delegated(); void setCanDuplicate(bool allow){ mCanDuplicate = allow; } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 496338ab..5d6eec0c 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -383,9 +383,9 @@ void UBGraphicsScene::processGroupItems() foreach (QGraphicsItem *item, selectedItems()) { item->setSelected(false); - item->setFlag(QGraphicsItem::ItemIsSelectable, false); + item->setFlag(QGraphicsItem::ItemIsSelectable, true); item->setFlag( QGraphicsItem::ItemIsMovable, false); - item->setFlag(QGraphicsItem::ItemIsFocusable); + item->setFlag(QGraphicsItem::ItemIsFocusable, true); groupItem->addToGroup(item); } diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index af71898c..7a7edb8a 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -93,7 +93,6 @@ void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) } void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { - qDebug() << "hover move catched"; UBGraphicsProxyWidget::hoverMoveEvent(event); } diff --git a/src/domain/ubgraphicsgroupcontaineritem.cpp b/src/domain/ubgraphicsgroupcontaineritem.cpp index e7a9eb93..41cc19d6 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.cpp +++ b/src/domain/ubgraphicsgroupcontaineritem.cpp @@ -9,7 +9,7 @@ #include "core/memcheck.h" UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent) - : QGraphicsItemGroup(parent) + : QGraphicsItem(parent) { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); @@ -23,8 +23,123 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent UBGraphicsGroupContainerItem::setAcceptHoverEvents(true); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + +} + +void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) +{ + if (!item) { + qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add null item"); + return; + } + if (item == this) { + qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add a group to itself"); + return; + } + + // COMBINE + bool ok; + QTransform itemTransform = item->itemTransform(this, &ok); + + if (!ok) { + qWarning("UBGraphicsGroupContainerItem::addToGroup: could not find a valid transformation from item to group coordinates"); + return; + } + + QTransform newItemTransform(itemTransform); + item->setPos(mapFromItem(item, 0, 0)); + item->setParentItem(this); + + // removing position from translation component of the new transform + if (!item->pos().isNull()) + newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); + + // removing additional transformations properties applied with itemTransform() + QPointF origin = item->transformOriginPoint(); + QMatrix4x4 m; + QList transformList = item->transformations(); + for (int i = 0; i < transformList.size(); ++i) + transformList.at(i)->applyTo(&m); + newItemTransform *= m.toTransform().inverted(); + newItemTransform.translate(origin.x(), origin.y()); + newItemTransform.rotate(-item->rotation()); + newItemTransform.scale(1/item->scale(), 1/item->scale()); + newItemTransform.translate(-origin.x(), -origin.y()); + + // ### Expensive, we could maybe use dirtySceneTransform bit for optimization + + item->setTransform(newItemTransform); +// item->d_func()->setIsMemberOfGroup(true); + prepareGeometryChange(); + itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect()); + update(); +} +void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item) +{ + if (!item) { + qWarning("QGraphicsItemGroup::removeFromGroup: cannot remove null item"); + return; + } + + QGraphicsItem *newParent = parentItem(); + + // COMBINE + bool ok; + QTransform itemTransform; + if (newParent) + itemTransform = item->itemTransform(newParent, &ok); + else + itemTransform = item->sceneTransform(); + + QPointF oldPos = item->mapToItem(newParent, 0, 0); + item->setParentItem(newParent); + item->setPos(oldPos); + + // removing position from translation component of the new transform + if (!item->pos().isNull()) + itemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); + + // removing additional transformations properties applied + // with itemTransform() or sceneTransform() + QPointF origin = item->transformOriginPoint(); + QMatrix4x4 m; + QList transformList = item->transformations(); + for (int i = 0; i < transformList.size(); ++i) + transformList.at(i)->applyTo(&m); + itemTransform *= m.toTransform().inverted(); + itemTransform.translate(origin.x(), origin.y()); + itemTransform.rotate(-item->rotation()); + itemTransform.scale(1 / item->scale(), 1 / item->scale()); + itemTransform.translate(-origin.x(), -origin.y()); + + // ### Expensive, we could maybe use dirtySceneTransform bit for optimization + + item->setTransform(itemTransform); +// item->d_func()->setIsMemberOfGroup(item->group() != 0); + + // ### Quite expensive. But removeFromGroup() isn't called very often. + prepareGeometryChange(); + itemsBoundingRect = childrenBoundingRect(); } +QRectF UBGraphicsGroupContainerItem::boundingRect() const +{ + return itemsBoundingRect; +} +void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) +{ + Q_UNUSED(widget); + if (option->state & QStyle::State_Selected) { + painter->setBrush(Qt::NoBrush); + QPen tmpPen; + 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() { @@ -60,23 +175,18 @@ void UBGraphicsGroupContainerItem::destroy() { foreach (QGraphicsItem *item, childItems()) { removeFromGroup(item); item->setFlag(QGraphicsItem::ItemIsSelectable, true); + item->setFlag(QGraphicsItem::ItemIsFocusable, true); } mDelegate->remove(true); } -void UBGraphicsGroupContainerItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - qDebug() << "hover move group"; - QGraphicsItemGroup::hoverMoveEvent(event); -} - void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (mDelegate->mousePressEvent(event)) { //NOOP } else { - QGraphicsItemGroup::mousePressEvent(event); + QGraphicsItem::mousePressEvent(event); setSelected(true); } } @@ -86,18 +196,18 @@ void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *even if (mDelegate->mouseMoveEvent(event)) { // NOOP; } else { - QGraphicsItemGroup::mouseMoveEvent(event); + QGraphicsItem::mouseMoveEvent(event); } } void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { mDelegate->mouseReleaseEvent(event); - QGraphicsItemGroup::mouseReleaseEvent(event); + QGraphicsItem::mouseReleaseEvent(event); } QVariant UBGraphicsGroupContainerItem::itemChange(GraphicsItemChange change, const QVariant &value) { QVariant newValue = mDelegate->itemChange(change, value); - return QGraphicsItemGroup::itemChange(change, newValue); + return QGraphicsItem::itemChange(change, newValue); } diff --git a/src/domain/ubgraphicsgroupcontaineritem.h b/src/domain/ubgraphicsgroupcontaineritem.h index c2dc73d7..250ef967 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.h +++ b/src/domain/ubgraphicsgroupcontaineritem.h @@ -5,11 +5,17 @@ #include "domain/UBItem.h" -class UBGraphicsGroupContainerItem : public QGraphicsItemGroup, public UBItem, public UBGraphicsItem +class UBGraphicsGroupContainerItem : public QGraphicsItem, public UBItem, public UBGraphicsItem { public: UBGraphicsGroupContainerItem (QGraphicsItem *parent = 0); + + void addToGroup(QGraphicsItem *item); + void removeFromGroup(QGraphicsItem *item); + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} virtual UBGraphicsScene* scene(); @@ -26,7 +32,6 @@ public: protected: - virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); @@ -34,6 +39,7 @@ protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: + QRectF itemsBoundingRect; }; From ccd8e5442c8d5e412ca022a24e0a4b2e35e8313d Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Thu, 10 May 2012 12:19:06 +0300 Subject: [PATCH 07/15] Fixed installation script for windows. Added CFFExportAdaptor; --- Sankore 3.1.iss | 6 +++++- release.win7.vc9.64.bat | 2 +- release.win7.vc9.bat | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sankore 3.1.iss b/Sankore 3.1.iss index 553f777f..eaeacb68 100644 --- a/Sankore 3.1.iss +++ b/Sankore 3.1.iss @@ -45,7 +45,10 @@ Type: files ; Name: "{app}\*.dll" [Files] Source: "..\Sankore-ThirdParty\microsoft\vcredist_x86.exe"; DestDir:"{tmp}" -Source: ".\build\win32\release\product\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "build\win32\release\product\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs + +;Sankore plugins +Source: "plugins\cffadaptor\build\win32\release\lib\CFF_Adaptor.dll"; DestDir: "{app}"; Flags: ignoreversion ;OpenSSL Source: "..\Sankore-ThirdParty\openssl\win32\libeay32.dll"; DestDir:"{app}"; Flags: ignoreversion @@ -60,6 +63,7 @@ Source: "..\Qt-sankore3.1\lib\QtWebKit4.dll"; DestDir: "{app}"; Flags: ignorever Source: "..\Qt-sankore3.1\lib\phonon4.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\Qt-sankore3.1\lib\QtNetwork4.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\Qt-sankore3.1\lib\QtSvg4.dll"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\Qt-sankore3.1\lib\QtOpenGL4.dll"; DestDir: "{app}"; Flags: ignoreversion ;Qt plugins Source: "..\Qt-sankore3.1\plugins\accessible\qtaccessiblecompatwidgets4.dll"; DestDir: "{app}\accessible"; Flags: ignoreversion diff --git a/release.win7.vc9.64.bat b/release.win7.vc9.64.bat index 810f9b0d..b344d2f8 100644 --- a/release.win7.vc9.64.bat +++ b/release.win7.vc9.64.bat @@ -62,7 +62,7 @@ nmake release-install copy %BASE_QT_TRANSLATIONS_DIRECTORY%\qt_*.qm build\win32\release\product\i18n\ del build\win32\release\product\i18n\qt_help* -del ".\build\win32\release\product\Sankore.pdb" +del "build\win32\release\product\Sankore.pdb" set INSTALLER_NAME=Open-Sankore diff --git a/release.win7.vc9.bat b/release.win7.vc9.bat index 51885958..dbf91aa2 100644 --- a/release.win7.vc9.bat +++ b/release.win7.vc9.bat @@ -66,7 +66,7 @@ copy resources\customizations build\win32\release\product\ del build\win32\release\product\i18n\qt_help* -del ".\build\win32\release\product\Sankore.pdb" +del "build\win32\release\product\Sankore.pdb" set INSTALLER_NAME=Open-Sankore From b484dae47f8b239aa428f1f69cba6ccc59589dd9 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 10 May 2012 17:23:50 +0300 Subject: [PATCH 08/15] Implemented removing selected items --- src/gui/UBFeaturesActionBar.cpp | 12 +++++++-- src/gui/UBFeaturesActionBar.h | 2 ++ src/gui/UBFeaturesWidget.cpp | 43 +++++++++++++++++++++++++++++++++ src/gui/UBFeaturesWidget.h | 2 ++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 7d1f092d..60900c84 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -66,8 +66,8 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid mButtonGroup->addButton(mpRemoveFavoriteBtn); mButtonGroup->addButton(mpNewFolderBtn); // Connect signals & slots - connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); - /*connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial())); + /*connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); + connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial())); connect(mpSearchAction,SIGNAL(triggered()), this, SLOT(onActionSearch())); connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash())); connect(mpCloseAction, SIGNAL(triggered()), this, SLOT(onActionClose())); @@ -78,6 +78,7 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder())); connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite())); + connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash())); // Build the default toolbar mLayout->addWidget(mpFavoriteBtn); @@ -149,6 +150,8 @@ void UBFeaturesActionBar::setButtons() mpFavoriteBtn->hide(); mpSocialBtn->hide(); mSearchBar->show(); + mpDeleteBtn->show(); + mpDeleteBtn->setEnabled(true); //mpSearchBtn->show(); //mpDeleteBtn->hide(); mpCloseBtn->hide(); @@ -181,6 +184,11 @@ void UBFeaturesActionBar::onActionRemoveFavorite() emit removeElementsFromFavorite(); } +void UBFeaturesActionBar::onActionTrash() +{ + emit deleteSelectedElements(); +} + /* void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event) { diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index deea070f..99664a6d 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -32,11 +32,13 @@ signals: void removeFromFavorite( const QMimeData &data ); void addElementsToFavorite(); void removeElementsFromFavorite(); + void deleteSelectedElements(); private slots: void onSearchTextChanged(QString txt); void onActionNewFolder(); void onActionFavorite(); void onActionRemoveFavorite(); + void onActionTrash(); protected: //void dragMoveEvent(QDragMoveEvent *event); void dragEnterEvent( QDragEnterEvent *event ); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index bc675a9f..8ee5e904 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -123,6 +123,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) ); connect( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) ); connect( mActionBar, SIGNAL( removeElementsFromFavorite() ), this, SLOT ( removeElementsFromFavorite() ) ); + connect( mActionBar, SIGNAL( deleteSelectedElements() ), this, SLOT( deleteSelectedElements() ) ); connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), this, SLOT( currentPathChanged( const QModelIndex & ) ) ); connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) ); @@ -278,6 +279,36 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData ) model->invalidate(); } +void UBFeaturesWidget::deleteSelectedElements() +{ + QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes(); + QList urls; + foreach ( QModelIndex sel, selected ) + { + UBFeature feature = sel.data( Qt::UserRole + 1 ).value(); + urls.append( feature.getFullPath() ); + } + + foreach (QUrl url, urls) + { + if ( controller->isTrash( url ) ) + { + controller->deleteItem( url ); + } + else + { + UBFeature elem = controller->moveItemToFolder( url, controller->getTrashElement() ); + controller->removeFromFavorite( url ); + featuresModel->addItem( elem ); + featuresModel->deleteFavoriteItem( url.toString() ); + } + featuresModel->deleteItem( url.toString() ); + } + + QSortFilterProxyModel *model = dynamic_cast( featuresListView->model() ); + model->invalidate(); +} + void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData ) { if ( !mimeData.hasUrls() ) @@ -902,6 +933,18 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path ) } } +void UBFeaturesModel::deleteItem( const QString &path ) +{ + for ( int i = 0; i < featuresList->size(); ++i ) + { + if ( !QString::compare( featuresList->at(i).getFullPath().toString(), path, Qt::CaseInsensitive ) ) + { + removeRow( i, QModelIndex() ); + return; + } + } +} + bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent ) { if ( row < 0 ) diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 0fafc7d9..8ad8e8a3 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -103,6 +103,7 @@ private slots: void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray); void addElementsToFavorite(); void removeElementsFromFavorite(); + void deleteSelectedElements(); protected: bool eventFilter(QObject *target, QEvent *event); }; @@ -200,6 +201,7 @@ public: void addItem( const UBFeature &item ); void deleteFavoriteItem( const QString &path ); + void deleteItem( const QString &path ); QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; QMimeData *mimeData( const QModelIndexList &indexes ) const; From 88ad16b413990279cc1c64f0940cdb2d5f5d93be Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 10 May 2012 18:25:47 +0300 Subject: [PATCH 09/15] Fixed signal-slot connecting bug --- src/gui/UBFeaturesActionBar.cpp | 1 + src/gui/UBFeaturesWidget.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 60900c84..a151406d 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -75,6 +75,7 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder()));*/ + connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder())); connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite())); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 8ee5e904..526fc23d 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -286,7 +286,8 @@ void UBFeaturesWidget::deleteSelectedElements() foreach ( QModelIndex sel, selected ) { UBFeature feature = sel.data( Qt::UserRole + 1 ).value(); - urls.append( feature.getFullPath() ); + if ( feature.isDeletable() ) + urls.append( feature.getFullPath() ); } foreach (QUrl url, urls) From ed45a90940bc69f6d66324b33daa7a558c9380dc Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Thu, 10 May 2012 19:23:23 +0300 Subject: [PATCH 10/15] Fix to linux installation script. Added CFFExportAdaptor library. --- release.linux.sh | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/release.linux.sh b/release.linux.sh index 79bdc17c..313ac7dc 100755 --- a/release.linux.sh +++ b/release.linux.sh @@ -39,14 +39,18 @@ checkDirectory(){ # path definition # ####################################################################### QT_PATH="/usr/local/Trolltech/Qt-4.7.3" -PLUGINS_PATH="$QT_PATH/plugins" +QT_PLUGINS_PATH="$QT_PATH/plugins" RELEASE_DIR=build/linux/release BUILD_DIR=$RELEASE_DIR/product GUI_TRANSLATIONS_DIRECTORY_PATH="../Qt-sankore3.1/translations" QT_LIBRARY_SOURCE_PATH="$QT_PATH/lib" +SANKORE_SRC_PLUGINS_PATH="plugins" +SANKORE_DST_PLUGINS_PATH=build/linux/release/product/plugins +CFF_ADAPTOR_SRC_PLUGIN_PATH=$SANKORE_SRC_PLUGINS_PATH/cffadaptor/build/linux/release/lib QMAKE_PATH="$QT_PATH/bin/qmake" -LRELEASE="/usr/local/Trolltech/Qt-4.7.3/bin/lrelease" +LRELEASE="../Qt-sankore3.1/bin/lrelease" +#LRELEASE="/usr/local/Trolltech/Qt-4.7.3/bin/lrelease" ARCHITECTURE=`uname -m` @@ -57,13 +61,15 @@ checkExecutable $QMAKE_PATH checkExecutable $LRELEASE checkDirectory $GUI_TRANSLATIONS_DIRECTORY_PATH -checkDirectory $PLUGINS_PATH +checkDirectory $QT_PLUGINS_PATH checkDirectory $QT_LIBRARY_SOURCE_PATH +checkDirectory $CFF_ADAPTOR_PLUGIN_PATH + ####################################################################### # cleaning # ####################################################################### -rm -rf $RELEASE_DIR +#rm -rf $RELEASE_DIR ####################################################################### @@ -126,21 +132,26 @@ cp -R resources/linux/qtlinux/* $BUILD_DIR cp -R resources/customizations $BUILD_DIR +notify-send "Sankore" "Copying plugins..." +mkdir "$SANKORE_DST_PLUGINS_PATH" +mkdir "$SANKORE_DST_PLUGINS_PATH/cffadaptor" +cp -R $CFF_ADAPTOR_SRC_PLUGIN_PATH/*.so* "$SANKORE_DST_PLUGINS_PATH/cffadaptor" + notify-send "QT" "Coping plugins and library ..." -cp -R $PLUGINS_PATH $BUILD_DIR +cp -R $QT_PLUGINS_PATH $BUILD_DIR #copying custom qt library QT_LIBRARY_DEST_PATH="$BUILD_DIR/qtlib" mkdir $QT_LIBRARY_DEST_PATH copyQtLibrary(){ - if [ ! -e "$QT_LIBRARY_SOURCE_PATH/$1.so.4.7.3" ]; then + if [ ! -e "$QT_LIBRARY_SOURCE_PATH/$1.so.4" ]; then notifyError "$1 library not found in path: $QT_LIBRARY_SOURCE_PATH" fi - cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4" "$QT_LIBRARY_DEST_PATH/" - cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4.7.3" "$QT_LIBRARY_DEST_PATH/" + cp $QT_LIBRARY_SOURCE_PATH/$1.so.4.* $QT_LIBRARY_DEST_PATH/ } +copyQtLibrary libphonon copyQtLibrary libQtWebKit copyQtLibrary libQtDBus copyQtLibrary libQtScript @@ -150,14 +161,8 @@ copyQtLibrary libQtNetwork copyQtLibrary libQtXml copyQtLibrary libQtGui copyQtLibrary libQtCore - -if [ ! -e "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4.4.0" ]; then - notifyError "phonon library not found in path: $QT_LIBRARY_SOURCE_PATH" -else - cp "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4" "$QT_LIBRARY_DEST_PATH/" - cp "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4.4.0" "$QT_LIBRARY_DEST_PATH/" -fi - +# uncomment for Qt 4.8 +#copyQtLibrary libQtOpenGL ####################################################################### # Removing unwanted files # @@ -279,7 +284,7 @@ echo "Priority: optional" >> "$CONTROL_FILE" echo "Architecture: $ARCHITECTURE" >> "$CONTROL_FILE" echo "Essential: no" >> "$CONTROL_FILE" echo "Installed-Size: `du -s $SANKORE_PACKAGE_DIRECTORY | awk '{ print $1 }'`" >> "$CONTROL_FILE" -echo "Maintainer: Open-Sankoré Developers team " >> "$CONTROL_FILE" +echo "Maintainer: Open-Sankore Developers team " >> "$CONTROL_FILE" echo "Homepage: http://dev.open-sankore.org" >> "$CONTROL_FILE" echo -n "Depends: " >> "$CONTROL_FILE" unset tab @@ -318,7 +323,7 @@ echo "Version=$VERSION" >> $SANKORE_SHORTCUT echo "Encoding=UTF-8" >> $SANKORE_SHORTCUT echo "Name=Open-Sankore ($VERSION)" >> $SANKORE_SHORTCUT echo "GenericName=Open-Sankore" >> $SANKORE_SHORTCUT -echo "Comment=Logiciel de création de présentations pour tableau numérique interactif (TNI)" >> $SANKORE_SHORTCUT +echo "Comment=Logiciel de creation de presentations pour tableau numerique interactif (TNI)" >> $SANKORE_SHORTCUT echo "Exec=/usr/local/$SANKORE_DIRECTORY_NAME/run.sh" >> $SANKORE_SHORTCUT echo "Icon=/usr/local/$SANKORE_DIRECTORY_NAME/sankore.png" >> $SANKORE_SHORTCUT echo "StartupNotify=true" >> $SANKORE_SHORTCUT @@ -353,4 +358,4 @@ cd $RELEASE_DIR rm ../../../install/linux/Open-Sankore.tar.gz tar cvzf ../../../install/linux/Open-Sankore.tar.gz Open-Sankore.$VERSION -C . -notify-send "Open-Sankore" "tar.gz Build done" +notify-send "Open-Sankore" "tar.gz Build done" \ No newline at end of file From 51afc034d317d7a7c8065342218f13ce57be2e7d Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Fri, 11 May 2012 09:17:23 +0200 Subject: [PATCH 11/15] Enabled a first version of the strokes as object --- src/board/UBDrawingController.cpp | 4 +- src/board/UBDrawingController.h | 2 +- src/domain/UBGraphicsDelegateFrame.cpp | 6 +- src/domain/UBGraphicsItemDelegate.cpp | 20 +++--- src/domain/UBGraphicsScene.cpp | 91 +++++++++++++++++++------- 5 files changed, 84 insertions(+), 39 deletions(-) diff --git a/src/board/UBDrawingController.cpp b/src/board/UBDrawingController.cpp index e03ef408..a9e4b813 100644 --- a/src/board/UBDrawingController.cpp +++ b/src/board/UBDrawingController.cpp @@ -45,7 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent) , mActiveRuler(NULL) , mStylusTool((UBStylusTool::Enum)-1) , mLatestDrawingTool((UBStylusTool::Enum)-1) - , mDrawingMode(DRAWING_MODE) + , mDrawingMode(/*DRAWING_MODE*/eDrawingMode_Vector) { connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged())); @@ -114,7 +114,7 @@ void UBDrawingController::setStylusTool(int tool) UBApplication::mainWindow->actionPen->setChecked(true); else if (mStylusTool == UBStylusTool::Eraser){ UBApplication::mainWindow->actionEraser->setChecked(true); - mDrawingMode = eDrawingMode_Artistic; + //mDrawingMode = eDrawingMode_Artistic; } else if (mStylusTool == UBStylusTool::Marker) UBApplication::mainWindow->actionMarker->setChecked(true); diff --git a/src/board/UBDrawingController.h b/src/board/UBDrawingController.h index 21d4f78d..4c620f1c 100644 --- a/src/board/UBDrawingController.h +++ b/src/board/UBDrawingController.h @@ -27,7 +27,7 @@ typedef enum{ eDrawingMode_Vector }eDrawingMode; -#define DRAWING_MODE eDrawingMode_Artistic +#define DRAWING_MODE eDrawingMode_Vector class UBDrawingController : public QObject { diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 54dc4650..027d35da 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -583,9 +583,9 @@ void UBGraphicsDelegateFrame::positionHandles() { QRectF itemRect = delegated()->boundingRect(); - if (mDelegate->getToolBarItem()->isVisibleOnBoard() - && mDelegate->getToolBarItem()->isShifting()) - itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1); +// if (mDelegate->getToolBarItem()->isVisibleOnBoard() +// && mDelegate->getToolBarItem()->isShifting()) +// itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1); QTransform itemTransform = delegated()->sceneTransform(); QPointF topLeft = itemTransform.map(itemRect.topLeft()); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 8a7494ec..2ff9d0ed 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -117,7 +117,7 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec void UBGraphicsItemDelegate::init() { - mToolBarItem = new UBGraphicsToolBarItem(delegated()); + //mToolBarItem = new UBGraphicsToolBarItem(delegated()); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame->hide(); @@ -167,7 +167,9 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate() QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedHasChanged) { + if(change == QGraphicsItem::ItemChildAddedChange){ + + }else if (change == QGraphicsItem::ItemSelectedHasChanged) { bool ok; bool selected = value.toUInt(&ok); if (ok) { @@ -321,17 +323,17 @@ void UBGraphicsItemDelegate::positionHandles() updateButtons(true); - if (mToolBarItem->isVisibleOnBoard()) - { - updateToolBar(); - mToolBarItem->show(); - } +// if (mToolBarItem->isVisibleOnBoard()) +// { +// updateToolBar(); +// mToolBarItem->show(); +// } } else { foreach(DelegateButton* button, mButtons) button->hide(); mFrame->hide(); - mToolBarItem->hide(); +// mToolBarItem->hide(); } } @@ -371,7 +373,7 @@ void UBGraphicsItemDelegate::remove(bool canUndo) scene->removeItem(mFrame); scene->removeItem(mDelegated); - scene->removeItem(mToolBarItem); + //scene->removeItem(mToolBarItem); if (canUndo) { diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f6f10436..5ebab1fd 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -308,9 +308,11 @@ UBGraphicsScene::~UBGraphicsScene() void UBGraphicsScene::selectionChangedProcessing() { - if (selectedItems().count()) + if (selectedItems().count()){ + qDebug() << "Selected item bounding rect: " << selectedItems().first()->boundingRect(); 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() { @@ -747,6 +749,8 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) { +// QList itemList; + const QLineF line(mPreviousPoint, pEndPoint); const QPolygonF eraserPolygon = UBGeometryUtils::lineToPolygon(line, pWidth); @@ -793,24 +797,29 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) if (mShouldUseOMP) { - #pragma omp parallel for +// #pragma omp parallel for for (int i = 0; i < collidItemsSize; i++) { - UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast(collidItems.at(i)); + UBGraphicsPolygonItem *collidingPolygonItem = qgraphicsitem_cast(collidItems.at(i)); if (NULL != collidingPolygonItem) { + collidingPolygonItem->setColor(QColor(Qt::green)); + UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) { - #pragma omp critical +// #pragma omp critical + qDebug() << "case 1"; // Put the entire polygon into the remove list + collidingPolygonItem->setColor(QColor(Qt::blue)); toBeRemovedItems << collidingPolygonItem; } else { // Here we get the polygon of the colliding item + QPolygonF collidingPolygon = collidingPolygonItem->polygon(); QPainterPath collidingPath; collidingPath.addPolygon(collidingPolygon); @@ -819,32 +828,40 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) QPainterPath croppedPath = collidingPath.subtracted(eraserPath); QPainterPath croppedPathSimplified = croppedPath.simplified(); - if (croppedPath == collidingPath) + /*if (croppedPath == collidingPath) { // NOOP + qDebug() << "case 2"; + toBeRemovedItems << collidingPolygonItem; } - else if (croppedPathSimplified.isEmpty()) + else */if (croppedPathSimplified.isEmpty()) { - #pragma omp critical +// #pragma omp critical + qDebug() << "case 3"; // Put the entire polygon into the remove list if the eraser removes all its visible content + collidingPolygonItem->setColor(QColor(Qt::blue)); toBeRemovedItems << collidingPolygonItem; } else { + //qDebug() << "case 4"; // Then we convert the remaining path to a list of polygons that will be converted in // UBGraphicsPolygonItems and added to the scene foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) { UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); - #pragma omp critical - // Add this new polygon to the 'added' list - toBeAddedItems << croppedPolygonItem; + croppedPolygonItem->setColor(QColor(Qt::black)); +// #pragma omp critical if(NULL != pGroup){ croppedPolygonItem->setStrokesGroup(pGroup); +// croppedPolygonItem->setTransform(pGroup->sceneTransform().inverted()); } + // Add this new polygon to the 'added' list + toBeAddedItems << croppedPolygonItem; } - #pragma omp critical +// #pragma omp critical // Remove the original polygonitem because it has been replaced by many smaller polygons + collidingPolygonItem->setColor(QColor(Qt::blue)); toBeRemovedItems << collidingPolygonItem; } } @@ -855,11 +872,12 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) { for (int i = 0; i < collidItemsSize; i++) { - UBGraphicsPolygonItem *collidingPolygonItem - = qgraphicsitem_cast (collidItems.at(i)); + UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast (collidItems.at(i)); if (collidingPolygonItem) { + UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); + if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) { toBeRemovedItems << collidingPolygonItem; @@ -887,6 +905,9 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) { UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); toBeAddedItems << croppedPolygonItem; + if(NULL != pGroup){ + croppedPolygonItem->setStrokesGroup(pGroup); + } } toBeRemovedItems << collidingPolygonItem; @@ -896,28 +917,50 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) } } - addItems(toBeAddedItems); - mAddedItems += toBeAddedItems; - if(eDrawingMode_Vector == DRAWING_MODE){ - foreach(QGraphicsItem* item, toBeAddedItems){ + foreach(QGraphicsItem* item, toBeRemovedItems){ UBGraphicsPolygonItem* poly = dynamic_cast(item); - if(NULL != poly && NULL != poly->strokesGroup()){ - poly->strokesGroup()->addToGroup(poly); + if(NULL != poly){ + if(NULL != poly->strokesGroup()){ + poly->strokesGroup()->removeFromGroup(poly); + removeItem(poly); + }else{ + qDebug() << "No group present"; + } } } + }else{ + removeItems(toBeRemovedItems); + mRemovedItems += toBeRemovedItems; } - removeItems(toBeRemovedItems); - mRemovedItems += toBeRemovedItems; - +// bool hack = false; +// UBGraphicsStrokesGroup* pG = new UBGraphicsStrokesGroup(); if(eDrawingMode_Vector == DRAWING_MODE){ - foreach(QGraphicsItem* item, toBeRemovedItems){ + foreach(QGraphicsItem* item, toBeAddedItems){ UBGraphicsPolygonItem* poly = dynamic_cast(item); if(NULL != poly && NULL != poly->strokesGroup()){ - poly->strokesGroup()->removeFromGroup(poly); +// if(!hack){ +// itemList = poly->strokesGroup()->childItems(); +// removeItem(poly->strokesGroup()); + +// foreach(QGraphicsItem* it, itemList){ +// pG->addToGroup(it); +// } +// hack = true; +// } + qreal dx = -poly->strokesGroup()->sceneTransform().inverted().dx(); + qreal dy = -poly->strokesGroup()->sceneTransform().inverted().dy(); + + //poly->setTransform(QTransform().translate(20, 0)); + poly->setTransform(QTransform().translate(dx, dy)); + poly->strokesGroup()/*pG*/->addToGroup(poly); } } + //addItem(pG); + }else{ + addItems(toBeAddedItems); + mAddedItems += toBeAddedItems; } } From 6f1ef4cd514c27794758b4d3bc2526772f934125 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Fri, 11 May 2012 14:11:46 +0300 Subject: [PATCH 12/15] Fixed some memory leaks --- src/gui/UBFeaturesWidget.cpp | 88 +++++++++++++++++++++++++++--------- src/gui/UBFeaturesWidget.h | 5 +- 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 526fc23d..889bc654 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -10,7 +10,7 @@ #include "globals/UBGlobals.h" #include "board/UBBoardController.h" -UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) +UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) { setObjectName(name); mName = "FeaturesWidget"; @@ -82,7 +82,6 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale //pathListView->setMovement( QListView::Static ); pathListView->setDragDropMode( QAbstractItemView::DropOnly ); - pathScene = new QGraphicsScene(this); //pathViewer = new UBFeaturesPathViewer( QPixmap(":images/libpalette/home.png"), controller->getRootPath(), pathScene, this ); featureProperties = new UBFeatureProperties(this); webView = new UBFeaturesWebView(this); @@ -133,6 +132,15 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale this, SLOT( onAddDownloadedFileToLibrary( bool, QUrl, QString,QByteArray ) ) ); } +UBFeaturesWidget::~UBFeaturesWidget() +{ + if ( thumbSlider != NULL ) + { + delete thumbSlider; + thumbSlider = NULL; + } +} + bool UBFeaturesWidget::eventFilter( QObject *target, QEvent *event ) { if ( target == featuresListView && event->type() == QEvent::Resize ) @@ -444,9 +452,7 @@ void UBFeaturesWidget::currentPathChanged(const QString &path) */ -UBFeaturesWidget::~UBFeaturesWidget() -{ -} + UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name ) : QListView(parent) @@ -537,15 +543,18 @@ UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget( UBFeaturesWebView::~UBFeaturesWebView() { - if(NULL != mpSankoreAPI){ + if( NULL != mpSankoreAPI ) + { delete mpSankoreAPI; mpSankoreAPI = NULL; } - if(NULL != mpView){ + if( NULL != mpView ) + { delete mpView; mpView = NULL; } - if(NULL != mpLayout){ + if( NULL != mpLayout ) + { delete mpLayout; mpLayout = NULL; } @@ -661,6 +670,55 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : connect( mpAddToLibButton, SIGNAL( clicked() ), this, SLOT(onAddToLib() ) ); } +UBFeatureProperties::~UBFeatureProperties() +{ + if ( mpOrigPixmap ) + { + delete mpOrigPixmap; + mpOrigPixmap = NULL; + } + if ( mpElement ) + { + delete mpElement; + mpElement = NULL; + } + if ( mpThumbnail ) + { + delete mpThumbnail; + mpThumbnail = NULL; + } + if ( mpButtonLayout ) + { + delete mpButtonLayout; + mpButtonLayout = NULL; + } + if ( mpAddPageButton ) + { + delete mpAddPageButton; + mpAddPageButton = NULL; + } + if ( mpSetAsBackgroundButton ) + { + delete mpSetAsBackgroundButton; + mpSetAsBackgroundButton = NULL; + } + if ( mpAddToLibButton ) + { + delete mpAddToLibButton; + mpAddToLibButton = NULL; + } + if ( mpObjInfoLabel ) + { + delete mpObjInfoLabel; + mpObjInfoLabel = NULL; + } + if ( mpObjInfos ) + { + delete mpObjInfos; + mpObjInfos = NULL; + } +} + void UBFeatureProperties::resizeEvent( QResizeEvent *event ) { Q_UNUSED(event); @@ -787,19 +845,7 @@ void UBFeatureProperties::onSetAsBackground() featuresWidget->getFeaturesController()->addItemAsBackground( *mpElement ); } -UBFeatureProperties::~UBFeatureProperties() -{ - if ( mpOrigPixmap ) - { - delete mpOrigPixmap; - mpOrigPixmap = NULL; - } - if ( mpElement ) - { - delete mpElement; - mpElement = NULL; - } -} + UBFeatureItemButton::UBFeatureItemButton(QWidget *parent, const char *name):QPushButton(parent) { diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 8ad8e8a3..afd29c97 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -80,7 +80,7 @@ private: QSlider *thumbSlider; QVBoxLayout *layout; //UBFeaturesPathViewer *pathViewer; - QGraphicsScene *pathScene; + //QGraphicsScene *pathScene; UBFeaturesActionBar *mActionBar; UBFeatureProperties *featureProperties; UBFeaturesWebView *webView; @@ -88,7 +88,6 @@ private: int currentStackedWidget; - QModelIndex trashIndex; private slots: void currentSelected( const QModelIndex & ); //void currentPathChanged(const QString &); @@ -131,7 +130,7 @@ class UBFeaturesWebView : public QWidget Q_OBJECT public: UBFeaturesWebView(QWidget* parent = 0, const char* name = "UBFeaturesWebView"); - ~UBFeaturesWebView(); + virtual ~UBFeaturesWebView(); void showElement(const UBFeature &elem); From 5e363a3afc46f304bd2afaf45be7447b70b011aa Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Fri, 11 May 2012 14:20:33 +0200 Subject: [PATCH 13/15] Unstable groups implementation --- src/adaptors/UBSvgSubsetAdaptor.cpp | 222 ++++++++++-------- src/adaptors/UBSvgSubsetAdaptor.h | 1 + src/board/UBBoardController.cpp | 10 +- src/domain/UBGraphicsItemDelegate.cpp | 30 ++- src/domain/UBGraphicsPolygonItem.cpp | 16 +- src/domain/UBGraphicsPolygonItem.h | 2 +- src/domain/UBGraphicsScene.cpp | 49 ++-- src/domain/UBGraphicsScene.h | 3 +- src/domain/ubgraphicsgroupcontaineritem.cpp | 45 +++- .../ubgraphicsgroupcontaineritemdelegate.cpp | 21 ++ .../ubgraphicsgroupcontaineritemdelegate.h | 4 + 11 files changed, 231 insertions(+), 172 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index e300bb3a..417e835d 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -30,6 +30,7 @@ #include "domain/UBAbstractWidget.h" #include "domain/UBGraphicsStroke.h" #include "domain/UBGraphicsStrokesGroup.h" +#include "domain/ubgraphicsgroupcontaineritem.h" #include "domain/UBItem.h" #include "tools/UBGraphicsRuler.h" @@ -929,8 +930,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement() bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() { + + if (mScene->isModified()) { + static int i = 0; + qDebug() << "persist call no is " << ++i; + QBuffer buffer; buffer.open(QBuffer::WriteOnly); mXmlWriter.setDevice(&buffer); @@ -1035,146 +1041,162 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() openStroke = 0; } - UBGraphicsPixmapItem *pixmapItem = qgraphicsitem_cast (item); + UBGraphicsGroupContainerItem *groupItem = qgraphicsitem_cast(item); - if (pixmapItem && pixmapItem->isVisible()) + if (groupItem && groupItem->isVisible()) { - pixmapItemToLinkedImage(pixmapItem); + qDebug() << "came across the group during the parsing"; continue; } - UBGraphicsSvgItem *svgItem = qgraphicsitem_cast (item); + parseCommonItems(item); + } - if (svgItem && svgItem->isVisible()) - { - svgItemToLinkedSvg(svgItem); - continue; - } + if (openStroke) + { + mXmlWriter.writeEndElement(); + groupHoldsInfo = false; + openStroke = 0; + } - UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (item); + mXmlWriter.writeEndDocument(); + QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1); + QFile file(fileName); - if (videoItem && videoItem->isVisible()) - { - videoItemToLinkedVideo(videoItem); - continue; - } + if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + qCritical() << "cannot open " << fileName << " for writing ..."; + return false; + } + file.write(buffer.data()); + file.flush(); + file.close(); - UBGraphicsAudioItem* audioItem = qgraphicsitem_cast (item); - if (audioItem && audioItem->isVisible()) { - audioItemToLinkedAudio(audioItem); - continue; - } + } + else + { + qDebug() << "ignoring unmodified page" << mPageIndex + 1; + } - UBGraphicsAppleWidgetItem *appleWidgetItem = qgraphicsitem_cast (item); + return true; +} - if (appleWidgetItem && appleWidgetItem->isVisible()) - { - graphicsAppleWidgetToSvg(appleWidgetItem); - continue; - } +bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::parseCommonItems(QGraphicsItem *item) +{ + UBGraphicsPixmapItem *pixmapItem = qgraphicsitem_cast (item); - UBGraphicsW3CWidgetItem *w3cWidgetItem = qgraphicsitem_cast (item); + if (pixmapItem && pixmapItem->isVisible()) + { + pixmapItemToLinkedImage(pixmapItem); + return true; + } - if (w3cWidgetItem && w3cWidgetItem->isVisible()) - { - graphicsW3CWidgetToSvg(w3cWidgetItem); - continue; - } + UBGraphicsSvgItem *svgItem = qgraphicsitem_cast (item); - UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast (item); + if (svgItem && svgItem->isVisible()) + { + svgItemToLinkedSvg(svgItem); + return true; + } - if (pdfItem && pdfItem->isVisible()) - { - pdfItemToLinkedPDF(pdfItem); - continue; - } + UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (item); - UBGraphicsTextItem *textItem = qgraphicsitem_cast (item); + if (videoItem && videoItem->isVisible()) + { + videoItemToLinkedVideo(videoItem); + return true; + } - if (textItem && textItem->isVisible()) - { - textItemToSvg(textItem); - continue; - } + UBGraphicsAudioItem* audioItem = qgraphicsitem_cast (item); + if (audioItem && audioItem->isVisible()) { + audioItemToLinkedAudio(audioItem); + return true; + } - UBGraphicsCurtainItem *curtainItem = qgraphicsitem_cast (item); + UBGraphicsAppleWidgetItem *appleWidgetItem = qgraphicsitem_cast (item); - if (curtainItem && curtainItem->isVisible()) - { - curtainItemToSvg(curtainItem); - continue; - } + if (appleWidgetItem && appleWidgetItem->isVisible()) + { + graphicsAppleWidgetToSvg(appleWidgetItem); + return true; + } - UBGraphicsRuler *ruler = qgraphicsitem_cast (item); + UBGraphicsW3CWidgetItem *w3cWidgetItem = qgraphicsitem_cast (item); - if (ruler && ruler->isVisible()) - { - rulerToSvg(ruler); - continue; - } + if (w3cWidgetItem && w3cWidgetItem->isVisible()) + { + graphicsW3CWidgetToSvg(w3cWidgetItem); + return true; + } - UBGraphicsCache* cache = qgraphicsitem_cast(item); - if(cache && cache->isVisible()) - { - cacheToSvg(cache); - continue; - } + UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast (item); - UBGraphicsCompass *compass = qgraphicsitem_cast (item); + if (pdfItem && pdfItem->isVisible()) + { + pdfItemToLinkedPDF(pdfItem); + return true; + } - if (compass && compass->isVisible()) - { - compassToSvg(compass); - continue; - } + UBGraphicsTextItem *textItem = qgraphicsitem_cast (item); - UBGraphicsProtractor *protractor = qgraphicsitem_cast (item); + if (textItem && textItem->isVisible()) + { + textItemToSvg(textItem); + return true; + } - if (protractor && protractor->isVisible()) - { - protractorToSvg(protractor); - continue; - } + UBGraphicsCurtainItem *curtainItem = qgraphicsitem_cast (item); - UBGraphicsTriangle *triangle = qgraphicsitem_cast (item); + if (curtainItem && curtainItem->isVisible()) + { + curtainItemToSvg(curtainItem); + return true; + } - if (triangle && triangle->isVisible()) - { - triangleToSvg(triangle); - continue; - } - } + UBGraphicsRuler *ruler = qgraphicsitem_cast (item); - if (openStroke) - { - mXmlWriter.writeEndElement(); - groupHoldsInfo = false; - openStroke = 0; - } + if (ruler && ruler->isVisible()) + { + rulerToSvg(ruler); + return true; + } - mXmlWriter.writeEndDocument(); - QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1); - QFile file(fileName); + UBGraphicsCache* cache = qgraphicsitem_cast(item); + if(cache && cache->isVisible()) + { + cacheToSvg(cache); + return true; + } - if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) - { - qCritical() << "cannot open " << fileName << " for writing ..."; - return false; - } - file.write(buffer.data()); - file.flush(); - file.close(); + UBGraphicsCompass *compass = qgraphicsitem_cast (item); + if (compass && compass->isVisible()) + { + compassToSvg(compass); + return true; } - else + + UBGraphicsProtractor *protractor = qgraphicsitem_cast (item); + + if (protractor && protractor->isVisible()) { - qDebug() << "ignoring unmodified page" << mPageIndex + 1; + protractorToSvg(protractor); + return true; + } + + UBGraphicsTriangle *triangle = qgraphicsitem_cast (item); + + if (triangle && triangle->isVisible()) + { + triangleToSvg(triangle); + return true; } return true; } + void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo) { mXmlWriter.writeStartElement("line"); diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 188bba2f..6514cf20 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -156,6 +156,7 @@ class UBSvgSubsetAdaptor UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex); bool persistScene(); + bool parseCommonItems(QGraphicsItem *item); virtual ~UBSvgSubsetWriter(){} diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index d3faba2b..512c4446 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1235,10 +1235,12 @@ void UBBoardController::ClearUndoStack() while (itUniq.hasNext()) { QGraphicsItem* item = itUniq.next(); - UBGraphicsScene *scene = dynamic_cast(item->scene()); - if(!scene) - { - mActiveScene->deleteItem(item); + if (item->scene()) { + UBGraphicsScene *scene = dynamic_cast(item->scene()); + if(!scene) + { + mActiveScene->deleteItem(item); + } } } diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index db37d684..ad352753 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -236,27 +236,25 @@ void UBGraphicsItemDelegate::setMimeData(QMimeData *mimeData) bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if((NULL != mMimeData) && ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())) - { - QDrag* mDrag = new QDrag(event->widget()); - mDrag->setMimeData(mMimeData); - if (!mDragPixmap.isNull()) { - mDrag->setPixmap(mDragPixmap); - mDrag->setHotSpot(mDragPixmap.rect().center()); - } - mDrag->exec(); - mDragPixmap = QPixmap(); - - return true; + if(mMimeData) { + QDrag* mDrag = new QDrag(event->widget()); + mDrag->setMimeData(mMimeData); + if (!mDragPixmap.isNull()) { + mDrag->setPixmap(mDragPixmap); + mDrag->setHotSpot(mDragPixmap.rect().center()); } + mDrag->exec(); + mDragPixmap = QPixmap(); - if(isLocked()) - { - event->accept(); return true; } - return true; + if(isLocked()) { + event->accept(); + return true; + } else { + return false; + } } bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 1fc87f6a..9c6dee10 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -189,18 +189,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi QGraphicsPolygonItem::paint(painter, option, widget); } -//QPainterPath UBGraphicsPolygonItem::shape() const -//{ +QPainterPath UBGraphicsPolygonItem::shape() const +{ -// QPainterPath path; -// path.addRect(boundingRect()); + QPainterPath path; + path.addRect(boundingRect()); -// return path; + return path; -//// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); +// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); -//// return shapePath; -//} +// return shapePath; +} UBGraphicsScene* UBGraphicsPolygonItem::scene() diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 663658f2..851092b2 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -118,7 +118,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem protected: void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); -// QPainterPath shape () const; + QPainterPath shape () const; private: diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0b19870c..da622bda 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -294,9 +294,15 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) } 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() @@ -315,7 +321,7 @@ 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::groupButtonProcessing() +void UBGraphicsScene::updateGroupButtonState() { QAction *groupAction = UBApplication::mainWindow->actionGroupItems; QList selItems = selectedItems(); @@ -351,11 +357,18 @@ void UBGraphicsScene::groupButtonClicked() UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); foreach (QGraphicsItem *item, selItems) { - item->setSelected(false); - item->setFlag(QGraphicsItem::ItemIsSelectable, false); - item->setFlag( QGraphicsItem::ItemIsMovable, false); - item->setFlag(QGraphicsItem::ItemIsFocusable); - groupItem->addToGroup(item); + if (item->type() == UBGraphicsGroupContainerItem::Type) { + QList childItems = item->childItems(); + UBGraphicsGroupContainerItem *currentGroup = dynamic_cast(item); + if (currentGroup) { + currentGroup->destroy(); + } + foreach (QGraphicsItem *chItem, childItems) { + groupItem->addToGroup(chItem); + } + } else { + groupItem->addToGroup(item); + } } 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: Mouse/Tablet events handling diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 4e531204..c26c76a1 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -305,9 +305,8 @@ public slots: void setToolCursor(int tool); void selectionChangedProcessing(); - void groupButtonProcessing(); + void updateGroupButtonState(); void groupButtonClicked(); - void processGroupItems(); void moveMagnifier(QPoint newPos); void closeMagnifier(); diff --git a/src/domain/ubgraphicsgroupcontaineritem.cpp b/src/domain/ubgraphicsgroupcontaineritem.cpp index 41cc19d6..64f68eee 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.cpp +++ b/src/domain/ubgraphicsgroupcontaineritem.cpp @@ -46,6 +46,12 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) 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); item->setPos(mapFromItem(item, 0, 0)); item->setParentItem(this); @@ -130,20 +136,24 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr QWidget *widget) { Q_UNUSED(widget); - if (option->state & QStyle::State_Selected) { - painter->setBrush(Qt::NoBrush); - QPen tmpPen; - 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)); - } + Q_UNUSED(painter); + Q_UNUSED(option); + +// we would not use paint smth for the moment +// if (option->state & QStyle::State_Selected) { +// painter->setBrush(Qt::NoBrush); +// QPen tmpPen; +// 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 *castScene = dynamic_cast(scene()); + UBGraphicsScene *castScene = dynamic_cast(QGraphicsItem::scene()); return castScene; } @@ -178,7 +188,12 @@ void UBGraphicsGroupContainerItem::destroy() { item->setFlag(QGraphicsItem::ItemIsFocusable, true); } - mDelegate->remove(true); + remove(); + + if (scene()) { + qDebug() << "scene is well casted"; + scene()->removeItem(this); + } } void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -186,9 +201,12 @@ void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *eve if (mDelegate->mousePressEvent(event)) { //NOOP } else { - QGraphicsItem::mousePressEvent(event); + + QGraphicsItem::mousePressEvent(event); setSelected(true); } + + } void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) @@ -198,11 +216,12 @@ void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *even } else { QGraphicsItem::mouseMoveEvent(event); } + } void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); +// mDelegate->mouseReleaseEvent(event); QGraphicsItem::mouseReleaseEvent(event); } diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp index 3fcf7b3f..db50b095 100644 --- a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp @@ -46,3 +46,24 @@ void UBGraphicsGroupContainerItemDelegate::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; +} diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.h b/src/domain/ubgraphicsgroupcontaineritemdelegate.h index 56a525f8..2396b10c 100644 --- a/src/domain/ubgraphicsgroupcontaineritemdelegate.h +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.h @@ -17,6 +17,10 @@ protected: virtual void decorateMenu(QMenu *menu); virtual void buildButtons(); + virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event); + virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + private: DelegateButton *mDestroyGroupButton; }; From 687da649b4a9c0ea698aa81c4c6fd063725e55d1 Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Fri, 11 May 2012 14:57:52 +0200 Subject: [PATCH 14/15] TextItem hotfix --- src/domain/UBGraphicsDelegateFrame.cpp | 6 +++--- src/domain/UBGraphicsItemDelegate.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 027d35da..91a9d353 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -583,9 +583,9 @@ void UBGraphicsDelegateFrame::positionHandles() { QRectF itemRect = delegated()->boundingRect(); -// if (mDelegate->getToolBarItem()->isVisibleOnBoard() -// && mDelegate->getToolBarItem()->isShifting()) -// itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1); + if (mDelegate->getToolBarItem()->isVisibleOnBoard() + && mDelegate->getToolBarItem()->isShifting()) + itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1); QTransform itemTransform = delegated()->sceneTransform(); QPointF topLeft = itemTransform.map(itemRect.topLeft()); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index f167e9d9..35fc5bf6 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -118,7 +118,7 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec void UBGraphicsItemDelegate::init() { - //mToolBarItem = new UBGraphicsToolBarItem(delegated()); + mToolBarItem = new UBGraphicsToolBarItem(delegated()); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame->hide(); @@ -333,17 +333,17 @@ void UBGraphicsItemDelegate::positionHandles() updateButtons(true); -// if (mToolBarItem->isVisibleOnBoard()) -// { -// updateToolBar(); -// mToolBarItem->show(); -// } + if (mToolBarItem->isVisibleOnBoard()) + { + updateToolBar(); + mToolBarItem->show(); + } } else { foreach(DelegateButton* button, mButtons) button->hide(); mFrame->hide(); -// mToolBarItem->hide(); + mToolBarItem->hide(); } } @@ -383,7 +383,7 @@ void UBGraphicsItemDelegate::remove(bool canUndo) scene->removeItem(mFrame); scene->removeItem(mDelegated); - //scene->removeItem(mToolBarItem); + scene->removeItem(mToolBarItem); if (canUndo) { From a77937cdfd47b9b0e450894e1af63b0099fac66f Mon Sep 17 00:00:00 2001 From: Ivan Ilyin Date: Fri, 11 May 2012 16:32:49 +0200 Subject: [PATCH 15/15] export ubz is as previous again --- src/adaptors/UBSvgSubsetAdaptor.cpp | 221 +++++++++++++-------------- src/adaptors/UBSvgSubsetAdaptor.h | 1 - src/domain/UBGraphicsPolygonItem.cpp | 16 +- src/domain/UBGraphicsPolygonItem.h | 2 +- 4 files changed, 115 insertions(+), 125 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 417e835d..b7381aad 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1041,162 +1041,153 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() openStroke = 0; } - UBGraphicsGroupContainerItem *groupItem = qgraphicsitem_cast(item); + UBGraphicsPixmapItem *pixmapItem = qgraphicsitem_cast (item); - if (groupItem && groupItem->isVisible()) + if (pixmapItem && pixmapItem->isVisible()) { - qDebug() << "came across the group during the parsing"; + pixmapItemToLinkedImage(pixmapItem); continue; } - parseCommonItems(item); - } + UBGraphicsSvgItem *svgItem = qgraphicsitem_cast (item); - if (openStroke) - { - mXmlWriter.writeEndElement(); - groupHoldsInfo = false; - openStroke = 0; - } + if (svgItem && svgItem->isVisible()) + { + svgItemToLinkedSvg(svgItem); + continue; + } - mXmlWriter.writeEndDocument(); - QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1); - QFile file(fileName); + UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (item); - if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) - { - qCritical() << "cannot open " << fileName << " for writing ..."; - return false; - } - file.write(buffer.data()); - file.flush(); - file.close(); + if (videoItem && videoItem->isVisible()) + { + videoItemToLinkedVideo(videoItem); + continue; + } - } - else - { - qDebug() << "ignoring unmodified page" << mPageIndex + 1; - } + UBGraphicsAudioItem* audioItem = qgraphicsitem_cast (item); + if (audioItem && audioItem->isVisible()) { + audioItemToLinkedAudio(audioItem); + continue; + } - return true; -} + UBGraphicsAppleWidgetItem *appleWidgetItem = qgraphicsitem_cast (item); -bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::parseCommonItems(QGraphicsItem *item) -{ - UBGraphicsPixmapItem *pixmapItem = qgraphicsitem_cast (item); + if (appleWidgetItem && appleWidgetItem->isVisible()) + { + graphicsAppleWidgetToSvg(appleWidgetItem); + continue; + } - if (pixmapItem && pixmapItem->isVisible()) - { - pixmapItemToLinkedImage(pixmapItem); - return true; - } + UBGraphicsW3CWidgetItem *w3cWidgetItem = qgraphicsitem_cast (item); - UBGraphicsSvgItem *svgItem = qgraphicsitem_cast (item); + if (w3cWidgetItem && w3cWidgetItem->isVisible()) + { + graphicsW3CWidgetToSvg(w3cWidgetItem); + continue; + } - if (svgItem && svgItem->isVisible()) - { - svgItemToLinkedSvg(svgItem); - return true; - } + UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast (item); - UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (item); + if (pdfItem && pdfItem->isVisible()) + { + pdfItemToLinkedPDF(pdfItem); + continue; + } - if (videoItem && videoItem->isVisible()) - { - videoItemToLinkedVideo(videoItem); - return true; - } + UBGraphicsTextItem *textItem = qgraphicsitem_cast (item); - UBGraphicsAudioItem* audioItem = qgraphicsitem_cast (item); - if (audioItem && audioItem->isVisible()) { - audioItemToLinkedAudio(audioItem); - return true; - } + if (textItem && textItem->isVisible()) + { + textItemToSvg(textItem); + continue; + } - UBGraphicsAppleWidgetItem *appleWidgetItem = qgraphicsitem_cast (item); + UBGraphicsCurtainItem *curtainItem = qgraphicsitem_cast (item); - if (appleWidgetItem && appleWidgetItem->isVisible()) - { - graphicsAppleWidgetToSvg(appleWidgetItem); - return true; - } + if (curtainItem && curtainItem->isVisible()) + { + curtainItemToSvg(curtainItem); + continue; + } - UBGraphicsW3CWidgetItem *w3cWidgetItem = qgraphicsitem_cast (item); + UBGraphicsRuler *ruler = qgraphicsitem_cast (item); - if (w3cWidgetItem && w3cWidgetItem->isVisible()) - { - graphicsW3CWidgetToSvg(w3cWidgetItem); - return true; - } + if (ruler && ruler->isVisible()) + { + rulerToSvg(ruler); + continue; + } - UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast (item); + UBGraphicsCache* cache = qgraphicsitem_cast(item); + if(cache && cache->isVisible()) + { + cacheToSvg(cache); + continue; + } - if (pdfItem && pdfItem->isVisible()) - { - pdfItemToLinkedPDF(pdfItem); - return true; - } + UBGraphicsCompass *compass = qgraphicsitem_cast (item); - UBGraphicsTextItem *textItem = qgraphicsitem_cast (item); + if (compass && compass->isVisible()) + { + compassToSvg(compass); + continue; + } - if (textItem && textItem->isVisible()) - { - textItemToSvg(textItem); - return true; - } + UBGraphicsProtractor *protractor = qgraphicsitem_cast (item); - UBGraphicsCurtainItem *curtainItem = qgraphicsitem_cast (item); + if (protractor && protractor->isVisible()) + { + protractorToSvg(protractor); + continue; + } - if (curtainItem && curtainItem->isVisible()) - { - curtainItemToSvg(curtainItem); - return true; - } + UBGraphicsTriangle *triangle = qgraphicsitem_cast (item); - UBGraphicsRuler *ruler = qgraphicsitem_cast (item); + if (triangle && triangle->isVisible()) + { + triangleToSvg(triangle); + continue; + } - if (ruler && ruler->isVisible()) - { - rulerToSvg(ruler); - return true; - } + UBGraphicsGroupContainerItem *groupItem = qgraphicsitem_cast(item); - UBGraphicsCache* cache = qgraphicsitem_cast(item); - if(cache && cache->isVisible()) - { - cacheToSvg(cache); - return true; - } + if (groupItem && groupItem->isVisible()) + { + qDebug() << "came across the group during the parsing"; + continue; + } + } - UBGraphicsCompass *compass = qgraphicsitem_cast (item); + if (openStroke) + { + mXmlWriter.writeEndElement(); + groupHoldsInfo = false; + openStroke = 0; + } - if (compass && compass->isVisible()) - { - compassToSvg(compass); - return true; - } + mXmlWriter.writeEndDocument(); + QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", mPageIndex + 1); + QFile file(fileName); - UBGraphicsProtractor *protractor = qgraphicsitem_cast (item); + if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) + { + qCritical() << "cannot open " << fileName << " for writing ..."; + return false; + } + file.write(buffer.data()); + file.flush(); + file.close(); - if (protractor && protractor->isVisible()) - { - protractorToSvg(protractor); - return true; } - - UBGraphicsTriangle *triangle = qgraphicsitem_cast (item); - - if (triangle && triangle->isVisible()) + else { - triangleToSvg(triangle); - return true; + qDebug() << "ignoring unmodified page" << mPageIndex + 1; } return true; } - - void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo) { mXmlWriter.writeStartElement("line"); diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 6514cf20..188bba2f 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -156,7 +156,6 @@ class UBSvgSubsetAdaptor UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex); bool persistScene(); - bool parseCommonItems(QGraphicsItem *item); virtual ~UBSvgSubsetWriter(){} diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 9c6dee10..1fc87f6a 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -189,18 +189,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi QGraphicsPolygonItem::paint(painter, option, widget); } -QPainterPath UBGraphicsPolygonItem::shape() const -{ +//QPainterPath UBGraphicsPolygonItem::shape() const +//{ - QPainterPath path; - path.addRect(boundingRect()); +// QPainterPath path; +// path.addRect(boundingRect()); - return path; +// return path; -// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); +//// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); -// return shapePath; -} +//// return shapePath; +//} UBGraphicsScene* UBGraphicsPolygonItem::scene() diff --git a/src/domain/UBGraphicsPolygonItem.h b/src/domain/UBGraphicsPolygonItem.h index 851092b2..663658f2 100644 --- a/src/domain/UBGraphicsPolygonItem.h +++ b/src/domain/UBGraphicsPolygonItem.h @@ -118,7 +118,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem protected: void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); - QPainterPath shape () const; +// QPainterPath shape () const; private: