UBToolWidget is QWidget again. He not depends on scene.

Still have some mesh with undo stack and with widget content.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent ccabe5adc7
commit f9e12cc320
  1. 26
      src/board/UBBoardController.cpp
  2. 1
      src/board/UBBoardController.h
  3. 6
      src/board/UBBoardView.cpp
  4. 189
      src/gui/UBToolWidget.cpp
  5. 55
      src/gui/UBToolWidget.h

@ -1782,6 +1782,13 @@ qreal UBBoardController::currentZoom()
return 1.0; return 1.0;
} }
void UBBoardController::removeTool(UBToolWidget* toolWidget)
{
toolWidget->hide();
delete toolWidget;
}
void UBBoardController::hide() void UBBoardController::hide()
{ {
UBApplication::mainWindow->actionLibrary->setChecked(false); UBApplication::mainWindow->actionLibrary->setChecked(false);
@ -2309,30 +2316,29 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget) void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{ {
graphicsWidget->remove();
mActiveScene->setURStackEnable(false); mActiveScene->setURStackEnable(false);
graphicsWidget->remove(false);
UBGraphicsItem *toolW3C = duplicateItem(dynamic_cast<UBItem *>(graphicsWidget)); UBGraphicsItem *toolW3C = duplicateItem(dynamic_cast<UBItem *>(graphicsWidget));
UBGraphicsWidgetItem *copyedGraphicsWidget = NULL; UBGraphicsWidgetItem *copyedGraphicsWidget = NULL;
if (UBGraphicsWidgetItem::Type == toolW3C->type()) if (UBGraphicsWidgetItem::Type == toolW3C->type())
copyedGraphicsWidget = static_cast<UBGraphicsWidgetItem *>(toolW3C); copyedGraphicsWidget = static_cast<UBGraphicsWidgetItem *>(toolW3C);
UBToolWidget *toolWidget = new UBToolWidget(copyedGraphicsWidget); UBToolWidget *toolWidget = new UBToolWidget(copyedGraphicsWidget, mControlView);
mActiveScene->addItem(toolWidget);
qreal ssf = 1 / UBApplication::boardController->systemScaleFactor();
toolWidget->setScale(ssf);
toolWidget->setPos(graphicsWidget->scenePos());
mActiveScene->setURStackEnable(true); mActiveScene->setURStackEnable(true);
QPoint controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center());
toolWidget->centerOn(mControlView->mapTo(mControlContainer, controlViewPos));
toolWidget->show();
} }
void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget) void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
{ {
UBGraphicsWidgetItem *graphicsWidgetItem = addW3cWidget(toolWidget->graphicsWidgetItem()->widgetUrl(), QPointF(0, 0)); UBGraphicsWidgetItem *graphicsWidgetItem = addW3cWidget(toolWidget->toolWidget()->widgetUrl(), QPointF(0, 0));
graphicsWidgetItem->setPos(toolWidget->pos()); graphicsWidgetItem->setPos(toolWidget->pos());
toolWidget->remove(); toolWidget->hide();
delete toolWidget;
graphicsWidgetItem->setSelected(true); graphicsWidgetItem->setSelected(true);
} }

@ -200,6 +200,7 @@ class UBBoardController : public UBDocumentContainer
void hideMessage(); void hideMessage();
void setDisabled(bool disable); void setDisabled(bool disable);
void setColorIndex(int pColorIndex); void setColorIndex(int pColorIndex);
void removeTool(UBToolWidget* toolWidget);
void hide(); void hide();
void show(); void show();
void setWidePageSize(bool checked); void setWidePageSize(bool checked);

@ -553,8 +553,8 @@ Here we determines cases when items should to get mouse press event at pressing
return false; return false;
break; break;
case UBToolWidget::Type: //case UBToolWidget::Type:
return true; // return true;
case QGraphicsWebView::Type: case QGraphicsWebView::Type:
return true; return true;
@ -1123,7 +1123,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
DelegateButton::Type != movingItem->type() && DelegateButton::Type != movingItem->type() &&
QGraphicsSvgItem::Type != movingItem->type() && QGraphicsSvgItem::Type != movingItem->type() &&
UBGraphicsDelegateFrame::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() &&
UBToolWidget::Type != movingItem->type() && // UBToolWidget::Type != movingItem->type() &&
UBGraphicsCache::Type != movingItem->type() && UBGraphicsCache::Type != movingItem->type() &&
QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools. QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools.
!(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) !(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()))

