1#include <Gui/Timeline/TimelineScrollArea.hpp>
8#include <Gui/Timeline/Timeline.hpp>
9#include <Gui/Timeline/TimelineFrameSelector.hpp>
13TimelineScrollArea::TimelineScrollArea( QWidget* parent ) : QScrollArea( parent ) {
14 horizontalScrollBar()->setStyleSheet(
"\
15 QScrollBar:horizontal {\
16 background: transparent;\
19 QScrollBar::handle:horizontal {\
23 QScrollBar::add-line:horizontal {\
25 background: transparent;\
28 QScrollBar::sub-line:horizontal {\
30 background: transparent;\
34int TimelineScrollArea::getNbInterval() {
38Scalar TimelineScrollArea::getMaxDuration() {
42void TimelineScrollArea::setMaxDuration( Scalar duration ) {
43 m_maxDuration = duration;
46int TimelineScrollArea::getZero() {
50Scalar TimelineScrollArea::getPixPerSec() {
54Scalar TimelineScrollArea::getStep() {
58void TimelineScrollArea::onDrawRuler(
int width ) {
60 while ( iStep < s_nbSteps && width * s_steps[iStep] < 50 * m_maxDuration )
63 if ( iStep == s_nbSteps ) {
return; }
65 m_step = s_steps[iStep];
66 emit stepChanged( m_step );
68 m_nbInterval = int(
std::ceil( m_maxDuration / m_step ) ) + 2;
69 m_pixPerSec = ( Scalar( width ) / m_nbInterval ) / m_step;
70 m_zero = int( m_pixPerSec * m_step );
71 widget()->setMinimumWidth( width );
76void TimelineScrollArea::keyPressEvent( QKeyEvent* event ) {
77 switch ( event->key() ) {
79 emit togglePlayPause();
83 emit removeKeyFrame();
87 if ( event->modifiers() & Qt::Modifier::SHIFT ) { emit removeKeyFrame(); }
88 else { emit addKeyFrame(); }
92 emit previousKeyFrame();
100 emit durationIncrement();
104 emit durationDecrement();
108 if ( event->modifiers() & Qt::Modifier::CTRL ) {
109 if ( event->modifiers() & Qt::Modifier::SHIFT ) { emit redo(); }
110 else { emit undo(); }
126void TimelineScrollArea::wheelEvent( QWheelEvent* event ) {
127 int ry =
event->angleDelta().ry();
128 bool ctrlDown =
event->modifiers() & Qt::Modifier::CTRL;
129 bool shiftDown =
event->modifiers() & Qt::Modifier::SHIFT;
132 if ( ry > 0 ) { emit nextKeyFrame(); }
133 else { emit previousKeyFrame(); }
136 else if ( ctrlDown ) {
137 horizontalScrollBar()->setValue(
138 int( horizontalScrollBar()->value() + ry * TIMELINE_SLIDE_SPEED ) );
142 int newRulerWidth = int( widget()->minimumWidth() +
143 ry * TIMELINE_ZOOM_SPEED * widget()->minimumWidth() / width() );
144 if ( newRulerWidth <= width() - 2 ) {
145 if ( widget()->minimumWidth() == width() - 2 ) {
return; }
146 else { newRulerWidth = width() - 2; }
149 double hScroll = horizontalScrollBar()->value();
151 double x =
event->position().x();
153 double time = ( hScroll + x - double( m_zero ) ) /
double( m_pixPerSec );
155 onDrawRuler( newRulerWidth );
158 double a =
time * double( m_pixPerSec ) + double( m_zero );
159 double hScrollAfterProjection = a - x;
160 horizontalScrollBar()->setValue(
static_cast<int>( hScrollAfterProjection ) );
165void TimelineScrollArea::mousePressEvent( QMouseEvent* event ) {
166 if ( event->button() == Qt::MiddleButton ) {
167 setCursor( Qt::SplitHCursor );
168 m_mousePosX =
event->x();
169 m_sliderPos = horizontalScrollBar()->value();
173void TimelineScrollArea::mouseReleaseEvent( QMouseEvent* event ) {
174 if ( event->button() == Qt::MiddleButton ) { setCursor( Qt::ArrowCursor ); }
177void TimelineScrollArea::mouseMoveEvent( QMouseEvent* event ) {
178 if ( event->buttons() & Qt::MiddleButton ) {
179 horizontalScrollBar()->setValue( ( m_sliderPos + m_mousePosX - event->x() ) );