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"
shun-iwasawa 481b59
#include "toonz/toonzfolders.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
shun-iwasawa fe0983
#include <time.h></time.h>
shun-iwasawa fe0983
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);
shun-iwasawa 481b59
shun-iwasawa 481b59
QString getFlipSettingsPath() {
shun-iwasawa 481b59
  return toQString(ToonzFolder::getMyModuleDir() +
shun-iwasawa 481b59
                   TFilePath("fliphistory.ini"));
shun-iwasawa 481b59
}
shun-iwasawa 481b59
shun-iwasawa ece48f
}  // namespace
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
shun-iwasawa fe0983
  // one). However, the fps should be sampled at a faster rate. Each sample is
shun-iwasawa fe0983
  // taken at 1/4 second, and the last 4 samples data are stored to keep trace
shun-iwasawa fe0983
  // of the last second of playback.
shun-iwasawa fe0983
  m_timer.start();
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
  qint64 timeResolution =
shun-iwasawa fe0983
      250 * 1000000;  // Use a sufficient sampling resolution (currently 1/4
shun-iwasawa fe0983
                      // sec). Fps calculation is made once per sample.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int fps = m_fps, currSample = 0;
shun-iwasawa fe0983
  qint64 playedFramesCount = 0;
shun-iwasawa fe0983
  qint64 nextSampleInstant = timeResolution;
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
  qint64 lastFrameCounts[4]    = {0, 0, 0,
shun-iwasawa 813865
                                  0};  // Keep the last 4 'played frames' counts.
shun-iwasawa fe0983
  qint64 lastSampleInstants[4] = {0, 0, 0,
shun-iwasawa fe0983
                                  0};  // Same for the last sampling instants
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
  qint64 targetFrameTime =
shun-iwasawa fe0983
      1000000000 / (qint64)abs(m_fps);  // User-required time between frames
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
  qint64 emissionInstant = 0;  // starting instant in which rendering is invoked
luz paz 1414d5
  qint64 avgSwapTime     = 0;  // average time for swapping buffers
shun-iwasawa fe0983
  qint64 shortTermDelayAdjuster =
