Tool widgets supported.

The old code has to be removed and remaining bugs fixed.
preferencesAboutTextFull
Yimgo 12 years ago
parent 9a62370716
commit a75ce30261
  1. 99
      src/board/UBBoardController.cpp
  2. 6
      src/board/UBBoardController.h
  3. 3
      src/domain/UBGraphicsScene.cpp
  4. 3
      src/domain/UBGraphicsScene.h
  5. 157
      src/gui/UBToolWidget.cpp
  6. 29
      src/gui/UBToolWidget.h

@ -1543,52 +1543,15 @@ qreal UBBoardController::currentZoom()
return 1.0; return 1.0;
} }
UBToolWidget* UBBoardController::addTool(const QUrl& toolUrl)
{
return addTool(toolUrl, mControlView->mapToScene(mControlView->rect().center()));
}
UBToolWidget* UBBoardController::addTool(const QUrl& toolUrl, QPointF scenePos)
{
UBToolWidget *toolWidget = new UBToolWidget(toolUrl, mMainWindow); // Deleted in UBBoardController::removeTool
QPoint pos = mControlView->mapToGlobal(mControlView->mapFromScene(scenePos));
pos -= QPoint(toolWidget->width() / 2, toolWidget->height() / 2);
toolWidget->move(pos);
mTools.append(toolWidget);
toolWidget->show();
return toolWidget;
}
void UBBoardController::removeTool(UBToolWidget* toolWidget)
{
toolWidget->hide();
mTools.removeAll(toolWidget);
delete toolWidget;
}
void UBBoardController::hide() void UBBoardController::hide()
{ {
UBApplication::mainWindow->actionLibrary->setChecked(false); UBApplication::mainWindow->actionLibrary->setChecked(false);
controlViewHidden();
} }
void UBBoardController::show() void UBBoardController::show()
{ {
UBApplication::mainWindow->actionLibrary->setChecked(false); UBApplication::mainWindow->actionLibrary->setChecked(false);
controlViewShown();
} }
@ -1813,25 +1776,6 @@ void UBBoardController::grabScene(const QRectF& pSceneRect)
} }
} }
void UBBoardController::controlViewHidden()
{
foreach(UBToolWidget* tool, mTools)
{
tool->hide();
}
}
void UBBoardController::controlViewShown()
{
foreach(UBToolWidget* tool, mTools)
{
tool->show();
}
}
UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos)
{ {
QUuid uuid = QUuid::createUuid(); QUuid uuid = QUuid::createUuid();
@ -2098,56 +2042,39 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget) void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{ {
/*QPoint controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center()); graphicsWidget->remove();
graphicsWidget->setSelected(false);
UBAbstractWidget *aw = graphicsWidget->widgetWebView();
graphicsWidget->setWidget(0);
UBToolWidget *toolWidget = new UBToolWidget(aw, mControlContainer); UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget);
mActiveScene->addItem(toolWidget);
graphicsWidget->scene()->removeItem(graphicsWidget); // TODO UB 4.6 probably leaking the frame
toolWidget->centerOn(mControlView->mapTo(mControlContainer, controlViewPos));
toolWidget->show();*/
} }
void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget) void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
{ {
/*int xIsOdd = toolWidget->width() % 2; QPoint mainWindowCenter = (QPointF(toolWidget->preferredWidth(), toolWidget->preferredHeight()) / 2).toPoint();
int yIsOdd = toolWidget->height() % 2;
QPoint mainWindowCenter = toolWidget->mapTo(mMainWindow, QPoint(toolWidget->width(), toolWidget->height()) / 2);
UBAbstractWidget* webWidget = toolWidget->webWidget();
webWidget->setParent(0);
UBGraphicsWidgetItem* graphicsWidget = 0; UBGraphicsWidgetItem *graphicsWidgetItem = toolWidget->graphicsWidgetItem();
graphicsWidgetItem->setParent(0);
UBW3CWidget* w3cWidget = qobject_cast<UBW3CWidget*>(webWidget); if (qobject_cast<UBGraphicsW3CWidgetItem*>(graphicsWidgetItem))
if (w3cWidget)
{ {
graphicsWidget = new UBGraphicsW3CWidgetItem(w3cWidget); graphicsWidgetItem = qobject_cast<UBGraphicsW3CWidgetItem*>(graphicsWidgetItem);
} }
else else
{ {
UBAppleWidget* appleWidget = qobject_cast<UBAppleWidget*>(webWidget); if (qobject_cast<UBGraphicsAppleWidgetItem*>(graphicsWidgetItem))
if (appleWidget)
{ {
graphicsWidget = new UBGraphicsAppleWidgetItem(appleWidget); graphicsWidgetItem = qobject_cast<UBGraphicsAppleWidgetItem*>(graphicsWidgetItem);
} }
} }
QPoint controlViewCenter = mControlView->mapFrom(mMainWindow, mainWindowCenter); QPoint controlViewCenter = mControlView->mapFrom(mMainWindow, mainWindowCenter);
QPointF scenePos = mControlView->mapToScene(controlViewCenter) + QPointF(xIsOdd * 0.5, yIsOdd * 0.5); QPointF scenePos = mControlView->mapToScene(controlViewCenter);
mActiveScene->addGraphicsWidget(graphicsWidget, scenePos); mActiveScene->addGraphicsWidget(graphicsWidgetItem, scenePos);
toolWidget->hide(); toolWidget->hide();
toolWidget->deleteLater();*/ toolWidget->deleteLater();
} }

