Segfault with ToolWidget instances fixed.

Trying to position ToolWidget at the right place to move naturally from widgetitem to toolidget.
preferencesAboutTextFull
Yimgo 12 years ago
parent d5af873782
commit cb7a0a3807
  1. 7
      src/board/UBBoardController.cpp
  2. 25
      src/domain/UBGraphicsItemDelegate.cpp
  3. 2
      src/frameworks/UBCoreGraphicsScene.cpp
  4. 13
      src/gui/UBToolWidget.cpp
  5. 2
      src/gui/UBToolWidget.h

@ -2041,10 +2041,15 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget) void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{ {
graphicsWidget->remove(); QPointF controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center());
graphicsWidget->hide();
UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget); UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget);
mActiveScene->addItem(toolWidget); mActiveScene->addItem(toolWidget);
qreal ssf = 1 / UBApplication::boardController->systemScaleFactor();
toolWidget->scale(ssf, ssf);
toolWidget->setPos(graphicsWidget->scenePos());
} }

@ -378,28 +378,13 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
void UBGraphicsItemDelegate::remove(bool canUndo) void UBGraphicsItemDelegate::remove(bool canUndo)
{ {
// QGraphicsScene* scene = mDelegated->scene();
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene()); UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
if (scene) if (scene && canUndo)
{ {
foreach(DelegateButton* button, mButtons) UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0);
scene->removeItem(button); UBApplication::undoStack->push(uc);
}
scene->removeItem(mFrame); mDelegated->hide();
/* 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<UBGraphicsWebView*>(mDelegated);
if (mDelegated_casted)
mDelegated_casted->setHtml(QString());
scene->removeItem(mDelegated);
if (canUndo)
{
UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0);
UBApplication::undoStack->push(uc);
}
}
} }

@ -32,7 +32,7 @@ UBCoreGraphicsScene::~UBCoreGraphicsScene()
//we must delete removed items that are no more in any scene //we must delete removed items that are no more in any scene
foreach (const QGraphicsItem* item, mItemsToDelete) foreach (const QGraphicsItem* item, mItemsToDelete)
{ {
if (item && (item->scene() == NULL || item->scene() == this)) if (item->scene() == NULL || item->scene() == this)
{ {
delete item; delete item;
} }

@ -61,8 +61,6 @@ UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent
, mShouldMoveWidget(false) , mShouldMoveWidget(false)
{ {
mGraphicsWidgetItem = pWidget; mGraphicsWidgetItem = pWidget;
mGraphicsWidgetItem->setParent(this);
mGraphicsWidgetItem->loadMainHtml();
initialize(); initialize();
@ -129,6 +127,15 @@ void UBToolWidget::javaScriptWindowObjectCleared()
} }
} }
void UBToolWidget::setPos(const QPointF &point)
{
UBToolWidget::setPos(point.x(), point.y());
}
void UBToolWidget::setPos(qreal x, qreal y)
{
QGraphicsItem::setPos((x - mContentMargin)*scale(), (y - mContentMargin)*scale());
}
void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
@ -185,7 +192,7 @@ void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width() if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width()
&& event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height()) && event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height())
{ {
scene()->removeItem(this); hide();
event->accept(); event->accept();
} }
else if (mGraphicsWidgetItem->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width() else if (mGraphicsWidgetItem->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width()

@ -37,6 +37,8 @@ class UBToolWidget : public QGraphicsWidget
UBGraphicsWidgetItem* graphicsWidgetItem() const; UBGraphicsWidgetItem* graphicsWidgetItem() const;
virtual UBGraphicsScene* scene(); virtual UBGraphicsScene* scene();
virtual void setPos(const QPointF &point);
virtual void setPos(qreal x, qreal y);
protected: protected:
void initialize(); void initialize();

Loading…
Cancel
Save