Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/camerasettingswidget.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/doublefield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/intfield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/checkbox.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/tselectionhandle.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjecttree.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tfilepath_io.h"
Toshihiro Shimizu 890ddd
#include "tutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qgridlayout></qgridlayout>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qgridlayout></qgridlayout>
Toshihiro Shimizu 890ddd
#include <qradiobutton></qradiobutton>
Toshihiro Shimizu 890ddd
#include <qbuttongroup></qbuttongroup>
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
#include <qcombobox></qcombobox>
Toshihiro Shimizu 890ddd
#include <qmessagebox></qmessagebox>
Toshihiro Shimizu 890ddd
#include <qlist></qlist>
Toshihiro Shimizu 890ddd
#include <qstringlist></qstringlist>
Toshihiro Shimizu 890ddd
#include <qregexp></qregexp>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qtextstream></qtextstream>
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#include <qstringlist></qstringlist>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// the first value in the preset list
Toshihiro Shimizu 890ddd
const QString custom = QObject::tr("<custom>");</custom>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---小数の余分なゼロを消す---*/
Toshihiro Shimizu 890ddd
QString removeZeros(QString srcStr)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!srcStr.contains('.'))
Toshihiro Shimizu 890ddd
		return srcStr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = srcStr.length() - 1; i >= 0; i--) {
Toshihiro Shimizu 890ddd
		if (srcStr.at(i) == '0')
Toshihiro Shimizu 890ddd
			srcStr.chop(1);
Toshihiro Shimizu 890ddd
		else if (srcStr.at(i) == '.') {
Toshihiro Shimizu 890ddd
			srcStr.chop(1);
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return srcStr;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QValidator::State SimpleExpValidator::validate(QString &input, int &pos) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*---使用可能な文字---*/
Toshihiro Shimizu 890ddd
	QString validChars("0123456789/.");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int slashCount = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < input.length(); i++) {
Toshihiro Shimizu 890ddd
		/*--- まず、使用不可能な文字が含まれている場合はInvalid ---*/
Toshihiro Shimizu 890ddd
		if (!validChars.contains(input.at(i)))
Toshihiro Shimizu 890ddd
			return Invalid;
Toshihiro Shimizu 890ddd
		if (input.at(i) == '/')
Toshihiro Shimizu 890ddd
			slashCount++;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*--- 中身は普通の数字。Doubleに変換可能ならOK ---*/
Toshihiro Shimizu 890ddd
	if (slashCount == 0) {
Toshihiro Shimizu 890ddd
		bool ok;
Toshihiro Shimizu 890ddd
		double tmp = input.toDouble(&ok);
Toshihiro Shimizu 890ddd
		if (ok)
Toshihiro Shimizu 890ddd
			return (tmp > 0) ? Acceptable : Intermediate;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return Intermediate;
Toshihiro Shimizu 890ddd
	} else if (slashCount >= 2) {
Toshihiro Shimizu 890ddd
		return Intermediate;
Toshihiro Shimizu 890ddd
	} else //slashCount == 1
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (input.at(0) == '/' || input.at(input.length() - 1) == '/')
Toshihiro Shimizu 890ddd
			return Intermediate;
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			QStringList strList = input.split('/');
Toshihiro Shimizu 890ddd
			/*--- スラッシュの左右でDoubleに変換できるかチェック。できないとIntermediate。 ---*/
Toshihiro Shimizu 890ddd
			for (int i = 0; i < strList.size(); i++) {
Toshihiro Shimizu 890ddd
				QString tmpStr = strList.at(i);
Toshihiro Shimizu 890ddd
				bool ok;
Toshihiro Shimizu 890ddd
				double tmp = tmpStr.toDouble(&ok);
Toshihiro Shimizu 890ddd
				if (!ok)
Toshihiro Shimizu 890ddd
					return Intermediate;
Toshihiro Shimizu 890ddd
				if (ok && tmp <= 0)
Toshihiro Shimizu 890ddd
					return Intermediate;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/*--- 左右でDoubleに変換できたのでOK ---*/
Toshihiro Shimizu 890ddd
			return Acceptable;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SimpleExpField::SimpleExpField(QWidget *parent)
Toshihiro Shimizu 890ddd
	: QLineEdit(parent)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_validator = new SimpleExpValidator(this);
Toshihiro Shimizu 890ddd
	setValidator(m_validator);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*--- 普通に値を入れる ---*/
Toshihiro Shimizu 890ddd
void SimpleExpField::setValue(double value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	str.setNum(value);
Toshihiro Shimizu 890ddd
	setText(str);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*--- A/R用 valueがw/hに近ければ "w/h" という文字列を入れる ---*/
Toshihiro Shimizu 890ddd
void SimpleExpField::setValue(double value, int w, int h)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(value, (double)w / (double)h, 1e-5))
Toshihiro Shimizu 890ddd
		str = QString().setNum(w) + "/" + QString().setNum(h);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		str.setNum(value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setText(str);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double SimpleExpField::getValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int slashCount = text().count('/');
Toshihiro Shimizu 890ddd
	if (slashCount == 0)
Toshihiro Shimizu 890ddd
		return text().toDouble();
Toshihiro Shimizu 890ddd
	else if (slashCount == 1) {
Toshihiro Shimizu 890ddd
		QStringList strList = text().split('/');
Toshihiro Shimizu 890ddd
		return strList.at(0).toDouble() / strList.at(1).toDouble();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	std::cout << "more than one slash!" << std::endl;
Toshihiro Shimizu 890ddd
	return 0.1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SimpleExpField::focusInEvent(QFocusEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_previousValue = text();
Toshihiro Shimizu 890ddd
	QLineEdit::focusInEvent(event);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SimpleExpField::focusOutEvent(QFocusEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int dummy;
Toshihiro Shimizu 890ddd
	QString tmp = text();
Toshihiro Shimizu 890ddd
	if (validator()->validate(tmp, dummy) != QValidator::Acceptable)
Toshihiro Shimizu 890ddd
		setText(m_previousValue);
Toshihiro Shimizu 890ddd
	QLineEdit::focusOutEvent(event);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
CameraSettingsWidget::CameraSettingsWidget(bool forCleanup)
Toshihiro Shimizu 890ddd
	: m_forCleanup(forCleanup), m_arValue(0), m_presetListFile(""), m_currentLevel(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_xPrev = new QRadioButton();
Toshihiro Shimizu 890ddd
	m_yPrev = new QRadioButton();
Toshihiro Shimizu 890ddd
	m_arPrev = new QRadioButton();
Toshihiro Shimizu 890ddd
	m_inchPrev = new QRadioButton();
Toshihiro Shimizu 890ddd
	m_dotPrev = new QRadioButton();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_lxFld = new MeasuredDoubleLineEdit();
Toshihiro Shimizu 890ddd
	m_lyFld = new MeasuredDoubleLineEdit();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_arFld = new SimpleExpField(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka bb1d04
	m_xResFld = new DVGui::IntLineEdit();
Shinya Kitaoka bb1d04
	m_yResFld = new DVGui::IntLineEdit();
Toshihiro Shimizu 890ddd
	m_xDpiFld = new DoubleLineEdit();
Toshihiro Shimizu 890ddd
	m_yDpiFld = new DoubleLineEdit();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_fspChk = new QPushButton("");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_useLevelSettingsBtn = new QPushButton(tr("Use Current Level Settings"));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_presetListOm = new QComboBox();
Toshihiro Shimizu 890ddd
	m_addPresetBtn = new QPushButton(tr("Add"));
Toshihiro Shimizu 890ddd
	m_removePresetBtn = new QPushButton(tr("Remove"));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//----
Toshihiro Shimizu 890ddd
	m_useLevelSettingsBtn->setEnabled(false);
Toshihiro Shimizu 890ddd
	m_useLevelSettingsBtn->setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
	m_lxFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_lyFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_arFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_xResFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_yResFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_xDpiFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_yDpiFld->installEventFilter(this);
Toshihiro Shimizu 890ddd
	m_xResFld->setMinimumWidth(0);
Toshihiro Shimizu 890ddd
	m_xResFld->setMaximumWidth(QWIDGETSIZE_MAX);
Toshihiro Shimizu 890ddd
	m_yResFld->setMinimumWidth(0);
Toshihiro Shimizu 890ddd
	m_yResFld->setMaximumWidth(QWIDGETSIZE_MAX);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*--- 表示精度を4桁にする ---*/
Toshihiro Shimizu 890ddd
	m_lxFld->setDecimals(4);
Toshihiro Shimizu 890ddd
	m_lyFld->setDecimals(4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_lxFld->setMeasure("camera.lx");
Toshihiro Shimizu 890ddd
	m_lyFld->setMeasure("camera.ly");
Toshihiro Shimizu 890ddd
	m_lxFld->setRange(numeric_limits<double>::epsilon(), numeric_limits<double>::infinity());</double></double>
Toshihiro Shimizu 890ddd
	m_lyFld->setRange(numeric_limits<double>::epsilon(), numeric_limits<double>::infinity());</double></double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_xResFld->setRange(1, 10000000);
Toshihiro Shimizu 890ddd
	m_yResFld->setRange(1, 10000000);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_xDpiFld->setRange(1, numeric_limits<double>::infinity());</double>
Toshihiro Shimizu 890ddd
	m_yDpiFld->setRange(1, numeric_limits<double>::infinity());</double>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_fspChk->setFixedSize(20, 20);
Toshihiro Shimizu 890ddd
	m_fspChk->setCheckable(true);
Toshihiro Shimizu 890ddd
	m_fspChk->setChecked(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_fspChk->setToolTip(tr("Force Squared Pixel"));
Toshihiro Shimizu 890ddd
	m_fspChk->setObjectName("ForceSquaredPixelButton");
Toshihiro Shimizu 890ddd
	m_addPresetBtn->setObjectName("PushButton_NoPadding");
Toshihiro Shimizu 890ddd
	m_removePresetBtn->setObjectName("PushButton_NoPadding");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_inchPrev->setFixedSize(11, 21);
Toshihiro Shimizu 890ddd
	m_dotPrev->setFixedSize(11, 21);
Toshihiro Shimizu 890ddd
	m_inchPrev->setObjectName("CameraSettingsRadioButton_Small");
Toshihiro Shimizu 890ddd
	m_dotPrev->setObjectName("CameraSettingsRadioButton_Small");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_xPrev->setObjectName("CameraSettingsRadioButton");
Toshihiro Shimizu 890ddd
	m_yPrev->setObjectName("CameraSettingsRadioButton");
Toshihiro Shimizu 890ddd
	m_arPrev->setObjectName("CameraSettingsRadioButton");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// radio buttons groups
Toshihiro Shimizu 890ddd
	QButtonGroup *group;
Toshihiro Shimizu 890ddd
	group = new QButtonGroup;
Toshihiro Shimizu 890ddd
	group->addButton(m_xPrev);
Toshihiro Shimizu 890ddd
	group->addButton(m_yPrev);
Toshihiro Shimizu 890ddd
	group->addButton(m_arPrev);
Toshihiro Shimizu 890ddd
	group = new QButtonGroup;
Toshihiro Shimizu 890ddd
	group->addButton(m_inchPrev);
Toshihiro Shimizu 890ddd
	group->addButton(m_dotPrev);
Toshihiro Shimizu 890ddd
	m_arPrev->setChecked(true);
Toshihiro Shimizu 890ddd
	m_dotPrev->setChecked(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//------ layout
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QVBoxLayout *mainLay = new QVBoxLayout();
Toshihiro Shimizu 890ddd
	mainLay->setSpacing(3);
Toshihiro Shimizu 890ddd
	mainLay->setMargin(3);
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		QGridLayout *gridLay = new QGridLayout();
Toshihiro Shimizu 890ddd
		gridLay->setHorizontalSpacing(2);
Toshihiro Shimizu 890ddd
		gridLay->setVerticalSpacing(3);
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_xPrev, 0, 2, Qt::AlignCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_yPrev, 0, 4, Qt::AlignCenter);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_inchPrev, 1, 0, Qt::AlignRight | Qt::AlignVCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(new QLabel("Inch"), 1, 1, Qt::AlignRight | Qt::AlignVCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_lxFld, 1, 2);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(new QLabel("x"), 1, 3, Qt::AlignCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_lyFld, 1, 4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_arPrev, 2, 2, Qt::AlignRight | Qt::AlignVCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(new QLabel("A/R"), 2, 3, Qt::AlignCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_arFld, 2, 4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_dotPrev, 3, 0, Qt::AlignRight | Qt::AlignVCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(new QLabel("Pixel"), 3, 1, Qt::AlignRight | Qt::AlignVCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_xResFld, 3, 2);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(new QLabel("x"), 3, 3, Qt::AlignCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_yResFld, 3, 4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			gridLay->addWidget(new QLabel("DPI"), 4, 1, Qt::AlignRight | Qt::AlignVCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_xDpiFld, 4, 2);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_fspChk, 4, 3, Qt::AlignCenter);
Toshihiro Shimizu 890ddd
			gridLay->addWidget(m_yDpiFld, 4, 4);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		gridLay->setColumnStretch(0, 0);
Toshihiro Shimizu 890ddd
		gridLay->setColumnStretch(1, 0);
Toshihiro Shimizu 890ddd
		gridLay->setColumnStretch(2, 1);
Toshihiro Shimizu 890ddd
		gridLay->setColumnStretch(3, 0);
Toshihiro Shimizu 890ddd
		gridLay->setColumnStretch(4, 1);
Toshihiro Shimizu 890ddd
		mainLay->addLayout(gridLay);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		mainLay->addWidget(m_useLevelSettingsBtn);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QHBoxLayout *resListLay = new QHBoxLayout();
Toshihiro Shimizu 890ddd
		resListLay->setSpacing(3);
Toshihiro Shimizu 890ddd
		resListLay->setMargin(1);
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			resListLay->addWidget(m_presetListOm, 1);
Toshihiro Shimizu 890ddd
			resListLay->addWidget(m_addPresetBtn, 0);
Toshihiro Shimizu 890ddd
			resListLay->addWidget(m_removePresetBtn, 0);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		mainLay->addLayout(resListLay);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setLayout(mainLay);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// initialize fields
Toshihiro Shimizu 890ddd
	TCamera camera;
Toshihiro Shimizu 890ddd
	setFields(&camera);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// connect events
Toshihiro Shimizu 890ddd
	bool ret = true;
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_lxFld, SIGNAL(editingFinished()), SLOT(onLxChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_lyFld, SIGNAL(editingFinished()), SLOT(onLyChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_arFld, SIGNAL(editingFinished()), SLOT(onArChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_xResFld, SIGNAL(editingFinished()), SLOT(onXResChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_yResFld, SIGNAL(editingFinished()), SLOT(onYResChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_xDpiFld, SIGNAL(editingFinished()), SLOT(onXDpiChanged()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_yDpiFld, SIGNAL(editingFinished()), SLOT(onYDpiChanged()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_fspChk, SIGNAL(clicked(bool)), SLOT(onFspChanged(bool)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_xPrev, SIGNAL(toggled(bool)), SLOT(onPrevToggled(bool)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_yPrev, SIGNAL(toggled(bool)), SLOT(onPrevToggled(bool)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_dotPrev, SIGNAL(toggled(bool)), SLOT(onPrevToggled(bool)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_inchPrev, SIGNAL(toggled(bool)), SLOT(onPrevToggled(bool)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_useLevelSettingsBtn, SIGNAL(clicked()), this, SLOT(useLevelSettings()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_presetListOm, SIGNAL(activated(const QString &)),
Toshihiro Shimizu 890ddd
						 SLOT(onPresetSelected(const QString &)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_addPresetBtn, SIGNAL(clicked()), SLOT(addPreset()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_removePresetBtn, SIGNAL(clicked()), SLOT(removePreset()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
CameraSettingsWidget::~CameraSettingsWidget()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setCurrentLevel(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::loadPresetList()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_presetListFile == "")
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_presetListOm->clear();
Toshihiro Shimizu 890ddd
	m_presetListOm->addItem(custom);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QFile file(m_presetListFile);
Toshihiro Shimizu 890ddd
	if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Toshihiro Shimizu 890ddd
		QTextStream in(&file);
Toshihiro Shimizu 890ddd
		while (!in.atEnd()) {
Toshihiro Shimizu 890ddd
			QString line = in.readLine().trimmed();
Toshihiro Shimizu 890ddd
			if (line != "")
Toshihiro Shimizu 890ddd
				m_presetListOm->addItem(line);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_presetListOm->setCurrentIndex(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::savePresetList()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QFile file(m_presetListFile);
Toshihiro Shimizu 890ddd
	if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	QTextStream out(&file);
Toshihiro Shimizu 890ddd
	int n = m_presetListOm->count();
Toshihiro Shimizu 890ddd
	for (int i = 1; i < n; i++)
Toshihiro Shimizu 890ddd
		out << m_presetListOm->itemText(i) << "\n";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool CameraSettingsWidget::parsePresetString(const QString &str, QString &name, int &xres, int &yres, QString &ar)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// str : name, 1024x768, 4/3
Toshihiro Shimizu 890ddd
	int b;
Toshihiro Shimizu 890ddd
	b = str.lastIndexOf(",");
Toshihiro Shimizu 890ddd
	if (b <= 1)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	b = str.lastIndexOf(",", b - 1);
Toshihiro Shimizu 890ddd
	if (b <= 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRegExp rx(" *([0-9]+)x([0-9]+) *, *(\\d*(\\.\\d+)?|\\d+/\\d+) *");
Toshihiro Shimizu 890ddd
	if (!rx.exactMatch(str.mid(b + 1)))
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	name = b > 0 ? str.left(b).trimmed() : "";
Toshihiro Shimizu 890ddd
	xres = rx.cap(1).toInt();
Toshihiro Shimizu 890ddd
	yres = rx.cap(2).toInt();
Toshihiro Shimizu 890ddd
	ar = rx.cap(3);
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool CameraSettingsWidget::parsePresetString(const QString &str,
Toshihiro Shimizu 890ddd
											 QString &name,
Toshihiro Shimizu 890ddd
											 int &xres,
Toshihiro Shimizu 890ddd
											 int &yres,
Toshihiro Shimizu 890ddd
											 double &fx,
Toshihiro Shimizu 890ddd
											 double &fy,
Toshihiro Shimizu 890ddd
											 QString &xoffset,
Toshihiro Shimizu 890ddd
											 QString &yoffset,
Toshihiro Shimizu 890ddd
											 double &ar,
Toshihiro Shimizu 890ddd
											 bool forCleanup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int len = str.length();
Toshihiro Shimizu 890ddd
	int i = len - 1;
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	int j = i;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//--- A/R
Toshihiro Shimizu 890ddd
	while (i >= 0 && '0' <= str[i] && str[i] <= '9')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i == len - 1 || i < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	if (str[i] == '/' || str[i] == '.') {
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
		int ii = i;
Toshihiro Shimizu 890ddd
		while (i >= 0 && '0' <= str[i] && str[i] <= '9')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i == ii)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ar = aspectRatioStringToValue(str.mid(i + 1, j - i));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//--- cleanup camera offsets
Toshihiro Shimizu 890ddd
	if (forCleanup) {
Toshihiro Shimizu 890ddd
		// yoffset
Toshihiro Shimizu 890ddd
		while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i < 0 || str[i] != ',')
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
		while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		j = i;
Toshihiro Shimizu 890ddd
		while (i >= 0 && str[i] != ',')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i < 0)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		i++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		yoffset = str.mid(i + 1, j - i);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// xoffset
Toshihiro Shimizu 890ddd
		while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i < 0 || str[i] != ',')
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
		while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		j = i;
Toshihiro Shimizu 890ddd
		while (i >= 0 && str[i] != ',')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i < 0)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		i++;
Toshihiro Shimizu 890ddd
		xoffset = str.mid(i + 1, j - i);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//--- camera size
Toshihiro Shimizu 890ddd
	// fy
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i < 0 || str[i] != ',')
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	i--;
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	j = i;
Toshihiro Shimizu 890ddd
	while (i >= 0 && (('0' <= str[i] && str[i] <= '9') || str[i] == '.'))
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (j == i || i < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	fy = str.mid(i + 1, j - i).toDouble();
Toshihiro Shimizu 890ddd
	// fx
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i < 0 || str[i] != 'x')
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	i--;
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	j = i;
Toshihiro Shimizu 890ddd
	while (i >= 0 && (('0' <= str[i] && str[i] <= '9') || str[i] == '.'))
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (j == i || i < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	fx = str.mid(i + 1, j - i).toDouble();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// yres
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i < 0 || str[i] != ',')
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	i--;
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	j = i;
Toshihiro Shimizu 890ddd
	while (i >= 0 && '0' <= str[i] && str[i] <= '9')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (j == i || i < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	yres = str.mid(i + 1, j - i).toInt();
Toshihiro Shimizu 890ddd
	// xres
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i < 0 || str[i] != 'x')
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	i--;
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	j = i;
Toshihiro Shimizu 890ddd
	while (i >= 0 && '0' <= str[i] && str[i] <= '9')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (j == i || i < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	xres = str.mid(i + 1, j - i).toInt();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// name
Toshihiro Shimizu 890ddd
	while (i >= 0 && str[i] == ' ')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i >= 0 && str[i] == ',')
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	if (i < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	i++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int k = 0;
Toshihiro Shimizu 890ddd
	while (k < i && str[k] == ' ')
Toshihiro Shimizu 890ddd
		k++;
Toshihiro Shimizu 890ddd
	if (k == i)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	/*--- 1文字のカメラ名にも対応するため ---*/
Toshihiro Shimizu 890ddd
	name = str.mid(k, i - k);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::setPresetListFile(const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_presetListFile = QString::fromStdWString(fp.getWideString());
Toshihiro Shimizu 890ddd
	loadPresetList();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool CameraSettingsWidget::eventFilter(QObject *obj, QEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (e->type() == QEvent::FocusIn) {
Toshihiro Shimizu 890ddd
		if (m_xPrev->isChecked() && obj == m_lxFld) // x-prev, fld=lx
Toshihiro Shimizu 890ddd
			m_yPrev->setChecked(true);
Toshihiro Shimizu 890ddd
		else if (m_yPrev->isChecked() && obj == m_lyFld) // y-prev, fld=ly
Toshihiro Shimizu 890ddd
			m_xPrev->setChecked(true);
Toshihiro Shimizu 890ddd
		else if (m_arPrev->isChecked() && obj == m_arFld) // ar-prev, fld=ar
Toshihiro Shimizu 890ddd
			m_xPrev->setChecked(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_inchPrev->isChecked() && (obj == m_lxFld || obj == m_lyFld || obj == m_arFld)) // inchPrev, fld = lx|ly|ar
Toshihiro Shimizu 890ddd
			m_dotPrev->setChecked(true);
Toshihiro Shimizu 890ddd
		else if (m_dotPrev->isChecked() && (obj == m_xResFld || obj == m_yResFld)) // dotPrev, fld = xres|yres
Toshihiro Shimizu 890ddd
			m_inchPrev->setChecked(true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return QObject::eventFilter(obj, e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::setCurrentLevel(TXshLevel *xshLevel)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = xshLevel ? xshLevel->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
	if (sl && sl->getType() == PLI_XSHLEVEL)
Toshihiro Shimizu 890ddd
		sl = 0;
Toshihiro Shimizu 890ddd
	if (sl == m_currentLevel)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (sl)
Toshihiro Shimizu 890ddd
		sl->addRef();
Toshihiro Shimizu 890ddd
	if (m_currentLevel)
Toshihiro Shimizu 890ddd
		m_currentLevel->release();
Toshihiro Shimizu 890ddd
	m_currentLevel = sl;
Toshihiro Shimizu 890ddd
	m_useLevelSettingsBtn->setEnabled(m_currentLevel != 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::useLevelSettings()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = m_currentLevel;
Toshihiro Shimizu 890ddd
	if (!sl)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Build dpi
Toshihiro Shimizu 890ddd
	TPointD dpi = sl->getDpi(TFrameId::NO_FRAME, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Build physical size
Toshihiro Shimizu 890ddd
	TDimensionD size(0, 0);
Toshihiro Shimizu 890ddd
	TDimension res = sl->getResolution();
Toshihiro Shimizu 890ddd
	if (res.lx <= 0 || res.ly <= 0 || dpi.x <= 0 || dpi.y <= 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	size.lx = res.lx / dpi.x;
Toshihiro Shimizu 890ddd
	size.ly = res.ly / dpi.y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TCamera camera;
Toshihiro Shimizu 890ddd
	getFields(&camera);
Toshihiro Shimizu 890ddd
	camera.setSize(size);
Toshihiro Shimizu 890ddd
	camera.setRes(res);
Toshihiro Shimizu 890ddd
	setFields(&camera);
Toshihiro Shimizu 890ddd
	emit levelSettingsUsed();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::setFields(const TCamera *camera)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TDimensionD sz = camera->getSize();
Toshihiro Shimizu 890ddd
	TDimension res = camera->getRes();
Toshihiro Shimizu 890ddd
	m_lxFld->setValue(sz.lx);
Toshihiro Shimizu 890ddd
	m_lyFld->setValue(sz.ly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_xResFld->setValue(res.lx);
Toshihiro Shimizu 890ddd
	m_yResFld->setValue(res.ly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setArFld(sz.lx / sz.ly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_xDpiFld->setValue(res.lx / sz.lx);
Toshihiro Shimizu 890ddd
	m_yDpiFld->setValue(res.ly / sz.ly);
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::getFields(TCamera *camera)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	camera->setSize(getSize());
Toshihiro Shimizu 890ddd
	camera->setRes(getRes());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TDimensionD CameraSettingsWidget::getSize() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double lx = m_lxFld->getValue();
Toshihiro Shimizu 890ddd
	double ly = m_lyFld->getValue();
Toshihiro Shimizu 890ddd
	return TDimensionD(lx, ly);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TDimension CameraSettingsWidget::getRes() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int xRes = (int)(m_xResFld->getValue());
Toshihiro Shimizu 890ddd
	int yRes = (int)(m_yResFld->getValue());
Toshihiro Shimizu 890ddd
	return TDimension(xRes, yRes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::updatePresetListOm()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_presetListOm->currentIndex() == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	bool match = false;
Toshihiro Shimizu 890ddd
	int xres, yres;
Toshihiro Shimizu 890ddd
	QString name, arStr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double fx, fy;
Toshihiro Shimizu 890ddd
	QString xoffset, yoffset;
Toshihiro Shimizu 890ddd
	double ar;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (parsePresetString(m_presetListOm->currentText(),
Toshihiro Shimizu 890ddd
						  name,
Toshihiro Shimizu 890ddd
						  xres,
Toshihiro Shimizu 890ddd
						  yres,
Toshihiro Shimizu 890ddd
						  fx,
Toshihiro Shimizu 890ddd
						  fy,
Toshihiro Shimizu 890ddd
						  xoffset,
Toshihiro Shimizu 890ddd
						  yoffset,
Toshihiro Shimizu 890ddd
						  ar,
Toshihiro Shimizu 890ddd
						  m_forCleanup)) {
Toshihiro Shimizu 890ddd
		double eps = 1.0e-6;
Toshihiro Shimizu 890ddd
		if (m_forCleanup && m_offsX && m_offsY) {
Toshihiro Shimizu 890ddd
			match = xres == m_xResFld->getValue() &&
Toshihiro Shimizu 890ddd
					yres == m_yResFld->getValue() &&
Toshihiro Shimizu 890ddd
					fx == m_lxFld->getValue() &&
Toshihiro Shimizu 890ddd
					fy == m_lyFld->getValue() &&
Toshihiro Shimizu 890ddd
					xoffset == m_offsX->text() &&
Toshihiro Shimizu 890ddd
					yoffset == m_offsY->text();
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			match = xres == m_xResFld->getValue() &&
Toshihiro Shimizu 890ddd
					yres == m_yResFld->getValue() &&
Toshihiro Shimizu 890ddd
					fx == m_lxFld->getValue() &&
Toshihiro Shimizu 890ddd
					fy == m_lyFld->getValue();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!match)
Toshihiro Shimizu 890ddd
		m_presetListOm->setCurrentIndex(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// ly,ar => lx
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::hComputeLx()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_lxFld->setValue(m_lyFld->getValue() * m_arValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// lx,ar => ly
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::hComputeLy()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_arValue == 0.0)
Toshihiro Shimizu 890ddd
		return; // non dovrebbe mai succedere
Toshihiro Shimizu 890ddd
	m_lyFld->setValue(m_lxFld->getValue() / m_arValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// lx,ly => ar
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::computeAr()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_lyFld->getValue() == 0.0)
Toshihiro Shimizu 890ddd
		return; // non dovrebbe mai succedere
Toshihiro Shimizu 890ddd
	setArFld(m_lxFld->getValue() / m_lyFld->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// xres,xdpi => lx
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::vComputeLx()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_xDpiFld->getValue() == 0.0)
Toshihiro Shimizu 890ddd
		return; // non dovrebbe mai succedere
Toshihiro Shimizu 890ddd
	m_lxFld->setValue(m_xResFld->getValue() / m_xDpiFld->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// yres,ydpi => ly
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::vComputeLy()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_yDpiFld->getValue() == 0.0)
Toshihiro Shimizu 890ddd
		return; // non dovrebbe mai succedere
Toshihiro Shimizu 890ddd
	m_lyFld->setValue(m_yResFld->getValue() / m_yDpiFld->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// lx,xdpi => xres
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::computeXRes()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_xResFld->setValue(tround(m_lxFld->getValue() * m_xDpiFld->getValue()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// ly,ydpi => yres
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::computeYRes()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_yResFld->setValue(tround(m_lyFld->getValue() * m_yDpiFld->getValue()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// lx,xres => xdpi
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::computeXDpi()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_lxFld->getValue() == 0.0)
Toshihiro Shimizu 890ddd
		return; // non dovrebbe mai succedere
Toshihiro Shimizu 890ddd
	m_xDpiFld->setValue(m_xResFld->getValue() / m_lxFld->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// ly,yres => ydpi
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::computeYDpi()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_lyFld->getValue() == 0.0)
Toshihiro Shimizu 890ddd
		return; // non dovrebbe mai succedere
Toshihiro Shimizu 890ddd
	m_yDpiFld->setValue(m_yResFld->getValue() / m_lyFld->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// set A/R field, assign m_arValue and compute a nice string representation for the value (e.g. "4/3" instead of 1.3333333)
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::setArFld(double ar)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_arValue = ar;
Toshihiro Shimizu 890ddd
	/*---ピクセルサイズのW/Hの値に近かったら"W/H"と表示する---*/
Toshihiro Shimizu 890ddd
	m_arFld->setValue(ar, (int)m_xResFld->getValue(), (int)m_yResFld->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// compute res or dpi according to the prevalence
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::computeResOrDpi()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	computeXRes();
Toshihiro Shimizu 890ddd
	computeYRes();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onLxChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(!m_inchPrev->isChecked());
Toshihiro Shimizu 890ddd
	//assert(!(m_fspChk->isChecked() && m_yPrev->isChecked() && m_dotPrev->isChecked()));
Toshihiro Shimizu 890ddd
	if (m_yPrev->isChecked())
Toshihiro Shimizu 890ddd
		computeAr();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		hComputeLy();
Toshihiro Shimizu 890ddd
	computeResOrDpi();
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onLyChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(!m_inchPrev->isChecked());
Toshihiro Shimizu 890ddd
	//assert(!(m_fspChk->isChecked() && m_xPrev->isChecked() && m_dotPrev->isChecked()));
Toshihiro Shimizu 890ddd
	if (m_xPrev->isChecked())
Toshihiro Shimizu 890ddd
		computeAr();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		hComputeLx();
Toshihiro Shimizu 890ddd
	computeResOrDpi();
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onArChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_arValue = aspectRatioStringToValue(m_arFld->text());
Toshihiro Shimizu 890ddd
	if (m_xPrev->isChecked())
Toshihiro Shimizu 890ddd
		hComputeLy();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		hComputeLx();
Toshihiro Shimizu 890ddd
	computeResOrDpi();
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onXResChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	vComputeLx();
Toshihiro Shimizu 890ddd
	if (m_yPrev->isChecked())
Toshihiro Shimizu 890ddd
		computeAr();
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		hComputeLy();
Toshihiro Shimizu 890ddd
		computeYRes();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onYResChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	vComputeLy();
Toshihiro Shimizu 890ddd
	if (m_xPrev->isChecked())
Toshihiro Shimizu 890ddd
		computeAr();
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		hComputeLx();
Toshihiro Shimizu 890ddd
		computeXRes();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onXDpiChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fspChk->isChecked())
Toshihiro Shimizu 890ddd
		m_yDpiFld->setValue(m_xDpiFld->getValue());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_dotPrev->isChecked()) {
Toshihiro Shimizu 890ddd
		vComputeLx();
Toshihiro Shimizu 890ddd
		if (m_arPrev->isChecked()) {
Toshihiro Shimizu 890ddd
			hComputeLy();
Toshihiro Shimizu 890ddd
			if (!m_fspChk->isChecked())
Toshihiro Shimizu 890ddd
				computeYDpi();
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			computeAr();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		computeXRes();
Toshihiro Shimizu 890ddd
		computeYRes();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onYDpiChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fspChk->isChecked())
Toshihiro Shimizu 890ddd
		m_xDpiFld->setValue(m_yDpiFld->getValue());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_dotPrev->isChecked()) {
Toshihiro Shimizu 890ddd
		vComputeLy();
Toshihiro Shimizu 890ddd
		if (m_arPrev->isChecked()) {
Toshihiro Shimizu 890ddd
			hComputeLx();
Toshihiro Shimizu 890ddd
			if (!m_fspChk->isChecked())
Toshihiro Shimizu 890ddd
				computeXDpi();
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			computeAr();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		computeXRes();
Toshihiro Shimizu 890ddd
		computeYRes();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onFspChanged(bool checked)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fspChk->isChecked()) {
Toshihiro Shimizu 890ddd
		if (m_xPrev->isChecked())
Toshihiro Shimizu 890ddd
			m_yDpiFld->setValue(m_xDpiFld->getValue());
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			m_xDpiFld->setValue(m_yDpiFld->getValue());
Toshihiro Shimizu 890ddd
		if (m_dotPrev->isChecked()) {
Toshihiro Shimizu 890ddd
			vComputeLx();
Toshihiro Shimizu 890ddd
			vComputeLy();
Toshihiro Shimizu 890ddd
			computeAr();
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			computeXRes();
Toshihiro Shimizu 890ddd
			computeYRes();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	updatePresetListOm();
Toshihiro Shimizu 890ddd
	emit changed();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onPrevToggled(bool checked)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*---Prevalences が変わっても ForceSquaredPixelオプションには影響しない---*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::onPresetSelected(const QString &str)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (str == custom || str.isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	QString name, arStr;
Toshihiro Shimizu 890ddd
	int xres = 0, yres = 0;
Toshihiro Shimizu 890ddd
	double fx, fy;
Toshihiro Shimizu 890ddd
	QString xoffset, yoffset;
Toshihiro Shimizu 890ddd
	double ar;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (parsePresetString(str,
Toshihiro Shimizu 890ddd
						  name,
Toshihiro Shimizu 890ddd
						  xres,
Toshihiro Shimizu 890ddd
						  yres,
Toshihiro Shimizu 890ddd
						  fx,
Toshihiro Shimizu 890ddd
						  fy,
Toshihiro Shimizu 890ddd
						  xoffset,
Toshihiro Shimizu 890ddd
						  yoffset,
Toshihiro Shimizu 890ddd
						  ar,
Toshihiro Shimizu 890ddd
						  m_forCleanup)) {
Toshihiro Shimizu 890ddd
		m_xResFld->setValue(xres);
Toshihiro Shimizu 890ddd
		m_yResFld->setValue(yres);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_lxFld->setValue(fx);
Toshihiro Shimizu 890ddd
		m_lyFld->setValue(fy);
Toshihiro Shimizu 890ddd
		m_arFld->setValue(ar, tround(xres), tround(yres));
Toshihiro Shimizu 890ddd
		m_arValue = ar;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_forCleanup && m_offsX && m_offsY) {
Toshihiro Shimizu 890ddd
			m_offsX->setText(xoffset);
Toshihiro Shimizu 890ddd
			m_offsY->setText(yoffset);
Toshihiro Shimizu 890ddd
			m_offsX->postSetText(); //calls onEditingFinished()
Toshihiro Shimizu 890ddd
			m_offsY->postSetText(); //calls onEditingFinished()
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*--- DPI以外はロードしたままの値を使う ---*/
Toshihiro Shimizu 890ddd
		computeXDpi();
Toshihiro Shimizu 890ddd
		computeYDpi();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!areAlmostEqual(fx, m_arValue * fy) && m_fspChk->isChecked())
Toshihiro Shimizu 890ddd
			m_fspChk->setChecked(false);
Toshihiro Shimizu 890ddd
		emit changed();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		QMessageBox::warning(this, tr("Bad camera preset"),
Toshihiro Shimizu 890ddd
							 tr("'%1' doesn't seem a well formed camera preset. \n"
Toshihiro Shimizu 890ddd
								"Possibly the preset file has been corrupted")
Toshihiro Shimizu 890ddd
								 .arg(str));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::addPreset()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int xRes = (int)(m_xResFld->getValue());
Toshihiro Shimizu 890ddd
	int yRes = (int)(m_yResFld->getValue());
Toshihiro Shimizu 890ddd
	double lx = m_lxFld->getValue();
Toshihiro Shimizu 890ddd
	double ly = m_lyFld->getValue();
Toshihiro Shimizu 890ddd
	double ar = m_arFld->getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString presetString;
Toshihiro Shimizu 890ddd
	/*--- Cleanupカメラの場合はオフセットも格納 ---*/
Toshihiro Shimizu 890ddd
	if (m_forCleanup) {
Toshihiro Shimizu 890ddd
		QString xoffset = (m_offsX) ? m_offsX->text() : QString("0");
Toshihiro Shimizu 890ddd
		QString yoffset = (m_offsY) ? m_offsY->text() : QString("0");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		presetString = QString::number(xRes) + "x" + QString::number(yRes) + ", " +
Toshihiro Shimizu 890ddd
					   removeZeros(QString::number(lx)) + "x" + removeZeros(QString::number(ly)) + ", " +
Toshihiro Shimizu 890ddd
					   xoffset + ", " + yoffset + ", " +
Toshihiro Shimizu 890ddd
					   aspectRatioValueToString(ar);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		presetString = QString::number(xRes) + "x" + QString::number(yRes) + ", " +
Toshihiro Shimizu 890ddd
					   removeZeros(QString::number(lx)) + "x" + removeZeros(QString::number(ly)) + ", " +
Toshihiro Shimizu 890ddd
					   aspectRatioValueToString(ar);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool ok;
Toshihiro Shimizu 890ddd
	QString qs = DVGui::getText(
Toshihiro Shimizu 890ddd
		tr("Preset name"),
Toshihiro Shimizu 890ddd
		tr("Enter the name for %1").arg(presetString),
Toshihiro Shimizu 890ddd
		"", &ok);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!ok)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int oldn = m_presetListOm->count();
Toshihiro Shimizu 890ddd
	m_presetListOm->addItem(qs + "," + presetString);
Toshihiro Shimizu 890ddd
	int newn = m_presetListOm->count();
Toshihiro Shimizu 890ddd
	m_presetListOm->blockSignals(true);
Toshihiro Shimizu 890ddd
	m_presetListOm->setCurrentIndex(m_presetListOm->count() - 1);
Toshihiro Shimizu 890ddd
	m_presetListOm->blockSignals(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	savePresetList();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CameraSettingsWidget::removePreset()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int index = m_presetListOm->currentIndex();
Toshihiro Shimizu 890ddd
	if (index <= 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// confirmation dialog
Shinya Kitaoka eabf18
	int ret = DVGui::MsgBox(QObject::tr("Deleting \"%1\".\nAre you sure?").arg(m_presetListOm->currentText()),
Toshihiro Shimizu 890ddd
					 QObject::tr("Delete"), QObject::tr("Cancel"));
Toshihiro Shimizu 890ddd
	if (ret == 0 || ret == 2)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_presetListOm->removeItem(index);
Toshihiro Shimizu 890ddd
	m_presetListOm->setCurrentIndex(0);
Toshihiro Shimizu 890ddd
	savePresetList();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// A/R : value => string (e.g. '4/3' or '1.23')
Toshihiro Shimizu 890ddd
double CameraSettingsWidget::aspectRatioStringToValue(const QString &s)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (s == "") {
Toshihiro Shimizu 890ddd
		return 1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int i = s.indexOf("/");
Toshihiro Shimizu 890ddd
	if (i <= 0 || i + 1 >= s.length())
Toshihiro Shimizu 890ddd
		return s.toDouble();
Toshihiro Shimizu 890ddd
	int num = s.left(i).toInt();
Toshihiro Shimizu 890ddd
	int den = s.mid(i + 1).toInt();
Toshihiro Shimizu 890ddd
	if (den <= 0)
Toshihiro Shimizu 890ddd
		den = 1;
Toshihiro Shimizu 890ddd
	return (double)num / (double)den;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// A/R : value => string (e.g. '4/3' or '1.23')
Toshihiro Shimizu 890ddd
/*---カメラの縦横ピクセル値を入力できるようにし、valueがX/Yの値に近かったら、"X/Y"と表示する---*/
Toshihiro Shimizu 890ddd
QString CameraSettingsWidget::aspectRatioValueToString(double value, int width, int height)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double v = value;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (width != 0 && height != 0) {
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(value, (double)width / (double)height, 1e-3)) /*-- 誤差3桁 --*/
Toshihiro Shimizu 890ddd
			return QString("%1/%2").arg(width).arg(height);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double iv = tround(v);
Toshihiro Shimizu 890ddd
	if (fabs(iv - v) > 0.01) {
Toshihiro Shimizu 890ddd
		for (int d = 2; d < 20; d++) {
Toshihiro Shimizu 890ddd
			int n = tround(v * d);
Toshihiro Shimizu 890ddd
			if (fabs(n - v * d) <= 0.01)
Toshihiro Shimizu 890ddd
				return QString::number(n) + "/" + QString::number(d);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return QString::number(value, 'f', 5);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		return QString::number((int)iv);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}