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