Commit 37149617 authored by Yimgo's avatar Yimgo

First modifications to move from QWebView to QGraphicsWebView.

This is not functional.
parent 46809871
......@@ -2484,7 +2484,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsW3CWidgetToSvg(UBGraphicsW3C
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsWidgetToSvg(UBGraphicsWidgetItem* item)
{
QUrl widgetRootUrl = item->widgetWebView()->widgetUrl();
QUrl widgetRootUrl = item->widgetUrl();
QString uuid = UBStringUtils::toCanonicalUuid(item->uuid());
QString widgetDirectoryPath = UBPersistenceManager::widgetDirectory;
if (widgetRootUrl.toString().startsWith("file://"))
......@@ -2513,13 +2513,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsWidgetToSvg(UBGraphicsWidget
graphicsItemToSvg(item);
if (item->widgetWebView()->isFrozen())
if (item->isFrozen())
{
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "frozen", xmlTrue);
}
QString snapshotPath = mDocumentPath + "/" + UBPersistenceManager::widgetDirectory + "/" + uuid + ".png";
item->widgetWebView()->takeSnapshot().save(snapshotPath, "PNG");
item->takeSnapshot().save(snapshotPath, "PNG");
mXmlWriter.writeStartElement(nsXHtml, "iframe");
......@@ -2528,10 +2528,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsWidgetToSvg(UBGraphicsWidget
mXmlWriter.writeAttribute("height", QString("%1").arg(item->boundingRect().height()));
QString startFileUrl;
if (item->widgetWebView()->mainHtmlFileName().startsWith("http://"))
startFileUrl = item->widgetWebView()->mainHtmlFileName();
if (item->mainHtmlFileName().startsWith("http://"))
startFileUrl = item->mainHtmlFileName();
else
startFileUrl = widgetRootUrl.toString() + "/" + item->widgetWebView()->mainHtmlFileName();
startFileUrl = widgetRootUrl.toString() + "/" + item->mainHtmlFileName();
mXmlWriter.writeAttribute("src", startFileUrl);
mXmlWriter.writeEndElement(); //iFrame
......@@ -2622,13 +2622,13 @@ UBGraphicsW3CWidgetItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsW3CWidge
QPixmap snapshot(pixPath);
if (!snapshot.isNull())
widgetItem->w3cWidget()->setSnapshot(snapshot);
widgetItem->setSnapshot(snapshot);
QStringRef frozen = mXmlReader.attributes().value(mNamespaceUri, "frozen");
if (!frozen.isNull() && frozen.toString() == xmlTrue && !snapshot.isNull())
{
widgetItem->w3cWidget()->freeze();
widgetItem->freeze();
}
graphicsItemFromSvg(widgetItem);
......
......@@ -281,12 +281,12 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
jsonFile.write(QString(" \"uuid\": \"%1\",\n").arg(UBStringUtils::toCanonicalUuid(widget->uuid())).toUtf8());
jsonFile.write(QString(" \"id\": \"%1\",\n").arg(widget->metadatas().id).toUtf8());
jsonFile.write(QString(" \"name\": \"%1\",\n").arg(widget->w3cWidget()->metadatas().name).toUtf8());
jsonFile.write(QString(" \"description\": \"%1\",\n").arg(widget->w3cWidget()->metadatas().description).toUtf8());
jsonFile.write(QString(" \"author\": \"%1\",\n").arg(widget->w3cWidget()->metadatas().author).toUtf8());
jsonFile.write(QString(" \"authorEmail\": \"%1\",\n").arg(widget->w3cWidget()->metadatas().authorEmail).toUtf8());
jsonFile.write(QString(" \"authorHref\": \"%1\",\n").arg(widget->w3cWidget()->metadatas().authorHref).toUtf8());
jsonFile.write(QString(" \"version\": \"%1\",\n").arg(widget->w3cWidget()->metadatas().authorHref).toUtf8());
jsonFile.write(QString(" \"name\": \"%1\",\n").arg(widget->metadatas().name).toUtf8());
jsonFile.write(QString(" \"description\": \"%1\",\n").arg(widget->metadatas().description).toUtf8());
jsonFile.write(QString(" \"author\": \"%1\",\n").arg(widget->metadatas().author).toUtf8());
jsonFile.write(QString(" \"authorEmail\": \"%1\",\n").arg(widget->metadatas().authorEmail).toUtf8());
jsonFile.write(QString(" \"authorHref\": \"%1\",\n").arg(widget->metadatas().authorHref).toUtf8());
jsonFile.write(QString(" \"version\": \"%1\",\n").arg(widget->metadatas().authorHref).toUtf8());
jsonFile.write(QString(" \"x\": %1,\n").arg(widget->sceneBoundingRect().x()).toUtf8());
jsonFile.write(QString(" \"y\": %1,\n").arg(widget->sceneBoundingRect().y()).toUtf8());
......@@ -298,7 +298,7 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
QString url = UBPersistenceManager::widgetDirectory + "/" + widget->uuid().toString() + ".wgt";
jsonFile.write(QString(" \"src\": \"%1\",\n").arg(url).toUtf8());
QString startFile = widget->w3cWidget()->mainHtmlFileName();
QString startFile = widget->mainHtmlFileName();
jsonFile.write(QString(" \"startFile\": \"%1\",\n").arg(startFile).toUtf8());
QMap<QString, QString> preferences = widget->preferences();
......@@ -363,7 +363,7 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
QMap<QString, QString> preferences = widgetItem->preferences();
QMap<QString, QString> datastoreEntries = widgetItem->datastoreEntries();
QString startFileName = widgetItem->w3cWidget()->mainHtmlFileName();
QString startFileName = widgetItem->mainHtmlFileName();
if (!startFileName.startsWith("http://"))
{
......@@ -394,18 +394,18 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
lines << " <script type=\"text/javascript\">";
lines << " var widget = {};";
lines << " widget.id = '" + widgetItem->w3cWidget()->metadatas().id + "';";
lines << " widget.name = '" + widgetItem->w3cWidget()->metadatas().name + "';";
lines << " widget.description = '" + widgetItem->w3cWidget()->metadatas().description + "';";
lines << " widget.author = '" + widgetItem->w3cWidget()->metadatas().author + "';";
lines << " widget.authorEmail = '" + widgetItem->w3cWidget()->metadatas().authorEmail + "';";
lines << " widget.authorHref = '" + widgetItem->w3cWidget()->metadatas().authorHref + "';";
lines << " widget.version = '" + widgetItem->w3cWidget()->metadatas().version + "';";
lines << " widget.id = '" + widgetItem->metadatas().id + "';";
lines << " widget.name = '" + widgetItem->metadatas().name + "';";
lines << " widget.description = '" + widgetItem->metadatas().description + "';";
lines << " widget.author = '" + widgetItem->metadatas().author + "';";
lines << " widget.authorEmail = '" + widgetItem->metadatas().authorEmail + "';";
lines << " widget.authorHref = '" + widgetItem->metadatas().authorHref + "';";
lines << " widget.version = '" + widgetItem->metadatas().version + "';";
lines << " widget.uuid = '" + UBStringUtils::toCanonicalUuid(widgetItem->uuid()) + "';";
lines << " widget.width = " + QString("%1").arg(widgetItem->w3cWidget()->width()) + ";";
lines << " widget.height = " + QString("%1").arg(widgetItem->w3cWidget()->height()) + ";";
lines << " widget.width = " + QString("%1").arg(widgetItem->nominalSize().width()) + ";";
lines << " widget.height = " + QString("%1").arg(widgetItem->nominalSize().height()) + ";";
lines << " widget.openUrl = function(url) { window.open(url); }";
lines << " widget.preferences = new Array()";
......
......@@ -30,25 +30,14 @@
#include "core/memcheck.h"
UBW3CWidgetAPI::UBW3CWidgetAPI(UBGraphicsW3CWidgetItem *graphicsWidget)
: QObject(graphicsWidget)
UBW3CWidgetAPI::UBW3CWidgetAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QObject *parent)
: QObject(parent)
, mGraphicsW3CWidget(graphicsWidget)
, mW3CWidget(mGraphicsW3CWidget->w3cWidget())
{
mPreferencesAPI = new UBW3CWidgetPreferenceAPI(graphicsWidget);
mPreferencesAPI = new UBW3CWidgetPreferenceAPI(graphicsWidget, parent);
}
UBW3CWidgetAPI::UBW3CWidgetAPI(UBW3CWidget *widget)
: QObject(widget)
, mGraphicsW3CWidget(0)
, mW3CWidget(widget)
{
mPreferencesAPI = new UBW3CWidgetPreferenceAPI(widget);
}
UBW3CWidgetAPI::~UBW3CWidgetAPI()
{
// NOOP
......@@ -66,55 +55,55 @@ QString UBW3CWidgetAPI::uuid()
int UBW3CWidgetAPI::width()
{
return mW3CWidget->geometry().width();
return mGraphicsW3CWidget->nominalSize().width();
}
int UBW3CWidgetAPI::height()
{
return mW3CWidget->geometry().height();
return mGraphicsW3CWidget->nominalSize().height();
}
QString UBW3CWidgetAPI::id()
{
return mW3CWidget->metadatas().id;
return mGraphicsW3CWidget->metadatas().id;
}
QString UBW3CWidgetAPI::name()
{
return mW3CWidget->metadatas().name;
return mGraphicsW3CWidget->metadatas().name;
}
QString UBW3CWidgetAPI::description()
{
return mW3CWidget->metadatas().description;
return mGraphicsW3CWidget->metadatas().description;
}
QString UBW3CWidgetAPI::author()
{
return mW3CWidget->metadatas().author;
return mGraphicsW3CWidget->metadatas().author;
}
QString UBW3CWidgetAPI::authorEmail()
{
return mW3CWidget->metadatas().authorEmail;
return mGraphicsW3CWidget->metadatas().authorEmail;
}
QString UBW3CWidgetAPI::authorHref()
{
return mW3CWidget->metadatas().authorHref;
return mGraphicsW3CWidget->metadatas().authorHref;
}
QString UBW3CWidgetAPI::version()
{
return mW3CWidget->metadatas().version;
return mGraphicsW3CWidget->metadatas().version;
}
QObject* UBW3CWidgetAPI::preferences()
......@@ -129,24 +118,13 @@ void UBW3CWidgetAPI::openURL(const QString& url)
}
UBW3CWidgetPreferenceAPI::UBW3CWidgetPreferenceAPI(UBGraphicsW3CWidgetItem *graphicsWidget)
: UBW3CWebStorage(graphicsWidget)
UBW3CWidgetPreferenceAPI::UBW3CWidgetPreferenceAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QOBject *parent)
: UBW3CWebStorage(parent)
, mGraphicsW3CWidget(graphicsWidget)
, mW3CWidget(graphicsWidget->w3cWidget())
{
// NOOP
}
UBW3CWidgetPreferenceAPI::UBW3CWidgetPreferenceAPI(UBW3CWidget *widget)
: UBW3CWebStorage(widget)
, mGraphicsW3CWidget(0)
, mW3CWidget(widget)
{
// NOOP
}
UBW3CWidgetPreferenceAPI::~UBW3CWidgetPreferenceAPI()
{
// NOOP
......@@ -155,45 +133,30 @@ UBW3CWidgetPreferenceAPI::~UBW3CWidgetPreferenceAPI()
QString UBW3CWidgetPreferenceAPI::key(int index)
{
QMap<QString, UBW3CWidget::PreferenceValue> w3CPrefs = mW3CWidget->preferences();
if (index < w3CPrefs.size())
return w3CPrefs.keys().at(index);
else
return "";
QMap<QString, UBGraphicsWidgetItem::PreferenceValue> w3CPrefs = mGraphicsW3CWidget->preferences();
if (index < w3CPrefs.size())
return w3CPrefs.keys().at(index);
else
return "";
}
QString UBW3CWidgetPreferenceAPI::getItem(const QString& key)
{
if (mGraphicsW3CWidget)
{
QMap<QString, QString> docPref = mGraphicsW3CWidget->preferences();
if (docPref.contains(key))
return docPref.value(key);
}
QMap<QString, UBW3CWidget::PreferenceValue> w3cPrefs = mW3CWidget->preferences();
if (w3cPrefs.contains(key))
{
UBW3CWidget::PreferenceValue pref = w3cPrefs.value(key);
return pref.value;
}
else
{
return "";
}
if (mGraphicsW3CWidget) {
QMap<QString, UBGraphicsWidgetItem::PreferenceValue> w3cPref = mGraphicsW3CWidget->preferences();
if (w3cPref.contains(key))
return w3cPref.value(key).value;
}
return "";
}
int UBW3CWidgetPreferenceAPI::length()
{
QMap<QString, UBW3CWidget::PreferenceValue> w3cPrefs = mW3CWidget->preferences();
QMap<QString, UBGraphicsWidgetItem::PreferenceValue> w3cPrefs = mGraphicsW3CWidget-->preferences();
return w3cPrefs.size();
}
......@@ -201,39 +164,26 @@ int UBW3CWidgetPreferenceAPI::length()
void UBW3CWidgetPreferenceAPI::setItem(const QString& key, const QString& value)
{
if (mGraphicsW3CWidget)
{
QMap<QString, UBW3CWidget::PreferenceValue> w3cPrefs = mW3CWidget->preferences();
if (mGraphicsW3CWidget) {
QMap<QString, UBGraphicsWidgetItem::PreferenceValue> w3cPrefs = mGraphicsW3CWidget->preferences();
if (w3cPrefs.contains(key) && !w3cPrefs.value(key).readonly)
mGraphicsW3CWidget->setPreference(key, value);
}
else
{
// No state for non graphics widget (aka tool widget)
}
if (w3cPrefs.contains(key) && !w3cPrefs.value(key).readonly)
mGraphicsW3CWidget->setPreference(key, value);
}
}
void UBW3CWidgetPreferenceAPI::removeItem(const QString& key)
{
if (mGraphicsW3CWidget)
mGraphicsW3CWidget->removePreference(key);
else
{
// No state for non graphics widget (aka tool widget)
}
if (mGraphicsW3CWidget)
mGraphicsW3CWidget->removePreference(key);
}
void UBW3CWidgetPreferenceAPI::clear()
{
if (mGraphicsW3CWidget)
mGraphicsW3CWidget->removeAllPreferences();
else
{
// No state for non graphics widget (aka tool widget)
}
if (mGraphicsW3CWidget)
mGraphicsW3CWidget->removeAllPreferences();
}
......
......@@ -47,8 +47,7 @@ class UBW3CWidgetAPI : public QObject
public:
UBW3CWidgetAPI(UBGraphicsW3CWidgetItem *graphicsWidget);
UBW3CWidgetAPI(UBW3CWidget *widget);
UBW3CWidgetAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QObject *parent = 0);
virtual ~UBW3CWidgetAPI();
......@@ -72,7 +71,6 @@ class UBW3CWidgetAPI : public QObject
private:
UBGraphicsW3CWidgetItem* mGraphicsW3CWidget;
UBW3CWidget *mW3CWidget;
UBW3CWidgetPreferenceAPI* mPreferencesAPI;
......@@ -88,8 +86,8 @@ class UBW3CWebStorage : public QObject
public:
UBW3CWebStorage(QObject *parent = 0)
: QObject(parent){}
virtual ~UBW3CWebStorage(){}
: QObject(parent){/* NOOP */}
virtual ~UBW3CWebStorage(){/* NOOP */}
public slots:
......@@ -110,8 +108,7 @@ class UBW3CWidgetPreferenceAPI : public UBW3CWebStorage
Q_OBJECT;
public:
UBW3CWidgetPreferenceAPI(UBGraphicsW3CWidgetItem *graphicsWidget);
UBW3CWidgetPreferenceAPI(UBW3CWidget *widget);
UBW3CWidgetPreferenceAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QOBject *parent = 0);
virtual ~UBW3CWidgetPreferenceAPI();
......@@ -129,7 +126,6 @@ class UBW3CWidgetPreferenceAPI : public UBW3CWebStorage
private:
UBGraphicsW3CWidgetItem* mGraphicsW3CWidget;
UBW3CWidget* mW3CWidget;
};
......
......@@ -17,16 +17,15 @@
#include "core/UBApplication.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsWidget.h"
#include "core/memcheck.h"
UBWidgetMessageAPI::UBWidgetMessageAPI(UBW3CWidget *widget)
: QObject(widget)
, mWebWidget(widget)
UBWidgetMessageAPI::UBWidgetMessageAPI(UBGraphicsWidgetItem *graphicsWidgetItem, QObject *parent)
: QObject(parent)
, mGraphicsWidgetItem(graphicsWidgetItem)
{
connect(UBWidgetAPIMessageBroker::instance(), SIGNAL(newMessage(const QString&, const QString&))
, this, SLOT(onNewMessage(const QString&, const QString&)), Qt::QueuedConnection);
connect(UBWidgetAPIMessageBroker::instance(), SIGNAL(newMessage(const QString&, const QString&)), this, SLOT(onNewMessage(const QString&, const QString&)), Qt::QueuedConnection);
}
UBWidgetMessageAPI::~UBWidgetMessageAPI()
......@@ -45,9 +44,7 @@ void UBWidgetMessageAPI::onNewMessage(const QString& pTopicName, const QString&
{
if (mSubscribedTopics.contains(pTopicName))
{
if (mWebWidget
&& mWebWidget->page()
&& mWebWidget->page()->mainFrame())
if (mGraphicsWidgetItem && mGraphicsWidgetItem->page() && mGraphicsWidgetItem->page()->mainFrame())
{
QString js;
......@@ -55,7 +52,7 @@ void UBWidgetMessageAPI::onNewMessage(const QString& pTopicName, const QString&
js += "{widget.messages.onmessage('";
js += pMessage + "', '" + pTopicName + "')}";
mWebWidget->page()->
mGraphicsWidgetItem->page()->
mainFrame()->evaluateJavaScript(js);
}
......
......@@ -25,7 +25,7 @@ class UBWidgetMessageAPI : public QObject
Q_OBJECT;
public:
UBWidgetMessageAPI(UBW3CWidget *widget);
UBWidgetMessageAPI(UBGraphicsWidgetItem *graphicsWidgetItem, QObject *parent = 0);
virtual ~UBWidgetMessageAPI();
public slots:
......@@ -49,7 +49,7 @@ class UBWidgetMessageAPI : public QObject
private:
QSet<QString> mSubscribedTopics;
UBW3CWidget *mWebWidget;
UBGraphicsWidgetItem *mGraphicsWidgetItem;
};
......
......@@ -736,9 +736,9 @@ void UBDocumentDatastoreAPI::removeItem(const QString& key)
{
mGraphicsW3CWidget->removeDatastoreEntry(key);
}
void
void UBDocumentDatastoreAPI::clear()
UBDocumentDatastoreAPI::clear()
{
mGraphicsW3CWidget->removeAllDatastoreEntries();
}
......
......@@ -57,7 +57,7 @@ class UBWidgetUniboardAPI : public QObject
*
* some potential values are
*
* en
* enlocale
* en-UK
* fr
* fr-CH
......
......@@ -1885,7 +1885,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP
w3cWidgetItem->setSnapshotPath(QUrl::fromLocalFile(snapshotPath));
UBGraphicsWidgetItem *tmpItem = dynamic_cast<UBGraphicsWidgetItem*>(w3cWidgetItem);
if (tmpItem)
tmpItem->widgetWebView()->takeSnapshot().save(snapshotPath, "PNG");
tmpItem->takeSnapshot().save(snapshotPath, "PNG");
}
......@@ -2092,7 +2092,7 @@ void UBBoardController::togglePodcast(bool checked)
void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicsWidget)
{
QPoint controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center());
/*QPoint controlViewPos = mControlView->mapFromScene(graphicsWidget->sceneBoundingRect().center());
graphicsWidget->setSelected(false);
......@@ -2105,13 +2105,13 @@ void UBBoardController::moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* gr
toolWidget->centerOn(mControlView->mapTo(mControlContainer, controlViewPos));
toolWidget->show();
toolWidget->show();*/
}
void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
{
int xIsOdd = toolWidget->width() % 2;
/*int xIsOdd = toolWidget->width() % 2;
int yIsOdd = toolWidget->height() % 2;
QPoint mainWindowCenter = toolWidget->mapTo(mMainWindow, QPoint(toolWidget->width(), toolWidget->height()) / 2);
......@@ -2141,7 +2141,7 @@ void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget)
mActiveScene->addGraphicsWidget(graphicsWidget, scenePos);
toolWidget->hide();
toolWidget->deleteLater();
toolWidget->deleteLater();*/
}
......@@ -2227,8 +2227,8 @@ void UBBoardController::freezeW3CWidget(QGraphicsItem *item, bool freeze)
return;
if (freeze) {
item_casted->widgetWebView()->page()->mainFrame()->setContent(UBW3CWidget::freezedWidgetPage().toAscii());
item_casted->page()->mainFrame()->setContent(UBW3CWidget::freezedWidgetPage().toAscii());
} else
item_casted->widgetWebView()->loadMainHtml();
item_casted->loadMainHtml();
}
}
......@@ -1182,7 +1182,7 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event)
}
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint());
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent);
QApplication::sendEvent(graphicsWidget,&newEvent);
} else {
mOkOnWidget = false;
event->ignore();
......
......@@ -1422,9 +1422,9 @@ UBGraphicsAppleWidgetItem* UBGraphicsScene::addAppleWidget(const QUrl& pWidgetUr
return appleWidget;
}
UBGraphicsW3CWidgetItem* UBGraphicsScene::addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos, int widgetType)
UBGraphicsW3CWidgetItem* UBGraphicsScene::addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos)
{
UBGraphicsW3CWidgetItem *w3CWidget = new UBGraphicsW3CWidgetItem(pWidgetUrl, 0, widgetType);
UBGraphicsW3CWidgetItem *w3CWidget = new UBGraphicsW3CWidgetItem(pWidgetUrl, 0);
addGraphicsWidget(w3CWidget, pPos);
......@@ -1444,7 +1444,7 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co
graphicsWidget->setPos(QPointF(pPos.x() - graphicsWidget->boundingRect().width() / 2,
pPos.y() - graphicsWidget->boundingRect().height() / 2));
if (graphicsWidget->widgetWebView()->canBeContent())
if (graphicsWidget->canBeContent())
{
// graphicsWidget->widgetWebView()->loadMainHtml();
......
......@@ -130,7 +130,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsWidgetItem* addWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0));
UBGraphicsAppleWidgetItem* addAppleWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0));
UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0),int widgetType = UBGraphicsItemType::W3CWidgetItemType);
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));
......
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsWebView.h"
#include <QtGui>
#include <QtWebKit>
#include "UBGraphicsScene.h"
#include "UBGraphicsItemDelegate.h"
#include "UBGraphicsDelegateFrame.h"
#include "core/memcheck.h"
UBGraphicsWebView::UBGraphicsWebView(QGraphicsItem* parent) :
QGraphicsWebView(parent)
{
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
mDelegate = new UBGraphicsItemDelegate(this,0, true, false, false);
mDelegate->init();
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
QGraphicsWebView::setAcceptHoverEvents(true);
}
UBGraphicsWebView::~UBGraphicsWebView()
{
if (mDelegate)
delete mDelegate;
}
QVariant UBGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemCursorHasChanged && scene())
{
unsetCursor();
}
if ((change == QGraphicsItem::ItemSelectedHasChanged)
&& scene())
{
if (isSelected())
{
scene()->setActiveWindow(this);
}
else
{
if(scene()->activeWindow() == this)
{
scene()->setActiveWindow(0);
}
}
}
QVariant newValue = mDelegate->itemChange(change, value);
return QGraphicsWebView::itemChange(change, newValue);
}
void UBGraphicsWebView::setUuid(const QUuid &pUuid)
{
UBItem::setUuid(pUuid);
setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
void UBGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mousePressEvent(event))
{
//NOOP
}
else
{
// QT Proxy Widget is a bit lazy, we force the selection ...
setSelected(true);
}
QGraphicsWebView::mousePressEvent(event);
}
void UBGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mouseMoveEvent(event))
{
// NOOP;
}
else
{
QGraphicsWebView::mouseMoveEvent(event);
}
}
void UBGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mDelegate->mouseReleaseEvent(event);
QGraphicsWebView::mouseReleaseEvent(event);
}
void UBGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *event)
{
if( mDelegate->weelEvent(event) )
{
QGraphicsWebView::wheelEvent(event);
event->accept();
}
}
void UBGraphicsWebView::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
// NOOP
}
void UBGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
// NOOP
}
void UBGraphicsWebView::setDelegate(UBGraphicsItemDelegate* pDelegate)
{
if (mDelegate)
{
delete mDelegate;
}
mDelegate = pDelegate;
}
void UBGraphicsWebView::resize(qreal w, qreal h)
{
UBGraphicsWebView::resize(QSizeF(w, h));
}
void UBGraphicsWebView::resize(const QSizeF & pSize)
{
if (pSize != size())
{
QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height());
QGraphicsWebView::resize(pSize.width(), pSize.height());
if (mDelegate)
mDelegate->positionHandles();
if (scene())
scene()->setModified(true);
}
}
QSizeF UBGraphicsWebView::size() const
{
return QGraphicsWebView::size();
}
UBGraphicsScene* UBGraphicsWebView::scene()
{
return static_cast<UBGraphicsScene*>(QGraphicsItem::scene());
}
void UBGraphicsWebView::remove()
{
if (mDelegate)
mDelegate->remove(true);
}
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGRAPHICSWEBVIEW_H_
#define UBGRAPHICSWEBVIEW_H_
#include <QtGui>
#include <QtWebKit>
#include "UBItem.h"
#include "UBResizableGraphicsItem.h"
class UBGraphicsItemDelegate;
class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResizableGraphicsItem, public UBGraphicsItem
{
public:
UBGraphicsWebView(QGraphicsItem* parent = 0);
virtual ~UBGraphicsWebView();
virtual void resize(qreal w, qreal h);
virtual void resize(const QSizeF & size);
virtual QSizeF size() const;
void setDelegate(UBGraphicsItemDelegate* pDelegate);
virtual UBGraphicsScene* scene();
virtual void remove();
virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;}
virtual void clearSource(){;}
virtual void setUuid(const QUuid &pUuid);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};
#endif /* UBGRAPHICSWEBVIEW_H_ */
......@@ -14,6 +14,8 @@
*/
#include "UBGraphicsWidgetItem.h"
#include <QtNetwork>
#include <QtXml>
#include "api/UBWidgetUniboardAPI.h"
#include "api/UBW3CWidgetAPI.h"
......@@ -26,20 +28,68 @@
#include "UBGraphicsScene.h"
#include "UBAppleWidget.h"
#include "frameworks/UBFileSystemUtils.h"
#include "web/UBWebPage.h"
#include "network/UBNetworkAccessManager.h"
#include "core/memcheck.h"
#include "core/UBApplicationController.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "web/UBWebKitUtils.h"
#include "web/UBWebController.h"
#include "frameworks/UBPlatformUtils.h"
#include "board/UBBoardController.h"
const QString freezedWidgetDefaultContentFilePath = "./etc/freezedWidgetWrapper.html";
QStringList UBGraphicsWidgetItem::sInlineJavaScripts;
bool UBGraphicsWidgetItem::sInlineJavaScriptLoaded = false;
bool UBGraphicsW3CWidgetItem::sTemplateLoaded = false;
QMap<QString, QString> UBGraphicsW3CWidgetItem::sNPAPIWrapperTemplates;
QString UBGraphicsW3CWidgetItem::sNPAPIWrappperConfigTemplate;
UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType)
: UBGraphicsProxyWidget(parent)
, mWebKitWidget(0)
: UBGraphicsWebView(parent)
, mShouldMoveWidget(false)
, mUniboardAPI(0)
, mIsResizable(false)
, mInitialLoadDone(false)
, mLoadIsErronous(false)
, mIsFreezable(true)
, mCanBeContent(0)
, mCanBeTool(0)
, mIsFrozen(false)
, mIsTakingSnapshot(false)
{
setAcceptDrops(false);
setAcceptDrops(true);
UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this, widgetType);
delegate->init();
setDelegate(delegate);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
QGraphicsWebView::setPage(new UBWebPage(this));
QGraphicsWebView::settings()->setAttribute(QWebSettings::JavaEnabled, true);
QGraphicsWebView::settings()->setAttribute(QWebSettings::PluginsEnabled, true);
QGraphicsWebView::settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
QGraphicsWebView::settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
QGraphicsWebView::settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
QGraphicsWebView::settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
QGraphicsWebView::settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
page()->setNetworkAccessManager(UBNetworkAccessManager::defaultAccessManager());
setAutoFillBackground(false);
QPalette pagePalette = page()->palette();
pagePalette.setBrush(QPalette::Base, QBrush(Qt::transparent));
pagePalette.setBrush(QPalette::Window, QBrush(Qt::transparent));
page()->setPalette(pagePalette);
QPalette viewPalette = palette();
pagePalette.setBrush(QPalette::Base, QBrush(Qt::transparent));
viewPalette.setBrush(QPalette::Window, QBrush(Qt::transparent));
setPalette(viewPalette);
}
......@@ -48,13 +98,299 @@ UBGraphicsWidgetItem::~UBGraphicsWidgetItem()
// NOOP
}
bool UBGraphicsWidgetItem::canBeContent()
{
// if we under MAC OS
#if defined(Q_OS_MAC)
return mCanBeContent & UBGraphicsWidgetItem::type_MAC;
#endif
// if we under UNIX OS
#if defined(Q_OS_UNIX)
return mCanBeContent & UBGraphicsWidgetItem::type_UNIX;
#endif
// if we under WINDOWS OS
#if defined(Q_OS_WIN)
return mCanBeContent & UBGraphicsWidgetItem::type_WIN;
#endif
}
bool UBGraphicsWidgetItem::canBeTool()
{
// if we under MAC OS
#if defined(Q_OS_MAC)
return mCanBeTool & UBGraphicsWidgetItem::type_MAC;
#endif
// if we under UNIX OS
#if defined(Q_OS_UNIX)
return mCanBeTool & UBGraphicsWidgetItem::type_UNIX;
#endif
// if we under WINDOWS OS
#if defined(Q_OS_WIN)
return mCanBeTool & UBGraphicsWidgetItem::type_WIN;
#endif
}
void UBGraphicsWidgetItem::loadMainHtml()
{
load(mMainHtmlUrl);
}
void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok)
{
mInitialLoadDone = true;
mLoadIsErronous = !ok;
update(boundingRect());
}
bool UBGraphicsWidgetItem::hasEmbededObjects()
{
if (page()->mainFrame()) {
QList<UBWebKitUtils::HtmlObject> htmlObjects = UBWebKitUtils::objectsInFrame(page()->mainFrame());
return htmlObjects.length() > 0;
}
return false;
}
bool UBGraphicsWidgetItem::hasEmbededFlash()
{
if (hasEmbededObjects())
{
return page()->mainFrame()->toHtml().contains("application/x-shockwave-flash");
}
else
{
return false;
}
}
QString UBGraphicsWidgetItem::iconFilePath(const QUrl& pUrl)
{
// TODO UB 4.x read config.xml widget.icon param first
QStringList files;
files << "icon.svg"; // W3C widget default 1
files << "icon.ico"; // W3C widget default 2
files << "icon.png"; // W3C widget default 3
files << "icon.gif"; // W3C widget default 4
files << "Icon.png"; // Apple widget default
QString file = UBFileSystemUtils::getFirstExistingFileFromList(pUrl.toLocalFile(), files);
// default
if (file.length() == 0)
{
file = QString(":/images/defaultWidgetIcon.png");
}
return file;
}
QString UBGraphicsWidgetItem::widgetName(const QUrl& widgetPath)
{
QString name;
QString version;
QFile w3CConfigFile(widgetPath.toLocalFile() + "/config.xml");
QFile appleConfigFile(widgetPath.toLocalFile() + "/Info.plist");
if (w3CConfigFile.exists() && w3CConfigFile.open(QFile::ReadOnly))
{
QDomDocument doc;
doc.setContent(w3CConfigFile.readAll());
QDomElement root = doc.firstChildElement("widget");
if (!root.isNull())
{
QDomElement nameElement = root.firstChildElement("name");
if (!nameElement.isNull())
name = nameElement.text();
version = root.attribute("version", "");
}
w3CConfigFile.close();
}
else if (appleConfigFile.exists() && appleConfigFile.open(QFile::ReadOnly))
{
QDomDocument doc;
doc.setContent(appleConfigFile.readAll());
QDomElement root = doc.firstChildElement("plist");
if (!root.isNull())
{
QDomElement dictElement = root.firstChildElement("dict");
if (!dictElement.isNull())
{
QDomNodeList childNodes = dictElement.childNodes();
// looking for something like
// ..
// <key>CFBundleDisplayName</key>
// <string>brain scans</string>
// ..
for(int i = 0; i < childNodes.count() - 1; i++)
{
if (childNodes.at(i).isElement())
{
QDomElement elKey = childNodes.at(i).toElement();
if (elKey.text() == "CFBundleDisplayName")
{
if (childNodes.at(i + 1).isElement())
{
QDomElement elValue = childNodes.at(i + 1).toElement();
name = elValue.text();
}
}
else if (elKey.text() == "CFBundleShortVersionString")
{
if (childNodes.at(i + 1).isElement())
{
QDomElement elValue = childNodes.at(i + 1).toElement();
version = elValue.text();
}
}
}
}
}
}
appleConfigFile.close();
}
QString result;
if (name.length() > 0)
{
result = name;
if (version.length() > 0)
{
result += " ";
result += version;
}
}
return result;
}
int UBGraphicsWidgetItem::widgetType(const QUrl& pUrl)
{
QString mime = UBFileSystemUtils::mimeTypeFromFileName(pUrl.toString());
if (mime == "application/vnd.apple-widget")
{
return UBWidgetType::Apple;
}
else if (mime == "application/widget")
{
return UBWidgetType::W3C;
}
else
{
return UBWidgetType::Other;
}
}
void UBGraphicsWidgetItem::injectInlineJavaScript()
{
if (!sInlineJavaScriptLoaded)
{
sInlineJavaScripts = UBApplication::applicationController->widgetInlineJavaScripts();
sInlineJavaScriptLoaded = true;
}
foreach(QString script, sInlineJavaScripts)
{
page()->mainFrame()->evaluateJavaScript(script);
}
}
void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (mIsFrozen)
{
painter->drawPixmap(0, 0, mSnapshot);
}
else if(mIsTakingSnapshot || (mInitialLoadDone && !mLoadIsErronous))
{
QGraphicsWebView::paint(painter, option, widget);
}
else
{
QString message = tr("Loading ...");
// this is the right way of doing but we receive two callback and the one return always that the
// load as failed... to check
// if (mLoadIsErronous)
// message = tr("Cannot load content");
// else
// message = tr("Loading ...");
painter->setFont(QFont("Arial", 12));
QFontMetrics fm = painter->fontMetrics();
QRect txtBoundingRect = fm.boundingRect(message);
txtBoundingRect.moveCenter(rect().center().toPoint());
txtBoundingRect.adjust(-10, -5, 10, 5);
painter->setPen(Qt::NoPen);
painter->setBrush(UBSettings::paletteColor);
painter->drawRoundedRect(txtBoundingRect, 3, 3);
painter->setPen(Qt::white);
painter->drawText(rect(), Qt::AlignCenter, message);
}
}
QPixmap UBGraphicsWidgetItem::takeSnapshot()
{
mIsTakingSnapshot = true;
QPixmap pixmap(size().toSize());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QStyleOptionGraphicsItem options;
paint(&painter, &options);
mIsTakingSnapshot = false;
return pixmap;
}
void UBGraphicsWidgetItem::setSnapshot(const QPixmap& pix)
{
mSnapshot = pix;
}
void UBGraphicsWidgetItem::freeze()
{
QPixmap pix = takeSnapshot();
mIsFrozen = true;
setSnapshot(pix);
}
void UBGraphicsWidgetItem::unFreeze()
{
mIsFrozen = false;
}
void UBGraphicsWidgetItem::javaScriptWindowObjectCleared()
{
injectInlineJavaScript();
if(!mUniboardAPI)
mUniboardAPI = new UBWidgetUniboardAPI(scene(), this);
mUniboardAPI = new UBWidgetUniboardAPI(scene(), this);
mWebKitWidget->page()->mainFrame()->addToJavaScriptWindowObject("sankore", mUniboardAPI);
page()->mainFrame()->addToJavaScriptWindowObject("sankore", mUniboardAPI);
}
......@@ -66,7 +402,7 @@ void UBGraphicsWidgetItem::setUuid(const QUuid &pUuid)
void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
UBGraphicsProxyWidget::mousePressEvent(event);
UBGraphicsWebView::mousePressEvent(event);
// did webkit consume the mouse press ?
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
......@@ -76,35 +412,33 @@ void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->accept();
}
void UBGraphicsWidgetItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mShouldMoveWidget = false;
UBGraphicsProxyWidget::mouseReleaseEvent(event);
UBGraphicsWebView::mouseReleaseEvent(event);
}
void UBGraphicsWidgetItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
sendJSEnterEvent();
mDelegate->hoverEnterEvent(event);
UBGraphicsProxyWidget::hoverEnterEvent(event);
UBGraphicsWebView::hoverEnterEvent(event);
}
void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
sendJSLeaveEvent();
mDelegate->hoverLeaveEvent(event);
UBGraphicsProxyWidget::hoverLeaveEvent(event);
UBGraphicsWebView::hoverLeaveEvent(event);
}
void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
UBGraphicsProxyWidget::hoverMoveEvent(event);
UBGraphicsWebView::hoverMoveEvent(event);
}
bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event)
{
if (mShouldMoveWidget && obj == mWebKitWidget && event->type() == QEvent::MouseMove)
if (mShouldMoveWidget && obj == this && event->type() == QEvent::MouseMove)
{
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
......@@ -129,19 +463,6 @@ bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event)
}
void UBGraphicsWidgetItem::resize ( qreal w, qreal h )
{
UBGraphicsProxyWidget::resize(w, h);
mWebKitWidget->resize(w, h);
}
void UBGraphicsWidgetItem::resize ( const QSizeF & size )
{
resize(size.width(), size.height());
}
void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom)
{
......@@ -151,21 +472,20 @@ void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom)
void UBGraphicsWidgetItem::initialize()
{
connect(mWebKitWidget->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
QPalette palette = mWebKitWidget->page()->palette();
QPalette palette = page()->palette();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
mWebKitWidget->page()->setPalette(palette);
UBGraphicsProxyWidget::setWidget(mWebKitWidget);
page()->setPalette(palette);
mWebKitWidget->installEventFilter(this);
installEventFilter(this);
UBGraphicsProxyWidget::setMinimumSize(mWebKitWidget->nominalSize());
UBGraphicsWebView::setMinimumSize(nominalSize());
connect(mWebKitWidget, SIGNAL(geometryChangeRequested(const QRect&)), this, SLOT(geometryChangeRequested(const QRect&)));
connect(page(), SIGNAL(geometryChangeRequested(const QRect&)), this, SLOT(geometryChangeRequested(const QRect&)));
connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(mainFrameLoadFinished (bool)));
if (mDelegate && mDelegate->frame() && mWebKitWidget->resizable())
if (mDelegate && mDelegate->frame() && resizable())
mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
......@@ -177,13 +497,6 @@ UBGraphicsScene* UBGraphicsWidgetItem::scene()
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene());
}
UBAbstractWidget* UBGraphicsWidgetItem::widgetWebView()
{
return mWebKitWidget;
}
void UBGraphicsWidgetItem::setPreference(const QString& key, QString value)
{
if (key == "" || (mPreferences.contains(key) && mPreferences.value(key) == value))
......@@ -267,23 +580,23 @@ void UBGraphicsWidgetItem::remove()
void UBGraphicsWidgetItem::removeScript()
{
if (mWebKitWidget && mWebKitWidget->page() && mWebKitWidget->page()->mainFrame())
if (page() && page()->mainFrame())
{
mWebKitWidget->page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}");
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}");
}
}
void UBGraphicsWidgetItem::sendJSEnterEvent()
{
if (mWebKitWidget && mWebKitWidget->page() && mWebKitWidget->page()->mainFrame())
if (page() && page()->mainFrame())
{
mWebKitWidget->page()->mainFrame()->evaluateJavaScript("if(widget && widget.onenter) { widget.onenter();}");
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onenter) { widget.onenter();}");
}
}
void UBGraphicsWidgetItem::sendJSLeaveEvent()
{
if (mWebKitWidget && mWebKitWidget->page() && mWebKitWidget->page()->mainFrame())
if (page() && page()->mainFrame())
{
mWebKitWidget->page()->mainFrame()->evaluateJavaScript("if(widget && widget.onleave) { widget.onleave();}");
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onleave) { widget.onleave();}");
}
}
......@@ -305,16 +618,42 @@ bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const
UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent)
: UBGraphicsWidgetItem(parent)
{
mWebKitWidget = new UBAppleWidget(pWidgetUrl, 0);
initialize();
}
QString path = pWidgetUrl.toLocalFile();
if (!path.endsWith(".wdgt") && !path.endsWith(".wdgt/"))
{
int lastSlashIndex = path.lastIndexOf("/");
if (lastSlashIndex > 0)
{
path = path.mid(0, lastSlashIndex + 1);
}
}
UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(UBAppleWidget *appleWidget, QGraphicsItem *parent)
: UBGraphicsWidgetItem(parent)
QFile plistFile(path + "/Info.plist");
plistFile.open(QFile::ReadOnly);
{
mWebKitWidget = appleWidget;
QByteArray plistBin = plistFile.readAll();
QString plist = QString::fromUtf8(plistBin);
int mainHtmlIndex = plist.indexOf("MainHTML");
int mainHtmlIndexStart = plist.indexOf("<string>", mainHtmlIndex);
int mainHtmlIndexEnd = plist.indexOf("</string>", mainHtmlIndexStart);
if (mainHtmlIndex > -1 && mainHtmlIndexStart > -1 && mainHtmlIndexEnd > -1)
{
mMainHtmlFileName = plist.mid(mainHtmlIndexStart + 8, mainHtmlIndexEnd - mainHtmlIndexStart - 8);
}
mMainHtmlUrl = pWidgetUrl;
mMainHtmlUrl.setPath(pWidgetUrl.path() + "/" + mMainHtmlFileName);
load(mMainHtmlUrl);
QPixmap defaultPixmap(pWidgetUrl.toLocalFile() + "/Default.png");
setMaximumSize(defaultPixmap.size());
mNominalSize = defaultPixmap.size();
initialize();
}
......@@ -328,7 +667,7 @@ UBGraphicsAppleWidgetItem::~UBGraphicsAppleWidgetItem()
UBItem* UBGraphicsAppleWidgetItem::deepCopy() const
{
UBGraphicsAppleWidgetItem *appleWidget = new UBGraphicsAppleWidgetItem(mWebKitWidget->widgetUrl(), parentItem());
UBGraphicsAppleWidgetItem *appleWidget = new UBGraphicsAppleWidgetItem(QGraphicsWebView::url(), parentItem());
foreach(QString key, mPreferences.keys())
{
......@@ -351,27 +690,182 @@ void UBGraphicsAppleWidgetItem::setUuid(const QUuid &pUuid)
setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent, int widgetType)
: UBGraphicsWidgetItem(parent, widgetType)
, mW3CWidgetAPI(0)
{
mW3CWidget = new UBW3CWidget(pWidgetUrl, 0);
mWebKitWidget = mW3CWidget;
initialize();
setOwnFolder(pWidgetUrl);
}
UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(UBW3CWidget *w3cWidget, QGraphicsItem *parent, int widgetType)
UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent)
: UBGraphicsWidgetItem(parent)
, mW3CWidget(w3cWidget)
, mW3CWidgetAPI(0)
{
Q_UNUSED(widgetType);
mWebKitWidget = mW3CWidget;
QString path = pWidgetUrl.toLocalFile();
QDir potentialDir(path);
if (!path.endsWith(".wgt") && !path.endsWith(".wgt/") && !potentialDir.exists())
{
int lastSlashIndex = path.lastIndexOf("/");
if (lastSlashIndex > 0)
{
path = path.mid(0, lastSlashIndex + 1);
}
}
if(!path.endsWith("/"))
path += "/";
int width = 300;
int height = 150;
QFile configFile(path + "config.xml");
configFile.open(QFile::ReadOnly);
QDomDocument doc;
doc.setContent(configFile.readAll());
QDomNodeList widgetDomList = doc.elementsByTagName("widget");
if (widgetDomList.count() > 0)
{
QDomElement widgetElement = widgetDomList.item(0).toElement();
width = widgetElement.attribute("width", "300").toInt();
height = widgetElement.attribute("height", "150").toInt();
mMetadatas.id = widgetElement.attribute("id", "");
//some early widget (<= 4.3.4) where using identifier instead of id
if (mMetadatas.id.length() == 0)
mMetadatas.id = widgetElement.attribute("identifier", "");
mMetadatas.version = widgetElement.attribute("version", "");
// TODO UB 4.x map properly ub namespace
mIsResizable = widgetElement.attribute("ub:resizable", "false") == "true";
mIsFreezable = widgetElement.attribute("ub:freezable", "true") == "true";
QString roles = widgetElement.attribute("ub:roles", "content tool").trimmed().toLower();
//------------------------------//
if( roles == "" || roles.contains("tool") )
{
mCanBeTool = UBGraphicsWidgetItem::type_ALL;
}
if( roles.contains("twin") )
{
mCanBeTool |= UBGraphicsWidgetItem::type_WIN;
}
if( roles.contains("tmac") )
{
mCanBeTool |= UBGraphicsWidgetItem::type_MAC;
}
if( roles.contains("tunix") )
{
mCanBeTool |= UBGraphicsWidgetItem::type_UNIX;
}
//---------//
if( roles == "" || roles.contains("content") )
{
mCanBeContent = UBGraphicsWidgetItem::type_ALL;
}
if( roles.contains("cwin") )
{
mCanBeContent |= UBGraphicsWidgetItem::type_WIN;
}
if( roles.contains("cmac") )
{
mCanBeContent |= UBGraphicsWidgetItem::type_MAC;
}
if( roles.contains("cunix") )
{
mCanBeContent |= UBGraphicsWidgetItem::type_UNIX;
}
//------------------------------//
QDomNodeList contentDomList = widgetElement.elementsByTagName("content");
if (contentDomList.count() > 0)
{
QDomElement contentElement = contentDomList.item(0).toElement();
mMainHtmlFileName = contentElement.attribute("src", "");
}
mMetadatas.name = textForSubElementByLocale(widgetElement, "name", QLocale::system());
mMetadatas.description = textForSubElementByLocale(widgetElement, "description ", QLocale::system());
QDomNodeList authorDomList = widgetElement.elementsByTagName("author");
if (authorDomList.count() > 0)
{
QDomElement authorElement = authorDomList.item(0).toElement();
mMetadatas.author = authorElement.text();
mMetadatas.authorHref = authorElement.attribute("href", "");
mMetadatas.authorEmail = authorElement.attribute("email ", "");
}
QDomNodeList propertiesDomList = widgetElement.elementsByTagName("preference");
/*for (uint i = 0; i < propertiesDomList.length(); i++)
{
QDomElement preferenceElement = propertiesDomList.at(i).toElement();
QString prefName = preferenceElement.attribute("name", "");
if (prefName.length() > 0)
{
QString prefValue = preferenceElement.attribute("value", "");
bool readOnly = (preferenceElement.attribute("readonly", "false") == "true");
mPreferences.insert(prefName, PreferenceValue(prefValue, readOnly));
}
}*/
}
if (mMainHtmlFileName.length() == 0)
{
QFile defaultStartFile(path + "index.htm");
if (defaultStartFile.exists())
{
mMainHtmlFileName = "index.htm";
}
else
{
QFile secondDefaultStartFile(path + "index.html");
if (secondDefaultStartFile.exists())
{
mMainHtmlFileName = "index.html";
}
}
}
mMainHtmlUrl = pWidgetUrl;
mMainHtmlUrl.setPath(pWidgetUrl.path() + "/" + mMainHtmlFileName);
// is it a valid local file ?
QFile f(mMainHtmlUrl.toLocalFile());
if(!f.exists())
mMainHtmlUrl = QUrl(mMainHtmlFileName);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(javaScriptWindowObjectCleared()));
load(mMainHtmlUrl);
setMaximumSize(QSize(width, height));
mNominalSize = QSize(width, height);
initialize();
setOwnFolder(pWidgetUrl);
}
UBGraphicsW3CWidgetItem::~UBGraphicsW3CWidgetItem()
{
// NOOP
......@@ -385,16 +879,16 @@ void UBGraphicsW3CWidgetItem::paint(QPainter * painter, const QStyleOptionGraphi
if (scene())
rc = scene()->renderingContext();
if ((!w3cWidget()->hasLoadedSuccessfully()) && (rc == UBGraphicsScene::NonScreen || rc == UBGraphicsScene::PdfExport))
if ((!hasLoadedSuccessfully()) && (rc == UBGraphicsScene::NonScreen || rc == UBGraphicsScene::PdfExport))
{
if (!w3cWidget()->snapshot().isNull())
if (!snapshot().isNull())
{
painter->drawPixmap(0, 0, w3cWidget()->snapshot());
painter->drawPixmap(0, 0, snapshot());
}
}
else
{
UBGraphicsProxyWidget::paint(painter, option, widget);
UBGraphicsWebView::paint(painter, option, widget);
}
}
......@@ -411,26 +905,13 @@ void UBGraphicsW3CWidgetItem::javaScriptWindowObjectCleared()
if(!mW3CWidgetAPI)
mW3CWidgetAPI = new UBW3CWidgetAPI(this);
mWebKitWidget->page()->mainFrame()->addToJavaScriptWindowObject("widget", mW3CWidgetAPI);
}
page()->mainFrame()->addToJavaScriptWindowObject("widget", mW3CWidgetAPI);
UBW3CWidget::Metadata UBGraphicsW3CWidgetItem::metadatas() const
{
return mW3CWidget->metadatas();
}
UBW3CWidget* UBGraphicsW3CWidgetItem::w3cWidget() const
{
return mW3CWidget;
}
UBItem* UBGraphicsW3CWidgetItem::deepCopy() const
{
UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(mWebKitWidget->widgetUrl(), parentItem());
UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(QGraphicsWebView::url(), parentItem());
copy->setPos(this->pos());
copy->setTransform(this->transform());
......@@ -441,7 +922,7 @@ UBItem* UBGraphicsW3CWidgetItem::deepCopy() const
copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable
copy->setSourceUrl(this->sourceUrl());
copy->resize(this->size());
copy->resize(this->size().width(), this->size().height());
foreach(QString key, mPreferences.keys())
{
......@@ -455,3 +936,299 @@ UBItem* UBGraphicsW3CWidgetItem::deepCopy() const
return copy;
}
bool UBGraphicsW3CWidgetItem::hasNPAPIWrapper(const QString& pMimeType)
{
loadNPAPIWrappersTemplates();
return sNPAPIWrapperTemplates.contains(pMimeType);
}
QString UBGraphicsW3CWidgetItem::createNPAPIWrapper(const QString& url,
const QString& pMimeType, const QSize& sizeHint, const QString& pName)
{
const QString userWidgetPath = UBSettings::settings()->userInteractiveDirectory() + "/" + tr("Web");
QDir userWidgetDir(userWidgetPath);
return createNPAPIWrapperInDir(url, userWidgetDir, pMimeType, sizeHint, pName);
}
QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, const QDir& pDir,
const QString& pMimeType, const QSize& sizeHint,
const QString& pName)
{
QString url = pUrl;
url = UBFileSystemUtils::removeLocalFilePrefix(url);
QString name = pName;
QFileInfo fi(url);
if (name.length() == 0)
name = fi.baseName();
if (fi.exists()){
url = fi.fileName();
}
loadNPAPIWrappersTemplates();
QString htmlTemplate;
if (pMimeType.length() > 0 && sNPAPIWrapperTemplates.contains(pMimeType)){
htmlTemplate = sNPAPIWrapperTemplates.value(pMimeType);
}
else {
QString extension = UBFileSystemUtils::extension(url);
if (sNPAPIWrapperTemplates.contains(extension))
htmlTemplate = sNPAPIWrapperTemplates.value(extension);
}
if (htmlTemplate.length() > 0){
htmlTemplate = htmlTemplate.replace(QString("{in.url}"), url)
.replace(QString("{in.width}"), QString("%1").arg(sizeHint.width()))
.replace(QString("{in.height}"), QString("%1").arg(sizeHint.height()));
QString configTemplate = sNPAPIWrappperConfigTemplate
.replace(QString("{in.id}"), url)
.replace(QString("{in.width}"), QString("%1").arg(sizeHint.width()))
.replace(QString("{in.height}"), QString("%1").arg(sizeHint.height()))
.replace(QString("{in.name}"), name)
.replace(QString("{in.startFile}"), QString("index.htm"));
QString dirPath = pDir.path();
if (!pDir.exists())
pDir.mkpath(dirPath);
QString widgetLibraryPath = dirPath + "/" + name + ".wgt";
QDir widgetLibraryDir(widgetLibraryPath);
if (widgetLibraryDir.exists())
{
if (!UBFileSystemUtils::deleteDir(widgetLibraryDir.path()))
{
qWarning() << "Cannot delete old widget " << widgetLibraryDir.path();
}
}
widgetLibraryDir.mkpath(widgetLibraryPath);
if (fi.exists()){
QString target = widgetLibraryPath + "/" + fi.fileName();
QString source = pUrl;
source = UBFileSystemUtils::removeLocalFilePrefix(source);
QFile::copy(source, target);
}
QFile configFile(widgetLibraryPath + "/config.xml");
if (!configFile.open(QIODevice::WriteOnly))
{
qWarning() << "Cannot open file " << configFile.fileName();
return "";
}
QTextStream outConfig(&configFile);
outConfig.setCodec("UTF-8");
outConfig << configTemplate;
configFile.close();
QFile indexFile(widgetLibraryPath + "/index.htm");
if (!indexFile.open(QIODevice::WriteOnly))
{
qWarning() << "Cannot open file " << indexFile.fileName();
return "";
}
QTextStream outIndex(&indexFile);
outIndex.setCodec("UTF-8");
outIndex << htmlTemplate;
indexFile.close();
return widgetLibraryPath;
}
else
{
return "";
}
}
QString UBGraphicsW3CWidgetItem::createHtmlWrapperInDir(const QString& html, const QDir& pDir,
const QSize& sizeHint, const QString& pName)
{
QString widgetPath = pDir.path() + "/" + pName + ".wgt";
widgetPath = UBFileSystemUtils::nextAvailableFileName(widgetPath);
QDir widgetDir(widgetPath);
if (!widgetDir.exists())
{
widgetDir.mkpath(widgetDir.path());
}
QFile configFile(widgetPath + "/" + "config.xml");
if (configFile.exists())
{
configFile.remove(configFile.fileName());
}
if (!configFile.open(QIODevice::WriteOnly))
{
qWarning() << "Cannot open file " << configFile.fileName();
return "";
}
QTextStream outConfig(&configFile);
outConfig.setCodec("UTF-8");
outConfig << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
outConfig << "<widget xmlns=\"http://www.w3.org/ns/widgets\"" << endl;
outConfig << " xmlns:ub=\"http://uniboard.mnemis.com/widgets\"" << endl;
outConfig << " id=\"http://uniboard.mnemis.com/" << pName << "\"" <<endl;
outConfig << " version=\"1.0\"" << endl;
outConfig << " width=\"" << sizeHint.width() << "\"" << endl;
outConfig << " height=\"" << sizeHint.height() << "\"" << endl;
outConfig << " ub:resizable=\"true\">" << endl;
outConfig << " <name>" << pName << "</name>" << endl;
outConfig << " <content src=\"" << pName << ".html\"/>" << endl;
outConfig << "</widget>" << endl;
configFile.close();
const QString fullHtmlFileName = widgetPath + "/" + pName + ".html";
QFile widgetHtmlFile(fullHtmlFileName);
if (widgetHtmlFile.exists())
{
widgetHtmlFile.remove(widgetHtmlFile.fileName());
}
if (!widgetHtmlFile.open(QIODevice::WriteOnly))
{
qWarning() << "cannot open file " << widgetHtmlFile.fileName();
return "";
}
QTextStream outStartFile(&widgetHtmlFile);
outStartFile.setCodec("UTF-8");
outStartFile << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">" << endl;
outStartFile << "<html>" << endl;
outStartFile << "<head>" << endl;
outStartFile << " <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">" << endl;
outStartFile << "</head>" << endl;
outStartFile << " <body>" << endl;
outStartFile << html << endl;
outStartFile << " </body>" << endl;
outStartFile << "</html>" << endl;
widgetHtmlFile.close();
return widgetPath;
}
QString UBGraphicsW3CWidgetItem::freezedWidgetPage()
{
static QString defaultcontent;
if (defaultcontent.isNull()) {
QFile wrapperFile(freezedWidgetDefaultContentFilePath);
if (!wrapperFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "can't open wrapper file " + freezedWidgetDefaultContentFilePath;
defaultcontent = "";
} else {
QByteArray arr = wrapperFile.readAll();
if (!arr.isEmpty()) {
defaultcontent = QString(arr);
} else {
qDebug() << "content of " + freezedWidgetDefaultContentFilePath + "is empty";
defaultcontent = "";
}
}
}
return defaultcontent;
}
void UBGraphicsW3CWidgetItem::loadNPAPIWrappersTemplates()
{
if (!sTemplateLoaded)
{
sNPAPIWrapperTemplates.clear();
QString etcPath = UBPlatformUtils::applicationResourcesDirectory() + "/etc/";
QDir etcDir(etcPath);
foreach(QString fileName, etcDir.entryList())
{
if (fileName.startsWith("npapi-wrapper") && (fileName.endsWith(".htm") || fileName.endsWith(".html")))
{
QString htmlContent = UBFileSystemUtils::readTextFile(etcPath + fileName);
if (htmlContent.length() > 0)
{
QStringList tokens = fileName.split(".");
if (tokens.length() >= 4)
{
QString mime = tokens.at(tokens.length() - 4 );
mime += "/" + tokens.at(tokens.length() - 3);
QString fileExtension = tokens.at(tokens.length() - 2);
sNPAPIWrapperTemplates.insert(mime, htmlContent);
sNPAPIWrapperTemplates.insert(fileExtension, htmlContent);
}
}
}
}
sNPAPIWrappperConfigTemplate = UBFileSystemUtils::readTextFile(etcPath + "npapi-wrapper.config.xml");
sTemplateLoaded = true;
}
}
QString UBGraphicsW3CWidgetItem::textForSubElementByLocale(QDomElement rootElement, QString subTagName, QLocale locale)
{
QDomNodeList subList = rootElement.elementsByTagName(subTagName);
QString lang = locale.name();
if (lang.length() > 2)
lang[2] = QLatin1Char('-');
if (subList.count() > 1)
{
for(int i = 0; i < subList.count(); i++)
{
QDomNode node = subList.at(i);
QDomElement element = node.toElement();
QString configLang = element.attribute("xml:lang", "");
if(lang == configLang || (configLang.length() == 2 && configLang == lang.left(2)))
return element.text();
}
}
if (subList.count() >= 1)
{
QDomElement element = subList.item(0).toElement();
return element.text();
}
return "";
}
......@@ -20,7 +20,7 @@
#include "core/UB.h"
#include "UBGraphicsProxyWidget.h"
#include "UBGraphicsWebView.h"
#include "UBW3CWidget.h"
#include "UBAppleWidget.h"
......@@ -32,7 +32,7 @@ class UBW3CWidgetWebStorageAPI;
class UBGraphiscItem;
class UBGraphiscItemDelegate;
class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
class UBGraphicsWidgetItem : public UBGraphicsWebView
{
Q_OBJECT
......@@ -42,26 +42,25 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
virtual UBGraphicsScene* scene();
UBAbstractWidget* widgetWebView();
virtual void initialize();
virtual UBItem* deepCopy() const = 0;
virtual void resize ( qreal w, qreal h );
virtual void resize ( const QSizeF & size );
/* preferences */
void setPreference(const QString& key, QString value);
QString preference(const QString& key) const;
QMap<QString, QString> preferences() const;
void removePreference(const QString& key);
void removeAllPreferences();
/* datastore */
void setDatastoreEntry(const QString& key, QString value);
QString datastoreEntry(const QString& key) const;
QMap<QString, QString> datastoreEntries() const;
void removeDatastoreEntry(const QString& key);
void removeAllDatastoreEntries();
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate; }
virtual void remove();
......@@ -80,6 +79,73 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
virtual void clearSource();
virtual void setUuid(const QUuid &pUuid);
/* from UBAbstractWidget */
void loadMainHtml();
QUrl mainHtml()
{
return mMainHtmlUrl;
}
QUrl widgetUrl()
{
return mWidgetUrl;
}
QString mainHtmlFileName()
{
return mMainHtmlFileName;
}
bool hasEmbededObjects();
bool hasEmbededFlash();
void resize(qreal width, qreal height);
QSize nominalSize() const
{
return mNominalSize;
}
bool canBeContent();
bool canBeTool();
bool hasLoadedSuccessfully() const
{
return (mInitialLoadDone && !mLoadIsErronous);
}
bool freezable()
{
return mIsFreezable;
}
bool resizable()
{
return mIsResizable;
}
static QString iconFilePath(const QUrl& pUrl);
static QString widgetName(const QUrl& pUrl);
static int widgetType(const QUrl& pUrl);
bool isFrozen()
{
return mIsFrozen;
}
QPixmap snapshot(){
return mSnapshot;
}
void setSnapshot(const QPixmap& pix);
QPixmap takeSnapshot();
public slots:
void freeze();
void unFreeze();
/* end from */
protected:
......@@ -96,14 +162,44 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
virtual void sendJSEnterEvent();
virtual void sendJSLeaveEvent();
UBAbstractWidget* mWebKitWidget;
QMap<QString, QString> mPreferences;
QMap<QString, QString> mDatastore;
/* from UBAbstractWidget*/
bool mMouseIsPressed;
bool mFirstReleaseAfterMove;
QUrl mMainHtmlUrl;
QString mMainHtmlFileName;
QUrl mWidgetUrl;
QSize mNominalSize;
bool mIsResizable;
bool mInitialLoadDone;
bool mLoadIsErronous;
bool mIsFreezable;
int mCanBeContent;
int mCanBeTool;
enum OSType
{
type_NONE = 0, // 0000
type_WIN = 1, // 0001
type_MAC = 2, // 0010
type_UNIX = 4, // 0100
type_ALL = 7, // 0111
};
virtual void injectInlineJavaScript();
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual void dropEvent(QDropEvent *);
/* end from */
protected slots:
void geometryChangeRequested(const QRect& geom);
virtual void javaScriptWindowObjectCleared();
/* from UBAbstractWidget*/
void mainFrameLoadFinished(bool ok);
/* end from */
private:
QPointF mLastMousePos;
......@@ -111,6 +207,14 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
UBWidgetUniboardAPI* mUniboardAPI;
QUrl ownFolder;
QUrl SnapshotFile;
/* from UBAbstractWidget*/
static QStringList sInlineJavaScripts;
static bool sInlineJavaScriptLoaded;
bool mIsFrozen;
QPixmap mSnapshot;
bool mIsTakingSnapshot;
/* end from */
};
class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
......@@ -119,7 +223,6 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
public:
UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
UBGraphicsAppleWidgetItem(UBAppleWidget *appleWidget, QGraphicsItem *parent = 0);
~UBGraphicsAppleWidgetItem();
enum { Type = UBGraphicsItemType::AppleWidgetItemType };
......@@ -139,8 +242,7 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
Q_OBJECT
public:
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0, int widgetType = UBGraphicsItemType::W3CWidgetItemType);
UBGraphicsW3CWidgetItem(UBW3CWidget *w3cWidget, QGraphicsItem *parent = 0, int widgetType = UBGraphicsItemType::W3CWidgetItemType);
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsW3CWidgetItem();
enum { Type = UBGraphicsItemType::W3CWidgetItemType };
......@@ -152,22 +254,64 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
virtual UBItem* deepCopy() const;
UBW3CWidget::Metadata metadatas() const;
UBW3CWidget* w3cWidget() const;
virtual void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget );
virtual void setUuid(const QUuid &pUuid);
static QString createNPAPIWrapper(const QString& url,
const QString& pMimeType = QString(), const QSize& sizeHint = QSize(300, 150),
const QString& pName = QString());
static QString createNPAPIWrapperInDir(const QString& url, const QDir& pDir,
const QString& pMimeType = QString(), const QSize& sizeHint = QSize(300, 150),
const QString& pName = QString());
static QString createHtmlWrapperInDir(const QString& html, const QDir& pDir,
const QSize& sizeHint, const QString& pName);
static QString freezedWidgetPage();
static bool hasNPAPIWrapper(const QString& pMimeType);
class Metadata
{
public:
QString id;
QString name;
QString description;
QString author;
QString authorEmail;
QString authorHref;
QString version;
};
Metadata metadatas() const
{
return mMetadatas;
}
Metadata mMetadatas;
private slots:
virtual void javaScriptWindowObjectCleared();
private:
UBW3CWidget* mW3CWidget;
UBW3CWidgetAPI* mW3CWidgetAPI;
static bool sTemplateLoaded;
static QMap<QString, QString> sNPAPIWrapperTemplates;
static QString sNPAPIWrappperConfigTemplate;
static void loadNPAPIWrappersTemplates();
static QString textForSubElementByLocale(QDomElement rootElement, QString subTagName, QLocale locale);
};
......
......@@ -55,7 +55,7 @@ void UBGraphicsWidgetItemDelegate::updateMenuActionState()
UBGraphicsItemDelegate::updateMenuActionState();
if (freezeAction)
freezeAction->setChecked(delegated()->widgetWebView()->isFrozen());
freezeAction->setChecked(delegated()->isFrozen());
}
void UBGraphicsWidgetItemDelegate::decorateMenu(QMenu* menu)
......@@ -71,7 +71,7 @@ void UBGraphicsWidgetItemDelegate::decorateMenu(QMenu* menu)
freezeAction->setCheckable(true);
if (delegated()->widgetWebView()->canBeTool())
if (delegated()->canBeTool())
{
setAsToolAction = mMenu->addAction(tr("Transform as Tool "), this, SLOT(pin()));
QIcon pinIcon;
......@@ -86,11 +86,11 @@ void UBGraphicsWidgetItemDelegate::freeze(bool frozen)
{
if(frozen)
{
delegated()->widgetWebView()->freeze();
delegated()->freeze();
}
else
{
delegated()->widgetWebView()->unFreeze();
delegated()->unFreeze();
}
}
......
......@@ -7,6 +7,7 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBDocumentUndoCommand.h \
src/domain/UBPageSizeUndoCommand.h \
src/domain/UBGraphicsProxyWidget.h \
src/domain/UBGraphicsWebView.h \
src/domain/UBGraphicsSvgItem.h \
src/domain/UBGraphicsPolygonItem.h \
src/domain/UBItem.h \
......@@ -40,6 +41,7 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBDocumentUndoCommand.cpp \
src/domain/UBPageSizeUndoCommand.cpp \
src/domain/UBGraphicsProxyWidget.cpp \
src/domain/UBGraphicsWebView.cpp \
src/domain/UBGraphicsSvgItem.cpp \
src/domain/UBGraphicsPolygonItem.cpp \
src/domain/UBItem.cpp \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment