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;
}
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()
{
UBApplication::mainWindow->actionLibrary->setChecked(false);
controlViewHidden();
}
void UBBoardController::show()
{
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)
{
QUuid uuid = QUuid::createUuid();
@ -2098,56 +2042,39 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{
/*QPoint controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center());
graphicsWidget->setSelected(false);
UBAbstractWidget *aw = graphicsWidget->widgetWebView();
graphicsWidget->setWidget(0);
graphicsWidget->remove();
UBToolWidget *toolWidget = new UBToolWidget(aw, mControlContainer);
graphicsWidget->scene()->removeItem(graphicsWidget); // TODO UB 4.6 probably leaking the frame
toolWidget->centerOn(mControlView->mapTo(mControlContainer, controlViewPos));
toolWidget->show();*/
UBToolWidget *toolWidget = new UBToolWidget(graphicsWidget);
mActiveScene->addItem(toolWidget);
}
void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
{
/*int xIsOdd = toolWidget->width() % 2;
int yIsOdd = toolWidget->height() % 2;
QPoint mainWindowCenter = toolWidget->mapTo(mMainWindow, QPoint(toolWidget->width(), toolWidget->height()) / 2);
UBAbstractWidget* webWidget = toolWidget->webWidget();
webWidget->setParent(0);
QPoint mainWindowCenter = (QPointF(toolWidget->preferredWidth(), toolWidget->preferredHeight()) / 2).toPoint();
UBGraphicsWidgetItem* graphicsWidget = 0;
UBGraphicsWidgetItem *graphicsWidgetItem = toolWidget->graphicsWidgetItem();
graphicsWidgetItem->setParent(0);
UBW3CWidget* w3cWidget = qobject_cast<UBW3CWidget*>(webWidget);
if (w3cWidget)
if (qobject_cast<UBGraphicsW3CWidgetItem*>(graphicsWidgetItem))
{
graphicsWidget = new UBGraphicsW3CWidgetItem(w3cWidget);
graphicsWidgetItem = qobject_cast<UBGraphicsW3CWidgetItem*>(graphicsWidgetItem);
}
else
{
UBAppleWidget* appleWidget = qobject_cast<UBAppleWidget*>(webWidget);
if (appleWidget)
if (qobject_cast<UBGraphicsAppleWidgetItem*>(graphicsWidgetItem))
{
graphicsWidget = new UBGraphicsAppleWidgetItem(appleWidget);
graphicsWidgetItem = qobject_cast<UBGraphicsAppleWidgetItem*>(graphicsWidgetItem);
}
}
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->deleteLater();*/
toolWidget->deleteLater();
}

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

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

@ -35,6 +35,7 @@ class UBGraphicsAudioItem;
class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem;
class UBGraphicsAppleWidgetItem;
class UBToolWidget;
class UBGraphicsPDFItem;
class UBGraphicsTextItem;
class UBGraphicsRuler;
@ -133,6 +134,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, 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* 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));

