24 #include <QHBoxLayout>
28 #include <QMessageBox>
30 #include <QWheelEvent>
34 #include "layermanager.h"
35 #include "timecontrols.h"
36 #include "timelinecells.h"
43 void TimeLine::initUI()
45 Q_ASSERT( editor() !=
nullptr );
47 setWindowTitle( tr(
"Timeline" ) );
49 QWidget* timeLineContent =
new QWidget(
this );
51 mLayerList =
new TimeLineCells(
this, editor(), TIMELINE_CELL_TYPE::Layers );
52 mTracks =
new TimeLineCells(
this, editor(), TIMELINE_CELL_TYPE::Tracks );
54 mHScrollbar =
new QScrollBar( Qt::Horizontal );
55 mVScrollbar =
new QScrollBar( Qt::Vertical );
56 mVScrollbar->setMinimum( 0 );
57 mVScrollbar->setMaximum( 1 );
58 mVScrollbar->setPageStep( 1 );
60 QWidget* leftWidget =
new QWidget();
61 leftWidget->setMinimumWidth( 120 );
62 QWidget* rightWidget =
new QWidget();
64 QWidget* leftToolBar =
new QWidget();
65 leftToolBar->setFixedHeight( 30 );
66 QWidget* rightToolBar =
new QWidget();
67 rightToolBar->setFixedHeight( 30 );
71 QToolBar* layerButtons =
new QToolBar(
this );
72 QLabel* layerLabel =
new QLabel( tr(
"Layers:" ) );
73 layerLabel->setIndent( 5 );
74 layerLabel->setFont( QFont(
"Helvetica", 10 ) );
76 QToolButton* addLayerButton =
new QToolButton(
this );
77 addLayerButton->setIcon( QIcon(
":icons/add.png" ) );
78 addLayerButton->setToolTip( tr(
"Add Layer") );
79 addLayerButton->setFixedSize( 24, 24 );
81 QToolButton* removeLayerButton =
new QToolButton(
this );
82 removeLayerButton->setIcon( QIcon(
":icons/remove.png" ) );
83 removeLayerButton->setToolTip( tr(
"Remove Layer") );
84 removeLayerButton->setFixedSize( 24, 24 );
86 layerButtons->addWidget( layerLabel );
87 layerButtons->addWidget( addLayerButton );
88 layerButtons->addWidget( removeLayerButton );
89 layerButtons->setFixedHeight(30);
91 QHBoxLayout* leftToolBarLayout =
new QHBoxLayout();
92 leftToolBarLayout->setMargin( 0 );
93 leftToolBarLayout->addWidget( layerButtons );
94 leftToolBar->setLayout( leftToolBarLayout );
96 QAction* newBitmapLayerAct =
new QAction( QIcon(
":icons/layer-bitmap.png" ), tr(
"New Bitmap Layer" ),
this );
97 QAction* newVectorLayerAct =
new QAction( QIcon(
":icons/layer-vector.png" ), tr(
"New Vector Layer" ),
this );
98 QAction* newSoundLayerAct =
new QAction( QIcon(
":icons/layer-sound.png" ), tr(
"New Sound Layer" ),
this );
99 QAction* newCameraLayerAct =
new QAction( QIcon(
":icons/layer-camera.png" ), tr(
"New Camera Layer" ),
this );
101 QMenu* layerMenu =
new QMenu( tr(
"&Layer" ),
this );
102 layerMenu->addAction( newBitmapLayerAct );
103 layerMenu->addAction( newVectorLayerAct );
104 layerMenu->addAction( newSoundLayerAct );
105 layerMenu->addAction( newCameraLayerAct );
106 addLayerButton->setMenu( layerMenu );
107 addLayerButton->setPopupMode( QToolButton::InstantPopup );
109 QGridLayout* leftLayout =
new QGridLayout();
110 leftLayout->addWidget( leftToolBar, 0, 0 );
111 leftLayout->addWidget( mLayerList, 1, 0 );
112 leftLayout->setMargin( 0 );
113 leftLayout->setSpacing( 0 );
114 leftWidget->setLayout( leftLayout );
118 QToolBar* timelineButtons =
new QToolBar(
this );
119 QLabel* keyLabel =
new QLabel( tr(
"Keys:" ) );
120 keyLabel->setFont( QFont(
"Helvetica", 10 ) );
121 keyLabel->setIndent( 5 );
123 QToolButton* addKeyButton =
new QToolButton(
this );
124 addKeyButton->setIcon( QIcon(
":icons/add.png" ) );
125 addKeyButton->setToolTip( tr(
"Add Frame") );
126 addKeyButton->setFixedSize( 24, 24 );
128 QToolButton* removeKeyButton =
new QToolButton(
this );
129 removeKeyButton->setIcon( QIcon(
":icons/remove.png" ) );
130 removeKeyButton->setToolTip( tr(
"Remove Frame") );
131 removeKeyButton->setFixedSize( 24, 24 );
133 QToolButton* duplicateKeyButton =
new QToolButton(
this );
134 duplicateKeyButton->setIcon( QIcon(
":icons/controls/duplicate.png" ) );
135 duplicateKeyButton->setToolTip( tr(
"Duplicate Frame") );
136 duplicateKeyButton->setFixedSize( 24, 24 );
138 QLabel* onionLabel =
new QLabel( tr(
"Onion skin:" ) );
139 onionLabel->setFont( QFont(
"Helvetica", 10 ) );
141 QToolButton* onionTypeButton =
new QToolButton(
this );
142 onionTypeButton->setIcon( QIcon(
":icons/onion_type.png" ) );
143 onionTypeButton->setToolTip( tr(
"Toggle match keyframes") );
144 onionTypeButton->setFixedSize( 24, 24 );
146 timelineButtons->addWidget( keyLabel );
147 timelineButtons->addWidget( addKeyButton );
148 timelineButtons->addWidget( removeKeyButton );
149 timelineButtons->addWidget( duplicateKeyButton );
150 timelineButtons->addSeparator();
151 timelineButtons->addWidget( onionLabel );
152 timelineButtons->addWidget( onionTypeButton );
153 timelineButtons->addSeparator();
154 timelineButtons->setFixedHeight(30);
158 mTimeControls->setCore( editor() );
159 mTimeControls->initUI();
160 mTimeControls->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
163 QHBoxLayout* rightToolBarLayout =
new QHBoxLayout();
164 rightToolBarLayout->addWidget( timelineButtons );
165 rightToolBarLayout->setAlignment(Qt::AlignLeft);
166 rightToolBarLayout->addWidget( mTimeControls );
167 rightToolBarLayout->setMargin( 0 );
168 rightToolBarLayout->setSpacing( 0 );
169 rightToolBar->setLayout( rightToolBarLayout );
171 QGridLayout* rightLayout =
new QGridLayout();
172 rightLayout->addWidget( rightToolBar, 0, 0 );
173 rightLayout->addWidget( mTracks, 1, 0 );
174 rightLayout->setMargin( 0 );
175 rightLayout->setSpacing( 0 );
176 rightWidget->setLayout( rightLayout );
179 QSplitter* splitter =
new QSplitter(
this );
180 splitter->addWidget( leftWidget );
181 splitter->addWidget( rightWidget );
182 splitter->setSizes(
QList<int>() << 100 << 600 );
185 QGridLayout* lay =
new QGridLayout();
186 lay->addWidget( splitter, 0, 0 );
187 lay->addWidget( mVScrollbar, 0, 1 );
188 lay->addWidget( mHScrollbar, 1, 0 );
190 lay->setSpacing( 0 );
191 timeLineContent->setLayout( lay );
192 setWidget( timeLineContent );
194 setWindowFlags( Qt::WindowStaysOnTopHint );
196 connect( mHScrollbar, &QScrollBar::valueChanged, mTracks, &TimeLineCells::hScrollChange );
197 connect (mTracks, &TimeLineCells::offsetChanged, mHScrollbar, &QScrollBar::setValue);
198 connect( mVScrollbar, &QScrollBar::valueChanged, mTracks, &TimeLineCells::vScrollChange );
199 connect( mVScrollbar, &QScrollBar::valueChanged, mLayerList, &TimeLineCells::vScrollChange );
201 connect( splitter, &QSplitter::splitterMoved,
this, &TimeLine::updateLength );
203 connect( addKeyButton, &QToolButton::clicked,
this, &TimeLine::addKeyClick );
204 connect( removeKeyButton, &QToolButton::clicked,
this, &TimeLine::removeKeyClick );
205 connect( duplicateKeyButton, &QToolButton::clicked,
this, &TimeLine::duplicateKeyClick );
206 connect( onionTypeButton, &QToolButton::clicked,
this, &TimeLine::toogleAbsoluteOnionClick );
208 connect( mTimeControls, &TimeControls::loopStartClick,
this, &TimeLine::loopStartClick );
209 connect( mTimeControls, &TimeControls::loopEndClick,
this, &TimeLine::loopEndClick );
210 connect( mTimeControls, &TimeControls::loopStartClick,
this, &TimeLine::updateLength );
211 connect( mTimeControls, &TimeControls::loopEndClick,
this, &TimeLine::updateLength );
212 connect( mTimeControls, &TimeControls::rangeStateChange,
this, &TimeLine::updateLength );
214 connect( mTimeControls, &TimeControls::soundClick,
this, &TimeLine::soundClick );
215 connect( mTimeControls, &TimeControls::fpsClick,
this, &TimeLine::fpsClick );
216 connect( mTimeControls, &TimeControls::fpsClick,
this, &TimeLine::updateLength );
218 connect( newBitmapLayerAct, &QAction::triggered,
this, &TimeLine::newBitmapLayer );
219 connect( newVectorLayerAct, &QAction::triggered,
this, &TimeLine::newVectorLayer );
220 connect( newSoundLayerAct, &QAction::triggered,
this, &TimeLine::newSoundLayer );
221 connect( newCameraLayerAct, &QAction::triggered,
this, &TimeLine::newCameraLayer );
222 connect( removeLayerButton, &QPushButton::clicked,
this, &TimeLine::deleteCurrentLayer );
224 connect( mLayerList, &TimeLineCells::mouseMovedY, mLayerList, &TimeLineCells::setMouseMoveY );
225 connect( mLayerList, &TimeLineCells::mouseMovedY, mTracks, &TimeLineCells::setMouseMoveY );
226 connect (mTracks, &TimeLineCells::lengthChanged,
this, &TimeLine::updateLength );
228 connect( editor(), &Editor::currentFrameChanged,
this, &TimeLine::updateFrame );
231 connect( layer, &LayerManager::layerCountChanged,
this, &TimeLine::updateLayerNumber );
236 void TimeLine::updateUI()
239 mLayerList->update();
242 int TimeLine::getFrameLength()
244 return mTracks->getFrameLength();
247 void TimeLine::resizeEvent(QResizeEvent*)
252 void TimeLine::wheelEvent(QWheelEvent* event)
254 if( event->modifiers() & Qt::ShiftModifier )
256 mHScrollbar->event(event);
260 mVScrollbar->event(event);
297 void TimeLine::deleteCurrentLayer()
299 QString strLayerName = editor()->layers()->currentLayer()->name();
301 int ret = QMessageBox::warning(
this,
303 tr(
"Are you sure you want to delete layer: " ) + strLayerName +
" ?",
304 QMessageBox::Ok | QMessageBox::Cancel,
306 if ( ret == QMessageBox::Ok )
308 editor()->layers()->deleteCurrentLayer();
312 void TimeLine::updateFrame(
int frameNumber )
314 Q_ASSERT ( mTracks );
316 mTracks->updateFrame( mLastUpdatedFrame );
317 mTracks->updateFrame( frameNumber );
319 mLastUpdatedFrame = frameNumber;
322 void TimeLine::updateLayerView()
324 int pageDisplay = ( mTracks->height() - mTracks->getOffsetY() ) / mTracks->getLayerHeight();
326 mVScrollbar->setMinimum( 0 );
327 mVScrollbar->setMaximum( qMax(0, qMax( 0, mNumLayers - pageDisplay ) ) );
332 void TimeLine::updateLayerNumber(
int numberOfLayers)
334 mNumLayers = numberOfLayers;
338 void TimeLine::updateLength()
340 int frameLength = getFrameLength();
341 mHScrollbar->setMaximum( qMax( 0, frameLength - mTracks->width() / mTracks->getFrameSize() ) );
342 mTimeControls->updateLength(frameLength);
347 void TimeLine::updateContent()
349 mLayerList->updateContent();
350 mTracks->updateContent();
354 void TimeLine::setLoop(
bool loop )
356 mTimeControls->toggleLoop(loop);
359 void TimeLine::setPlaying(
bool isPlaying )
362 mTimeControls->updatePlayState();
365 void TimeLine::setRangeState(
bool range )
367 mTimeControls->toggleLoopControl(range);
370 int TimeLine::getRangeLower()
372 return mTimeControls->getRangeLower();
375 int TimeLine::getRangeUpper()
377 return mTimeControls->getRangeUpper();
380 void TimeLine::onObjectLoaded()
382 mTimeControls->updateUI();