shun-iwasawa fe0983
      0;  // accumurate recent errors and adjust in short term
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  while (!m_abort) {
shun-iwasawa fe0983
    emissionInstant = m_timer.nsecsElapsed();
shun-iwasawa fe0983
shun-iwasawa fe0983
    if (emissionInstant > nextSampleInstant) {
shun-iwasawa fe0983
      // Fps calculation
shun-iwasawa fe0983
      qint64 framesCount = playedFramesCount - lastFrameCounts[currSample];
shun-iwasawa fe0983
      qint64 elapsedTime = emissionInstant - lastSampleInstants[currSample];
shun-iwasawa fe0983
      fps                = troundp((long double)(1000000000 * framesCount) /
shun-iwasawa 813865
                                   (long double)elapsedTime);
shun-iwasawa fe0983
shun-iwasawa fe0983
      targetFrameTime =
shun-iwasawa fe0983
          1000000000 / (qint64)abs(m_fps);  // m_fps could have changed...
shun-iwasawa fe0983
shun-iwasawa fe0983
      // estimate time for swapping buffers
shun-iwasawa fe0983
      qint64 avgSwapTimeD = (elapsedTime / framesCount) - targetFrameTime;
shun-iwasawa fe0983
      if (avgSwapTime - avgSwapTimeD >
shun-iwasawa fe0983
          20000000)  // Reset beyond, say, 20 msecs tolerance.
shun-iwasawa fe0983
        avgSwapTime = avgSwapTimeD;
shun-iwasawa fe0983
      else
shun-iwasawa fe0983
        avgSwapTime += avgSwapTimeD;
shun-iwasawa fe0983
      avgSwapTime = std::min(targetFrameTime, std::max(avgSwapTime, (qint64)0));
Shinya Kitaoka 120a6e
luz paz 1414d5
      // prepare for the next sampling
Shinya Kitaoka 120a6e
      lastFrameCounts[currSample]    = playedFramesCount;
shun-iwasawa fe0983
      lastSampleInstants[currSample] = emissionInstant;
shun-iwasawa fe0983
      currSample                     = (currSample + 1) % 4;
shun-iwasawa fe0983
      nextSampleInstant              = emissionInstant + timeResolution;
shun-iwasawa fe0983
    }
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
    // draw the next frame
shun-iwasawa fe0983
    if (playedFramesCount) {
shun-iwasawa fe0983
      qint64 delayAdjust = shortTermDelayAdjuster / 4;
shun-iwasawa fe0983
      qint64 targetInstant =
shun-iwasawa fe0983
          emissionInstant + targetFrameTime - avgSwapTime - delayAdjust;
shun-iwasawa fe0983
      targetInstant = std::max(targetInstant, emissionInstant);
shun-iwasawa fe0983
      shortTermDelayAdjuster -= delayAdjust;
shun-iwasawa fe0983
shun-iwasawa fe0983
      // Show the next frame, telling currently measured fps
shun-iwasawa c1ce3c
      // For the Flipbook, the wait time will be inserted at the end of paintGL
shun-iwasawa c1ce3c
      // in order to achieve precise playback
shun-iwasawa fe0983
      emit nextFrame(fps, &m_timer, targetInstant);
shun-iwasawa fe0983
shun-iwasawa c1ce3c
      // Playing on Viewer / Combo Viewer will advance the current frame.
shun-iwasawa c1ce3c
      // Calling qApp->processEvents() on drawing frame causes repaint of other
shun-iwasawa c1ce3c
      // panels which slows playback. Therefore in Viewer / Combo Viewer panels
shun-iwasawa c1ce3c
      // it just calls update() and necessary wait will be inserted here.
shun-iwasawa c1ce3c
      qint64 currentInstant = m_timer.nsecsElapsed();
shun-iwasawa c1ce3c
      while (currentInstant < targetInstant) {
shun-iwasawa c1ce3c
        currentInstant = m_timer.nsecsElapsed();
shun-iwasawa c1ce3c
      }
shun-iwasawa c1ce3c
shun-iwasawa fe0983
      if (FlipConsole::m_areLinked) {
shun-iwasawa fe0983
        // In case there are linked consoles, update them too.
shun-iwasawa fe0983
        // Their load time must be included in the fps calculation.
shun-iwasawa fe0983
        int i, consolesCount = FlipConsole::m_visibleConsoles.size();
shun-iwasawa fe0983
        for (i = 0; i < consolesCount; ++i) {
shun-iwasawa fe0983
          FlipConsole *console = FlipConsole::m_visibleConsoles.at(i);
shun-iwasawa fe0983
          if (console->isLinkable() && console != FlipConsole::m_currentConsole)
shun-iwasawa fe0983
            console->playbackExecutor().emitNextFrame(m_fps < 0 ? -fps : fps);
shun-iwasawa fe0983
        }
shun-iwasawa fe0983
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
    //-------- Each nextFrame() blocks until the frame has been shown ---------
shun-iwasawa fe0983
shun-iwasawa fe0983
    // accumurate error and slightly adjust waiting time for subsequent frames
shun-iwasawa fe0983
    qint64 delay = m_timer.nsecsElapsed() - emissionInstant - targetFrameTime;
shun-iwasawa fe0983
    // just ignore a large error
shun-iwasawa fe0983
    if (delay < targetFrameTime) shortTermDelayAdjuster += delay;
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
    ++playedFramesCount;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_abort = false;
shun-iwasawa fe0983
  m_timer.invalidate();
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,
shun-iwasawa 813865
                 ((*m_progressBarStatus)[i] == PBFrameStarted) ? PBStartedColor
shun-iwasawa 813865
                 : ((*m_progressBarStatus)[i] == PBFrameFinished)
shun-iwasawa 813865
                     ? PBFinishedColor
shun-iwasawa 813865
                     : 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()));
shun-iwasawa 2055df
  p.drawImage(
shun-iwasawa 2055df
      QRect(PBColorMarginLeft, 0,
shun-iwasawa 2055df
            sliderRect.width() - PBColorMarginLeft - PBColorMarginRight,
shun-iwasawa 2055df
            height()),
shun-iwasawa 2055df
      PBOverlay,
shun-iwasawa 2055df
      QRect(PBColorMarginLeft, 0, overlayInnerWidth, PBOverlay.height()));
Shinya Kitaoka 120a6e
  p.drawImage(
Shinya Kitaoka 120a6e
      QRect(width() - PBColorMarginRight, 0, PBColorMarginRight, height()),
shun-iwasawa 2055df
      PBOverlay,
shun-iwasawa 2055df
      QRect(PBOverlay.width() - PBColorMarginRight, 0, PBColorMarginRight,
shun-iwasawa 2055df
            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());
shun-iwasawa 443318
  if (me->button() == Qt::MiddleButton)
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,
manongjohn 77dd6e
  eShowViewerControls  = 0x1000,
Jeremy Bullock 83d04e
  eShowSound           = 0x2000,
Jeremy Bullock 83d04e
  eShowLocator         = 0x4000,
shun-iwasawa 481b59
  eShowGainControls    = 0x8000,
shun-iwasawa 481b59
  eShowHowMany         = 0x10000
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
FlipConsole::FlipConsole(QVBoxLayout *mainLayout, std::vector<int> gadgetsMask,</int>
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)
shun-iwasawa 481b59
    , m_customizeMask((eShowHowMany - 1) & ~eShowGainControls)
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)
manongjohn 77dd6e
    , m_viewerSep(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)
shun-iwasawa 481b59
    , m_enableBlankFrameButton(0)
shun-iwasawa 481b59
    , m_prevGainStep(0)
shun-iwasawa 481b59
    , m_gainSep(nullptr)
shun-iwasawa 481b59
    , m_resetGainBtn(nullptr) {
shun-iwasawa 481b59
  QSettings flipSettings(getFlipSettingsPath(), QSettings::IniFormat);
shun-iwasawa 481b59
  flipSettings.beginGroup("ConsoleCustomizeMasks");
shun-iwasawa 481b59
  QString s = flipSettings.value(m_customizeId).toString();
Shinya Kitaoka 120a6e
  if (s != "") m_customizeMask = s.toUInt();
Shinya Kitaoka 120a6e
manongjohn 77dd6e
  if (m_gadgetsMask.size() == 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
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eFrames)) {
manongjohn 77dd6e
    createPlayToolBar(customWidget);
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
manongjohn 77dd6e
      if (hasButton(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
manongjohn 77dd6e
  if (hasButton(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
  applyCustomizeMask();
Shinya Kitaoka 120a6e
shun-iwasawa fe0983
  bool ret = connect(&m_playbackExecutor,
shun-iwasawa fe0983
                     SIGNAL(nextFrame(int, QElapsedTimer *, qint64)), this,
shun-iwasawa fe0983
                     SLOT(onNextFrame(int, QElapsedTimer *, qint64)),
shun-iwasawa fe0983
                     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
Jeremy Bullock 83d04e
void FlipConsole::showHidePlaybar(bool isShow) {
Jeremy Bullock 83d04e
  m_playToolBarContainer->setVisible(isShow);
Jeremy Bullock 83d04e
}
Jeremy Bullock 83d04e
Jeremy Bullock 83d04e
//-----------------------------------------------------------------------------
Jeremy Bullock 83d04e
Jeremy Bullock 83d04e
void FlipConsole::showHideFrameSlider(bool isShow) {
Jeremy Bullock 83d04e
  m_frameSliderFrame->setVisible(isShow);
Jeremy Bullock 83d04e
}
Jeremy Bullock 83d04e
Jeremy Bullock 83d04e
//-----------------------------------------------------------------------------
Jeremy Bullock 83d04e
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
Kite 521c84
#define LX 22
Kite 521c84
#define LY 22
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);
Kite 521c84
    setObjectName("flipDoubleButton");
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) {
Shinya Kitaoka 120a6e
  if (!m_playToolBar) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QList<qaction *=""> list = m_playToolBar->actions();</qaction>
Rozhuk Ivan 823a31
  for (size_t i = 0; i < list.size(); i++)
Shinya Kitaoka 120a6e
    if (list[i]->data().toUInt() == button) {
Rozhuk Ivan 823a31
      if (button == eSound) {
Rozhuk Ivan 823a31
        if (doShowHide) {
Shinya Kitaoka 120a6e
          m_soundSep->setVisible(enable);
Rozhuk Ivan 823a31
        } else {
Shinya Kitaoka 120a6e
          m_soundSep->setEnabled(enable);
Jeremy Bullock d03efb
        }
Rozhuk Ivan 823a31
      }
Shinya Kitaoka 120a6e
      if (button == eHisto) {
Rozhuk Ivan 823a31
        if (doShowHide) {
Shinya Kitaoka 120a6e
          m_histoSep->setVisible(enable && m_customizeMask & eShowHisto);
Rozhuk Ivan 823a31
        } else {
Shinya Kitaoka 120a6e
          m_histoSep->setEnabled(enable);
Jeremy Bullock d03efb
        }
Shinya Kitaoka 120a6e
      }
Rozhuk Ivan 823a31
      if (doShowHide) {
Shinya Kitaoka 120a6e
        list[i]->setVisible(enable);
Rozhuk Ivan 823a31
      } else {
Shinya Kitaoka 120a6e
        list[i]->setEnabled(enable);
Rozhuk Ivan 823a31
      }
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;
Rozhuk Ivan 823a31
  default:
Rozhuk Ivan 823a31
    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
shun-iwasawa fe0983
bool FlipConsole::drawBlanks(int from, int to, QElapsedTimer *timer,
shun-iwasawa fe0983
                             qint64 target) {
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) ||
shun-iwasawa 2055df
        (!m_reverse && m_currentFrame + m_step >
shun-iwasawa 2055df
                           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;
shun-iwasawa fe0983
    m_consoleOwner->onDrawFrame(from, m_settings, timer, target);
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
shun-iwasawa fe0983
void FlipConsole::onNextFrame(int fps, QElapsedTimer *timer,
shun-iwasawa fe0983
                              qint64 targetInstant) {
shun-iwasawa fe0983
  if (playbackExecutor().isAborted()) return;
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;
shun-iwasawa fe0983
    playNextFrame(timer, targetInstant);
Shinya Kitaoka 120a6e
    m_reverse = reverse;
Shinya Kitaoka 120a6e
  } else
shun-iwasawa fe0983
    playNextFrame(timer, targetInstant);
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
  }
shun-iwasawa 02ac7e
  if (m_stopAt > 0 && m_currentFrame >= m_stopAt &&
shun-iwasawa 02ac7e
      (m_isPlay || m_startAt == -1)) {
flurick c8ee00
    doButtonPressed(ePause);
shun-iwasawa 02ac7e
    m_stopAt  = -1;
shun-iwasawa 02ac7e
    m_startAt = -1;
flurick c8ee00
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa fe0983
void FlipConsole::playNextFrame(QElapsedTimer *timer, qint64 targetInstant) {
Shinya Kitaoka 120a6e
  int from = m_from, to = m_to;
flurick c8ee00
  if (m_markerFrom <= m_markerTo && m_stopAt == -1)
flurick c8ee00
    from = m_markerFrom, to = m_markerTo;
shun-iwasawa 02ac7e
  else if (m_stopAt > 0 && m_startAt > 0) {
shun-iwasawa 02ac7e
    from = m_startAt;
shun-iwasawa 02ac7e
    to   = m_stopAt;
shun-iwasawa 02ac7e
  }
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 {
shun-iwasawa fe0983
    if (drawBlanks(from, to, timer, targetInstant)) 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;
shun-iwasawa fe0983
  m_consoleOwner->onDrawFrame(m_currentFrame, m_settings, timer, targetInstant);
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;
shun-iwasawa 2055df
  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 "));
Kite 521c84
  if (m_fpsField) m_fpsField->setLineEditBackgroundColor(getFpsFieldColor());
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) {
Kite 521c84
  QAction *action1 =
Kite 521c84
      new QAction(createQIcon(iconStr1, true), tip1, m_playToolBar);
Kite 521c84
  QAction *action2 =
Kite 521c84
      new QAction(createQIcon(iconStr2, true), 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) {
Kite 521c84
  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(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
shun-iwasawa 481b59
  QSettings flipSettings(getFlipSettingsPath(), QSettings::IniFormat);
shun-iwasawa 481b59
  flipSettings.beginGroup("ConsoleCustomizeMasks");
shun-iwasawa 481b59
  flipSettings.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);
Jeremy Bullock 83d04e
  if (m_subcamSep) {
Jeremy Bullock 83d04e
    int count = m_gadgetsMask.size();
Jeremy Bullock 83d04e
    bool hasDefineLoadBox =
Jeremy Bullock 83d04e
        std::find(m_gadgetsMask.begin(), m_gadgetsMask.end(), eDefineLoadBox) ==
Jeremy Bullock 83d04e
        m_gadgetsMask.end();
shun-iwasawa 2055df
    bool hasUseLoadBox   = std::find(m_gadgetsMask.begin(), m_gadgetsMask.end(),
shun-iwasawa 813865
                                     eUseLoadBox) == m_gadgetsMask.end();
Jeremy Bullock 83d04e
    bool hasDefineSubCam = std::find(m_gadgetsMask.begin(), m_gadgetsMask.end(),
Jeremy Bullock 83d04e
                                     eDefineSubCamera) == m_gadgetsMask.end();
Jeremy Bullock 83d04e
    m_subcamSep->setVisible(
Jeremy Bullock 83d04e
        (hasDefineSubCam && m_customizeMask & eShowDefineSubCamera) ||
Jeremy Bullock 83d04e
        (hasDefineLoadBox && m_customizeMask & eShowDefineLoadBox) ||
Jeremy Bullock 83d04e
        (hasUseLoadBox && m_customizeMask & eShowUseLoadBox));
Jeremy Bullock 83d04e
  }
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
Jeremy Bullock 83d04e
  enableButton(eSound, m_customizeMask & eShowSound);
Jeremy Bullock 83d04e
  enableButton(eLocator, m_customizeMask & eShowLocator);
Jeremy Bullock 83d04e
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
manongjohn 77dd6e
  enableButton(eZoomIn, m_customizeMask & eShowViewerControls);
manongjohn 77dd6e
  enableButton(eZoomOut, m_customizeMask & eShowViewerControls);
manongjohn 77dd6e
  enableButton(eFlipHorizontal, m_customizeMask & eShowViewerControls);
manongjohn 77dd6e
  enableButton(eFlipVertical, m_customizeMask & eShowViewerControls);
manongjohn 77dd6e
  enableButton(eResetView, m_customizeMask & eShowViewerControls);
manongjohn 77dd6e
  if (m_viewerSep)
manongjohn 77dd6e
    m_viewerSep->setVisible(m_customizeMask & eShowViewerControls);
manongjohn 77dd6e
shun-iwasawa 481b59
  if (m_resetGainBtn) {
shun-iwasawa 481b59
    enableButton(eDecreaseGain, m_customizeMask & eShowGainControls);
shun-iwasawa 481b59
    enableButton(eResetGain, m_customizeMask & eShowGainControls);
shun-iwasawa 481b59
    enableButton(eIncreaseGain, m_customizeMask & eShowGainControls);
shun-iwasawa 481b59
    m_gainSep->setVisible(m_customizeMask & eShowGainControls);
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FlipConsole::createCustomizeMenu(bool withCustomWidget) {
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eCustomize)) {
Kite 521c84
    QIcon icon          = createQIcon("menu");
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
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eSave))
manongjohn 77dd6e
      addMenuItem(eShowSave, tr("Save"), menu);
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eSaveImg) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eCompare))
Shinya Kitaoka 120a6e
      addMenuItem(eShowCompare, tr("Snapshot"), menu);
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eDefineSubCamera))
Shinya Kitaoka 120a6e
      addMenuItem(eShowDefineSubCamera, tr("Define Sub-camera"), menu);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eDefineLoadBox))
Shinya Kitaoka 120a6e
      addMenuItem(eShowDefineLoadBox, tr("Define Loading Box"), menu);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eUseLoadBox))
Shinya Kitaoka 120a6e
      addMenuItem(eShowUseLoadBox, tr("Use Loading Box"), menu);
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eWhiteBg) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eBlackBg) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eCheckBg))
Shinya Kitaoka 120a6e
      addMenuItem(eShowBg, tr("Background Colors"), menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    addMenuItem(eShowVcr, tr("Playback Controls"), menu);
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eRed) || hasButton(m_gadgetsMask, eGreen) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eBlue) || hasButton(m_gadgetsMask, eMatte))
Shinya Kitaoka 120a6e
      addMenuItem(eShowcolorFilter, tr("Color Channels"), menu);
