Commit f3a449f5 authored by Yimgo's avatar Yimgo

Cosmetics in UBGrahicsWebView and UBGraphicsWidgetItem classes.

parent 4cbdf772
......@@ -13,20 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsWebView.h"
#include <QtGui>
#include <QtWebKit>
#include "UBGraphicsWebView.h"
#include "UBGraphicsScene.h"
#include "UBGraphicsItemDelegate.h"
#include "UBGraphicsDelegateFrame.h"
#include "core/memcheck.h"
UBGraphicsWebView::UBGraphicsWebView(QGraphicsItem* parent) :
QGraphicsWebView(parent)
UBGraphicsWebView::UBGraphicsWebView(QGraphicsItem* parent)
: QGraphicsWebView(parent)
{
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
......@@ -68,30 +66,17 @@ void UBGraphicsWebView::setUuid(const QUuid &pUuid)
void UBGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mousePressEvent(event))
{
//NOOP
}
else
{
// QT Proxy Widget is a bit lazy, we force the selection ...
if (!mDelegate->mousePressEvent(event))
setSelected(true); /* forcing selection */
setSelected(true);
}
QGraphicsWebView::mousePressEvent(event);
}
void UBGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mouseMoveEvent(event))
{
// NOOP;
}
else
{
if (!mDelegate->mouseMoveEvent(event))
QGraphicsWebView::mouseMoveEvent(event);
}
}
......@@ -103,7 +88,7 @@ void UBGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *event)
{
if( mDelegate->weelEvent(event) )
if (mDelegate->weelEvent(event))
{
QGraphicsWebView::wheelEvent(event);
event->accept();
......@@ -113,20 +98,18 @@ void UBGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *event)
void UBGraphicsWebView::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
// NOOP
/* NOOP */
}
void UBGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
// NOOP
/* NOOP */
}
void UBGraphicsWebView::setDelegate(UBGraphicsItemDelegate* pDelegate)
{
if (mDelegate)
{
delete mDelegate;
}
mDelegate = pDelegate;
}
......@@ -140,8 +123,7 @@ void UBGraphicsWebView::resize(qreal w, qreal h)
void UBGraphicsWebView::resize(const QSizeF & pSize)
{
if (pSize != size())
{
if (pSize != size()) {
QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height());
QGraphicsWebView::resize(pSize.width(), pSize.height());
if (mDelegate)
......
......@@ -19,7 +19,6 @@
#include <QtGui>
#include <QtWebKit>
#include "UBItem.h"
#include "UBResizableGraphicsItem.h"
......@@ -56,8 +55,6 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual bool event(QEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};
......
......@@ -13,55 +13,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsWidgetItem.h"
#include <QtNetwork>
#include <QtXml>
#include "api/UBWidgetUniboardAPI.h"
#include "api/UBW3CWidgetAPI.h"
#include "UBGraphicsWidgetItem.h"
#include "UBGraphicsScene.h"
#include "UBGraphicsItemDelegate.h"
#include "UBGraphicsWidgetItemDelegate.h"
#include "UBGraphicsDelegateFrame.h"
#include "UBGraphicsScene.h"
#include "frameworks/UBFileSystemUtils.h"
#include "web/UBWebPage.h"
#include "network/UBNetworkAccessManager.h"
#include "api/UBWidgetUniboardAPI.h"
#include "api/UBW3CWidgetAPI.h"
#include "board/UBBoardController.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/UBFileSystemUtils.h"
#include "frameworks/UBPlatformUtils.h"
#include "board/UBBoardController.h"
#include "network/UBNetworkAccessManager.h"
QStringList UBGraphicsWidgetItem::sInlineJavaScripts;
bool UBGraphicsWidgetItem::sInlineJavaScriptLoaded = false;
#include "web/UBWebPage.h"
#include "web/UBWebKitUtils.h"
#include "web/UBWebController.h"
bool UBGraphicsW3CWidgetItem::sTemplateLoaded = false;
QMap<QString, QString> UBGraphicsW3CWidgetItem::sNPAPIWrapperTemplates;
QString UBGraphicsW3CWidgetItem::sNPAPIWrappperConfigTemplate;
bool UBGraphicsWidgetItem::sInlineJavaScriptLoaded = false;
QStringList UBGraphicsWidgetItem::sInlineJavaScripts;
UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType)
: UBGraphicsWebView(parent)
, mIsResizable(false)
, mInitialLoadDone(false)
, mLoadIsErronous(false)
, mIsFreezable(true)
, mIsResizable(false)
, mLoadIsErronous(false)
, mCanBeContent(0)
, mCanBeTool(0)
, mShouldMoveWidget(false)
, mUniboardAPI(0)
, mIsFrozen(false)
, mIsTakingSnapshot(false)
, mShouldMoveWidget(false)
, mUniboardAPI(0)
{
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));
......@@ -75,6 +70,7 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType
page()->setNetworkAccessManager(UBNetworkAccessManager::defaultAccessManager());
setAcceptDrops(true);
setAutoFillBackground(false);
QPalette pagePalette = page()->palette();
......@@ -86,12 +82,71 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(QGraphicsItem *parent, int widgetType
pagePalette.setBrush(QPalette::Base, QBrush(Qt::transparent));
viewPalette.setBrush(QPalette::Window, QBrush(Qt::transparent));
setPalette(viewPalette);
UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this, widgetType);
delegate->init();
setDelegate(delegate);
}
UBGraphicsWidgetItem::~UBGraphicsWidgetItem()
{
// NOOP
/* NOOP */
}
void UBGraphicsWidgetItem::initialize()
{
installEventFilter(this);
UBGraphicsWebView::setMinimumSize(nominalSize());
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly
if (mDelegate && mDelegate->frame() && resizable())
mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing);
QPalette palette = page()->palette();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
page()->setPalette(palette);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
connect(page(), SIGNAL(geometryChangeRequested(const QRect&)), this, SLOT(geometryChangeRequested(const QRect&)));
connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(mainFrameLoadFinished (bool)));
}
QUrl UBGraphicsWidgetItem::mainHtml()
{
return mMainHtmlUrl;
}
void UBGraphicsWidgetItem::loadMainHtml()
{
load(mMainHtmlUrl);
}
QUrl UBGraphicsWidgetItem::widgetUrl()
{
return mWidgetUrl;
}
QString UBGraphicsWidgetItem::mainHtmlFileName()
{
return mMainHtmlFileName;
}
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;
}
bool UBGraphicsWidgetItem::canBeContent()
......@@ -130,219 +185,158 @@ bool UBGraphicsWidgetItem::canBeTool()
#endif
}
void UBGraphicsWidgetItem::loadMainHtml()
QString UBGraphicsWidgetItem::preference(const QString& key) const
{
load(mMainHtmlUrl);
return mPreferences.value(key);
}
void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok)
void UBGraphicsWidgetItem::setPreference(const QString& key, QString value)
{
mInitialLoadDone = true;
mLoadIsErronous = !ok;
if (key == "" || (mPreferences.contains(key) && mPreferences.value(key) == value))
return;
update(boundingRect());
mPreferences.insert(key, value);
if (scene())
scene()->setModified(true);
}
bool UBGraphicsWidgetItem::hasEmbededObjects()
QMap<QString, QString> UBGraphicsWidgetItem::preferences() const
{
if (page()->mainFrame()) {
QList<UBWebKitUtils::HtmlObject> htmlObjects = UBWebKitUtils::objectsInFrame(page()->mainFrame());
return htmlObjects.length() > 0;
}
return mPreferences;
}
return false;
void UBGraphicsWidgetItem::removePreference(const QString& key)
{
mPreferences.remove(key);
}
bool UBGraphicsWidgetItem::hasEmbededFlash()
void UBGraphicsWidgetItem::removeAllPreferences()
{
if (hasEmbededObjects())
{
return page()->mainFrame()->toHtml().contains("application/x-shockwave-flash");
}
mPreferences.clear();
}
QString UBGraphicsWidgetItem::datastoreEntry(const QString& key) const
{
if (mDatastore.contains(key))
return mDatastore.value(key);
else
{
return false;
}
return QString();
}
QString UBGraphicsWidgetItem::iconFilePath(const QUrl& pUrl)
void UBGraphicsWidgetItem::setDatastoreEntry(const QString& key, QString value)
{
// TODO UB 4.x read config.xml widget.icon param first
if (key == "" || (mDatastore.contains(key) && mDatastore.value(key) == value))
return;
QStringList files;
mDatastore.insert(key, value);
if (scene())
scene()->setModified(true);
}
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
QMap<QString, QString> UBGraphicsWidgetItem::datastoreEntries() const
{
return mDatastore;
}
files << "Icon.png"; // Apple widget default
QString file = UBFileSystemUtils::getFirstExistingFileFromList(pUrl.toLocalFile(), files);
void UBGraphicsWidgetItem::removeDatastoreEntry(const QString& key)
{
mDatastore.remove(key);
}
// default
if (file.length() == 0)
{
file = QString(":/images/defaultWidgetIcon.png");
}
return file;
void UBGraphicsWidgetItem::removeAllDatastoreEntries()
{
mDatastore.clear();
}
QString UBGraphicsWidgetItem::widgetName(const QUrl& widgetPath)
UBGraphicsItemDelegate* UBGraphicsWidgetItem::Delegate() const
{
QString name;
QString version;
QFile w3CConfigFile(widgetPath.toLocalFile() + "/config.xml");
QFile appleConfigFile(widgetPath.toLocalFile() + "/Info.plist");
return mDelegate;
}
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();
void UBGraphicsWidgetItem::remove()
{
if (mDelegate)
mDelegate->remove();
}
version = root.attribute("version", "");
}
void UBGraphicsWidgetItem::removeScript()
{
if (page() && page()->mainFrame())
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}");
}
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();
void UBGraphicsWidgetItem::processDropEvent(QDropEvent *event)
{
return mUniboardAPI->ProcessDropEvent(event);
}
bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const
{
return mUniboardAPI->isDropableData(data);
}
// looking for something like
// ..
// <key>CFBundleDisplayName</key>
// <string>brain scans</string>
// ..
QUrl UBGraphicsWidgetItem::getOwnFolder() const {
return ownFolder;
}
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();
}
}
}
}
}
}
void UBGraphicsWidgetItem::setOwnFolder(const QUrl &newFolder)
{
ownFolder = newFolder;
}
appleConfigFile.close();
}
void UBGraphicsWidgetItem::setSnapshotPath(const QUrl &newFilePath)
{
SnapshotFile = newFilePath;
}
QString result;
QUrl UBGraphicsWidgetItem::getSnapshotPath()
{
return SnapshotFile;
}
if (name.length() > 0)
{
result = name;
if (version.length() > 0)
{
result += " ";
result += version;
}
}
void UBGraphicsWidgetItem::clearSource()
{
UBFileSystemUtils::deleteDir(getOwnFolder().toLocalFile());
UBFileSystemUtils::deleteFile(getSnapshotPath().toLocalFile());
}
return result;
void UBGraphicsWidgetItem::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
}
int UBGraphicsWidgetItem::widgetType(const QUrl& pUrl)
QSize UBGraphicsWidgetItem::nominalSize() const
{
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;
}
return mNominalSize;
}
void UBGraphicsWidgetItem::injectInlineJavaScript()
bool UBGraphicsWidgetItem::hasLoadedSuccessfully() const
{
if (!sInlineJavaScriptLoaded)
{
sInlineJavaScripts = UBApplication::applicationController->widgetInlineJavaScripts();
sInlineJavaScriptLoaded = true;
}
foreach(QString script, sInlineJavaScripts)
{
page()->mainFrame()->evaluateJavaScript(script);
}
return (mInitialLoadDone && !mLoadIsErronous);
}
void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
bool UBGraphicsWidgetItem::freezable()
{
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);
return mIsFreezable;
}
txtBoundingRect.moveCenter(rect().center().toPoint());
txtBoundingRect.adjust(-10, -5, 10, 5);
bool UBGraphicsWidgetItem::resizable()
{
return mIsResizable;
}
painter->setPen(Qt::NoPen);
painter->setBrush(UBSettings::paletteColor);
painter->drawRoundedRect(txtBoundingRect, 3, 3);
bool UBGraphicsWidgetItem::isFrozen()
{
return mIsFrozen;
}
painter->setPen(Qt::white);
painter->drawText(rect(), Qt::AlignCenter, message);
}
QPixmap UBGraphicsWidgetItem::snapshot()
{
return mSnapshot;
}
QPixmap UBGraphicsWidgetItem::takeSnapshot()
......@@ -366,34 +360,122 @@ void UBGraphicsWidgetItem::setSnapshot(const QPixmap& pix)
mSnapshot = pix;
}
void UBGraphicsWidgetItem::freeze()
UBGraphicsScene* UBGraphicsWidgetItem::scene()
{
QPixmap pix = takeSnapshot();
mIsFrozen = true;
setSnapshot(pix);
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene());
}
int UBGraphicsWidgetItem::widgetType(const QUrl& pUrl)
{
QString mime = UBFileSystemUtils::mimeTypeFromFileName(pUrl.toString());
void UBGraphicsWidgetItem::unFreeze()
if (mime == "application/vnd.apple-widget")
return UBWidgetType::Apple;
else if (mime == "application/widget")
return UBWidgetType::W3C;
else
return UBWidgetType::Other;
}
QString UBGraphicsWidgetItem::widgetName(const QUrl& widgetPath)
{
mIsFrozen = false;
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;
}
void UBGraphicsWidgetItem::javaScriptWindowObjectCleared()
QString UBGraphicsWidgetItem::iconFilePath(const QUrl& pUrl)
{
injectInlineJavaScript();
/* TODO UB 4.x read config.xml widget.icon param first */
if(!mUniboardAPI)
mUniboardAPI = new UBWidgetUniboardAPI(scene(), this);
QStringList files;
page()->mainFrame()->addToJavaScriptWindowObject("sankore", mUniboardAPI);
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;
}
void UBGraphicsWidgetItem::setUuid(const QUuid &pUuid)
void UBGraphicsWidgetItem::freeze()
{
UBItem::setUuid(pUuid);
setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene
QPixmap pix = takeSnapshot();
mIsFrozen = true;
setSnapshot(pix);
}
void UBGraphicsWidgetItem::unFreeze()
{
mIsFrozen = false;
}
void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
......@@ -434,196 +516,120 @@ void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event)
{
if (mShouldMoveWidget && obj == this && event->type() == QEvent::MouseMove)
{
if (mShouldMoveWidget && obj == this && event->type() == QEvent::MouseMove) {
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
if (mouseMoveEvent->buttons() & Qt::LeftButton)
{
if (mouseMoveEvent->buttons() & Qt::LeftButton) {
QPointF scenePos = mapToScene(mouseMoveEvent->pos());
QPointF newPos = pos() + scenePos - mLastMousePos;
setPos(newPos);
mLastMousePos = scenePos;
event->accept();
return true;
}
}
//standard event processing
return QObject::eventFilter(obj, event);
}
void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom)
{
resize(geom.width(), geom.height());
}
void UBGraphicsWidgetItem::initialize()
{
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared()));
QPalette palette = page()->palette();
palette.setBrush(QPalette::Base, QBrush(Qt::transparent));
page()->setPalette(palette);
installEventFilter(this);
UBGraphicsWebView::setMinimumSize(nominalSize());
connect(page(), SIGNAL(geometryChangeRequested(const QRect&)), this, SLOT(geometryChangeRequested(const QRect&)));
connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(mainFrameLoadFinished (bool)));
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
}
UBGraphicsScene* UBGraphicsWidgetItem::scene()
{
return qobject_cast<UBGraphicsScene*>(QGraphicsItem::scene());
}
void UBGraphicsWidgetItem::setPreference(const QString& key, QString value)
{
if (key == "" || (mPreferences.contains(key) && mPreferences.value(key) == value))
return;
mPreferences.insert(key, value);
if (scene())
scene()->setModified(true);
}
QString UBGraphicsWidgetItem::preference(const QString& key) const
{
return mPreferences.value(key);
}
QMap<QString, QString> UBGraphicsWidgetItem::preferences() const
{
return mPreferences;
}
void UBGraphicsWidgetItem::removePreference(const QString& key)
{
mPreferences.remove(key);
}
void UBGraphicsWidgetItem::removeAllPreferences()
{
mPreferences.clear();
}
void UBGraphicsWidgetItem::setDatastoreEntry(const QString& key, QString value)
{
if (key == "" || (mDatastore.contains(key) && mDatastore.value(key) == value))
return;
mDatastore.insert(key, value);
if (scene())
scene()->setModified(true);
}
QString UBGraphicsWidgetItem::datastoreEntry(const QString& key) const
{
if (mDatastore.contains(key))
return mDatastore.value(key);
else
return "";
}
QMap<QString, QString> UBGraphicsWidgetItem::datastoreEntries() const
{
return mDatastore;
}
void UBGraphicsWidgetItem::removeDatastoreEntry(const QString& key)
{
mDatastore.remove(key);
}
void UBGraphicsWidgetItem::removeAllDatastoreEntries()
{
mDatastore.clear();
}
void UBGraphicsWidgetItem::remove()
{
if (mDelegate)
mDelegate->remove();
mLastMousePos = scenePos;
}
event->accept();
void UBGraphicsWidgetItem::removeScript()
{
if (page() && page()->mainFrame())
{
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}");
return true;
}
}
/* standard event processing */
return QObject::eventFilter(obj, event);
}
void UBGraphicsWidgetItem::sendJSEnterEvent()
{
if (page() && page()->mainFrame())
{
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onenter) { widget.onenter();}");
}
}
void UBGraphicsWidgetItem::sendJSLeaveEvent()
{
if (page() && page()->mainFrame())
{
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onleave) { widget.onleave();}");
}
void UBGraphicsWidgetItem::injectInlineJavaScript()
{
if (!sInlineJavaScriptLoaded) {
sInlineJavaScripts = UBApplication::applicationController->widgetInlineJavaScripts();
sInlineJavaScriptLoaded = true;
}
foreach(QString script, sInlineJavaScripts)
page()->mainFrame()->evaluateJavaScript(script);
}
void UBGraphicsWidgetItem::clearSource()
void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
UBFileSystemUtils::deleteDir(getOwnFolder().toLocalFile());
UBFileSystemUtils::deleteFile(getSnapshotPath().toLocalFile());
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);
}
}
void UBGraphicsWidgetItem::processDropEvent(QDropEvent *event)
void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom)
{
return mUniboardAPI->ProcessDropEvent(event);
resize(geom.width(), geom.height());
}
bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const
void UBGraphicsWidgetItem::javaScriptWindowObjectCleared()
{
return mUniboardAPI->isDropableData(data);
injectInlineJavaScript();
if(!mUniboardAPI)
mUniboardAPI = new UBWidgetUniboardAPI(scene(), this);
page()->mainFrame()->addToJavaScriptWindowObject("sankore", mUniboardAPI);
}
void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok)
{
mInitialLoadDone = true;
mLoadIsErronous = !ok;
update(boundingRect());
}
UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent)
: UBGraphicsWidgetItem(parent)
{
QString path = pWidgetUrl.toLocalFile();
if (!path.endsWith(".wdgt") && !path.endsWith(".wdgt/"))
{
if (!path.endsWith(".wdgt") && !path.endsWith(".wdgt/")) {
int lastSlashIndex = path.lastIndexOf("/");
if (lastSlashIndex > 0)
{
path = path.mid(0, lastSlashIndex + 1);
}
}
QFile plistFile(path + "/Info.plist");
plistFile.open(QFile::ReadOnly);
......@@ -636,9 +642,7 @@ UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGr
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);
......@@ -657,34 +661,42 @@ UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGr
UBGraphicsAppleWidgetItem::~UBGraphicsAppleWidgetItem()
{
// NOOP
/* NOOP */
}
int UBGraphicsAppleWidgetItem::type() const
{
return Type;
}
void UBGraphicsAppleWidgetItem::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
}
UBItem* UBGraphicsAppleWidgetItem::deepCopy() const
{
UBGraphicsAppleWidgetItem *appleWidget = new UBGraphicsAppleWidgetItem(QGraphicsWebView::url(), parentItem());
foreach(QString key, mPreferences.keys())
{
appleWidget->setPreference(key, mPreferences.value(key));
}
foreach(QString key, mDatastore.keys())
{
appleWidget->setDatastoreEntry(key, mDatastore.value(key));
}
appleWidget->setSourceUrl(this->sourceUrl());
return appleWidget;
}
void UBGraphicsAppleWidgetItem::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
}
bool UBGraphicsW3CWidgetItem::sTemplateLoaded = false;
QString UBGraphicsW3CWidgetItem::sNPAPIWrappperConfigTemplate;
QMap<QString, QString> UBGraphicsW3CWidgetItem::sNPAPIWrapperTemplates;
UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent)
: UBGraphicsWidgetItem(parent)
......@@ -693,16 +705,13 @@ UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphi
QString path = pWidgetUrl.toLocalFile();
QDir potentialDir(path);
if (!path.endsWith(".wgt") && !path.endsWith(".wgt/") && !potentialDir.exists())
{
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("/"))
if (!path.endsWith("/"))
path += "/";
int width = 300;
......@@ -715,8 +724,7 @@ UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphi
doc.setContent(configFile.readAll());
QDomNodeList widgetDomList = doc.elementsByTagName("widget");
if (widgetDomList.count() > 0)
{
if (widgetDomList.count() > 0) {
QDomElement widgetElement = widgetDomList.item(0).toElement();
width = widgetElement.attribute("width", "300").toInt();
......@@ -724,70 +732,52 @@ UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphi
mMetadatas.id = widgetElement.attribute("id", "");
//some early widget (<= 4.3.4) where using identifier instead of 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
/* 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") )
{
if (roles == "" || roles.contains("tool"))
mCanBeTool = UBGraphicsWidgetItem::type_ALL;
}
if( roles.contains("twin") )
{
if (roles.contains("twin"))
mCanBeTool |= UBGraphicsWidgetItem::type_WIN;
}
if( roles.contains("tmac") )
{
if (roles.contains("tmac"))
mCanBeTool |= UBGraphicsWidgetItem::type_MAC;
}
if( roles.contains("tunix") )
{
if (roles.contains("tunix"))
mCanBeTool |= UBGraphicsWidgetItem::type_UNIX;
}
//---------//
/* --------- */
if( roles == "" || roles.contains("content") )
{
if (roles == "" || roles.contains("content"))
mCanBeContent = UBGraphicsWidgetItem::type_ALL;
}
if( roles.contains("cwin") )
{
if (roles.contains("cwin"))
mCanBeContent |= UBGraphicsWidgetItem::type_WIN;
}
if( roles.contains("cmac") )
{
if (roles.contains("cmac"))
mCanBeContent |= UBGraphicsWidgetItem::type_MAC;
}
if( roles.contains("cunix") )
{
if (roles.contains("cunix"))
mCanBeContent |= UBGraphicsWidgetItem::type_UNIX;
}
//------------------------------//
QDomNodeList contentDomList = widgetElement.elementsByTagName("content");
if (contentDomList.count() > 0)
{
if (contentDomList.count() > 0) {
QDomElement contentElement = contentDomList.item(0).toElement();
mMainHtmlFileName = contentElement.attribute("src", "");
}
......@@ -796,8 +786,7 @@ UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphi
QDomNodeList authorDomList = widgetElement.elementsByTagName("author");
if (authorDomList.count() > 0)
{
if (authorDomList.count() > 0) {
QDomElement authorElement = authorDomList.item(0).toElement();
mMetadatas.author = authorElement.text();
......@@ -807,43 +796,35 @@ UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphi
QDomNodeList propertiesDomList = widgetElement.elementsByTagName("preference");
/*for (uint i = 0; i < propertiesDomList.length(); i++)
{
for (uint i = 0; i < propertiesDomList.length(); i++) {
QDomElement preferenceElement = propertiesDomList.at(i).toElement();
QString prefName = preferenceElement.attribute("name", "");
if (prefName.length() > 0)
{
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)
{
if (mMainHtmlFileName.length() == 0) {
QFile defaultStartFile(path + "index.htm");
if (defaultStartFile.exists())
{
mMainHtmlFileName = "index.htm";
}
else
{
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 ?
/* is it a valid local file ? */
QFile f(mMainHtmlUrl.toLocalFile());
if(!f.exists())
......@@ -864,28 +845,12 @@ UBGraphicsW3CWidgetItem::UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphi
UBGraphicsW3CWidgetItem::~UBGraphicsW3CWidgetItem()
{
// NOOP
/* NOOP */
}
void UBGraphicsW3CWidgetItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
int UBGraphicsW3CWidgetItem::type() const
{
UBGraphicsScene::RenderingContext rc = UBGraphicsScene::Screen;
if (scene())
rc = scene()->renderingContext();
if ((!hasLoadedSuccessfully()) && (rc == UBGraphicsScene::NonScreen || rc == UBGraphicsScene::PdfExport))
{
if (!snapshot().isNull())
{
painter->drawPixmap(0, 0, snapshot());
}
}
else
{
UBGraphicsWebView::paint(painter, option, widget);
}
return Type;
}
void UBGraphicsW3CWidgetItem::setUuid(const QUuid &pUuid)
......@@ -894,17 +859,6 @@ void UBGraphicsW3CWidgetItem::setUuid(const QUuid &pUuid)
setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
void UBGraphicsW3CWidgetItem::javaScriptWindowObjectCleared()
{
UBGraphicsWidgetItem::javaScriptWindowObjectCleared();
if(!mW3CWidgetAPI)
mW3CWidgetAPI = new UBW3CWidgetAPI(this);
page()->mainFrame()->addToJavaScriptWindowObject("widget", mW3CWidgetAPI);
}
UBItem* UBGraphicsW3CWidgetItem::deepCopy() const
{
UBGraphicsW3CWidgetItem *copy = new UBGraphicsW3CWidgetItem(QGraphicsWebView::url(), parentItem());
......@@ -921,28 +875,40 @@ UBItem* UBGraphicsW3CWidgetItem::deepCopy() const
copy->resize(this->size().width(), this->size().height());
foreach(QString key, UBGraphicsWidgetItem::preferences().keys())
{
copy->setPreference(key, UBGraphicsWidgetItem::preferences().value(key));
}
foreach(QString key, mDatastore.keys())
{
copy->setDatastoreEntry(key, mDatastore.value(key));
}
return copy;
}
bool UBGraphicsW3CWidgetItem::hasNPAPIWrapper(const QString& pMimeType)
void UBGraphicsW3CWidgetItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
loadNPAPIWrappersTemplates();
UBGraphicsScene::RenderingContext rc = UBGraphicsScene::Screen;
return sNPAPIWrapperTemplates.contains(pMimeType);
if (scene())
rc = scene()->renderingContext();
if ((!hasLoadedSuccessfully()) && (rc == UBGraphicsScene::NonScreen || rc == UBGraphicsScene::PdfExport)) {
if (!snapshot().isNull())
painter->drawPixmap(0, 0, snapshot());
}
else
UBGraphicsWebView::paint(painter, option, widget);
}
QMap<QString, UBGraphicsW3CWidgetItem::PreferenceValue> UBGraphicsW3CWidgetItem::preferences()
{
return mPreferences;
}
UBGraphicsW3CWidgetItem::Metadata UBGraphicsW3CWidgetItem::metadatas() const
{
return mMetadatas;
}
QString UBGraphicsW3CWidgetItem::createNPAPIWrapper(const QString& url,
const QString& pMimeType, const QSize& sizeHint, const QString& pName)
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);
......@@ -950,11 +916,7 @@ QString UBGraphicsW3CWidgetItem::createNPAPIWrapper(const QString& url,
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 UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, const QDir& pDir, const QString& pMimeType, const QSize& sizeHint, const QString& pName)
{
QString url = pUrl;
url = UBFileSystemUtils::removeLocalFilePrefix(url);
......@@ -965,25 +927,22 @@ QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, co
if (name.length() == 0)
name = fi.baseName();
if (fi.exists()){
if (fi.exists())
url = fi.fileName();
}
loadNPAPIWrappersTemplates();
QString htmlTemplate;
if (pMimeType.length() > 0 && sNPAPIWrapperTemplates.contains(pMimeType)){
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){
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()));
......@@ -1003,15 +962,11 @@ QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, co
QDir widgetLibraryDir(widgetLibraryPath);
if (widgetLibraryDir.exists())
{
if (!UBFileSystemUtils::deleteDir(widgetLibraryDir.path()))
{
qWarning() << "Cannot delete old widget " << widgetLibraryDir.path();
}
}
widgetLibraryDir.mkpath(widgetLibraryPath);
if (fi.exists()){
if (fi.exists()) {
QString target = widgetLibraryPath + "/" + fi.fileName();
QString source = pUrl;
source = UBFileSystemUtils::removeLocalFilePrefix(source);
......@@ -1020,10 +975,9 @@ QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, co
QFile configFile(widgetLibraryPath + "/config.xml");
if (!configFile.open(QIODevice::WriteOnly))
{
if (!configFile.open(QIODevice::WriteOnly)) {
qWarning() << "Cannot open file " << configFile.fileName();
return "";
return QString();
}
QTextStream outConfig(&configFile);
......@@ -1034,10 +988,9 @@ QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, co
QFile indexFile(widgetLibraryPath + "/index.htm");
if (!indexFile.open(QIODevice::WriteOnly))
{
if (!indexFile.open(QIODevice::WriteOnly)) {
qWarning() << "Cannot open file " << indexFile.fileName();
return "";
return QString();
}
QTextStream outIndex(&indexFile);
......@@ -1049,34 +1002,24 @@ QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, co
return widgetLibraryPath;
}
else
{
return "";
}
return QString();
}
QString UBGraphicsW3CWidgetItem::createHtmlWrapperInDir(const QString& html, const QDir& pDir,
const QSize& sizeHint, const QString& pName)
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))
{
if (!configFile.open(QIODevice::WriteOnly)) {
qWarning() << "Cannot open file " << configFile.fileName();
return "";
}
......@@ -1104,13 +1047,10 @@ QString UBGraphicsW3CWidgetItem::createHtmlWrapperInDir(const QString& html, con
QFile widgetHtmlFile(fullHtmlFileName);
if (widgetHtmlFile.exists())
{
widgetHtmlFile.remove(widgetHtmlFile.fileName());
}
if (!widgetHtmlFile.open(QIODevice::WriteOnly))
{
if (!widgetHtmlFile.open(QIODevice::WriteOnly)) {
qWarning() << "cannot open file " << widgetHtmlFile.fileName();
return "";
return QString();
}
QTextStream outStartFile(&widgetHtmlFile);
......@@ -1129,7 +1069,6 @@ QString UBGraphicsW3CWidgetItem::createHtmlWrapperInDir(const QString& html, con
widgetHtmlFile.close();
return widgetPath;
}
QString UBGraphicsW3CWidgetItem::freezedWidgetPage()
......@@ -1143,13 +1082,14 @@ QString UBGraphicsW3CWidgetItem::freezedWidgetPage()
if (!wrapperFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "can't open wrapper file " + freezedWidgetDefaultContentFilePath;
defaultcontent = "";
} else {
}
else {
QByteArray arr = wrapperFile.readAll();
if (!arr.isEmpty()) {
if (!arr.isEmpty())
defaultcontent = QString(arr);
} else {
else {
qDebug() << "content of " + freezedWidgetDefaultContentFilePath + "is empty";
defaultcontent = "";
defaultcontent = QString();
}
}
}
......@@ -1157,29 +1097,42 @@ QString UBGraphicsW3CWidgetItem::freezedWidgetPage()
return defaultcontent;
}
bool UBGraphicsW3CWidgetItem::hasNPAPIWrapper(const QString& pMimeType)
{
loadNPAPIWrappersTemplates();
return sNPAPIWrapperTemplates.contains(pMimeType);
}
void UBGraphicsW3CWidgetItem::javaScriptWindowObjectCleared()
{
UBGraphicsWidgetItem::javaScriptWindowObjectCleared();
if(!mW3CWidgetAPI)
mW3CWidgetAPI = new UBW3CWidgetAPI(this);
page()->mainFrame()->addToJavaScriptWindowObject("widget", mW3CWidgetAPI);
}
void UBGraphicsW3CWidgetItem::loadNPAPIWrappersTemplates()
{
if (!sTemplateLoaded)
{
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")))
{
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)
{
if (htmlContent.length() > 0) {
QStringList tokens = fileName.split(".");
if (tokens.length() >= 4)
{
if (tokens.length() >= 4) {
QString mime = tokens.at(tokens.length() - 4 );
mime += "/" + tokens.at(tokens.length() - 3);
......@@ -1191,14 +1144,11 @@ void UBGraphicsW3CWidgetItem::loadNPAPIWrappersTemplates()
}
}
}
sNPAPIWrappperConfigTemplate = UBFileSystemUtils::readTextFile(etcPath + "npapi-wrapper.config.xml");
sTemplateLoaded = true;
}
}
QString UBGraphicsW3CWidgetItem::textForSubElementByLocale(QDomElement rootElement, QString subTagName, QLocale locale)
{
QDomNodeList subList = rootElement.elementsByTagName(subTagName);
......@@ -1208,10 +1158,8 @@ QString UBGraphicsW3CWidgetItem::textForSubElementByLocale(QDomElement rootEleme
if (lang.length() > 2)
lang[2] = QLatin1Char('-');
if (subList.count() > 1)
{
for(int i = 0; i < subList.count(); i++)
{
if (subList.count() > 1) {
for(int i = 0; i < subList.count(); i++) {
QDomNode node = subList.at(i);
QDomElement element = node.toElement();
......@@ -1222,11 +1170,10 @@ QString UBGraphicsW3CWidgetItem::textForSubElementByLocale(QDomElement rootEleme
}
}
if (subList.count() >= 1)
{
if (subList.count() >= 1) {
QDomElement element = subList.item(0).toElement();
return element.text();
}
return "";
return QString();
}
......@@ -19,10 +19,10 @@
#include <QtWebKit>
#include <QDomElement>
#include "core/UB.h"
#include "UBGraphicsWebView.h"
#include "core/UB.h"
class UBWidgetUniboardAPI;
class UBGraphicsScene;
class UBW3CWidgetAPI;
......@@ -46,143 +46,72 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView
UBGraphicsWidgetItem(QGraphicsItem *parent = 0, int widgetType = 0);
~UBGraphicsWidgetItem();
virtual UBGraphicsScene* scene();
virtual void initialize();
virtual UBItem* deepCopy() const = 0;
QUrl mainHtml();
void loadMainHtml();
QUrl widgetUrl();
QString mainHtmlFileName();
bool hasEmbededObjects();
bool hasEmbededFlash();
bool canBeContent();
bool canBeTool();
/* preferences */
void setPreference(const QString& key, QString value);
QString preference(const QString& key) const;
void setPreference(const QString& key, QString value);
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;
void setDatastoreEntry(const QString& key, QString value);
QMap<QString, QString> datastoreEntries() const;
void removeDatastoreEntry(const QString& key);
void removeAllDatastoreEntries();
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate; }
virtual UBGraphicsItemDelegate* Delegate() const;
virtual void remove();
void removeScript();
QString downloadUrl(const QString &fileUrl, const QString &extention);
QString downloadWeb(const QString &fileUrl);
void processDropEvent(QDropEvent *event);
bool isDropableData(const QMimeData *data) const;
virtual void setOwnFolder(const QUrl &newFolder) {ownFolder = newFolder;}
virtual QUrl getOwnFolder() const {return ownFolder;}
virtual void setSnapshotPath(const QUrl &newFilePath){SnapshotFile = newFilePath;}
virtual QUrl getSnapshotPath(){return SnapshotFile;}
virtual QUrl getOwnFolder() const;
virtual void setOwnFolder(const QUrl &newFolder);
virtual void setSnapshotPath(const QUrl &newFilePath);
virtual QUrl getSnapshotPath();
virtual void clearSource();
virtual void setUuid(const QUuid &pUuid);
/* from UBAbstractWidget */
void loadMainHtml();
QUrl mainHtml()
{
return mMainHtmlUrl;
}
QUrl widgetUrl()
{
return mWidgetUrl;
}
virtual void setUuid(const QUuid &pUuid);
QString mainHtmlFileName()
{
return mMainHtmlFileName;
}
QSize nominalSize() const;
bool hasEmbededObjects();
bool hasEmbededFlash();
bool hasLoadedSuccessfully() const;
QSize nominalSize() const
{
return mNominalSize;
}
bool freezable();
bool resizable();
bool isFrozen();
bool canBeContent();
bool canBeTool();
bool hasLoadedSuccessfully() const
{
return (mInitialLoadDone && !mLoadIsErronous);
}
bool freezable()
{
return mIsFreezable;
}
QPixmap snapshot();
void setSnapshot(const QPixmap& pix);
QPixmap takeSnapshot();
bool resizable()
{
return mIsResizable;
}
virtual UBItem* deepCopy() const = 0;
virtual UBGraphicsScene* scene();
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();
static QString widgetName(const QUrl& pUrl);
static QString iconFilePath(const QUrl& pUrl);
public slots:
void freeze();
void unFreeze();
/* end from */
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);
virtual void sendJSEnterEvent();
virtual void sendJSLeaveEvent();
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
......@@ -192,33 +121,49 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView
type_ALL = 7, // 0111
};
virtual void injectInlineJavaScript();
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
bool mFirstReleaseAfterMove;
bool mInitialLoadDone;
bool mIsFreezable;
bool mIsResizable;
bool mLoadIsErronous;
bool mMouseIsPressed;
int mCanBeContent;
int mCanBeTool;
QSize mNominalSize;
QString mMainHtmlFileName;
QUrl mMainHtmlUrl;
QUrl mWidgetUrl;
QMap<QString, QString> mDatastore;
QMap<QString, QString> mPreferences;
//virtual void dropEvent(QDropEvent *);
/* end from */
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);
virtual void sendJSEnterEvent();
virtual void sendJSLeaveEvent();
virtual void injectInlineJavaScript();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
protected slots:
void geometryChangeRequested(const QRect& geom);
virtual void javaScriptWindowObjectCleared();
/* from UBAbstractWidget*/
void mainFrameLoadFinished(bool ok);
/* end from */
private:
QPointF mLastMousePos;
bool mIsFrozen;
bool mIsTakingSnapshot;
bool mShouldMoveWidget;
UBWidgetUniboardAPI* mUniboardAPI;
QPixmap mSnapshot;
QPointF mLastMousePos;
QUrl ownFolder;
QUrl SnapshotFile;
/* from UBAbstractWidget*/
static QStringList sInlineJavaScripts;
static bool sInlineJavaScriptLoaded;
bool mIsFrozen;
QPixmap mSnapshot;
bool mIsTakingSnapshot;
/* end from */
static QStringList sInlineJavaScripts;
};
class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
......@@ -229,15 +174,14 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsAppleWidgetItem();
enum { Type = UBGraphicsItemType::AppleWidgetItemType };
virtual int type() const;
virtual void setUuid(const QUuid &pUuid);
virtual UBItem* deepCopy() const;
virtual int type() const
enum
{
return Type;
}
virtual UBItem* deepCopy() const;
virtual void setUuid(const QUuid &pUuid);
Type = UBGraphicsItemType::AppleWidgetItemType
};
};
......@@ -246,43 +190,13 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
Q_OBJECT
public:
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsW3CWidgetItem();
enum { Type = UBGraphicsItemType::W3CWidgetItemType };
virtual int type() const
{
return Type;
}
virtual UBItem* deepCopy() 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 PreferenceValue
{
public:
PreferenceValue()
{
// NOOP
/* NOOP */
}
......@@ -292,8 +206,8 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
readonly = pReadonly;
}
QString value;
bool readonly;
QString value;
};
class Metadata
......@@ -308,39 +222,44 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
QString version;
};
QMap<QString, PreferenceValue> preferences()
enum
{
return mPreferences;
}
Type = UBGraphicsItemType::W3CWidgetItemType
};
Metadata metadatas() const
{
return mMetadatas;
}
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsW3CWidgetItem();
virtual int type() const;
virtual void setUuid(const QUuid &pUuid);
virtual UBItem* deepCopy() const;
virtual void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget );
QMap<QString, PreferenceValue> preferences();
Metadata metadatas() const;
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);
Metadata mMetadatas;
private slots:
virtual void javaScriptWindowObjectCleared();
private:
QMap<QString, PreferenceValue> mPreferences;
static void loadNPAPIWrappersTemplates();
static QString textForSubElementByLocale(QDomElement rootElement, QString subTagName, QLocale locale);
UBW3CWidgetAPI* mW3CWidgetAPI;
QMap<QString, PreferenceValue> mPreferences;
static bool sTemplateLoaded;
static QMap<QString, QString> sNPAPIWrapperTemplates;
static QString sNPAPIWrappperConfigTemplate;
static void loadNPAPIWrappersTemplates();
static QString textForSubElementByLocale(QDomElement rootElement, QString subTagName, QLocale locale);
static QMap<QString, QString> sNPAPIWrapperTemplates;
};
#endif // UBGRAPHICSWIDGETITEM_H
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