|
|
@ -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,92 @@ 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() |
|
|
|
void UBToolWidget::remove() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mGraphicsWebView->setHtml(QString()); |
|
|
|
mToolWidget = NULL; |
|
|
|
scene()->removeItem(this); |
|
|
|
hide(); |
|
|
|
} |
|
|
|
deleteLater(); |
|
|
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|