@ -32,32 +32,32 @@ QPixmap* UBToolWidget::sClosePixmap = 0;
QPixmap* UBToolWidget::sUnpinPixmap = 0; QPixmap* UBToolWidget::sUnpinPixmap = 0;
UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent) UBToolWidget::UBToolWidget(const QUrl& pUrl, QWidget *pParent)
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mShouldMoveWidget(false) , mShouldMoveWidget(false)
, mContentMargin(0) , mContentMargin(0)
, mFrameWidth(0) , mFrameWidth(0)
, mGraphicsWebView(0) , mWebView(0)
, mGraphicsWidgetItem(0) , mToolWidget(0)
{ {
int widgetType = UBGraphicsWidgetItem::widgetType(pUrl); int widgetType = UBGraphicsWidgetItem::widgetType(pUrl);
if (widgetType == UBWidgetType::Apple) if (widgetType == UBWidgetType::Apple)
mGraphicsWidgetItem = new UBGraphicsAppleWidgetItem(pUrl, this); mToolWidget = new UBGraphicsAppleWidgetItem(pUrl);
else if (widgetType == UBWidgetType::W3C) else if (widgetType == UBWidgetType::W3C)
mGraphicsWidgetItem = new UBGraphicsW3CWidgetItem(pUrl, this); mToolWidget = new UBGraphicsW3CWidgetItem(pUrl);
else else
qDebug() << "UBToolWidget::UBToolWidget: Unknown widget Type"; qDebug() << "UBToolWidget::UBToolWidget: Unknown widget Type";
initialize(); initialize();
} }
UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent) UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QWidget *pParent)
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mShouldMoveWidget(false) , mShouldMoveWidget(false)
, mContentMargin(0) , mContentMargin(0)
, mFrameWidth(0) , mFrameWidth(0)
, mGraphicsWebView(0) , mWebView(0)
, mGraphicsWidgetItem(pWidget) , mToolWidget(pWidget)
{ {
initialize(); initialize();
javaScriptWindowObjectCleared(); javaScriptWindowObjectCleared();
@ -76,50 +76,66 @@ void UBToolWidget::initialize()
if(!sUnpinPixmap) if(!sUnpinPixmap)
sUnpinPixmap = new QPixmap(":/images/unpin.svg"); sUnpinPixmap = new QPixmap(":/images/unpin.svg");
UBGraphicsScene *wscene = dynamic_cast<UBGraphicsScene *>(mGraphicsWidgetItem->scene()); UBGraphicsScene *wscene = dynamic_cast<UBGraphicsScene *>(mToolWidget->scene());
if (wscene) if (wscene)
{ {
wscene->removeItemFromDeletion(mGraphicsWidgetItem); wscene->removeItemFromDeletion(mToolWidget);
wscene->removeItem(mGraphicsWidgetItem); wscene->removeItem(mToolWidget);
} }
mGraphicsWidgetItem->setParent(this);
QGraphicsLinearLayout *graphicsLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
mWebView = new QWebView(this);
QPalette palette = mWebView->page()->palette();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mWebView->page()->setPalette(palette);
mWebView->installEventFilter(this);
mFrameWidth = UBSettings::settings()->objectFrameWidth; mFrameWidth = UBSettings::settings()->objectFrameWidth;
mContentMargin = sClosePixmap->width() / 2 + mFrameWidth; mContentMargin = sClosePixmap->width() / 2 + mFrameWidth;
graphicsLayout->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin); setLayout(new QVBoxLayout());
setPreferredSize(mGraphicsWidgetItem->preferredWidth() + mContentMargin * 2, mGraphicsWidgetItem->preferredHeight() + mContentMargin * 2); layout()->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin);
layout()->addWidget(mWebView);
mGraphicsWebView = new QGraphicsWebView(this); setFixedSize(mToolWidget->boundingRect().width() + mContentMargin * 2, mToolWidget->boundingRect().height() + mContentMargin * 2);
connect(mGraphicsWebView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
mGraphicsWebView->load(mGraphicsWidgetItem->mainHtml());
graphicsLayout->addItem(mGraphicsWebView);
mGraphicsWebView->setAcceptDrops(false); connect(mWebView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
mGraphicsWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true); mWebView->load(mToolWidget->mainHtml());
mGraphicsWebView->setAttribute(Qt::WA_OpaquePaintEvent, false);
QPalette palette = mGraphicsWebView->page()->palette();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mGraphicsWebView->page()->setPalette(palette);
setLayout(graphicsLayout); mWebView->setAcceptDrops(false);
mWebView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
mWebView->setAttribute(Qt::WA_OpaquePaintEvent, false);
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared())); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared()));
} }
bool UBToolWidget::event(QEvent *event)
bool UBToolWidget::eventFilter(QObject *obj, QEvent *event)
{ {
if (event->type() == QEvent::ShortcutOverride) if (mShouldMoveWidget && obj == mWebView && event->type() == QEvent::MouseMove)
event->accept(); {
return QGraphicsWidget::event(event); QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
if (mouseMoveEvent->buttons() & Qt::LeftButton)
{
move(pos() - mMousePressPos + mWebView->mapTo(this, mouseMoveEvent->pos()));
event->accept();
return true;
}
}
// standard event processing
return QObject::eventFilter(obj, event);
} }
void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBToolWidget::mousePressEvent(QMouseEvent *event)
{ {
QGraphicsWidget::mousePressEvent(event); QWidget::mousePressEvent(event);
/* did webkit consume the mouse press ? */ /* did webkit consume the mouse press ? */
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
@ -128,108 +144,85 @@ void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
update(); update();
} }
void UBToolWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBToolWidget::mouseMoveEvent(QMouseEvent *event)
{ {
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) { if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) {
setPos(pos() - mMousePressPos + event->pos()); move(pos() - mMousePressPos + event->pos());
event->accept(); event->accept();
} }
QGraphicsWidget::mouseMoveEvent(event); QWidget::mouseMoveEvent(event);
} }
void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBToolWidget::mouseReleaseEvent(QMouseEvent *event)
{ {
mShouldMoveWidget = false; mShouldMoveWidget = false;
if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width() && event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height()) { if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width() && event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height()) {
remove(); UBApplication::boardController->removeTool(this);
event->accept(); event->accept();
} }
else if (mGraphicsWidgetItem->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width() && event->pos().y() >= 0 && event->pos().y() < sUnpinPixmap->height()) { else if (mToolWidget->canBeContent() && event->pos().x() >= mContentMargin && event->pos().x() < mContentMargin + sUnpinPixmap->width() && event->pos().y() >= 0 && event->pos().y() < sUnpinPixmap->height()) {
UBApplication::boardController->moveToolWidgetToScene(this); UBApplication::boardController->moveToolWidgetToScene(this);
event->accept(); event->accept();
} }
else else
QGraphicsWidget::mouseReleaseEvent(event); /* don't propgate to parent, the widget is deleted in UBApplication */ QWidget::mouseReleaseEvent(event); /* don't propgate to parent, the widget is deleted in UBApplication */
} }
void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void UBToolWidget::paintEvent(QPaintEvent *event)
{ {
QGraphicsWidget::paint(painter, option, widget); QWidget::paintEvent(event);
/* painting lightweight toolbar */ //if (isActiveWindow())
if (isActiveWindow()) { {
painter->setRenderHint(QPainter::Antialiasing); QPainter painter(this);
painter->setPen(Qt::NoPen); painter.setRenderHint(QPainter::Antialiasing);
painter->setBrush(QColor(127, 127, 127, 127)); painter.setPen(Qt::NoPen);
painter.setBrush(QColor(127, 127, 127, 127));
painter->drawRoundedRect(QRectF(sClosePixmap->width() / 2, sClosePixmap->height() / 2, preferredWidth() - sClosePixmap->width(), mFrameWidth), mFrameWidth / 2, mFrameWidth / 2);
painter->drawPixmap(0, 0, *sClosePixmap); painter.drawRoundedRect(QRectF(sClosePixmap->width() / 2
if (mGraphicsWidgetItem->canBeContent()) , sClosePixmap->height() / 2
painter->drawPixmap(mContentMargin, 0, *sUnpinPixmap); , width() - sClosePixmap->width()
, mFrameWidth)
, mFrameWidth / 2
, mFrameWidth / 2);
painter.drawPixmap(0, 0, *sClosePixmap);
if (mToolWidget->canBeContent())
painter.drawPixmap(mContentMargin, 0, *sUnpinPixmap);
} }
} }
void UBToolWidget::javaScriptWindowObjectCleared() void UBToolWidget::javaScriptWindowObjectCleared()
{ {
UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene(), mGraphicsWidgetItem); UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene(), mToolWidget);
mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); mWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI);
UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem); UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mToolWidget);
if (graphicsW3cWidgetItem) if (graphicsW3cWidgetItem)
{ {
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem); UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem);
mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI); mWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI);
} }
} }
UBGraphicsWidgetItem* UBToolWidget::graphicsWidgetItem() const UBGraphicsWidgetItem* UBToolWidget::toolWidget() const
{ {
return mGraphicsWidgetItem; return mToolWidget;
} }
QPointF UBToolWidget::naturalCenter() const QPoint UBToolWidget::naturalCenter() const
{ {
if (mGraphicsWebView) if (mWebView)
return mGraphicsWebView->geometry().center(); return mWebView->geometry().center();
else else
return QPointF(0, 0); return QPoint(0, 0);
}
void UBToolWidget::centerOn(const QPointF& pos)
{
QGraphicsWidget::setPos(pos - QPointF(preferredWidth() / 2, preferredHeight() / 2));
}
void UBToolWidget::remove()
{
mGraphicsWebView->setHtml(QString());
scene()->removeItem(this);
}
UBGraphicsScene* UBToolWidget::scene()
{
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene());
}
QPointF UBToolWidget::pos() const
{
return QPointF(QGraphicsItem::pos().x() + mContentMargin * scale(), QGraphicsItem::pos().y() + mContentMargin * scale());
}
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());
} }
int UBToolWidget::type() const void UBToolWidget::centerOn(const QPoint& pos)
{ {
return Type; QWidget::move(pos - QPoint(width() / 2, height() / 2));
} }

