diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index b2580fbe..587a3269 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -2151,7 +2151,7 @@ void UBBoardController::togglePodcast(bool checked) void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget) { - graphicsWidget->hide(); + graphicsWidget->remove(); UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget); mActiveScene->addItem(toolWidget); @@ -2164,10 +2164,9 @@ void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* gr void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget) { - UBGraphicsWidgetItem *graphicsWidgetItem = toolWidget->graphicsWidgetItem(); - - toolWidget->hide(); - graphicsWidgetItem->show(); + UBGraphicsWidgetItem *graphicsWidgetItem = addW3cWidget(toolWidget->graphicsWidgetItem()->widgetUrl(), QPointF(0, 0)); + graphicsWidgetItem->setPos(toolWidget->pos()); + toolWidget->remove(); graphicsWidgetItem->setSelected(true); } diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index db0a1ff9..2195d477 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -378,13 +378,35 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible) void UBGraphicsItemDelegate::remove(bool canUndo) { - UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); + /*UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); if (scene && canUndo) { UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0); UBApplication::undoStack->push(uc); } - mDelegated->hide(); + mDelegated->hide(); */ + + UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); + if (scene) + { + foreach(DelegateButton* button, mButtons) + scene->removeItem(button); + + scene->removeItem(mFrame); + + /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ + UBGraphicsWebView *mDelegated_casted = dynamic_cast(mDelegated); + if (mDelegated_casted) + mDelegated_casted->setHtml(QString()); + + scene->removeItem(mDelegated); + + if (canUndo) + { + UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0); + UBApplication::undoStack->push(uc); + } + } } diff --git a/src/gui/UBToolWidget.cpp b/src/gui/UBToolWidget.cpp index e3055060..15f99d47 100644 --- a/src/gui/UBToolWidget.cpp +++ b/src/gui/UBToolWidget.cpp @@ -41,6 +41,7 @@ QPixmap* UBToolWidget::sUnpinPixmap = 0; UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent) : QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) , mGraphicsWidgetItem(0) + , mGraphicsWebView(0) , mShouldMoveWidget(false) { int widgetType = UBGraphicsWidgetItem::widgetType(pUrl); @@ -89,27 +90,22 @@ void UBToolWidget::initialize() graphicsLayout->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin); setPreferredSize(mGraphicsWidgetItem->preferredWidth() + mContentMargin * 2, mGraphicsWidgetItem->preferredHeight() + mContentMargin * 2); - mGraphicsWidgetItem->setAcceptDrops(false); + mGraphicsWebView = new QGraphicsWebView(); + connect(mGraphicsWebView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared())); + mGraphicsWebView->load(mGraphicsWidgetItem->mainHtml()); + graphicsLayout->addItem(mGraphicsWebView); - mGraphicsWidgetItem->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + mGraphicsWebView->setAcceptDrops(false); + mGraphicsWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + mGraphicsWebView->setAttribute(Qt::WA_OpaquePaintEvent, false); - mGraphicsWidgetItem->setAttribute(Qt::WA_OpaquePaintEvent, false); - - QPalette palette = mGraphicsWidgetItem->page()->palette(); + QPalette palette = mGraphicsWebView->page()->palette(); palette.setBrush(QPalette::Base, QBrush(Qt::transparent)); - mGraphicsWidgetItem->page()->setPalette(palette); - - connect(mGraphicsWidgetItem->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared())); - - QGraphicsWebView *addedGraphicsWebView = new QGraphicsWebView(); - addedGraphicsWebView->load(mGraphicsWidgetItem->mainHtml()); - graphicsLayout->addItem(addedGraphicsWebView); + mGraphicsWebView->page()->setPalette(palette); setLayout(graphicsLayout); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared())); - - mGraphicsWidgetItem->installEventFilter(this); } @@ -117,13 +113,13 @@ void UBToolWidget::javaScriptWindowObjectCleared() { UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene()); - mGraphicsWidgetItem->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); + mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast(mGraphicsWidgetItem); if (graphicsW3cWidgetItem) { UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem); - mGraphicsWidgetItem->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI); + mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI); } } @@ -137,6 +133,11 @@ void UBToolWidget::setPos(qreal x, qreal y) QGraphicsItem::setPos(x - mContentMargin * scale(), y - mContentMargin * scale()); } +QPointF UBToolWidget::pos() const +{ + return QPointF(QGraphicsItem::pos().x() + mContentMargin * scale(), QGraphicsItem::pos().y() + mContentMargin * scale()); +} + void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QGraphicsWidget::paint(painter, option, widget); @@ -192,7 +193,7 @@ void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width() && event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height()) { - hide(); + remove(); event->accept(); } else if (mGraphicsWidgetItem->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width() @@ -235,8 +236,8 @@ void UBToolWidget::centerOn(const QPointF& pos) QPointF UBToolWidget::naturalCenter() const { - if (mGraphicsWidgetItem) - return mGraphicsWidgetItem->geometry().center(); + if (mGraphicsWebView) + return mGraphicsWebView->geometry().center(); else return QPointF(0, 0); } @@ -251,3 +252,9 @@ UBGraphicsScene* UBToolWidget::scene() { return qobject_cast(QGraphicsItem::scene()); } + +void UBToolWidget::remove() +{ + mGraphicsWebView->setHtml(QString()); + scene()->removeItem(this); +} diff --git a/src/gui/UBToolWidget.h b/src/gui/UBToolWidget.h index 78bb2d0c..fa23a459 100644 --- a/src/gui/UBToolWidget.h +++ b/src/gui/UBToolWidget.h @@ -17,6 +17,7 @@ #define UBTOOLWIDGET_H_ #include +#include class UBGraphicsWidgetItem; class QWidget; @@ -36,9 +37,11 @@ class UBToolWidget : public QGraphicsWidget QPointF naturalCenter() const; UBGraphicsWidgetItem* graphicsWidgetItem() const; + void remove(); virtual UBGraphicsScene* scene(); virtual void setPos(const QPointF &point); virtual void setPos(qreal x, qreal y); + virtual QPointF pos() const; protected: void initialize(); @@ -59,6 +62,7 @@ class UBToolWidget : public QGraphicsWidget static QPixmap *sUnpinPixmap; UBGraphicsWidgetItem *mGraphicsWidgetItem; + QGraphicsWebView *mGraphicsWebView; QPointF mMousePressPos;