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