Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
e6be59ce
Commit
e6be59ce
authored
Aug 10, 2012
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Plain Diff
MAC warnings fix
parents
312505e5
aba21c9e
Changes
42
Show whitespace changes
Inline
Side-by-side
Showing
42 changed files
with
1598 additions
and
2189 deletions
+1598
-2189
UBCFFSubsetAdaptor.cpp
src/adaptors/UBCFFSubsetAdaptor.cpp
+2
-2
UBSvgSubsetAdaptor.cpp
src/adaptors/UBSvgSubsetAdaptor.cpp
+8
-9
UBDocumentPublisher.cpp
src/adaptors/publishing/UBDocumentPublisher.cpp
+19
-19
UBW3CWidgetAPI.cpp
src/api/UBW3CWidgetAPI.cpp
+43
-86
UBW3CWidgetAPI.h
src/api/UBW3CWidgetAPI.h
+4
-8
UBWidgetMessageAPI.cpp
src/api/UBWidgetMessageAPI.cpp
+7
-10
UBWidgetMessageAPI.h
src/api/UBWidgetMessageAPI.h
+2
-2
UBWidgetUniboardAPI.cpp
src/api/UBWidgetUniboardAPI.cpp
+6
-7
UBBoardController.cpp
src/board/UBBoardController.cpp
+16
-106
UBBoardController.h
src/board/UBBoardController.h
+0
-6
UBBoardPaletteManager.cpp
src/board/UBBoardPaletteManager.cpp
+0
-1
UBBoardPaletteManager.h
src/board/UBBoardPaletteManager.h
+1
-2
UBBoardView.cpp
src/board/UBBoardView.cpp
+1
-3
UBBoardView.h
src/board/UBBoardView.h
+0
-1
UBFeaturesController.cpp
src/board/UBFeaturesController.cpp
+3
-3
UBLibraryController.cpp
src/board/UBLibraryController.cpp
+2
-3
UBApplicationController.cpp
src/core/UBApplicationController.cpp
+3
-2
UBAbstractWidget.cpp
src/domain/UBAbstractWidget.cpp
+0
-476
UBAbstractWidget.h
src/domain/UBAbstractWidget.h
+0
-155
UBAppleWidget.cpp
src/domain/UBAppleWidget.cpp
+0
-77
UBGraphicsItemDelegate.cpp
src/domain/UBGraphicsItemDelegate.cpp
+15
-3
UBGraphicsMediaItem.cpp
src/domain/UBGraphicsMediaItem.cpp
+2
-2
UBGraphicsMediaItem.h
src/domain/UBGraphicsMediaItem.h
+2
-2
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+7
-6
UBGraphicsScene.h
src/domain/UBGraphicsScene.h
+4
-2
UBGraphicsWebView.cpp
src/domain/UBGraphicsWebView.cpp
+160
-0
UBGraphicsWebView.h
src/domain/UBGraphicsWebView.h
+62
-0
UBGraphicsWidgetItem.cpp
src/domain/UBGraphicsWidgetItem.cpp
+936
-202
UBGraphicsWidgetItem.h
src/domain/UBGraphicsWidgetItem.h
+151
-64
UBGraphicsWidgetItemDelegate.cpp
src/domain/UBGraphicsWidgetItemDelegate.cpp
+4
-4
UBW3CWidget.cpp
src/domain/UBW3CWidget.cpp
+0
-525
UBW3CWidget.h
src/domain/UBW3CWidget.h
+0
-126
domain.pri
src/domain/domain.pri
+16
-20
UBCoreGraphicsScene.cpp
src/frameworks/UBCoreGraphicsScene.cpp
+3
-1
UBFavoriteToolPalette.cpp
src/gui/UBFavoriteToolPalette.cpp
+3
-4
UBFeaturesWidget.cpp
src/gui/UBFeaturesWidget.cpp
+0
-1
UBTeacherGuideWidgetsTools.cpp
src/gui/UBTeacherGuideWidgetsTools.cpp
+5
-3
UBToolWidget.cpp
src/gui/UBToolWidget.cpp
+90
-85
UBToolWidget.h
src/gui/UBToolWidget.h
+21
-14
UBRoutedMouseEventWebView.cpp
src/web/UBRoutedMouseEventWebView.cpp
+0
-100
UBRoutedMouseEventWebView.h
src/web/UBRoutedMouseEventWebView.h
+0
-45
web.pri
src/web/web.pri
+0
-2
No files found.
src/adaptors/UBCFFSubsetAdaptor.cpp
View file @
e6be59ce
...
...
@@ -31,7 +31,7 @@
#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsTextItemDelegate.h"
#include "domain/UB
W3CWidget
.h"
#include "domain/UB
GraphicsWidgetItem
.h"
#include "frameworks/UBFileSystemUtils.h"
...
...
@@ -776,7 +776,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &ele
return
false
;
}
QString
flashUrl
=
UB
W3CWidget
::
createNPAPIWrapperInDir
(
flashPath
,
tmpFlashDir
,
"application/x-shockwave-flash"
QString
flashUrl
=
UB
GraphicsW3CWidgetItem
::
createNPAPIWrapperInDir
(
flashPath
,
tmpFlashDir
,
"application/x-shockwave-flash"
,
QSize
(
mCurrentSceneRect
.
width
(),
mCurrentSceneRect
.
height
()));
UBGraphicsWidgetItem
*
flashItem
=
mCurrentScene
->
addW3CWidget
(
QUrl
::
fromLocalFile
(
flashUrl
));
flashItem
->
setSourceUrl
(
urlPath
);
...
...
src/adaptors/UBSvgSubsetAdaptor.cpp
View file @
e6be59ce
...
...
@@ -27,7 +27,6 @@
#include "domain/UBGraphicsPDFItem.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsTextItemDelegate.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsStroke.h"
#include "domain/UBGraphicsStrokesGroup.h"
#include "domain/UBGraphicsGroupContainerItem.h"
...
...
@@ -2488,7 +2487,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsW3CWidgetToSvg(UBGraphicsW3C
void
UBSvgSubsetAdaptor
::
UBSvgSubsetWriter
::
graphicsWidgetToSvg
(
UBGraphicsWidgetItem
*
item
)
{
QUrl
widgetRootUrl
=
item
->
widget
WebView
()
->
widget
Url
();
QUrl
widgetRootUrl
=
item
->
widgetUrl
();
QString
uuid
=
UBStringUtils
::
toCanonicalUuid
(
item
->
uuid
());
QString
widgetDirectoryPath
=
UBPersistenceManager
::
widgetDirectory
;
if
(
widgetRootUrl
.
toString
().
startsWith
(
"file://"
))
...
...
@@ -2517,13 +2516,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsWidgetToSvg(UBGraphicsWidget
graphicsItemToSvg
(
item
);
if
(
item
->
widgetWebView
()
->
isFrozen
())
if
(
item
->
isFrozen
())
{
mXmlWriter
.
writeAttribute
(
UBSettings
::
uniboardDocumentNamespaceUri
,
"frozen"
,
xmlTrue
);
}
QString
snapshotPath
=
mDocumentPath
+
"/"
+
UBPersistenceManager
::
widgetDirectory
+
"/"
+
uuid
+
".png"
;
item
->
widgetWebView
()
->
takeSnapshot
().
save
(
snapshotPath
,
"PNG"
);
item
->
takeSnapshot
().
save
(
snapshotPath
,
"PNG"
);
mXmlWriter
.
writeStartElement
(
nsXHtml
,
"iframe"
);
...
...
@@ -2532,10 +2531,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::graphicsWidgetToSvg(UBGraphicsWidget
mXmlWriter
.
writeAttribute
(
"height"
,
QString
(
"%1"
).
arg
(
item
->
boundingRect
().
height
()));
QString
startFileUrl
;
if
(
item
->
widgetWebView
()
->
mainHtmlFileName
().
startsWith
(
"http://"
))
startFileUrl
=
item
->
widgetWebView
()
->
mainHtmlFileName
();
if
(
item
->
mainHtmlFileName
().
startsWith
(
"http://"
))
startFileUrl
=
item
->
mainHtmlFileName
();
else
startFileUrl
=
widgetRootUrl
.
toString
()
+
"/"
+
item
->
widgetWebView
()
->
mainHtmlFileName
();
startFileUrl
=
widgetRootUrl
.
toString
()
+
"/"
+
item
->
mainHtmlFileName
();
mXmlWriter
.
writeAttribute
(
"src"
,
startFileUrl
);
mXmlWriter
.
writeEndElement
();
//iFrame
...
...
@@ -2626,13 +2625,13 @@ UBGraphicsW3CWidgetItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsW3CWidge
QPixmap
snapshot
(
pixPath
);
if
(
!
snapshot
.
isNull
())
widgetItem
->
w3cWidget
()
->
setSnapshot
(
snapshot
);
widgetItem
->
setSnapshot
(
snapshot
);
QStringRef
frozen
=
mXmlReader
.
attributes
().
value
(
mNamespaceUri
,
"frozen"
);
if
(
!
frozen
.
isNull
()
&&
frozen
.
toString
()
==
xmlTrue
&&
!
snapshot
.
isNull
())
{
widgetItem
->
w3cWidget
()
->
freeze
();
widgetItem
->
freeze
();
}
graphicsItemFromSvg
(
widgetItem
);
...
...
src/adaptors/publishing/UBDocumentPublisher.cpp
View file @
e6be59ce
...
...
@@ -281,12 +281,12 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
jsonFile
.
write
(
QString
(
"
\"
uuid
\"
:
\"
%1
\"
,
\n
"
).
arg
(
UBStringUtils
::
toCanonicalUuid
(
widget
->
uuid
())).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
id
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
id
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
name
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
w3cWidget
()
->
metadatas
().
name
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
description
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
w3cWidget
()
->
metadatas
().
description
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
author
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
w3cWidget
()
->
metadatas
().
author
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
authorEmail
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
w3cWidget
()
->
metadatas
().
authorEmail
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
authorHref
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
w3cWidget
()
->
metadatas
().
authorHref
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
version
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
w3cWidget
()
->
metadatas
().
authorHref
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
name
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
name
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
description
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
description
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
author
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
author
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
authorEmail
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
authorEmail
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
authorHref
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
authorHref
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
version
\"
:
\"
%1
\"
,
\n
"
).
arg
(
widget
->
metadatas
().
authorHref
).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
x
\"
: %1,
\n
"
).
arg
(
widget
->
sceneBoundingRect
().
x
()).
toUtf8
());
jsonFile
.
write
(
QString
(
"
\"
y
\"
: %1,
\n
"
).
arg
(
widget
->
sceneBoundingRect
().
y
()).
toUtf8
());
...
...
@@ -298,10 +298,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
QString
url
=
UBPersistenceManager
::
widgetDirectory
+
"/"
+
widget
->
uuid
().
toString
()
+
".wgt"
;
jsonFile
.
write
(
QString
(
"
\"
src
\"
:
\"
%1
\"
,
\n
"
).
arg
(
url
).
toUtf8
());
QString
startFile
=
widget
->
w3cWidget
()
->
mainHtmlFileName
();
QString
startFile
=
widget
->
mainHtmlFileName
();
jsonFile
.
write
(
QString
(
"
\"
startFile
\"
:
\"
%1
\"
,
\n
"
).
arg
(
startFile
).
toUtf8
());
QMap
<
QString
,
QString
>
preferences
=
widget
->
preferences
();
QMap
<
QString
,
QString
>
preferences
=
widget
->
UBGraphicsWidgetItem
::
preferences
();
jsonFile
.
write
(
QString
(
"
\"
preferences
\"
: {
\n
"
).
toUtf8
());
...
...
@@ -360,10 +360,10 @@ void UBDocumentPublisher::upgradeDocumentForPublishing()
void
UBDocumentPublisher
::
generateWidgetPropertyScript
(
UBGraphicsW3CWidgetItem
*
widgetItem
,
int
pageNumber
)
{
QMap
<
QString
,
QString
>
preferences
=
widgetItem
->
preferences
();
QMap
<
QString
,
QString
>
preferences
=
widgetItem
->
UBGraphicsWidgetItem
::
preferences
();
QMap
<
QString
,
QString
>
datastoreEntries
=
widgetItem
->
datastoreEntries
();
QString
startFileName
=
widgetItem
->
w3cWidget
()
->
mainHtmlFileName
();
QString
startFileName
=
widgetItem
->
mainHtmlFileName
();
if
(
!
startFileName
.
startsWith
(
"http://"
))
{
...
...
@@ -394,18 +394,18 @@ void UBDocumentPublisher::generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *
lines
<<
" <script type=
\"
text/javascript
\"
>"
;
lines
<<
" var widget = {};"
;
lines
<<
" widget.id = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
id
+
"';"
;
lines
<<
" widget.name = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
name
+
"';"
;
lines
<<
" widget.description = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
description
+
"';"
;
lines
<<
" widget.author = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
author
+
"';"
;
lines
<<
" widget.authorEmail = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
authorEmail
+
"';"
;
lines
<<
" widget.authorHref = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
authorHref
+
"';"
;
lines
<<
" widget.version = '"
+
widgetItem
->
w3cWidget
()
->
metadatas
().
version
+
"';"
;
lines
<<
" widget.id = '"
+
widgetItem
->
metadatas
().
id
+
"';"
;
lines
<<
" widget.name = '"
+
widgetItem
->
metadatas
().
name
+
"';"
;
lines
<<
" widget.description = '"
+
widgetItem
->
metadatas
().
description
+
"';"
;
lines
<<
" widget.author = '"
+
widgetItem
->
metadatas
().
author
+
"';"
;
lines
<<
" widget.authorEmail = '"
+
widgetItem
->
metadatas
().
authorEmail
+
"';"
;
lines
<<
" widget.authorHref = '"
+
widgetItem
->
metadatas
().
authorHref
+
"';"
;
lines
<<
" widget.version = '"
+
widgetItem
->
metadatas
().
version
+
"';"
;
lines
<<
" widget.uuid = '"
+
UBStringUtils
::
toCanonicalUuid
(
widgetItem
->
uuid
())
+
"';"
;
lines
<<
" widget.width = "
+
QString
(
"%1"
).
arg
(
widgetItem
->
w3cWidget
()
->
width
())
+
";"
;
lines
<<
" widget.height = "
+
QString
(
"%1"
).
arg
(
widgetItem
->
w3cWidget
()
->
height
())
+
";"
;
lines
<<
" widget.width = "
+
QString
(
"%1"
).
arg
(
widgetItem
->
nominalSize
().
width
())
+
";"
;
lines
<<
" widget.height = "
+
QString
(
"%1"
).
arg
(
widgetItem
->
nominalSize
().
height
())
+
";"
;
lines
<<
" widget.openUrl = function(url) { window.open(url); }"
;
lines
<<
" widget.preferences = new Array()"
;
...
...
src/api/UBW3CWidgetAPI.cpp
View file @
e6be59ce
...
...
@@ -30,25 +30,14 @@
#include "core/memcheck.h"
UBW3CWidgetAPI
::
UBW3CWidgetAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
)
:
QObject
(
graphicsWidge
t
)
UBW3CWidgetAPI
::
UBW3CWidgetAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
,
QObject
*
parent
)
:
QObject
(
paren
t
)
,
mGraphicsW3CWidget
(
graphicsWidget
)
,
mW3CWidget
(
mGraphicsW3CWidget
->
w3cWidget
())
{
mPreferencesAPI
=
new
UBW3CWidgetPreferenceAPI
(
graphicsWidget
);
mPreferencesAPI
=
new
UBW3CWidgetPreferenceAPI
(
graphicsWidget
,
parent
);
}
UBW3CWidgetAPI
::
UBW3CWidgetAPI
(
UBW3CWidget
*
widget
)
:
QObject
(
widget
)
,
mGraphicsW3CWidget
(
0
)
,
mW3CWidget
(
widget
)
{
mPreferencesAPI
=
new
UBW3CWidgetPreferenceAPI
(
widget
);
}
UBW3CWidgetAPI
::~
UBW3CWidgetAPI
()
{
// NOOP
...
...
@@ -66,55 +55,55 @@ QString UBW3CWidgetAPI::uuid()
int
UBW3CWidgetAPI
::
width
()
{
return
m
W3CWidget
->
geometry
().
width
();
return
m
GraphicsW3CWidget
->
nominalSize
().
width
();
}
int
UBW3CWidgetAPI
::
height
()
{
return
m
W3CWidget
->
geometry
().
height
();
return
m
GraphicsW3CWidget
->
nominalSize
().
height
();
}
QString
UBW3CWidgetAPI
::
id
()
{
return
mW3CWidget
->
metadatas
().
id
;
return
m
Graphics
W3CWidget
->
metadatas
().
id
;
}
QString
UBW3CWidgetAPI
::
name
()
{
return
mW3CWidget
->
metadatas
().
name
;
return
m
Graphics
W3CWidget
->
metadatas
().
name
;
}
QString
UBW3CWidgetAPI
::
description
()
{
return
mW3CWidget
->
metadatas
().
description
;
return
m
Graphics
W3CWidget
->
metadatas
().
description
;
}
QString
UBW3CWidgetAPI
::
author
()
{
return
mW3CWidget
->
metadatas
().
author
;
return
m
Graphics
W3CWidget
->
metadatas
().
author
;
}
QString
UBW3CWidgetAPI
::
authorEmail
()
{
return
mW3CWidget
->
metadatas
().
authorEmail
;
return
m
Graphics
W3CWidget
->
metadatas
().
authorEmail
;
}
QString
UBW3CWidgetAPI
::
authorHref
()
{
return
mW3CWidget
->
metadatas
().
authorHref
;
return
m
Graphics
W3CWidget
->
metadatas
().
authorHref
;
}
QString
UBW3CWidgetAPI
::
version
()
{
return
mW3CWidget
->
metadatas
().
version
;
return
m
Graphics
W3CWidget
->
metadatas
().
version
;
}
QObject
*
UBW3CWidgetAPI
::
preferences
()
...
...
@@ -129,24 +118,13 @@ void UBW3CWidgetAPI::openURL(const QString& url)
}
UBW3CWidgetPreferenceAPI
::
UBW3CWidgetPreferenceAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
)
:
UBW3CWebStorage
(
graphicsWidge
t
)
UBW3CWidgetPreferenceAPI
::
UBW3CWidgetPreferenceAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
,
QObject
*
parent
)
:
UBW3CWebStorage
(
paren
t
)
,
mGraphicsW3CWidget
(
graphicsWidget
)
,
mW3CWidget
(
graphicsWidget
->
w3cWidget
())
{
// NOOP
}
UBW3CWidgetPreferenceAPI
::
UBW3CWidgetPreferenceAPI
(
UBW3CWidget
*
widget
)
:
UBW3CWebStorage
(
widget
)
,
mGraphicsW3CWidget
(
0
)
,
mW3CWidget
(
widget
)
{
// NOOP
}
UBW3CWidgetPreferenceAPI
::~
UBW3CWidgetPreferenceAPI
()
{
// NOOP
...
...
@@ -155,45 +133,35 @@ UBW3CWidgetPreferenceAPI::~UBW3CWidgetPreferenceAPI()
QString
UBW3CWidgetPreferenceAPI
::
key
(
int
index
)
{
QMap
<
QString
,
UBW3CWidget
::
PreferenceValue
>
w3CPrefs
=
m
W3CWidget
->
preferences
();
QMap
<
QString
,
UBGraphicsW3CWidgetItem
::
PreferenceValue
>
w3CPrefs
=
mGraphics
W3CWidget
->
preferences
();
if
(
index
<
w3CPrefs
.
size
())
return
w3CPrefs
.
keys
().
at
(
index
);
else
return
""
;
}
QString
UBW3CWidgetPreferenceAPI
::
getItem
(
const
QString
&
key
)
{
if
(
mGraphicsW3CWidget
)
{
QMap
<
QString
,
QString
>
docPref
=
mGraphicsW3CWidget
->
preferences
();
if
(
mGraphicsW3CWidget
)
{
QMap
<
QString
,
QString
>
docPref
=
mGraphicsW3CWidget
->
UBGraphicsWidgetItem
::
preferences
();
if
(
docPref
.
contains
(
key
))
return
docPref
.
value
(
key
);
}
QMap
<
QString
,
UBW3CWidget
::
PreferenceValue
>
w3cPrefs
=
mW3CWidget
->
preferences
();
if
(
w3cPrefs
.
contains
(
key
))
{
UBW3CWidget
::
PreferenceValue
pref
=
w3cPrefs
.
value
(
key
);
QMap
<
QString
,
UBGraphicsW3CWidgetItem
::
PreferenceValue
>
w3cPrefs
=
mGraphicsW3CWidget
->
preferences
();
if
(
w3cPrefs
.
contains
(
key
))
{
UBGraphicsW3CWidgetItem
::
PreferenceValue
pref
=
w3cPrefs
.
value
(
key
);
return
pref
.
value
;
}
else
{
return
""
;
}
return
QString
();
}
int
UBW3CWidgetPreferenceAPI
::
length
()
{
QMap
<
QString
,
UB
W3CWidget
::
PreferenceValue
>
w3cPrefs
=
m
W3CWidget
->
preferences
();
QMap
<
QString
,
UB
GraphicsW3CWidgetItem
::
PreferenceValue
>
w3cPrefs
=
mGraphics
W3CWidget
->
preferences
();
return
w3cPrefs
.
size
();
}
...
...
@@ -201,28 +169,21 @@ int UBW3CWidgetPreferenceAPI::length()
void
UBW3CWidgetPreferenceAPI
::
setItem
(
const
QString
&
key
,
const
QString
&
value
)
{
if
(
mGraphicsW3CWidget
)
{
QMap
<
QString
,
UBW3CWidget
::
PreferenceValue
>
w3cPrefs
=
mW3CWidget
->
preferences
();
if
(
mGraphicsW3CWidget
)
{
QMap
<
QString
,
UBGraphicsW3CWidgetItem
::
PreferenceValue
>
w3cPrefs
=
mGraphicsW3CWidget
->
preferences
();
if
(
w3cPrefs
.
contains
(
key
)
&&
!
w3cPrefs
.
value
(
key
).
readonly
)
mGraphicsW3CWidget
->
setPreference
(
key
,
value
);
}
else
{
// No state for non graphics widget (aka tool widget)
}
}
void
UBW3CWidgetPreferenceAPI
::
removeItem
(
const
QString
&
key
)
{
if
(
mGraphicsW3CWidget
)
mGraphicsW3CWidget
->
removePreference
(
key
);
else
{
// No state for non graphics widget (aka tool widget)
}
}
...
...
@@ -230,10 +191,6 @@ void UBW3CWidgetPreferenceAPI::clear()
{
if
(
mGraphicsW3CWidget
)
mGraphicsW3CWidget
->
removeAllPreferences
();
else
{
// No state for non graphics widget (aka tool widget)
}
}
...
...
src/api/UBW3CWidgetAPI.h
View file @
e6be59ce
...
...
@@ -47,8 +47,7 @@ class UBW3CWidgetAPI : public QObject
public
:
UBW3CWidgetAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
);
UBW3CWidgetAPI
(
UBW3CWidget
*
widget
);
UBW3CWidgetAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
,
QObject
*
parent
=
0
);
virtual
~
UBW3CWidgetAPI
();
...
...
@@ -72,7 +71,6 @@ class UBW3CWidgetAPI : public QObject
private
:
UBGraphicsW3CWidgetItem
*
mGraphicsW3CWidget
;
UBW3CWidget
*
mW3CWidget
;
UBW3CWidgetPreferenceAPI
*
mPreferencesAPI
;
...
...
@@ -88,8 +86,8 @@ class UBW3CWebStorage : public QObject
public
:
UBW3CWebStorage
(
QObject
*
parent
=
0
)
:
QObject
(
parent
){}
virtual
~
UBW3CWebStorage
(){}
:
QObject
(
parent
){
/* NOOP */
}
virtual
~
UBW3CWebStorage
(){
/* NOOP */
}
public
slots
:
...
...
@@ -110,8 +108,7 @@ class UBW3CWidgetPreferenceAPI : public UBW3CWebStorage
Q_OBJECT
;
public
:
UBW3CWidgetPreferenceAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
);
UBW3CWidgetPreferenceAPI
(
UBW3CWidget
*
widget
);
UBW3CWidgetPreferenceAPI
(
UBGraphicsW3CWidgetItem
*
graphicsWidget
,
QObject
*
parent
=
0
);
virtual
~
UBW3CWidgetPreferenceAPI
();
...
...
@@ -129,7 +126,6 @@ class UBW3CWidgetPreferenceAPI : public UBW3CWebStorage
private
:
UBGraphicsW3CWidgetItem
*
mGraphicsW3CWidget
;
UBW3CWidget
*
mW3CWidget
;
};
...
...
src/api/UBWidgetMessageAPI.cpp
View file @
e6be59ce
...
...
@@ -17,16 +17,15 @@
#include "core/UBApplication.h"
#include "domain/UB
AbstractWidget
.h"
#include "domain/UB
GraphicsWebView
.h"
#include "core/memcheck.h"
UBWidgetMessageAPI
::
UBWidgetMessageAPI
(
UB
W3CWidget
*
widge
t
)
:
QObject
(
widge
t
)
,
m
WebWidget
(
widget
)
UBWidgetMessageAPI
::
UBWidgetMessageAPI
(
UB
GraphicsWidgetItem
*
graphicsWidgetItem
,
QObject
*
paren
t
)
:
QObject
(
paren
t
)
,
m
GraphicsWidgetItem
(
graphicsWidgetItem
)
{
connect
(
UBWidgetAPIMessageBroker
::
instance
(),
SIGNAL
(
newMessage
(
const
QString
&
,
const
QString
&
))
,
this
,
SLOT
(
onNewMessage
(
const
QString
&
,
const
QString
&
)),
Qt
::
QueuedConnection
);
connect
(
UBWidgetAPIMessageBroker
::
instance
(),
SIGNAL
(
newMessage
(
const
QString
&
,
const
QString
&
)),
this
,
SLOT
(
onNewMessage
(
const
QString
&
,
const
QString
&
)),
Qt
::
QueuedConnection
);
}
UBWidgetMessageAPI
::~
UBWidgetMessageAPI
()
...
...
@@ -45,9 +44,7 @@ void UBWidgetMessageAPI::onNewMessage(const QString& pTopicName, const QString&
{
if
(
mSubscribedTopics
.
contains
(
pTopicName
))
{
if
(
mWebWidget
&&
mWebWidget
->
page
()
&&
mWebWidget
->
page
()
->
mainFrame
())
if
(
mGraphicsWidgetItem
&&
mGraphicsWidgetItem
->
page
()
&&
mGraphicsWidgetItem
->
page
()
->
mainFrame
())
{
QString
js
;
...
...
@@ -55,7 +52,7 @@ void UBWidgetMessageAPI::onNewMessage(const QString& pTopicName, const QString&
js
+=
"{widget.messages.onmessage('"
;
js
+=
pMessage
+
"', '"
+
pTopicName
+
"')}"
;
m
WebWidget
->
page
()
->
m
GraphicsWidgetItem
->
page
()
->
mainFrame
()
->
evaluateJavaScript
(
js
);
}
...
...
src/api/UBWidgetMessageAPI.h
View file @
e6be59ce
...
...
@@ -25,7 +25,7 @@ class UBWidgetMessageAPI : public QObject
Q_OBJECT
;
public
:
UBWidgetMessageAPI
(
UB
W3CWidget
*
widget
);
UBWidgetMessageAPI
(
UB
GraphicsWidgetItem
*
graphicsWidgetItem
,
QObject
*
parent
=
0
);
virtual
~
UBWidgetMessageAPI
();
public
slots
:
...
...
@@ -49,7 +49,7 @@ class UBWidgetMessageAPI : public QObject
private
:
QSet
<
QString
>
mSubscribedTopics
;
UB
W3CWidget
*
mWebWidget
;
UB
GraphicsWidgetItem
*
mGraphicsWidgetItem
;
};
...
...
src/api/UBWidgetUniboardAPI.cpp
View file @
e6be59ce
...
...
@@ -30,7 +30,6 @@
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBAbstractWidget.h"
#include "adaptors/UBThumbnailAdaptor.h"
...
...
@@ -79,7 +78,7 @@ UBWidgetUniboardAPI::UBWidgetUniboardAPI(UBGraphicsScene *pScene, UBGraphicsWidg
if
(
w3CGraphicsWidget
)
{
mMessagesAPI
=
new
UBWidgetMessageAPI
(
w3CGraphicsWidget
->
w3cWidget
()
);
mMessagesAPI
=
new
UBWidgetMessageAPI
(
w3CGraphicsWidget
);
mDatastoreAPI
=
new
UBDatastoreAPI
(
w3CGraphicsWidget
);
}
...
...
@@ -547,7 +546,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event)
QDropEvent
readyEvent
(
dropPoint
,
dropActions
,
&
dropMimeData
,
dropMouseButtons
,
dropModifiers
);
//sending event to destination either it had been downloaded or not
QApplication
::
sendEvent
(
mGraphicsWidget
->
widgetWebView
()
,
&
readyEvent
);
QApplication
::
sendEvent
(
mGraphicsWidget
,
&
readyEvent
);
readyEvent
.
acceptProposedAction
();
}
...
...
@@ -602,11 +601,11 @@ void UBWidgetUniboardAPI::onDownloadFinished(bool pSuccess, sDownloadFileDesc de
//To make js interpreter accept drop event we need to generate move event first.
QDragMoveEvent
pseudoMove
(
dropPoint
,
desc
.
dropActions
,
&
dropMimeData
,
desc
.
dropMouseButtons
,
desc
.
dropModifiers
);
QApplication
::
sendEvent
(
mGraphicsWidget
->
widgetWebView
()
,
&
pseudoMove
);
QApplication
::
sendEvent
(
mGraphicsWidget
,
&
pseudoMove
);
QDropEvent
readyEvent
(
dropPoint
,
desc
.
dropActions
,
&
dropMimeData
,
desc
.
dropMouseButtons
,
desc
.
dropModifiers
);
//sending event to destination either it had been downloaded or not
QApplication
::
sendEvent
(
mGraphicsWidget
->
widgetWebView
()
,
&
readyEvent
);
QApplication
::
sendEvent
(
mGraphicsWidget
,
&
readyEvent
);
readyEvent
.
acceptProposedAction
();
}
...
...
@@ -736,9 +735,9 @@ void UBDocumentDatastoreAPI::removeItem(const QString& key)
{
mGraphicsW3CWidget
->
removeDatastoreEntry
(
key
);
}
void
void
UBDocumentDatastoreAPI
::
clear
()
UBDocumentDatastoreAPI
::
clear
()
{
mGraphicsW3CWidget
->
removeAllDatastoreEntries
();
}
...
...
src/board/UBBoardController.cpp
View file @
e6be59ce
...
...
@@ -49,7 +49,6 @@
#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsPDFItem.h"
#include "domain/UBW3CWidget.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBPageSizeUndoCommand.h"
#include "domain/UBGraphicsGroupContainerItem.h"
...
...
@@ -1151,7 +1150,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
else
size
=
mActiveScene
->
nominalSize
()
*
.8
;
QString
widgetUrl
=
UB
W3CWidget
::
createNPAPIWrapper
(
sUrl
,
mimeType
,
size
);
QString
widgetUrl
=
UB
GraphicsW3CWidgetItem
::
createNPAPIWrapper
(
sUrl
,
mimeType
,
size
);
if
(
widgetUrl
.
length
()
>
0
)
{
...
...
@@ -1274,7 +1273,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
else
size
=
mActiveScene
->
nominalSize
()
*
.8
;
QString
widgetUrl
=
UB
W3CWidget
::
createNPAPIWrapper
(
swfFile
,
"application/x-shockwave-flash"
,
size
);
QString
widgetUrl
=
UB
GraphicsW3CWidgetItem
::
createNPAPIWrapper
(
swfFile
,
"application/x-shockwave-flash"
,
size
);
if
(
widgetUrl
.
length
()
>
0
)
{
...
...
@@ -1655,52 +1654,15 @@ qreal UBBoardController::currentZoom()
return
1.0
;
}
UBToolWidget
*
UBBoardController
::
addTool
(
const
QUrl
&
toolUrl
)
{
return
addTool
(
toolUrl
,
mControlView
->
mapToScene
(
mControlView
->
rect
().
center
()));
}
UBToolWidget
*
UBBoardController
::
addTool
(
const
QUrl
&
toolUrl
,
QPointF
scenePos
)
{
UBToolWidget
*
toolWidget
=
new
UBToolWidget
(
toolUrl
,
mMainWindow
);
// Deleted in UBBoardController::removeTool
QPoint
pos
=
mControlView
->
mapToGlobal
(
mControlView
->
mapFromScene
(
scenePos
));
pos
-=
QPoint
(
toolWidget
->
width
()
/
2
,
toolWidget
->
height
()
/
2
);
toolWidget
->
move
(
pos
);
mTools
.
append
(
toolWidget
);
toolWidget
->
show
();
return
toolWidget
;
}
void
UBBoardController
::
removeTool
(
UBToolWidget
*
toolWidget
)
{
toolWidget
->
hide
();
mTools
.
removeAll
(
toolWidget
);
delete
toolWidget
;
}
void
UBBoardController
::
hide
()
{
UBApplication
::
mainWindow
->
actionLibrary
->
setChecked
(
false
);
controlViewHidden
();
}
void
UBBoardController
::
show
()
{
UBApplication
::
mainWindow
->
actionLibrary
->
setChecked
(
false
);
controlViewShown
();
}
...
...
@@ -1925,25 +1887,6 @@ void UBBoardController::grabScene(const QRectF& pSceneRect)
}
}
void
UBBoardController
::
controlViewHidden
()
{
foreach
(
UBToolWidget
*
tool
,
mTools
)
{
tool
->
hide
();
}
}
void
UBBoardController
::
controlViewShown
()
{
foreach
(
UBToolWidget
*
tool
,
mTools
)
{
tool
->
show
();
}
}
UBGraphicsMediaItem
*
UBBoardController
::
addVideo
(
const
QUrl
&
pSourceUrl
,
bool
startPlay
,
const
QPointF
&
pos
)
{
QUuid
uuid
=
QUuid
::
createUuid
();
...
...
@@ -2003,7 +1946,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP
w3cWidgetItem
->
setSnapshotPath
(
QUrl
::
fromLocalFile
(
snapshotPath
));
UBGraphicsWidgetItem
*
tmpItem
=
dynamic_cast
<
UBGraphicsWidgetItem
*>
(
w3cWidgetItem
);
if
(
tmpItem
)
tmpItem
->
widgetWebView
()
->
takeSnapshot
().
save
(
snapshotPath
,
"PNG"
);
tmpItem
->
takeSnapshot
().
save
(
snapshotPath
,
"PNG"
);
}
...
...
@@ -2208,56 +2151,23 @@ void UBBoardController::togglePodcast(bool checked)
void
UBBoardController
::
moveGraphicsWidgetToControlView
(
UBGraphicsWidgetItem
*
graphicsWidget
)
{
QPoint
controlViewPos
=
mControlView
->
mapFromScene
(
graphicsWidget
->
sceneBoundingRect
().
center
());
graphicsWidget
->
setSelected
(
false
);
UBAbstractWidget
*
aw
=
graphicsWidget
->
widgetWebView
();
graphicsWidget
->
setWidget
(
0
);
graphicsWidget
->
remove
();
UBToolWidget
*
toolWidget
=
new
UBToolWidget
(
aw
,
mControlContainer
);
UBToolWidget
*
toolWidget
=
new
UBToolWidget
(
graphicsWidget
);
mActiveScene
->
addItem
(
toolWidget
);
qreal
ssf
=
1
/
UBApplication
::
boardController
->
systemScaleFactor
();
graphicsWidget
->
scene
()
->
removeItem
(
graphicsWidget
);
// TODO UB 4.6 probably leaking the frame
toolWidget
->
centerOn
(
mControlView
->
mapTo
(
mControlContainer
,
controlViewPos
));
toolWidget
->
show
();
toolWidget
->
setScale
(
ssf
);
toolWidget
->
setPos
(
graphicsWidget
->
scenePos
());
}
void
UBBoardController
::
moveToolWidgetToScene
(
UBToolWidget
*
toolWidget
)
{
int
xIsOdd
=
toolWidget
->
width
()
%
2
;
int
yIsOdd
=
toolWidget
->
height
()
%
2
;
QPoint
mainWindowCenter
=
toolWidget
->
mapTo
(
mMainWindow
,
QPoint
(
toolWidget
->
width
(),
toolWidget
->
height
())
/
2
);
UBAbstractWidget
*
webWidget
=
toolWidget
->
webWidget
();
webWidget
->
setParent
(
0
);
UBGraphicsWidgetItem
*
graphicsWidget
=
0
;
UBW3CWidget
*
w3cWidget
=
qobject_cast
<
UBW3CWidget
*>
(
webWidget
);
if
(
w3cWidget
)
{
graphicsWidget
=
new
UBGraphicsW3CWidgetItem
(
w3cWidget
);
}
else
{
UBAppleWidget
*
appleWidget
=
qobject_cast
<
UBAppleWidget
*>
(
webWidget
);
if
(
appleWidget
)
{
graphicsWidget
=
new
UBGraphicsAppleWidgetItem
(
appleWidget
);
}
}
QPoint
controlViewCenter
=
mControlView
->
mapFrom
(
mMainWindow
,
mainWindowCenter
);
QPointF
scenePos
=
mControlView
->
mapToScene
(
controlViewCenter
)
+
QPointF
(
xIsOdd
*
0.5
,
yIsOdd
*
0.5
);
mActiveScene
->
addGraphicsWidget
(
graphicsWidget
,
scenePos
);
toolWidget
->
hide
();
toolWidget
->
deleteLater
();
UBGraphicsWidgetItem
*
graphicsWidgetItem
=
addW3cWidget
(
toolWidget
->
graphicsWidgetItem
()
->
widgetUrl
(),
QPointF
(
0
,
0
));
graphicsWidgetItem
->
setPos
(
toolWidget
->
pos
());
toolWidget
->
remove
();
graphicsWidgetItem
->
setSelected
(
true
);
}
...
...
@@ -2343,8 +2253,8 @@ void UBBoardController::freezeW3CWidget(QGraphicsItem *item, bool freeze)
return
;
if
(
freeze
)
{
item_casted
->
widgetWebView
()
->
load
(
QUrl
(
item_casted
->
w3cWidget
()
->
freezedWidgetFilePath
()));
}
else
item_casted
->
widgetWebView
()
->
loadMainHtml
();
item_casted
->
load
(
QUrl
(
UBGraphicsW3CWidgetItem
::
freezedWidgetFilePath
()));
}
else
item_casted
->
loadMainHtml
();
}
}
src/board/UBBoardController.h
View file @
e6be59ce
...
...
@@ -197,17 +197,12 @@ class UBBoardController : public UBDocumentContainer
void
hideMessage
();
void
setDisabled
(
bool
disable
);
void
setColorIndex
(
int
pColorIndex
);
UBToolWidget
*
addTool
(
const
QUrl
&
toolUrl
,
QPointF
scenePos
);
UBToolWidget
*
addTool
(
const
QUrl
&
toolUrl
);
void
removeTool
(
UBToolWidget
*
toolWidget
);
void
hide
();
void
show
();
void
setWidePageSize
(
bool
checked
);
void
setRegularPageSize
(
bool
checked
);
void
stylusToolChanged
(
int
tool
);
void
grabScene
(
const
QRectF
&
pSceneRect
);
void
controlViewHidden
();
void
controlViewShown
();
UBGraphicsMediaItem
*
addVideo
(
const
QUrl
&
pUrl
,
bool
startPlay
,
const
QPointF
&
pos
);
UBGraphicsMediaItem
*
addAudio
(
const
QUrl
&
pUrl
,
bool
startPlay
,
const
QPointF
&
pos
);
UBGraphicsWidgetItem
*
addW3cWidget
(
const
QUrl
&
pUrl
,
const
QPointF
&
pos
);
...
...
@@ -277,7 +272,6 @@ class UBBoardController : public UBDocumentContainer
QColor
mPenColorOnLightBackground
;
QColor
mMarkerColorOnDarkBackground
;
QColor
mMarkerColorOnLightBackground
;
QList
<
UBToolWidget
*>
mTools
;
qreal
mSystemScaleFactor
;
bool
mCleanupDone
;
QMap
<
QAction
*
,
QPair
<
QString
,
QString
>
>
mActionTexts
;
...
...
src/board/UBBoardPaletteManager.cpp
View file @
e6be59ce
...
...
@@ -48,7 +48,6 @@
#include "network/UBServerXMLHttpRequest.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsPixmapItem.h"
#include "document/UBDocumentProxy.h"
...
...
src/board/UBBoardPaletteManager.h
View file @
e6be59ce
...
...
@@ -19,7 +19,6 @@
#include <QtGui>
#include <QtWebKit>
#include "web/UBRoutedMouseEventWebView.h"
#include "gui/UBLeftPalette.h"
#include "gui/UBRightPalette.h"
#include "gui/UBPageNavigationWidget.h"
...
...
src/board/UBBoardView.cpp
View file @
e6be59ce
...
...
@@ -123,8 +123,6 @@ UBBoardView::init ()
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
setAcceptDrops
(
true
);
setOptimizationFlag
(
QGraphicsView
::
IndirectPainting
);
// enable UBBoardView::drawItems filter
mTabletStylusIsPressed
=
false
;
mMouseButtonIsPressed
=
false
;
mPendingStylusReleaseEvent
=
false
;
...
...
@@ -1181,7 +1179,7 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event)
}
QPoint
newPoint
(
graphicsWidget
->
mapFromScene
(
mapToScene
(
event
->
pos
())).
toPoint
());
QDragMoveEvent
newEvent
(
newPoint
,
event
->
dropAction
(),
event
->
mimeData
(),
event
->
mouseButtons
(),
event
->
keyboardModifiers
());
QApplication
::
sendEvent
(
graphicsWidget
->
widgetWebView
()
,
&
newEvent
);
QApplication
::
sendEvent
(
graphicsWidget
,
&
newEvent
);
}
else
{
mOkOnWidget
=
false
;
event
->
ignore
();
...
...
src/board/UBBoardView.h
View file @
e6be59ce
...
...
@@ -21,7 +21,6 @@
#include "domain/UBGraphicsDelegateFrame.h"
class
UBBoardController
;
class
UBAppleWidget
;
class
UBGraphicsScene
;
class
UBGraphicsWidgetItem
;
class
UBRubberBand
;
...
...
src/board/UBFeaturesController.cpp
View file @
e6be59ce
...
...
@@ -11,7 +11,6 @@
#include "frameworks/UBPlatformUtils.h"
#include "core/UBDownloadManager.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsPixmapItem.h"
...
...
@@ -24,6 +23,7 @@ const QString UBFeaturesController::virtualRootName = "root";
void
UBFeaturesComputingThread
::
scanFS
(
const
QUrl
&
currentPath
,
const
QString
&
currVirtualPath
)
{
Q_ASSERT
(
QFileInfo
(
currentPath
.
toLocalFile
()).
exists
());
QFileInfoList
fileInfoList
=
UBFileSystemUtils
::
allElementsInDirectory
(
currentPath
.
toLocalFile
());
...
...
@@ -556,7 +556,7 @@ QImage UBFeaturesController::getIcon(const QString &path, UBFeatureElementType p
return
QImage
(
":images/libpalette/folder.svg"
);
}
else
if
(
pFType
==
FEATURE_INTERACTIVE
)
{
return
QImage
(
UB
AbstractWidget
::
iconFilePath
(
QUrl
::
fromLocalFile
(
path
)));
return
QImage
(
UB
GraphicsWidgetItem
::
iconFilePath
(
QUrl
::
fromLocalFile
(
path
)));
}
...
...
@@ -564,7 +564,7 @@ QImage UBFeaturesController::getIcon(const QString &path, UBFeatureElementType p
return
QImage
(
UBToolsManager
::
manager
()
->
iconFromToolId
(
path
)
);
}
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
path
).
contains
(
"application"
))
{
return
QImage
(
UB
AbstractWidget
::
iconFilePath
(
QUrl
::
fromLocalFile
(
path
)
)
);
return
QImage
(
UB
GraphicsWidgetItem
::
iconFilePath
(
QUrl
::
fromLocalFile
(
path
)
)
);
}
QImage
thumb
;
...
...
src/board/UBLibraryController.cpp
View file @
e6be59ce
...
...
@@ -24,7 +24,6 @@
#include "core/UBApplicationController.h"
#include "core/UBDownloadManager.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsPixmapItem.h"
...
...
@@ -325,7 +324,7 @@ QImage UBLibraryController::thumbnailForFile(UBLibElement* pElement)
return
image
;
}
if
(
pElement
->
type
()
==
eUBLibElementType_InteractiveItem
){
QImage
image
=
QImage
(
UB
AbstractWidget
::
iconFilePath
(
pElement
->
path
()));
QImage
image
=
QImage
(
UB
GraphicsWidgetItem
::
iconFilePath
(
pElement
->
path
()));
return
image
;
}
...
...
@@ -780,7 +779,7 @@ UBLibElement::UBLibElement(eUBLibElementType type, const QUrl &path, const QStri
mThumbnail
=
QImage
(
":images/libpalette/folder.svg"
);
if
(
type
==
eUBLibElementType_InteractiveItem
)
mThumbnail
=
QImage
(
UB
AbstractWidget
::
iconFilePath
(
path
));
mThumbnail
=
QImage
(
UB
GraphicsWidgetItem
::
iconFilePath
(
path
));
if
(
type
==
eUBLibElementType_Item
)
mExtension
=
QFileInfo
(
path
.
toLocalFile
()).
completeSuffix
();
...
...
src/core/UBApplicationController.cpp
View file @
e6be59ce
...
...
@@ -33,6 +33,8 @@
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentController.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "desktop/UBDesktopPalette.h"
#include "desktop/UBDesktopAnnotationController.h"
...
...
@@ -44,7 +46,6 @@
#include "gui/UBTeacherGuideWidget.h"
#include "domain/UBGraphicsPixmapItem.h"
#include "domain/UBW3CWidget.h"
#include "podcast/UBPodcastController.h"
...
...
@@ -318,7 +319,7 @@ void UBApplicationController::addCapturedEmbedCode(const QString& embedCode)
int
width
=
300
;
int
height
=
150
;
QString
widgetPath
=
UB
W3CWidget
::
createHtmlWrapperInDir
(
embedCode
,
userWidgetDir
,
QString
widgetPath
=
UB
GraphicsW3CWidgetItem
::
createHtmlWrapperInDir
(
embedCode
,
userWidgetDir
,
QSize
(
width
,
height
),
UBStringUtils
::
toCanonicalUuid
(
QUuid
::
createUuid
()));
if
(
widgetPath
.
length
()
>
0
)
...
...
src/domain/UBAbstractWidget.cpp
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBAbstractWidget.h"
#include <QtNetwork>
#include <QtXml>
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplicationController.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "network/UBNetworkAccessManager.h"
#include "web/UBWebPage.h"
#include "web/UBWebKitUtils.h"
#include "web/UBWebController.h"
#include "core/memcheck.h"
QStringList
UBAbstractWidget
::
sInlineJavaScripts
;
bool
UBAbstractWidget
::
sInlineJavaScriptLoaded
=
false
;
UBAbstractWidget
::
UBAbstractWidget
(
const
QUrl
&
pWidgetUrl
,
QWidget
*
parent
)
:
UBRoutedMouseEventWebView
(
parent
)
,
mWidgetUrl
(
pWidgetUrl
)
,
mIsResizable
(
false
)
,
mInitialLoadDone
(
false
)
,
mLoadIsErronous
(
false
)
,
mIsFreezable
(
true
)
,
mCanBeContent
(
0
)
,
mCanBeTool
(
0
)
,
mIsFrozen
(
false
)
,
mIsTakingSnapshot
(
false
)
{
setAcceptDrops
(
true
);
setPage
(
new
UBWebPage
(
this
));
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
JavaEnabled
,
true
);
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
PluginsEnabled
,
true
);
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
LocalStorageDatabaseEnabled
,
true
);
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
OfflineWebApplicationCacheEnabled
,
true
);
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
OfflineStorageDatabaseEnabled
,
true
);
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
JavascriptCanAccessClipboard
,
true
);
QWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
DnsPrefetchEnabled
,
true
);
QWebView
::
page
()
->
setNetworkAccessManager
(
UBNetworkAccessManager
::
defaultAccessManager
());
setAutoFillBackground
(
false
);
QPalette
pagePalette
=
QWebView
::
page
()
->
palette
();
pagePalette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
pagePalette
.
setBrush
(
QPalette
::
Window
,
QBrush
(
Qt
::
transparent
));
QWebView
::
page
()
->
setPalette
(
pagePalette
);
QPalette
viewPalette
=
palette
();
pagePalette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
viewPalette
.
setBrush
(
QPalette
::
Window
,
QBrush
(
Qt
::
transparent
));
setPalette
(
viewPalette
);
connect
(
QWebView
::
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
connect
(
QWebView
::
page
(),
SIGNAL
(
geometryChangeRequested
(
const
QRect
&
)),
this
,
SIGNAL
(
geometryChangeRequested
(
const
QRect
&
)));
connect
(
this
,
SIGNAL
(
loadFinished
(
bool
)),
this
,
SLOT
(
mainFrameLoadFinished
(
bool
)));
setMouseTracking
(
true
);
}
bool
UBAbstractWidget
::
canBeContent
()
{
// if we under MAC OS
#if defined(Q_OS_MAC)
return
mCanBeContent
&
UBAbstractWidget
::
type_MAC
;
#endif
// if we under UNIX OS
#if defined(Q_OS_UNIX)
return
mCanBeContent
&
UBAbstractWidget
::
type_UNIX
;
#endif
// if we under WINDOWS OS
#if defined(Q_OS_WIN)
return
mCanBeContent
&
UBAbstractWidget
::
type_WIN
;
#endif
}
bool
UBAbstractWidget
::
canBeTool
()
{
// if we under MAC OS
#if defined(Q_OS_MAC)
return
mCanBeTool
&
UBAbstractWidget
::
type_MAC
;
#endif
// if we under UNIX OS
#if defined(Q_OS_UNIX)
return
mCanBeTool
&
UBAbstractWidget
::
type_UNIX
;
#endif
// if we under WINDOWS OS
#if defined(Q_OS_WIN)
return
mCanBeTool
&
UBAbstractWidget
::
type_WIN
;
#endif
}
UBAbstractWidget
::~
UBAbstractWidget
()
{
// NOOP
}
void
UBAbstractWidget
::
loadMainHtml
()
{
mInitialLoadDone
=
false
;
QWebView
::
load
(
mMainHtmlUrl
);
}
bool
UBAbstractWidget
::
event
(
QEvent
*
event
)
{
if
(
event
->
type
()
==
QEvent
::
ContextMenu
)
{
event
->
accept
();
return
true
;
}
else
{
return
QWebView
::
event
(
event
);
}
}
void
UBAbstractWidget
::
mainFrameLoadFinished
(
bool
ok
)
{
mInitialLoadDone
=
true
;
mLoadIsErronous
=
!
ok
;
update
();
}
bool
UBAbstractWidget
::
hasEmbededObjects
()
{
if
(
QWebView
::
page
()
->
mainFrame
())
{
QList
<
UBWebKitUtils
::
HtmlObject
>
htmlObjects
=
UBWebKitUtils
::
objectsInFrame
(
QWebView
::
page
()
->
mainFrame
());
return
htmlObjects
.
length
()
>
0
;
}
return
false
;
}
bool
UBAbstractWidget
::
hasEmbededFlash
()
{
if
(
hasEmbededObjects
())
{
return
QWebView
::
page
()
->
mainFrame
()
->
toHtml
().
contains
(
"application/x-shockwave-flash"
);
}
else
{
return
false
;
}
}
void
UBAbstractWidget
::
resize
(
qreal
width
,
qreal
height
)
{
qreal
w
=
qMax
((
qreal
)
mNominalSize
.
width
(),
width
);
qreal
h
=
qMax
((
qreal
)
mNominalSize
.
height
(),
height
);
QWebView
::
page
()
->
setViewportSize
(
QSize
(
w
,
h
));
QWebView
::
setFixedSize
(
QSize
(
w
,
h
));
}
QString
UBAbstractWidget
::
iconFilePath
(
const
QUrl
&
pUrl
)
{
// TODO UB 4.x read config.xml widget.icon param first
QStringList
files
;
files
<<
"icon.svg"
;
// W3C widget default 1
files
<<
"icon.ico"
;
// W3C widget default 2
files
<<
"icon.png"
;
// W3C widget default 3
files
<<
"icon.gif"
;
// W3C widget default 4
files
<<
"Icon.png"
;
// Apple widget default
QString
file
=
UBFileSystemUtils
::
getFirstExistingFileFromList
(
pUrl
.
toLocalFile
(),
files
);
// default
if
(
file
.
length
()
==
0
)
{
file
=
QString
(
":/images/defaultWidgetIcon.png"
);
}
return
file
;
}
QString
UBAbstractWidget
::
widgetName
(
const
QUrl
&
widgetPath
)
{
QString
name
;
QString
version
;
QFile
w3CConfigFile
(
widgetPath
.
toLocalFile
()
+
"/config.xml"
);
QFile
appleConfigFile
(
widgetPath
.
toLocalFile
()
+
"/Info.plist"
);
if
(
w3CConfigFile
.
exists
()
&&
w3CConfigFile
.
open
(
QFile
::
ReadOnly
))
{
QDomDocument
doc
;
doc
.
setContent
(
w3CConfigFile
.
readAll
());
QDomElement
root
=
doc
.
firstChildElement
(
"widget"
);
if
(
!
root
.
isNull
())
{
QDomElement
nameElement
=
root
.
firstChildElement
(
"name"
);
if
(
!
nameElement
.
isNull
())
name
=
nameElement
.
text
();
version
=
root
.
attribute
(
"version"
,
""
);
}
w3CConfigFile
.
close
();
}
else
if
(
appleConfigFile
.
exists
()
&&
appleConfigFile
.
open
(
QFile
::
ReadOnly
))
{
QDomDocument
doc
;
doc
.
setContent
(
appleConfigFile
.
readAll
());
QDomElement
root
=
doc
.
firstChildElement
(
"plist"
);
if
(
!
root
.
isNull
())
{
QDomElement
dictElement
=
root
.
firstChildElement
(
"dict"
);
if
(
!
dictElement
.
isNull
())
{
QDomNodeList
childNodes
=
dictElement
.
childNodes
();
// looking for something like
// ..
// <key>CFBundleDisplayName</key>
// <string>brain scans</string>
// ..
for
(
int
i
=
0
;
i
<
childNodes
.
count
()
-
1
;
i
++
)
{
if
(
childNodes
.
at
(
i
).
isElement
())
{
QDomElement
elKey
=
childNodes
.
at
(
i
).
toElement
();
if
(
elKey
.
text
()
==
"CFBundleDisplayName"
)
{
if
(
childNodes
.
at
(
i
+
1
).
isElement
())
{
QDomElement
elValue
=
childNodes
.
at
(
i
+
1
).
toElement
();
name
=
elValue
.
text
();
}
}
else
if
(
elKey
.
text
()
==
"CFBundleShortVersionString"
)
{
if
(
childNodes
.
at
(
i
+
1
).
isElement
())
{
QDomElement
elValue
=
childNodes
.
at
(
i
+
1
).
toElement
();
version
=
elValue
.
text
();
}
}
}
}
}
}
appleConfigFile
.
close
();
}
QString
result
;
if
(
name
.
length
()
>
0
)
{
result
=
name
;
if
(
version
.
length
()
>
0
)
{
result
+=
" "
;
result
+=
version
;
}
}
return
result
;
}
int
UBAbstractWidget
::
widgetType
(
const
QUrl
&
pUrl
)
{
QString
mime
=
UBFileSystemUtils
::
mimeTypeFromFileName
(
pUrl
.
toString
());
if
(
mime
==
"application/vnd.apple-widget"
)
{
return
UBWidgetType
::
Apple
;
}
else
if
(
mime
==
"application/widget"
)
{
return
UBWidgetType
::
W3C
;
}
else
{
return
UBWidgetType
::
Other
;
}
}
void
UBAbstractWidget
::
mousePressEvent
(
QMouseEvent
*
event
)
{
if
(
mIsFrozen
)
{
event
->
accept
();
return
;
}
UBRoutedMouseEventWebView
::
mousePressEvent
(
event
);
mMouseIsPressed
=
true
;
}
void
UBAbstractWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
if
(
mIsFrozen
)
{
event
->
accept
();
return
;
}
// TODO UB 4.x fix web kit mouse move routing
if
(
mFirstReleaseAfterMove
)
{
mFirstReleaseAfterMove
=
false
;
}
else
{
UBRoutedMouseEventWebView
::
mouseMoveEvent
(
event
);
}
}
void
UBAbstractWidget
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
if
(
mIsFrozen
)
{
event
->
accept
();
return
;
}
UBRoutedMouseEventWebView
::
mouseReleaseEvent
(
event
);
mMouseIsPressed
=
false
;
mFirstReleaseAfterMove
=
true
;
}
QWebView
*
UBAbstractWidget
::
createWindow
(
QWebPage
::
WebWindowType
type
)
{
if
(
type
==
QWebPage
::
WebBrowserWindow
)
{
UBApplication
::
applicationController
->
showInternet
();
return
UBApplication
::
webController
->
createNewTab
();
}
else
{
return
this
;
}
}
void
UBAbstractWidget
::
injectInlineJavaScript
()
{
if
(
!
sInlineJavaScriptLoaded
)
{
sInlineJavaScripts
=
UBApplication
::
applicationController
->
widgetInlineJavaScripts
();
sInlineJavaScriptLoaded
=
true
;
}
foreach
(
QString
script
,
sInlineJavaScripts
)
{
QWebView
::
page
()
->
mainFrame
()
->
evaluateJavaScript
(
script
);
}
}
void
UBAbstractWidget
::
javaScriptWindowObjectCleared
()
{
injectInlineJavaScript
();
}
void
UBAbstractWidget
::
paintEvent
(
QPaintEvent
*
event
)
{
if
(
mIsFrozen
)
{
QPainter
p
(
this
);
p
.
drawPixmap
(
0
,
0
,
mSnapshot
);
}
else
{
QWebView
::
paintEvent
(
event
);
}
if
(
!
mInitialLoadDone
||
mLoadIsErronous
)
{
QPainter
p
(
this
);
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
(
mInitialLoadDone
&&
mLoadIsErronous
)
message
=
tr
(
"Cannot load content"
);
else
message
=
tr
(
"Loading ..."
);
p
.
setFont
(
QFont
(
"Arial"
,
12
));
QFontMetrics
fm
=
p
.
fontMetrics
();
QRect
txtBoundingRect
=
fm
.
boundingRect
(
message
);
txtBoundingRect
.
moveCenter
(
rect
().
center
());
txtBoundingRect
.
adjust
(
-
10
,
-
5
,
10
,
5
);
p
.
setPen
(
Qt
::
NoPen
);
p
.
setBrush
(
UBSettings
::
paletteColor
);
p
.
drawRoundedRect
(
txtBoundingRect
,
3
,
3
);
p
.
setPen
(
Qt
::
white
);
p
.
drawText
(
rect
(),
Qt
::
AlignCenter
,
message
);
}
}
void
UBAbstractWidget
::
dropEvent
(
QDropEvent
*
event
)
{
QWebView
::
dropEvent
(
event
);
}
QPixmap
UBAbstractWidget
::
takeSnapshot
()
{
mIsTakingSnapshot
=
true
;
QPixmap
pix
(
size
());
pix
.
fill
(
Qt
::
transparent
);
render
(
&
pix
);
mIsTakingSnapshot
=
false
;
return
pix
;
}
void
UBAbstractWidget
::
setSnapshot
(
const
QPixmap
&
pix
)
{
mSnapshot
=
pix
;
}
void
UBAbstractWidget
::
freeze
()
{
QPixmap
pix
=
takeSnapshot
();
mIsFrozen
=
true
;
setSnapshot
(
pix
);
update
();
}
void
UBAbstractWidget
::
unFreeze
()
{
mIsFrozen
=
false
;
update
();
}
src/domain/UBAbstractWidget.h
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBABSTRACTWIDGET_H_
#define UBABSTRACTWIDGET_H_
#include <QtGui>
#include <QtWebKit>
#include "web/UBRoutedMouseEventWebView.h"
struct
UBWidgetType
{
enum
Enum
{
W3C
=
0
,
Apple
,
Other
};
};
class
UBAbstractWidget
:
public
UBRoutedMouseEventWebView
{
Q_OBJECT
;
public
:
UBAbstractWidget
(
const
QUrl
&
pWidgetUrl
,
QWidget
*
parent
=
0
);
virtual
~
UBAbstractWidget
();
void
loadMainHtml
();
QUrl
mainHtml
()
{
return
mMainHtmlUrl
;
}
QUrl
widgetUrl
()
{
return
mWidgetUrl
;
}
QString
mainHtmlFileName
()
{
return
mMainHtmlFileName
;
}
bool
hasEmbededObjects
();
bool
hasEmbededFlash
();
void
resize
(
qreal
width
,
qreal
height
);
QSize
nominalSize
()
const
{
return
mNominalSize
;
}
bool
canBeContent
();
bool
canBeTool
();
bool
hasLoadedSuccessfully
()
const
{
return
(
mInitialLoadDone
&&
!
mLoadIsErronous
);
}
bool
freezable
()
{
return
mIsFreezable
;}
bool
resizable
()
{
return
mIsResizable
;}
static
QString
iconFilePath
(
const
QUrl
&
pUrl
);
static
QString
widgetName
(
const
QUrl
&
pUrl
);
static
int
widgetType
(
const
QUrl
&
pUrl
);
bool
isFrozen
(){
return
mIsFrozen
;}
QPixmap
snapshot
(){
return
mSnapshot
;}
void
setSnapshot
(
const
QPixmap
&
pix
);
QPixmap
takeSnapshot
();
public
slots
:
void
freeze
();
void
unFreeze
();
signals
:
void
geometryChangeRequested
(
const
QRect
&
geom
);
protected
:
bool
mMouseIsPressed
;
bool
mFirstReleaseAfterMove
;
virtual
bool
event
(
QEvent
*
e
);
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
virtual
QWebView
*
createWindow
(
QWebPage
::
WebWindowType
type
);
QUrl
mMainHtmlUrl
;
QString
mMainHtmlFileName
;
QUrl
mWidgetUrl
;
QSize
mNominalSize
;
bool
mIsResizable
;
bool
mInitialLoadDone
;
bool
mLoadIsErronous
;
bool
mIsFreezable
;
int
mCanBeContent
;
int
mCanBeTool
;
enum
OSType
{
type_NONE
=
0
,
// 0000
type_WIN
=
1
,
// 0001
type_MAC
=
2
,
// 0010
type_UNIX
=
4
,
// 0100
type_ALL
=
7
,
// 0111
};
virtual
void
injectInlineJavaScript
();
virtual
void
paintEvent
(
QPaintEvent
*
event
);
virtual
void
dropEvent
(
QDropEvent
*
);
protected
slots
:
void
mainFrameLoadFinished
(
bool
ok
);
private
:
static
QStringList
sInlineJavaScripts
;
static
bool
sInlineJavaScriptLoaded
;
bool
mIsFrozen
;
QPixmap
mSnapshot
;
bool
mIsTakingSnapshot
;
private
slots
:
void
javaScriptWindowObjectCleared
();
};
#endif
/* UBABSTRACTWIDGET_H_ */
src/domain/UBAppleWidget.cpp
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBAppleWidget.h"
#include <QtNetwork>
#include "web/UBWebKitUtils.h"
#include "network/UBNetworkAccessManager.h"
#include "core/memcheck.h"
UBAppleWidget
::
UBAppleWidget
(
const
QUrl
&
pWidgetUrl
,
QWidget
*
parent
)
:
UBAbstractWidget
(
pWidgetUrl
,
parent
)
{
QString
path
=
pWidgetUrl
.
toLocalFile
();
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
);
QByteArray
plistBin
=
plistFile
.
readAll
();
QString
plist
=
QString
::
fromUtf8
(
plistBin
);
int
mainHtmlIndex
=
plist
.
indexOf
(
"MainHTML"
);
int
mainHtmlIndexStart
=
plist
.
indexOf
(
"<string>"
,
mainHtmlIndex
);
int
mainHtmlIndexEnd
=
plist
.
indexOf
(
"</string>"
,
mainHtmlIndexStart
);
if
(
mainHtmlIndex
>
-
1
&&
mainHtmlIndexStart
>
-
1
&&
mainHtmlIndexEnd
>
-
1
)
{
mMainHtmlFileName
=
plist
.
mid
(
mainHtmlIndexStart
+
8
,
mainHtmlIndexEnd
-
mainHtmlIndexStart
-
8
);
}
mMainHtmlUrl
=
pWidgetUrl
;
mMainHtmlUrl
.
setPath
(
pWidgetUrl
.
path
()
+
"/"
+
mMainHtmlFileName
);
QWebView
::
load
(
mMainHtmlUrl
);
QPixmap
defaultPixmap
(
pWidgetUrl
.
toLocalFile
()
+
"/Default.png"
);
setFixedSize
(
defaultPixmap
.
size
());
mNominalSize
=
defaultPixmap
.
size
();
}
UBAppleWidget
::~
UBAppleWidget
()
{
// NOOP
}
src/domain/UBGraphicsItemDelegate.cpp
View file @
e6be59ce
...
...
@@ -37,7 +37,6 @@
#include "UBGraphicsWidgetItem.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsGroupContainerItem.h"
...
...
@@ -379,7 +378,14 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
void
UBGraphicsItemDelegate
::
remove
(
bool
canUndo
)
{
// QGraphicsScene* scene = mDelegated->scene();
/*UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
if (scene && canUndo)
{
UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0);
UBApplication::undoStack->push(uc);
}
mDelegated->hide(); */
UBGraphicsScene
*
scene
=
dynamic_cast
<
UBGraphicsScene
*>
(
mDelegated
->
scene
());
if
(
scene
)
{
...
...
@@ -387,11 +393,17 @@ void UBGraphicsItemDelegate::remove(bool canUndo)
scene
->
removeItem
(
button
);
scene
->
removeItem
(
mFrame
);
/* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */
UBGraphicsWebView
*
mDelegated_casted
=
dynamic_cast
<
UBGraphicsWebView
*>
(
mDelegated
);
if
(
mDelegated_casted
)
mDelegated_casted
->
setHtml
(
QString
());
scene
->
removeItem
(
mDelegated
);
if
(
canUndo
)
{
UBGraphicsItemUndoCommand
*
uc
=
new
UBGraphicsItemUndoCommand
(
(
UBGraphicsScene
*
)
scene
,
mDelegated
,
0
);
UBGraphicsItemUndoCommand
*
uc
=
new
UBGraphicsItemUndoCommand
(
scene
,
mDelegated
,
0
);
UBApplication
::
undoStack
->
push
(
uc
);
}
}
...
...
src/domain/UBGraphicsMediaItem.cpp
View file @
e6be59ce
...
...
@@ -54,11 +54,11 @@ bool UBGraphicsMediaItem::sIsMutedByDefault = false;
UBGraphicsMediaItem
::
UBGraphicsMediaItem
(
const
QUrl
&
pMediaFileUrl
,
QGraphicsItem
*
parent
)
:
UBGraphicsProxyWidget
(
parent
)
,
mVideoWidget
(
NULL
)
,
mAudioWidget
(
NULL
)
,
mMuted
(
sIsMutedByDefault
)
,
mMutedByUserAction
(
sIsMutedByDefault
)
,
mMediaFileUrl
(
pMediaFileUrl
)
,
mVideoWidget
(
NULL
)
,
mAudioWidget
(
NULL
)
,
mLinkedImage
(
NULL
)
,
mInitialPos
(
0
)
{
...
...
src/domain/UBGraphicsMediaItem.h
View file @
e6be59ce
...
...
@@ -139,8 +139,6 @@ private:
QUrl
mMediaFileUrl
;
QString
mMediaSource
;
qint64
mInitialPos
;
mediaType
mMediaType
;
bool
mShouldMove
;
...
...
@@ -149,5 +147,7 @@ private:
bool
haveLinkedImage
;
QGraphicsPixmapItem
*
mLinkedImage
;
qint64
mInitialPos
;
};
#endif // UBGRAPHICSMEDIAITEM_H
src/domain/UBGraphicsScene.cpp
View file @
e6be59ce
...
...
@@ -31,6 +31,7 @@
#include "gui/UBMagnifer.h"
#include "gui/UBMainWindow.h"
#include "gui/UBToolWidget.h"
#include "tools/UBGraphicsRuler.h"
#include "tools/UBGraphicsProtractor.h"
...
...
@@ -59,8 +60,6 @@
#include "domain/UBGraphicsGroupContainerItem.h"
#include "UBAppleWidget.h"
#include "UBW3CWidget.h"
#include "UBGraphicsStroke.h"
#include "core/memcheck.h"
...
...
@@ -1396,7 +1395,7 @@ UBGraphicsMediaItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool s
UBGraphicsWidgetItem
*
UBGraphicsScene
::
addWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
)
{
int
widgetType
=
UB
AbstractWidget
::
widgetType
(
pWidgetUrl
);
int
widgetType
=
UB
GraphicsWidgetItem
::
widgetType
(
pWidgetUrl
);
if
(
widgetType
==
UBWidgetType
::
Apple
)
{
...
...
@@ -1422,9 +1421,9 @@ UBGraphicsAppleWidgetItem* UBGraphicsScene::addAppleWidget(const QUrl& pWidgetUr
return
appleWidget
;
}
UBGraphicsW3CWidgetItem
*
UBGraphicsScene
::
addW3CWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
,
int
widgetType
)
UBGraphicsW3CWidgetItem
*
UBGraphicsScene
::
addW3CWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
)
{
UBGraphicsW3CWidgetItem
*
w3CWidget
=
new
UBGraphicsW3CWidgetItem
(
pWidgetUrl
,
0
,
widgetType
);
UBGraphicsW3CWidgetItem
*
w3CWidget
=
new
UBGraphicsW3CWidgetItem
(
pWidgetUrl
,
0
);
addGraphicsWidget
(
w3CWidget
,
pPos
);
...
...
@@ -1444,7 +1443,7 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co
graphicsWidget
->
setPos
(
QPointF
(
pPos
.
x
()
-
graphicsWidget
->
boundingRect
().
width
()
/
2
,
pPos
.
y
()
-
graphicsWidget
->
boundingRect
().
height
()
/
2
));
if
(
graphicsWidget
->
widgetWebView
()
->
canBeContent
())
if
(
graphicsWidget
->
canBeContent
())
{
// graphicsWidget->widgetWebView()->loadMainHtml();
...
...
@@ -1464,6 +1463,8 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co
UBApplication
::
boardController
->
controlView
()
->
setFocus
();
}
UBGraphicsW3CWidgetItem
*
UBGraphicsScene
::
addOEmbed
(
const
QUrl
&
pContentUrl
,
const
QPointF
&
pPos
)
{
QStringList
widgetPaths
=
UBPersistenceManager
::
persistenceManager
()
->
allWidgets
(
UBSettings
::
settings
()
->
applicationApplicationsLibraryDirectory
());
...
...
src/domain/UBGraphicsScene.h
View file @
e6be59ce
...
...
@@ -35,12 +35,12 @@ class UBGraphicsAudioItem;
class
UBGraphicsWidgetItem
;
class
UBGraphicsW3CWidgetItem
;
class
UBGraphicsAppleWidgetItem
;
class
UBToolWidget
;
class
UBGraphicsPDFItem
;
class
UBGraphicsTextItem
;
class
UBGraphicsRuler
;
class
UBGraphicsProtractor
;
class
UBGraphicsCompass
;
class
UBAbstractWidget
;
class
UBDocumentProxy
;
class
UBGraphicsCurtainItem
;
class
UBGraphicsStroke
;
...
...
@@ -132,9 +132,11 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsWidgetItem
*
addWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
UBGraphicsAppleWidgetItem
*
addAppleWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
UBGraphicsW3CWidgetItem
*
addW3CWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
)
,
int
widgetType
=
UBGraphicsItemType
::
W3CWidgetItemType
);
UBGraphicsW3CWidgetItem
*
addW3CWidget
(
const
QUrl
&
pWidgetUrl
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
void
addGraphicsWidget
(
UBGraphicsWidgetItem
*
graphicsWidget
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
UBGraphicsMediaItem
*
addMedia
(
const
QUrl
&
pMediaFileUrl
,
bool
shouldPlayAsap
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
UBGraphicsMediaItem
*
addVideo
(
const
QUrl
&
pVideoFileUrl
,
bool
shouldPlayAsap
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
UBGraphicsMediaItem
*
addAudio
(
const
QUrl
&
pAudioFileUrl
,
bool
shouldPlayAsap
,
const
QPointF
&
pPos
=
QPointF
(
0
,
0
));
...
...
src/domain/UBGraphicsWebView.cpp
0 → 100644
View file @
e6be59ce
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <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
)
{
setData
(
UBGraphicsItemData
::
ItemLayerType
,
UBItemLayerType
::
Object
);
mDelegate
=
new
UBGraphicsItemDelegate
(
this
,
0
,
true
,
false
,
false
);
mDelegate
->
init
();
setFlag
(
QGraphicsItem
::
ItemSendsGeometryChanges
,
true
);
QGraphicsWebView
::
setAcceptHoverEvents
(
true
);
}
UBGraphicsWebView
::~
UBGraphicsWebView
()
{
if
(
mDelegate
)
delete
mDelegate
;
}
QVariant
UBGraphicsWebView
::
itemChange
(
GraphicsItemChange
change
,
const
QVariant
&
value
)
{
if
((
change
==
QGraphicsItem
::
ItemSelectedHasChanged
)
&&
scene
())
{
if
(
isSelected
())
scene
()
->
setActiveWindow
(
this
);
else
if
(
scene
()
->
activeWindow
()
==
this
)
scene
()
->
setActiveWindow
(
0
);
}
QVariant
newValue
=
mDelegate
->
itemChange
(
change
,
value
);
return
QGraphicsWebView
::
itemChange
(
change
,
newValue
);
}
void
UBGraphicsWebView
::
setUuid
(
const
QUuid
&
pUuid
)
{
UBItem
::
setUuid
(
pUuid
);
setData
(
UBGraphicsItemData
::
ItemUuid
,
QVariant
(
pUuid
));
//store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
void
UBGraphicsWebView
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
!
mDelegate
->
mousePressEvent
(
event
))
setSelected
(
true
);
/* forcing selection */
QGraphicsWebView
::
mousePressEvent
(
event
);
}
void
UBGraphicsWebView
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
!
mDelegate
->
mouseMoveEvent
(
event
))
QGraphicsWebView
::
mouseMoveEvent
(
event
);
}
void
UBGraphicsWebView
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDelegate
->
mouseReleaseEvent
(
event
);
QGraphicsWebView
::
mouseReleaseEvent
(
event
);
}
void
UBGraphicsWebView
::
wheelEvent
(
QGraphicsSceneWheelEvent
*
event
)
{
if
(
mDelegate
->
weelEvent
(
event
))
{
QGraphicsWebView
::
wheelEvent
(
event
);
event
->
accept
();
}
}
void
UBGraphicsWebView
::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
Q_UNUSED
(
event
)
/* NOOP */
}
void
UBGraphicsWebView
::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
Q_UNUSED
(
event
)
/* NOOP */
}
void
UBGraphicsWebView
::
setDelegate
(
UBGraphicsItemDelegate
*
pDelegate
)
{
if
(
mDelegate
)
delete
mDelegate
;
mDelegate
=
pDelegate
;
}
void
UBGraphicsWebView
::
resize
(
qreal
w
,
qreal
h
)
{
UBGraphicsWebView
::
resize
(
QSizeF
(
w
,
h
));
}
void
UBGraphicsWebView
::
resize
(
const
QSizeF
&
pSize
)
{
if
(
pSize
!=
size
())
{
QGraphicsWebView
::
setMaximumSize
(
pSize
.
width
(),
pSize
.
height
());
QGraphicsWebView
::
resize
(
pSize
.
width
(),
pSize
.
height
());
if
(
mDelegate
)
mDelegate
->
positionHandles
();
if
(
scene
())
scene
()
->
setModified
(
true
);
}
}
QSizeF
UBGraphicsWebView
::
size
()
const
{
return
QGraphicsWebView
::
size
();
}
UBGraphicsScene
*
UBGraphicsWebView
::
scene
()
{
return
static_cast
<
UBGraphicsScene
*>
(
QGraphicsItem
::
scene
());
}
void
UBGraphicsWebView
::
remove
()
{
if
(
mDelegate
)
mDelegate
->
remove
(
true
);
}
bool
UBGraphicsWebView
::
event
(
QEvent
*
event
)
{
if
(
event
->
type
()
==
QEvent
::
ShortcutOverride
)
event
->
accept
();
return
QGraphicsWebView
::
event
(
event
);
}
src/domain/UB
AppleWidget
.h
→
src/domain/UB
GraphicsWebView
.h
View file @
e6be59ce
...
...
@@ -13,24 +13,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UB
APPLEWIDGET
_H_
#define UB
APPLEWIDGET
_H_
#ifndef UB
GRAPHICSWEBVIEW
_H_
#define UB
GRAPHICSWEBVIEW
_H_
#include <QtGui>
#include <QtWebKit>
#include "UBAbstractWidget.h"
#include "UBItem.h"
#include "UBResizableGraphicsItem.h"
class
UB
Item
;
class
UB
GraphicsItemDelegate
;
class
UB
AppleWidget
:
public
UBAbstractWidget
class
UB
GraphicsWebView
:
public
QGraphicsWebView
,
public
UBItem
,
public
UBResizableGraphicsItem
,
public
UBGraphicsItem
{
Q_OBJECT
;
public
:
UBAppleWidget
(
const
QUrl
&
pWidgetUrl
,
QWidget
*
parent
=
0
);
virtual
~
UBAppleWidget
();
UBGraphicsWebView
(
QGraphicsItem
*
parent
=
0
);
virtual
~
UBGraphicsWebView
();
virtual
void
resize
(
qreal
w
,
qreal
h
);
virtual
void
resize
(
const
QSizeF
&
size
);
virtual
QSizeF
size
()
const
;
void
setDelegate
(
UBGraphicsItemDelegate
*
pDelegate
);
virtual
UBGraphicsScene
*
scene
();
virtual
void
remove
();
virtual
UBGraphicsItemDelegate
*
Delegate
()
const
{
return
mDelegate
;}
virtual
void
clearSource
(){;}
virtual
void
setUuid
(
const
QUuid
&
pUuid
);
protected
:
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
wheelEvent
(
QGraphicsSceneWheelEvent
*
event
);
virtual
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
bool
event
(
QEvent
*
event
);
virtual
QVariant
itemChange
(
GraphicsItemChange
change
,
const
QVariant
&
value
);
};
#endif
/* UB
APPLEWIDGET
_H_ */
#endif
/* UB
GRAPHICSWEBVIEW
_H_ */
src/domain/UBGraphicsWidgetItem.cpp
View file @
e6be59ce
...
...
@@ -13,308 +13,646 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsWidgetItem.h"
#include "api/UBWidgetUniboardAPI.h"
#include "api/UBW3CWidgetAPI.h"
#include <QtNetwork>
#include <QtXml>
#include "UBGraphicsWidgetItem.h"
#include "UBGraphicsScene.h"
#include "UBGraphicsItemDelegate.h"
#include "UBGraphicsWidgetItemDelegate.h"
#include "UBGraphicsDelegateFrame.h"
#include "
UBW3CWidget
.h"
#include "
UBGraphicsScene
.h"
#include "UBAppleWidget.h"
#include "frameworks/UBFileSystemUtils
.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"
UBGraphicsWidgetItem
::
UBGraphicsWidgetItem
(
QGraphicsItem
*
parent
,
int
widgetType
)
:
UBGraphicsProxyWidget
(
parent
)
,
mWebKitWidget
(
0
)
#include "frameworks/UBFileSystemUtils.h"
#include "frameworks/UBPlatformUtils.h"
#include "network/UBNetworkAccessManager.h"
#include "web/UBWebPage.h"
#include "web/UBWebKitUtils.h"
#include "web/UBWebController.h"
bool
UBGraphicsWidgetItem
::
sInlineJavaScriptLoaded
=
false
;
QStringList
UBGraphicsWidgetItem
::
sInlineJavaScripts
;
UBGraphicsWidgetItem
::
UBGraphicsWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
)
:
UBGraphicsWebView
(
parent
)
,
mInitialLoadDone
(
false
)
,
mIsFreezable
(
true
)
,
mIsResizable
(
false
)
,
mLoadIsErronous
(
false
)
,
mCanBeContent
(
0
)
,
mCanBeTool
(
0
)
,
mWidgetUrl
(
pWidgetUrl
)
,
mIsFrozen
(
false
)
,
mIsTakingSnapshot
(
false
)
,
mShouldMoveWidget
(
false
)
,
mUniboardAPI
(
0
)
{
setAcceptDrops
(
false
);
UBGraphicsWidgetItemDelegate
*
delegate
=
new
UBGraphicsWidgetItemDelegate
(
this
,
widgetType
);
delegate
->
init
();
setDelegate
(
delegate
);
setData
(
UBGraphicsItemData
::
itemLayerType
,
QVariant
(
itemLayerType
::
ObjectItem
));
//Necessary to set if we want z value to be assigned correctly
}
QGraphicsWebView
::
setPage
(
new
UBWebPage
(
this
));
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
JavaEnabled
,
true
);
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
PluginsEnabled
,
true
);
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
LocalStorageDatabaseEnabled
,
true
);
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
OfflineWebApplicationCacheEnabled
,
true
);
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
OfflineStorageDatabaseEnabled
,
true
);
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
JavascriptCanAccessClipboard
,
true
);
QGraphicsWebView
::
settings
()
->
setAttribute
(
QWebSettings
::
DnsPrefetchEnabled
,
true
);
UBGraphicsWidgetItem
::~
UBGraphicsWidgetItem
()
{
// NOOP
}
page
()
->
setNetworkAccessManager
(
UBNetworkAccessManager
::
defaultAccessManager
());
setAcceptDrops
(
true
);
setAutoFillBackground
(
false
);
void
UBGraphicsWidgetItem
::
javaScriptWindowObjectCleared
()
{
if
(
!
mUniboardAPI
)
mUniboardAPI
=
new
UBWidgetUniboardAPI
(
scene
(),
this
);
QPalette
pagePalette
=
page
()
->
palette
();
pagePalette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
pagePalette
.
setBrush
(
QPalette
::
Window
,
QBrush
(
Qt
::
transparent
));
page
()
->
setPalette
(
pagePalette
);
mWebKitWidget
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
mUniboardAPI
);
QPalette
viewPalette
=
palette
();
pagePalette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
viewPalette
.
setBrush
(
QPalette
::
Window
,
QBrush
(
Qt
::
transparent
));
setPalette
(
viewPalette
);
UBGraphicsWidgetItemDelegate
*
delegate
=
new
UBGraphicsWidgetItemDelegate
(
this
);
delegate
->
init
();
setDelegate
(
delegate
);
}
void
UBGraphicsWidgetItem
::
setUuid
(
const
QUuid
&
pUuid
)
UBGraphicsWidgetItem
::~
UBGraphicsWidgetItem
()
{
UBItem
::
setUuid
(
pUuid
);
setData
(
UBGraphicsItemData
::
ItemUuid
,
QVariant
(
pUuid
));
//store item uuid inside the QGraphicsItem to fast operations with Items on the scene
/* NOOP */
}
void
UBGraphicsWidgetItem
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
void
UBGraphicsWidgetItem
::
initialize
(
)
{
UBGraphicsProxyWidget
::
mousePressEvent
(
event
);
installEventFilter
(
this
);
UBGraphicsWebView
::
setMinimumSize
(
nominalSize
());
setData
(
UBGraphicsItemData
::
itemLayerType
,
QVariant
(
itemLayerType
::
ObjectItem
));
// Necessary to set if we want z value to be assigned correctly
// did webkit consume the mouse press ?
mShouldMoveWidget
=
!
event
->
isAccepted
()
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
);
if
(
mDelegate
&&
mDelegate
->
frame
()
&&
resizable
())
mDelegate
->
frame
()
->
setOperationMode
(
UBGraphicsDelegateFrame
::
Resizing
);
mLastMousePos
=
mapToScene
(
event
->
pos
());
QPalette
palette
=
page
()
->
palette
();
palette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
page
()
->
setPalette
(
palette
);
event
->
accept
();
connect
(
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
connect
(
page
(),
SIGNAL
(
geometryChangeRequested
(
const
QRect
&
)),
this
,
SLOT
(
geometryChangeRequested
(
const
QRect
&
)));
connect
(
this
,
SIGNAL
(
loadFinished
(
bool
)),
this
,
SLOT
(
mainFrameLoadFinished
(
bool
)));
}
void
UBGraphicsWidgetItem
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
QUrl
UBGraphicsWidgetItem
::
mainHtml
()
{
mShouldMoveWidget
=
false
;
UBGraphicsProxyWidget
::
mouseReleaseEvent
(
event
);
return
mMainHtmlUrl
;
}
void
UBGraphicsWidgetItem
::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
void
UBGraphicsWidgetItem
::
loadMainHtml
(
)
{
sendJSEnterEvent
();
mDelegate
->
hoverEnterEvent
(
event
);
UBGraphicsProxyWidget
::
hoverEnterEvent
(
event
);
mInitialLoadDone
=
false
;
load
(
mMainHtmlUrl
);
}
void
UBGraphicsWidgetItem
::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
QUrl
UBGraphicsWidgetItem
::
widgetUrl
()
{
sendJSLeaveEvent
();
mDelegate
->
hoverLeaveEvent
(
event
);
UBGraphicsProxyWidget
::
hoverLeaveEvent
(
event
);
return
mWidgetUrl
;
}
void
UBGraphicsWidgetItem
::
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
)
QString
UBGraphicsWidgetItem
::
mainHtmlFileName
(
)
{
UBGraphicsProxyWidget
::
hoverMoveEvent
(
event
)
;
return
mMainHtmlFileName
;
}
bool
UBGraphicsWidgetItem
::
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
bool
UBGraphicsWidgetItem
::
hasEmbededObjects
()
{
if
(
mShouldMoveWidget
&&
obj
==
mWebKitWidget
&&
event
->
type
()
==
QEvent
::
MouseMove
)
{
QMouseEvent
*
mouseMoveEvent
=
static_cast
<
QMouseEvent
*>
(
event
);
if
(
page
()
->
mainFrame
())
{
QList
<
UBWebKitUtils
::
HtmlObject
>
htmlObjects
=
UBWebKitUtils
::
objectsInFrame
(
page
()
->
mainFrame
());
return
htmlObjects
.
length
()
>
0
;
}
if
(
mouseMoveEvent
->
buttons
()
&
Qt
::
LeftButton
)
{
QPointF
scenePos
=
mapToScene
(
mouseMoveEvent
->
pos
());
return
false
;
}
QPointF
newPos
=
pos
()
+
scenePos
-
mLastMousePos
;
bool
UBGraphicsWidgetItem
::
hasEmbededFlash
()
{
if
(
hasEmbededObjects
())
return
page
()
->
mainFrame
()
->
toHtml
().
contains
(
"application/x-shockwave-flash"
);
else
return
false
;
}
setPos
(
newPos
);
bool
UBGraphicsWidgetItem
::
canBeContent
()
{
// if we under MAC OS
#if defined(Q_OS_MAC)
return
mCanBeContent
&
UBGraphicsWidgetItem
::
type_MAC
;
#endif
// if we under UNIX OS
#if defined(Q_OS_UNIX)
return
mCanBeContent
&
UBGraphicsWidgetItem
::
type_UNIX
;
#endif
// if we under WINDOWS OS
#if defined(Q_OS_WIN)
return
mCanBeContent
&
UBGraphicsWidgetItem
::
type_WIN
;
#endif
}
mLastMousePos
=
scenePos
;
bool
UBGraphicsWidgetItem
::
canBeTool
()
{
// if we under MAC OS
#if defined(Q_OS_MAC)
return
mCanBeTool
&
UBGraphicsWidgetItem
::
type_MAC
;
#endif
// if we under UNIX OS
#if defined(Q_OS_UNIX)
return
mCanBeTool
&
UBGraphicsWidgetItem
::
type_UNIX
;
#endif
// if we under WINDOWS OS
#if defined(Q_OS_WIN)
return
mCanBeTool
&
UBGraphicsWidgetItem
::
type_WIN
;
#endif
}
event
->
accept
();
QString
UBGraphicsWidgetItem
::
preference
(
const
QString
&
key
)
const
{
return
mPreferences
.
value
(
key
);
}
return
true
;
}
}
void
UBGraphicsWidgetItem
::
setPreference
(
const
QString
&
key
,
QString
value
)
{
if
(
key
==
""
||
(
mPreferences
.
contains
(
key
)
&&
mPreferences
.
value
(
key
)
==
value
))
return
;
//standard event processing
return
QObject
::
eventFilter
(
obj
,
event
);
mPreferences
.
insert
(
key
,
value
);
if
(
scene
())
scene
()
->
setModified
(
true
);
}
void
UBGraphicsWidgetItem
::
resize
(
qreal
w
,
qreal
h
)
QMap
<
QString
,
QString
>
UBGraphicsWidgetItem
::
preferences
()
const
{
UBGraphicsProxyWidget
::
resize
(
w
,
h
);
mWebKitWidget
->
resize
(
w
,
h
);
return
mPreferences
;
}
void
UBGraphicsWidgetItem
::
re
size
(
const
QSizeF
&
size
)
void
UBGraphicsWidgetItem
::
re
movePreference
(
const
QString
&
key
)
{
resize
(
size
.
width
(),
size
.
height
()
);
mPreferences
.
remove
(
key
);
}
void
UBGraphicsWidgetItem
::
geometryChangeRequested
(
const
QRect
&
geom
)
void
UBGraphicsWidgetItem
::
removeAllPreferences
(
)
{
resize
(
geom
.
width
(),
geom
.
height
()
);
mPreferences
.
clear
(
);
}
void
UBGraphicsWidgetItem
::
initialize
()
QString
UBGraphicsWidgetItem
::
datastoreEntry
(
const
QString
&
key
)
const
{
connect
(
mWebKitWidget
->
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
if
(
mDatastore
.
contains
(
key
))
return
mDatastore
.
value
(
key
);
else
return
QString
();
}
QPalette
palette
=
mWebKitWidget
->
page
()
->
palette
();
palette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
mWebKitWidget
->
page
()
->
setPalette
(
palette
);
void
UBGraphicsWidgetItem
::
setDatastoreEntry
(
const
QString
&
key
,
QString
value
)
{
if
(
key
==
""
||
(
mDatastore
.
contains
(
key
)
&&
mDatastore
.
value
(
key
)
==
value
))
return
;
UBGraphicsProxyWidget
::
setWidget
(
mWebKitWidget
);
mDatastore
.
insert
(
key
,
value
);
if
(
scene
())
scene
()
->
setModified
(
true
);
}
mWebKitWidget
->
installEventFilter
(
this
);
QMap
<
QString
,
QString
>
UBGraphicsWidgetItem
::
datastoreEntries
()
const
{
return
mDatastore
;
}
UBGraphicsProxyWidget
::
setMinimumSize
(
mWebKitWidget
->
nominalSize
());
connect
(
mWebKitWidget
,
SIGNAL
(
geometryChangeRequested
(
const
QRect
&
)),
this
,
SLOT
(
geometryChangeRequested
(
const
QRect
&
)));
void
UBGraphicsWidgetItem
::
removeDatastoreEntry
(
const
QString
&
key
)
{
mDatastore
.
remove
(
key
);
}
if
(
mDelegate
&&
mDelegate
->
frame
()
&&
mWebKitWidget
->
resizable
())
mDelegate
->
frame
()
->
setOperationMode
(
UBGraphicsDelegateFrame
::
Resizing
);
setData
(
UBGraphicsItemData
::
itemLayerType
,
QVariant
(
itemLayerType
::
ObjectItem
));
//Necessary to set if we want z value to be assigned correctly
void
UBGraphicsWidgetItem
::
removeAllDatastoreEntries
()
{
mDatastore
.
clear
();
}
UBGraphicsItemDelegate
*
UBGraphicsWidgetItem
::
Delegate
()
const
{
return
mDelegate
;
}
UBGraphicsScene
*
UBGraphicsWidgetItem
::
scen
e
()
void
UBGraphicsWidgetItem
::
remov
e
()
{
return
qobject_cast
<
UBGraphicsScene
*>
(
QGraphicsItem
::
scene
());
if
(
mDelegate
)
mDelegate
->
remove
();
}
void
UBGraphicsWidgetItem
::
removeScript
()
{
if
(
page
()
&&
page
()
->
mainFrame
())
page
()
->
mainFrame
()
->
evaluateJavaScript
(
"if(widget && widget.onremove) { widget.onremove();}"
);
}
UBAbstractWidget
*
UBGraphicsWidgetItem
::
widgetWebView
()
void
UBGraphicsWidgetItem
::
processDropEvent
(
QDropEvent
*
event
)
{
return
mUniboardAPI
->
ProcessDropEvent
(
event
);
}
bool
UBGraphicsWidgetItem
::
isDropableData
(
const
QMimeData
*
data
)
const
{
return
m
WebKitWidget
;
return
m
UniboardAPI
->
isDropableData
(
data
)
;
}
QUrl
UBGraphicsWidgetItem
::
getOwnFolder
()
const
{
return
ownFolder
;
}
void
UBGraphicsWidgetItem
::
set
Preference
(
const
QString
&
key
,
QString
value
)
void
UBGraphicsWidgetItem
::
set
OwnFolder
(
const
QUrl
&
newFolder
)
{
if
(
key
==
""
||
(
mPreferences
.
contains
(
key
)
&&
mPreferences
.
value
(
key
)
==
value
))
return
;
ownFolder
=
newFolder
;
}
mPreferences
.
insert
(
key
,
value
);
if
(
scene
())
scene
()
->
setModified
(
true
)
;
void
UBGraphicsWidgetItem
::
setSnapshotPath
(
const
QUrl
&
newFilePath
)
{
SnapshotFile
=
newFilePath
;
}
QUrl
UBGraphicsWidgetItem
::
getSnapshotPath
()
{
return
SnapshotFile
;
}
QString
UBGraphicsWidgetItem
::
preference
(
const
QString
&
key
)
const
void
UBGraphicsWidgetItem
::
clearSource
()
{
return
mPreferences
.
value
(
key
);
UBFileSystemUtils
::
deleteDir
(
getOwnFolder
().
toLocalFile
());
UBFileSystemUtils
::
deleteFile
(
getSnapshotPath
().
toLocalFile
());
}
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
}
Q
Map
<
QString
,
QString
>
UBGraphicsWidgetItem
::
preferences
()
const
Q
Size
UBGraphicsWidgetItem
::
nominalSize
()
const
{
return
m
Preferences
;
return
m
NominalSize
;
}
bool
UBGraphicsWidgetItem
::
hasLoadedSuccessfully
()
const
{
return
(
mInitialLoadDone
&&
!
mLoadIsErronous
);
}
void
UBGraphicsWidgetItem
::
removePreference
(
const
QString
&
key
)
bool
UBGraphicsWidgetItem
::
freezable
()
{
mPreferences
.
remove
(
key
)
;
return
mIsFreezable
;
}
bool
UBGraphicsWidgetItem
::
resizable
()
{
return
mIsResizable
;
}
void
UBGraphicsWidgetItem
::
removeAllPreferences
()
bool
UBGraphicsWidgetItem
::
isFrozen
()
{
mPreferences
.
clear
()
;
return
mIsFrozen
;
}
QPixmap
UBGraphicsWidgetItem
::
snapshot
()
{
return
mSnapshot
;
}
void
UBGraphicsWidgetItem
::
setDatastoreEntry
(
const
QString
&
key
,
QString
value
)
QPixmap
UBGraphicsWidgetItem
::
takeSnapshot
(
)
{
if
(
key
==
""
||
(
mDatastore
.
contains
(
key
)
&&
mDatastore
.
value
(
key
)
==
value
))
return
;
mIsTakingSnapshot
=
true
;
mDatastore
.
insert
(
key
,
value
);
if
(
scene
())
scene
()
->
setModified
(
true
);
}
QPixmap
pixmap
(
size
().
toSize
());
pixmap
.
fill
(
Qt
::
transparent
);
QPainter
painter
(
&
pixmap
);
QStyleOptionGraphicsItem
options
;
paint
(
&
painter
,
&
options
);
QString
UBGraphicsWidgetItem
::
datastoreEntry
(
const
QString
&
key
)
const
mIsTakingSnapshot
=
false
;
return
pixmap
;
}
void
UBGraphicsWidgetItem
::
setSnapshot
(
const
QPixmap
&
pix
)
{
if
(
mDatastore
.
contains
(
key
))
return
mDatastore
.
value
(
key
);
else
return
""
;
mSnapshot
=
pix
;
}
UBGraphicsScene
*
UBGraphicsWidgetItem
::
scene
()
{
return
qobject_cast
<
UBGraphicsScene
*>
(
QGraphicsItem
::
scene
());
}
QMap
<
QString
,
QString
>
UBGraphicsWidgetItem
::
datastoreEntries
()
const
int
UBGraphicsWidgetItem
::
widgetType
(
const
QUrl
&
pUrl
)
{
return
mDatastore
;
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
;
}
QString
UBGraphicsWidgetItem
::
widgetName
(
const
QUrl
&
widgetPath
)
{
QString
name
;
QString
version
;
QFile
w3CConfigFile
(
widgetPath
.
toLocalFile
()
+
"/config.xml"
);
QFile
appleConfigFile
(
widgetPath
.
toLocalFile
()
+
"/Info.plist"
);
if
(
w3CConfigFile
.
exists
()
&&
w3CConfigFile
.
open
(
QFile
::
ReadOnly
))
{
QDomDocument
doc
;
doc
.
setContent
(
w3CConfigFile
.
readAll
());
QDomElement
root
=
doc
.
firstChildElement
(
"widget"
);
if
(
!
root
.
isNull
())
{
QDomElement
nameElement
=
root
.
firstChildElement
(
"name"
);
if
(
!
nameElement
.
isNull
())
name
=
nameElement
.
text
();
version
=
root
.
attribute
(
"version"
,
""
);
}
w3CConfigFile
.
close
();
}
else
if
(
appleConfigFile
.
exists
()
&&
appleConfigFile
.
open
(
QFile
::
ReadOnly
))
{
QDomDocument
doc
;
doc
.
setContent
(
appleConfigFile
.
readAll
());
QDomElement
root
=
doc
.
firstChildElement
(
"plist"
);
if
(
!
root
.
isNull
())
{
QDomElement
dictElement
=
root
.
firstChildElement
(
"dict"
);
if
(
!
dictElement
.
isNull
())
{
QDomNodeList
childNodes
=
dictElement
.
childNodes
();
/* looking for something like
* ..
* <key>CFBundleDisplayName</key>
* <string>brain scans</string>
* ..
*/
void
UBGraphicsWidgetItem
::
removeDatastoreEntry
(
const
QString
&
key
)
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
;
}
QString
UBGraphicsWidgetItem
::
iconFilePath
(
const
QUrl
&
pUrl
)
{
mDatastore
.
remove
(
key
);
/* TODO UB 4.x read config.xml widget.icon param first */
QStringList
files
;
files
<<
"icon.svg"
;
/* W3C widget default 1 */
files
<<
"icon.ico"
;
/* W3C widget default 2 */
files
<<
"icon.png"
;
/* W3C widget default 3 */
files
<<
"icon.gif"
;
/* W3C widget default 4 */
files
<<
"Icon.png"
;
/* Apple widget default */
QString
file
=
UBFileSystemUtils
::
getFirstExistingFileFromList
(
pUrl
.
toLocalFile
(),
files
);
/* default */
if
(
file
.
length
()
==
0
)
{
file
=
QString
(
":/images/defaultWidgetIcon.png"
);
}
return
file
;
}
void
UBGraphicsWidgetItem
::
freeze
()
{
QPixmap
pix
=
takeSnapshot
();
mIsFrozen
=
true
;
setSnapshot
(
pix
);
}
void
UBGraphicsWidgetItem
::
removeAllDatastoreEntries
()
void
UBGraphicsWidgetItem
::
unFreeze
()
{
m
Datastore
.
clear
()
;
m
IsFrozen
=
false
;
}
void
UBGraphicsWidgetItem
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
UBGraphicsWebView
::
mousePressEvent
(
event
);
void
UBGraphicsWidgetItem
::
remove
()
// did webkit consume the mouse press ?
mShouldMoveWidget
=
!
event
->
isAccepted
()
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
);
mLastMousePos
=
mapToScene
(
event
->
pos
());
event
->
accept
();
}
void
UBGraphicsWidgetItem
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mShouldMoveWidget
=
false
;
if
(
mDelegate
)
mDelegate
->
remove
();
UBGraphicsWebView
::
mouseReleaseEvent
(
event
);
}
void
UBGraphicsWidgetItem
::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
sendJSEnterEvent
();
mDelegate
->
hoverEnterEvent
(
event
);
UBGraphicsWebView
::
hoverEnterEvent
(
event
);
}
void
UBGraphicsWidgetItem
::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
sendJSLeaveEvent
();
mDelegate
->
hoverLeaveEvent
(
event
);
UBGraphicsWebView
::
hoverLeaveEvent
(
event
);
}
void
UBGraphicsWidgetItem
::
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
UBGraphicsWebView
::
hoverMoveEvent
(
event
);
}
void
UBGraphicsWidgetItem
::
removeScript
(
)
bool
UBGraphicsWidgetItem
::
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
{
if
(
mWebKitWidget
&&
mWebKitWidget
->
page
()
&&
mWebKitWidget
->
page
()
->
mainFrame
())
{
mWebKitWidget
->
page
()
->
mainFrame
()
->
evaluateJavaScript
(
"if(widget && widget.onremove) { widget.onremove();}"
);
if
(
mShouldMoveWidget
&&
obj
==
this
&&
event
->
type
()
==
QEvent
::
MouseMove
)
{
QMouseEvent
*
mouseMoveEvent
=
static_cast
<
QMouseEvent
*>
(
event
);
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
::
sendJSEnterEvent
()
{
if
(
mWebKitWidget
&&
mWebKitWidget
->
page
()
&&
mWebKitWidget
->
page
()
->
mainFrame
())
{
mWebKitWidget
->
page
()
->
mainFrame
()
->
evaluateJavaScript
(
"if(widget && widget.onenter) { widget.onenter();}"
);
}
if
(
page
()
&&
page
()
->
mainFrame
())
page
()
->
mainFrame
()
->
evaluateJavaScript
(
"if(widget && widget.onenter) { widget.onenter();}"
);
}
void
UBGraphicsWidgetItem
::
sendJSLeaveEvent
()
{
if
(
mWebKitWidget
&&
mWebKitWidget
->
page
()
&&
mWebKitWidget
->
page
()
->
mainFrame
())
{
mWebKitWidget
->
page
()
->
mainFrame
()
->
evaluateJavaScript
(
"if(widget && widget.onleave) { widget.onleave();}"
);
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
UBGraphicsWebView
::
paint
(
painter
,
option
,
widget
);
if
(
!
mInitialLoadDone
||
mLoadIsErronous
)
{
QString
message
;
if
(
mInitialLoadDone
&&
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
)
{
re
turn
mUniboardAPI
->
ProcessDropEvent
(
event
);
re
size
(
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
);
}
UBGraphicsAppleWidgetItem
::
UBGraphicsAppleWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
)
:
UBGraphicsWidgetItem
(
parent
)
void
UBGraphicsWidgetItem
::
mainFrameLoadFinished
(
bool
ok
)
{
mWebKitWidget
=
new
UBAppleWidget
(
pWidgetUrl
,
0
);
initialize
();
mInitialLoadDone
=
true
;
mLoadIsErronous
=
!
ok
;
update
(
boundingRect
());
}
UBGraphicsAppleWidgetItem
::
UBGraphicsAppleWidgetItem
(
UBAppleWidget
*
appleWidget
,
QGraphicsItem
*
parent
)
:
UBGraphicsWidgetItem
(
parent
)
UBGraphicsAppleWidgetItem
::
UBGraphicsAppleWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
)
:
UBGraphicsWidgetItem
(
pWidgetUrl
,
parent
)
{
mWebKitWidget
=
appleWidget
;
QString
path
=
pWidgetUrl
.
toLocalFile
();
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
);
QByteArray
plistBin
=
plistFile
.
readAll
();
QString
plist
=
QString
::
fromUtf8
(
plistBin
);
int
mainHtmlIndex
=
plist
.
indexOf
(
"MainHTML"
);
int
mainHtmlIndexStart
=
plist
.
indexOf
(
"<string>"
,
mainHtmlIndex
);
int
mainHtmlIndexEnd
=
plist
.
indexOf
(
"</string>"
,
mainHtmlIndexStart
);
if
(
mainHtmlIndex
>
-
1
&&
mainHtmlIndexStart
>
-
1
&&
mainHtmlIndexEnd
>
-
1
)
mMainHtmlFileName
=
plist
.
mid
(
mainHtmlIndexStart
+
8
,
mainHtmlIndexEnd
-
mainHtmlIndexStart
-
8
);
mMainHtmlUrl
=
pWidgetUrl
;
mMainHtmlUrl
.
setPath
(
pWidgetUrl
.
path
()
+
"/"
+
mMainHtmlFileName
);
load
(
mMainHtmlUrl
);
QPixmap
defaultPixmap
(
pWidgetUrl
.
toLocalFile
()
+
"/Default.png"
);
setMaximumSize
(
defaultPixmap
.
size
());
mNominalSize
=
defaultPixmap
.
size
();
initialize
();
}
...
...
@@ -322,13 +660,23 @@ UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(UBAppleWidget *appleWidget,
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
(
mWebKitWidget
->
widgetU
rl
(),
parentItem
());
UBGraphicsAppleWidgetItem
*
appleWidget
=
new
UBGraphicsAppleWidgetItem
(
QGraphicsWebView
::
u
rl
(),
parentItem
());
copyItemParameters
(
appleWidget
);
...
...
@@ -355,38 +703,183 @@ void UBGraphicsAppleWidgetItem::copyItemParameters(UBItem *copy) const
}
}
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
}
UBGraphicsW3CWidgetItem
::
UBGraphicsW3CWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
,
int
widgetType
)
:
UBGraphicsWidgetItem
(
parent
,
widgetType
)
bool
UBGraphicsW3CWidgetItem
::
sTemplateLoaded
=
false
;
QString
UBGraphicsW3CWidgetItem
::
sNPAPIWrappperConfigTemplate
;
QMap
<
QString
,
QString
>
UBGraphicsW3CWidgetItem
::
sNPAPIWrapperTemplates
;
UBGraphicsW3CWidgetItem
::
UBGraphicsW3CWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
)
:
UBGraphicsWidgetItem
(
pWidgetUrl
,
parent
)
,
mW3CWidgetAPI
(
0
)
{
mW3CWidget
=
new
UBW3CWidget
(
pWidgetUrl
,
0
);
mWebKitWidget
=
mW3CWidget
;
QString
path
=
pWidgetUrl
.
toLocalFile
();
QDir
potentialDir
(
path
);
if
(
!
path
.
endsWith
(
".wgt"
)
&&
!
path
.
endsWith
(
".wgt/"
)
&&
!
potentialDir
.
exists
())
{
int
lastSlashIndex
=
path
.
lastIndexOf
(
"/"
);
if
(
lastSlashIndex
>
0
)
path
=
path
.
mid
(
0
,
lastSlashIndex
+
1
);
}
if
(
!
path
.
endsWith
(
"/"
))
path
+=
"/"
;
int
width
=
300
;
int
height
=
150
;
QFile
configFile
(
path
+
"config.xml"
);
configFile
.
open
(
QFile
::
ReadOnly
);
QDomDocument
doc
;
doc
.
setContent
(
configFile
.
readAll
());
QDomNodeList
widgetDomList
=
doc
.
elementsByTagName
(
"widget"
);
if
(
widgetDomList
.
count
()
>
0
)
{
QDomElement
widgetElement
=
widgetDomList
.
item
(
0
).
toElement
();
width
=
widgetElement
.
attribute
(
"width"
,
"300"
).
toInt
();
height
=
widgetElement
.
attribute
(
"height"
,
"150"
).
toInt
();
mMetadatas
.
id
=
widgetElement
.
attribute
(
"id"
,
""
);
/* some early widget (<= 4.3.4) where using identifier instead of id */
if
(
mMetadatas
.
id
.
length
()
==
0
)
mMetadatas
.
id
=
widgetElement
.
attribute
(
"identifier"
,
""
);
mMetadatas
.
version
=
widgetElement
.
attribute
(
"version"
,
""
);
/* TODO UB 4.x map properly ub namespace */
mIsResizable
=
widgetElement
.
attribute
(
"ub:resizable"
,
"false"
)
==
"true"
;
mIsFreezable
=
widgetElement
.
attribute
(
"ub:freezable"
,
"true"
)
==
"true"
;
QString
roles
=
widgetElement
.
attribute
(
"ub:roles"
,
"content tool"
).
trimmed
().
toLower
();
/* ------------------------------ */
if
(
roles
==
""
||
roles
.
contains
(
"tool"
))
mCanBeTool
=
UBGraphicsWidgetItem
::
type_ALL
;
if
(
roles
.
contains
(
"twin"
))
mCanBeTool
|=
UBGraphicsWidgetItem
::
type_WIN
;
if
(
roles
.
contains
(
"tmac"
))
mCanBeTool
|=
UBGraphicsWidgetItem
::
type_MAC
;
if
(
roles
.
contains
(
"tunix"
))
mCanBeTool
|=
UBGraphicsWidgetItem
::
type_UNIX
;
/* --------- */
if
(
roles
==
""
||
roles
.
contains
(
"content"
))
mCanBeContent
=
UBGraphicsWidgetItem
::
type_ALL
;
if
(
roles
.
contains
(
"cwin"
))
mCanBeContent
|=
UBGraphicsWidgetItem
::
type_WIN
;
if
(
roles
.
contains
(
"cmac"
))
mCanBeContent
|=
UBGraphicsWidgetItem
::
type_MAC
;
if
(
roles
.
contains
(
"cunix"
))
mCanBeContent
|=
UBGraphicsWidgetItem
::
type_UNIX
;
//------------------------------//
QDomNodeList
contentDomList
=
widgetElement
.
elementsByTagName
(
"content"
);
if
(
contentDomList
.
count
()
>
0
)
{
QDomElement
contentElement
=
contentDomList
.
item
(
0
).
toElement
();
mMainHtmlFileName
=
contentElement
.
attribute
(
"src"
,
""
);
}
mMetadatas
.
name
=
textForSubElementByLocale
(
widgetElement
,
"name"
,
QLocale
::
system
());
mMetadatas
.
description
=
textForSubElementByLocale
(
widgetElement
,
"description "
,
QLocale
::
system
());
QDomNodeList
authorDomList
=
widgetElement
.
elementsByTagName
(
"author"
);
if
(
authorDomList
.
count
()
>
0
)
{
QDomElement
authorElement
=
authorDomList
.
item
(
0
).
toElement
();
mMetadatas
.
author
=
authorElement
.
text
();
mMetadatas
.
authorHref
=
authorElement
.
attribute
(
"href"
,
""
);
mMetadatas
.
authorEmail
=
authorElement
.
attribute
(
"email "
,
""
);
}
QDomNodeList
propertiesDomList
=
widgetElement
.
elementsByTagName
(
"preference"
);
for
(
uint
i
=
0
;
i
<
propertiesDomList
.
length
();
i
++
)
{
QDomElement
preferenceElement
=
propertiesDomList
.
at
(
i
).
toElement
();
QString
prefName
=
preferenceElement
.
attribute
(
"name"
,
""
);
if
(
prefName
.
length
()
>
0
)
{
QString
prefValue
=
preferenceElement
.
attribute
(
"value"
,
""
);
bool
readOnly
=
(
preferenceElement
.
attribute
(
"readonly"
,
"false"
)
==
"true"
);
mPreferences
.
insert
(
prefName
,
PreferenceValue
(
prefValue
,
readOnly
));
}
}
}
if
(
mMainHtmlFileName
.
length
()
==
0
)
{
QFile
defaultStartFile
(
path
+
"index.htm"
);
if
(
defaultStartFile
.
exists
())
mMainHtmlFileName
=
"index.htm"
;
else
{
QFile
secondDefaultStartFile
(
path
+
"index.html"
);
if
(
secondDefaultStartFile
.
exists
())
mMainHtmlFileName
=
"index.html"
;
}
}
mMainHtmlUrl
=
pWidgetUrl
;
mMainHtmlUrl
.
setPath
(
pWidgetUrl
.
path
()
+
"/"
+
mMainHtmlFileName
);
/* is it a valid local file ? */
QFile
f
(
mMainHtmlUrl
.
toLocalFile
());
if
(
!
f
.
exists
())
mMainHtmlUrl
=
QUrl
(
mMainHtmlFileName
);
connect
(
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
load
(
mMainHtmlUrl
);
setMaximumSize
(
QSize
(
width
,
height
));
mNominalSize
=
QSize
(
width
,
height
);
initialize
();
setOwnFolder
(
pWidgetUrl
);
}
UBGraphicsW3CWidgetItem
::
UBGraphicsW3CWidgetItem
(
UBW3CWidget
*
w3cWidget
,
QGraphicsItem
*
parent
,
int
widgetType
)
:
UBGraphicsWidgetItem
(
parent
)
,
mW3CWidget
(
w3cWidget
)
,
mW3CWidgetAPI
(
0
)
UBGraphicsW3CWidgetItem
::~
UBGraphicsW3CWidgetItem
()
{
Q_UNUSED
(
widgetType
);
mWebKitWidget
=
mW3CWidget
;
initialize
();
/* NOOP */
}
int
UBGraphicsW3CWidgetItem
::
type
()
const
{
return
Type
;
}
UBGraphicsW3CWidgetItem
::~
UBGraphicsW3CWidgetItem
(
)
void
UBGraphicsW3CWidgetItem
::
setUuid
(
const
QUuid
&
pUuid
)
{
// NOOP
UBItem
::
setUuid
(
pUuid
);
setData
(
UBGraphicsItemData
::
ItemUuid
,
QVariant
(
pUuid
));
//store item uuid inside the QGraphicsItem to fast operations with Items on the scene
}
UBItem
*
UBGraphicsW3CWidgetItem
::
deepCopy
()
const
{
UBGraphicsW3CWidgetItem
*
copy
=
new
UBGraphicsW3CWidgetItem
(
mWidgetUrl
,
parentItem
());
copy
->
setUuid
(
this
->
uuid
());
// this is OK for now as long as Widgets are imutable
copyItemParameters
(
copy
);
return
copy
;
}
void
UBGraphicsW3CWidgetItem
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
...
...
@@ -395,23 +888,222 @@ void UBGraphicsW3CWidgetItem::paint(QPainter * painter, const QStyleOptionGraphi
if
(
scene
())
rc
=
scene
()
->
renderingContext
();
if
((
!
w3cWidget
()
->
hasLoadedSuccessfully
())
&&
(
rc
==
UBGraphicsScene
::
NonScreen
||
rc
==
UBGraphicsScene
::
PdfExport
))
{
if
(
!
w3cWidget
()
->
snapshot
().
isNull
())
{
painter
->
drawPixmap
(
0
,
0
,
w3cWidget
()
->
snapshot
());
if
(
rc
==
UBGraphicsScene
::
NonScreen
||
rc
==
UBGraphicsScene
::
PdfExport
)
{
if
(
!
snapshot
().
isNull
())
painter
->
drawPixmap
(
0
,
0
,
snapshot
());
}
else
UBGraphicsWidgetItem
::
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
)
{
const
QString
userWidgetPath
=
UBSettings
::
settings
()
->
userInteractiveDirectory
()
+
"/"
+
tr
(
"Web"
);
QDir
userWidgetDir
(
userWidgetPath
);
return
createNPAPIWrapperInDir
(
url
,
userWidgetDir
,
pMimeType
,
sizeHint
,
pName
);
}
QString
UBGraphicsW3CWidgetItem
::
createNPAPIWrapperInDir
(
const
QString
&
pUrl
,
const
QDir
&
pDir
,
const
QString
&
pMimeType
,
const
QSize
&
sizeHint
,
const
QString
&
pName
)
{
QString
url
=
pUrl
;
url
=
UBFileSystemUtils
::
removeLocalFilePrefix
(
url
);
QString
name
=
pName
;
QFileInfo
fi
(
url
);
if
(
name
.
length
()
==
0
)
name
=
fi
.
baseName
();
if
(
fi
.
exists
())
url
=
fi
.
fileName
();
loadNPAPIWrappersTemplates
();
QString
htmlTemplate
;
if
(
pMimeType
.
length
()
>
0
&&
sNPAPIWrapperTemplates
.
contains
(
pMimeType
))
htmlTemplate
=
sNPAPIWrapperTemplates
.
value
(
pMimeType
);
else
{
QString
extension
=
UBFileSystemUtils
::
extension
(
url
);
if
(
sNPAPIWrapperTemplates
.
contains
(
extension
))
htmlTemplate
=
sNPAPIWrapperTemplates
.
value
(
extension
);
}
if
(
htmlTemplate
.
length
()
>
0
)
{
htmlTemplate
=
htmlTemplate
.
replace
(
QString
(
"{in.url}"
),
url
)
.
replace
(
QString
(
"{in.width}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
width
()))
.
replace
(
QString
(
"{in.height}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
height
()));
QString
configTemplate
=
sNPAPIWrappperConfigTemplate
.
replace
(
QString
(
"{in.id}"
),
url
)
.
replace
(
QString
(
"{in.width}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
width
()))
.
replace
(
QString
(
"{in.height}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
height
()))
.
replace
(
QString
(
"{in.name}"
),
name
)
.
replace
(
QString
(
"{in.startFile}"
),
QString
(
"index.htm"
));
QString
dirPath
=
pDir
.
path
();
if
(
!
pDir
.
exists
())
pDir
.
mkpath
(
dirPath
);
QString
widgetLibraryPath
=
dirPath
+
"/"
+
name
+
".wgt"
;
QDir
widgetLibraryDir
(
widgetLibraryPath
);
if
(
widgetLibraryDir
.
exists
())
if
(
!
UBFileSystemUtils
::
deleteDir
(
widgetLibraryDir
.
path
()))
qWarning
()
<<
"Cannot delete old widget "
<<
widgetLibraryDir
.
path
();
widgetLibraryDir
.
mkpath
(
widgetLibraryPath
);
if
(
fi
.
exists
())
{
QString
target
=
widgetLibraryPath
+
"/"
+
fi
.
fileName
();
QString
source
=
pUrl
;
source
=
UBFileSystemUtils
::
removeLocalFilePrefix
(
source
);
QFile
::
copy
(
source
,
target
);
}
QFile
configFile
(
widgetLibraryPath
+
"/config.xml"
);
if
(
!
configFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"Cannot open file "
<<
configFile
.
fileName
();
return
QString
();
}
QTextStream
outConfig
(
&
configFile
);
outConfig
.
setCodec
(
"UTF-8"
);
outConfig
<<
configTemplate
;
configFile
.
close
();
QFile
indexFile
(
widgetLibraryPath
+
"/index.htm"
);
if
(
!
indexFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"Cannot open file "
<<
indexFile
.
fileName
();
return
QString
();
}
QTextStream
outIndex
(
&
indexFile
);
outIndex
.
setCodec
(
"UTF-8"
);
outIndex
<<
htmlTemplate
;
indexFile
.
close
();
return
widgetLibraryPath
;
}
else
{
UBGraphicsProxyWidget
::
paint
(
painter
,
option
,
widget
);
return
QString
();
}
QString
UBGraphicsW3CWidgetItem
::
createHtmlWrapperInDir
(
const
QString
&
html
,
const
QDir
&
pDir
,
const
QSize
&
sizeHint
,
const
QString
&
pName
)
{
QString
widgetPath
=
pDir
.
path
()
+
"/"
+
pName
+
".wgt"
;
widgetPath
=
UBFileSystemUtils
::
nextAvailableFileName
(
widgetPath
);
QDir
widgetDir
(
widgetPath
);
if
(
!
widgetDir
.
exists
())
widgetDir
.
mkpath
(
widgetDir
.
path
());
QFile
configFile
(
widgetPath
+
"/"
+
"config.xml"
);
if
(
configFile
.
exists
())
configFile
.
remove
(
configFile
.
fileName
());
if
(
!
configFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"Cannot open file "
<<
configFile
.
fileName
();
return
""
;
}
QTextStream
outConfig
(
&
configFile
);
outConfig
.
setCodec
(
"UTF-8"
);
outConfig
<<
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
<<
endl
;
outConfig
<<
"<widget xmlns=
\"
http://www.w3.org/ns/widgets
\"
"
<<
endl
;
outConfig
<<
" xmlns:ub=
\"
http://uniboard.mnemis.com/widgets
\"
"
<<
endl
;
outConfig
<<
" id=
\"
http://uniboard.mnemis.com/"
<<
pName
<<
"
\"
"
<<
endl
;
outConfig
<<
" version=
\"
1.0
\"
"
<<
endl
;
outConfig
<<
" width=
\"
"
<<
sizeHint
.
width
()
<<
"
\"
"
<<
endl
;
outConfig
<<
" height=
\"
"
<<
sizeHint
.
height
()
<<
"
\"
"
<<
endl
;
outConfig
<<
" ub:resizable=
\"
true
\"
>"
<<
endl
;
outConfig
<<
" <name>"
<<
pName
<<
"</name>"
<<
endl
;
outConfig
<<
" <content src=
\"
"
<<
pName
<<
".html
\"
/>"
<<
endl
;
outConfig
<<
"</widget>"
<<
endl
;
configFile
.
close
();
const
QString
fullHtmlFileName
=
widgetPath
+
"/"
+
pName
+
".html"
;
QFile
widgetHtmlFile
(
fullHtmlFileName
);
if
(
widgetHtmlFile
.
exists
())
widgetHtmlFile
.
remove
(
widgetHtmlFile
.
fileName
());
if
(
!
widgetHtmlFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"cannot open file "
<<
widgetHtmlFile
.
fileName
();
return
QString
();
}
QTextStream
outStartFile
(
&
widgetHtmlFile
);
outStartFile
.
setCodec
(
"UTF-8"
);
outStartFile
<<
"<!DOCTYPE HTML PUBLIC
\"
-//W3C//DTD HTML 4.01//EN
\"
\"
http://www.w3.org/TR/html4/strict.dtd
\"
>"
<<
endl
;
outStartFile
<<
"<html>"
<<
endl
;
outStartFile
<<
"<head>"
<<
endl
;
outStartFile
<<
" <meta http-equiv=
\"
content-type
\"
content=
\"
text/html; charset=utf-8
\"
>"
<<
endl
;
outStartFile
<<
"</head>"
<<
endl
;
outStartFile
<<
" <body>"
<<
endl
;
outStartFile
<<
html
<<
endl
;
outStartFile
<<
" </body>"
<<
endl
;
outStartFile
<<
"</html>"
<<
endl
;
widgetHtmlFile
.
close
();
return
widgetPath
;
}
QString
UBGraphicsW3CWidgetItem
::
freezedWidgetPage
()
{
static
QString
defaultcontent
;
if
(
defaultcontent
.
isNull
())
{
QString
freezedWidgetDefaultContentFilePath
=
freezedWidgetFilePath
();
QFile
wrapperFile
(
freezedWidgetDefaultContentFilePath
);
if
(
!
wrapperFile
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
qDebug
()
<<
"can't open wrapper file "
+
freezedWidgetDefaultContentFilePath
;
defaultcontent
=
""
;
}
else
{
QByteArray
arr
=
wrapperFile
.
readAll
();
if
(
!
arr
.
isEmpty
())
defaultcontent
=
QString
(
arr
);
else
{
qDebug
()
<<
"content of "
+
freezedWidgetDefaultContentFilePath
+
"is empty"
;
defaultcontent
=
QString
();
}
}
}
return
defaultcontent
;
}
void
UBGraphicsW3CWidgetItem
::
setUuid
(
const
QUuid
&
pUuid
)
QString
UBGraphicsW3CWidgetItem
::
freezedWidgetFilePath
(
)
{
UBItem
::
setUuid
(
pUuid
);
setData
(
UBGraphicsItemData
::
ItemUuid
,
QVariant
(
pUuid
));
//store item uuid inside the QGraphicsItem to fast operations with Items on the scene
return
UBPlatformUtils
::
applicationResourcesDirectory
()
+
"/etc/"
+
"freezedWidgetWrapper.html"
;
}
bool
UBGraphicsW3CWidgetItem
::
hasNPAPIWrapper
(
const
QString
&
pMimeType
)
{
loadNPAPIWrappersTemplates
();
return
sNPAPIWrapperTemplates
.
contains
(
pMimeType
);
}
void
UBGraphicsW3CWidgetItem
::
javaScriptWindowObjectCleared
()
...
...
@@ -421,30 +1113,71 @@ void UBGraphicsW3CWidgetItem::javaScriptWindowObjectCleared()
if
(
!
mW3CWidgetAPI
)
mW3CWidgetAPI
=
new
UBW3CWidgetAPI
(
this
);
mWebKitWidget
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"widget"
,
mW3CWidgetAPI
);
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"widget"
,
mW3CWidgetAPI
);
}
UBW3CWidget
::
Metadata
UBGraphicsW3CWidgetItem
::
metadatas
()
const
void
UBGraphicsW3CWidgetItem
::
loadNPAPIWrappersTemplates
()
{
return
mW3CWidget
->
metadatas
();
}
if
(
!
sTemplateLoaded
)
{
sNPAPIWrapperTemplates
.
clear
();
QString
etcPath
=
UBPlatformUtils
::
applicationResourcesDirectory
()
+
"/etc/"
;
UBW3CWidget
*
UBGraphicsW3CWidgetItem
::
w3cWidget
()
const
{
return
mW3CWidget
;
}
QDir
etcDir
(
etcPath
);
foreach
(
QString
fileName
,
etcDir
.
entryList
())
{
if
(
fileName
.
startsWith
(
"npapi-wrapper"
)
&&
(
fileName
.
endsWith
(
".htm"
)
||
fileName
.
endsWith
(
".html"
)))
{
UBItem
*
UBGraphicsW3CWidgetItem
::
deepCopy
()
const
QString
htmlContent
=
UBFileSystemUtils
::
readTextFile
(
etcPath
+
fileName
);
if
(
htmlContent
.
length
()
>
0
)
{
QStringList
tokens
=
fileName
.
split
(
"."
);
if
(
tokens
.
length
()
>=
4
)
{
QString
mime
=
tokens
.
at
(
tokens
.
length
()
-
4
);
mime
+=
"/"
+
tokens
.
at
(
tokens
.
length
()
-
3
);
QString
fileExtension
=
tokens
.
at
(
tokens
.
length
()
-
2
);
sNPAPIWrapperTemplates
.
insert
(
mime
,
htmlContent
);
sNPAPIWrapperTemplates
.
insert
(
fileExtension
,
htmlContent
);
}
}
}
}
sNPAPIWrappperConfigTemplate
=
UBFileSystemUtils
::
readTextFile
(
etcPath
+
"npapi-wrapper.config.xml"
);
sTemplateLoaded
=
true
;
}
}
QString
UBGraphicsW3CWidgetItem
::
textForSubElementByLocale
(
QDomElement
rootElement
,
QString
subTagName
,
QLocale
locale
)
{
UBGraphicsW3CWidgetItem
*
copy
=
new
UBGraphicsW3CWidgetItem
(
mWebKitWidget
->
widgetUrl
(),
parentItem
());
copy
->
setUuid
(
this
->
uuid
());
// this is OK for now as long as Widgets are imutable
copyItemParameters
(
copy
);
QDomNodeList
subList
=
rootElement
.
elementsByTagName
(
subTagName
);
return
copy
;
QString
lang
=
locale
.
name
();
if
(
lang
.
length
()
>
2
)
lang
[
2
]
=
QLatin1Char
(
'-'
);
if
(
subList
.
count
()
>
1
)
{
for
(
int
i
=
0
;
i
<
subList
.
count
();
i
++
)
{
QDomNode
node
=
subList
.
at
(
i
);
QDomElement
element
=
node
.
toElement
();
QString
configLang
=
element
.
attribute
(
"xml:lang"
,
""
);
if
(
lang
==
configLang
||
(
configLang
.
length
()
==
2
&&
configLang
==
lang
.
left
(
2
)))
return
element
.
text
();
}
}
if
(
subList
.
count
()
>=
1
)
{
QDomElement
element
=
subList
.
item
(
0
).
toElement
();
return
element
.
text
();
}
return
QString
();
}
void
UBGraphicsW3CWidgetItem
::
copyItemParameters
(
UBItem
*
copy
)
const
...
...
@@ -462,9 +1195,9 @@ void UBGraphicsW3CWidgetItem::copyItemParameters(UBItem *copy) const
cp
->
resize
(
this
->
size
());
foreach
(
QString
key
,
mPreferences
.
keys
())
foreach
(
QString
key
,
UBGraphicsWidgetItem
::
preferences
()
.
keys
())
{
cp
->
setPreference
(
key
,
mPreferences
.
value
(
key
));
cp
->
setPreference
(
key
,
UBGraphicsWidgetItem
::
preferences
()
.
value
(
key
));
}
foreach
(
QString
key
,
mDatastore
.
keys
())
...
...
@@ -473,3 +1206,4 @@ void UBGraphicsW3CWidgetItem::copyItemParameters(UBItem *copy) const
}
}
}
src/domain/UBGraphicsWidgetItem.h
View file @
e6be59ce
...
...
@@ -17,100 +17,153 @@
#include <QtGui>
#include <QtWebKit>
#include <QDomElement>
#include "
core/UB
.h"
#include "
UBGraphicsWebView
.h"
#include "UBGraphicsProxyWidget.h"
#include "UBW3CWidget.h"
#include "UBAppleWidget.h"
#include "core/UB.h"
class
UBWidgetUniboardAPI
;
class
UBGraphicsScene
;
class
UBAbstractWidget
;
class
UBW3CWidgetAPI
;
class
UBW3CWidgetWebStorageAPI
;
class
UBGraphiscItem
;
class
UBGraphiscItemDelegate
;
class
UBGraphicsWidgetItem
:
public
UBGraphicsProxyWidget
struct
UBWidgetType
{
enum
Enum
{
W3C
=
0
,
Apple
,
Other
};
};
class
UBGraphicsWidgetItem
:
public
UBGraphicsWebView
{
Q_OBJECT
public
:
UBGraphicsWidgetItem
(
QGraphicsItem
*
parent
=
0
,
int
widgetType
=
0
);
UBGraphicsWidgetItem
(
const
QUrl
&
pWidgetUrl
=
QUrl
(),
QGraphicsItem
*
parent
=
0
);
~
UBGraphicsWidgetItem
();
virtual
UBGraphicsScene
*
scene
();
UBAbstractWidget
*
widgetWebView
();
virtual
void
initialize
();
virtual
UBItem
*
deepCopy
()
const
=
0
;
QUrl
mainHtml
();
void
loadMainHtml
();
QUrl
widgetUrl
();
QString
mainHtmlFileName
();
virtual
void
resize
(
qreal
w
,
qreal
h
);
virtual
void
resize
(
const
QSizeF
&
size
);
bool
hasEmbededObjects
();
bool
hasEmbededFlash
();
bool
canBeContent
();
bool
canBeTool
();
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
();
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
);
QSize
nominalSize
()
const
;
bool
hasLoadedSuccessfully
()
const
;
bool
freezable
();
bool
resizable
();
bool
isFrozen
();
QPixmap
snapshot
();
void
setSnapshot
(
const
QPixmap
&
pix
);
QPixmap
takeSnapshot
();
virtual
UBItem
*
deepCopy
()
const
=
0
;
virtual
UBGraphicsScene
*
scene
();
static
int
widgetType
(
const
QUrl
&
pUrl
);
static
QString
widgetName
(
const
QUrl
&
pUrl
);
static
QString
iconFilePath
(
const
QUrl
&
pUrl
);
public
slots
:
void
freeze
();
void
unFreeze
();
protected
:
enum
OSType
{
type_NONE
=
0
,
// 0000
type_WIN
=
1
,
// 0001
type_MAC
=
2
,
// 0010
type_UNIX
=
4
,
// 0100
type_ALL
=
7
,
// 0111
};
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
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
();
UBAbstractWidget
*
mWebKitWidget
;
QMap
<
QString
,
QString
>
mPreferences
;
QMap
<
QString
,
QString
>
mDatastore
;
virtual
void
injectInlineJavaScript
();
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
=
0
);
protected
slots
:
void
geometryChangeRequested
(
const
QRect
&
geom
);
virtual
void
javaScriptWindowObjectCleared
();
void
mainFrameLoadFinished
(
bool
ok
);
private
:
QPointF
mLastMousePos
;
bool
mIsFrozen
;
bool
mIsTakingSnapshot
;
bool
mShouldMoveWidget
;
UBWidgetUniboardAPI
*
mUniboardAPI
;
QPixmap
mSnapshot
;
QPointF
mLastMousePos
;
QUrl
ownFolder
;
QUrl
SnapshotFile
;
static
bool
sInlineJavaScriptLoaded
;
static
QStringList
sInlineJavaScripts
;
};
class
UBGraphicsAppleWidgetItem
:
public
UBGraphicsWidgetItem
...
...
@@ -119,21 +172,17 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
public
:
UBGraphicsAppleWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
=
0
);
UBGraphicsAppleWidgetItem
(
UBAppleWidget
*
appleWidget
,
QGraphicsItem
*
parent
=
0
);
~
UBGraphicsAppleWidgetItem
();
enum
{
Type
=
UBGraphicsItemType
::
AppleWidgetItemType
};
virtual
int
type
()
const
{
return
Type
;
}
virtual
UBItem
*
deepCopy
()
const
;
virtual
void
copyItemParameters
(
UBItem
*
copy
)
const
;
virtual
int
type
()
const
;
virtual
void
setUuid
(
const
QUuid
&
pUuid
);
virtual
UBItem
*
deepCopy
()
const
;
enum
{
Type
=
UBGraphicsItemType
::
AppleWidgetItemType
};
};
...
...
@@ -142,38 +191,76 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
Q_OBJECT
public
:
UBGraphicsW3CWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
=
0
,
int
widgetType
=
UBGraphicsItemType
::
W3CWidgetItemType
);
UBGraphicsW3CWidgetItem
(
UBW3CWidget
*
w3cWidget
,
QGraphicsItem
*
parent
=
0
,
int
widgetType
=
UBGraphicsItemType
::
W3CWidgetItemType
);
~
UBGraphicsW3CWidgetItem
();
enum
{
Type
=
UBGraphicsItemType
::
W3CWidgetItemType
};
class
PreferenceValue
{
public
:
virtual
int
type
()
const
PreferenceValue
()
{
return
Type
;
/* NOOP */
}
virtual
UBItem
*
deepCopy
()
const
;
virtual
void
copyItemParameters
(
UBItem
*
copy
)
const
;
PreferenceValue
(
const
QString
&
pValue
,
bool
pReadonly
)
{
value
=
pValue
;
readonly
=
pReadonly
;
}
UBW3CWidget
::
Metadata
metadatas
()
const
;
bool
readonly
;
QString
value
;
};
UBW3CWidget
*
w3cWidget
()
const
;
class
Metadata
{
public
:
QString
id
;
QString
name
;
QString
description
;
QString
author
;
QString
authorEmail
;
QString
authorHref
;
QString
version
;
};
enum
{
Type
=
UBGraphicsItemType
::
W3CWidgetItemType
};
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
UBGraphicsW3CWidgetItem
(
const
QUrl
&
pWidgetUrl
,
QGraphicsItem
*
parent
=
0
);
~
UBGraphicsW3CWidgetItem
();
virtual
int
type
()
const
;
virtual
void
setUuid
(
const
QUuid
&
pUuid
);
virtual
UBItem
*
deepCopy
()
const
;
virtual
void
copyItemParameters
(
UBItem
*
copy
)
const
;
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
QMap
<
QString
,
PreferenceValue
>
preferences
();
Metadata
metadatas
()
const
;
private
slots
:
static
QString
freezedWidgetFilePath
();
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
:
static
void
loadNPAPIWrappersTemplates
();
static
QString
textForSubElementByLocale
(
QDomElement
rootElement
,
QString
subTagName
,
QLocale
locale
);
UBW3CWidget
*
mW3CWidget
;
UBW3CWidgetAPI
*
mW3CWidgetAPI
;
QMap
<
QString
,
PreferenceValue
>
mPreferences
;
static
bool
sTemplateLoaded
;
static
QString
sNPAPIWrappperConfigTemplate
;
static
QMap
<
QString
,
QString
>
sNPAPIWrapperTemplates
;
};
#endif // UBGRAPHICSWIDGETITEM_H
src/domain/UBGraphicsWidgetItemDelegate.cpp
View file @
e6be59ce
...
...
@@ -55,7 +55,7 @@ void UBGraphicsWidgetItemDelegate::updateMenuActionState()
UBGraphicsItemDelegate
::
updateMenuActionState
();
if
(
freezeAction
)
freezeAction
->
setChecked
(
delegated
()
->
widgetWebView
()
->
isFrozen
());
freezeAction
->
setChecked
(
delegated
()
->
isFrozen
());
}
void
UBGraphicsWidgetItemDelegate
::
decorateMenu
(
QMenu
*
menu
)
...
...
@@ -71,7 +71,7 @@ void UBGraphicsWidgetItemDelegate::decorateMenu(QMenu* menu)
freezeAction
->
setCheckable
(
true
);
if
(
delegated
()
->
widgetWebView
()
->
canBeTool
())
if
(
delegated
()
->
canBeTool
())
{
setAsToolAction
=
mMenu
->
addAction
(
tr
(
"Transform as Tool "
),
this
,
SLOT
(
pin
()));
QIcon
pinIcon
;
...
...
@@ -86,11 +86,11 @@ void UBGraphicsWidgetItemDelegate::freeze(bool frozen)
{
if
(
frozen
)
{
delegated
()
->
widgetWebView
()
->
freeze
();
delegated
()
->
freeze
();
}
else
{
delegated
()
->
widgetWebView
()
->
unFreeze
();
delegated
()
->
unFreeze
();
}
}
...
...
src/domain/UBW3CWidget.cpp
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBW3CWidget.h"
#include <QtNetwork>
#include <QtXml>
#include "frameworks/UBPlatformUtils.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "api/UBWidgetUniboardAPI.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
bool
UBW3CWidget
::
sTemplateLoaded
=
false
;
QMap
<
QString
,
QString
>
UBW3CWidget
::
sNPAPIWrapperTemplates
;
QString
UBW3CWidget
::
sNPAPIWrappperConfigTemplate
;
UBW3CWidget
::
UBW3CWidget
(
const
QUrl
&
pWidgetUrl
,
QWidget
*
parent
)
:
UBAbstractWidget
(
pWidgetUrl
,
parent
)
{
QString
path
=
pWidgetUrl
.
toLocalFile
();
QDir
potentialDir
(
path
);
if
(
!
path
.
endsWith
(
".wgt"
)
&&
!
path
.
endsWith
(
".wgt/"
)
&&
!
potentialDir
.
exists
())
{
int
lastSlashIndex
=
path
.
lastIndexOf
(
"/"
);
if
(
lastSlashIndex
>
0
)
{
path
=
path
.
mid
(
0
,
lastSlashIndex
+
1
);
}
}
if
(
!
path
.
endsWith
(
"/"
))
path
+=
"/"
;
int
width
=
300
;
int
height
=
150
;
QFile
configFile
(
path
+
"config.xml"
);
configFile
.
open
(
QFile
::
ReadOnly
);
QDomDocument
doc
;
doc
.
setContent
(
configFile
.
readAll
());
QDomNodeList
widgetDomList
=
doc
.
elementsByTagName
(
"widget"
);
if
(
widgetDomList
.
count
()
>
0
)
{
QDomElement
widgetElement
=
widgetDomList
.
item
(
0
).
toElement
();
width
=
widgetElement
.
attribute
(
"width"
,
"300"
).
toInt
();
height
=
widgetElement
.
attribute
(
"height"
,
"150"
).
toInt
();
mMetadatas
.
id
=
widgetElement
.
attribute
(
"id"
,
""
);
//some early widget (<= 4.3.4) where using identifier instead of id
if
(
mMetadatas
.
id
.
length
()
==
0
)
mMetadatas
.
id
=
widgetElement
.
attribute
(
"identifier"
,
""
);
mMetadatas
.
version
=
widgetElement
.
attribute
(
"version"
,
""
);
// TODO UB 4.x map properly ub namespace
mIsResizable
=
widgetElement
.
attribute
(
"ub:resizable"
,
"false"
)
==
"true"
;
mIsFreezable
=
widgetElement
.
attribute
(
"ub:freezable"
,
"true"
)
==
"true"
;
QString
roles
=
widgetElement
.
attribute
(
"ub:roles"
,
"content tool"
).
trimmed
().
toLower
();
//------------------------------//
if
(
roles
==
""
||
roles
.
contains
(
"tool"
)
)
{
mCanBeTool
=
UBAbstractWidget
::
type_ALL
;
}
if
(
roles
.
contains
(
"twin"
)
)
{
mCanBeTool
|=
UBAbstractWidget
::
type_WIN
;
}
if
(
roles
.
contains
(
"tmac"
)
)
{
mCanBeTool
|=
UBAbstractWidget
::
type_MAC
;
}
if
(
roles
.
contains
(
"tunix"
)
)
{
mCanBeTool
|=
UBAbstractWidget
::
type_UNIX
;
}
//---------//
if
(
roles
==
""
||
roles
.
contains
(
"content"
)
)
{
mCanBeContent
=
UBAbstractWidget
::
type_ALL
;
}
if
(
roles
.
contains
(
"cwin"
)
)
{
mCanBeContent
|=
UBAbstractWidget
::
type_WIN
;
}
if
(
roles
.
contains
(
"cmac"
)
)
{
mCanBeContent
|=
UBAbstractWidget
::
type_MAC
;
}
if
(
roles
.
contains
(
"cunix"
)
)
{
mCanBeContent
|=
UBAbstractWidget
::
type_UNIX
;
}
//------------------------------//
QDomNodeList
contentDomList
=
widgetElement
.
elementsByTagName
(
"content"
);
if
(
contentDomList
.
count
()
>
0
)
{
QDomElement
contentElement
=
contentDomList
.
item
(
0
).
toElement
();
mMainHtmlFileName
=
contentElement
.
attribute
(
"src"
,
""
);
}
mMetadatas
.
name
=
textForSubElementByLocale
(
widgetElement
,
"name"
,
locale
());
mMetadatas
.
description
=
textForSubElementByLocale
(
widgetElement
,
"description "
,
locale
());
QDomNodeList
authorDomList
=
widgetElement
.
elementsByTagName
(
"author"
);
if
(
authorDomList
.
count
()
>
0
)
{
QDomElement
authorElement
=
authorDomList
.
item
(
0
).
toElement
();
mMetadatas
.
author
=
authorElement
.
text
();
mMetadatas
.
authorHref
=
authorElement
.
attribute
(
"href"
,
""
);
mMetadatas
.
authorEmail
=
authorElement
.
attribute
(
"email "
,
""
);
}
QDomNodeList
propertiesDomList
=
widgetElement
.
elementsByTagName
(
"preference"
);
for
(
uint
i
=
0
;
i
<
propertiesDomList
.
length
();
i
++
)
{
QDomElement
preferenceElement
=
propertiesDomList
.
at
(
i
).
toElement
();
QString
prefName
=
preferenceElement
.
attribute
(
"name"
,
""
);
if
(
prefName
.
length
()
>
0
)
{
QString
prefValue
=
preferenceElement
.
attribute
(
"value"
,
""
);
bool
readOnly
=
(
preferenceElement
.
attribute
(
"readonly"
,
"false"
)
==
"true"
);
mPreferences
.
insert
(
prefName
,
PreferenceValue
(
prefValue
,
readOnly
));
}
}
}
if
(
mMainHtmlFileName
.
length
()
==
0
)
{
QFile
defaultStartFile
(
path
+
"index.htm"
);
if
(
defaultStartFile
.
exists
())
{
mMainHtmlFileName
=
"index.htm"
;
}
else
{
QFile
secondDefaultStartFile
(
path
+
"index.html"
);
if
(
secondDefaultStartFile
.
exists
())
{
mMainHtmlFileName
=
"index.html"
;
}
}
}
mMainHtmlUrl
=
pWidgetUrl
;
mMainHtmlUrl
.
setPath
(
pWidgetUrl
.
path
()
+
"/"
+
mMainHtmlFileName
);
// is it a valid local file ?
QFile
f
(
mMainHtmlUrl
.
toLocalFile
());
if
(
!
f
.
exists
())
mMainHtmlUrl
=
QUrl
(
mMainHtmlFileName
);
connect
(
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
QWebView
::
load
(
mMainHtmlUrl
);
setFixedSize
(
QSize
(
width
,
height
));
mNominalSize
=
QSize
(
width
,
height
);
}
UBW3CWidget
::~
UBW3CWidget
()
{
// NOOP
}
void
UBW3CWidget
::
javaScriptWindowObjectCleared
()
{
UBWidgetUniboardAPI
*
uniboardAPI
=
new
UBWidgetUniboardAPI
(
UBApplication
::
boardController
->
activeScene
(),
0
);
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
uniboardAPI
);
}
bool
UBW3CWidget
::
hasNPAPIWrapper
(
const
QString
&
pMimeType
)
{
loadNPAPIWrappersTemplates
();
return
sNPAPIWrapperTemplates
.
contains
(
pMimeType
);
}
QString
UBW3CWidget
::
createNPAPIWrapper
(
const
QString
&
url
,
const
QString
&
pMimeType
,
const
QSize
&
sizeHint
,
const
QString
&
pName
)
{
const
QString
userWidgetPath
=
UBSettings
::
settings
()
->
userInteractiveDirectory
()
+
"/"
+
tr
(
"Web"
);
QDir
userWidgetDir
(
userWidgetPath
);
return
createNPAPIWrapperInDir
(
url
,
userWidgetDir
,
pMimeType
,
sizeHint
,
pName
);
}
QString
UBW3CWidget
::
createNPAPIWrapperInDir
(
const
QString
&
pUrl
,
const
QDir
&
pDir
,
const
QString
&
pMimeType
,
const
QSize
&
sizeHint
,
const
QString
&
pName
)
{
QString
url
=
pUrl
;
url
=
UBFileSystemUtils
::
removeLocalFilePrefix
(
url
);
QString
name
=
pName
;
QFileInfo
fi
(
url
);
if
(
name
.
length
()
==
0
)
name
=
fi
.
baseName
();
if
(
fi
.
exists
()){
url
=
fi
.
fileName
();
}
loadNPAPIWrappersTemplates
();
QString
htmlTemplate
;
if
(
pMimeType
.
length
()
>
0
&&
sNPAPIWrapperTemplates
.
contains
(
pMimeType
)){
htmlTemplate
=
sNPAPIWrapperTemplates
.
value
(
pMimeType
);
}
else
{
QString
extension
=
UBFileSystemUtils
::
extension
(
url
);
if
(
sNPAPIWrapperTemplates
.
contains
(
extension
))
htmlTemplate
=
sNPAPIWrapperTemplates
.
value
(
extension
);
}
if
(
htmlTemplate
.
length
()
>
0
){
htmlTemplate
=
htmlTemplate
.
replace
(
QString
(
"{in.url}"
),
url
)
.
replace
(
QString
(
"{in.width}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
width
()))
.
replace
(
QString
(
"{in.height}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
height
()));
QString
configTemplate
=
sNPAPIWrappperConfigTemplate
.
replace
(
QString
(
"{in.id}"
),
url
)
.
replace
(
QString
(
"{in.width}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
width
()))
.
replace
(
QString
(
"{in.height}"
),
QString
(
"%1"
).
arg
(
sizeHint
.
height
()))
.
replace
(
QString
(
"{in.name}"
),
name
)
.
replace
(
QString
(
"{in.startFile}"
),
QString
(
"index.htm"
));
QString
dirPath
=
pDir
.
path
();
if
(
!
pDir
.
exists
())
pDir
.
mkpath
(
dirPath
);
QString
widgetLibraryPath
=
dirPath
+
"/"
+
name
+
".wgt"
;
QDir
widgetLibraryDir
(
widgetLibraryPath
);
if
(
widgetLibraryDir
.
exists
())
{
if
(
!
UBFileSystemUtils
::
deleteDir
(
widgetLibraryDir
.
path
()))
{
qWarning
()
<<
"Cannot delete old widget "
<<
widgetLibraryDir
.
path
();
}
}
widgetLibraryDir
.
mkpath
(
widgetLibraryPath
);
if
(
fi
.
exists
()){
QString
target
=
widgetLibraryPath
+
"/"
+
fi
.
fileName
();
QString
source
=
pUrl
;
source
=
UBFileSystemUtils
::
removeLocalFilePrefix
(
source
);
QFile
::
copy
(
source
,
target
);
}
QFile
configFile
(
widgetLibraryPath
+
"/config.xml"
);
if
(
!
configFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"Cannot open file "
<<
configFile
.
fileName
();
return
""
;
}
QTextStream
outConfig
(
&
configFile
);
outConfig
.
setCodec
(
"UTF-8"
);
outConfig
<<
configTemplate
;
configFile
.
close
();
QFile
indexFile
(
widgetLibraryPath
+
"/index.htm"
);
if
(
!
indexFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"Cannot open file "
<<
indexFile
.
fileName
();
return
""
;
}
QTextStream
outIndex
(
&
indexFile
);
outIndex
.
setCodec
(
"UTF-8"
);
outIndex
<<
htmlTemplate
;
indexFile
.
close
();
return
widgetLibraryPath
;
}
else
{
return
""
;
}
}
QString
UBW3CWidget
::
createHtmlWrapperInDir
(
const
QString
&
html
,
const
QDir
&
pDir
,
const
QSize
&
sizeHint
,
const
QString
&
pName
)
{
QString
widgetPath
=
pDir
.
path
()
+
"/"
+
pName
+
".wgt"
;
widgetPath
=
UBFileSystemUtils
::
nextAvailableFileName
(
widgetPath
);
QDir
widgetDir
(
widgetPath
);
if
(
!
widgetDir
.
exists
())
{
widgetDir
.
mkpath
(
widgetDir
.
path
());
}
QFile
configFile
(
widgetPath
+
"/"
+
"config.xml"
);
if
(
configFile
.
exists
())
{
configFile
.
remove
(
configFile
.
fileName
());
}
if
(
!
configFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"Cannot open file "
<<
configFile
.
fileName
();
return
""
;
}
QTextStream
outConfig
(
&
configFile
);
outConfig
.
setCodec
(
"UTF-8"
);
outConfig
<<
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
<<
endl
;
outConfig
<<
"<widget xmlns=
\"
http://www.w3.org/ns/widgets
\"
"
<<
endl
;
outConfig
<<
" xmlns:ub=
\"
http://uniboard.mnemis.com/widgets
\"
"
<<
endl
;
outConfig
<<
" id=
\"
http://uniboard.mnemis.com/"
<<
pName
<<
"
\"
"
<<
endl
;
outConfig
<<
" version=
\"
1.0
\"
"
<<
endl
;
outConfig
<<
" width=
\"
"
<<
sizeHint
.
width
()
<<
"
\"
"
<<
endl
;
outConfig
<<
" height=
\"
"
<<
sizeHint
.
height
()
<<
"
\"
"
<<
endl
;
outConfig
<<
" ub:resizable=
\"
true
\"
>"
<<
endl
;
outConfig
<<
" <name>"
<<
pName
<<
"</name>"
<<
endl
;
outConfig
<<
" <content src=
\"
"
<<
pName
<<
".html
\"
/>"
<<
endl
;
outConfig
<<
"</widget>"
<<
endl
;
configFile
.
close
();
const
QString
fullHtmlFileName
=
widgetPath
+
"/"
+
pName
+
".html"
;
QFile
widgetHtmlFile
(
fullHtmlFileName
);
if
(
widgetHtmlFile
.
exists
())
{
widgetHtmlFile
.
remove
(
widgetHtmlFile
.
fileName
());
}
if
(
!
widgetHtmlFile
.
open
(
QIODevice
::
WriteOnly
))
{
qWarning
()
<<
"cannot open file "
<<
widgetHtmlFile
.
fileName
();
return
""
;
}
QTextStream
outStartFile
(
&
widgetHtmlFile
);
outStartFile
.
setCodec
(
"UTF-8"
);
outStartFile
<<
"<!DOCTYPE HTML PUBLIC
\"
-//W3C//DTD HTML 4.01//EN
\"
\"
http://www.w3.org/TR/html4/strict.dtd
\"
>"
<<
endl
;
outStartFile
<<
"<html>"
<<
endl
;
outStartFile
<<
"<head>"
<<
endl
;
outStartFile
<<
" <meta http-equiv=
\"
content-type
\"
content=
\"
text/html; charset=utf-8
\"
>"
<<
endl
;
outStartFile
<<
"</head>"
<<
endl
;
outStartFile
<<
" <body>"
<<
endl
;
outStartFile
<<
html
<<
endl
;
outStartFile
<<
" </body>"
<<
endl
;
outStartFile
<<
"</html>"
<<
endl
;
widgetHtmlFile
.
close
();
return
widgetPath
;
}
QString
UBW3CWidget
::
freezedWidgetPage
()
{
static
QString
defaultcontent
;
if
(
defaultcontent
.
isNull
())
{
QString
freezedWidgetDefaultContentFilePath
=
freezedWidgetFilePath
();
QFile
wrapperFile
(
freezedWidgetDefaultContentFilePath
);
if
(
!
wrapperFile
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
qDebug
()
<<
"can't open wrapper file "
+
freezedWidgetDefaultContentFilePath
;
defaultcontent
=
""
;
}
else
{
QByteArray
arr
=
wrapperFile
.
readAll
();
if
(
!
arr
.
isEmpty
())
{
defaultcontent
=
QString
(
arr
);
}
else
{
qDebug
()
<<
"content of "
+
freezedWidgetDefaultContentFilePath
+
"is empty"
;
defaultcontent
=
""
;
}
}
}
return
defaultcontent
;
}
QString
UBW3CWidget
::
freezedWidgetFilePath
()
{
return
UBPlatformUtils
::
applicationResourcesDirectory
()
+
"/etc/"
+
"freezedWidgetWrapper.html"
;
}
void
UBW3CWidget
::
loadNPAPIWrappersTemplates
()
{
if
(
!
sTemplateLoaded
)
{
sNPAPIWrapperTemplates
.
clear
();
QString
etcPath
=
UBPlatformUtils
::
applicationResourcesDirectory
()
+
"/etc/"
;
QDir
etcDir
(
etcPath
);
foreach
(
QString
fileName
,
etcDir
.
entryList
())
{
if
(
fileName
.
startsWith
(
"npapi-wrapper"
)
&&
(
fileName
.
endsWith
(
".htm"
)
||
fileName
.
endsWith
(
".html"
)))
{
QString
htmlContent
=
UBFileSystemUtils
::
readTextFile
(
etcPath
+
fileName
);
if
(
htmlContent
.
length
()
>
0
)
{
QStringList
tokens
=
fileName
.
split
(
"."
);
if
(
tokens
.
length
()
>=
4
)
{
QString
mime
=
tokens
.
at
(
tokens
.
length
()
-
4
);
mime
+=
"/"
+
tokens
.
at
(
tokens
.
length
()
-
3
);
QString
fileExtension
=
tokens
.
at
(
tokens
.
length
()
-
2
);
sNPAPIWrapperTemplates
.
insert
(
mime
,
htmlContent
);
sNPAPIWrapperTemplates
.
insert
(
fileExtension
,
htmlContent
);
}
}
}
}
sNPAPIWrappperConfigTemplate
=
UBFileSystemUtils
::
readTextFile
(
etcPath
+
"npapi-wrapper.config.xml"
);
sTemplateLoaded
=
true
;
}
}
QString
UBW3CWidget
::
textForSubElementByLocale
(
QDomElement
rootElement
,
QString
subTagName
,
QLocale
locale
)
{
QDomNodeList
subList
=
rootElement
.
elementsByTagName
(
subTagName
);
QString
lang
=
locale
.
name
();
if
(
lang
.
length
()
>
2
)
lang
[
2
]
=
QLatin1Char
(
'-'
);
if
(
subList
.
count
()
>
1
)
{
for
(
int
i
=
0
;
i
<
subList
.
count
();
i
++
)
{
QDomNode
node
=
subList
.
at
(
i
);
QDomElement
element
=
node
.
toElement
();
QString
configLang
=
element
.
attribute
(
"xml:lang"
,
""
);
if
(
lang
==
configLang
||
(
configLang
.
length
()
==
2
&&
configLang
==
lang
.
left
(
2
)))
return
element
.
text
();
}
}
if
(
subList
.
count
()
>=
1
)
{
QDomElement
element
=
subList
.
item
(
0
).
toElement
();
return
element
.
text
();
}
return
""
;
}
src/domain/UBW3CWidget.h
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBW3CWIDGET_H_
#define UBW3CWIDGET_H_
#include <QtGui>
#include <QtWebKit>
#include <QtXml>
/*
* wrapper for w3c widget 1.0 as define in http://www.w3.org/TR/widgets/
*/
#include "UBAbstractWidget.h"
class
UBItem
;
class
UBW3CWidget
:
public
UBAbstractWidget
{
Q_OBJECT
;
public
:
UBW3CWidget
(
const
QUrl
&
pWidgetUrl
,
QWidget
*
parent
=
0
);
virtual
~
UBW3CWidget
();
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
QString
freezedWidgetFilePath
();
static
bool
hasNPAPIWrapper
(
const
QString
&
pMimeType
);
class
PreferenceValue
{
public
:
PreferenceValue
()
{
// NOOP
}
PreferenceValue
(
const
QString
&
pValue
,
bool
pReadonly
)
{
value
=
pValue
;
readonly
=
pReadonly
;
}
QString
value
;
bool
readonly
;
};
class
Metadata
{
public
:
QString
id
;
QString
name
;
QString
description
;
QString
author
;
QString
authorEmail
;
QString
authorHref
;
QString
version
;
};
QMap
<
QString
,
PreferenceValue
>
preferences
()
{
return
mPreferences
;
}
Metadata
metadatas
()
const
{
return
mMetadatas
;
}
private
:
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
);
// w3c metadata widget attributes
//
// http://www.w3.org/TR/widgets/#widget0
Metadata
mMetadatas
;
private
slots
:
void
javaScriptWindowObjectCleared
();
};
#endif
/* UBW3CWIDGET_H_ */
src/domain/domain.pri
View file @
e6be59ce
...
...
@@ -7,15 +7,13 @@ HEADERS += src/domain/UBGraphicsScene.h \
src/domain/UBDocumentUndoCommand.h \
src/domain/UBPageSizeUndoCommand.h \
src/domain/UBGraphicsProxyWidget.h \
src/domain/UBGraphicsWebView.h \
src/domain/UBGraphicsSvgItem.h \
src/domain/UBGraphicsPolygonItem.h \
src/domain/UBItem.h \
src/domain/UBGraphicsWidgetItem.h \
src/domain/UBAppleWidget.h \
src/domain/UBGraphicsPDFItem.h \
src/domain/UBGraphicsTextItem.h \
src/domain/UBAbstractWidget.h \
src/domain/UBW3CWidget.h \
src/domain/UBResizableGraphicsItem.h \
src/domain/UBGraphicsStroke.h \
src/domain/UBGraphicsMediaItem.h \
...
...
@@ -40,16 +38,14 @@ SOURCES += src/domain/UBGraphicsScene.cpp \
src/domain/UBDocumentUndoCommand.cpp \
src/domain/UBPageSizeUndoCommand.cpp \
src/domain/UBGraphicsProxyWidget.cpp \
src/domain/UBGraphicsWebView.cpp \
src/domain/UBGraphicsSvgItem.cpp \
src/domain/UBGraphicsPolygonItem.cpp \
src/domain/UBItem.cpp \
src/domain/UBGraphicsVideoItem.cpp \
src/domain/UBGraphicsWidgetItem.cpp \
src/domain/UBAppleWidget.cpp \
src/domain/UBGraphicsPDFItem.cpp \
src/domain/UBGraphicsTextItem.cpp \
src/domain/UBAbstractWidget.cpp \
src/domain/UBW3CWidget.cpp \
src/domain/UBResizableGraphicsItem.cpp \
src/domain/UBGraphicsStroke.cpp \
src/domain/UBGraphicsMediaItem.cpp \
...
...
src/frameworks/UBCoreGraphicsScene.cpp
View file @
e6be59ce
...
...
@@ -32,7 +32,7 @@ UBCoreGraphicsScene::~UBCoreGraphicsScene()
//we must delete removed items that are no more in any scene
foreach
(
const
QGraphicsItem
*
item
,
mItemsToDelete
)
{
if
(
item
->
scene
()
==
NULL
||
item
->
scene
()
==
this
)
if
(
item
->
scene
()
==
NULL
||
item
->
scene
()
==
this
)
{
delete
item
;
}
...
...
@@ -61,6 +61,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete)
{
mItemsToDelete
.
remove
(
item
);
delete
item
;
item
=
0
;
}
}
...
...
@@ -84,6 +85,7 @@ bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item)
mItemsToDelete
.
remove
(
item
);
delete
item
;
item
=
0
;
return
true
;
}
else
...
...
src/gui/UBFavoriteToolPalette.cpp
View file @
e6be59ce
...
...
@@ -18,11 +18,10 @@
#include "core/UBSettings.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "tools/UBToolsManager.h"
#include "domain/UBAbstractWidget.h"
#include "gui/UBMainWindow.h"
#include "core/memcheck.h"
...
...
@@ -67,9 +66,9 @@ UBFavoriteToolPalette::UBFavoriteToolPalette(QWidget* parent)
foreach
(
QString
widgetPath
,
appPathes
)
{
QAction
*
action
=
new
QAction
(
UB
AbstractWidget
::
widgetName
(
QUrl
::
fromLocalFile
(
widgetPath
)),
this
);
QAction
*
action
=
new
QAction
(
UB
GraphicsWidgetItem
::
widgetName
(
QUrl
::
fromLocalFile
(
widgetPath
)),
this
);
action
->
setData
(
QUrl
::
fromLocalFile
(
widgetPath
));
action
->
setIcon
(
QIcon
(
UB
AbstractWidget
::
iconFilePath
(
QUrl
::
fromLocalFile
(
widgetPath
))));
action
->
setIcon
(
QIcon
(
UB
GraphicsWidgetItem
::
iconFilePath
(
QUrl
::
fromLocalFile
(
widgetPath
))));
connect
(
action
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
addFavorite
()));
toolsActions
<<
action
;
...
...
src/gui/UBFeaturesWidget.cpp
View file @
e6be59ce
#include <QDomDocument>
#include "UBFeaturesWidget.h"
#include "domain/UBAbstractWidget.h"
#include "gui/UBThumbnailWidget.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplication.h"
...
...
src/gui/UBTeacherGuideWidgetsTools.cpp
View file @
e6be59ce
...
...
@@ -22,6 +22,8 @@
#include <QUrl>
#include <QWebSettings>
#include <QApplication>
#include <QDomElement>
#include <QWebFrame>
#include "UBTeacherGuideWidgetsTools.h"
...
...
@@ -30,7 +32,7 @@
#include "board/UBBoardController.h"
#include "domain/UB
W3CWidget
.h"
#include "domain/UB
GraphicsWidgetItem
.h"
#include "globals/UBGlobals.h"
...
...
@@ -360,7 +362,7 @@ void UBTGMediaWidget::removeSource()
void
UBTGMediaWidget
::
hideEvent
(
QHideEvent
*
event
)
{
if
(
mpWebView
)
mpWebView
->
page
()
->
mainFrame
()
->
setContent
(
UB
W3CWidget
::
freezedWidgetPage
().
toAscii
());
mpWebView
->
page
()
->
mainFrame
()
->
setContent
(
UB
GraphicsW3CWidgetItem
::
freezedWidgetPage
().
toAscii
());
QWidget
::
hideEvent
(
event
);
}
...
...
@@ -421,7 +423,7 @@ void UBTGMediaWidget::createWorkWidget()
mMediaType
=
"w3c"
;
if
(
!
(
mIsPresentationMode
||
mIsInitializationMode
)){
QDir
baseW3CDirectory
(
UBPersistenceManager
::
persistenceManager
()
->
teacherGuideAbsoluteObjectPath
(
proxyDocument
));
mMediaPath
=
UB
W3CWidget
::
createNPAPIWrapperInDir
(
mMediaPath
,
baseW3CDirectory
,
mimeType
,
QSize
(
100
,
100
),
QUuid
::
createUuid
());
mMediaPath
=
UB
GraphicsW3CWidgetItem
::
createNPAPIWrapperInDir
(
mMediaPath
,
baseW3CDirectory
,
mimeType
,
QSize
(
100
,
100
),
QUuid
::
createUuid
());
}
mpWebView
=
new
UBDraggableWeb
(
mMediaPath
);
mpWebView
->
setAcceptDrops
(
false
);
...
...
src/gui/UBToolWidget.cpp
View file @
e6be59ce
...
...
@@ -23,9 +23,6 @@
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBAppleWidget.h"
#include "domain/UBW3CWidget.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsWidgetItem.h"
...
...
@@ -41,38 +38,30 @@ QPixmap* UBToolWidget::sClosePixmap = 0;
QPixmap
*
UBToolWidget
::
sUnpinPixmap
=
0
;
UBToolWidget
::
UBToolWidget
(
const
QUrl
&
pUrl
,
QWidget
*
pParent
)
:
QWidget
(
pParent
,
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
)
,
mToolWidget
(
0
)
UBToolWidget
::
UBToolWidget
(
const
QUrl
&
pUrl
,
QGraphicsItem
*
pParent
)
:
QGraphicsWidget
(
pParent
,
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
)
,
mGraphicsWidgetItem
(
0
)
,
mGraphicsWebView
(
0
)
,
mShouldMoveWidget
(
false
)
{
int
widgetType
=
UB
AbstractWidget
::
widgetType
(
pUrl
);
int
widgetType
=
UB
GraphicsWidgetItem
::
widgetType
(
pUrl
);
if
(
widgetType
==
UBWidgetType
::
Apple
)
{
mToolWidget
=
new
UBAppleWidget
(
pUrl
,
this
);
}
else
if
(
widgetType
==
UBWidgetType
::
W3C
)
{
mToolWidget
=
new
UBW3CWidget
(
pUrl
,
this
);
}
if
(
widgetType
==
UBWidgetType
::
Apple
)
mGraphicsWidgetItem
=
new
UBGraphicsAppleWidgetItem
(
pUrl
,
this
);
else
if
(
widgetType
==
UBWidgetType
::
W3C
)
mGraphicsWidgetItem
=
new
UBGraphicsW3CWidgetItem
(
pUrl
,
this
);
else
{
qDebug
()
<<
"UBToolWidget::UBToolWidget: Unknown widget Type"
;
return
;
}
initialize
();
}
UBToolWidget
::
UBToolWidget
(
UBAbstractWidget
*
pWidget
,
QWidget
*
pParent
)
:
QWidget
(
pParent
,
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
)
,
mToolWidget
(
pWidget
)
UBToolWidget
::
UBToolWidget
(
UBGraphicsWidgetItem
*
pWidget
,
QGraphicsItem
*
pParent
)
:
QGraphicsWidget
(
pParent
,
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
)
,
mShouldMoveWidget
(
false
)
{
mToolWidget
->
setParent
(
this
);
mToolWidget
->
loadMainHtml
();
mGraphicsWidgetItem
=
pWidget
;
initialize
();
...
...
@@ -88,85 +77,90 @@ UBToolWidget::~UBToolWidget()
void
UBToolWidget
::
initialize
()
{
mToolWidget
->
setAcceptDrops
(
false
);
if
(
!
sClosePixmap
)
{
if
(
!
sClosePixmap
)
sClosePixmap
=
new
QPixmap
(
":/images/close.svg"
);
}
if
(
!
sUnpinPixmap
)
{
sUnpinPixmap
=
new
QPixmap
(
":/images/unpin.svg"
);
}
mToolWidget
->
settings
()
->
setAttribute
(
QWebSettings
::
PluginsEnabled
,
true
);
mToolWidget
->
setAttribute
(
Qt
::
WA_OpaquePaintEvent
,
false
);
QPalette
palette
=
mToolWidget
->
page
()
->
palette
();
palette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
mToolWidget
->
page
()
->
setPalette
(
palette
);
connect
(
mToolWidget
->
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
setLayout
(
new
QVBoxLayout
());
QGraphicsLinearLayout
*
graphicsLayout
=
new
QGraphicsLinearLayout
(
Qt
::
Vertical
);
mFrameWidth
=
UBSettings
::
settings
()
->
objectFrameWidth
;
mContentMargin
=
sClosePixmap
->
width
()
/
2
+
mFrameWidth
;
graphicsLayout
->
setContentsMargins
(
mContentMargin
,
mContentMargin
,
mContentMargin
,
mContentMargin
);
setPreferredSize
(
mGraphicsWidgetItem
->
preferredWidth
()
+
mContentMargin
*
2
,
mGraphicsWidgetItem
->
preferredHeight
()
+
mContentMargin
*
2
);
layout
()
->
setContentsMargins
(
mContentMargin
,
mContentMargin
,
mContentMargin
,
mContentMargin
);
layout
()
->
addWidget
(
mToolWidget
);
mGraphicsWebView
=
new
QGraphicsWebView
();
connect
(
mGraphicsWebView
->
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
mGraphicsWebView
->
load
(
mGraphicsWidgetItem
->
mainHtml
());
graphicsLayout
->
addItem
(
mGraphicsWebView
);
setFixedSize
(
mToolWidget
->
width
()
+
mContentMargin
*
2
,
mToolWidget
->
height
()
+
mContentMargin
*
2
);
mGraphicsWebView
->
setAcceptDrops
(
false
);
mGraphicsWebView
->
settings
()
->
setAttribute
(
QWebSettings
::
PluginsEnabled
,
true
);
mGraphicsWebView
->
setAttribute
(
Qt
::
WA_OpaquePaintEvent
,
false
);
mToolWidget
->
installEventFilter
(
this
);
QPalette
palette
=
mGraphicsWebView
->
page
()
->
palette
();
palette
.
setBrush
(
QPalette
::
Base
,
QBrush
(
Qt
::
transparent
));
mGraphicsWebView
->
page
()
->
setPalette
(
palette
);
setLayout
(
graphicsLayout
);
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
}
void
UBToolWidget
::
javaScriptWindowObjectCleared
()
{
UBWidgetUniboardAPI
*
uniboardAPI
=
new
UBWidgetUniboardAPI
(
UBApplication
::
boardController
->
activeScene
()
);
UBWidgetUniboardAPI
*
uniboardAPI
=
new
UBWidgetUniboardAPI
(
UBApplication
::
boardController
->
activeScene
(),
mGraphicsWidgetItem
);
m
ToolWidget
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
uniboardAPI
);
m
GraphicsWebView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
uniboardAPI
);
UB
W3CWidget
*
w3c
=
dynamic_cast
<
UBW3CWidget
*>
(
mToolWidget
);
if
(
w3c
)
UB
GraphicsW3CWidgetItem
*
graphicsW3cWidgetItem
=
dynamic_cast
<
UBGraphicsW3CWidgetItem
*>
(
mGraphicsWidgetItem
);
if
(
graphicsW3cWidgetItem
)
{
UBW3CWidgetAPI
*
widgetAPI
=
new
UBW3CWidgetAPI
(
w3c
);
m
ToolWidget
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"widget"
,
widgetAPI
);
UBW3CWidgetAPI
*
widgetAPI
=
new
UBW3CWidgetAPI
(
graphicsW3cWidgetItem
);
m
GraphicsWebView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"widget"
,
widgetAPI
);
}
}
void
UBToolWidget
::
setPos
(
const
QPointF
&
point
)
{
UBToolWidget
::
setPos
(
point
.
x
(),
point
.
y
());
}
void
UBToolWidget
::
paintEvent
(
QPaintEvent
*
event
)
void
UBToolWidget
::
setPos
(
qreal
x
,
qreal
y
)
{
QWidget
::
paintEvent
(
event
);
QGraphicsItem
::
setPos
(
x
-
mContentMargin
*
scale
(),
y
-
mContentMargin
*
scale
());
}
QPointF
UBToolWidget
::
pos
()
const
{
return
QPointF
(
QGraphicsItem
::
pos
().
x
()
+
mContentMargin
*
scale
(),
QGraphicsItem
::
pos
().
y
()
+
mContentMargin
*
scale
());
}
void
UBToolWidget
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
QGraphicsWidget
::
paint
(
painter
,
option
,
widget
);
if
(
isActiveWindow
())
{
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
painter
.
setPen
(
Qt
::
NoPen
);
painter
.
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
->
setRenderHint
(
QPainter
::
Antialiasing
);
painter
->
setPen
(
Qt
::
NoPen
);
painter
->
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
.
drawRoundedRect
(
QRectF
(
sClosePixmap
->
width
()
/
2
,
sClosePixmap
->
height
()
/
2
,
width
()
-
sClosePixmap
->
width
()
,
mFrameWidth
),
mFrameWidth
/
2
,
mFrameWidth
/
2
);
painter
->
drawRoundedRect
(
QRectF
(
sClosePixmap
->
width
()
/
2
,
sClosePixmap
->
height
()
/
2
,
preferredWidth
()
-
sClosePixmap
->
width
(),
mFrameWidth
),
mFrameWidth
/
2
,
mFrameWidth
/
2
);
painter
.
drawPixmap
(
0
,
0
,
*
sClosePixmap
);
painter
->
drawPixmap
(
0
,
0
,
*
sClosePixmap
);
if
(
m
ToolWidget
->
canBeContent
())
painter
.
drawPixmap
(
mContentMargin
,
0
,
*
sUnpinPixmap
);
if
(
m
GraphicsWidgetItem
->
canBeContent
())
painter
->
drawPixmap
(
mContentMargin
,
0
,
*
sUnpinPixmap
);
}
}
void
UBToolWidget
::
mousePressEvent
(
QMouseEvent
*
event
)
void
UBToolWidget
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
QWidget
::
mousePressEvent
(
event
);
Q
Graphics
Widget
::
mousePressEvent
(
event
);
// did webkit consume the mouse press ?
mShouldMoveWidget
=
!
event
->
isAccepted
()
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
);
...
...
@@ -179,50 +173,50 @@ void UBToolWidget::mousePressEvent ( QMouseEvent * event )
}
void
UBToolWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
void
UBToolWidget
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
mShouldMoveWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
move
(
pos
()
-
mMousePressPos
+
event
->
pos
());
setPos
(
pos
()
-
mMousePressPos
+
event
->
pos
());
event
->
accept
();
}
QWidget
::
mouseMoveEvent
(
event
);
Q
Graphics
Widget
::
mouseMoveEvent
(
event
);
}
void
UBToolWidget
::
mouseReleaseEvent
(
Q
MouseEvent
*
event
)
void
UBToolWidget
::
mouseReleaseEvent
(
Q
GraphicsSceneMouseEvent
*
event
)
{
mShouldMoveWidget
=
false
;
if
(
event
->
pos
().
x
()
>=
0
&&
event
->
pos
().
x
()
<
sClosePixmap
->
width
()
&&
event
->
pos
().
y
()
>=
0
&&
event
->
pos
().
y
()
<
sClosePixmap
->
height
())
{
UBApplication
::
boardController
->
removeTool
(
this
);
remove
(
);
event
->
accept
();
}
else
if
(
m
ToolWidget
->
canBeContent
()
&&
event
->
pos
().
x
()
>=
mContentMargin
&&
event
->
pos
().
x
()
<
mContentMargin
+
sUnpinPixmap
->
width
()
else
if
(
m
GraphicsWidgetItem
->
canBeContent
()
&&
event
->
pos
().
x
()
>=
mContentMargin
&&
event
->
pos
().
x
()
<
mContentMargin
+
sUnpinPixmap
->
width
()
&&
event
->
pos
().
y
()
>=
0
&&
event
->
pos
().
y
()
<
sUnpinPixmap
->
height
())
{
UBApplication
::
boardController
->
moveToolWidgetToScene
(
this
);
event
->
accept
();
}
else
QWidget
::
mouseReleaseEvent
(
event
);
// don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
Q
Graphics
Widget
::
mouseReleaseEvent
(
event
);
// don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
}
bool
UBToolWidget
::
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
{
if
(
mShouldMoveWidget
&&
obj
==
m
ToolWidget
&&
event
->
type
()
==
QEvent
::
MouseMove
)
if
(
mShouldMoveWidget
&&
obj
==
m
GraphicsWidgetItem
&&
event
->
type
()
==
QEvent
::
MouseMove
)
{
QMouseEvent
*
mouseMoveEvent
=
static_cast
<
QMouseEvent
*>
(
event
);
if
(
mouseMoveEvent
->
buttons
()
&
Qt
::
LeftButton
)
{
move
(
pos
()
-
mMousePressPos
+
mToolWidget
->
mapTo
(
this
,
mouseMoveEvent
->
pos
()));
setPos
(
pos
()
-
mMousePressPos
+
mGraphicsWidgetItem
->
mapToItem
(
this
,
mouseMoveEvent
->
pos
()));
event
->
accept
();
return
true
;
...
...
@@ -234,22 +228,33 @@ bool UBToolWidget::eventFilter(QObject *obj, QEvent *event)
}
void
UBToolWidget
::
centerOn
(
const
QPoint
&
pos
)
void
UBToolWidget
::
centerOn
(
const
QPoint
F
&
pos
)
{
Q
Widget
::
move
(
pos
-
QPoint
(
width
()
/
2
,
h
eight
()
/
2
));
Q
GraphicsWidget
::
setPos
(
pos
-
QPointF
(
preferredWidth
()
/
2
,
preferredH
eight
()
/
2
));
}
QPoint
UBToolWidget
::
naturalCenter
()
const
QPoint
F
UBToolWidget
::
naturalCenter
()
const
{
if
(
m
ToolWidget
)
return
m
ToolWidget
->
geometry
().
center
();
if
(
m
GraphicsWebView
)
return
m
GraphicsWebView
->
geometry
().
center
();
else
return
QPoint
(
0
,
0
);
return
QPointF
(
0
,
0
);
}
UBGraphicsWidgetItem
*
UBToolWidget
::
graphicsWidgetItem
()
const
{
return
mGraphicsWidgetItem
;
}
UBGraphicsScene
*
UBToolWidget
::
scene
()
{
return
qobject_cast
<
UBGraphicsScene
*>
(
QGraphicsItem
::
scene
());
}
UBAbstractWidget
*
UBToolWidget
::
webWidget
()
const
void
UBToolWidget
::
remove
()
{
return
mToolWidget
;
mGraphicsWebView
->
setHtml
(
QString
());
scene
()
->
removeItem
(
this
);
}
src/gui/UBToolWidget.h
View file @
e6be59ce
...
...
@@ -17,33 +17,39 @@
#define UBTOOLWIDGET_H_
#include <QtGui>
#include <QtWebKit>
class
UB
AbstractWidget
;
class
UB
GraphicsWidgetItem
;
class
QWidget
;
class
UBGraphicsScene
;
class
UBToolWidget
:
public
QWidget
class
UBToolWidget
:
public
Q
Graphics
Widget
{
Q_OBJECT
;
Q_OBJECT
public
:
UBToolWidget
(
const
QUrl
&
pUrl
,
Q
Widget
*
pParent
=
0
);
UBToolWidget
(
UB
AbstractWidget
*
pWidget
,
QWidget
*
pParent
=
0
);
UBToolWidget
(
const
QUrl
&
pUrl
,
Q
GraphicsItem
*
pParent
=
0
);
UBToolWidget
(
UB
GraphicsWidgetItem
*
pGraphicsWidgetItem
,
QGraphicsItem
*
pParent
=
0
);
virtual
~
UBToolWidget
();
void
centerOn
(
const
QPoint
&
pos
);
void
centerOn
(
const
QPoint
F
&
pos
);
QPoint
naturalCenter
()
const
;
QPoint
F
naturalCenter
()
const
;
UBAbstractWidget
*
webWidget
()
const
;
UBGraphicsWidgetItem
*
graphicsWidgetItem
()
const
;
void
remove
();
virtual
UBGraphicsScene
*
scene
();
virtual
void
setPos
(
const
QPointF
&
point
);
virtual
void
setPos
(
qreal
x
,
qreal
y
);
virtual
QPointF
pos
()
const
;
protected
:
void
initialize
();
virtual
void
paint
Event
(
QPaintEvent
*
);
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
bool
eventFilter
(
QObject
*
obj
,
QEvent
*
event
);
...
...
@@ -55,9 +61,10 @@ class UBToolWidget : public QWidget
static
QPixmap
*
sClosePixmap
;
static
QPixmap
*
sUnpinPixmap
;
UBAbstractWidget
*
mToolWidget
;
UBGraphicsWidgetItem
*
mGraphicsWidgetItem
;
QGraphicsWebView
*
mGraphicsWebView
;
QPoint
mMousePressPos
;
QPoint
F
mMousePressPos
;
bool
mShouldMoveWidget
;
...
...
src/web/UBRoutedMouseEventWebView.cpp
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBRoutedMouseEventWebView.h"
#include <QtCore>
#include <QtWebKit>
#include <QtGui>
#include "core/memcheck.h"
UBRoutedMouseEventWebView
::
UBRoutedMouseEventWebView
(
QWidget
*
parent
)
:
QWebView
(
parent
)
{
QWebView
::
setRenderHints
(
QPainter
::
Antialiasing
|
QPainter
::
TextAntialiasing
|
QPainter
::
SmoothPixmapTransform
);
}
UBRoutedMouseEventWebView
::~
UBRoutedMouseEventWebView
()
{
// NOOP
}
void
UBRoutedMouseEventWebView
::
mouseMoveEvent
(
QMouseEvent
*
ev
)
{
QWebPage
*
p
=
page
();
if
(
p
)
{
p
->
event
(
ev
);
}
}
void
UBRoutedMouseEventWebView
::
mousePressEvent
(
QMouseEvent
*
ev
)
{
QWebPage
*
p
=
page
();
if
(
p
)
{
p
->
event
(
ev
);
}
}
void
UBRoutedMouseEventWebView
::
mouseDoubleClickEvent
(
QMouseEvent
*
ev
)
{
QWebPage
*
p
=
page
();
if
(
p
)
{
p
->
event
(
ev
);
}
}
void
UBRoutedMouseEventWebView
::
mouseReleaseEvent
(
QMouseEvent
*
ev
)
{
QWebPage
*
p
=
page
();
if
(
p
)
{
p
->
event
(
ev
);
}
}
void
UBRoutedMouseEventWebView
::
contextMenuEvent
(
QContextMenuEvent
*
ev
)
{
QWebPage
*
p
=
page
();
if
(
p
)
{
p
->
event
(
ev
);
}
}
void
UBRoutedMouseEventWebView
::
wheelEvent
(
QWheelEvent
*
ev
)
{
QWebPage
*
p
=
page
();
if
(
p
)
{
p
->
event
(
ev
);
}
}
//void UBRoutedMouseEventWebView::dropEvent(QDropEvent *event)
//{
//// QWebView::dropEvent(event);
// event->accept();
//}
src/web/UBRoutedMouseEventWebView.h
deleted
100644 → 0
View file @
312505e5
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBROUTEDMOUSEEVENTWEBVIEW_H_
#define UBROUTEDMOUSEEVENTWEBVIEW_H_
#include <QtWebKit>
/*
* This class changes the routing of mouse events.
* Qt 4.5.2 does not report back the "accepted" flag set
* by WebKit, as we want to know if a mouse event has been
* consumed by webKit, we override them without keeping the
* accepted flag status
*/
class
UBRoutedMouseEventWebView
:
public
QWebView
{
public
:
UBRoutedMouseEventWebView
(
QWidget
*
parent
=
0
);
virtual
~
UBRoutedMouseEventWebView
();
protected
:
virtual
void
mouseMoveEvent
(
QMouseEvent
*
ev
);
virtual
void
mousePressEvent
(
QMouseEvent
*
ev
);
virtual
void
mouseDoubleClickEvent
(
QMouseEvent
*
ev
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
ev
);
virtual
void
contextMenuEvent
(
QContextMenuEvent
*
ev
);
virtual
void
wheelEvent
(
QWheelEvent
*
ev
);
// virtual void dropEvent(QDropEvent *);
};
#endif
/* UBROUTEDMOUSEEVENTWEBVIEW_H_ */
src/web/web.pri
View file @
e6be59ce
...
...
@@ -13,7 +13,6 @@ HEADERS += src/web/UBWebController.h \
src/web/UBWebKitUtils.h \
src/web/UBWebPage.h \
src/web/UBWebPluginWidget.h \
src/web/UBRoutedMouseEventWebView.h \
src/web/UBOEmbedParser.h\
src/web/browser/WBBrowserWindow.h \
src/web/browser/WBChaseWidget.h \
...
...
@@ -35,7 +34,6 @@ SOURCES += src/web/UBWebController.cpp \
src/web/UBWebKitUtils.cpp \
src/web/UBWebPage.cpp \
src/web/UBWebPluginWidget.cpp \
src/web/UBRoutedMouseEventWebView.cpp \
src/web/UBOEmbedParser.cpp\
src/web/browser/WBBrowserWindow.cpp \
src/web/browser/WBChaseWidget.cpp \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment