commit
96d942c8cc
Binary file not shown.
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 6.7 KiB |
@ -0,0 +1,86 @@ |
||||
#include <QDomDocument> |
||||
|
||||
#include "core/UBApplication.h" |
||||
|
||||
#include "UBLibWebView.h" |
||||
|
||||
UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent) |
||||
, mpView(NULL) |
||||
, mpWebSettings(NULL) |
||||
, mpLayout(NULL) |
||||
{ |
||||
setObjectName(name); |
||||
|
||||
setAttribute(Qt::WA_StyledBackground, true); |
||||
setStyleSheet(UBApplication::globalStyleSheet()); |
||||
|
||||
mpLayout = new QVBoxLayout(); |
||||
setLayout(mpLayout); |
||||
|
||||
mpView = new QWebView(this); |
||||
mpView->setObjectName("SearchEngineView"); |
||||
//mpView->setStyleSheet(QString("background-color:white;"));
|
||||
|
||||
mpWebSettings = QWebSettings::globalSettings(); |
||||
mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::PluginsEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); |
||||
mpWebSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, true); |
||||
|
||||
mpLayout->addWidget(mpView); |
||||
} |
||||
|
||||
UBLibWebView::~UBLibWebView() |
||||
{ |
||||
if(NULL != mpView) |
||||
{ |
||||
delete mpView; |
||||
mpView = NULL; |
||||
} |
||||
if(NULL != mpLayout) |
||||
{ |
||||
delete mpLayout; |
||||
mpLayout = NULL; |
||||
} |
||||
} |
||||
|
||||
void UBLibWebView::setElement(UBLibElement *elem) |
||||
{ |
||||
if(NULL != elem) |
||||
{ |
||||
QString qsWidgetName; |
||||
QString path = elem->path().toLocalFile(); |
||||
|
||||
QString qsConfigPath = QString("%0/config.xml").arg(path); |
||||
|
||||
if(QFile::exists(qsConfigPath)) |
||||
{ |
||||
QFile f(qsConfigPath); |
||||
if(f.open(QIODevice::ReadOnly)) |
||||
{ |
||||
QDomDocument domDoc; |
||||
domDoc.setContent(QString(f.readAll())); |
||||
QDomElement root = domDoc.documentElement(); |
||||
|
||||
QDomNode node = root.firstChild(); |
||||
while(!node.isNull()) |
||||
{ |
||||
if(node.toElement().tagName() == "content") |
||||
{ |
||||
QDomAttr srcAttr = node.toElement().attributeNode("src"); |
||||
qsWidgetName = srcAttr.value(); |
||||
break; |
||||
} |
||||
node = node.nextSibling(); |
||||
} |
||||
f.close(); |
||||
} |
||||
} |
||||
|
||||
mpView->load(QUrl::fromLocalFile(QString("%0/%1").arg(path).arg(qsWidgetName))); |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
#ifndef UBLIBWEBVIEW_H |
||||
#define UBLIBWEBVIEW_H |
||||
|
||||
#include <QWidget> |
||||
#include <QWebView> |
||||
#include <QWebSettings> |
||||
#include <QVBoxLayout> |
||||
|
||||
#include "board/UBLibraryController.h" |
||||
|
||||
class UBLibWebView : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBLibWebView(QWidget* parent = 0, const char* name = "UBLibWebView"); |
||||
~UBLibWebView(); |
||||
|
||||
void setElement(UBLibElement* elem); |
||||
|
||||
private: |
||||
QWebView* mpView; |
||||
QWebSettings* mpWebSettings; |
||||
QVBoxLayout* mpLayout; |
||||
}; |
||||
|
||||
#endif // UBLIBWEBVIEW_H
|
Loading…
Reference in new issue