|
|
@ -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()); |
|
|
|
} |
|
|
|
} |
|
|
|