Toshihiro Shimizu 890ddd
Jeremy Bullock 83d04e
    if (hasButton(m_gadgetsMask, eSound))
Jeremy Bullock 83d04e
      addMenuItem(eShowSound, tr("Sound"), menu);
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eHisto))
manongjohn 77dd6e
      addMenuItem(eShowHisto, tr("Histogram"), menu);
Toshihiro Shimizu 890ddd
Jeremy Bullock 83d04e
    if (hasButton(m_gadgetsMask, eLocator))
Jeremy Bullock 83d04e
      addMenuItem(eShowLocator, tr("Locator"), menu);
Jeremy Bullock 83d04e
Jeremy Bullock 83d04e
    if (withCustomWidget) addMenuItem(eShowCustom, tr("Set Key"), menu);
Jeremy Bullock 83d04e
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eFilledRaster))
Shinya Kitaoka 120a6e
      addMenuItem(eFilledRaster, tr("Display Areas as Filled"), menu);
Toshihiro Shimizu 890ddd
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eZoomIn) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eZoomOut) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eFlipHorizontal) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eFlipVertical) ||
manongjohn 77dd6e
        hasButton(m_gadgetsMask, eResetView))
manongjohn 77dd6e
      addMenuItem(eShowViewerControls, tr("Viewer Controls"), menu);
