Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/flipconsole.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/menubarcommand.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvscrollwidget.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/flipconsoleowner.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "../toonz/tapp.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
Toshihiro Shimizu 890ddd
#include <qhboxlayout></qhboxlayout>
Toshihiro Shimizu 890ddd
#include <qtoolbar></qtoolbar>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qframe></qframe>
Toshihiro Shimizu 890ddd
#include <qslider></qslider>
Toshihiro Shimizu 890ddd
#include <qtimerevent></qtimerevent>
Toshihiro Shimizu 890ddd
#include <qtoolbutton></qtoolbutton>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qicon></qicon>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qwidgetaction></qwidgetaction>
Toshihiro Shimizu 890ddd
#include <qstyle></qstyle>
Toshihiro Shimizu 890ddd
#include <qstylepainter></qstylepainter>
Toshihiro Shimizu 890ddd
#include <qstyleoption></qstyleoption>
Toshihiro Shimizu 890ddd
#include <qstyleoptionframev3></qstyleoptionframev3>
Toshihiro Shimizu 890ddd
#include <qsettings></qsettings>
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qscrollbar></qscrollbar>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================================
Toshihiro Shimizu 890ddd
//    Preliminary stuff - local namespace
Toshihiro Shimizu 890ddd
//==========================================================================================
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookWhiteBgToggle("FlipBookWhiteBgToggle", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookBlackBgToggle("FlipBookBlackBgToggle", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar FlipBookCheckBgToggle("FlipBookCheckBgToggle", 0);
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
// Please refer to the "qss/standard/standard.qss" file for explanations of the
Shinya Kitaoka 120a6e
// following properties.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int PBHeight;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QImage PBOverlay;
Toshihiro Shimizu 890ddd
QImage PBMarker;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int PBColorMarginLeft   = 0;
Shinya Kitaoka 120a6e
int PBColorMarginTop    = 0;
Shinya Kitaoka 120a6e
int PBColorMarginRight  = 0;
Toshihiro Shimizu 890ddd
int PBColorMarginBottom = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int PBMarkerMarginLeft  = 0;
Toshihiro Shimizu 890ddd
int PBMarkerMarginRight = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QColor PBBaseColor       = QColor(235, 235, 235);
Toshihiro Shimizu 890ddd
QColor PBNotStartedColor = QColor(210, 40, 40);
Shinya Kitaoka 120a6e
QColor PBStartedColor    = QColor(220, 160, 160);
Shinya Kitaoka 120a6e
QColor PBFinishedColor   = QColor(235, 235, 235);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBHeight() const { return PBHeight; }
Shinya Kitaoka 120a6e
void FlipSlider::setPBHeight(int height) {
Shinya Kitaoka 120a6e
  setFixedHeight(height);
Shinya Kitaoka 120a6e
  PBHeight = height;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QImage FlipSlider::getPBOverlay() const { return PBOverlay; }
Toshihiro Shimizu 890ddd
void FlipSlider::setPBOverlay(const QImage &img) { PBOverlay = img; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QImage FlipSlider::getPBMarker() const { return PBMarker; }
Toshihiro Shimizu 890ddd
void FlipSlider::setPBMarker(const QImage &img) { PBMarker = img; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBColorMarginLeft() const { return PBColorMarginLeft; }
Shinya Kitaoka 120a6e
void FlipSlider::setPBColorMarginLeft(int margin) {
Shinya Kitaoka 120a6e
  PBColorMarginLeft = margin;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBColorMarginTop() const { return PBColorMarginTop; }
Toshihiro Shimizu 890ddd
void FlipSlider::setPBColorMarginTop(int margin) { PBColorMarginTop = margin; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBColorMarginRight() const { return PBColorMarginRight; }
Shinya Kitaoka 120a6e
void FlipSlider::setPBColorMarginRight(int margin) {
Shinya Kitaoka 120a6e
  PBColorMarginRight = margin;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBColorMarginBottom() const { return PBColorMarginBottom; }
Shinya Kitaoka 120a6e
void FlipSlider::setPBColorMarginBottom(int margin) {
Shinya Kitaoka 120a6e
  PBColorMarginBottom = margin;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBMarkerMarginLeft() const { return PBMarkerMarginLeft; }
Shinya Kitaoka 120a6e
void FlipSlider::setPBMarkerMarginLeft(int margin) {
Shinya Kitaoka 120a6e
  PBMarkerMarginLeft = margin;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int FlipSlider::getPBMarkerMarginRight() const { return PBMarkerMarginRight; }
Shinya Kitaoka 120a6e
void FlipSlider::setPBMarkerMarginRight(int margin) {
Shinya Kitaoka 120a6e
  PBMarkerMarginRight = margin;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QColor FlipSlider::getBaseColor() const { return PBBaseColor; }
Toshihiro Shimizu 890ddd
void FlipSlider::setBaseColor(const QColor &color) { PBBaseColor = color; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QColor FlipSlider::getNotStartedColor() const { return PBNotStartedColor; }
Shinya Kitaoka 120a6e
void FlipSlider::setNotStartedColor(const QColor &color) {
Shinya Kitaoka 120a6e
  PBNotStartedColor = color;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QColor FlipSlider::getStartedColor() const { return PBStartedColor; }
Shinya Kitaoka 120a6e
void FlipSlider::setStartedColor(const QColor &color) {
Shinya Kitaoka 120a6e
  PBStartedColor = color;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QColor FlipSlider::getFinishedColor() const { return PBFinishedColor; }
Shinya Kitaoka 120a6e
void FlipSlider::setFinishedColor(const QColor &color) {
Shinya Kitaoka 120a6e
  PBFinishedColor = color;
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FlipConsole *FlipConsole::m_currentConsole = 0;
Toshihiro Shimizu 890ddd
QList<flipconsole *=""> FlipConsole::m_visibleConsoles;</flipconsole>
Toshihiro Shimizu 890ddd
bool FlipConsole::m_isLinkedPlaying = false;
Shinya Kitaoka 120a6e
bool FlipConsole::m_areLinked       = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PlaybackExecutor::PlaybackExecutor() : m_fps(25), m_abort(false) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PlaybackExecutor::resetFps(int fps) { m_fps = fps; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PlaybackExecutor::run() {
Shinya Kitaoka 120a6e
  // (Daniele)
Shinya Kitaoka 120a6e
  // We'll build the fps considering an interval of roughly 1 second (the last
Shinya Kitaoka 120a6e
  // one).
Shinya Kitaoka 120a6e
  // However, the fps should be sampled at a faster rate. Each sample is taken
Shinya Kitaoka 120a6e
  // at
Shinya Kitaoka 120a6e
  // 1/4 second, and the last 4 samples data are stored to keep trace of the
Shinya Kitaoka 120a6e
  // last
Shinya Kitaoka 120a6e
  // second of playback.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TStopWatch timer;
Shinya Kitaoka 120a6e
  timer.start();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 timeResolution =
Shinya Kitaoka 120a6e
      250;  // Use a sufficient sampling resolution (currently 1/4 sec).
Shinya Kitaoka 120a6e
            // Fps calculation is made once per sample.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int fps = m_fps, currSample = 0;
Shinya Kitaoka 120a6e
  TUINT32 playedFramesCount = 0;
Shinya Kitaoka 120a6e
  TUINT32 loadedInstant, nextSampleInstant = timeResolution;
Shinya Kitaoka 120a6e
  TUINT32 sampleTotalLoadingTime = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 lastFrameCounts[4] = {0, 0, 0,
Shinya Kitaoka 120a6e
                                0};  // Keep the last 4 'played frames' counts.
Shinya Kitaoka 120a6e
  TUINT32 lastSampleInstants[4] = {0, 0, 0,
Shinya Kitaoka 120a6e
                                   0};  // Same for the last sampling instants
Shinya Kitaoka 120a6e
  TUINT32 lastLoadingTimes[4] = {0, 0, 0,
Shinya Kitaoka 120a6e
                                 0};  // Same for total sample loading times
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double targetFrameTime =
Shinya Kitaoka 120a6e
      1000.0 / abs(m_fps);  // User-required time between frames
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TUINT32 emissionInstant = 0;  // Effective instant in which loading is invoked
Shinya Kitaoka 120a6e
  double emissionInstantD = 0.0;  // Double precision version of the above
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double lastLoadingTime = 0.0;  // Mean frame loading time in the last sample
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  while (!m_abort) {
Shinya Kitaoka 120a6e
    emissionInstant = timer.getTotalTime();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Draw the next frame
Shinya Kitaoka 120a6e
    emit nextFrame(fps);  // Show the next frame, telling
Shinya Kitaoka 120a6e
                          // currently measured fps
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (FlipConsole::m_areLinked) {
Shinya Kitaoka 120a6e
      // In case there are linked consoles, update them too.
Shinya Kitaoka 120a6e
      // Their load time must be included in the fps calculation.
Shinya Kitaoka 120a6e
      int i, consolesCount = FlipConsole::m_visibleConsoles.size();
Shinya Kitaoka 120a6e
      for (i = 0; i < consolesCount; ++i) {
Shinya Kitaoka 120a6e
        FlipConsole *console = FlipConsole::m_visibleConsoles.at(i);
Shinya Kitaoka 120a6e
        if (console->isLinkable() && console != FlipConsole::m_currentConsole)
Shinya Kitaoka 120a6e
          console->playbackExecutor().emitNextFrame(m_fps < 0 ? -fps : fps);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    //-------- Each nextFrame() blocks until the frame has been shown ---------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ++playedFramesCount;
Shinya Kitaoka 120a6e
    loadedInstant = timer.getTotalTime();
Shinya Kitaoka 120a6e
    sampleTotalLoadingTime += (loadedInstant - emissionInstant);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Recalculate data only after the specified time resolution has passed.
Shinya Kitaoka 120a6e
    if (loadedInstant > nextSampleInstant) {
Shinya Kitaoka 120a6e
      // Sampling instant. Perform calculations.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Store values
Shinya Kitaoka 120a6e
      TUINT32 framesCount = playedFramesCount - lastFrameCounts[currSample];
Shinya Kitaoka 120a6e
      TUINT32 elapsedTime = loadedInstant - lastSampleInstants[currSample];
Shinya Kitaoka 120a6e
      double loadingTime =
Shinya Kitaoka 120a6e
          (sampleTotalLoadingTime - lastLoadingTimes[currSample]) /
Shinya Kitaoka 120a6e
          (double)framesCount;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      lastFrameCounts[currSample]    = playedFramesCount;
Shinya Kitaoka 120a6e
      lastSampleInstants[currSample] = loadedInstant;
Shinya Kitaoka 120a6e
      lastLoadingTimes[currSample]   = sampleTotalLoadingTime;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      currSample        = (currSample + 1) % 4;
Shinya Kitaoka 120a6e
      nextSampleInstant = loadedInstant + timeResolution;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Rebuild current fps
Shinya Kitaoka 120a6e
      fps             = troundp((1000 * framesCount) / (double)elapsedTime);
Shinya Kitaoka 120a6e
      targetFrameTime = 1000.0 / abs(m_fps);  // m_fps could have changed...
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // In case the playback is too slow to keep the required pace, reset the
Shinya Kitaoka 120a6e
      // emission timeline.
Shinya Kitaoka 120a6e
      // Otherwise, it should be kept as the difference needs to be compensated
Shinya Kitaoka 120a6e
      // to get the required fps.
Shinya Kitaoka 120a6e
      if ((int)emissionInstant - (int)emissionInstantD >
Shinya Kitaoka 120a6e
          20)  // Reset beyond, say, 20 msecs tolerance.
Shinya Kitaoka 120a6e
        emissionInstantD = (double)loadedInstant - loadingTime;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        emissionInstantD +=
Shinya Kitaoka 120a6e
            lastLoadingTime -
Shinya Kitaoka 120a6e
            loadingTime;  // Otherwise, just adapt to the new loading time
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      lastLoadingTime = loadingTime;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Calculate the new emission instant
Shinya Kitaoka 120a6e
    emissionInstant = std::max((int)(emissionInstantD += targetFrameTime), 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Sleep until the next emission instant has been reached
Shinya Kitaoka 120a6e
    while (timer.getTotalTime() < emissionInstant) msleep(1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_abort = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FlipSlider::FlipSlider(QWidget *parent)
Shinya Kitaoka 120a6e
    : QAbstractSlider(parent), m_enabled(false), m_progressBarStatus(0) {
Shinya Kitaoka 120a6e
  setObjectName("FlipSlider");
Shinya Kitaoka 120a6e
  setOrientation(Qt::Horizontal);
Shinya Kitaoka 120a6e
  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipSlider::paintEvent(QPaintEvent *ev) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Draw the progress status colorbar
Shinya Kitaoka 120a6e
  QRect sliderRect(QPoint(), size());
Shinya Kitaoka 120a6e
  QRect colorRect(sliderRect.adjusted(PBMarkerMarginLeft, PBColorMarginTop,
Shinya Kitaoka 120a6e
                                      -PBMarkerMarginRight,
Shinya Kitaoka 120a6e
                                      -PBColorMarginBottom));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int val, maxValuePlusStep = maximum() + singleStep();
Shinya Kitaoka 120a6e
  int colorWidth = colorRect.width(), colorHeight = colorRect.height();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
  int currPos = PBColorMarginLeft, nextPos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // paint the base of slider
Shinya Kitaoka 120a6e
  if (m_enabled && m_progressBarStatus && !m_progressBarStatus->empty()) {
Shinya Kitaoka 120a6e
    unsigned int i, pbStatusSize = m_progressBarStatus->size();
Shinya Kitaoka 120a6e
    for (i = 0, val = minimum() + singleStep(); i < pbStatusSize;
Shinya Kitaoka 120a6e
         ++i, val += singleStep()) {
Shinya Kitaoka 120a6e
      nextPos = sliderPositionFromValue(minimum(), maxValuePlusStep, val,
Shinya Kitaoka 120a6e
                                        colorWidth) +
Shinya Kitaoka 120a6e
                PBMarkerMarginLeft;
Shinya Kitaoka 120a6e
      if (i == pbStatusSize - 1) nextPos += PBMarkerMarginRight;
Shinya Kitaoka 120a6e
      p.fillRect(currPos, PBColorMarginTop, nextPos - currPos, colorHeight,
Shinya Kitaoka 120a6e
                 ((*m_progressBarStatus)[i] == PBFrameStarted)
Shinya Kitaoka 120a6e
                     ? PBStartedColor
Shinya Kitaoka 120a6e
                     : ((*m_progressBarStatus)[i] == PBFrameFinished)
Shinya Kitaoka 120a6e
                           ? PBFinishedColor
Shinya Kitaoka 120a6e
                           : PBNotStartedColor);
Shinya Kitaoka 120a6e
      currPos = nextPos;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Draw frames outside the pb
Shinya Kitaoka 120a6e
    if (val < maximum())
Shinya Kitaoka 120a6e
      p.fillRect(currPos, PBColorMarginTop,
Shinya Kitaoka 120a6e
                 width() - PBColorMarginRight - currPos, colorHeight,
Shinya Kitaoka 120a6e
                 PBNotStartedColor);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    p.fillRect(PBColorMarginLeft, PBColorMarginTop,
Shinya Kitaoka 120a6e
               sliderRect.width() - PBColorMarginLeft - PBColorMarginRight,
Shinya Kitaoka 120a6e
               colorHeight, PBBaseColor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Draw the PB Overlay
Shinya Kitaoka 120a6e
  int overlayInnerWidth =
Shinya Kitaoka 120a6e
      PBOverlay.width() - PBColorMarginLeft - PBColorMarginRight;
Shinya Kitaoka 120a6e
  int markerInnerWidth =
Shinya Kitaoka 120a6e
      PBMarker.width() - PBMarkerMarginLeft - PBMarkerMarginRight;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.drawImage(QRect(0, 0, PBColorMarginLeft, height()), PBOverlay,
Shinya Kitaoka 120a6e
              QRect(0, 0, PBColorMarginLeft, PBOverlay.height()));
Shinya Kitaoka 120a6e
  p.drawImage(QRect(PBColorMarginLeft, 0,
Shinya Kitaoka 120a6e
                    sliderRect.width() - PBColorMarginLeft - PBColorMarginRight,
Shinya Kitaoka 120a6e
                    height()),
Shinya Kitaoka 120a6e
              PBOverlay, QRect(PBColorMarginLeft, 0, overlayInnerWidth,
Shinya Kitaoka 120a6e
                               PBOverlay.height()));
Shinya Kitaoka 120a6e
  p.drawImage(
Shinya Kitaoka 120a6e
      QRect(width() - PBColorMarginRight, 0, PBColorMarginRight, height()),
Shinya Kitaoka 120a6e
      PBOverlay, QRect(PBOverlay.width() - PBColorMarginRight, 0,
Shinya Kitaoka 120a6e
                       PBColorMarginRight, PBOverlay.height()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Draw the position marker
Shinya Kitaoka 120a6e
  currPos = sliderPositionFromValue(minimum(), maxValuePlusStep, value(),
Shinya Kitaoka 120a6e
                                    colorWidth) +
Shinya Kitaoka 120a6e
            PBMarkerMarginLeft;
Shinya Kitaoka 120a6e
  nextPos = sliderPositionFromValue(minimum(), maxValuePlusStep,
Shinya Kitaoka 120a6e
                                    value() + singleStep(), colorWidth) +
Shinya Kitaoka 120a6e
            PBMarkerMarginLeft;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  p.drawImage(
Shinya Kitaoka 120a6e
      QRect(currPos - PBMarkerMarginLeft, 0, PBMarkerMarginLeft, height()),
Shinya Kitaoka 120a6e
      PBMarker, QRect(0, 0, PBMarkerMarginLeft, PBMarker.height()));
Shinya Kitaoka 120a6e
  p.drawImage(
Shinya Kitaoka 120a6e
      QRect(currPos, 0, nextPos - currPos, height()), PBMarker,
Shinya Kitaoka 120a6e
      QRect(PBMarkerMarginLeft, 0, markerInnerWidth, PBMarker.height()));
Shinya Kitaoka 120a6e
  p.drawImage(QRect(nextPos, 0, PBMarkerMarginRight, height()), PBMarker,
Shinya Kitaoka 120a6e
              QRect(PBMarker.width() - PBMarkerMarginRight, 0,
Shinya Kitaoka 120a6e
                    PBMarkerMarginRight, PBMarker.height()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline int FlipSlider::sliderPositionFromValue(int min, int max, int val,
Shinya Kitaoka 120a6e
                                               int span) {
Shinya Kitaoka 120a6e
  return tceil(span * ((val - min) / (double)(max - min)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline int FlipSlider::sliderValueFromPosition(int min, int max, int step,
Shinya Kitaoka 120a6e
                                               int pos, int span) {
Shinya Kitaoka 120a6e
  int colorBarPos     = pos - PBColorMarginLeft;
Shinya Kitaoka 120a6e
  int colorSpan       = span - PBColorMarginLeft - PBColorMarginRight;
Shinya Kitaoka 120a6e
  int tempRelativePos = (max - min + step) * (colorBarPos / (double)colorSpan);
Shinya Kitaoka 120a6e
  return min + (tempRelativePos - tempRelativePos % step);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline int FlipSlider::pageStepVal(int val) {
Shinya Kitaoka 120a6e
  return tcrop(value() + pageStep() * tsign(val - value()), minimum(),
Shinya Kitaoka 120a6e
               maximum());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Mouse Press behaviour:
Toshihiro Shimizu 890ddd
//  a) If middle button, just put frame to cursor position
Toshihiro Shimizu 890ddd
//  b) If left button, and cursor on current frame pos, do like (a)
Toshihiro Shimizu 890ddd
//  c) If left button, and cursor NOT on curr.. perform a page up/down on
Toshihiro Shimizu 890ddd
//     the side of cursor pos
Shinya Kitaoka 120a6e
void FlipSlider::mousePressEvent(QMouseEvent *me) {
Shinya Kitaoka 120a6e
  emit flipSliderPressed();
Shinya Kitaoka 120a6e
  int cursorValue = sliderValueFromPosition(minimum(), maximum(), singleStep(),
Shinya Kitaoka 120a6e
                                            me->pos().x(), width());
Shinya Kitaoka 120a6e
  if (me->button() == Qt::MidButton)
Shinya Kitaoka 120a6e
    if (cursorValue == value())
Shinya Kitaoka 120a6e
      setSliderDown(true);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      // Move the page step
Shinya Kitaoka 120a6e
      setValue(pageStepVal(cursorValue));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  else if (me->button() == Qt::LeftButton && cursorValue != value())
Shinya Kitaoka 120a6e
    setValue(cursorValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipSlider::mouseMoveEvent(QMouseEvent *me) {
Shinya Kitaoka 120a6e
  if (isSliderDown() || me->buttons() & Qt::LeftButton) {
Shinya Kitaoka 120a6e
    int cursorValue = sliderValueFromPosition(
Shinya Kitaoka 120a6e
        minimum(), maximum(), singleStep(), me->pos().x(), width());
Shinya Kitaoka 120a6e
    setValue(cursorValue);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipSlider::mouseReleaseEvent(QMouseEvent *me) {
Shinya Kitaoka 120a6e
  setSliderDown(false);
Shinya Kitaoka 120a6e
  emit flipSliderReleased();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
enum {
Shinya Kitaoka 120a6e
  eShowCompare         = 0x001,
Shinya Kitaoka 120a6e
  eShowBg              = 0x002,
Shinya Kitaoka 120a6e
  eShowFramerate       = 0x004,
Shinya Kitaoka 120a6e
  eShowVcr             = 0x008,
Shinya Kitaoka 120a6e
  eShowcolorFilter     = 0x010,
Shinya Kitaoka 120a6e
  eShowCustom          = 0x020,
Shinya Kitaoka 120a6e
  eShowHisto           = 0x040,
Shinya Kitaoka 120a6e
  eShowSave            = 0x080,
Shinya Kitaoka 120a6e
  eShowDefineSubCamera = 0x100,
Shinya Kitaoka 120a6e
  eShowFilledRaster    = 0x200,
Shinya Kitaoka 120a6e
  eShowDefineLoadBox   = 0x400,
Shinya Kitaoka 120a6e
  eShowUseLoadBox      = 0x800,
Shinya Kitaoka 120a6e
  eShowHowMany         = 0x1000
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FlipConsole::FlipConsole(QVBoxLayout *mainLayout, UINT gadgetsMask,
Shinya Kitaoka 120a6e
                         bool isLinkable, QWidget *customWidget,
Shinya Kitaoka 120a6e
                         const QString &customizeId,
Shinya Kitaoka 120a6e
                         FlipConsoleOwner *consoleOwner, bool enableBlanks)
Shinya Kitaoka 120a6e
    : m_gadgetsMask(gadgetsMask)
Shinya Kitaoka 120a6e
    , m_from(1)
Shinya Kitaoka 120a6e
    , m_to(1)
Shinya Kitaoka 120a6e
    , m_step(1)
Shinya Kitaoka 120a6e
    , m_currentFrame(1)
Shinya Kitaoka 120a6e
    , m_framesCount(1)
Shinya Kitaoka 120a6e
    , m_settings()
Shinya Kitaoka 120a6e
    , m_fps(24)
shun_iwasawa d77cdf
    , m_sceneFps(24)
Shinya Kitaoka 120a6e
    , m_isPlay(false)
Shinya Kitaoka 120a6e
    , m_reverse(false)
Shinya Kitaoka 120a6e
    , m_doubleRed(0)
Shinya Kitaoka 120a6e
    , m_doubleGreen(0)
Shinya Kitaoka 120a6e
    , m_doubleBlue(0)
Shinya Kitaoka 120a6e
    , m_doubleRedAction(0)
Shinya Kitaoka 120a6e
    , m_doubleGreenAction(0)
Shinya Kitaoka 120a6e
    , m_doubleBlueAction(0)
Shinya Kitaoka 120a6e
    , m_fpsSlider(0)
Shinya Kitaoka 120a6e
    , m_markerFrom(0)
Shinya Kitaoka 120a6e
    , m_markerTo(-1)
Shinya Kitaoka 120a6e
    , m_playbackExecutor()
Shinya Kitaoka 120a6e
    , m_drawBlanksEnabled(enableBlanks)
Shinya Kitaoka 120a6e
    , m_blanksCount(0)
Shinya Kitaoka 120a6e
    , m_blankColor(TPixel::Transparent)
Shinya Kitaoka 120a6e
    , m_blanksToDraw(0)
Shinya Kitaoka 120a6e
    , m_isLinkable(isLinkable)
Shinya Kitaoka 120a6e
    , m_customAction(0)
Shinya Kitaoka 120a6e
    , m_customizeMask(eShowHowMany - 1)
Shinya Kitaoka 120a6e
    , m_fpsLabelAction(0)
Shinya Kitaoka 120a6e
    , m_fpsSliderAction(0)
Shinya Kitaoka 120a6e
    , m_fpsFieldAction(0)
Shinya Kitaoka 120a6e
    , m_fpsField(0)
Shinya Kitaoka 120a6e
    , m_customizeId(customizeId)
Shinya Kitaoka 120a6e
    , m_histoSep(0)
Shinya Kitaoka 120a6e
    , m_filledRasterSep(0)
Shinya Kitaoka 120a6e
    , m_bgSep(0)
Shinya Kitaoka 120a6e
    , m_vcrSep(0)
Shinya Kitaoka 120a6e
    , m_compareSep(0)
Shinya Kitaoka 120a6e
    , m_saveSep(0)
Shinya Kitaoka 120a6e
    , m_colorFilterSep(0)
Shinya Kitaoka 120a6e
    , m_subcamSep(0)
Shinya Kitaoka 120a6e
    , m_playToolBar(0)
Shinya Kitaoka 120a6e
    , m_colorFilterGroup(0)
Shinya Kitaoka 120a6e
    , m_fpsLabel(0)
Shinya Kitaoka 120a6e
    , m_consoleOwner(consoleOwner)
Shinya Kitaoka 120a6e
    , m_enableBlankFrameButton(0) {
Shinya Kitaoka 120a6e
  QString s                    = QSettings().value(m_customizeId).toString();
Shinya Kitaoka 120a6e
  if (s != "") m_customizeMask = s.toUInt();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_gadgetsMask == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // mainLayout->setMargin(1);
Shinya Kitaoka 120a6e
  // mainLayout->setSpacing(0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // create toolbars other than frame slider
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & (~eFrames)) {
Shinya Kitaoka 120a6e
    createPlayToolBar(customWidget != 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_playToolBarContainer = new ToolBarContainer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QHBoxLayout *hLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
    hLayout->setMargin(0);
Shinya Kitaoka 120a6e
    hLayout->setSpacing(0);
Shinya Kitaoka 120a6e
    hLayout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      DvScrollWidget *scrollableContainer = new DvScrollWidget;
Shinya Kitaoka 120a6e
      scrollableContainer->setWidget(m_playToolBar);
Shinya Kitaoka 120a6e
      hLayout->addWidget(scrollableContainer);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // show fps
Shinya Kitaoka 120a6e
      if (m_gadgetsMask & eRate) {
Shinya Kitaoka 120a6e
        QFrame *fpsSliderFrame = createFpsSlider();
Shinya Kitaoka 120a6e
        hLayout->addWidget(fpsSliderFrame, 1);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_playToolBarContainer->setLayout(hLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_playToolBarContainer);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // create frame slider
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eFrames) {
Shinya Kitaoka 120a6e
    m_frameSliderFrame = createFrameSlider();
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_frameSliderFrame);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (customWidget) {
Shinya Kitaoka 120a6e
    m_customAction = m_playToolBar->addWidget(customWidget);
Shinya Kitaoka 120a6e
    m_customSep    = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  applyCustomizeMask();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool ret = connect(&m_playbackExecutor, SIGNAL(nextFrame(int)), this,
Shinya Kitaoka 120a6e
                     SLOT(onNextFrame(int)), Qt::BlockingQueuedConnection);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // parent->setLayout(mainLayout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::showHideAllParts(bool isShow) {
Shinya Kitaoka 120a6e
  m_playToolBarContainer->setVisible(isShow);
Shinya Kitaoka 120a6e
  m_frameSliderFrame->setVisible(isShow);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void showEvent(QShowEvent *);
Toshihiro Shimizu 890ddd
void hideEvent(QHideEvent *);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::makeCurrent() {
Shinya Kitaoka 120a6e
  if (m_currentConsole == this) return;
Shinya Kitaoka 120a6e
  int i = m_visibleConsoles.indexOf(this);
Shinya Kitaoka 120a6e
  if (i >= 0) m_visibleConsoles.takeAt(i);
Shinya Kitaoka 120a6e
  m_visibleConsoles.append(this);
Shinya Kitaoka 120a6e
  m_currentConsole = this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setActive(bool active) {
Shinya Kitaoka 120a6e
  if (active)
Shinya Kitaoka 120a6e
    makeCurrent();
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    pressButton(ePause);
Shinya Kitaoka 120a6e
    int i = m_visibleConsoles.indexOf(this);
Shinya Kitaoka 120a6e
    if (i >= 0) m_visibleConsoles.takeAt(i);
Shinya Kitaoka 120a6e
    if (m_currentConsole == this) {
Shinya Kitaoka 120a6e
      if (!m_visibleConsoles.empty())
Shinya Kitaoka 120a6e
        m_currentConsole = m_visibleConsoles.last();
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_currentConsole = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define LX 21
Toshihiro Shimizu 890ddd
#define LY 17
Shinya Kitaoka d1f6c4
class DoubleButton final : public QToolButton {
Shinya Kitaoka 120a6e
  QAction *m_firstAction, *m_secondAction;
Shinya Kitaoka 120a6e
  QIcon::Mode m_firstMode, m_secondMode;
Shinya Kitaoka 120a6e
  QIcon::State m_firstState, m_secondState;
Shinya Kitaoka 120a6e
  bool m_enabled;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DoubleButton(QAction *firstAction, QAction *secondAction, QWidget *parent = 0)
Shinya Kitaoka 120a6e
      : QToolButton(parent)
Shinya Kitaoka 120a6e
      , m_firstAction(firstAction)
Shinya Kitaoka 120a6e
      , m_secondAction(secondAction)
Shinya Kitaoka 120a6e
      , m_firstMode(QIcon::Normal)
Shinya Kitaoka 120a6e
      , m_secondMode(QIcon::Normal)
Shinya Kitaoka 120a6e
      , m_firstState(QIcon::Off)
Shinya Kitaoka 120a6e
      , m_secondState(QIcon::Off)
Shinya Kitaoka 120a6e
      , m_enabled(true) {
Shinya Kitaoka 120a6e
    setFixedSize(LX, LY);
Shinya Kitaoka 120a6e
    setMouseTracking(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void setEnabledSecondButton(bool state) {
Shinya Kitaoka 120a6e
    if (!state && m_secondAction->isChecked()) m_secondAction->trigger();
Shinya Kitaoka 120a6e
    m_enabled = state;
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *e) override {
Shinya Kitaoka 120a6e
    QPainter p(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    p.drawPixmap(0, 0,
Shinya Kitaoka 120a6e
                 m_firstAction->icon().pixmap(
Shinya Kitaoka 120a6e
                     QSize(LX, LY / 2),
Shinya Kitaoka 120a6e
                     m_firstAction->isChecked() ? QIcon::Normal : m_firstMode,
Shinya Kitaoka 120a6e
                     m_firstAction->isChecked() ? QIcon::On : m_firstState));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QIcon::Mode mode =
Shinya Kitaoka 120a6e
        m_enabled ? (m_secondAction->isChecked() ? QIcon::Normal : m_secondMode)
Shinya Kitaoka 120a6e
                  : QIcon::Disabled;
Shinya Kitaoka 120a6e
    QIcon::State state =
Shinya Kitaoka 120a6e
        m_enabled ? (m_secondAction->isChecked() ? QIcon::On : m_secondState)
Shinya Kitaoka 120a6e
                  : QIcon::Off;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    p.drawPixmap(0, LY / 2 + 1,
Shinya Kitaoka 120a6e
                 m_secondAction->icon().pixmap(QSize(LX, LY / 2), mode, state));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    QRect firstActionRect(0, 0, LX, LY / 2);
Shinya Kitaoka 120a6e
    QRect secondActionRect(0, LY / 2 + 1, LX, LY / 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QPoint pos = e->pos();
Shinya Kitaoka 120a6e
    if (firstActionRect.contains(pos)) {
Shinya Kitaoka 120a6e
      m_firstAction->trigger();
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (m_enabled) m_secondAction->trigger();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    QPoint pos = e->pos();
Shinya Kitaoka 120a6e
    QRect firstActionRect(0, 0, LX, LY / 2);
Shinya Kitaoka 120a6e
    QRect secondActionRect(0, LY / 2 + 1, LX, LY / 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_firstState  = QIcon::Off;
Shinya Kitaoka 120a6e
    m_secondState = QIcon::Off;
Shinya Kitaoka 120a6e
    m_firstMode   = QIcon::Normal;
Shinya Kitaoka 120a6e
    m_secondMode  = QIcon::Normal;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (firstActionRect.contains(pos)) {
Shinya Kitaoka 120a6e
      m_firstMode = QIcon::Active;
Shinya Kitaoka 120a6e
      setToolTip(m_firstAction->toolTip());
Shinya Kitaoka 120a6e
    } else if (secondActionRect.contains(pos) && m_enabled) {
Shinya Kitaoka 120a6e
      m_secondMode = QIcon::Active;
Shinya Kitaoka 120a6e
      setToolTip(m_secondAction->toolTip());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void leaveEvent(QEvent *e) override {
Shinya Kitaoka 120a6e
    m_firstMode   = QIcon::Normal;
Shinya Kitaoka 120a6e
    m_firstState  = QIcon::Off;
Shinya Kitaoka 120a6e
    m_secondMode  = QIcon::Normal;
Shinya Kitaoka 120a6e
    m_secondState = QIcon::Off;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QToolButton::leaveEvent(e);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::enableButton(UINT button, bool enable, bool doShowHide) {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!m_playToolBar) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QList<qaction *=""> list = m_playToolBar->actions();</qaction>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)list.size(); i++)
Shinya Kitaoka 120a6e
    if (list[i]->data().toUInt() == button) {
Shinya Kitaoka 120a6e
      if (button == eSound)
Shinya Kitaoka 120a6e
        if (doShowHide)
Shinya Kitaoka 120a6e
          m_soundSep->setVisible(enable);
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          m_soundSep->setEnabled(enable);
Shinya Kitaoka 120a6e
      if (button == eHisto) {
Shinya Kitaoka 120a6e
        if (doShowHide)
Shinya Kitaoka 120a6e
          m_histoSep->setVisible(enable && m_customizeMask & eShowHisto);
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          m_histoSep->setEnabled(enable);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (doShowHide)
Shinya Kitaoka 120a6e
        list[i]->setVisible(enable);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        list[i]->setEnabled(enable);
Shinya Kitaoka 120a6e
      if (!enable && list[i]->isChecked()) pressButton((EGadget)button);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // double buttons are special, they are not accessible directly from the
Shinya Kitaoka 120a6e
  // playtoolbar...
Shinya Kitaoka 120a6e
  switch ((EGadget)button) {
Shinya Kitaoka 120a6e
  case eGRed:
Shinya Kitaoka 120a6e
    if (m_doubleRed) m_doubleRed->setEnabledSecondButton(enable);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case eGGreen:
Shinya Kitaoka 120a6e
    if (m_doubleGreen) m_doubleGreen->setEnabledSecondButton(enable);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case eGBlue:
Shinya Kitaoka 120a6e
    if (m_doubleBlue) m_doubleBlue->setEnabledSecondButton(enable);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::toggleLinked() {
Shinya Kitaoka 120a6e
  m_areLinked = !m_areLinked;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  FlipConsole *playingConsole = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_visibleConsoles.size(); i++) {
Shinya Kitaoka 120a6e
    playingConsole = m_visibleConsoles.at(i);
Shinya Kitaoka 120a6e
    if (playingConsole->m_isLinkable &&
Shinya Kitaoka 120a6e
        playingConsole->m_playbackExecutor.isRunning())
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (i == m_visibleConsoles.size()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // if we are here, flip is playing!
Shinya Kitaoka 120a6e
  m_isLinkedPlaying = m_areLinked;
Shinya Kitaoka 120a6e
  int button =
Shinya Kitaoka 120a6e
      m_areLinked ? (playingConsole->m_isPlay ? ePlay : eLoop) : ePause;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < m_visibleConsoles.size(); i++) {
Shinya Kitaoka 120a6e
    FlipConsole *console = m_visibleConsoles.at(i);
Shinya Kitaoka 120a6e
    if (console->m_isLinkable && console != playingConsole) {
Shinya Kitaoka 120a6e
      console->setChecked(button, true);
Shinya Kitaoka 120a6e
      console->doButtonPressed(button);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FlipConsole::drawBlanks(int from, int to) {
Shinya Kitaoka 120a6e
  if (m_blanksCount == 0 || m_isPlay || m_framesCount <= 1) return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // enable blanks only when the blank button is pressed
Shinya Kitaoka 120a6e
  if (m_enableBlankFrameButton && !m_enableBlankFrameButton->isChecked())
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_blanksToDraw > 1 ||
Shinya Kitaoka 120a6e
      (m_blanksToDraw == 0 &&
Shinya Kitaoka 120a6e
       ((m_reverse && m_currentFrame - m_step < from) ||
Shinya Kitaoka 120a6e
        (!m_reverse &&
Shinya Kitaoka 120a6e
         m_currentFrame + m_step >
Shinya Kitaoka 120a6e
             to))))  // we are on the last frame of the loop
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    m_blanksToDraw = (m_blanksToDraw == 0 ? m_blanksCount : m_blanksToDraw - 1);
Shinya Kitaoka 120a6e
    m_settings.m_blankColor     = m_blankColor;
Shinya Kitaoka 120a6e
    m_settings.m_drawBlankFrame = true;
Shinya Kitaoka 120a6e
    m_consoleOwner->onDrawFrame(from, m_settings);
Shinya Kitaoka 120a6e
    m_settings.m_drawBlankFrame = false;
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_blanksToDraw = 0;
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::onNextFrame(int fps) {
Shinya Kitaoka 120a6e
  if (fps < 0)  // can be negative only if is a linked console; it means that
Shinya Kitaoka 120a6e
                // the master console is playing backward
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    bool reverse = m_reverse;
Shinya Kitaoka 120a6e
    m_reverse    = true;
Shinya Kitaoka 120a6e
    fps          = -fps;
Shinya Kitaoka 120a6e
    playNextFrame();
Shinya Kitaoka 120a6e
    m_reverse = reverse;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    playNextFrame();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (fps == -1) return;
Shinya Kitaoka 120a6e
  if (m_fpsLabel)
Shinya Kitaoka 120a6e
    m_fpsLabel->setText(tr(" FPS ") + QString::number(fps * tsign(m_fps)) +
Shinya Kitaoka 120a6e
                        "/");
Shinya Kitaoka 120a6e
  if (m_fpsField) {
Shinya Kitaoka 120a6e
    if (fps == abs(m_fps))
Shinya Kitaoka 120a6e
      m_fpsField->setLineEditBackgroundColor(Qt::green);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_fpsField->setLineEditBackgroundColor(Qt::red);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::playNextFrame() {
Shinya Kitaoka 120a6e
  int from = m_from, to = m_to;
Shinya Kitaoka 120a6e
  if (m_markerFrom <= m_markerTo) from = m_markerFrom, to = m_markerTo;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_framesCount == 0 ||
Shinya Kitaoka 120a6e
      (m_isPlay && m_currentFrame == (m_reverse ? from : to))) {
Shinya Kitaoka 120a6e
    doButtonPressed(ePause);
Shinya Kitaoka 120a6e
    setChecked(m_isPlay ? ePlay : eLoop, false);
Shinya Kitaoka 120a6e
    setChecked(ePause, true);
Shinya Kitaoka 120a6e
    if (Preferences::instance()->rewindAfterPlaybackEnabled())
Shinya Kitaoka 120a6e
      m_currentFrame = (m_reverse ? to : from);
Shinya Kitaoka 120a6e
    emit playStateChanged(false);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (drawBlanks(from, to)) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_reverse)
Shinya Kitaoka 120a6e
      m_currentFrame =
Shinya Kitaoka 120a6e
          ((m_currentFrame - m_step < from) ? to : m_currentFrame - m_step);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_currentFrame =
Shinya Kitaoka 120a6e
          ((m_currentFrame + m_step > to) ? from : m_currentFrame + m_step);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currFrameSlider->setValue(m_currentFrame);
Shinya Kitaoka 120a6e
  m_editCurrFrame->setText(QString::number(m_currentFrame));
Shinya Kitaoka 120a6e
  m_settings.m_blankColor        = TPixel::Transparent;
Shinya Kitaoka 120a6e
  m_settings.m_recomputeIfNeeded = true;
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::updateCurrentFPS(int val) {
Shinya Kitaoka 120a6e
  setCurrentFPS(val);
Shinya Kitaoka 120a6e
  m_fpsSlider->setValue(m_fps);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun_iwasawa d77cdf
void FlipConsole::setFrameRate(int val, bool forceUpdate) {
shun_iwasawa d77cdf
  if (m_sceneFps != val || forceUpdate) {
shun_iwasawa d77cdf
    if (!m_fpsSlider) return;
shun_iwasawa d77cdf
    m_fpsSlider->setValue(val);
shun_iwasawa d77cdf
    setCurrentFPS(val);
shun_iwasawa d77cdf
  }
shun_iwasawa d77cdf
  m_sceneFps = val;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setCurrentFPS(bool dragging) {
Shinya Kitaoka 120a6e
  setCurrentFPS(m_fpsField->getValue());
Shinya Kitaoka 120a6e
  m_fpsSlider->setValue(m_fps);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setCurrentFPS(int val) {
Shinya Kitaoka 120a6e
  if (m_fps == val) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (val == 0) val = 1;
Shinya Kitaoka 120a6e
  m_fps             = val;
Shinya Kitaoka 120a6e
  m_fpsField->setValue(m_fps);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_playbackExecutor.isRunning() || m_isLinkedPlaying)
Shinya Kitaoka 120a6e
    m_reverse = (val < 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_fpsLabel) m_fpsLabel->setText(tr(" FPS "));
Shinya Kitaoka 120a6e
  if (m_fpsField) m_fpsField->setLineEditBackgroundColor(Qt::transparent);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_playbackExecutor.resetFps(m_fps);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::createButton(UINT buttonMask, const char *iconStr,
Shinya Kitaoka 120a6e
                               const QString &tip, bool checkable,
Shinya Kitaoka 120a6e
                               QActionGroup *group) {
shun_iwasawa 4a5f42
  QIcon icon      = createQIcon(iconStr);
Shinya Kitaoka 120a6e
  QAction *action = new QAction(icon, tip, m_playToolBar);
Shinya Kitaoka 120a6e
  action->setData(QVariant(buttonMask));
Shinya Kitaoka 120a6e
  action->setCheckable(checkable);
Shinya Kitaoka 120a6e
  if (group) group->addAction(action);
Shinya Kitaoka 120a6e
  m_actions[(EGadget)buttonMask] = action;
Shinya Kitaoka 120a6e
  m_playToolBar->addAction(action);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QAction *FlipConsole::createCheckedButtonWithBorderImage(
Shinya Kitaoka 120a6e
    UINT buttonMask, const char *iconStr, const QString &tip, bool checkable,
Shinya Kitaoka 120a6e
    QActionGroup *group, const char *cmdId) {
shun_iwasawa 4a5f42
  QIcon icon            = createQIcon(iconStr);
Shinya Kitaoka 120a6e
  QWidgetAction *action = new QWidgetAction(m_playToolBar);
Shinya Kitaoka 120a6e
  action->setIcon(icon);
Shinya Kitaoka 120a6e
  action->setToolTip(tip);
Shinya Kitaoka 120a6e
  action->setData(QVariant(buttonMask));
Shinya Kitaoka 120a6e
  action->setCheckable(checkable);
Shinya Kitaoka 120a6e
  if (group) group->addAction(action);
Shinya Kitaoka 120a6e
  QToolButton *button = new QToolButton(m_playToolBar);
Shinya Kitaoka 120a6e
  button->setDefaultAction(action);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_buttons[(EGadget)buttonMask] = button;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (cmdId) {
Shinya Kitaoka 120a6e
    QAction *a = CommandManager::instance()->getAction(cmdId);
Shinya Kitaoka 120a6e
    if (a) button->addAction(a);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  action->setDefaultWidget(button);
Shinya Kitaoka 120a6e
  button->setObjectName("chackableButtonWithImageBorder");
Shinya Kitaoka 120a6e
  connect(button, SIGNAL(triggered(QAction *)), this,
Shinya Kitaoka 120a6e
          SLOT(onButtonPressed(QAction *)));
Shinya Kitaoka 120a6e
  // connect(action, SIGNAL(toggled(bool)), button, SLOT(setChecked(bool)));
Shinya Kitaoka 120a6e
  m_playToolBar->addAction(action);
Shinya Kitaoka 120a6e
  return action;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QAction *FlipConsole::createDoubleButton(
Shinya Kitaoka 120a6e
    UINT buttonMask1, UINT buttonMask2, const char *iconStr1,
Shinya Kitaoka 120a6e
    const char *iconStr2, const QString &tip1, const QString &tip2,
Shinya Kitaoka 120a6e
    QActionGroup *group, DoubleButton *&widget) {
shun_iwasawa 4a5f42
  QAction *action1 = new QAction(createQIcon(iconStr1), tip1, m_playToolBar);
shun_iwasawa 4a5f42
  QAction *action2 = new QAction(createQIcon(iconStr2), tip2, m_playToolBar);
Shinya Kitaoka 120a6e
  m_actions[(EGadget)buttonMask1] = action1;
Shinya Kitaoka 120a6e
  m_actions[(EGadget)buttonMask2] = action2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  action1->setData(QVariant(buttonMask1));
Shinya Kitaoka 120a6e
  action1->setCheckable(true);
Shinya Kitaoka 120a6e
  action2->setData(QVariant(buttonMask2));
Shinya Kitaoka 120a6e
  action2->setCheckable(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (group) {
Shinya Kitaoka 120a6e
    group->addAction(action1);
Shinya Kitaoka 120a6e
    group->addAction(action2);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  widget = new DoubleButton(action1, action2, this);
Shinya Kitaoka 120a6e
  return m_playToolBar->addWidget(widget);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // m_playToolBar->addAction(action1);
Shinya Kitaoka 120a6e
  // m_playToolBar->addAction(action2);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::createOnOffButton(UINT buttonMask, const char *iconStr,
Shinya Kitaoka 120a6e
                                    const QString &tip, QActionGroup *group) {
shun_iwasawa 4a5f42
  QIcon icon      = createQIconOnOff(iconStr);
Shinya Kitaoka 120a6e
  QAction *action = new QAction(icon, tip, m_playToolBar);
Shinya Kitaoka 120a6e
  action->setData(QVariant(buttonMask));
Shinya Kitaoka 120a6e
  action->setCheckable(true);
Shinya Kitaoka 120a6e
  if (group) group->addAction(action);
Shinya Kitaoka 120a6e
  m_playToolBar->addAction(action);
Shinya Kitaoka 120a6e
  m_actions[(EGadget)buttonMask] = action;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::addMenuItem(UINT id, const QString &text, QMenu *menu) {
Shinya Kitaoka 120a6e
  QAction *a = new QAction(text, menu);
Shinya Kitaoka 120a6e
  a->setCheckable(true);
Shinya Kitaoka 120a6e
  a->setChecked(id & m_customizeMask);
Shinya Kitaoka 120a6e
  a->setData(QVariant(id));
Shinya Kitaoka 120a6e
  menu->addAction(a);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::onCustomizeButtonPressed(QAction *a) {
Shinya Kitaoka 120a6e
  UINT id = a->data().toUInt();
Shinya Kitaoka 120a6e
  if (a->isChecked())
Shinya Kitaoka 120a6e
    m_customizeMask = m_customizeMask | id;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_customizeMask = m_customizeMask & (~id);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QSettings().setValue(m_customizeId, QString::number(m_customizeMask));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  applyCustomizeMask();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void FlipConsole::applyCustomizeMask() {
Shinya Kitaoka 120a6e
  enableButton(eSave, m_customizeMask & eShowSave);
Shinya Kitaoka 120a6e
  // if(m_saveSep)
Shinya Kitaoka 120a6e
  //  m_saveSep->setVisible(m_customizeMask&eShowSave);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enableButton(eSaveImg, m_customizeMask & eShowCompare);
Shinya Kitaoka 120a6e
  enableButton(eCompare, m_customizeMask & eShowCompare);
Shinya Kitaoka 120a6e
  if (m_compareSep) m_compareSep->setVisible(m_customizeMask & eShowCompare);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enableButton(eDefineSubCamera, m_customizeMask & eShowDefineSubCamera);
Shinya Kitaoka 120a6e
  enableButton(eDefineLoadBox, m_customizeMask & eShowDefineLoadBox);
Shinya Kitaoka 120a6e
  enableButton(eUseLoadBox, m_customizeMask & eShowUseLoadBox);
Shinya Kitaoka 120a6e
  if (m_subcamSep)
Shinya Kitaoka 120a6e
    m_subcamSep->setVisible(m_customizeMask & eShowDefineSubCamera ||
Shinya Kitaoka 120a6e
                            m_customizeMask & eShowDefineLoadBox ||
Shinya Kitaoka 120a6e
                            m_customizeMask & eShowUseLoadBox);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enableButton(eWhiteBg, m_customizeMask & eShowBg);
Shinya Kitaoka 120a6e
  enableButton(eBlackBg, m_customizeMask & eShowBg);
Shinya Kitaoka 120a6e
  enableButton(eCheckBg, m_customizeMask & eShowBg);
Shinya Kitaoka 120a6e
  if (m_bgSep) m_bgSep->setVisible(m_customizeMask & eShowBg);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_fpsLabel && m_fpsSlider && m_fpsField) {
Shinya Kitaoka 120a6e
    m_fpsLabel->setVisible(m_customizeMask & eShowFramerate);
Shinya Kitaoka 120a6e
    m_fpsSlider->setVisible(m_customizeMask & eShowFramerate);
Shinya Kitaoka 120a6e
    m_fpsField->setVisible(m_customizeMask & eShowFramerate);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enableButton(eFirst, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
  enableButton(ePrev, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
  enableButton(ePause, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
  enableButton(ePlay, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
  enableButton(eLoop, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
  enableButton(eNext, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
  enableButton(eLast, m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_vcrSep) m_vcrSep->setVisible(m_customizeMask & eShowVcr);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enableButton(eMatte, m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
  enableButton(eHisto, m_customizeMask & eShowHisto);
Shinya Kitaoka 120a6e
  if (m_histoSep) m_histoSep->setVisible(m_customizeMask & eShowHisto);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_doubleRedAction) {
Shinya Kitaoka 120a6e
    m_doubleRedAction->setVisible(m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
    m_doubleGreenAction->setVisible(m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
    m_doubleBlueAction->setVisible(m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    enableButton(eRed, m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
    enableButton(eGreen, m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
    enableButton(eBlue, m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_colorFilterGroup)
Shinya Kitaoka 120a6e
    m_colorFilterGroup->setVisible(m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_colorFilterSep)
Shinya Kitaoka 120a6e
    m_colorFilterSep->setVisible(m_customizeMask & eShowcolorFilter);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_customAction) {
Shinya Kitaoka 120a6e
    bool visible = bool(m_customizeMask & eShowCustom);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_customAction->setVisible(visible);
Shinya Kitaoka 120a6e
    m_customSep->setVisible(visible);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enableButton(eFilledRaster, m_customizeMask & eShowFilledRaster);
Shinya Kitaoka 120a6e
  if (m_filledRasterSep)
Shinya Kitaoka 120a6e
    m_filledRasterSep->setVisible(m_customizeMask & eShowFilledRaster);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::createCustomizeMenu(bool withCustomWidget) {
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eCustomize) {
shun_iwasawa 3cc41f
    QIcon icon          = createQIcon("options");
Shinya Kitaoka 120a6e
    QToolButton *button = new QToolButton();
Shinya Kitaoka 120a6e
    button->setIcon(icon);
Shinya Kitaoka 120a6e
    button->setPopupMode(QToolButton::MenuButtonPopup);
Shinya Kitaoka 120a6e
    button->setObjectName("flipCustomize");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    QMenu *menu = new QMenu();
Shinya Kitaoka 120a6e
    button->setMenu(menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_playToolBar->addWidget(button);
Shinya Kitaoka 120a6e
    m_playToolBar->addSeparator();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eSave) addMenuItem(eShowSave, tr("Save"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eSaveImg || m_gadgetsMask & eCompare)
Shinya Kitaoka 120a6e
      addMenuItem(eShowCompare, tr("Snapshot"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eDefineSubCamera)
Shinya Kitaoka 120a6e
      addMenuItem(eShowDefineSubCamera, tr("Define Sub-camera"), menu);
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eDefineLoadBox)
Shinya Kitaoka 120a6e
      addMenuItem(eShowDefineLoadBox, tr("Define Loading Box"), menu);
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eUseLoadBox)
Shinya Kitaoka 120a6e
      addMenuItem(eShowUseLoadBox, tr("Use Loading Box"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eWhiteBg || m_gadgetsMask & eBlackBg ||
Shinya Kitaoka 120a6e
        m_gadgetsMask & eCheckBg)
Shinya Kitaoka 120a6e
      addMenuItem(eShowBg, tr("Background Colors"), menu);
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eRate)
Shinya Kitaoka 120a6e
      addMenuItem(eShowFramerate, tr("Framerate"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    addMenuItem(eShowVcr, tr("Playback Controls"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if ((m_gadgetsMask & eRed) || (m_gadgetsMask & eGreen) ||
Shinya Kitaoka 120a6e
        (m_gadgetsMask & eBlue) || (m_gadgetsMask & eMatte))
Shinya Kitaoka 120a6e
      addMenuItem(eShowcolorFilter, tr("Color Channels"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (withCustomWidget) addMenuItem(eShowCustom, tr("Set Key"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eHisto) addMenuItem(eShowHisto, tr("Histogram"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eFilledRaster)
Shinya Kitaoka 120a6e
      addMenuItem(eFilledRaster, tr("Display Areas as Filled"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    bool ret = connect(menu, SIGNAL(triggered(QAction *)), this,
Shinya Kitaoka 120a6e
                       SLOT(onCustomizeButtonPressed(QAction *)));
Shinya Kitaoka 120a6e
    assert(ret);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::createPlayToolBar(bool withCustomWidget) {
Shinya Kitaoka 120a6e
  bool ret = true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_playToolBar = new QToolBar(this);
Shinya Kitaoka 120a6e
  m_playToolBar->setMovable(false);
Shinya Kitaoka 120a6e
  m_playToolBar->setObjectName("FlipConsolePlayToolBar");
shun_iwasawa 4a5f42
  m_playToolBar->setIconSize(QSize(17, 17));
Shinya Kitaoka 120a6e
  //	m_playToolBar->setObjectName("chackableButtonToolBar");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // m_playToolBar->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  createCustomizeMenu(withCustomWidget);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eSave) {
shun_iwasawa 4a5f42
    createButton(eSave, "save", tr("&Save Images"), false);
Shinya Kitaoka 120a6e
    // m_saveSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // snapshot
Shinya Kitaoka 120a6e
  bool separator = false;
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eSaveImg) {
Shinya Kitaoka 120a6e
    createButton(eSaveImg, "snapshot", tr("&Snapshot"), false);
Shinya Kitaoka 120a6e
    separator = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eCompare) {
Shinya Kitaoka 120a6e
    createButton(eCompare, "compare", tr("&Compare to Snapshot"), true);
Shinya Kitaoka 120a6e
    separator = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (separator) m_compareSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // sub camera
Shinya Kitaoka 120a6e
  separator = false;
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eDefineSubCamera) {
Shinya Kitaoka 120a6e
    createButton(eDefineSubCamera, "define_subcamera_preview",
Shinya Kitaoka 120a6e
                 tr("&Define Sub-camera"), true);
Shinya Kitaoka 120a6e
    separator = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eDefineLoadBox) {
Shinya Kitaoka 120a6e
    createButton(eDefineLoadBox, "define_subcamera_preview",
Shinya Kitaoka 120a6e
                 tr("&Define Loading Box"), true);
Shinya Kitaoka 120a6e
    separator = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eUseLoadBox) {
Shinya Kitaoka 120a6e
    createButton(eUseLoadBox, "use_subcamera_preview", tr("&Use Loading Box"),
Shinya Kitaoka 120a6e
                 true);
Shinya Kitaoka 120a6e
    separator = true;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (separator) m_subcamSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // preview BGs
Shinya Kitaoka 120a6e
  QActionGroup *group = new QActionGroup(m_playToolBar);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eWhiteBg)
Shinya Kitaoka 120a6e
    createOnOffButton(eWhiteBg, "preview_white", tr("&White Background"),
Shinya Kitaoka 120a6e
                      group);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eBlackBg)
Shinya Kitaoka 120a6e
    createOnOffButton(eBlackBg, "preview_black", tr("&Black Background"),
Shinya Kitaoka 120a6e
                      group);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eCheckBg)
Shinya Kitaoka 120a6e
    createOnOffButton(eCheckBg, "preview_checkboard",
Shinya Kitaoka 120a6e
                      tr("&Checkered Background"), group);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eWhiteBg) m_bgSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // VCR buttons
Shinya Kitaoka 120a6e
  QActionGroup *playGroup = new QActionGroup(m_playToolBar);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eFirst)
Shinya Kitaoka 120a6e
    createButton(eFirst, "framefirst", tr("&First Frame"), false);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & ePrev)
Shinya Kitaoka 120a6e
    createButton(ePrev, "frameprev", tr("&Previous Frame"), false);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & ePause)
Shinya Kitaoka 120a6e
    createCheckedButtonWithBorderImage(ePause, "pause", tr("Pause"), true,
Shinya Kitaoka 120a6e
                                       playGroup, "A_Flip_Pause");
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & ePlay)
Shinya Kitaoka 120a6e
    createCheckedButtonWithBorderImage(ePlay, "play", tr("Play"), true,
Shinya Kitaoka 120a6e
                                       playGroup, "A_Flip_Play");
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eLoop)
Shinya Kitaoka 120a6e
    createCheckedButtonWithBorderImage(eLoop, "loop", tr("Loop"), true,
Shinya Kitaoka 120a6e
                                       playGroup, "A_Flip_Loop");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eNext)
Shinya Kitaoka 120a6e
    createButton(eNext, "framenext", tr("&Next frame"), false);
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eLast)
Shinya Kitaoka 120a6e
    createButton(eLast, "framelast", tr("&Last Frame"), false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // separator
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & ePlay) m_vcrSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Channel Selector
Shinya Kitaoka 120a6e
  m_colorFilterGroup = new QActionGroup(m_playToolBar);
Shinya Kitaoka 120a6e
  m_colorFilterGroup->setExclusive(false);
Shinya Kitaoka 120a6e
  if ((m_gadgetsMask & eRed) && !(m_gadgetsMask & eGRed))
Shinya Kitaoka 120a6e
    createButton(eRed, "channelred", tr("Red Channel"), true);
Shinya Kitaoka 120a6e
  else if ((m_gadgetsMask & eRed) && (m_gadgetsMask & eGRed))
Shinya Kitaoka 120a6e
    m_doubleRedAction = createDoubleButton(
Shinya Kitaoka 120a6e
        eRed, eGRed, "half_R", "half_bw", tr("Red Channel"),
Shinya Kitaoka 120a6e
        tr("Red Channel in Grayscale"), m_colorFilterGroup, m_doubleRed);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if ((m_gadgetsMask & eGreen) && !(m_gadgetsMask & eGGreen))
Shinya Kitaoka 120a6e
    createButton(eGreen, "channelgreen", tr("Green Channel"), true);
Shinya Kitaoka 120a6e
  else if ((m_gadgetsMask & eGreen) && (m_gadgetsMask & eGGreen))
Shinya Kitaoka 120a6e
    m_doubleGreenAction = createDoubleButton(
Shinya Kitaoka 120a6e
        eGreen, eGGreen, "half_G", "half_bw", tr("Green Channel"),
Shinya Kitaoka 120a6e
        tr("Green Channel in Grayscale"), m_colorFilterGroup, m_doubleGreen);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if ((m_gadgetsMask & eBlue) && !(m_gadgetsMask & eGBlue))
Shinya Kitaoka 120a6e
    createButton(eBlue, "channelblue", tr("Blue Channel"), true);
Shinya Kitaoka 120a6e
  else if ((m_gadgetsMask & eBlue) && (m_gadgetsMask & eGBlue))
Shinya Kitaoka 120a6e
    m_doubleBlueAction = createDoubleButton(
Shinya Kitaoka 120a6e
        eBlue, eGBlue, "half_B", "half_bw", tr("Blue Channel"),
Shinya Kitaoka 120a6e
        tr("Blue Channel in Grayscale"), m_colorFilterGroup, m_doubleBlue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ret = ret && connect(m_colorFilterGroup, SIGNAL(triggered(QAction *)), this,
Shinya Kitaoka 120a6e
                       SLOT(onButtonPressed(QAction *)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eMatte)
Shinya Kitaoka 120a6e
    createButton(eMatte, "channelmatte", tr("Alpha Channel"), true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // separator
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eRed || m_gadgetsMask & eGRed)
Shinya Kitaoka 120a6e
    m_colorFilterSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
shun_iwasawa db5f54
  // Sound & Histogram & Locator
shun_iwasawa db5f54
  if (m_gadgetsMask & eSound || m_gadgetsMask & eHisto ||
shun_iwasawa db5f54
      m_gadgetsMask & eLocator) {
Shinya Kitaoka 120a6e
    if (m_gadgetsMask & eSound) {
Shinya Kitaoka 120a6e
      createButton(eSound, "sound", tr("&Soundtrack "), true);
Shinya Kitaoka 120a6e
      m_soundSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
    }
shun_iwasawa db5f54
    if (m_gadgetsMask & eHisto)
Shinya Kitaoka 120a6e
      createButton(eHisto, "histograms", tr("&Histogram"), false);
shun_iwasawa db5f54
    if (m_gadgetsMask & eLocator)
shun_iwasawa db5f54
      createButton(eLocator, "locator", tr("&Locator"), false);
shun_iwasawa db5f54
    if (m_gadgetsMask & eHisto || m_gadgetsMask & eLocator)
Shinya Kitaoka 120a6e
      m_histoSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_gadgetsMask & eFilledRaster) {
Shinya Kitaoka 120a6e
    createOnOffButton(eFilledRaster, "preview_white",
Shinya Kitaoka 120a6e
                      tr("&Display Areas as Filled"), 0);
Shinya Kitaoka 120a6e
    m_filledRasterSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // for all actions in this toolbar
Shinya Kitaoka 120a6e
  ret = ret && connect(m_playToolBar, SIGNAL(actionTriggered(QAction *)), this,
Shinya Kitaoka 120a6e
                       SLOT(onButtonPressed(QAction *)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setChecked(ePause, true);
Shinya Kitaoka 120a6e
  setChecked(eWhiteBg, FlipBookWhiteBgToggle);
Shinya Kitaoka 120a6e
  setChecked(eBlackBg, FlipBookBlackBgToggle);
Shinya Kitaoka 120a6e
  setChecked(eCheckBg, FlipBookCheckBgToggle);
Shinya Kitaoka 120a6e
  assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::enableBlanks(bool state) {
Shinya Kitaoka 120a6e
  m_drawBlanksEnabled = state;
Shinya Kitaoka 120a6e
  m_blankColor        = TPixel::Transparent;
Shinya Kitaoka 120a6e
  if (m_drawBlanksEnabled)
Shinya Kitaoka 120a6e
    Preferences::instance()->getBlankValues(m_blanksCount, m_blankColor);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    m_blanksCount = 0;
Shinya Kitaoka 120a6e
    m_blankColor  = TPixel::Transparent;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! call consoleOwner->onDrawFrame() intead of emitting drawFrame signal
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void FlipConsole::showCurrentFrame() {
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setChecked(UINT button, bool state) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  if (m_playToolBar) {
Shinya Kitaoka 120a6e
    QObjectList objectList = m_playToolBar->children();
Shinya Kitaoka 120a6e
    for (i = 0; i < (int)objectList.size(); i++) {
Shinya Kitaoka 120a6e
      QAction *action = dynamic_cast<qaction *="">(objectList[i]);</qaction>
Shinya Kitaoka 120a6e
      if (!action) {
Shinya Kitaoka 120a6e
        QToolButton *toolButton = dynamic_cast<qtoolbutton *="">(objectList[i]);</qtoolbutton>
Shinya Kitaoka 120a6e
        if (!toolButton) continue;
Shinya Kitaoka 120a6e
        action = toolButton->defaultAction();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (action && action->data().toUInt() == button) {
Shinya Kitaoka 120a6e
        action->setChecked(state);
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_colorFilterGroup) {
Shinya Kitaoka 120a6e
    QList<qaction *=""> list = m_colorFilterGroup->actions();</qaction>
Shinya Kitaoka 120a6e
    for (i = 0; i < (int)list.size(); i++)
Shinya Kitaoka 120a6e
      if (list[i]->data().toUInt() == button) {
Shinya Kitaoka 120a6e
        list[i]->setChecked(state);
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FlipConsole::isChecked(UINT button) const {
Shinya Kitaoka 120a6e
  QList<qaction *=""> list;</qaction>
Shinya Kitaoka 120a6e
  int i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_playToolBar) {
Shinya Kitaoka 120a6e
    list = m_playToolBar->actions();
Shinya Kitaoka 120a6e
    for (i = 0; i < (int)list.size(); i++)
Shinya Kitaoka 120a6e
      if (list[i]->data().toUInt() == button) return list[i]->isChecked();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_colorFilterGroup) {
Shinya Kitaoka 120a6e
    list = m_colorFilterGroup->actions();
Shinya Kitaoka 120a6e
    for (i = 0; i < (int)list.size(); i++)
Shinya Kitaoka 120a6e
      if (list[i]->data().toUInt() == button) return list[i]->isChecked();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::pressLinkedConsoleButton(UINT button, FlipConsole *parent) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  assert(parent);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < m_visibleConsoles.size(); i++) {
Shinya Kitaoka 120a6e
    FlipConsole *console = m_visibleConsoles.at(i);
Shinya Kitaoka 120a6e
    if (console->m_isLinkable && console != parent) {
Shinya Kitaoka 120a6e
      console->setChecked(button, parent ? parent->isChecked(button) : true);
Shinya Kitaoka 120a6e
      console->doButtonPressed(button);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::onButtonPressed(int button) {
Shinya Kitaoka 120a6e
  makeCurrent();
Jeremy Bullock 0cb7c2
  if (m_playbackExecutor.isRunning() &&
Jeremy Bullock 0cb7c2
      (button == FlipConsole::ePlay || button == FlipConsole::eLoop)) {
Jeremy Bullock 0cb7c2
    pressButton(ePause);
Jeremy Bullock 0cb7c2
  } else
Jeremy Bullock 0cb7c2
    doButtonPressed(button);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_areLinked) pressLinkedConsoleButton(button, this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void FlipConsole::pressButton(EGadget buttonId) {
Jeremy Bullock 0cb7c2
  if (m_visibleConsoles.indexOf(this) < 0 && m_visibleConsoles.size() > 0) {
Jeremy Bullock 0cb7c2
    FlipConsole *console = m_visibleConsoles.at(0);
Jeremy Bullock 0cb7c2
    console->makeCurrent();
Jeremy Bullock 0cb7c2
    if (console->m_buttons.contains(buttonId)) {
Jeremy Bullock 0cb7c2
      console->m_buttons[buttonId]->click();
Jeremy Bullock 0cb7c2
    } else if (console->m_actions.contains(buttonId))
Jeremy Bullock 0cb7c2
      console->m_actions[buttonId]->trigger();
Jeremy Bullock 0cb7c2
  } else {
Jeremy Bullock 0cb7c2
    if (m_buttons.contains(buttonId)) {
Jeremy Bullock 0cb7c2
      m_buttons[buttonId]->click();
Jeremy Bullock 0cb7c2
    } else if (m_actions.contains(buttonId))
Jeremy Bullock 0cb7c2
      m_actions[buttonId]->trigger();
Jeremy Bullock 0cb7c2
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::onLoadBox(bool isDefine) {
Shinya Kitaoka 120a6e
  int shrink, dummy;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Preferences::instance()->getViewValues(shrink, dummy);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (shrink != 1) {
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
    MessageBox(0, "Cannot use loading box with a shrink factor! ", "Warning",
Shinya Kitaoka 120a6e
               MB_OK);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    setChecked(eUseLoadBox, false);
Shinya Kitaoka 120a6e
    setChecked(eDefineLoadBox, false);
Shinya Kitaoka 120a6e
    m_settings.m_useLoadbox = m_settings.m_defineLoadbox = false;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isDefine)
Shinya Kitaoka 120a6e
    m_settings.m_defineLoadbox = !m_settings.m_defineLoadbox;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_settings.m_useLoadbox = !m_settings.m_useLoadbox;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_settings.m_defineLoadbox && m_settings.m_useLoadbox) {
Shinya Kitaoka 120a6e
    setChecked(isDefine ? eUseLoadBox : eDefineLoadBox, false);
Shinya Kitaoka 120a6e
    if (isDefine)
Shinya Kitaoka 120a6e
      m_settings.m_useLoadbox = false;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_settings.m_defineLoadbox = false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::doButtonPressed(UINT button) {
Shinya Kitaoka 120a6e
  emit buttonPressed((FlipConsole::EGadget)button);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int from = m_from, to = m_to;
Shinya Kitaoka 120a6e
  // When the level editing mode, ignore the preview frame range marker
Shinya Kitaoka 120a6e
  if (m_markerFrom <= m_markerTo && m_frameHandle &&
Shinya Kitaoka 120a6e
      m_frameHandle->isEditingScene())
Shinya Kitaoka 120a6e
    from = m_markerFrom, to = m_markerTo;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool linked = m_areLinked && m_isLinkable;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (button) {
Shinya Kitaoka 120a6e
  case eFirst:
Shinya Kitaoka 120a6e
    m_currentFrame = from;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case ePrev:
Shinya Kitaoka 120a6e
    m_currentFrame =
Shinya Kitaoka 120a6e
        (m_currentFrame - m_step < from) ? from : m_currentFrame - m_step;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case eNext:
Shinya Kitaoka 120a6e
    m_currentFrame =
Shinya Kitaoka 120a6e
        (m_currentFrame + m_step > to) ? to : m_currentFrame + m_step;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case eLast:
Shinya Kitaoka 120a6e
    m_currentFrame = to;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case ePlay:
Shinya Kitaoka 120a6e
  case eLoop:
Shinya Kitaoka 120a6e
    // if (	  isChecked(ePlay,   false);
Shinya Kitaoka 120a6e
    // setChecked(eLoop,   false);
Shinya Kitaoka 120a6e
    m_editCurrFrame->disconnect();
Shinya Kitaoka 120a6e
    m_currFrameSlider->disconnect();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_isPlay = (button == ePlay);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (linked && m_isLinkedPlaying) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if ((m_fps == 0 || m_framesCount == 0) && m_playbackExecutor.isRunning()) {
Shinya Kitaoka 120a6e
      doButtonPressed(ePause);
Shinya Kitaoka 120a6e
      if (m_fpsLabel) m_fpsLabel->setText(tr(" FPS ") + QString::number(m_fps));
Shinya Kitaoka 120a6e
      if (m_fpsField) m_fpsField->setLineEditBackgroundColor(Qt::transparent);
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (m_fpsLabel) m_fpsLabel->setText(tr(" FPS	") + "/");
Shinya Kitaoka 120a6e
    if (m_fpsField) m_fpsField->setLineEditBackgroundColor(Qt::red);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_playbackExecutor.resetFps(m_fps);
Shinya Kitaoka 120a6e
    if (!m_playbackExecutor.isRunning()) m_playbackExecutor.start();
Shinya Kitaoka 120a6e
    m_isLinkedPlaying = linked;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_reverse = (m_fps < 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!linked) {
Shinya Kitaoka 120a6e
      // if the play button pressed at the end frame, then go back to the start
Shinya Kitaoka 120a6e
      // frame and play
Shinya Kitaoka 120a6e
      if (m_currentFrame <= from ||
Shinya Kitaoka 120a6e
          m_currentFrame >=
Shinya Kitaoka 120a6e
              to)  // the first frame of the playback is drawn right now
Shinya Kitaoka 120a6e
        m_currentFrame               = m_reverse ? to : from;
Shinya Kitaoka 120a6e
      m_settings.m_recomputeIfNeeded = true;
Shinya Kitaoka 120a6e
      m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    emit playStateChanged(true);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case ePause:
shun-iwasawa 79662f
    if (!m_playbackExecutor.isRunning() && !m_isLinkedPlaying) return;
shun-iwasawa 79662f
Shinya Kitaoka 120a6e
    m_isLinkedPlaying = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_playbackExecutor.isRunning()) m_playbackExecutor.abort();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_isPlay       = false;
Shinya Kitaoka 120a6e
    m_blanksToDraw = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_consoleOwner->swapBuffers();
Shinya Kitaoka 120a6e
    m_consoleOwner->changeSwapBehavior(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_settings.m_blankColor != TPixel::Transparent) {
Shinya Kitaoka 120a6e
      m_settings.m_blankColor        = TPixel::Transparent;
Shinya Kitaoka 120a6e
      m_settings.m_recomputeIfNeeded = true;
Shinya Kitaoka 120a6e
      m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (m_fpsLabel) m_fpsLabel->setText(tr(" FPS "));
Shinya Kitaoka 120a6e
    if (m_fpsField) m_fpsField->setLineEditBackgroundColor(Qt::transparent);
Shinya Kitaoka 120a6e
    // setChecked(ePlay,   false);
Shinya Kitaoka 120a6e
    // setChecked(eLoop,   false);
Shinya Kitaoka 120a6e
    connect(m_editCurrFrame, SIGNAL(editingFinished()), this,
Shinya Kitaoka 120a6e
            SLOT(OnSetCurrentFrame()));
Shinya Kitaoka 120a6e
    connect(m_currFrameSlider, SIGNAL(flipSliderReleased()), this,
Shinya Kitaoka 120a6e
            SLOT(OnFrameSliderRelease()));
Shinya Kitaoka 120a6e
    connect(m_currFrameSlider, SIGNAL(flipSliderPressed()), this,
Shinya Kitaoka 120a6e
            SLOT(OnFrameSliderPress()));
Shinya Kitaoka 120a6e
    connect(m_currFrameSlider, SIGNAL(valueChanged(int)), this,
Shinya Kitaoka 120a6e
            SLOT(OnSetCurrentFrame(int)));
Shinya Kitaoka 120a6e
    connect(m_currFrameSlider, SIGNAL(flipSliderReleased()), this,
Shinya Kitaoka 120a6e
            SLOT(onSliderRelease()));
Shinya Kitaoka 120a6e
    emit playStateChanged(false);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eGRed:
Shinya Kitaoka 120a6e
  case eGGreen:
Shinya Kitaoka 120a6e
  case eGBlue:
Shinya Kitaoka 120a6e
  case eRed:
Shinya Kitaoka 120a6e
  case eGreen:
Shinya Kitaoka 120a6e
  case eBlue:
Shinya Kitaoka 120a6e
  case eMatte: {
Shinya Kitaoka 120a6e
    if (button != eGRed) setChecked(eGRed, false);
Shinya Kitaoka 120a6e
    if (button != eGGreen) setChecked(eGGreen, false);
Shinya Kitaoka 120a6e
    if (button != eGBlue) setChecked(eGBlue, false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (button == eGRed || button == eGGreen || button == eGBlue) {
Shinya Kitaoka 120a6e
      m_settings.m_greytones = isChecked(button);
Shinya Kitaoka 120a6e
      setChecked(eRed, false);
Shinya Kitaoka 120a6e
      setChecked(eGreen, false);
Shinya Kitaoka 120a6e
      setChecked(eBlue, false);
Shinya Kitaoka 120a6e
      setChecked(eMatte, false);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      m_settings.m_greytones = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_doubleRed) {
Shinya Kitaoka 120a6e
      m_doubleRed->update();
Shinya Kitaoka 120a6e
      m_doubleGreen->update();
Shinya Kitaoka 120a6e
      m_doubleBlue->update();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int colorMask = 0;
Shinya Kitaoka 120a6e
    if (isChecked(eRed) || isChecked(eGRed))
Shinya Kitaoka 120a6e
      colorMask = colorMask | TRop::RChan;
Shinya Kitaoka 120a6e
    if (isChecked(eGreen) || isChecked(eGGreen))
Shinya Kitaoka 120a6e
      colorMask = colorMask | TRop::GChan;
Shinya Kitaoka 120a6e
    if (isChecked(eBlue) || isChecked(eGBlue))
Shinya Kitaoka 120a6e
      colorMask                      = colorMask | TRop::BChan;
Shinya Kitaoka 120a6e
    if (isChecked(eMatte)) colorMask = colorMask | TRop::MChan;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (colorMask == (TRop::RChan | TRop::GChan | TRop::BChan) ||
Shinya Kitaoka 120a6e
        colorMask == (TRop::RChan | TRop::GChan | TRop::BChan | TRop::MChan))
Shinya Kitaoka 120a6e
      m_settings.m_colorMask = 0;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      m_settings.m_colorMask = colorMask;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  case eSound:
Shinya Kitaoka 120a6e
    // emit soundEnabled(isChecked(eSound));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eWhiteBg:
Shinya Kitaoka 120a6e
  case eBlackBg:
Shinya Kitaoka 120a6e
  case eCheckBg:
Shinya Kitaoka 120a6e
    m_settings.m_bg       = (EGadget)button;
Shinya Kitaoka 120a6e
    FlipBookWhiteBgToggle = isChecked(eWhiteBg);
Shinya Kitaoka 120a6e
    FlipBookBlackBgToggle = isChecked(eBlackBg);
Shinya Kitaoka 120a6e
    FlipBookCheckBgToggle = isChecked(eCheckBg);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case FlipConsole::eCompare:
Shinya Kitaoka 120a6e
    m_settings.m_doCompare = !m_settings.m_doCompare;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eHisto:
Shinya Kitaoka 120a6e
  case eSaveImg:
Shinya Kitaoka 120a6e
  case eSave:
shun_iwasawa db5f54
  case eLocator:
Shinya Kitaoka 120a6e
    // nothing to do
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eDefineSubCamera:
Shinya Kitaoka 120a6e
    // nothing to do
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eDefineLoadBox:
Shinya Kitaoka 120a6e
    onLoadBox(true);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eUseLoadBox:
Shinya Kitaoka 120a6e
    onLoadBox(false);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case eFilledRaster:
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currFrameSlider->setValue(m_currentFrame);
Shinya Kitaoka 120a6e
  m_editCurrFrame->setText(QString::number(m_currentFrame));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QFrame *FlipConsole::createFrameSlider() {
Shinya Kitaoka 120a6e
  QFrame *frameSliderFrame = new QFrame(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_editCurrFrame = new DVGui::IntLineEdit(frameSliderFrame, m_currentFrame);
Shinya Kitaoka 120a6e
  m_editCurrFrame->setToolTip(tr("Set the current frame"));
Shinya Kitaoka 120a6e
  m_editCurrFrame->setFixedWidth(40);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currFrameSlider = new FlipSlider(frameSliderFrame);
Shinya Kitaoka 120a6e
  m_currFrameSlider->setToolTip(tr("Drag to play the animation"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currFrameSlider->setRange(0, 0);
Shinya Kitaoka 120a6e
  m_currFrameSlider->setValue(0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_drawBlanksEnabled) {
Shinya Kitaoka 120a6e
    m_enableBlankFrameButton = new QPushButton(this);
Shinya Kitaoka 120a6e
    m_enableBlankFrameButton->setCheckable(true);
Shinya Kitaoka 120a6e
    m_enableBlankFrameButton->setChecked(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_enableBlankFrameButton->setFixedHeight(24);
Shinya Kitaoka 120a6e
    m_enableBlankFrameButton->setFixedWidth(66);
Shinya Kitaoka 120a6e
    m_enableBlankFrameButton->setObjectName("enableBlankFrameButton");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // layout
Shinya Kitaoka 120a6e
  QHBoxLayout *frameSliderLayout = new QHBoxLayout();
Shinya Kitaoka 120a6e
  frameSliderLayout->setSpacing(5);
Shinya Kitaoka 120a6e
  frameSliderLayout->setMargin(2);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    frameSliderLayout->addWidget(m_editCurrFrame, 0);
Shinya Kitaoka 120a6e
    frameSliderLayout->addWidget(m_currFrameSlider, 1);
Shinya Kitaoka 120a6e
    if (m_drawBlanksEnabled)
Shinya Kitaoka 120a6e
      frameSliderLayout->addWidget(m_enableBlankFrameButton, 0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  frameSliderFrame->setLayout(frameSliderLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  connect(m_editCurrFrame, SIGNAL(editingFinished()), this,
Shinya Kitaoka 120a6e
          SLOT(OnSetCurrentFrame()));
Shinya Kitaoka 120a6e
  connect(m_currFrameSlider, SIGNAL(valueChanged(int)), this,
Shinya Kitaoka 120a6e
          SLOT(OnSetCurrentFrame(int)));
Shinya Kitaoka 120a6e
  connect(m_currFrameSlider, SIGNAL(flipSliderReleased()), this,
Shinya Kitaoka 120a6e
          SLOT(OnFrameSliderRelease()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return frameSliderFrame;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QFrame *FlipConsole::createFpsSlider() {
Shinya Kitaoka 120a6e
  QFrame *fpsSliderFrame = new QFrame(this);
Shinya Kitaoka 120a6e
  // frame per second
Shinya Kitaoka 120a6e
  m_fpsLabel  = new QLabel(QString(" FPS -- /"), fpsSliderFrame);
Shinya Kitaoka 120a6e
  m_fpsSlider = new QScrollBar(Qt::Horizontal, fpsSliderFrame);
Shinya Kitaoka 120a6e
  m_fpsField  = new DVGui::IntLineEdit(fpsSliderFrame, m_fps, -60, 60);
Shinya Kitaoka 120a6e
  m_fpsField->setFixedWidth(40);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_fpsLabel->setMinimumWidth(m_fpsLabel->fontMetrics().width("_FPS_24___"));
Shinya Kitaoka 120a6e
  m_fpsLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
  m_fpsSlider->setObjectName("ViewerFpsSlider");
Shinya Kitaoka 120a6e
  m_fpsSlider->setRange(-60, 60);
Shinya Kitaoka 120a6e
  m_fpsSlider->setValue(m_fps);
Shinya Kitaoka 120a6e
  m_fpsSlider->setToolTip(tr("Set the playback frame rate"));
Shinya Kitaoka 120a6e
  m_fpsSlider->setContextMenuPolicy(Qt::NoContextMenu);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QHBoxLayout *hLay = new QHBoxLayout();
Shinya Kitaoka 120a6e
  hLay->setSpacing(0);
Shinya Kitaoka 120a6e
  hLay->setMargin(0);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    hLay->addWidget(m_fpsLabel, 0);
Shinya Kitaoka 120a6e
    hLay->addWidget(m_fpsField, 0);
Shinya Kitaoka 120a6e
    hLay->addWidget(m_fpsSlider, 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  fpsSliderFrame->setLayout(hLay);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  connect(m_fpsSlider, SIGNAL(valueChanged(int)), this,
Shinya Kitaoka 120a6e
          SLOT(setCurrentFPS(int)));
Shinya Kitaoka 120a6e
  connect(m_fpsField, SIGNAL(editingFinished()), this, SLOT(onFPSEdited()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return fpsSliderFrame;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::onFPSEdited(void) {
Shinya Kitaoka 120a6e
  // this will emit fpsSlider->ValueChanged as well
Shinya Kitaoka 120a6e
  m_fpsSlider->setValue(m_fpsField->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setFrameRange(int from, int to, int step, int current) {
Shinya Kitaoka 120a6e
  if (from != m_from || to != m_to || step != m_step) {
Shinya Kitaoka 120a6e
    m_from = from;
Shinya Kitaoka 120a6e
    m_to   = to;
Shinya Kitaoka 120a6e
    m_step = step;
Shinya Kitaoka 120a6e
    m_to -= (m_to - m_from) % m_step;
Shinya Kitaoka 120a6e
    m_framesCount = (m_to - m_from) / m_step + 1;
Shinya Kitaoka 120a6e
    m_currFrameSlider->blockSignals(true);
Shinya Kitaoka 120a6e
    // m_currFrameSlider->setRange(0, m_framesCount-1);
Shinya Kitaoka 120a6e
    m_currFrameSlider->setRange(m_from, m_to);
Shinya Kitaoka 120a6e
    m_currFrameSlider->setSingleStep(m_step);
Shinya Kitaoka 120a6e
    m_currFrameSlider->blockSignals(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_playbackExecutor.isRunning() ||
Shinya Kitaoka 120a6e
      m_isLinkedPlaying)  // if in playing mode, the slider and the frame field
Shinya Kitaoka 120a6e
                          // are already set in the timer!
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // limit the current frame in the range from-to
Shinya Kitaoka 120a6e
  if (current < from)
Shinya Kitaoka 120a6e
    current = from;
Shinya Kitaoka 120a6e
  else if (current > to)
Shinya Kitaoka 120a6e
    current = to;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currFrameSlider->blockSignals(true);
Shinya Kitaoka 120a6e
  setCurrentFrame(current);
Shinya Kitaoka 120a6e
  m_currFrameSlider->blockSignals(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::incrementCurrentFrame(int delta) {
Shinya Kitaoka 120a6e
  m_currentFrame = m_currentFrame + delta;
Shinya Kitaoka 120a6e
  if (m_currentFrame < m_from)
Shinya Kitaoka 120a6e
    m_currentFrame += m_to - m_from + 1;
Shinya Kitaoka 120a6e
  else if (m_currentFrame > m_to)
Shinya Kitaoka 120a6e
    m_currentFrame -= m_to - m_from + 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_editCurrFrame->setText(QString::number(m_currentFrame));
Shinya Kitaoka 120a6e
  m_currFrameSlider->setValue(m_currentFrame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::OnSetCurrentFrame() {
Shinya Kitaoka 120a6e
  int newFrame = m_editCurrFrame->text().toInt();
Shinya Kitaoka 120a6e
  if (m_step > 1) {
Shinya Kitaoka 120a6e
    newFrame -= ((newFrame - m_from) % m_step);
Shinya Kitaoka 120a6e
    m_editCurrFrame->setText(QString::number(newFrame));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int i, deltaFrame = newFrame - m_currentFrame;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_framesCount == 0) m_editCurrFrame->setText(QString::number(1));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_framesCount == 0 || newFrame == m_currentFrame || newFrame == 0) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (newFrame > m_to) {
Shinya Kitaoka 120a6e
    m_editCurrFrame->setText(QString::number(m_currentFrame));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_currentFrame = newFrame;
Shinya Kitaoka 120a6e
  m_currFrameSlider->setValue(m_currentFrame);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_areLinked)
Shinya Kitaoka 120a6e
    for (i = 0; i < m_visibleConsoles.size(); i++) {
Shinya Kitaoka 120a6e
      FlipConsole *console = m_visibleConsoles.at(i);
Shinya Kitaoka 120a6e
      if (console->m_isLinkable && console != this)
Shinya Kitaoka 120a6e
        console->incrementCurrentFrame(deltaFrame);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::onSliderRelease() { emit sliderReleased(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Shinya Kitaoka 120a6e
void FlipConsole::OnFrameSliderRelease() {
Shinya Kitaoka 120a6e
  m_settings.m_recomputeIfNeeded = true;
Shinya Kitaoka 120a6e
  m_currentFrame                 = -1;
Shinya Kitaoka 120a6e
  OnSetCurrentFrame();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::OnFrameSliderPress() {
Shinya Kitaoka 120a6e
  m_settings.m_recomputeIfNeeded = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------
Toshihiro Shimizu 890ddd
//----------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::OnSetCurrentFrame(int index) {
Shinya Kitaoka 120a6e
  if (m_framesCount == 0) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (index == m_currentFrame) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int deltaFrame = index - m_currentFrame;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_currentFrame = index;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(m_currentFrame <= m_to);
Shinya Kitaoka 120a6e
  m_editCurrFrame->setText(QString::number(m_currentFrame));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_areLinked)
Shinya Kitaoka 120a6e
    for (int i = 0; i < m_visibleConsoles.size(); i++) {
Shinya Kitaoka 120a6e
      FlipConsole *console = m_visibleConsoles.at(i);
Shinya Kitaoka 120a6e
      if (console->m_isLinkable && console != this)
Shinya Kitaoka 120a6e
        console->incrementCurrentFrame(deltaFrame);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setCurrentFrame(int frame, bool forceResetting) {
Shinya Kitaoka 120a6e
  m_currentFrame = (frame == -1) ? m_from : frame;
Shinya Kitaoka 120a6e
  if ((m_playbackExecutor.isRunning() || m_isLinkedPlaying) &&
Shinya Kitaoka 120a6e
      !forceResetting)  // if in playing mode, the slider and the frame field
Shinya Kitaoka 120a6e
                        // are already set in the timer!
Shinya Kitaoka 120a6e
    return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_editCurrFrame->setValue(m_currentFrame);
Shinya Kitaoka 120a6e
  m_currFrameSlider->setValue(m_currentFrame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::enableProgressBar(bool enable) {
Shinya Kitaoka 120a6e
  m_currFrameSlider->setProgressBarEnabled(enable);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::setProgressBarStatus(const std::vector<uchar> *pbStatus) {</uchar>
Shinya Kitaoka 120a6e
  m_currFrameSlider->setProgressBarStatus(pbStatus);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const std::vector<uchar> *FlipConsole::getProgressBarStatus() const {</uchar>
Shinya Kitaoka 120a6e
  return m_currFrameSlider->getProgressBarStatus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun_iwasawa 1f4a70
void FlipConsole::onPreferenceChanged(const QString &prefName) {
shun_iwasawa 1f4a70
  // react only when related properties are changed
shun_iwasawa 1f4a70
  if (prefName != "BlankCount" && prefName != "BlankColor" &&
shun_iwasawa 1f4a70
      !prefName.isEmpty())
shun_iwasawa 1f4a70
    return;
shun_iwasawa 1f4a70
Shinya Kitaoka 120a6e
  if (m_drawBlanksEnabled) {
Shinya Kitaoka 120a6e
    Preferences::instance()->getBlankValues(m_blanksCount, m_blankColor);
Shinya Kitaoka 120a6e
    if (m_blanksCount == 0) {
Shinya Kitaoka 120a6e
      if (m_enableBlankFrameButton->isVisible())
Shinya Kitaoka 120a6e
        m_enableBlankFrameButton->hide();
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (m_enableBlankFrameButton->isHidden())
Shinya Kitaoka 120a6e
        m_enableBlankFrameButton->show();
Shinya Kitaoka 120a6e
      QString buttonText = QString("+%1 Blank").arg(m_blanksCount);
Shinya Kitaoka 120a6e
      if (m_blanksCount > 1) buttonText += "s";
Shinya Kitaoka 120a6e
      m_enableBlankFrameButton->setText(buttonText);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      //--- use white text for dark color and vice versa
Shinya Kitaoka 120a6e
      QString textColor;
Shinya Kitaoka 120a6e
      QString dimmedTextColor;
Shinya Kitaoka 120a6e
      int val = (int)m_blankColor.r * 30 + (int)m_blankColor.g * 59 +
Shinya Kitaoka 120a6e
                (int)m_blankColor.b * 11;
Shinya Kitaoka 120a6e
      if (val < 12800) {
Shinya Kitaoka 120a6e
        textColor       = QString("white");
Shinya Kitaoka 120a6e
        dimmedTextColor = QString("rgb(200,200,200)");
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        textColor       = QString("black");
Shinya Kitaoka 120a6e
        dimmedTextColor = QString("rgb(55,55,55)");
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      int dc = 150;
Shinya Kitaoka 120a6e
      QColor lightBevel(std::min(m_blankColor.r + dc, 255),
Shinya Kitaoka 120a6e
                        std::min(m_blankColor.g + dc, 255),
Shinya Kitaoka 120a6e
                        std::min(m_blankColor.b + dc, 255));
Shinya Kitaoka 120a6e
      QColor darkBevel(std::max(m_blankColor.r - dc, 0),
Shinya Kitaoka 120a6e
                       std::max(m_blankColor.g - dc, 0),
Shinya Kitaoka 120a6e
                       std::max(m_blankColor.b - dc, 0));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      m_enableBlankFrameButton->setStyleSheet(
Shinya Kitaoka 120a6e
          QString("#enableBlankFrameButton{ \
Shinya Kitaoka 473e70
              background-color: transparent; \
Shinya Kitaoka 473e70
              padding: 2px;\
Shinya Kitaoka 473e70
              font-weight: bold; \
Shinya Kitaoka 473e70
              font-size: 12px; \
Shinya Kitaoka 473e70
              color: %11;\
Shinya Kitaoka 473e70
              border-style: inset; \
Shinya Kitaoka 473e70
              border-left-color: rgb(%5,%6,%7); \
Shinya Kitaoka 473e70
              border-top-color: rgb(%5,%6,%7); \
Shinya Kitaoka 473e70
              border-right-color: rgb(%8,%9,%10); \
Shinya Kitaoka 473e70
              border-bottom-color: rgb(%8,%9,%10); \
Shinya Kitaoka 473e70
              border-width: 2px; \
Shinya Kitaoka 473e70
              border-radius: 3px; \
Shinya Kitaoka 473e70
            } \
Shinya Kitaoka 473e70
            #enableBlankFrameButton:checked { \
Shinya Kitaoka 473e70
              background-color: rgb(%1,%2,%3); \
Shinya Kitaoka 473e70
              color: %4; \
Shinya Kitaoka 473e70
              border-style: outset; \
Shinya Kitaoka 473e70
              border-left-color: rgb(%8,%9,%10); \
Shinya Kitaoka 473e70
              border-top-color: rgb(%8,%9,%10); \
Shinya Kitaoka 473e70
              border-right-color: rgb(%5,%6,%7); \
Shinya Kitaoka 473e70
              border-bottom-color: rgb(%5,%6,%7); \
Shinya Kitaoka 473e70
            } ")
Shinya Kitaoka 120a6e
              .arg(m_blankColor.r)
Shinya Kitaoka 120a6e
              .arg(m_blankColor.g)
Shinya Kitaoka 120a6e
              .arg(m_blankColor.b)
Shinya Kitaoka 120a6e
              .arg(textColor)
Shinya Kitaoka 120a6e
              .arg(lightBevel.red())
Shinya Kitaoka 120a6e
              .arg(lightBevel.green())
Shinya Kitaoka 120a6e
              .arg(lightBevel.blue())
Shinya Kitaoka 120a6e
              .arg(darkBevel.red())
Shinya Kitaoka 120a6e
              .arg(darkBevel.green())
Shinya Kitaoka 120a6e
              .arg(darkBevel.blue())
Shinya Kitaoka 120a6e
              .arg(dimmedTextColor));
Shinya Kitaoka 120a6e
      m_enableBlankFrameButton->update();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//====================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class FlipConsoleActionsCreator : AuxActionsCreator {
Shinya Kitaoka 120a6e
  void createToggleAction(QObject *parent, const char *cmdId, const char *name,
Shinya Kitaoka 120a6e
                          int buttonId) {
Shinya Kitaoka 120a6e
    QAction *action = new QAction(name, parent);
Shinya Kitaoka 120a6e
    action->setData(QVariant(buttonId));
Shinya Kitaoka 120a6e
    CommandManager::instance()->define(cmdId, MiscCommandType, "", action);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 473e70
  void createActions(QObject *parent) override {
Shinya Kitaoka 120a6e
    /*createToggleAction(parent, "A_Flip_Play",  "Play",  FlipConsole::ePlay);
Shinya Kitaoka 120a6e
createToggleAction(parent, "A_Flip_Pause", "Pause", FlipConsole::ePause);
Shinya Kitaoka 120a6e
createToggleAction(parent, "A_Flip_Loop",  "Loop",  FlipConsole::eLoop);*/
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
} flipConsoleActionsCreator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------