@ -23,9 +23,6 @@
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBAppleWidget.h"
#include "domain/UBW3CWidget.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsWidgetItem.h"
@ -41,38 +38,31 @@ QPixmap* UBToolWidget::sClosePixmap = 0;
QPixmap* UBToolWidget::sUnpinPixmap = 0;
UBToolWidget::UBToolWidget(const QUrl& pUrl, QWidget* pParent)
: QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mToolWidget(0)
UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent)
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mGraphicsWidgetItem(0)
, mShouldMoveWidget(false)
{
int widgetType = UBAbstractWidget::widgetType(pUrl);
int widgetType = UBGraphicsWidgetItem::widgetType(pUrl);
if(widgetType == UBWidgetType::Apple)
{
mToolWidget = new UBAppleWidget(pUrl, this);
}
else if(widgetType == UBWidgetType::W3C)
{
mToolWidget = new UBW3CWidget(pUrl, this);
}
if (widgetType == UBWidgetType::Apple)
mGraphicsWidgetItem = new UBGraphicsAppleWidgetItem(pUrl, this);
else if (widgetType == UBWidgetType::W3C)
mGraphicsWidgetItem = new UBGraphicsW3CWidgetItem(pUrl, this);
else
{
qDebug() << "UBToolWidget::UBToolWidget: Unknown widget Type";
return;
}
initialize();
}
UBToolWidget::UBToolWidget(UBAbstractWidget* pWidget, QWidget* pParent)
: QWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mToolWidget(pWidget)
UBToolWidget::UBToolWidget(UBGraphicsWidgetItem *pWidget, QGraphicsItem *pParent)
: QGraphicsWidget(pParent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, mShouldMoveWidget(false)
{
mToolWidget->setParent(this);
mToolWidget->loadMainHtml();
mGraphicsWidgetItem = pWidget;
mGraphicsWidgetItem->setParent(this);
mGraphicsWidgetItem->loadMainHtml();
initialize();
@ -88,85 +78,81 @@ UBToolWidget::~UBToolWidget()
void UBToolWidget::initialize()
{
mToolWidget->setAcceptDrops(false);
if(!sClosePixmap)
{
if (!sClosePixmap)
sClosePixmap = new QPixmap(":/images/close.svg");
}
if(!sUnpinPixmap)
{
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();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mToolWidget->page()->setPalette(palette);
mGraphicsWidgetItem->setAcceptDrops(false);
connect(mToolWidget->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared()));
mGraphicsWidgetItem->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
setLayout(new QVBoxLayout());
mGraphicsWidgetItem->setAttribute(Qt::WA_OpaquePaintEvent, false);
mFrameWidth = UBSettings::settings()->objectFrameWidth;
mContentMargin = sClosePixmap->width() / 2 + mFrameWidth;
QPalette palette = mGraphicsWidgetItem->page()->palette();
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);
layout()->addWidget(mToolWidget);
QGraphicsWebView *addedGraphicsWebView = new QGraphicsWebView();
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()
{
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);
if (w3c)
UBGraphicsW3CWidgetItem *graphicsW3cWidgetItem = dynamic_cast<UBGraphicsW3CWidgetItem*>(mGraphicsWidgetItem);
if (graphicsW3cWidgetItem)
{
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(w3c);
mToolWidget->page()->mainFrame()->addToJavaScriptWindowObject("widget", widgetAPI);
}*/
UBW3CWidgetAPI* widgetAPI = new UBW3CWidgetAPI(graphicsW3cWidgetItem);
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())
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(127, 127, 127, 127));
painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(127, 127, 127, 127));
painter.drawRoundedRect(QRectF(sClosePixmap->width() / 2
, sClosePixmap->height() / 2
, width() - sClosePixmap->width()
, mFrameWidth), mFrameWidth / 2, mFrameWidth / 2);
painter->drawRoundedRect(QRectF(sClosePixmap->width() / 2, sClosePixmap->height() / 2, preferredWidth() - sClosePixmap->width(), mFrameWidth), mFrameWidth / 2, mFrameWidth / 2);
painter.drawPixmap(0, 0, *sClosePixmap);
painter->drawPixmap(0, 0, *sClosePixmap);
if (mToolWidget->canBeContent())
painter.drawPixmap(mContentMargin, 0, *sUnpinPixmap);
if (mGraphicsWidgetItem->canBeContent())
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 ?
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))
{
move(pos() - mMousePressPos + event->pos());
setPos(pos() - mMousePressPos + event->pos());
event->accept();
}
QWidget::mouseMoveEvent(event);
QGraphicsWidget::mouseMoveEvent(event);
}
void UBToolWidget::mouseReleaseEvent(QMouseEvent * event)
void UBToolWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mShouldMoveWidget = false;
if (event->pos().x() >= 0 && event->pos().x() < sClosePixmap->width()
&& event->pos().y() >= 0 && event->pos().y() < sClosePixmap->height())
{
UBApplication::boardController->removeTool(this);
scene()->removeItem(this);
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())
{
UBApplication::boardController->moveToolWidgetToScene(this);
event->accept();
}
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)
{
if (mShouldMoveWidget && obj == mToolWidget && event->type() == QEvent::MouseMove)
if (mShouldMoveWidget && obj == mGraphicsWidgetItem && event->type() == QEvent::MouseMove)
{
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
if (mouseMoveEvent->buttons() & Qt::LeftButton)
{
move(pos() - mMousePressPos + mToolWidget->mapTo(this, mouseMoveEvent->pos()));
setPos(pos() - mMousePressPos + mGraphicsWidgetItem->mapToItem(this, mouseMoveEvent->pos()));
event->accept();
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)
return mToolWidget->geometry().center();
if (mGraphicsWidgetItem)
return mGraphicsWidgetItem->geometry().center();
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>
class UBAbstractWidget;
class UBGraphicsWidgetItem;
class QWidget;
class UBGraphicsScene;
class UBToolWidget : public QWidget
class UBToolWidget : public QGraphicsWidget
{
Q_OBJECT;
Q_OBJECT
public:
UBToolWidget(const QUrl& pUrl, QWidget* pParent = 0);
UBToolWidget(UBAbstractWidget* pWidget, QWidget* pParent = 0);
UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent = 0);
UBToolWidget(UBGraphicsWidgetItem* pGraphicsWidgetItem, QGraphicsItem *pParent = 0);
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:
void initialize();
virtual void paintEvent(QPaintEvent *);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);
@ -55,9 +56,9 @@ class UBToolWidget : public QWidget
static QPixmap *sClosePixmap;
static QPixmap *sUnpinPixmap;
UBAbstractWidget *mToolWidget;
UBGraphicsWidgetItem *mGraphicsWidgetItem;
QPoint mMousePressPos;
QPointF mMousePressPos;
bool mShouldMoveWidget;

Loading…
Cancel
Save