manongjohn 77dd6e
Jeremy Bullock 83d04e
    if (hasButton(m_gadgetsMask, eRate))
Jeremy Bullock 83d04e
      addMenuItem(eShowFramerate, tr("Framerate"), menu);
Jeremy Bullock 83d04e
shun-iwasawa 481b59
    if (hasButton(m_gadgetsMask, eDecreaseGain))
shun-iwasawa 481b59
      addMenuItem(eShowGainControls, tr("Gain Controls"), menu);
shun-iwasawa 481b59
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
manongjohn 77dd6e
void FlipConsole::createPlayToolBar(QWidget *customWidget) {
manongjohn 77dd6e
  bool ret              = true;
manongjohn 77dd6e
  bool withCustomWidget = customWidget != 0;
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");
Kite 521c84
  m_playToolBar->setIconSize(QSize(20, 20));
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
manongjohn 77dd6e
  if (hasButton(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;
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eSaveImg)) {
Shinya Kitaoka 120a6e
    createButton(eSaveImg, "snapshot", tr("&Snapshot"), false);
Shinya Kitaoka 120a6e
    separator = true;
Shinya Kitaoka 120a6e
  }
manongjohn 77dd6e
  if (hasButton(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;
manongjohn 77dd6e
  if (hasButton(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
  }
manongjohn 77dd6e
  if (hasButton(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
  }
manongjohn 77dd6e
  if (hasButton(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);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eWhiteBg))
Shinya Kitaoka 120a6e
    createOnOffButton(eWhiteBg, "preview_white", tr("&White Background"),
Shinya Kitaoka 120a6e
                      group);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eBlackBg))
Shinya Kitaoka 120a6e
    createOnOffButton(eBlackBg, "preview_black", tr("&Black Background"),
Shinya Kitaoka 120a6e
                      group);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eCheckBg))
