Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
VLMC
Commits
4e5b8788
Commit
4e5b8788
authored
May 08, 2009
by
Ludovic Fauvet
Browse files
Timeline: changes cursor movement behaviour
parent
2ac147e1
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/gui/GraphicsCursorItem.cpp
View file @
4e5b8788
...
...
@@ -3,9 +3,9 @@
GraphicsCursorItem
::
GraphicsCursorItem
(
int
height
,
const
QPen
&
pen
)
:
m_height
(
height
),
m_pen
(
pen
)
{
setFlags
(
QGraphicsItem
::
ItemIgnoresTransformations
);
setZValue
(
100
);
setFlags
(
QGraphicsItem
::
ItemIgnoresTransformations
|
QGraphicsItem
::
ItemIsMovable
);
setCursor
(
QCursor
(
Qt
::
SizeHorCursor
)
);
setZValue
(
100
);
m_boundingRect
=
QRectF
(
-
2
,
0
,
3
,
m_height
);
}
...
...
@@ -20,3 +20,21 @@ void GraphicsCursorItem::paint( QPainter* painter, const QStyleOptionGraphicsIte
painter
->
setPen
(
m_pen
);
painter
->
drawLine
(
0
,
0
,
0
,
m_height
);
}
QVariant
GraphicsCursorItem
::
itemChange
(
GraphicsItemChange
change
,
const
QVariant
&
value
)
{
if
(
change
==
ItemPositionChange
)
{
qreal
posX
=
value
.
toPointF
().
x
();
if
(
posX
<
0
)
posX
=
0
;
if
(
posX
!=
pos
().
x
()
)
emit
cursorPositionChanged
(
posX
);
return
QPoint
(
posX
,
pos
().
y
()
);
}
return
QGraphicsItem
::
itemChange
(
change
,
value
);
}
void
GraphicsCursorItem
::
setCursorPos
(
int
position
)
{
setPos
(
position
,
pos
().
y
()
);
}
src/gui/GraphicsCursorItem.h
View file @
4e5b8788
#ifndef GRAPHICSCURSORITEM_H
#define GRAPHICSCURSORITEM_H
#include <QObject>
#include <QGraphicsItem>
#include <QPen>
#include <QRectF>
#include <QPainter>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
class
GraphicsCursorItem
:
public
QGraphicsItem
class
GraphicsCursorItem
:
public
QObject
,
public
QGraphicsItem
{
Q_OBJECT
public:
GraphicsCursorItem
(
int
height
,
const
QPen
&
pen
);
int
cursorPos
()
const
{
return
pos
().
x
();
}
void
setCursorPos
(
int
position
);
protected:
virtual
QRectF
boundingRect
()
const
;
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
=
0
);
virtual
QVariant
itemChange
(
GraphicsItemChange
change
,
const
QVariant
&
value
);
private:
int
m_height
;
QPen
m_pen
;
QRectF
m_boundingRect
;
signals:
void
cursorPositionChanged
(
int
pos
);
};
#endif // GRAPHICSCURSORITEM_H
src/gui/Timeline.cpp
View file @
4e5b8788
...
...
@@ -53,7 +53,6 @@ Timeline::Timeline( QWidget *parent ) :
setDuration
(
0
);
connect
(
m_tracksView
->
horizontalScrollBar
(),
SIGNAL
(
valueChanged
(
int
)
),
m_tracksRuler
,
SLOT
(
moveRuler
(
int
)
)
);
connect
(
m_tracksView
,
SIGNAL
(
durationChanged
(
int
)
),
this
,
SLOT
(
setDuration
(
int
)
)
);
connect
(
m_tracksView
,
SIGNAL
(
cursorPositionChanged
(
int
)
),
m_tracksRuler
,
SLOT
(
update
()
)
);
}
void
Timeline
::
changeEvent
(
QEvent
*
e
)
...
...
src/gui/TracksRuler.cpp
View file @
4e5b8788
...
...
@@ -41,6 +41,10 @@ TracksRuler::TracksRuler( TracksView* tracksView, QWidget* parent )
m_bigMarkDistance
=
FRAME_SIZE
*
m_fps
*
60
;
setMinimumHeight
(
30
);
setPixelPerMark
(
5
);
// Redraw the ruler when the cursor position change
connect
(
tracksView
->
tracksCursor
(),
SIGNAL
(
cursorPositionChanged
(
int
)
),
this
,
SLOT
(
update
()
)
);
}
void
TracksRuler
::
setPixelPerMark
(
double
rate
)
...
...
src/gui/TracksView.cpp
View file @
4e5b8788
...
...
@@ -50,8 +50,6 @@ TracksView::TracksView( QGraphicsScene* scene, QWidget* parent )
const
int
maxHeight
=
m_tracksHeight
*
m_tracksCount
;
setSceneRect
(
0
,
0
,
sceneRect
().
width
(),
maxHeight
);
m_cursorPos
=
0
;
m_cursorLine
=
new
GraphicsCursorItem
(
maxHeight
,
QPen
(
QColor
(
220
,
30
,
30
)
)
);
m_scene
->
addItem
(
m_cursorLine
);
}
...
...
@@ -117,12 +115,6 @@ void TracksView::drawBackground( QPainter* painter, const QRectF& rect )
void
TracksView
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
int
mappedXPos
=
(
int
)(
mapToScene
(
event
->
pos
()
).
x
()
+
0.5
);
if
(
event
->
buttons
()
==
Qt
::
LeftButton
&&
event
->
modifiers
()
==
Qt
::
NoModifier
)
{
setCursorPos
(
mappedXPos
);
}
QGraphicsView
::
mouseMoveEvent
(
event
);
}
...
...
@@ -147,18 +139,13 @@ void TracksView::mousePressEvent( QMouseEvent* event )
return
;
}
int
mappedXPos
=
(
int
)(
mapToScene
(
event
->
pos
()
).
x
()
+
0.5
);
if
(
event
->
buttons
()
==
Qt
::
LeftButton
&&
event
->
modifiers
()
==
Qt
::
NoModifier
)
{
setCursorPos
(
mappedXPos
);
}
QGraphicsView
::
mousePressEvent
(
event
);
}
void
TracksView
::
mouseReleaseEvent
(
QMouseEvent
*
)
void
TracksView
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
setDragMode
(
QGraphicsView
::
NoDrag
);
QGraphicsView
::
mouseReleaseEvent
(
event
);
}
void
TracksView
::
wheelEvent
(
QWheelEvent
*
event
)
...
...
@@ -182,15 +169,13 @@ void TracksView::wheelEvent( QWheelEvent* event )
void
TracksView
::
setCursorPos
(
int
pos
)
{
m_cursorPos
=
pos
;
if
(
m_cursorPos
<
0
)
m_cursorPos
=
0
;
m_cursorLine
->
setPos
(
m_cursorPos
,
0
);
emit
cursorPositionChanged
(
pos
);
if
(
pos
<
0
)
pos
=
0
;
m_cursorLine
->
setCursorPos
(
pos
);
}
int
TracksView
::
cursorPos
()
{
return
m_cursorPos
;
return
m_
cursorLine
->
cursorPos
()
;
}
void
TracksView
::
addClip
(
Media
*
clip
,
const
QPoint
&
point
)
...
...
src/gui/TracksView.h
View file @
4e5b8788
...
...
@@ -45,6 +45,7 @@ public:
int
tracksCount
()
const
{
return
m_tracksCount
;
}
void
setCursorPos
(
int
pos
);
int
cursorPos
();
GraphicsCursorItem
*
tracksCursor
()
const
{
return
m_cursorLine
;
}
void
addClip
(
Media
*
clip
,
const
QPoint
&
point
);
void
setScale
(
double
scaleFactor
);
...
...
@@ -64,7 +65,6 @@ private:
int
m_tracksHeight
;
int
m_tracksCount
;
int
m_projectDuration
;
int
m_cursorPos
;
int
m_fps
;
GraphicsCursorItem
*
m_cursorLine
;
...
...
@@ -72,7 +72,6 @@ signals:
void
zoomIn
();
void
zoomOut
();
void
durationChanged
(
int
duration
);
void
cursorPositionChanged
(
int
pos
);
};
#endif // TRACKSVIEW_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