@ -195,17 +195,12 @@ class UBBoardController : public UBDocumentContainer
void hideMessage(); void hideMessage();
void setDisabled(bool disable); void setDisabled(bool disable);
void setColorIndex(int pColorIndex); void setColorIndex(int pColorIndex);
UBToolWidget* addTool(const QUrl& toolUrl, QPointF scenePos);
UBToolWidget* addTool(const QUrl& toolUrl);
void removeTool(UBToolWidget* toolWidget);
void hide(); void hide();
void show(); void show();
void setWidePageSize(bool checked); void setWidePageSize(bool checked);
void setRegularPageSize(bool checked); void setRegularPageSize(bool checked);
void stylusToolChanged(int tool); void stylusToolChanged(int tool);
void grabScene(const QRectF& pSceneRect); void grabScene(const QRectF& pSceneRect);
void controlViewHidden();
void controlViewShown();
UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos);
UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos);
UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos); UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
@ -275,7 +270,6 @@ class UBBoardController : public UBDocumentContainer
QColor mPenColorOnLightBackground; QColor mPenColorOnLightBackground;
QColor mMarkerColorOnDarkBackground; QColor mMarkerColorOnDarkBackground;
QColor mMarkerColorOnLightBackground; QColor mMarkerColorOnLightBackground;
QList<UBToolWidget*> mTools;
qreal mSystemScaleFactor; qreal mSystemScaleFactor;
bool mCleanupDone; bool mCleanupDone;
QMap<QAction*, QPair<QString, QString> > mActionTexts; QMap<QAction*, QPair<QString, QString> > mActionTexts;

@ -31,6 +31,7 @@
#include "gui/UBMagnifer.h" #include "gui/UBMagnifer.h"
#include "gui/UBMainWindow.h" #include "gui/UBMainWindow.h"
#include "gui/UBToolWidget.h"
#include "tools/UBGraphicsRuler.h" #include "tools/UBGraphicsRuler.h"
#include "tools/UBGraphicsProtractor.h" #include "tools/UBGraphicsProtractor.h"
@ -1464,6 +1465,8 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co
UBApplication::boardController->controlView()->setFocus(); UBApplication::boardController->controlView()->setFocus();
} }
UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, const QPointF& pPos) UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, const QPointF& pPos)
{ {
QStringList widgetPaths = UBPersistenceManager::persistenceManager()->allWidgets(UBSettings::settings()->applicationApplicationsLibraryDirectory()); QStringList widgetPaths = UBPersistenceManager::persistenceManager()->allWidgets(UBSettings::settings()->applicationApplicationsLibraryDirectory());

@ -35,6 +35,7 @@ class UBGraphicsAudioItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class UBGraphicsAppleWidgetItem; class UBGraphicsAppleWidgetItem;
class UBToolWidget;
class UBGraphicsPDFItem; class UBGraphicsPDFItem;
class UBGraphicsTextItem; class UBGraphicsTextItem;
class UBGraphicsRuler; class UBGraphicsRuler;
@ -133,6 +134,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0));
void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0)); void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0));
UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));
UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));
UBGraphicsMediaItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsMediaItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));