Shinya Kitaoka 120a6e
    createOnOffButton(eCheckBg, "preview_checkboard",
Shinya Kitaoka 120a6e
                      tr("&Checkered Background"), group);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eWhiteBg))
manongjohn 77dd6e
    m_bgSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // VCR buttons
Shinya Kitaoka 120a6e
  QActionGroup *playGroup = new QActionGroup(m_playToolBar);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eFirst))
Shinya Kitaoka 120a6e
    createButton(eFirst, "framefirst", tr("&First Frame"), false);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, ePrev))
Shinya Kitaoka 120a6e
    createButton(ePrev, "frameprev", tr("&Previous Frame"), false);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, ePause))
Shinya Kitaoka 120a6e
    createCheckedButtonWithBorderImage(ePause, "pause", tr("Pause"), true,
Shinya Kitaoka 120a6e
                                       playGroup, "A_Flip_Pause");
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, ePlay))
Shinya Kitaoka 120a6e
    createCheckedButtonWithBorderImage(ePlay, "play", tr("Play"), true,
Shinya Kitaoka 120a6e
                                       playGroup, "A_Flip_Play");
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eLoop))
Shinya Kitaoka 120a6e
    createCheckedButtonWithBorderImage(eLoop, "loop", tr("Loop"), true,
Shinya Kitaoka 120a6e
                                       playGroup, "A_Flip_Loop");
Shinya Kitaoka 120a6e
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eNext))
Kite 521c84
    createButton(eNext, "framenext", tr("&Next Frame"), false);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eLast))
Shinya Kitaoka 120a6e
    createButton(eLast, "framelast", tr("&Last Frame"), false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // separator
manongjohn 77dd6e
  if (hasButton(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);
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eRed) && !hasButton(m_gadgetsMask, eGRed))
Shinya Kitaoka 120a6e
    createButton(eRed, "channelred", tr("Red Channel"), true);
manongjohn 77dd6e
  else if (hasButton(m_gadgetsMask, eRed) && hasButton(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
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eGreen) && !hasButton(m_gadgetsMask, eGGreen))
Shinya Kitaoka 120a6e
    createButton(eGreen, "channelgreen", tr("Green Channel"), true);
