tahoma2d/toonz/sources/toonzqt/framenavigator.cpp

112 lines
3.2 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
// TnzLib includes
#include "toonz/tframehandle.h"
// TnzQt includes
#include "toonzqt/gutil.h"
// Qt includes
#include <QAction>
#include "toonzqt/framenavigator.h"
using namespace DVGui;
//=============================================================================
// FrameNavigator
//-----------------------------------------------------------------------------
FrameNavigator::FrameNavigator(QWidget *parent)
2016-06-15 18:43:10 +12:00
: QToolBar(parent), m_frame(0), m_lineEdit(0), m_frameHandle(0) {
setMaximumWidth(130);
QAction *prevButton =
new QAction(createQIconPNG("frameprev"), tr("Previous Frame"), this);
connect(prevButton, SIGNAL(triggered()), this, SLOT(prevFrame()));
addAction(prevButton);
m_lineEdit = new DVGui::IntLineEdit(this);
m_lineEdit->setFixedHeight(16);
bool ret = connect(m_lineEdit, SIGNAL(editingFinished()), this,
SLOT(onEditingFinished()));
addWidget(m_lineEdit);
QAction *nextButton =
new QAction(createQIconPNG("framenext"), tr("Next Frame"), this);
ret =
ret && connect(nextButton, SIGNAL(triggered()), this, SLOT(nextFrame()));
addAction(nextButton);
assert(ret);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool FrameNavigator::anyWidgetHasFocus() {
return hasFocus() || m_lineEdit->hasFocus() || m_lineEdit->hasFocus();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::setFrameHandle(TFrameHandle *fh) {
if (fh == m_frameHandle) return;
if (isVisible() && m_frameHandle)
disconnect(m_frameHandle, SIGNAL(frameSwitched()), this,
SLOT(onFrameSwitched()));
m_frameHandle = fh;
if (m_frameHandle) {
if (isVisible())
connect(m_frameHandle, SIGNAL(frameSwitched()), this,
SLOT(onFrameSwitched()));
updateFrame(m_frameHandle->getFrame());
}
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::updateFrame(int frame) {
m_frame = frame;
m_lineEdit->setValue(m_frame + 1);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::setFrame(int frame, bool notifyFrameHandler) {
if (m_frame == frame) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
updateFrame(frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_frameHandle && notifyFrameHandler) m_frameHandle->setFrame(frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (notifyFrameHandler) emit frameSwitched();
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::onEditingFinished() {
setFrame(m_lineEdit->getValue() - 1, true);
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::onFrameSwitched() {
if (m_frameHandle) updateFrame(m_frameHandle->getFrame());
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::showEvent(QShowEvent *) {
onFrameSwitched();
if (m_frameHandle)
connect(m_frameHandle, SIGNAL(frameSwitched()), this,
SLOT(onFrameSwitched()));
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FrameNavigator::hideEvent(QHideEvent *) {
if (m_frameHandle)
disconnect(m_frameHandle, SIGNAL(frameSwitched()), this,
SLOT(onFrameSwitched()));
2016-03-19 06:57:51 +13:00
}