@ -23,9 +23,6 @@
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBAppleWidget.h"
#include "domain/UBW3CWidget.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsWidgetItem.h"
@ -41,38 +38,31 @@ QPixmap* UBToolWidget::sClosePixmap = 0;
QPixmap* UBToolWidget::sUnpinPixmap = 0; QPixmap* UBToolWidget::sUnpinPixmap = 0;
UBToolWidget::UBToolWidget(const QUrl& pUrl, QWidget* pParent) UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent)
: QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mToolWidget(0) , mGraphicsWidgetItem(0)
, mShouldMoveWidget(false) , mShouldMoveWidget(false)
{ {
int widgetType = UBAbstractWidget::widgetType(pUrl); int widgetType = UBGraphicsWidgetItem::widgetType(pUrl);
if(widgetType == UBWidgetType::Apple) if (widgetType == UBWidgetType::Apple)
{ mGraphicsWidgetItem = new UBGraphicsAppleWidgetItem(pUrl, this);
mToolWidget = new UBAppleWidget(pUrl, this); else if (widgetType == UBWidgetType::W3C)
} mGraphicsWidgetItem = new UBGraphicsW3CWidgetItem(pUrl, this);
else if(widgetType == UBWidgetType::W3C)
{
mToolWidget = new UBW3CWidget(pUrl, this);
}
else else
{
qDebug() << "UBToolWidget::UBToolWidget: Unknown widget Type"; qDebug() << "UBToolWidget::UBToolWidget: Unknown widget Type";
return;
}
initialize(); initialize();
} }
UBToolWidget::UBToolWidget(UBAbstractWidget* pWidget, QWidget* pParent) UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent)
: QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mToolWidget(pWidget)
, mShouldMoveWidget(false) , mShouldMoveWidget(false)
{ {
mToolWidget->setParent(this); mGraphicsWidgetItem = pWidget;
mToolWidget->loadMainHtml(); mGraphicsWidgetItem->setParent(this);
mGraphicsWidgetItem->loadMainHtml();
initialize(); initialize();
@ -88,85 +78,81 @@ UBToolWidget::~UBToolWidget()
void UBToolWidget::initialize() void UBToolWidget::initialize()
{ {
mToolWidget->setAcceptDrops(false); if (!sClosePixmap)
if(!sClosePixmap)
{
sClosePixmap = new QPixmap(":/images/close.svg"); sClosePixmap = new QPixmap(":/images/close.svg");
}
if(!sUnpinPixmap) if(!sUnpinPixmap)
{
sUnpinPixmap = new QPixmap(":/images/unpin.svg"); sUnpinPixmap = new QPixmap(":/images/unpin.svg");
}
mToolWidget->settings()->setAttribute(QWebSettings::PluginsEnabled, true); QGraphicsLinearLayout *graphicsLayout = new QGraphicsLinearLayout(Qt::Vertical);
mToolWidget->setAttribute(Qt::WA_OpaquePaintEvent, false); mFrameWidth = UBSettings::settings()->objectFrameWidth;
mContentMargin = sClosePixmap->width() / 2 + mFrameWidth;
graphicsLayout->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin);
setPreferredSize(mGraphicsWidgetItem->preferredWidth() + mContentMargin * 2, mGraphicsWidgetItem->preferredHeight() + mContentMargin * 2);
QPalette palette = mToolWidget->page()->palette(); mGraphicsWidgetItem->setAcceptDrops(false);
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mToolWidget->page()->setPalette(palette);
connect(mToolWidget->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared())); mGraphicsWidgetItem->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared()));
setLayout(new QVBoxLayout()); mGraphicsWidgetItem->setAttribute(Qt::WA_OpaquePaintEvent, false);
mFrameWidth = UBSettings::settings()->objectFrameWidth; QPalette palette = mGraphicsWidgetItem->page()->palette();
mContentMargin = sClosePixmap->width() / 2 + mFrameWidth; palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mGraphicsWidgetItem->page()->setPalette(palette);
connect(mGraphicsWidgetItem->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
layout()->setContentsMargins(mContentMargin, mContentMargin, mContentMargin, mContentMargin); QGraphicsWebView *addedGraphicsWebView = new QGraphicsWebView();
layout()->addWidget(mToolWidget); addedGraphicsWebView->load(mGraphicsWidgetItem->mainHtml());
graphicsLayout->addItem(addedGraphicsWebView);
setFixedSize(mToolWidget->width() + mContentMargin * 2, mToolWidget->height() + mContentMargin * 2); setLayout(graphicsLayout);
mToolWidget->installEventFilter(this); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared()));
mGraphicsWidgetItem->installEventFilter(this);
} }
void UBToolWidget::javaScriptWindowObjectCleared() void UBToolWidget::javaScriptWindowObjectCleared()
{ {
UBWidgetUniboardAPI* uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene()); UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene());
mToolWidget->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); mGraphicsWidgetItem->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI);
/*UBW3CWidget* w3c = dynamic_cast<UBW3CWidget*>(mToolWidget); UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem);
if (w3c) if (graphicsW3cWidgetItem)
{ {
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(w3c); UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem);
mToolWidget->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI); mGraphicsWidgetItem->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI);
}*/ }
} }
void UBToolWidget::paintEvent(QPaintEvent *event) void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
QWidget::paintEvent(event); QGraphicsWidget::paint(painter, option, widget);
if (isActiveWindow()) if (isActiveWindow())
{ {
QPainter painter(this); painter->setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::Antialiasing); painter->setPen(Qt::NoPen);
painter.setPen(Qt::NoPen); painter->setBrush(QColor(127, 127, 127, 127));
painter.setBrush(QColor(127, 127, 127, 127));
painter.drawRoundedRect(QRectF(sClosePixmap->width() / 2 painter->drawRoundedRect(QRectF(sClosePixmap->width() / 2, sClosePixmap->height() / 2, preferredWidth() - sClosePixmap->width(), mFrameWidth), mFrameWidth / 2, mFrameWidth / 2);
, sClosePixmap->height() / 2
, width() - sClosePixmap->width()
, mFrameWidth), mFrameWidth / 2, mFrameWidth / 2);
painter.drawPixmap(0, 0, *sClosePixmap); painter->drawPixmap(0, 0, *sClosePixmap);
if (mToolWidget->canBeContent()) if (mGraphicsWidgetItem->canBeContent())
painter.drawPixmap(mContentMargin, 0, *sUnpinPixmap); painter->drawPixmap(mContentMargin, 0, *sUnpinPixmap);
} }
} }
void UBToolWidget::mousePressEvent ( QMouseEvent * event ) void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
QWidget::mousePressEvent(event); QGraphicsWidget::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);
@ -179,50 +165,50 @@ void UBToolWidget::mousePressEvent ( QMouseEvent * event )
} }
void UBToolWidget::mouseMoveEvent ( QMouseEvent * event ) void UBToolWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton))
{ {
move(pos() - mMousePressPos + event->pos()); setPos(pos() - mMousePressPos + event->pos());
event->accept(); event->accept();
} }
QWidget::mouseMoveEvent(event); QGraphicsWidget::mouseMoveEvent(event);
} }
void UBToolWidget::mouseReleaseEvent(QMouseEvent * event) void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
mShouldMoveWidget = false; mShouldMoveWidget = false;
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())
{ {
UBApplication::boardController->removeTool(this); scene()->removeItem(this);
event->accept(); event->accept();
} }
else if (mToolWidget->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()
&& event->pos().y() >= 0 && event->pos().y() < sUnpinPixmap->height()) && event->pos().y() >= 0 && event->pos().y() < sUnpinPixmap->height())
{ {
UBApplication::boardController->moveToolWidgetToScene(this); UBApplication::boardController->moveToolWidgetToScene(this);
event->accept(); event->accept();
} }
else else
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool QGraphicsWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
} }
bool UBToolWidget::eventFilter(QObject *obj, QEvent *event) bool UBToolWidget::eventFilter(QObject *obj, QEvent *event)
{ {
if (mShouldMoveWidget && obj == mToolWidget && event->type() == QEvent::MouseMove) if (mShouldMoveWidget && obj == mGraphicsWidgetItem && event->type() == QEvent::MouseMove)
{ {
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event); QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
if (mouseMoveEvent->buttons() & Qt::LeftButton) if (mouseMoveEvent->buttons() & Qt::LeftButton)
{ {
move(pos() - mMousePressPos + mToolWidget->mapTo(this, mouseMoveEvent->pos())); setPos(pos() - mMousePressPos + mGraphicsWidgetItem->mapToItem(this, mouseMoveEvent->pos()));
event->accept(); event->accept();
return true; return true;
@ -234,22 +220,27 @@ bool UBToolWidget::eventFilter(QObject *obj, QEvent *event)
} }
void UBToolWidget::centerOn(const QPoint& pos) void UBToolWidget::centerOn(const QPointF& pos)
{ {
QWidget::move(pos - QPoint(width() / 2, height() / 2)); QGraphicsWidget::setPos(pos - QPointF(preferredWidth() / 2, preferredHeight() / 2));
} }
QPoint UBToolWidget::naturalCenter() const QPointF UBToolWidget::naturalCenter() const
{ {
if (mToolWidget) if (mGraphicsWidgetItem)
return mToolWidget->geometry().center(); return mGraphicsWidgetItem->geometry().center();
else else
return QPoint(0, 0); return QPointF(0, 0);
} }
UBAbstractWidget* UBToolWidget::webWidget() const UBGraphicsWidgetItem* UBToolWidget::graphicsWidgetItem() const
{
return mGraphicsWidgetItem;
}
UBGraphicsScene* UBToolWidget::scene()
{ {
return mToolWidget; return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene());
} }

@ -18,32 +18,33 @@
#include <QtGui> #include <QtGui>
class UBAbstractWidget; class UBGraphicsWidgetItem;
class QWidget; class QWidget;
class UBGraphicsScene; class UBGraphicsScene;
class UBToolWidget : public QWidget class UBToolWidget : public QGraphicsWidget
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBToolWidget(const QUrl& pUrl, QWidget* pParent = 0); UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent = 0);
UBToolWidget(UBAbstractWidget* pWidget, QWidget* pParent = 0); UBToolWidget(UBGraphicsWidgetItem* pGraphicsWidgetItem, QGraphicsItem *pParent = 0);
virtual ~UBToolWidget(); virtual ~UBToolWidget();
void centerOn(const QPoint& pos); void centerOn(const QPointF& pos);
QPoint naturalCenter() const; QPointF naturalCenter() const;
UBAbstractWidget* webWidget() const; UBGraphicsWidgetItem* graphicsWidgetItem() const;
virtual UBGraphicsScene* scene();
protected: protected:
void initialize(); void initialize();
virtual void paintEvent(QPaintEvent *); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual void mousePressEvent ( QMouseEvent * event ); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent ( QMouseEvent * event ); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent ( QMouseEvent * event ); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event); virtual bool eventFilter(QObject *obj, QEvent *event);
@ -55,9 +56,9 @@ class UBToolWidget : public QWidget
static QPixmap *sClosePixmap; static QPixmap *sClosePixmap;
static QPixmap *sUnpinPixmap; static QPixmap *sUnpinPixmap;
UBAbstractWidget *mToolWidget; UBGraphicsWidgetItem *mGraphicsWidgetItem;
QPoint mMousePressPos; QPointF mMousePressPos;
bool mShouldMoveWidget; bool mShouldMoveWidget;

Loading…
Cancel
Save