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)
Shinya Kitaoka 120a6e
    : QToolBar(parent), m_frame(0), m_lineEdit(0), m_frameHandle(0) {
Shinya Kitaoka 120a6e
  setMaximumWidth(130);
Shinya Kitaoka 120a6e
  QAction *prevButton =
Shinya Kitaoka 120a6e
      new QAction(createQIconPNG("frameprev"), tr("Previous Frame"), this);
Shinya Kitaoka 120a6e
  connect(prevButton, SIGNAL(triggered()), this, SLOT(prevFrame()));
Shinya Kitaoka 120a6e
  addAction(prevButton);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_lineEdit = new DVGui::IntLineEdit(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_lineEdit->setFixedHeight(16);
Shinya Kitaoka 120a6e
  bool ret = connect(m_lineEdit, SIGNAL(editingFinished()), this,
Shinya Kitaoka 120a6e
                     SLOT(onEditingFinished()));
Shinya Kitaoka 120a6e
  addWidget(m_lineEdit);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction *nextButton =
Shinya Kitaoka 120a6e
      new QAction(createQIconPNG("framenext"), tr("Next Frame"), this);
Shinya Kitaoka 120a6e
  ret =
Shinya Kitaoka 120a6e
      ret && connect(nextButton, SIGNAL(triggered()), this, SLOT(nextFrame()));
Shinya Kitaoka 120a6e
  addAction(nextButton);
Shinya Kitaoka 120a6e
  assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FrameNavigator::anyWidgetHasFocus() {
Shinya Kitaoka 120a6e
  return hasFocus() || m_lineEdit->hasFocus() || m_lineEdit->hasFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::setFrameHandle(TFrameHandle *fh) {
Shinya Kitaoka 120a6e
  if (fh == m_frameHandle) return;
Shinya Kitaoka 120a6e
  if (isVisible() && m_frameHandle)
Shinya Kitaoka 120a6e
    disconnect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
               SLOT(onFrameSwitched()));
Shinya Kitaoka 120a6e
  m_frameHandle = fh;
Shinya Kitaoka 120a6e
  if (m_frameHandle) {
Shinya Kitaoka 120a6e
    if (isVisible())
Shinya Kitaoka 120a6e
      connect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
              SLOT(onFrameSwitched()));
Shinya Kitaoka 120a6e
    updateFrame(m_frameHandle->getFrame());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::updateFrame(int frame) {
Shinya Kitaoka 120a6e
  m_frame = frame;
Shinya Kitaoka 120a6e
  m_lineEdit->setValue(m_frame + 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::setFrame(int frame, bool notifyFrameHandler) {
Shinya Kitaoka 120a6e
  if (m_frame == frame) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateFrame(frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_frameHandle && notifyFrameHandler) m_frameHandle->setFrame(frame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (notifyFrameHandler) emit frameSwitched();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::onEditingFinished() {
Shinya Kitaoka 120a6e
  setFrame(m_lineEdit->getValue() - 1, true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::onFrameSwitched() {
Shinya Kitaoka 120a6e
  if (m_frameHandle) updateFrame(m_frameHandle->getFrame());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::showEvent(QShowEvent *) {
Shinya Kitaoka 120a6e
  onFrameSwitched();
Shinya Kitaoka 120a6e
  if (m_frameHandle)
Shinya Kitaoka 120a6e
    connect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
            SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameNavigator::hideEvent(QHideEvent *) {
Shinya Kitaoka 120a6e
  if (m_frameHandle)
Shinya Kitaoka 120a6e
    disconnect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
               SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
}