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