Fixed widgets removing.

preferencesAboutTextFull
Yimgo 12 years ago
parent 4cdccf4afe
commit 11b164ed78
  1. 9
      src/board/UBBoardController.cpp
  2. 26
      src/domain/UBGraphicsItemDelegate.cpp
  3. 45
      src/gui/UBToolWidget.cpp
  4. 4
      src/gui/UBToolWidget.h

@ -2151,7 +2151,7 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget) void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{ {
graphicsWidget->hide(); graphicsWidget->remove();
UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget); UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget);
mActiveScene->addItem(toolWidget); mActiveScene->addItem(toolWidget);
@ -2164,10 +2164,9 @@ void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* gr
void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget) void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
{ {
UBGraphicsWidgetItem *graphicsWidgetItem = toolWidget->graphicsWidgetItem(); UBGraphicsWidgetItem *graphicsWidgetItem = addW3cWidget(toolWidget->graphicsWidgetItem()->widgetUrl(), QPointF(0, 0));
graphicsWidgetItem->setPos(toolWidget->pos());
toolWidget->hide(); toolWidget->remove();
graphicsWidgetItem->show();
graphicsWidgetItem->setSelected(true); graphicsWidgetItem->setSelected(true);
} }

@ -378,13 +378,35 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
void UBGraphicsItemDelegate::remove(bool canUndo) void UBGraphicsItemDelegate::remove(bool canUndo)
{ {
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene()); /*UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
if (scene && canUndo) if (scene && canUndo)
{ {
UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0); UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0);
UBApplication::undoStack->push(uc); UBApplication::undoStack->push(uc);
} }
mDelegated->hide(); mDelegated->hide(); */
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(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<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);
}
}
} }

@ -41,6 +41,7 @@ QPixmap* UBToolWidget::sUnpinPixmap = 0;
UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent) UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent)
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mGraphicsWidgetItem(0) , mGraphicsWidgetItem(0)
, mGraphicsWebView(0)
, mShouldMoveWidget(false) , mShouldMoveWidget(false)
{ {
int widgetType = UBGraphicsWidgetItem::widgetType(pUrl); int widgetType = UBGraphicsWidgetItem::widgetType(pUrl);
@ -89,27 +90,22 @@ void UBToolWidget::initialize()
graphicsLayout->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin); graphicsLayout->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin);
setPreferredSize(mGraphicsWidgetItem->preferredWidth() + mContentMargin * 2, mGraphicsWidgetItem->preferredHeight() + mContentMargin * 2); 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 = mGraphicsWebView->page()->palette();
QPalette palette = mGraphicsWidgetItem->page()->palette();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent)); palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mGraphicsWidgetItem->page()->setPalette(palette); mGraphicsWebView->page()->setPalette(palette);
connect(mGraphicsWidgetItem->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
QGraphicsWebView *addedGraphicsWebView = new QGraphicsWebView();
addedGraphicsWebView->load(mGraphicsWidgetItem->mainHtml());
graphicsLayout->addItem(addedGraphicsWebView);
setLayout(graphicsLayout); setLayout(graphicsLayout);
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared())); 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()); UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene());
mGraphicsWidgetItem->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI);
UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem); UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem);
if (graphicsW3cWidgetItem) if (graphicsW3cWidgetItem)
{ {
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(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()); 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) void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
QGraphicsWidget::paint(painter, option, 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() 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())
{ {
hide(); remove();
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()
@ -235,8 +236,8 @@ void UBToolWidget::centerOn(const QPointF& pos)
QPointF UBToolWidget::naturalCenter() const QPointF UBToolWidget::naturalCenter() const
{ {
if (mGraphicsWidgetItem) if (mGraphicsWebView)
return mGraphicsWidgetItem->geometry().center(); return mGraphicsWebView->geometry().center();
else else
return QPointF(0, 0); return QPointF(0, 0);
} }
@ -251,3 +252,9 @@ UBGraphicsScene* UBToolWidget::scene()
{ {
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene()); return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene());
} }
void UBToolWidget::remove()
{
mGraphicsWebView->setHtml(QString());
scene()->removeItem(this);
}

@ -17,6 +17,7 @@
#define UBTOOLWIDGET_H_ #define UBTOOLWIDGET_H_
#include <QtGui> #include <QtGui>
#include <QtWebKit>
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class QWidget; class QWidget;
@ -36,9 +37,11 @@ class UBToolWidget : public QGraphicsWidget
QPointF naturalCenter() const; QPointF naturalCenter() const;
UBGraphicsWidgetItem* graphicsWidgetItem() const; UBGraphicsWidgetItem* graphicsWidgetItem() const;
void remove();
virtual UBGraphicsScene* scene(); virtual UBGraphicsScene* scene();
virtual void setPos(const QPointF &point); virtual void setPos(const QPointF &point);
virtual void setPos(qreal x, qreal y); virtual void setPos(qreal x, qreal y);
virtual QPointF pos() const;
protected: protected:
void initialize(); void initialize();
@ -59,6 +62,7 @@ class UBToolWidget : public QGraphicsWidget
static QPixmap *sUnpinPixmap; static QPixmap *sUnpinPixmap;
UBGraphicsWidgetItem *mGraphicsWidgetItem; UBGraphicsWidgetItem *mGraphicsWidgetItem;
QGraphicsWebView *mGraphicsWebView;
QPointF mMousePressPos; QPointF mMousePressPos;

Loading…
Cancel
Save