Commit f3a449f5 authored by Yimgo's avatar Yimgo

Cosmetics in UBGrahicsWebView and UBGraphicsWidgetItem classes.

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