Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Games
Palapeli
Commits
8b77baaa
Commit
8b77baaa
authored
Apr 24, 2010
by
Stefan Majewsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ScrollViewportInteractor.
svn path=/trunk/KDE/kdegames/palapeli/; revision=1118501
parent
0f3846ef
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
6 deletions
+49
-6
src/engine/interactors.cpp
src/engine/interactors.cpp
+27
-6
src/engine/interactors.h
src/engine/interactors.h
+12
-0
src/engine/triggermapper.cpp
src/engine/triggermapper.cpp
+2
-0
src/engine/view.cpp
src/engine/view.cpp
+7
-0
src/engine/view.h
src/engine/view.h
+1
-0
No files found.
src/engine/interactors.cpp
View file @
8b77baaa
...
...
@@ -20,7 +20,6 @@
#include "piece.h"
#include "view.h"
#include <QScrollBar>
#include <QStyle>
#include <QStyleOptionRubberBand>
#include <KLocalizedString>
...
...
@@ -155,18 +154,17 @@ bool Palapeli::MoveViewportInteractor::startInteraction(const Palapeli::MouseEve
void
Palapeli
::
MoveViewportInteractor
::
continueInteraction
(
const
Palapeli
::
MouseEvent
&
event
)
{
QGraphicsView
*
v
=
view
();
const
QPointF
delta
=
event
.
pos
-
m_lastPos
;
Palapeli
::
View
*
view
=
qobject_cast
<
Palapeli
::
View
*>
(
this
->
view
());
if
(
view
)
view
->
moveViewportBy
(
event
.
pos
-
m_lastPos
);
m_lastPos
=
event
.
pos
;
v
->
horizontalScrollBar
()
->
setValue
(
v
->
horizontalScrollBar
()
->
value
()
+
(
v
->
isRightToLeft
()
?
delta
.
x
()
:
-
delta
.
x
()));
v
->
verticalScrollBar
()
->
setValue
(
v
->
verticalScrollBar
()
->
value
()
-
delta
.
y
());
}
//END Palapeli::MoveViewportInteractor
//BEGIN Palapeli::ZoomViewportInteractor
Palapeli
::
ZoomViewportInteractor
::
ZoomViewportInteractor
(
QGraphicsView
*
view
)
:
Palapeli
::
Interactor
(
0
,
Palapeli
::
WheelInteractor
,
view
)
//priority: un
decided
ATM
:
Palapeli
::
Interactor
(
0
,
Palapeli
::
WheelInteractor
,
view
)
//priority: un
used for wheel interactors
ATM
{
setMetadata
(
ViewportInteraction
,
i18nc
(
"Description (used like a name) for a mouse interaction method"
,
"Zoom viewport"
),
QIcon
());
}
...
...
@@ -179,6 +177,29 @@ void Palapeli::ZoomViewportInteractor::doInteraction(const Palapeli::WheelEvent&
}
//END Palapeli::ZoomViewportInteractor
//BEGIN Palapeli::ScrollViewportInteractor
Palapeli
::
ScrollViewportInteractor
::
ScrollViewportInteractor
(
Qt
::
Orientation
orientation
,
QGraphicsView
*
view
)
:
Palapeli
::
Interactor
(
0
,
Palapeli
::
WheelInteractor
,
view
)
//priority: unused for wheel interactors ATM
,
m_orientation
(
orientation
)
{
QString
description
;
if
(
orientation
==
Qt
::
Horizontal
)
description
=
i18nc
(
"Description (used like a name) for a mouse interaction method"
,
"Scroll viewport horizontally"
);
else
description
=
i18nc
(
"Description (used like a name) for a mouse interaction method"
,
"Scroll viewport vertically"
);
setMetadata
(
ViewportInteraction
,
description
,
QIcon
());
}
void
Palapeli
::
ScrollViewportInteractor
::
doInteraction
(
const
Palapeli
::
WheelEvent
&
event
)
{
const
QPoint
widgetDelta
=
(
m_orientation
==
Qt
::
Horizontal
)
?
QPoint
(
event
.
delta
,
0
)
:
QPoint
(
0
,
event
.
delta
);
Palapeli
::
View
*
view
=
qobject_cast
<
Palapeli
::
View
*>
(
this
->
view
());
if
(
view
)
view
->
moveViewportBy
(
view
->
mapToScene
(
widgetDelta
)
-
view
->
mapToScene
(
QPoint
()));
}
//END Palapeli::ScrollViewportInteractor
//BEGIN Palapeli::RubberBandItem
Palapeli
::
RubberBandItem
::
RubberBandItem
(
QGraphicsItem
*
parent
)
...
...
src/engine/interactors.h
View file @
8b77baaa
...
...
@@ -81,6 +81,18 @@ namespace Palapeli
virtual
void
doInteraction
(
const
Palapeli
::
WheelEvent
&
event
);
};
//This interactor is assigned to nothing by default.
//Turning the wheel will scroll the viewport either horizontally or vertically.
class
ScrollViewportInteractor
:
public
Palapeli
::
Interactor
{
public:
ScrollViewportInteractor
(
Qt
::
Orientation
orientation
,
QGraphicsView
*
view
);
protected:
virtual
void
doInteraction
(
const
Palapeli
::
WheelEvent
&
event
);
private:
Qt
::
Orientation
m_orientation
;
};
class
RubberBandItem
:
public
QGraphicsItem
{
public:
...
...
src/engine/triggermapper.cpp
View file @
8b77baaa
...
...
@@ -40,6 +40,8 @@ QMap<QByteArray, Palapeli::Interactor*> Palapeli::TriggerMapper::createInteracto
result
[
"SelectPiece"
]
=
new
Palapeli
::
SelectPieceInteractor
(
view
);
result
[
"MoveViewport"
]
=
new
Palapeli
::
MoveViewportInteractor
(
view
);
result
[
"ZoomViewport"
]
=
new
Palapeli
::
ZoomViewportInteractor
(
view
);
result
[
"ScrollViewportHoriz"
]
=
new
Palapeli
::
ScrollViewportInteractor
(
Qt
::
Horizontal
,
view
);
result
[
"ScrollViewportVert"
]
=
new
Palapeli
::
ScrollViewportInteractor
(
Qt
::
Vertical
,
view
);
result
[
"RubberBand"
]
=
new
Palapeli
::
RubberBandInteractor
(
view
);
result
[
"Constraints"
]
=
new
Palapeli
::
ConstraintInteractor
(
view
);
return
result
;
...
...
src/engine/view.cpp
View file @
8b77baaa
...
...
@@ -24,6 +24,7 @@
#include <cmath>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QScrollBar>
#include <KLocalizedString>
#include <KMessageBox>
...
...
@@ -118,6 +119,12 @@ void Palapeli::View::wheelEvent(QWheelEvent* event)
//We do intentionally *not* propagate to QGV::wheelEvent.
}
void
Palapeli
::
View
::
moveViewportBy
(
const
QPointF
&
sceneDelta
)
{
horizontalScrollBar
()
->
setValue
(
horizontalScrollBar
()
->
value
()
+
(
isRightToLeft
()
?
sceneDelta
.
x
()
:
-
sceneDelta
.
x
()));
verticalScrollBar
()
->
setValue
(
verticalScrollBar
()
->
value
()
-
sceneDelta
.
y
());
}
void
Palapeli
::
View
::
zoomBy
(
int
delta
)
{
zoomTo
(
m_zoomLevel
+
delta
/
10
);
...
...
src/engine/view.h
View file @
8b77baaa
...
...
@@ -45,6 +45,7 @@ namespace Palapeli
public
Q_SLOTS
:
void
setScene
(
Palapeli
::
Scene
*
scene
);
void
moveViewportBy
(
const
QPointF
&
sceneDelta
);
void
zoomIn
();
void
zoomOut
();
void
zoomBy
(
int
delta
);
//delta = 0 -> no change, delta < 0 -> zoom out, delta > 0 -> zoom in
...
...
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