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
d2eff8eb
Commit
d2eff8eb
authored
Aug 10, 2012
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Sankore/Sankore-3.1
parents
f5d5a5fa
9244a43a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
130 deletions
+99
-130
UBBoardView.cpp
src/board/UBBoardView.cpp
+3
-2
UB.h
src/core/UB.h
+2
-1
UBToolWidget.cpp
src/gui/UBToolWidget.cpp
+74
-108
UBToolWidget.h
src/gui/UBToolWidget.h
+20
-19
No files found.
src/board/UBBoardView.cpp
View file @
d2eff8eb
...
...
@@ -988,8 +988,9 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
}
else
{
if
(
QGraphicsSvgItem
::
Type
!=
movingItem
->
type
()
&&
UBGraphicsDelegateFrame
::
Type
!=
movingItem
->
type
())
if
(
QGraphicsSvgItem
::
Type
!=
movingItem
->
type
()
&&
UBGraphicsDelegateFrame
::
Type
!=
movingItem
->
type
()
&&
UBToolWidget
::
Type
!=
movingItem
->
type
())
{
bReleaseIsNeed
=
false
;
if
(
movingItem
->
isSelected
()
&&
mMultipleSelectionIsEnabled
)
...
...
src/core/UB.h
View file @
d2eff8eb
...
...
@@ -142,7 +142,8 @@ struct UBGraphicsItemType
TriangleItemType
,
MagnifierItemType
,
cacheItemType
,
groupContainerType
groupContainerType
,
ToolWidgetItemType
};
};
...
...
src/gui/UBToolWidget.cpp
View file @
d2eff8eb
...
...
@@ -14,38 +14,33 @@
*/
#include <QtGui>
#include "UBToolWidget.h"
#include "frameworks/UBPlatformUtils.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "api/UBWidgetUniboardAPI.h"
#include "api/UBW3CWidgetAPI.h"
#include "board/UBBoardController.h"
#include "board/UBBoardView.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "frameworks/UBPlatformUtils.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h"
QPixmap
*
UBToolWidget
::
sClosePixmap
=
0
;
QPixmap
*
UBToolWidget
::
sUnpinPixmap
=
0
;
UBToolWidget
::
UBToolWidget
(
const
QUrl
&
pUrl
,
QGraphicsItem
*
pParent
)
:
QGraphicsWidget
(
pParent
,
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
)
,
mGraphicsWidgetItem
(
0
)
,
mGraphicsWebView
(
0
)
,
mShouldMoveWidget
(
false
)
,
mContentMargin
(
0
)
,
mFrameWidth
(
0
)
,
mGraphicsWebView
(
0
)
,
mGraphicsWidgetItem
(
0
)
{
int
widgetType
=
UBGraphicsWidgetItem
::
widgetType
(
pUrl
);
if
(
widgetType
==
UBWidgetType
::
Apple
)
mGraphicsWidgetItem
=
new
UBGraphicsAppleWidgetItem
(
pUrl
,
this
);
else
if
(
widgetType
==
UBWidgetType
::
W3C
)
...
...
@@ -56,25 +51,23 @@ UBToolWidget::UBToolWidget(const QUrl& pUrl, QGraphicsItem *pParent)
initialize
();
}
UBToolWidget
::
UBToolWidget
(
UBGraphicsWidgetItem
*
pWidget
,
QGraphicsItem
*
pParent
)
:
QGraphicsWidget
(
pParent
,
Qt
::
FramelessWindowHint
|
Qt
::
WindowStaysOnTopHint
)
,
mShouldMoveWidget
(
false
)
,
mContentMargin
(
0
)
,
mFrameWidth
(
0
)
,
mGraphicsWebView
(
0
)
,
mGraphicsWidgetItem
(
pWidget
)
{
mGraphicsWidgetItem
=
pWidget
;
initialize
();
javaScriptWindowObjectCleared
();
}
UBToolWidget
::~
UBToolWidget
()
{
// NOOP
}
void
UBToolWidget
::
initialize
()
{
if
(
!
sClosePixmap
)
...
...
@@ -108,131 +101,85 @@ void UBToolWidget::initialize()
connect
(
UBApplication
::
boardController
,
SIGNAL
(
activeSceneChanged
()),
this
,
SLOT
(
javaScriptWindowObjectCleared
()));
}
void
UBToolWidget
::
javaScriptWindowObjectCleared
()
{
UBWidgetUniboardAPI
*
uniboardAPI
=
new
UBWidgetUniboardAPI
(
UBApplication
::
boardController
->
activeScene
(),
mGraphicsWidgetItem
);
mGraphicsWebView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
uniboardAPI
);
UBGraphicsW3CWidgetItem
*
graphicsW3cWidgetItem
=
dynamic_cast
<
UBGraphicsW3CWidgetItem
*>
(
mGraphicsWidgetItem
);
if
(
graphicsW3cWidgetItem
)
{
UBW3CWidgetAPI
*
widgetAPI
=
new
UBW3CWidgetAPI
(
graphicsW3cWidgetItem
);
mGraphicsWebView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"widget"
,
widgetAPI
);
}
}
void
UBToolWidget
::
setPos
(
const
QPointF
&
point
)
{
UBToolWidget
::
setPos
(
point
.
x
(),
point
.
y
());
}
void
UBToolWidget
::
setPos
(
qreal
x
,
qreal
y
)
{
QGraphicsItem
::
setPos
(
x
-
mContentMargin
*
scale
(),
y
-
mContentMargin
*
scale
());
}
QPointF
UBToolWidget
::
pos
()
const
bool
UBToolWidget
::
event
(
QEvent
*
event
)
{
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
())
{
painter
->
setRenderHint
(
QPainter
::
Antialiasing
);
painter
->
setPen
(
Qt
::
NoPen
);
painter
->
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
painter
->
drawRoundedRect
(
QRectF
(
sClosePixmap
->
width
()
/
2
,
sClosePixmap
->
height
()
/
2
,
preferredWidth
()
-
sClosePixmap
->
width
(),
mFrameWidth
),
mFrameWidth
/
2
,
mFrameWidth
/
2
);
painter
->
drawPixmap
(
0
,
0
,
*
sClosePixmap
);
if
(
mGraphicsWidgetItem
->
canBeContent
())
painter
->
drawPixmap
(
mContentMargin
,
0
,
*
sUnpinPixmap
);
}
if
(
event
->
type
()
==
QEvent
::
ShortcutOverride
)
event
->
accept
();
return
QGraphicsWidget
::
event
(
event
);
}
void
UBToolWidget
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
QGraphicsWidget
::
mousePressEvent
(
event
);
/
/ did webkit consume the mouse press ?
/
* did webkit consume the mouse press ? */
mShouldMoveWidget
=
!
event
->
isAccepted
()
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
);
mMousePressPos
=
event
->
pos
();
event
->
accept
();
update
();
}
void
UBToolWidget
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
mShouldMoveWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
if
(
mShouldMoveWidget
&&
(
event
->
buttons
()
&
Qt
::
LeftButton
))
{
setPos
(
pos
()
-
mMousePressPos
+
event
->
pos
());
event
->
accept
();
}
QGraphicsWidget
::
mouseMoveEvent
(
event
);
}
void
UBToolWidget
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mShouldMoveWidget
=
false
;
if
(
event
->
pos
().
x
()
>=
0
&&
event
->
pos
().
x
()
<
sClosePixmap
->
width
()
&&
event
->
pos
().
y
()
>=
0
&&
event
->
pos
().
y
()
<
sClosePixmap
->
height
())
{
if
(
event
->
pos
().
x
()
>=
0
&&
event
->
pos
().
x
()
<
sClosePixmap
->
width
()
&&
event
->
pos
().
y
()
>=
0
&&
event
->
pos
().
y
()
<
sClosePixmap
->
height
())
{
remove
();
event
->
accept
();
}
else
if
(
mGraphicsWidgetItem
->
canBeContent
()
&&
event
->
pos
().
x
()
>=
mContentMargin
&&
event
->
pos
().
x
()
<
mContentMargin
+
sUnpinPixmap
->
width
()
&&
event
->
pos
().
y
()
>=
0
&&
event
->
pos
().
y
()
<
sUnpinPixmap
->
height
())
{
else
if
(
mGraphicsWidgetItem
->
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
QGraphicsWidget
::
mouseReleaseEvent
(
event
);
/
/ don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
QGraphicsWidget
::
mouseReleaseEvent
(
event
);
/
* don't propgate to parent, the widget is deleted in UBApplication */
}
bool
UBToolWidget
::
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
void
UBToolWidget
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
if
(
mShouldMoveWidget
&&
obj
==
mGraphicsWidgetItem
&&
event
->
type
()
==
QEvent
::
MouseMove
)
{
QMouseEvent
*
mouseMoveEvent
=
static_cast
<
QMouseEvent
*>
(
event
);
QGraphicsWidget
::
paint
(
painter
,
option
,
widget
);
if
(
mouseMoveEvent
->
buttons
()
&
Qt
::
LeftButton
)
{
setPos
(
pos
()
-
mMousePressPos
+
mGraphicsWidgetItem
->
mapToItem
(
this
,
mouseMoveEvent
->
pos
()));
/* painting lightweight toolbar */
if
(
isActiveWindow
())
{
painter
->
setRenderHint
(
QPainter
::
Antialiasing
);
painter
->
setPen
(
Qt
::
NoPen
);
painter
->
setBrush
(
QColor
(
127
,
127
,
127
,
127
));
event
->
accept
();
return
true
;
}
painter
->
drawRoundedRect
(
QRectF
(
sClosePixmap
->
width
()
/
2
,
sClosePixmap
->
height
()
/
2
,
preferredWidth
()
-
sClosePixmap
->
width
(),
mFrameWidth
),
mFrameWidth
/
2
,
mFrameWidth
/
2
);
painter
->
drawPixmap
(
0
,
0
,
*
sClosePixmap
);
if
(
mGraphicsWidgetItem
->
canBeContent
())
painter
->
drawPixmap
(
mContentMargin
,
0
,
*
sUnpinPixmap
);
}
// standard event processing
return
QObject
::
eventFilter
(
obj
,
event
);
}
void
UBToolWidget
::
centerOn
(
const
QPointF
&
pos
)
void
UBToolWidget
::
javaScriptWindowObjectCleared
()
{
QGraphicsWidget
::
setPos
(
pos
-
QPointF
(
preferredWidth
()
/
2
,
preferredHeight
()
/
2
));
UBWidgetUniboardAPI
*
uniboardAPI
=
new
UBWidgetUniboardAPI
(
UBApplication
::
boardController
->
activeScene
(),
mGraphicsWidgetItem
);
mGraphicsWebView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
uniboardAPI
);
UBGraphicsW3CWidgetItem
*
graphicsW3cWidgetItem
=
dynamic_cast
<
UBGraphicsW3CWidgetItem
*>
(
mGraphicsWidgetItem
);
if
(
graphicsW3cWidgetItem
)
{
UBW3CWidgetAPI
*
widgetAPI
=
new
UBW3CWidgetAPI
(
graphicsW3cWidgetItem
);
mGraphicsWebView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"widget"
,
widgetAPI
);
}
}
UBGraphicsWidgetItem
*
UBToolWidget
::
graphicsWidgetItem
()
const
{
return
mGraphicsWidgetItem
;
}
QPointF
UBToolWidget
::
naturalCenter
()
const
{
...
...
@@ -242,10 +189,15 @@ QPointF UBToolWidget::naturalCenter() const
return
QPointF
(
0
,
0
);
}
void
UBToolWidget
::
centerOn
(
const
QPointF
&
pos
)
{
QGraphicsWidget
::
setPos
(
pos
-
QPointF
(
preferredWidth
()
/
2
,
preferredHeight
()
/
2
));
}
UBGraphicsWidgetItem
*
UBToolWidget
::
graphicsWidgetItem
()
const
void
UBToolWidget
::
remove
()
{
return
mGraphicsWidgetItem
;
mGraphicsWebView
->
setHtml
(
QString
());
scene
()
->
removeItem
(
this
);
}
UBGraphicsScene
*
UBToolWidget
::
scene
()
...
...
@@ -253,8 +205,22 @@ UBGraphicsScene* UBToolWidget::scene()
return
qobject_cast
<
UBGraphicsScene
*>
(
QGraphicsItem
::
scene
());
}
void
UBToolWidget
::
remove
()
QPointF
UBToolWidget
::
pos
()
const
{
mGraphicsWebView
->
setHtml
(
QString
());
scene
()
->
removeItem
(
this
);
return
QPointF
(
QGraphicsItem
::
pos
().
x
()
+
mContentMargin
*
scale
(),
QGraphicsItem
::
pos
().
y
()
+
mContentMargin
*
scale
());
}
void
UBToolWidget
::
setPos
(
const
QPointF
&
point
)
{
UBToolWidget
::
setPos
(
point
.
x
(),
point
.
y
());
}
void
UBToolWidget
::
setPos
(
qreal
x
,
qreal
y
)
{
QGraphicsItem
::
setPos
(
x
-
mContentMargin
*
scale
(),
y
-
mContentMargin
*
scale
());
}
int
UBToolWidget
::
type
()
const
{
return
Type
;
}
src/gui/UBToolWidget.h
View file @
d2eff8eb
...
...
@@ -18,10 +18,10 @@
#include <QtGui>
#include <QtWebKit>
#include "core/UB.h"
class
UBGraphicsWidgetItem
;
class
QWidget
;
class
UBGraphicsScene
;
class
UBGraphicsWidgetItem
;
class
UBToolWidget
:
public
QGraphicsWidget
{
...
...
@@ -32,44 +32,45 @@ class UBToolWidget : public QGraphicsWidget
UBToolWidget
(
UBGraphicsWidgetItem
*
pGraphicsWidgetItem
,
QGraphicsItem
*
pParent
=
0
);
virtual
~
UBToolWidget
();
void
centerOn
(
const
QPointF
&
pos
);
UBGraphicsWidgetItem
*
graphicsWidgetItem
()
const
;
QPointF
naturalCenter
()
const
;
UBGraphicsWidgetItem
*
graphicsWidgetItem
()
const
;
void
centerOn
(
const
QPointF
&
pos
)
;
void
remove
();
virtual
UBGraphicsScene
*
scene
();
virtual
QPointF
pos
()
const
;
virtual
void
setPos
(
const
QPointF
&
point
);
virtual
void
setPos
(
qreal
x
,
qreal
y
);
virtual
QPointF
pos
()
const
;
virtual
int
type
()
const
;
enum
{
Type
=
UBGraphicsItemType
::
ToolWidgetItemType
};
protected
:
void
initialize
();
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
virtual
bool
event
(
QEvent
*
event
);
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
bool
eventFilter
(
QObject
*
obj
,
QEvent
*
event
);
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
private
slots
:
void
javaScriptWindowObjectCleared
();
protected
:
static
QPixmap
*
sClosePixmap
;
static
QPixmap
*
sUnpinPixmap
;
UBGraphicsWidgetItem
*
mGraphicsWidgetItem
;
QGraphicsWebView
*
mGraphicsWebView
;
QPointF
mMousePressPos
;
bool
mShouldMoveWidget
;
int
mContentMargin
;
int
mFrameWidth
;
QGraphicsWebView
*
mGraphicsWebView
;
UBGraphicsWidgetItem
*
mGraphicsWidgetItem
;
QPointF
mMousePressPos
;
static
QPixmap
*
sClosePixmap
;
static
QPixmap
*
sUnpinPixmap
;
};
#endif
/* UBTOOLWIDGET_H_ */
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