manongjohn 77dd6e
  else if (hasButton(m_gadgetsMask, eGreen) &&
manongjohn 77dd6e
           hasButton(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
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eBlue) && !hasButton(m_gadgetsMask, eGBlue))
Shinya Kitaoka 120a6e
    createButton(eBlue, "channelblue", tr("Blue Channel"), true);
manongjohn 77dd6e
  else if (hasButton(m_gadgetsMask, eBlue) && hasButton(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
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eMatte))
Shinya Kitaoka 120a6e
    createButton(eMatte, "channelmatte", tr("Alpha Channel"), true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // separator
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eRed) || hasButton(m_gadgetsMask, eGRed))
Shinya Kitaoka 120a6e
    m_colorFilterSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
shun_iwasawa db5f54
  // Sound & Histogram & Locator
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eSound) || hasButton(m_gadgetsMask, eHisto) ||
manongjohn 77dd6e
      hasButton(m_gadgetsMask, eLocator)) {
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eSound)) {
Shinya Kitaoka 120a6e
      createButton(eSound, "sound", tr("&Soundtrack "), true);
Shinya Kitaoka 120a6e
      m_soundSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
    }
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eHisto))
Shinya Kitaoka 120a6e
      createButton(eHisto, "histograms", tr("&Histogram"), false);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eLocator))
shun_iwasawa db5f54
      createButton(eLocator, "locator", tr("&Locator"), false);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eHisto) || hasButton(m_gadgetsMask, eLocator))
Shinya Kitaoka 120a6e
      m_histoSep = m_playToolBar->addSeparator();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
manongjohn 77dd6e
  if (hasButton(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
manongjohn 77dd6e
  if (withCustomWidget) {
manongjohn 77dd6e
    m_customAction = m_playToolBar->addWidget(customWidget);
manongjohn 77dd6e
    m_customSep    = m_playToolBar->addSeparator();
manongjohn 77dd6e
  }
manongjohn 77dd6e
manongjohn 77dd6e
  if (hasButton(m_gadgetsMask, eZoomIn) || hasButton(m_gadgetsMask, eZoomOut) ||
manongjohn 77dd6e
      hasButton(m_gadgetsMask, eFlipHorizontal) ||
manongjohn 77dd6e
      hasButton(m_gadgetsMask, eFlipVertical) ||
manongjohn 77dd6e
      hasButton(m_gadgetsMask, eResetView)) {
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eZoomIn))
manongjohn 77dd6e
      createButton(eZoomIn, "zoomin", tr("&Zoom In"), false);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eZoomOut))
manongjohn 77dd6e
      createButton(eZoomOut, "zoomout", tr("&Zoom Out"), false);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eFlipHorizontal))
Kite 521c84
      createButton(eFlipHorizontal, "fliphoriz", tr("&Flip Horizontally"), 0);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eFlipVertical))
Kite 521c84
      createButton(eFlipVertical, "flipvert", tr("&Flip Vertically"), 0);
manongjohn 77dd6e
    if (hasButton(m_gadgetsMask, eResetView))
manongjohn 77dd6e
      createButton(eResetView, "reset", tr("&Reset View"), false);
manongjohn 77dd6e
    m_viewerSep = m_playToolBar->addSeparator();
manongjohn 77dd6e
  }