@ -17,60 +17,51 @@
#define UBTOOLWIDGET_H_ #define UBTOOLWIDGET_H_
#include <QtGui> #include <QtGui>
#include <QtWebKit>
#include "core/UB.h"
class UBGraphicsScene;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class QWidget;
class UBGraphicsScene;
class QWebView;
class UBToolWidget : public QGraphicsWidget class UBToolWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT;
public: public:
UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent = 0); UBToolWidget(const QUrl& pUrl, QWidget* pParent = 0);
UBToolWidget(UBGraphicsWidgetItem* pGraphicsWidgetItem, QGraphicsItem *pParent = 0); UBToolWidget(UBGraphicsWidgetItem* pWidget, QWidget* pParent = 0);
virtual ~UBToolWidget(); virtual ~UBToolWidget();
UBGraphicsWidgetItem* graphicsWidgetItem() const; void centerOn(const QPoint& pos);
QPointF naturalCenter() const;
void centerOn(const QPointF& pos); QPoint naturalCenter() const;
void remove();
virtual UBGraphicsScene* scene(); UBGraphicsWidgetItem *toolWidget() const;
virtual QPointF pos() const;
virtual void setPos(const QPointF &point);
virtual void setPos(qreal x, qreal y);
virtual int type() const;
enum
{
Type = UBGraphicsItemType::ToolWidgetItemType
};
protected: protected:
void initialize(); void initialize();
virtual void paintEvent(QPaintEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual bool event(QEvent *event); virtual bool eventFilter(QObject *obj, QEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private slots: private slots:
void javaScriptWindowObjectCleared(); void javaScriptWindowObjectCleared();
protected: protected:
bool mShouldMoveWidget; QWebView *mWebView;
int mContentMargin; UBGraphicsWidgetItem *mToolWidget;
int mFrameWidth;
QGraphicsWebView *mGraphicsWebView;
UBGraphicsWidgetItem *mGraphicsWidgetItem;
QPointF mMousePressPos;
static QPixmap *sClosePixmap; static QPixmap *sClosePixmap;
static QPixmap *sUnpinPixmap; static QPixmap *sUnpinPixmap;
QPoint mMousePressPos;
bool mShouldMoveWidget;
int mContentMargin;
int mFrameWidth;
}; };
#endif /* UBTOOLWIDGET_H_ */ #endif /* UBTOOLWIDGET_H_ */

Loading…
Cancel
Save