|
|
@ -14,38 +14,33 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <QtGui> |
|
|
|
#include <QtGui> |
|
|
|
|
|
|
|
|
|
|
|
#include "UBToolWidget.h" |
|
|
|
#include "UBToolWidget.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "frameworks/UBPlatformUtils.h" |
|
|
|
|
|
|
|
#include "frameworks/UBFileSystemUtils.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "core/UBApplication.h" |
|
|
|
|
|
|
|
#include "core/UBSettings.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
|
|
|
|
#include "domain/UBGraphicsWidgetItem.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "api/UBWidgetUniboardAPI.h" |
|
|
|
#include "api/UBWidgetUniboardAPI.h" |
|
|
|
#include "api/UBW3CWidgetAPI.h" |
|
|
|
#include "api/UBW3CWidgetAPI.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBBoardController.h" |
|
|
|
#include "board/UBBoardView.h" |
|
|
|
#include "board/UBBoardView.h" |
|
|
|
|
|
|
|
#include "core/UBApplication.h" |
|
|
|
|
|
|
|
#include "core/UBSettings.h" |
|
|
|
|
|
|
|
#include "domain/UBGraphicsScene.h" |
|
|
|
|
|
|
|
#include "domain/UBGraphicsWidgetItem.h" |
|
|
|
|
|
|
|
#include "frameworks/UBPlatformUtils.h" |
|
|
|
|
|
|
|
#include "frameworks/UBFileSystemUtils.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap* UBToolWidget::sClosePixmap = 0; |
|
|
|
QPixmap* UBToolWidget::sClosePixmap = 0; |
|
|
|
QPixmap* UBToolWidget::sUnpinPixmap = 0; |
|
|
|
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) |
|
|
|
|
|
|
|
, mGraphicsWebView(0) |
|
|
|
|
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
|
|
|
|
, mContentMargin(0) |
|
|
|
|
|
|
|
, mFrameWidth(0) |
|
|
|
|
|
|
|
, mGraphicsWebView(0) |
|
|
|
|
|
|
|
, mGraphicsWidgetItem(0)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
int widgetType = UBGraphicsWidgetItem::widgetType(pUrl); |
|
|
|
int widgetType = UBGraphicsWidgetItem::widgetType(pUrl); |
|
|
|
|
|
|
|
|
|
|
|
if (widgetType == UBWidgetType::Apple) |
|
|
|
if (widgetType == UBWidgetType::Apple) |
|
|
|
mGraphicsWidgetItem = new UBGraphicsAppleWidgetItem(pUrl, this); |
|
|
|
mGraphicsWidgetItem = new UBGraphicsAppleWidgetItem(pUrl, this); |
|
|
|
else if (widgetType == UBWidgetType::W3C) |
|
|
|
else if (widgetType == UBWidgetType::W3C) |
|
|
@ -56,25 +51,23 @@ UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent) |
|
|
|
initialize(); |
|
|
|
initialize(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent) |
|
|
|
UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent) |
|
|
|
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) |
|
|
|
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
, mShouldMoveWidget(false) |
|
|
|
|
|
|
|
, mContentMargin(0) |
|
|
|
|
|
|
|
, mFrameWidth(0) |
|
|
|
|
|
|
|
, mGraphicsWebView(0) |
|
|
|
|
|
|
|
, mGraphicsWidgetItem(pWidget) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mGraphicsWidgetItem = pWidget; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialize(); |
|
|
|
initialize(); |
|
|
|
|
|
|
|
|
|
|
|
javaScriptWindowObjectCleared(); |
|
|
|
javaScriptWindowObjectCleared(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBToolWidget::~UBToolWidget() |
|
|
|
UBToolWidget::~UBToolWidget() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// NOOP
|
|
|
|
// NOOP
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::initialize() |
|
|
|
void UBToolWidget::initialize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!sClosePixmap) |
|
|
|
if (!sClosePixmap) |
|
|
@ -108,131 +101,85 @@ void UBToolWidget::initialize() |
|
|
|
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared())); |
|
|
|
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UBToolWidget::event(QEvent *event) |
|
|
|
void UBToolWidget::javaScriptWindowObjectCleared() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene(), mGraphicsWidgetItem); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem); |
|
|
|
|
|
|
|
if (graphicsW3cWidgetItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem); |
|
|
|
|
|
|
|
mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPointF UBToolWidget::pos() const |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return QPointF(QGraphicsItem::pos().x() + mContentMargin * scale(), QGraphicsItem::pos().y() + mContentMargin * scale()); |
|
|
|
if (event->type() == QEvent::ShortcutOverride) |
|
|
|
} |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
return QGraphicsWidget::event(event); |
|
|
|
void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QGraphicsWidget::paint(painter, option, widget); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isActiveWindow()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mGraphicsWidgetItem->canBeContent()) |
|
|
|
|
|
|
|
painter->drawPixmap(mContentMargin, 0, *sUnpinPixmap); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
void UBToolWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QGraphicsWidget::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); |
|
|
|
|
|
|
|
|
|
|
|
mMousePressPos = event->pos(); |
|
|
|
mMousePressPos = event->pos(); |
|
|
|
|
|
|
|
|
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
void UBToolWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) |
|
|
|
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton)) { |
|
|
|
{ |
|
|
|
|
|
|
|
setPos(pos() - mMousePressPos + event->pos()); |
|
|
|
setPos(pos() - mMousePressPos + event->pos()); |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QGraphicsWidget::mouseMoveEvent(event); |
|
|
|
QGraphicsWidget::mouseMoveEvent(event); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *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()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
remove(); |
|
|
|
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() && 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 |
|
|
|
QGraphicsWidget::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 */ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
|
|
bool UBToolWidget::eventFilter(QObject *obj, QEvent *event) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (mShouldMoveWidget && obj == mGraphicsWidgetItem && event->type() == QEvent::MouseMove) |
|
|
|
QGraphicsWidget::paint(painter, option, widget); |
|
|
|
{ |
|
|
|
|
|
|
|
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mouseMoveEvent->buttons() & Qt::LeftButton) |
|
|
|
/* painting lightweight toolbar */ |
|
|
|
{ |
|
|
|
if (isActiveWindow()) { |
|
|
|
setPos(pos() - mMousePressPos + mGraphicsWidgetItem->mapToItem(this, mouseMoveEvent->pos())); |
|
|
|
painter->setRenderHint(QPainter::Antialiasing); |
|
|
|
|
|
|
|
painter->setPen(Qt::NoPen); |
|
|
|
|
|
|
|
painter->setBrush(QColor(127, 127, 127, 127)); |
|
|
|
|
|
|
|
|
|
|
|
event->accept(); |
|
|
|
painter->drawRoundedRect(QRectF(sClosePixmap->width() / 2, sClosePixmap->height() / 2, preferredWidth() - sClosePixmap->width(), mFrameWidth), mFrameWidth / 2, mFrameWidth / 2); |
|
|
|
return true; |
|
|
|
painter->drawPixmap(0, 0, *sClosePixmap); |
|
|
|
} |
|
|
|
if (mGraphicsWidgetItem->canBeContent()) |
|
|
|
|
|
|
|
painter->drawPixmap(mContentMargin, 0, *sUnpinPixmap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// standard event processing
|
|
|
|
|
|
|
|
return QObject::eventFilter(obj, event); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::javaScriptWindowObjectCleared() |
|
|
|
void UBToolWidget::centerOn(const QPointF& pos) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
QGraphicsWidget::setPos(pos - QPointF(preferredWidth() / 2, preferredHeight() / 2)); |
|
|
|
UBWidgetUniboardAPI *uniboardAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene(), mGraphicsWidgetItem); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", uniboardAPI); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem); |
|
|
|
|
|
|
|
if (graphicsW3cWidgetItem) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem); |
|
|
|
|
|
|
|
mGraphicsWebView->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsWidgetItem* UBToolWidget::graphicsWidgetItem() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return mGraphicsWidgetItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QPointF UBToolWidget::naturalCenter() const |
|
|
|
QPointF UBToolWidget::naturalCenter() const |
|
|
|
{ |
|
|
|
{ |
|
|
@ -242,10 +189,15 @@ QPointF UBToolWidget::naturalCenter() const |
|
|
|
return QPointF(0, 0); |
|
|
|
return QPointF(0, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::centerOn(const QPointF& pos) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QGraphicsWidget::setPos(pos - QPointF(preferredWidth() / 2, preferredHeight() / 2)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsWidgetItem* UBToolWidget::graphicsWidgetItem() const |
|
|
|
void UBToolWidget::remove() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return mGraphicsWidgetItem; |
|
|
|
mGraphicsWebView->setHtml(QString()); |
|
|
|
|
|
|
|
scene()->removeItem(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsScene* UBToolWidget::scene() |
|
|
|
UBGraphicsScene* UBToolWidget::scene() |
|
|
@ -253,8 +205,22 @@ UBGraphicsScene* UBToolWidget::scene() |
|
|
|
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene()); |
|
|
|
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBToolWidget::remove() |
|
|
|
QPointF UBToolWidget::pos() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
mGraphicsWebView->setHtml(QString()); |
|
|
|
return QPointF(QGraphicsItem::pos().x() + mContentMargin * scale(), QGraphicsItem::pos().y() + mContentMargin * scale()); |
|
|
|
scene()->removeItem(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Type; |
|
|
|
} |
|
|
|
} |
|
|
|