manongjohn 77dd6e
shun-iwasawa 481b59
  if (hasButton(m_gadgetsMask, eDecreaseGain)) {
shun-iwasawa 481b59
    createButton(eDecreaseGain, "prevkey",
shun-iwasawa 481b59
                 tr("&Reduce gain 1/2 stop (divide by sqrt(2))"), false);
shun-iwasawa 481b59
    createButton(eResetGain, "", "f/8", false);
shun-iwasawa 481b59
    m_resetGainBtn = dynamic_cast<qtoolbutton *="">(</qtoolbutton>
shun-iwasawa 481b59
        m_playToolBar->widgetForAction(m_actions[eResetGain]));
shun-iwasawa 481b59
    m_resetGainBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
shun-iwasawa 481b59
    m_resetGainBtn->setToolTip(
shun-iwasawa 481b59
        tr("Toggle gain between 1 and the previous setting.\n"
shun-iwasawa 481b59
           "Gain is shown as an f-stop and the \"neutral\" or 1.0 gain f-stop "
shun-iwasawa 481b59
           "is f/8."));
shun-iwasawa 481b59
    m_resetGainBtn->setFixedWidth(36);
shun-iwasawa 481b59
    createButton(eIncreaseGain, "nextkey",
shun-iwasawa 481b59
                 tr("&Increase gain 1/2 stop (multiply by sqrt(2))"), false);
shun-iwasawa 481b59
    m_gainSep = m_playToolBar->addSeparator();
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
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
//-----------------------------------------------------------------------------
luz paz 6454c4
/*! call consoleOwner->onDrawFrame() instead of emitting drawFrame signal
shun-iwasawa ece48f
 */
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 d03efb
  } else {
shun-iwasawa 2055df
    // Sync playback state among all viewers & combo viewers.
shun-iwasawa 2055df
    // Note that the property "m_isLinkable" is used for distinguishing the
shun-iwasawa 2055df
    // owner between (viewer / combo viewer) and (flipbook / color model).
shun-iwasawa 2055df
    if (!m_isLinkable &&
shun-iwasawa 2055df
        (button == FlipConsole::ePlay || button == FlipConsole::eLoop)) {
Jeremy Bullock d03efb
      bool stoppedOther = false;
shun-iwasawa 2055df
      for (auto playingConsole : m_visibleConsoles) {
shun-iwasawa 2055df
        if (playingConsole == this || playingConsole->isLinkable()) continue;
Jeremy Bullock d03efb
        if (playingConsole->m_playbackExecutor.isRunning()) {
Jeremy Bullock d03efb
          playingConsole->doButtonPressed(ePause);
Jeremy Bullock d03efb
          playingConsole->setChecked(ePlay, false);
Jeremy Bullock d03efb
          playingConsole->setChecked(eLoop, false);
Jeremy Bullock d03efb
          playingConsole->setChecked(ePause, true);
Jeremy Bullock d03efb
          stoppedOther = true;
shun-iwasawa 481b59
          m_stopAt     = -1;
shun-iwasawa 02ac7e
          m_startAt    = -1;
Jeremy Bullock d03efb
        }
Jeremy Bullock d03efb
      }
Jeremy Bullock d03efb
      if (stoppedOther) {
Jeremy Bullock d03efb
        setChecked(ePlay, false);
Jeremy Bullock d03efb
        setChecked(eLoop, false);
Jeremy Bullock d03efb
        setChecked(ePause, true);
Jeremy Bullock d03efb
        return;
Jeremy Bullock d03efb
      }
Jeremy Bullock d03efb
    }
Jeremy Bullock d03efb
Jeremy Bullock 0cb7c2
    doButtonPressed(button);
Jeremy Bullock d03efb
  }
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) {
shun-iwasawa ece48f
  FlipConsole *console = this;
Jeremy Bullock 0cb7c2
  if (m_visibleConsoles.indexOf(this) < 0 && m_visibleConsoles.size() > 0) {
shun-iwasawa ece48f
    console = m_visibleConsoles.at(0);
Jeremy Bullock 0cb7c2
    console->makeCurrent();
Jeremy Bullock 0cb7c2
  }
shun-iwasawa ece48f
  if (console->m_buttons.contains(buttonId) &&
shun-iwasawa ece48f
      console->m_buttons[buttonId]->isEnabled())
shun-iwasawa ece48f
    console->m_buttons[buttonId]->click();
shun-iwasawa ece48f
  else if (console->m_actions.contains(buttonId) &&
shun-iwasawa ece48f
           console->m_actions[buttonId]->isEnabled())
shun-iwasawa ece48f
    console->m_actions[buttonId]->trigger();
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 &&
shun-iwasawa 481b59
      m_frameHandle->isEditingScene() && m_stopAt == -1)
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));
Kite 521c84
      if (m_fpsField)
Kite 521c84
        m_fpsField->setLineEditBackgroundColor(getFpsFieldColor());
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) {
Kite 521c84
      // if the play button pressed at the end frame, then go back to the
Kite 521c84
      // start 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
shun-iwasawa 2055df
        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:
Jeremy Bullock d03efb
    if (!m_playbackExecutor.isRunning() && !m_isLinkedPlaying) {
shun-iwasawa 2055df
      // Sync playback state among all viewers & combo viewers.
shun-iwasawa 2055df
      // Note that the property "m_isLinkable" is used for distinguishing the
shun-iwasawa 2055df
      // owner between (viewer / combo viewer) and (flipbook / color model).
shun-iwasawa 2055df
      if (!m_isLinkable) {
shun-iwasawa 2055df
        for (auto playingConsole : m_visibleConsoles) {
shun-iwasawa 2055df
          if (playingConsole->isLinkable()) continue;
shun-iwasawa 2055df
          if (playingConsole->m_playbackExecutor.isRunning())
shun-iwasawa 2055df
            playingConsole->doButtonPressed(button);
shun-iwasawa 2055df
          playingConsole->setChecked(ePlay, false);
shun-iwasawa 2055df
          playingConsole->setChecked(eLoop, false);
shun-iwasawa 2055df
          playingConsole->setChecked(ePause, true);
shun-iwasawa 2055df
        }
Jeremy Bullock d03efb
      }
shun-iwasawa 02ac7e
      m_stopAt  = -1;
shun-iwasawa 02ac7e
      m_startAt = -1;
Jeremy Bullock d03efb
      return;
Jeremy Bullock d03efb
    }
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
flurick c8ee00
    m_stopAt       = -1;
shun-iwasawa 02ac7e
    m_startAt      = -1;
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 "));
Kite 521c84
    if (m_fpsField) m_fpsField->setLineEditBackgroundColor(getFpsFieldColor());
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))
shun-iwasawa 2055df
      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
Kite 1e6f90
  case eFlipHorizontal:
Kite 1e6f90
  case eFlipVertical:
Kite 1e6f90
  case eZoomIn:
Kite 1e6f90
  case eZoomOut:
Kite 1e6f90
  case eResetView:
Kite 1e6f90
    return;
Kite 1e6f90
shun-iwasawa 481b59
  case eDecreaseGain:
shun-iwasawa 481b59
    adjustGain(false);
shun-iwasawa 481b59
    break;
shun-iwasawa 481b59
  case eIncreaseGain:
shun-iwasawa 481b59
    adjustGain(true);
shun-iwasawa 481b59
    break;
shun-iwasawa 481b59
  case eResetGain:
shun-iwasawa 481b59
    resetGain();
shun-iwasawa 481b59
    break;
shun-iwasawa 481b59
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
flurick c8ee00
void FlipConsole::setStopAt(int frame) { m_stopAt = frame; }
flurick c8ee00
flurick c8ee00
//--------------------------------------------------------------------
flurick c8ee00
shun-iwasawa 02ac7e
void FlipConsole::setStartAt(int frame) { m_startAt = frame; }
shun-iwasawa 02ac7e
shun-iwasawa 02ac7e
//--------------------------------------------------------------------
shun-iwasawa 02ac7e
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");
shun-iwasawa 813865
shun-iwasawa 813865
    m_buttons[eBlankFrames] = m_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
shun-iwasawa 443318
  m_fpsLabel->setMinimumWidth(
shun-iwasawa 443318
      m_fpsLabel->fontMetrics().horizontalAdvance("_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() ||
Kite 521c84
      m_isLinkedPlaying)  // if in playing mode, the slider and the frame
Kite 521c84
                          // field 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
Kite 521c84
      // Set text color based on luminescence of blankColor color
Shinya Kitaoka 120a6e
      QString textColor;
Kite 521c84
      double luminescence =
Kite 521c84
          ((0.299 * (int)m_blankColor.r) + (0.587 * (int)m_blankColor.g) +
Kite 521c84
           (0.114 * (int)m_blankColor.b)) /
Kite 521c84
          255;
Kite 521c84
      if (luminescence > 0.5)
Kite 521c84
        textColor = QString("black");
Kite 521c84
      else
Kite 521c84
        textColor = QString("white");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      m_enableBlankFrameButton->setStyleSheet(
Kite 521c84
          QString("#enableBlankFrameButton:checked { \
Shinya Kitaoka 473e70
              background-color: rgb(%1,%2,%3); \
Kite 521c84
              color: %4;}")
Shinya Kitaoka 120a6e
              .arg(m_blankColor.r)
Shinya Kitaoka 120a6e
              .arg(m_blankColor.g)
Shinya Kitaoka 120a6e
              .arg(m_blankColor.b)
Kite 521c84
              .arg(textColor));
Shinya Kitaoka 120a6e
      m_enableBlankFrameButton->update();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
//--------------------------------------------------------------------
shun-iwasawa 481b59
shun-iwasawa 481b59
void FlipConsole::adjustGain(bool increase) {
shun-iwasawa 481b59
  if (increase && m_settings.m_gainStep < 12)
shun-iwasawa 481b59
    m_settings.m_gainStep++;
shun-iwasawa 481b59
  else if (!increase && m_settings.m_gainStep > -12)
shun-iwasawa 481b59
    m_settings.m_gainStep--;
shun-iwasawa 481b59
shun-iwasawa 481b59
  // enable / disable buttons (-6 to +6 steps range)
shun-iwasawa 481b59
  enableButton(eDecreaseGain, m_settings.m_gainStep > -12, false);
shun-iwasawa 481b59
  enableButton(eIncreaseGain, m_settings.m_gainStep < 12, false);
shun-iwasawa 481b59
shun-iwasawa 481b59
  if (m_settings.m_gainStep != 0) m_prevGainStep = m_settings.m_gainStep;
shun-iwasawa 481b59
shun-iwasawa 481b59
  // update label
shun-iwasawa 481b59
  double fNumber   = std::pow(2.0, 3.0 - (double)m_settings.m_gainStep * 0.25);
shun-iwasawa 481b59
  QString labelStr = QString("f/%1").arg(QString::number(fNumber, 'g', 2));
shun-iwasawa 481b59
  double gain      = std::pow(2.0, (double)m_settings.m_gainStep * 0.5);
shun-iwasawa 481b59
  m_resetGainBtn->setText(labelStr);
shun-iwasawa 481b59
  m_resetGainBtn->setToolTip(labelStr + tr(" (gain %1)").arg(gain));
shun-iwasawa 481b59
}
shun-iwasawa 481b59
shun-iwasawa 481b59
void FlipConsole::resetGain(bool forceInit) {
shun-iwasawa 481b59
  if (forceInit) m_prevGainStep = 0;
shun-iwasawa 481b59
shun-iwasawa 481b59
  if (m_settings.m_gainStep == 0)
shun-iwasawa 481b59
    m_settings.m_gainStep = m_prevGainStep;
shun-iwasawa 481b59
  else
shun-iwasawa 481b59
    m_settings.m_gainStep = 0;
shun-iwasawa 481b59
shun-iwasawa 481b59
  // update label
shun-iwasawa 481b59
  double fNumber   = std::pow(2.0, 3.0 - (double)m_settings.m_gainStep * 0.25);
shun-iwasawa 481b59
  QString labelStr = QString("f/%1").arg(QString::number(fNumber, 'g', 2));
shun-iwasawa 481b59
  double gain      = std::pow(2.0, (double)m_settings.m_gainStep * 0.5);
shun-iwasawa 481b59
  m_resetGainBtn->setText(labelStr);
shun-iwasawa 481b59
  m_resetGainBtn->setToolTip(labelStr + tr(" (gain %1)").arg(gain));
shun-iwasawa 481b59
}
shun-iwasawa 481b59
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
//--------------------------------------------------------------------