Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "levelsettingspopup.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Tnz6 includes
Toshihiro Shimizu 890ddd
#include "menubarcommandids.h"
Toshihiro Shimizu 890ddd
#include "tapp.h"
Toshihiro Shimizu 890ddd
#include "flipbook.h"
Toshihiro Shimizu 890ddd
#include "fileviewerpopup.h"
Toshihiro Shimizu 890ddd
#include "castselection.h"
Toshihiro Shimizu 890ddd
#include "fileselection.h"
Toshihiro Shimizu 890ddd
#include "columnselection.h"
shun-iwasawa 409dec
#include "levelcommand.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/menubarcommand.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/infoviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/filefield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/doublefield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/intfield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/checkbox.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/tselectionhandle.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/icongenerator.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxselection.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelset.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjecttree.h"
Toshihiro Shimizu 890ddd
#include "toonz/palettecontroller.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/childstack.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.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 "tfiletype.h"
Toshihiro Shimizu 890ddd
#include "tlevel.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
shun-iwasawa 29ceb2
#include "tundo.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qhboxlayout></qhboxlayout>
Toshihiro Shimizu 890ddd
#include <qcombobox></qcombobox>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qmainwindow></qmainwindow>
Toshihiro Shimizu 890ddd
#include <qgroupbox></qgroupbox>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString dpiToString(const TPointD &dpi) {
Shinya Kitaoka 120a6e
  if (dpi.x == 0.0 || dpi.y == 0.0)
Shinya Kitaoka 120a6e
    return QString("none");
shun-iwasawa 29ceb2
  else if (dpi.x < 0.0 || dpi.y < 0.0)
shun-iwasawa 29ceb2
    return LevelSettingsPopup::tr("[Various]");
Shinya Kitaoka 120a6e
  else if (areAlmostEqual(dpi.x, dpi.y, 0.01))
Shinya Kitaoka 120a6e
    return QString::number(dpi.x);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return QString::number(dpi.x) + ", " + QString::number(dpi.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD getCurrentCameraDpi() {
Shinya Kitaoka 120a6e
  TCamera *camera =
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera();
Shinya Kitaoka 120a6e
  TDimensionD size = camera->getSize();
Shinya Kitaoka 120a6e
  TDimension res   = camera->getRes();
Shinya Kitaoka 120a6e
  return TPointD(res.lx / size.lx, res.ly / size.ly);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 29ceb2
void uniteValue(QString &oldValue, QString &newValue, bool isFirst) {
shun-iwasawa 29ceb2
  if (isFirst)
shun-iwasawa 29ceb2
    oldValue = newValue;
shun-iwasawa 29ceb2
  else if (oldValue != newValue &&
shun-iwasawa 29ceb2
           oldValue != LevelSettingsPopup::tr("[Various]"))
shun-iwasawa 29ceb2
    oldValue = LevelSettingsPopup::tr("[Various]");
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
void uniteValue(int &oldValue, int &newValue, bool isFirst) {
shun-iwasawa 29ceb2
  if (isFirst)
shun-iwasawa 29ceb2
    oldValue = newValue;
shun-iwasawa 29ceb2
  else if (oldValue != -1 && oldValue != newValue)
shun-iwasawa 29ceb2
    oldValue = -1;
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
void uniteValue(TPointD &oldValue, TPointD &newValue, bool isFirst) {
shun-iwasawa 29ceb2
  if (isFirst)
shun-iwasawa 29ceb2
    oldValue = newValue;
shun-iwasawa 29ceb2
  else if (oldValue != TPointD(-1, -1) && oldValue != newValue)
shun-iwasawa 29ceb2
    oldValue = TPointD(-1, -1);
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
void uniteValue(Qt::CheckState &oldValue, Qt::CheckState &newValue,
shun-iwasawa 29ceb2
                bool isFirst) {
shun-iwasawa 29ceb2
  if (isFirst)
shun-iwasawa 29ceb2
    oldValue = newValue;
shun-iwasawa 29ceb2
  else if (oldValue != Qt::PartiallyChecked && oldValue != newValue)
shun-iwasawa 29ceb2
    oldValue = Qt::PartiallyChecked;
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
void uniteValue(double &oldValue, double &newValue, bool isFirst) {
shun-iwasawa 29ceb2
  if (isFirst)
shun-iwasawa 29ceb2
    oldValue = newValue;
shun-iwasawa 29ceb2
  else if (oldValue != -1.0 && oldValue != newValue)
shun-iwasawa 29ceb2
    oldValue = -1.0;
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
class LevelSettingsUndo final : public TUndo {
shun-iwasawa 29ceb2
public:
shun-iwasawa 29ceb2
  enum Type {
shun-iwasawa 29ceb2
    Name,
shun-iwasawa 29ceb2
    Path,
shun-iwasawa 29ceb2
    ScanPath,
shun-iwasawa 29ceb2
    DpiType,
shun-iwasawa 29ceb2
    Dpi,
shun-iwasawa 29ceb2
    DoPremulti,
shun-iwasawa 29ceb2
    WhiteTransp,
shun-iwasawa 29ceb2
    Softness,
shun-iwasawa 29ceb2
    Subsampling,
shun-iwasawa 481b59
    LevelType,
shun-iwasawa 481b59
    ColorSpaceGamma
shun-iwasawa 29ceb2
  };
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
private:
shun-iwasawa 29ceb2
  TXshLevelP m_xl;
shun-iwasawa 29ceb2
  const Type m_type;
shun-iwasawa 29ceb2
  const QVariant m_before;
shun-iwasawa 29ceb2
  const QVariant m_after;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setName(const QString name) const {
shun-iwasawa 29ceb2
    TLevelSet *levelSet =
shun-iwasawa 29ceb2
        TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
shun-iwasawa 29ceb2
    levelSet->renameLevel(m_xl.getPointer(), name.toStdWString());
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentScene()->notifyCastChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setPath(const TFilePath path) const {
shun-iwasawa 29ceb2
    TXshSoundLevelP sdl = m_xl->getSoundLevel();
shun-iwasawa 29ceb2
    if (sdl) {
shun-iwasawa 29ceb2
      sdl->setPath(path);
shun-iwasawa 29ceb2
      sdl->loadSoundTrack();
shun-iwasawa 29ceb2
      TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
shun-iwasawa 29ceb2
      TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
shun-iwasawa 29ceb2
      return;
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl  = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    TXshPaletteLevelP pl = m_xl->getPaletteLevel();
shun-iwasawa 29ceb2
    if (!sl && !pl) return;
shun-iwasawa 29ceb2
    if (sl) {
shun-iwasawa 29ceb2
      sl->setPath(path);
shun-iwasawa 29ceb2
      TApp::instance()
shun-iwasawa 29ceb2
          ->getPaletteController()
shun-iwasawa 29ceb2
          ->getCurrentLevelPalette()
shun-iwasawa 29ceb2
          ->setPalette(sl->getPalette());
shun-iwasawa 29ceb2
      sl->invalidateFrames();
shun-iwasawa 29ceb2
      std::vector<tframeid> frames;</tframeid>
shun-iwasawa 29ceb2
      sl->getFids(frames);
shun-iwasawa 29ceb2
      for (auto const &fid : frames) {
shun-iwasawa 29ceb2
        IconGenerator::instance()->invalidate(sl.getPointer(), fid);
shun-iwasawa 29ceb2
      }
shun-iwasawa 29ceb2
    } else if (pl) {
shun-iwasawa 29ceb2
      pl->setPath(path);
shun-iwasawa 29ceb2
      TApp::instance()
shun-iwasawa 29ceb2
          ->getPaletteController()
shun-iwasawa 29ceb2
          ->getCurrentLevelPalette()
shun-iwasawa 29ceb2
          ->setPalette(pl->getPalette());
shun-iwasawa 29ceb2
      pl->load();
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setScanPath(const TFilePath path) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() != TZP_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->setScannedPath(path);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setDpiType(LevelProperties::DpiPolicy policy) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->getProperties()->setDpiPolicy(policy);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentScene()->setDirtyFlag(true);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setDpi(TPointD dpi) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->getProperties()->setDpi(dpi);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentScene()->setDirtyFlag(true);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setSubsampling(int subsampling) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->getProperties()->setSubsampling(subsampling);
shun-iwasawa 29ceb2
    sl->invalidateFrames();
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentScene()->setDirtyFlag(true);
shun-iwasawa 29ceb2
    TApp::instance()
shun-iwasawa 29ceb2
        ->getCurrentXsheet()
shun-iwasawa 29ceb2
        ->getXsheet()
shun-iwasawa 29ceb2
        ->getStageObjectTree()
shun-iwasawa 29ceb2
        ->invalidateAll();
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setDoPremulti(bool on) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->getProperties()->setDoPremultiply(on);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setSoftness(int softness) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->getProperties()->setDoAntialias(softness);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void setWhiteTransp(bool on) const {
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) return;
shun-iwasawa 29ceb2
    sl->getProperties()->setWhiteTransp(on);
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 481b59
  void setColorSpaceGamma(double gamma) const {
shun-iwasawa 481b59
    TXshSimpleLevelP sl = m_xl->getSimpleLevel();
shun-iwasawa 481b59
    if (!sl || sl->getType() != OVL_XSHLEVEL) return;
shun-iwasawa 481b59
    sl->getProperties()->setColorSpaceGamma(gamma);
shun-iwasawa 481b59
    sl->invalidateFrames();
shun-iwasawa 481b59
    TApp::instance()->getCurrentScene()->setDirtyFlag(true);
shun-iwasawa 481b59
    TApp::instance()
shun-iwasawa 481b59
        ->getCurrentXsheet()
shun-iwasawa 481b59
        ->getXsheet()
shun-iwasawa 481b59
        ->getStageObjectTree()
shun-iwasawa 481b59
        ->invalidateAll();
shun-iwasawa 481b59
    TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
shun-iwasawa 29ceb2
  void setValue(const QVariant value) const {
shun-iwasawa 29ceb2
    switch (m_type) {
shun-iwasawa 29ceb2
    case Name:
shun-iwasawa 29ceb2
      setName(value.toString());
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case Path:
shun-iwasawa 29ceb2
      setPath(TFilePath(value.toString()));
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case ScanPath:
shun-iwasawa 29ceb2
      setScanPath(TFilePath(value.toString()));
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case DpiType:
shun-iwasawa 29ceb2
      setDpiType(LevelProperties::DpiPolicy(value.toInt()));
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case Dpi: {
shun-iwasawa 29ceb2
      QPointF dpi = value.toPointF();
shun-iwasawa 29ceb2
      setDpi(TPointD(dpi.x(), dpi.y()));
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
    case Subsampling:
shun-iwasawa 29ceb2
      setSubsampling(value.toInt());
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case DoPremulti:
shun-iwasawa 29ceb2
      setDoPremulti(value.toBool());
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case Softness:
shun-iwasawa 29ceb2
      setSoftness(value.toInt());
shun-iwasawa 29ceb2
      break;
shun-iwasawa 29ceb2
    case WhiteTransp:
shun-iwasawa 29ceb2
      setWhiteTransp(value.toBool());
shun-iwasawa 29ceb2
      break;
shun-iwasawa 481b59
    case ColorSpaceGamma:
shun-iwasawa 481b59
      setColorSpaceGamma(value.toDouble());
shun-iwasawa 481b59
      break;
Rozhuk Ivan 823a31
    default:
Rozhuk Ivan 823a31
      break;
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
    // This signal is for updating the level settings
shun-iwasawa 29ceb2
    TApp::instance()->getCurrentScene()->notifySceneChanged();
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
public:
shun-iwasawa 29ceb2
  LevelSettingsUndo(TXshLevel *xl, Type type, const QVariant before,
shun-iwasawa 29ceb2
                    const QVariant after)
shun-iwasawa 29ceb2
      : m_xl(xl), m_type(type), m_before(before), m_after(after) {}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void undo() const override { setValue(m_before); }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  void redo() const override { setValue(m_after); }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  int getSize() const override { return sizeof *this; }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  QString getHistoryString() override {
shun-iwasawa 29ceb2
    return QObject::tr("Edit Level Settings : %1")
shun-iwasawa 29ceb2
        .arg(QString::fromStdWString(m_xl->getName()));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
};
shun-iwasawa 29ceb2
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
}  // anonymous namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class LevelSettingsPopup
shun-iwasawa 29ceb2
   \brief The LevelSettingsPopup class provides a dialog to show
shun-iwasawa 29ceb2
   and change current level settings.
shun-iwasawa 29ceb2
   Inherits \b Dialog.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
LevelSettingsPopup::LevelSettingsPopup()
Shinya Kitaoka 120a6e
    : Dialog(TApp::instance()->getMainWindow(), false, false, "LevelSettings")
Shinya Kitaoka 120a6e
    , m_whiteTransp(0)
Shinya Kitaoka 120a6e
    , m_scanPathFld(0) {
Shinya Kitaoka 120a6e
  setWindowTitle(tr("Level Settings"));
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_nameFld             = new LineEdit();
shun-iwasawa 29ceb2
  m_pathFld             = new FileField();  // Path
shun-iwasawa 29ceb2
  m_scanPathFld         = new FileField();  // ScanPath
shun-iwasawa 29ceb2
  QLabel *scanPathLabel = new QLabel(tr("Scan Path:"), this);
shun-iwasawa 29ceb2
  m_typeLabel           = new QLabel();  // Level Type
Shinya Kitaoka 120a6e
  // Type
Shinya Kitaoka 120a6e
  m_dpiTypeOm = new QComboBox();
Shinya Kitaoka 120a6e
  // DPI
shun-iwasawa 29ceb2
  QLabel *dpiLabel = new QLabel(tr("DPI:"));
shun-iwasawa 29ceb2
  m_dpiFld         = new DoubleLineEdit();
shun-iwasawa 29ceb2
  m_squarePixCB    = new CheckBox(tr("Forced Squared Pixel"));
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  QLabel *widthLabel  = new QLabel(tr("Width:"));
shun-iwasawa 29ceb2
  m_widthFld          = new MeasuredDoubleLineEdit();
shun-iwasawa 29ceb2
  QLabel *heightLabel = new QLabel(tr("Height:"));
shun-iwasawa 29ceb2
  m_heightFld         = new MeasuredDoubleLineEdit();
Shinya Kitaoka 120a6e
  // Use Camera Dpi
Shinya Kitaoka 120a6e
  m_useCameraDpiBtn = new QPushButton(tr("Use Camera DPI"));
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_cameraDpiLabel       = new QLabel(tr(""));
shun-iwasawa 29ceb2
  m_imageDpiLabel        = new QLabel(tr(""));
shun-iwasawa 29ceb2
  m_imageResLabel        = new QLabel(tr(""));
shun-iwasawa 29ceb2
  QLabel *cameraDpiTitle = new QLabel(tr("Camera DPI:"));
shun-iwasawa 29ceb2
  QLabel *imageDpiTitle  = new QLabel(tr("Image DPI:"));
shun-iwasawa 29ceb2
  QLabel *imageResTitle  = new QLabel(tr("Resolution:"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // subsampling
Shinya Kitaoka 120a6e
  m_subsamplingLabel = new QLabel(tr("Subsampling:"));
Shinya Kitaoka 120a6e
  m_subsamplingFld   = new DVGui::IntLineEdit(this, 1, 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_doPremultiply = new CheckBox(tr("Premultiply"), this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_whiteTransp = new CheckBox(tr("White As Transparent"), this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_doAntialias       = new CheckBox(tr("Add Antialiasing"), this);
shun-iwasawa 29ceb2
  m_softnessLabel     = new QLabel(tr("Antialias Softness:"), this);
Shinya Kitaoka 120a6e
  m_antialiasSoftness = new DVGui::IntLineEdit(0, 10, 0, 100);
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
  m_colorSpaceGammaLabel = new QLabel(tr("Color Space Gamma:"));
shun-iwasawa 481b59
  m_colorSpaceGammaFld   = new DoubleLineEdit();
shun-iwasawa 481b59
  m_colorSpaceGammaFld->setRange(0.1, 10.);
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
  //----
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_pathFld->setFileMode(QFileDialog::AnyFile);
Shinya Kitaoka 120a6e
  m_scanPathFld->setFileMode(QFileDialog::AnyFile);
Shinya Kitaoka 120a6e
shun-iwasawa e87e08
  m_dpiTypeOm->addItem(tr("Image DPI"), "Image DPI");
shun-iwasawa e87e08
  m_dpiTypeOm->addItem(tr("Custom DPI"), "Custom DPI");
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_squarePixCB->setCheckState(Qt::Checked);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_widthFld->setMeasure("camera.lx");
Shinya Kitaoka 120a6e
  m_heightFld->setMeasure("camera.ly");
Jeremy Bullock 59dbbf
Jeremy Bullock 59dbbf
  if (Preferences::instance()->getCameraUnits() == "pixel") {
Jeremy Bullock 59dbbf
    m_widthFld->setDecimals(0);
Jeremy Bullock 59dbbf
    m_heightFld->setDecimals(0);
Jeremy Bullock 59dbbf
  }
Jeremy Bullock d06574
shun-iwasawa 29ceb2
  m_doPremultiply->setTristate();
shun-iwasawa 29ceb2
  m_doPremultiply->setCheckState(Qt::Unchecked);
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_doAntialias->setTristate();
shun-iwasawa 29ceb2
  m_doAntialias->setCheckState(Qt::Unchecked);
Shinya Kitaoka 120a6e
  m_antialiasSoftness->setEnabled(false);
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_whiteTransp->setTristate();
shun-iwasawa 29ceb2
  m_whiteTransp->setCheckState(Qt::Unchecked);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // register activation flags
shun-iwasawa 29ceb2
  m_activateFlags[m_nameFld]     = AllTypes;
shun-iwasawa 29ceb2
  m_activateFlags[m_pathFld]     = SimpleLevel | Palette | Sound;
shun-iwasawa 29ceb2
  m_activateFlags[m_scanPathFld] = ToonzRaster;
shun-iwasawa 29ceb2
  m_activateFlags[scanPathLabel] = ToonzRaster | MultiSelection;
shun-iwasawa 29ceb2
  // m_activateFlags[m_typeLabel]   = AllTypes | MultiSelection;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  unsigned int dpiWidgetsFlag  = HasDPILevel | HideOnPixelMode | MultiSelection;
shun-iwasawa 29ceb2
  m_activateFlags[m_dpiTypeOm] = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[dpiLabel]    = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_dpiFld]    = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_squarePixCB] = dpiWidgetsFlag;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  unsigned int rasterWidgetsFlag     = ToonzRaster | Raster | MultiSelection;
shun-iwasawa 29ceb2
  m_activateFlags[widthLabel]        = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_widthFld]        = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[heightLabel]       = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_heightFld]       = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_useCameraDpiBtn] = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_cameraDpiLabel] =
shun-iwasawa 29ceb2
      AllTypes | HideOnPixelMode | MultiSelection;
shun-iwasawa 29ceb2
  m_activateFlags[m_imageDpiLabel] = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_imageResLabel] = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[cameraDpiTitle] = AllTypes | HideOnPixelMode | MultiSelection;
shun-iwasawa 29ceb2
  m_activateFlags[imageDpiTitle]  = dpiWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[imageResTitle]  = dpiWidgetsFlag;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  m_activateFlags[m_doPremultiply]     = Raster | MultiSelection;
shun-iwasawa 29ceb2
  m_activateFlags[m_whiteTransp]       = Raster | MultiSelection;
shun-iwasawa 29ceb2
  m_activateFlags[m_doAntialias]       = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_softnessLabel]     = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_antialiasSoftness] = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_subsamplingLabel]  = rasterWidgetsFlag;
shun-iwasawa 29ceb2
  m_activateFlags[m_subsamplingFld]    = rasterWidgetsFlag;
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
  unsigned int linearFlag                 = LinearRaster | MultiSelection;
shun-iwasawa 481b59
  m_activateFlags[m_colorSpaceGammaLabel] = linearFlag;
shun-iwasawa 481b59
  m_activateFlags[m_colorSpaceGammaFld]   = linearFlag;
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
  //----layout
Shinya Kitaoka 120a6e
  m_topLayout->setMargin(5);
Shinya Kitaoka 120a6e
  m_topLayout->setSpacing(5);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    //--Name&Path
Shinya Kitaoka 120a6e
    QGroupBox *nameBox      = new QGroupBox(tr("Name && Path"), this);
Shinya Kitaoka 120a6e
    QGridLayout *nameLayout = new QGridLayout();
Shinya Kitaoka 120a6e
    nameLayout->setMargin(5);
Shinya Kitaoka 120a6e
    nameLayout->setSpacing(5);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      nameLayout->addWidget(new QLabel(tr("Name:"), this), 0, 0,
Shinya Kitaoka 120a6e
                            Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      nameLayout->addWidget(m_nameFld, 0, 1);
Shinya Kitaoka 120a6e
      nameLayout->addWidget(new QLabel(tr("Path:"), this), 1, 0,
Shinya Kitaoka 120a6e
                            Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      nameLayout->addWidget(m_pathFld, 1, 1);
shun-iwasawa 29ceb2
      nameLayout->addWidget(scanPathLabel, 2, 0,
Shinya Kitaoka 120a6e
                            Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      nameLayout->addWidget(m_scanPathFld, 2, 1);
Shinya Kitaoka 120a6e
      nameLayout->addWidget(m_typeLabel, 3, 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    nameLayout->setColumnStretch(0, 0);
Shinya Kitaoka 120a6e
    nameLayout->setColumnStretch(1, 1);
Shinya Kitaoka 120a6e
    nameBox->setLayout(nameLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_topLayout->addWidget(nameBox);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    //----DPI & Resolution
Jeremy Bullock 59dbbf
    QGroupBox *dpiBox;
Jeremy Bullock 59dbbf
    if (Preferences::instance()->getUnits() == "pixel")
Jeremy Bullock 59dbbf
      dpiBox = new QGroupBox(tr("Resolution"), this);
Jeremy Bullock 59dbbf
    else
shun-iwasawa 29ceb2
      dpiBox = new QGroupBox(tr("DPI && Resolution"), this);
Shinya Kitaoka 120a6e
    QGridLayout *dpiLayout = new QGridLayout();
Jeremy Bullock 59dbbf
    dpiLayout->setMargin(5);
Shinya Kitaoka 120a6e
    dpiLayout->setSpacing(5);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_dpiTypeOm, 0, 1, 1, 3);
shun-iwasawa 29ceb2
      dpiLayout->addWidget(dpiLabel, 1, 0, Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_dpiFld, 1, 1);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_squarePixCB, 1, 2, 1, 2,
Shinya Kitaoka 120a6e
                           Qt::AlignRight | Qt::AlignVCenter);
shun-iwasawa 29ceb2
      dpiLayout->addWidget(widthLabel, 2, 0, Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_widthFld, 2, 1);
shun-iwasawa 29ceb2
      dpiLayout->addWidget(heightLabel, 2, 2,
Shinya Kitaoka 120a6e
                           Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_heightFld, 2, 3);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_useCameraDpiBtn, 3, 1, 1, 3);
shun-iwasawa 29ceb2
      dpiLayout->addWidget(cameraDpiTitle, 4, 0,
Shinya Kitaoka 120a6e
                           Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_cameraDpiLabel, 4, 1, 1, 3);
shun-iwasawa 29ceb2
      dpiLayout->addWidget(imageDpiTitle, 5, 0,
Shinya Kitaoka 120a6e
                           Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_imageDpiLabel, 5, 1, 1, 3);
shun-iwasawa 29ceb2
      dpiLayout->addWidget(imageResTitle, 6, 0,
Shinya Kitaoka 120a6e
                           Qt::AlignRight | Qt::AlignVCenter);
Shinya Kitaoka 120a6e
      dpiLayout->addWidget(m_imageResLabel, 6, 1, 1, 3);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    dpiLayout->setColumnStretch(0, 0);
Shinya Kitaoka 120a6e
    dpiLayout->setColumnStretch(1, 1);
Shinya Kitaoka 120a6e
    dpiLayout->setColumnStretch(2, 0);
Shinya Kitaoka 120a6e
    dpiLayout->setColumnStretch(3, 1);
Shinya Kitaoka 120a6e
    dpiBox->setLayout(dpiLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_topLayout->addWidget(dpiBox);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_topLayout->addWidget(m_doPremultiply);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_topLayout->addWidget(m_whiteTransp);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_topLayout->addWidget(m_doAntialias);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    //---subsampling
Shinya Kitaoka 120a6e
    QGridLayout *bottomLay = new QGridLayout();
Shinya Kitaoka 120a6e
    bottomLay->setMargin(3);
Shinya Kitaoka 120a6e
    bottomLay->setSpacing(3);
Shinya Kitaoka 120a6e
    {
shun-iwasawa 29ceb2
      bottomLay->addWidget(m_softnessLabel, 0, 0);
Shinya Kitaoka 120a6e
      bottomLay->addWidget(m_antialiasSoftness, 0, 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      bottomLay->addWidget(m_subsamplingLabel, 1, 0);
Shinya Kitaoka 120a6e
      bottomLay->addWidget(m_subsamplingFld, 1, 1);
shun-iwasawa 481b59
shun-iwasawa 481b59
      bottomLay->addWidget(m_colorSpaceGammaLabel, 2, 0);
shun-iwasawa 481b59
      bottomLay->addWidget(m_colorSpaceGammaFld, 2, 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    bottomLay->setColumnStretch(0, 0);
Shinya Kitaoka 120a6e
    bottomLay->setColumnStretch(1, 0);
Shinya Kitaoka 120a6e
    bottomLay->setColumnStretch(2, 1);
Shinya Kitaoka 120a6e
    m_topLayout->addLayout(bottomLay);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_topLayout->addStretch();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----signal/slot connections
Shinya Kitaoka 120a6e
  connect(m_nameFld, SIGNAL(editingFinished()), SLOT(onNameChanged()));
Shinya Kitaoka 120a6e
  connect(m_pathFld, SIGNAL(pathChanged()), SLOT(onPathChanged()));
shun-iwasawa 29ceb2
  connect(m_dpiTypeOm, SIGNAL(activated(int)), SLOT(onDpiTypeChanged(int)));
Shinya Kitaoka 120a6e
  connect(m_dpiFld, SIGNAL(editingFinished()), SLOT(onDpiFieldChanged()));
Shinya Kitaoka 120a6e
  connect(m_squarePixCB, SIGNAL(stateChanged(int)),
Shinya Kitaoka 120a6e
          SLOT(onSquarePixelChanged(int)));
shun-iwasawa 29ceb2
  connect(m_widthFld, SIGNAL(valueChanged()), SLOT(onWidthFieldChanged()));
shun-iwasawa 29ceb2
  connect(m_heightFld, SIGNAL(valueChanged()), SLOT(onHeightFieldChanged()));
Shinya Kitaoka 120a6e
  connect(m_useCameraDpiBtn, SIGNAL(clicked()), SLOT(useCameraDpi()));
Shinya Kitaoka 120a6e
  connect(m_subsamplingFld, SIGNAL(editingFinished()),
Shinya Kitaoka 120a6e
          SLOT(onSubsamplingChanged()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*--- ScanPathの入力に対応 ---*/
Shinya Kitaoka 120a6e
  connect(m_scanPathFld, SIGNAL(pathChanged()), SLOT(onScanPathChanged()));
shun-iwasawa 29ceb2
  connect(m_doPremultiply, SIGNAL(clicked(bool)),
shun-iwasawa 29ceb2
          SLOT(onDoPremultiplyClicked()));
shun-iwasawa 29ceb2
  connect(m_doAntialias, SIGNAL(clicked(bool)), SLOT(onDoAntialiasClicked()));
Shinya Kitaoka 120a6e
  connect(m_antialiasSoftness, SIGNAL(editingFinished()),
Shinya Kitaoka 120a6e
          SLOT(onAntialiasSoftnessChanged()));
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  connect(m_whiteTransp, SIGNAL(clicked(bool)), SLOT(onWhiteTranspClicked()));
Shinya Kitaoka 120a6e
shun-iwasawa 481b59
  connect(m_colorSpaceGammaFld, SIGNAL(editingFinished()),
shun-iwasawa 481b59
          SLOT(onColorSpaceGammaFieldChanged()));
Shinya Kitaoka 120a6e
  updateLevelSettings();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::showEvent(QShowEvent *e) {
Shinya Kitaoka 120a6e
  bool ret =
Shinya Kitaoka 120a6e
      connect(TApp::instance()->getCurrentSelection(),
Shinya Kitaoka 120a6e
              SIGNAL(selectionSwitched(TSelection *, TSelection *)), this,
Shinya Kitaoka 120a6e
              SLOT(onSelectionSwitched(TSelection *, TSelection *)));
Shinya Kitaoka 120a6e
  ret = ret && connect(TApp::instance()->getCurrentSelection(),
Shinya Kitaoka 120a6e
                       SIGNAL(selectionChanged(TSelection *)),
Shinya Kitaoka 120a6e
                       SLOT(updateLevelSettings()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CastSelection *castSelection = dynamic_cast<castselection *="">(</castselection>
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentSelection()->getSelection());
Shinya Kitaoka 120a6e
  if (castSelection)
Shinya Kitaoka 120a6e
    ret = ret && connect(castSelection, SIGNAL(itemSelectionChanged()), this,
Shinya Kitaoka 120a6e
                         SLOT(onCastSelectionChanged()));
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  // update level settings after cleanup by this connection
Shinya Kitaoka 120a6e
  ret = ret && connect(TApp::instance()->getCurrentScene(),
Shinya Kitaoka 120a6e
                       SIGNAL(sceneChanged()), SLOT(onSceneChanged()));
shun-iwasawa 29ceb2
  ret = ret && connect(TApp::instance()->getCurrentScene(),
shun-iwasawa 29ceb2
                       SIGNAL(preferenceChanged(const QString &)),
shun-iwasawa 29ceb2
                       SLOT(onPreferenceChanged(const QString &)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
  updateLevelSettings();
shun-iwasawa 29ceb2
  onPreferenceChanged("");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::hideEvent(QHideEvent *e) {
Shinya Kitaoka 120a6e
  bool ret =
Shinya Kitaoka 120a6e
      disconnect(TApp::instance()->getCurrentSelection(),
Shinya Kitaoka 120a6e
                 SIGNAL(selectionSwitched(TSelection *, TSelection *)), this,
Shinya Kitaoka 120a6e
                 SLOT(onSelectionSwitched(TSelection *, TSelection *)));
Shinya Kitaoka 120a6e
  ret = ret && disconnect(TApp::instance()->getCurrentSelection(),
Shinya Kitaoka 120a6e
                          SIGNAL(selectionChanged(TSelection *)), this,
Shinya Kitaoka 120a6e
                          SLOT(updateLevelSettings()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CastSelection *castSelection = dynamic_cast<castselection *="">(</castselection>
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentSelection()->getSelection());
Shinya Kitaoka 120a6e
  if (castSelection)
Shinya Kitaoka 120a6e
    ret = ret && disconnect(castSelection, SIGNAL(itemSelectionChanged()), this,
Shinya Kitaoka 120a6e
                            SLOT(onCastSelectionChanged()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ret = ret && disconnect(TApp::instance()->getCurrentScene(),
Shinya Kitaoka 120a6e
                          SIGNAL(sceneChanged()), this, SLOT(onSceneChanged()));
shun-iwasawa 29ceb2
  ret = ret && disconnect(TApp::instance()->getCurrentScene(),
shun-iwasawa 29ceb2
                          SIGNAL(preferenceChanged(const QString &)), this,
shun-iwasawa 29ceb2
                          SLOT(onPreferenceChanged(const QString &)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
  Dialog::hideEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onSceneChanged() { updateLevelSettings(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 29ceb2
void LevelSettingsPopup::onPreferenceChanged(const QString &propertyName) {
shun-iwasawa 29ceb2
  if (!propertyName.isEmpty() && propertyName != "pixelsOnly") return;
shun-iwasawa 29ceb2
  bool pixelsMode = Preferences::instance()->getBoolValue(pixelsOnly);
shun-iwasawa 29ceb2
  QMap<qwidget *,="" int="" unsigned="">::iterator i = m_activateFlags.begin();</qwidget>
shun-iwasawa 29ceb2
  while (i != m_activateFlags.end()) {
shun-iwasawa 29ceb2
    if (i.value() & HideOnPixelMode) i.key()->setHidden(pixelsMode);
shun-iwasawa 29ceb2
    ++i;
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  int decimals = (pixelsMode) ? 0 : 4;
shun-iwasawa 29ceb2
  m_widthFld->setDecimals(decimals);
shun-iwasawa 29ceb2
  m_heightFld->setDecimals(decimals);
shun-iwasawa c9a4a1
  adjustSize();
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
//-----------------------------------------------------------------------------
shun-iwasawa 29ceb2
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onCastSelectionChanged() { updateLevelSettings(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onSelectionSwitched(TSelection *oldSelection,
Shinya Kitaoka 120a6e
                                             TSelection *newSelection) {
Shinya Kitaoka 120a6e
  CastSelection *castSelection = dynamic_cast<castselection *="">(newSelection);</castselection>
Shinya Kitaoka 120a6e
  if (!castSelection) {
Shinya Kitaoka 120a6e
    CastSelection *oldCastSelection =
Shinya Kitaoka 120a6e
        dynamic_cast<castselection *="">(oldSelection);</castselection>
Shinya Kitaoka 120a6e
    if (oldCastSelection)
Shinya Kitaoka 120a6e
      disconnect(oldCastSelection, SIGNAL(itemSelectionChanged()), this,
Shinya Kitaoka 120a6e
                 SLOT(onCastSelectionChanged()));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  connect(castSelection, SIGNAL(itemSelectionChanged()), this,
Shinya Kitaoka 120a6e
          SLOT(onCastSelectionChanged()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 29ceb2
SelectedLevelType LevelSettingsPopup::getType(TXshLevelP level_p) {
shun-iwasawa 29ceb2
  if (!level_p) return None;
shun-iwasawa 29ceb2
  switch (level_p->getType()) {
shun-iwasawa 29ceb2
  case TZP_XSHLEVEL:
shun-iwasawa 29ceb2
    return ToonzRaster;
shun-iwasawa 481b59
  case OVL_XSHLEVEL: {
shun-iwasawa 481b59
    if (level_p->getPath().getType() == "exr")
shun-iwasawa 481b59
      return LinearRaster;
shun-iwasawa 481b59
    else
shun-iwasawa 481b59
      return NonLinearRaster;
shun-iwasawa 481b59
  }
shun-iwasawa 29ceb2
  case MESH_XSHLEVEL:
shun-iwasawa 29ceb2
    return Mesh;
shun-iwasawa 29ceb2
  case PLI_XSHLEVEL:
shun-iwasawa 29ceb2
    return ToonzVector;
shun-iwasawa 29ceb2
  case PLT_XSHLEVEL:
shun-iwasawa 29ceb2
    return Palette;
shun-iwasawa 29ceb2
  case CHILD_XSHLEVEL:
shun-iwasawa 29ceb2
    return SubXsheet;
shun-iwasawa 29ceb2
  case SND_XSHLEVEL:
shun-iwasawa 29ceb2
    return Sound;
shun-iwasawa 29ceb2
  default:  // Other types are not supported
shun-iwasawa 29ceb2
    return Others;
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
LevelSettingsValues LevelSettingsPopup::getValues(TXshLevelP level) {
shun-iwasawa 29ceb2
  LevelSettingsValues values;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  values.name = QString::fromStdWString(level->getName());
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  TXshSimpleLevelP sl         = level->getSimpleLevel();
shun-iwasawa 29ceb2
  TXshPaletteLevelP pl        = level->getPaletteLevel();
shun-iwasawa 29ceb2
  TXshChildLevelP cl          = level->getChildLevel();
shun-iwasawa 29ceb2
  TXshSoundLevelP sdl         = level->getSoundLevel();
shun-iwasawa 29ceb2
  SelectedLevelType levelType = getType(level);
shun-iwasawa 29ceb2
  // path
shun-iwasawa 29ceb2
  if (sl) {
shun-iwasawa 29ceb2
    values.path     = toQString(sl->getPath());
shun-iwasawa 29ceb2
    values.scanPath = toQString(sl->getScannedPath());
shun-iwasawa 29ceb2
  } else if (pl)
shun-iwasawa 29ceb2
    values.path = toQString(pl->getPath());
shun-iwasawa 29ceb2
  else if (sdl)
shun-iwasawa 29ceb2
    values.path = toQString(sdl->getPath());
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // leveltype
shun-iwasawa 29ceb2
  switch (levelType) {
shun-iwasawa 29ceb2
  case ToonzRaster:
shun-iwasawa 29ceb2
    values.typeStr = tr("Toonz Raster level");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 481b59
  case NonLinearRaster:
shun-iwasawa 481b59
  case LinearRaster:
shun-iwasawa 29ceb2
    values.typeStr = tr("Raster level");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  case Mesh:
shun-iwasawa 29ceb2
    values.typeStr = tr("Mesh level");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  case ToonzVector:
shun-iwasawa 29ceb2
    values.typeStr = tr("Toonz Vector level");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  case Palette:
shun-iwasawa 29ceb2
    values.typeStr = tr("Palette level");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  case SubXsheet:
shun-iwasawa 29ceb2
    values.typeStr = tr("SubXsheet Level");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  case Sound:
shun-iwasawa 29ceb2
    values.typeStr = tr("Sound Column");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  default:
shun-iwasawa 29ceb2
    values.typeStr = tr("Another Level Type");
shun-iwasawa 29ceb2
    break;
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // dpi & res & resampling
shun-iwasawa 29ceb2
  if (levelType & HasDPILevel) {
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy dpiPolicy = sl->getProperties()->getDpiPolicy();
shun-iwasawa 29ceb2
    assert(dpiPolicy == LevelProperties::DP_ImageDpi ||
shun-iwasawa 29ceb2
           dpiPolicy == LevelProperties::DP_CustomDpi);
shun-iwasawa 29ceb2
    values.dpiType = (dpiPolicy == LevelProperties::DP_ImageDpi) ? 0 : 1;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    // dpi field
shun-iwasawa 29ceb2
    values.dpi = sl->getDpi();
shun-iwasawa 29ceb2
    // image dpi
shun-iwasawa 29ceb2
    values.imageDpi = dpiToString(sl->getImageDpi());
shun-iwasawa 29ceb2
shun-iwasawa 481b59
    if (levelType == ToonzRaster || levelType & Raster) {
shun-iwasawa 29ceb2
      // size field
shun-iwasawa 29ceb2
      TDimensionD size(0, 0);
shun-iwasawa 29ceb2
      TDimension res = sl->getResolution();
shun-iwasawa 29ceb2
      if (res.lx > 0 && res.ly > 0 && values.dpi.x > 0 && values.dpi.y > 0) {
shun-iwasawa 29ceb2
        size.lx       = res.lx / values.dpi.x;
shun-iwasawa 29ceb2
        size.ly       = res.ly / values.dpi.y;
shun-iwasawa 29ceb2
        values.width  = tround(size.lx * 100.0) / 100.0;
shun-iwasawa 29ceb2
        values.height = tround(size.ly * 100.0) / 100.0;
shun-iwasawa 29ceb2
      } else {
shun-iwasawa 29ceb2
        values.width  = -1.0;
shun-iwasawa 29ceb2
        values.height = -1.0;
shun-iwasawa 29ceb2
      }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
      // image res
shun-iwasawa 29ceb2
      TDimension imgRes = sl->getResolution();
shun-iwasawa 29ceb2
      values.imageRes =
shun-iwasawa 29ceb2
          QString::number(imgRes.lx) + "x" + QString::number(imgRes.ly);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
      // subsampling
shun-iwasawa 29ceb2
      values.subsampling = sl->getProperties()->getSubsampling();
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
      values.doPremulti =
shun-iwasawa 29ceb2
          (sl->getProperties()->doPremultiply()) ? Qt::Checked : Qt::Unchecked;
shun-iwasawa 29ceb2
      values.whiteTransp =
shun-iwasawa 29ceb2
          (sl->getProperties()->whiteTransp()) ? Qt::Checked : Qt::Unchecked;
shun-iwasawa 29ceb2
      values.doAntialias = (sl->getProperties()->antialiasSoftness() > 0)
shun-iwasawa 29ceb2
                               ? Qt::Checked
shun-iwasawa 29ceb2
                               : Qt::Unchecked;
shun-iwasawa 08548b
      values.softness    = sl->getProperties()->antialiasSoftness();
shun-iwasawa 481b59
shun-iwasawa 481b59
      if (levelType == LinearRaster)
shun-iwasawa 481b59
        values.colorSpaceGamma = sl->getProperties()->colorSpaceGamma();
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // gather dirty flags (subsampling is editable for only non-dirty levels)
shun-iwasawa 29ceb2
  if (sl && sl->getProperties()->getDirtyFlag()) values.isDirty = Qt::Checked;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  return values;
shun-iwasawa 29ceb2
}
shun-iwasawa 29ceb2
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Update popup value.
Shinya Kitaoka 120a6e
                Take current level and act on level type set popup value.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void LevelSettingsPopup::updateLevelSettings() {
Shinya Kitaoka 120a6e
  TApp *app = TApp::instance();
shun-iwasawa 29ceb2
  m_selectedLevels.clear();
Shinya Kitaoka 120a6e
  CastSelection *castSelection =
Shinya Kitaoka 120a6e
      dynamic_cast<castselection *="">(app->getCurrentSelection()->getSelection());</castselection>
Shinya Kitaoka 120a6e
  TCellSelection *cellSelection = dynamic_cast<tcellselection *="">(</tcellselection>
Shinya Kitaoka 120a6e
      app->getCurrentSelection()->getSelection());
Shinya Kitaoka 120a6e
  TColumnSelection *columnSelection = dynamic_cast<tcolumnselection *="">(</tcolumnselection>
Shinya Kitaoka 120a6e
      app->getCurrentSelection()->getSelection());
Shinya Kitaoka 120a6e
  FxSelection *fxSelection =
Shinya Kitaoka 120a6e
      dynamic_cast<fxselection *="">(app->getCurrentSelection()->getSelection());</fxselection>
shun-iwasawa 29ceb2
  // - - - Cell Selection
Shinya Kitaoka 120a6e
  if (cellSelection) {
Shinya Kitaoka 120a6e
    TXsheet *currentXsheet = app->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
    if (currentXsheet && !cellSelection->isEmpty()) {
Shinya Kitaoka 120a6e
      int r0, c0, r1, c1;
Shinya Kitaoka 120a6e
      cellSelection->getSelectedCells(r0, c0, r1, c1);
shun-iwasawa 29ceb2
      for (int c = c0; c <= c1; c++)
shun-iwasawa 29ceb2
        for (int r = r0; r <= r1; r++)
shun-iwasawa 29ceb2
          if (TXshLevelP level = currentXsheet->getCell(r, c).m_level)
shun-iwasawa 29ceb2
            m_selectedLevels.insert(level);
Shinya Kitaoka 120a6e
    } else
shun-iwasawa 29ceb2
      m_selectedLevels.insert(app->getCurrentLevel()->getLevel());
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  // - - - Column Selection
Shinya Kitaoka 120a6e
  else if (columnSelection) {
Shinya Kitaoka 120a6e
    TXsheet *currentXsheet = app->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
    if (currentXsheet && !columnSelection->isEmpty()) {
shun-iwasawa 29ceb2
      int sceneLength             = currentXsheet->getFrameCount();
Shinya Kitaoka 120a6e
      std::set<int> columnIndices = columnSelection->getIndices();</int>
Shinya Kitaoka 120a6e
      std::set<int>::iterator it;</int>
Shinya Kitaoka 120a6e
      for (it = columnIndices.begin(); it != columnIndices.end(); ++it) {
Shinya Kitaoka 120a6e
        int columnIndex = *it;
shun-iwasawa 29ceb2
        int r0, r1;
shun-iwasawa 29ceb2
        currentXsheet->getCellRange(columnIndex, r0, r1);
shun-iwasawa 29ceb2
        if (r1 < 0) continue;  // skip empty column
shun-iwasawa 29ceb2
        for (int r = r0; r <= r1; r++)
shun-iwasawa 29ceb2
          if (TXshLevelP level = currentXsheet->getCell(r, columnIndex).m_level)
shun-iwasawa 29ceb2
            m_selectedLevels.insert(level);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else
shun-iwasawa 29ceb2
      m_selectedLevels.insert(app->getCurrentLevel()->getLevel());
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  // - - - Cast Selection
shun-iwasawa 29ceb2
  else if (castSelection) {
Shinya Kitaoka 120a6e
    std::vector<txshlevel *=""> levels;</txshlevel>
Shinya Kitaoka 120a6e
    castSelection->getSelectedLevels(levels);
shun-iwasawa 29ceb2
    for (TXshLevel *level : levels) m_selectedLevels.insert(level);
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  // - - - Schematic Nodes Selection
Shinya Kitaoka 120a6e
  else if (fxSelection) {
Shinya Kitaoka 120a6e
    TXsheet *currentXsheet  = app->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
    QList<tfxp> selectedFxs = fxSelection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
    if (currentXsheet && !selectedFxs.isEmpty()) {
Shinya Kitaoka 120a6e
      for (int f = 0; f < selectedFxs.size(); f++) {
Shinya Kitaoka 120a6e
        TLevelColumnFx *lcfx =
Shinya Kitaoka 120a6e
            dynamic_cast<tlevelcolumnfx *="">(selectedFxs.at(f).getPointer());</tlevelcolumnfx>
Shinya Kitaoka 120a6e
        if (lcfx) {
shun-iwasawa 29ceb2
          int r0, r1;
shun-iwasawa 29ceb2
          int firstRow =
shun-iwasawa 29ceb2
              lcfx->getXshColumn()->getCellColumn()->getRange(r0, r1);
shun-iwasawa 29ceb2
          for (int r = r0; r <= r1; r++)
shun-iwasawa 29ceb2
            if (TXshLevelP level =
shun-iwasawa 29ceb2
                    lcfx->getXshColumn()->getCellColumn()->getCell(r).m_level)
shun-iwasawa 29ceb2
              m_selectedLevels.insert(level);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
shun-iwasawa 29ceb2
      if (m_selectedLevels.isEmpty())
shun-iwasawa 29ceb2
        m_selectedLevels.insert(app->getCurrentLevel()->getLevel());
Shinya Kitaoka 120a6e
    } else
shun-iwasawa 29ceb2
      m_selectedLevels.insert(app->getCurrentLevel()->getLevel());
Shinya Kitaoka 120a6e
  } else
shun-iwasawa 29ceb2
    m_selectedLevels.insert(app->getCurrentLevel()->getLevel());
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // Unite flags, Remove unsupported items
shun-iwasawa 29ceb2
  unsigned int levelTypeFlag         = 0;
shun-iwasawa 29ceb2
  QSet<txshlevelp>::iterator lvl_itr = m_selectedLevels.begin();</txshlevelp>
shun-iwasawa 29ceb2
  while (lvl_itr != m_selectedLevels.end()) {
shun-iwasawa 29ceb2
    SelectedLevelType type = getType(*lvl_itr);
shun-iwasawa 29ceb2
    if (type == None || type == Others)
shun-iwasawa 29ceb2
      lvl_itr = m_selectedLevels.erase(lvl_itr);
shun-iwasawa 29ceb2
    else {
shun-iwasawa 29ceb2
      levelTypeFlag |= type;
shun-iwasawa 29ceb2
      ++lvl_itr;
shun-iwasawa 29ceb2
    }
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  if (m_selectedLevels.count() >= 2)
shun-iwasawa 29ceb2
    levelTypeFlag |= MultiSelection;
shun-iwasawa 29ceb2
  else if (m_selectedLevels.isEmpty())
shun-iwasawa 29ceb2
    levelTypeFlag |= NoSelection;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // Enable / Disable all widgets
shun-iwasawa 29ceb2
  QMap<qwidget *,="" int="" unsigned="">::iterator w_itr = m_activateFlags.begin();</qwidget>
shun-iwasawa 29ceb2
  while (w_itr != m_activateFlags.end()) {
shun-iwasawa 29ceb2
    unsigned int activateFlag = w_itr.value();
shun-iwasawa 29ceb2
    w_itr.key()->setEnabled((levelTypeFlag & activateFlag) == levelTypeFlag);
shun-iwasawa 29ceb2
    ++w_itr;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  // Gather values
shun-iwasawa 29ceb2
  LevelSettingsValues values;
shun-iwasawa 29ceb2
  lvl_itr = m_selectedLevels.begin();
shun-iwasawa 29ceb2
  while (lvl_itr != m_selectedLevels.end()) {
shun-iwasawa 29ceb2
    TXshLevelP level            = *lvl_itr;
shun-iwasawa 29ceb2
    bool isFirst                = (lvl_itr == m_selectedLevels.begin());
shun-iwasawa 29ceb2
    LevelSettingsValues new_val = getValues(level);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    uniteValue(values.name, new_val.name, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.path, new_val.path, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.scanPath, new_val.scanPath, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.typeStr, new_val.typeStr, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.dpiType, new_val.dpiType, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.dpi, new_val.dpi, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.width, new_val.width, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.height, new_val.height, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.imageDpi, new_val.imageDpi, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.imageRes, new_val.imageRes, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.doPremulti, new_val.doPremulti, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.whiteTransp, new_val.whiteTransp, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.doAntialias, new_val.doAntialias, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.softness, new_val.softness, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.subsampling, new_val.subsampling, isFirst);
shun-iwasawa 481b59
    uniteValue(values.colorSpaceGamma, new_val.colorSpaceGamma, isFirst);
shun-iwasawa 29ceb2
    uniteValue(values.isDirty, new_val.isDirty, isFirst);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    ++lvl_itr;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_nameFld->setText(values.name);
shun-iwasawa 29ceb2
  m_pathFld->setPath(values.path);
shun-iwasawa 29ceb2
  m_scanPathFld->setPath(values.scanPath);
shun-iwasawa 29ceb2
  m_typeLabel->setText(values.typeStr);
shun-iwasawa 29ceb2
  m_dpiTypeOm->setCurrentIndex(values.dpiType);
shun-iwasawa 29ceb2
  m_dpiFld->setText(dpiToString(values.dpi));
shun-iwasawa 29ceb2
  if (values.width <= 0.0) {
shun-iwasawa 29ceb2
    m_widthFld->setValue(0.0);
shun-iwasawa 29ceb2
    m_widthFld->setText((values.width < 0.0) ? tr("[Various]") : tr(""));
shun-iwasawa 29ceb2
  } else
shun-iwasawa 29ceb2
    m_widthFld->setValue(values.width);
shun-iwasawa 29ceb2
  if (values.height <= 0.0) {
shun-iwasawa 29ceb2
    m_heightFld->setValue(0.0);
shun-iwasawa 29ceb2
    m_heightFld->setText((values.height < 0.0) ? tr("[Various]") : tr(""));
shun-iwasawa 29ceb2
  } else
shun-iwasawa 29ceb2
    m_heightFld->setValue(values.height);
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  m_cameraDpiLabel->setText(dpiToString(getCurrentCameraDpi()));
shun-iwasawa 29ceb2
  m_imageDpiLabel->setText(values.imageDpi);
shun-iwasawa 29ceb2
  m_imageResLabel->setText(values.imageRes);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  m_doPremultiply->setCheckState(values.doPremulti);
shun-iwasawa 29ceb2
  m_whiteTransp->setCheckState(values.whiteTransp);
shun-iwasawa 29ceb2
  m_doAntialias->setCheckState(values.doAntialias);
shun-iwasawa 29ceb2
  if (values.softness < 0)
shun-iwasawa 29ceb2
    m_antialiasSoftness->setText("");
shun-iwasawa 29ceb2
  else
shun-iwasawa 29ceb2
    m_antialiasSoftness->setValue(values.softness);
shun-iwasawa 29ceb2
  if (values.subsampling < 0)
shun-iwasawa 29ceb2
    m_subsamplingFld->setText("");
shun-iwasawa 29ceb2
  else
shun-iwasawa 29ceb2
    m_subsamplingFld->setValue(values.subsampling);
shun-iwasawa 481b59
shun-iwasawa 481b59
  if (values.colorSpaceGamma > 0)
shun-iwasawa 481b59
    m_colorSpaceGammaFld->setValue(values.colorSpaceGamma);
shun-iwasawa 481b59
  else if (m_colorSpaceGammaFld->isEnabled())
shun-iwasawa 481b59
    m_colorSpaceGammaFld->setText(tr("[Various]"));
shun-iwasawa 481b59
  else
shun-iwasawa 481b59
    m_colorSpaceGammaFld->setText("");
shun-iwasawa 481b59
shun-iwasawa 29ceb2
  // disable the softness field when the antialias is not active
shun-iwasawa 29ceb2
  if (m_doAntialias->checkState() != Qt::Checked)
shun-iwasawa 29ceb2
    m_antialiasSoftness->setDisabled(true);
shun-iwasawa 29ceb2
  // disable the subsampling field when dirty level is selected
shun-iwasawa 481b59
  if (values.isDirty != Qt::Unchecked) {
shun-iwasawa 481b59
    m_subsamplingFld->setDisabled(true);
shun-iwasawa 481b59
    m_colorSpaceGammaFld->setDisabled(true);
shun-iwasawa 481b59
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onNameChanged() {
shun-iwasawa 29ceb2
  assert(m_selectedLevels.size() == 1);
shun-iwasawa 29ceb2
  if (m_selectedLevels.size() != 1) return;
shun-iwasawa 29ceb2
  QString text = m_nameFld->text();
Shinya Kitaoka 120a6e
  if (text.length() == 0) {
Shinya Kitaoka 120a6e
    error("The name " + text +
Shinya Kitaoka 120a6e
          " you entered for the level is not valid.\n Please enter a different "
Shinya Kitaoka 120a6e
          "name.");
Jeremy Bullock 2a4168
    m_nameFld->setFocus();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  TXshLevel *level = m_selectedLevels.begin()->getPointer();
shun-iwasawa 29ceb2
  if ((getType(level) & (SimpleLevel | SubXsheet)) == 0) return;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  // in case the level name is not changed
shun-iwasawa 29ceb2
  QString oldName = QString::fromStdWString(level->getName());
shun-iwasawa 29ceb2
  if (oldName == text) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TLevelSet *levelSet =
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
Shinya Kitaoka 120a6e
shun-iwasawa 409dec
  TUndoManager::manager()->beginBlock();
shun-iwasawa 409dec
shun-iwasawa 409dec
  // remove existing & unused level
shun-iwasawa 409dec
  if (Preferences::instance()->isAutoRemoveUnusedLevelsEnabled()) {
shun-iwasawa 409dec
    TXshLevel *existingLevel = levelSet->getLevel(text.toStdWString());
shun-iwasawa 409dec
    if (existingLevel &&
shun-iwasawa 409dec
        LevelCmd::removeLevelFromCast(existingLevel, nullptr, false))
shun-iwasawa 409dec
      DVGui::info(QObject::tr("Removed unused level %1 from the scene cast. "
shun-iwasawa 409dec
                              "(This behavior can be disabled in Preferences.)")
shun-iwasawa 409dec
                      .arg(text));
shun-iwasawa 409dec
  }
shun-iwasawa 409dec
Shinya Kitaoka 120a6e
  if (!levelSet->renameLevel(level, text.toStdWString())) {
Shinya Kitaoka 120a6e
    error("The name " + text +
Shinya Kitaoka 120a6e
          " you entered for the level is already used.\nPlease enter a "
Shinya Kitaoka 120a6e
          "different name.");
Jeremy Bullock 2a4168
    m_nameFld->setFocus();
shun-iwasawa f404fb
    TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  TUndoManager::manager()->add(
shun-iwasawa 29ceb2
      new LevelSettingsUndo(level, LevelSettingsUndo::Name, oldName, text));
shun-iwasawa 29ceb2
shun-iwasawa 409dec
  TUndoManager::manager()->endBlock();
shun-iwasawa 409dec
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->notifyCastChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onPathChanged() {
shun-iwasawa 29ceb2
  assert(m_selectedLevels.size() == 1);
shun-iwasawa 29ceb2
  if (m_selectedLevels.size() != 1) return;
shun-iwasawa 29ceb2
  TXshLevelP levelP = *m_selectedLevels.begin();
shun-iwasawa 29ceb2
  if ((m_activateFlags[m_pathFld] & getType(levelP)) == 0) return;
shun-iwasawa 29ceb2
Shinya Kitaoka 120a6e
  QString text = m_pathFld->getPath();
Shinya Kitaoka 120a6e
  TFilePath newPath(text.toStdWString());
Shinya Kitaoka 120a6e
  newPath =
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentScene()->getScene()->codeFilePath(newPath);
Shinya Kitaoka 120a6e
  m_pathFld->setPath(QString::fromStdWString(newPath.getWideString()));
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  TXshSoundLevelP sdl = levelP->getSoundLevel();
shun-iwasawa 29ceb2
  if (sdl) {
Shinya Kitaoka 120a6e
    // old level is a sound level
Shinya Kitaoka 120a6e
    TFileType::Type levelType = TFileType::getInfo(newPath);
Shinya Kitaoka 120a6e
    if (levelType == TFileType::AUDIO_LEVEL) {
shun-iwasawa 29ceb2
      TFilePath oldPath = sdl->getPath();
Shinya Kitaoka 120a6e
      if (oldPath == newPath) return;
shun-iwasawa 29ceb2
      sdl->setPath(newPath);
shun-iwasawa 29ceb2
      sdl->loadSoundTrack();
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged();
shun-iwasawa 29ceb2
      TUndoManager::manager()->add(
shun-iwasawa 29ceb2
          new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::Path,
shun-iwasawa 29ceb2
                                oldPath.getQString(), newPath.getQString()));
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      error(tr("The file %1 is not a sound level.")
Shinya Kitaoka 120a6e
                .arg(QString::fromStdWString(newPath.getLevelNameW())));
Shinya Kitaoka 120a6e
      updateLevelSettings();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  TXshSimpleLevelP sl  = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
  TXshPaletteLevelP pl = levelP->getPaletteLevel();
shun-iwasawa 29ceb2
  if (!sl && !pl) return;
shun-iwasawa 29ceb2
  TFilePath oldPath = (sl) ? sl->getPath() : pl->getPath();
Shinya Kitaoka 120a6e
  if (oldPath == newPath) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TLevelSet *levelSet =
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
shun-iwasawa 29ceb2
  TXshLevel *lvlWithSamePath = nullptr;
Shinya Kitaoka 120a6e
  for (int i = 0; i < levelSet->getLevelCount(); i++) {
shun-iwasawa 29ceb2
    TXshLevel *tmpLvl = levelSet->getLevel(i);
shun-iwasawa 29ceb2
    if (!tmpLvl) continue;
shun-iwasawa 29ceb2
    if (tmpLvl == levelP.getPointer()) continue;
shun-iwasawa 29ceb2
    TXshSimpleLevelP tmpSl  = tmpLvl->getSimpleLevel();
shun-iwasawa 29ceb2
    TXshPaletteLevelP tmpPl = tmpLvl->getPaletteLevel();
shun-iwasawa 29ceb2
    if (!tmpSl && !tmpPl) continue;
shun-iwasawa 29ceb2
    TFilePath tmpPath = (tmpSl) ? tmpSl->getPath() : tmpPl->getPath();
shun-iwasawa 29ceb2
    if (tmpPath == newPath) {
shun-iwasawa 29ceb2
      lvlWithSamePath = tmpLvl;
shun-iwasawa 29ceb2
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  if (lvlWithSamePath) {
Shinya Kitaoka 120a6e
    QString question;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    question = "The path you entered for the level " +
shun-iwasawa 29ceb2
               QString(::to_string(lvlWithSamePath->getName()).c_str()) +
Shinya Kitaoka 120a6e
               "is already used: this may generate some conflicts in the file "
Shinya Kitaoka 120a6e
               "management.\nAre you sure you want to assign the same path to "
Shinya Kitaoka 120a6e
               "two different levels?";
Shinya Kitaoka 120a6e
    int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No"));
Shinya Kitaoka 120a6e
    if (ret == 0 || ret == 2) {
shun-iwasawa 29ceb2
      m_pathFld->setPath(toQString(oldPath));
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFileType::Type oldType = TFileType::getInfo(oldPath);
Shinya Kitaoka 120a6e
  TFileType::Type newType = TFileType::getInfo(newPath);
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  if (sl && sl->getType() == TZP_XSHLEVEL &&
shun-iwasawa 29ceb2
      sl->getScannedPath() != TFilePath()) {
shun-iwasawa 29ceb2
    if (newPath == TFilePath() || newPath == sl->getScannedPath()) {
shun-iwasawa 29ceb2
      newPath = sl->getScannedPath();
shun-iwasawa 29ceb2
      sl->setType(OVL_XSHLEVEL);
shun-iwasawa 29ceb2
      sl->setScannedPath(TFilePath());
shun-iwasawa 29ceb2
      sl->setPath(newPath);
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentScene()->notifyCastChange();
Shinya Kitaoka 120a6e
      updateLevelSettings();
shun-iwasawa 29ceb2
      sl->invalidateFrames();
Shinya Kitaoka 120a6e
      std::vector<tframeid> frames;</tframeid>
shun-iwasawa 29ceb2
      sl->getFids(frames);
Shinya Kitaoka 120a6e
      for (auto const &fid : frames) {
shun-iwasawa 29ceb2
        IconGenerator::instance()->invalidate(sl.getPointer(), fid);
Shinya Kitaoka 120a6e
      }
shun-iwasawa 29ceb2
      TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
      TUndoManager::manager()->add(
shun-iwasawa 29ceb2
          new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::Path,
shun-iwasawa 29ceb2
                                oldPath.getQString(), newPath.getQString()));
shun-iwasawa 29ceb2
      TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
          levelP.getPointer(), LevelSettingsUndo::ScanPath,
shun-iwasawa 29ceb2
          newPath.getQString(), QString()));
shun-iwasawa 29ceb2
      TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
          levelP.getPointer(), LevelSettingsUndo::LevelType, TZP_XSHLEVEL,
shun-iwasawa 29ceb2
          OVL_XSHLEVEL));
shun-iwasawa 29ceb2
      TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (oldType != newType ||
shun-iwasawa 29ceb2
      (sl && sl->getType() == TZP_XSHLEVEL && newPath.getType() != "tlv") ||
shun-iwasawa 29ceb2
      (sl && sl->getType() != TZP_XSHLEVEL && newPath.getType() == "tlv") ||
shun-iwasawa 29ceb2
      (pl && newPath.getType() != "tpl")) {
Shinya Kitaoka 120a6e
    error("Wrong path");
shun-iwasawa 29ceb2
    m_pathFld->setPath(toQString(oldPath));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  //-- update the path here
shun-iwasawa 29ceb2
  if (sl) {
shun-iwasawa 29ceb2
    sl->setPath(newPath);
shun-iwasawa 29ceb2
    TApp::instance()
shun-iwasawa 29ceb2
        ->getPaletteController()
shun-iwasawa 29ceb2
        ->getCurrentLevelPalette()
shun-iwasawa 29ceb2
        ->setPalette(sl->getPalette());
shun-iwasawa 29ceb2
    sl->invalidateFrames();
shun-iwasawa 29ceb2
    std::vector<tframeid> frames;</tframeid>
shun-iwasawa 29ceb2
    sl->getFids(frames);
shun-iwasawa 29ceb2
    for (auto const &fid : frames) {
shun-iwasawa 29ceb2
      IconGenerator::instance()->invalidate(sl.getPointer(), fid);
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
  } else if (pl) {
shun-iwasawa 29ceb2
    pl->setPath(newPath);
shun-iwasawa 29ceb2
    TApp::instance()
shun-iwasawa 29ceb2
        ->getPaletteController()
shun-iwasawa 29ceb2
        ->getCurrentLevelPalette()
shun-iwasawa 29ceb2
        ->setPalette(pl->getPalette());
shun-iwasawa 29ceb2
    pl->load();
shun-iwasawa 29ceb2
  }
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->notifySceneChanged();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
  updateLevelSettings();
shun-iwasawa 29ceb2
  TUndoManager::manager()->add(
shun-iwasawa 29ceb2
      new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::Path,
shun-iwasawa 29ceb2
                            oldPath.getQString(), newPath.getQString()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onScanPathChanged() {
shun-iwasawa 29ceb2
  assert(m_selectedLevels.size() == 1);
shun-iwasawa 29ceb2
  if (m_selectedLevels.size() != 1) return;
shun-iwasawa 29ceb2
  TXshLevelP levelP   = *m_selectedLevels.begin();
shun-iwasawa 29ceb2
  TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
  if (!sl || sl->getType() != TZP_XSHLEVEL) return;
shun-iwasawa 29ceb2
Shinya Kitaoka 120a6e
  QString text = m_scanPathFld->getPath();
Shinya Kitaoka 120a6e
  TFilePath newScanPath(text.toStdWString());
Shinya Kitaoka 120a6e
luz paz 6454c4
  // limit the available formats for now
Shinya Kitaoka 120a6e
  if (newScanPath.getType() != "tif" && newScanPath.getType() != "tiff" &&
Shinya Kitaoka 120a6e
      newScanPath.getType() != "tzi") {
shun-iwasawa 29ceb2
    m_scanPathFld->setPath(toQString(sl->getScannedPath()));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  newScanPath = TApp::instance()->getCurrentScene()->getScene()->codeFilePath(
Shinya Kitaoka 120a6e
      newScanPath);
Shinya Kitaoka 120a6e
  m_scanPathFld->setPath(QString::fromStdWString(newScanPath.getWideString()));
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  TFilePath oldScanPath = sl->getScannedPath();
Shinya Kitaoka 120a6e
  if (oldScanPath == newScanPath) return;
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  // check if the "Cleanup Settings > SaveIn" value is the same as the current
shun-iwasawa 29ceb2
  // level
Shinya Kitaoka 120a6e
  TFilePath settingsPath =
Shinya Kitaoka 120a6e
      (newScanPath.getParentDir() + newScanPath.getName()).withType("cln");
Shinya Kitaoka 120a6e
  settingsPath =
Shinya Kitaoka 120a6e
      TApp::instance()->getCurrentScene()->getScene()->decodeFilePath(
Shinya Kitaoka 120a6e
          settingsPath);
Shinya Kitaoka 120a6e
  if (TSystem::doesExistFileOrLevel(settingsPath)) {
Shinya Kitaoka 120a6e
    TIStream is(settingsPath);
Shinya Kitaoka 120a6e
    TFilePath cleanupLevelPath;
Shinya Kitaoka 120a6e
    std::string tagName;
Shinya Kitaoka 120a6e
    while (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
      if (tagName == "cleanupPalette" || tagName == "cleanupCamera" ||
Shinya Kitaoka 120a6e
          tagName == "autoCenter" || tagName == "transform" ||
Shinya Kitaoka 120a6e
          tagName == "lineProcessing" || tagName == "closestField" ||
Shinya Kitaoka 120a6e
          tagName == "fdg") {
Shinya Kitaoka 120a6e
        is.skipCurrentTag();
Shinya Kitaoka 120a6e
      } else if (tagName == "path") {
Shinya Kitaoka 120a6e
        is >> cleanupLevelPath;
Shinya Kitaoka 120a6e
        is.closeChild();
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        std::cout << "mismatch tag:" << tagName << std::endl;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (cleanupLevelPath != TFilePath()) {
Shinya Kitaoka 120a6e
      TFilePath codedCleanupLevelPath =
Shinya Kitaoka 120a6e
          TApp::instance()->getCurrentScene()->getScene()->codeFilePath(
Shinya Kitaoka 120a6e
              cleanupLevelPath);
shun-iwasawa 29ceb2
      if (sl->getPath().getParentDir() != cleanupLevelPath &&
shun-iwasawa 29ceb2
          sl->getPath().getParentDir() != codedCleanupLevelPath)
Shinya Kitaoka 120a6e
        DVGui::warning(
Shinya Kitaoka 120a6e
            "\"Save In\" path of the Cleanup Settings does not match.");
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      DVGui::warning("Loading Cleanup Settings failed.");
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    DVGui::warning(".cln file for the Scanned Level not found.");
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  sl->setScannedPath(newScanPath);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
Shinya Kitaoka 120a6e
  updateLevelSettings();
shun-iwasawa 29ceb2
  TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
      levelP.getPointer(), LevelSettingsUndo::ScanPath,
shun-iwasawa 29ceb2
      oldScanPath.getQString(), newScanPath.getQString()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa e87e08
void LevelSettingsPopup::onDpiTypeChanged(int index) {
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    QString dpiPolicyStr = m_dpiTypeOm->itemData(index).toString();
shun-iwasawa 29ceb2
    assert(dpiPolicyStr == "Custom DPI" || dpiPolicyStr == "Image DPI");
shun-iwasawa 29ceb2
    LevelProperties *prop = sl->getProperties();
shun-iwasawa 29ceb2
    // dpiPolicyStr ==> dpiPolicy
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy dpiPolicy = dpiPolicyStr == "Custom DPI"
shun-iwasawa 29ceb2
                                               ? LevelProperties::DP_CustomDpi
shun-iwasawa 29ceb2
                                               : LevelProperties::DP_ImageDpi;
shun-iwasawa 29ceb2
    // se ImageDpi, ma l'immagine non ha dpi -> CustomDpi
shun-iwasawa 29ceb2
    assert(dpiPolicy == LevelProperties::DP_CustomDpi ||
shun-iwasawa 29ceb2
           sl->getImageDpi().x > 0.0 && sl->getImageDpi().y > 0.0);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    if (prop->getDpiPolicy() == dpiPolicy) continue;
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy oldPolicy = prop->getDpiPolicy();
shun-iwasawa 29ceb2
    prop->setDpiPolicy(dpiPolicy);
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::DpiType, oldPolicy, dpiPolicy));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
shun-iwasawa 29ceb2
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateLevelSettings();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onDpiFieldChanged() {
shun-iwasawa 29ceb2
  QString w     = m_dpiFld->text();
Shinya Kitaoka 120a6e
  std::string s = w.toStdString();
Shinya Kitaoka 120a6e
  TPointD dpi;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i = 0, len = s.length();
Shinya Kitaoka 120a6e
  while (i < len && s[i] == ' ') i++;
Shinya Kitaoka 120a6e
  int j = i;
Shinya Kitaoka 120a6e
  while (j < len && '0' <= s[j] && s[j] <= '9') j++;
Shinya Kitaoka 120a6e
  if (j < len && s[j] == '.') {
Shinya Kitaoka 120a6e
    j++;
Shinya Kitaoka 120a6e
    while (j < len && '0' <= s[j] && s[j] <= '9') j++;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (i < j) {
Shinya Kitaoka 120a6e
    dpi.x = std::stod(s.substr(i, j - i));
Shinya Kitaoka 120a6e
    i     = j;
Shinya Kitaoka 120a6e
    while (i < len && s[i] == ' ') i++;
Shinya Kitaoka 120a6e
    if (i < len && s[i] == ',') {
Shinya Kitaoka 120a6e
      i++;
Shinya Kitaoka 120a6e
      while (i < len && s[i] == ' ') i++;
Shinya Kitaoka 120a6e
      dpi.y = std::stod(s.substr(i));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  if (dpi.x <= 0.0) {
shun-iwasawa 29ceb2
    updateLevelSettings();
shun-iwasawa 29ceb2
    return;
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  if (dpi.y == 0.0) dpi.y = dpi.x;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    TPointD oldDpi = sl->getProperties()->getDpi();
shun-iwasawa 29ceb2
    if (oldDpi == dpi) continue;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy oldPolicy = sl->getProperties()->getDpiPolicy();
shun-iwasawa 29ceb2
    sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi);
shun-iwasawa 29ceb2
    sl->getProperties()->setDpi(dpi);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::DpiType,
shun-iwasawa 29ceb2
                              oldPolicy, LevelProperties::DP_CustomDpi));
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::Dpi,
shun-iwasawa 29ceb2
        QPointF(oldDpi.x, oldDpi.y), QPointF(dpi.x, dpi.y)));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  updateLevelSettings();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onSquarePixelChanged(int value) {
Shinya Kitaoka 120a6e
  if (!value) return;
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    TPointD oldDpi = sl->getDpi();
shun-iwasawa 29ceb2
    if (areAlmostEqual(oldDpi.x, oldDpi.y)) continue;
shun-iwasawa 29ceb2
    TPointD dpi(oldDpi.x, oldDpi.x);
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy oldPolicy = sl->getProperties()->getDpiPolicy();
shun-iwasawa 29ceb2
    sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi);
shun-iwasawa 29ceb2
    sl->getProperties()->setDpi(dpi);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::DpiType,
shun-iwasawa 29ceb2
                              oldPolicy, LevelProperties::DP_CustomDpi));
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::Dpi,
shun-iwasawa 29ceb2
        QPointF(oldDpi.x, oldDpi.y), QPointF(dpi.x, dpi.y)));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  updateLevelSettings();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onWidthFieldChanged() {
shun-iwasawa 29ceb2
  double lx = m_widthFld->getValue();
Shinya Kitaoka 120a6e
  if (lx <= 0) {
shun-iwasawa 29ceb2
    updateLevelSettings();
shun-iwasawa 29ceb2
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    TPointD dpi = sl->getDpi();
shun-iwasawa 29ceb2
    if (dpi.x <= 0) continue;
shun-iwasawa 29ceb2
    TDimension res = sl->getResolution();
shun-iwasawa 29ceb2
    if (res.lx <= 0) continue;
shun-iwasawa 29ceb2
    dpi.x = res.lx / lx;
shun-iwasawa 29ceb2
    if (m_squarePixCB->isChecked()) dpi.y = dpi.x;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy oldPolicy = sl->getProperties()->getDpiPolicy();
shun-iwasawa 29ceb2
    sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi);
shun-iwasawa 29ceb2
    TPointD oldDpi = sl->getProperties()->getDpi();
shun-iwasawa 29ceb2
    sl->getProperties()->setDpi(dpi);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::DpiType,
shun-iwasawa 29ceb2
                              oldPolicy, LevelProperties::DP_CustomDpi));
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::Dpi,
shun-iwasawa 29ceb2
        QPointF(oldDpi.x, oldDpi.y), QPointF(dpi.x, dpi.y)));
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  updateLevelSettings();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onHeightFieldChanged() {
shun-iwasawa 29ceb2
  double ly = m_heightFld->getValue();
Shinya Kitaoka 120a6e
  if (ly <= 0) {
shun-iwasawa 29ceb2
    updateLevelSettings();
shun-iwasawa 29ceb2
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    TPointD dpi = sl->getDpi();
shun-iwasawa 29ceb2
    if (dpi.y <= 0) continue;
shun-iwasawa 29ceb2
    TDimension res = sl->getResolution();
shun-iwasawa 29ceb2
    if (res.ly <= 0) continue;
shun-iwasawa 29ceb2
    dpi.y = res.ly / ly;
shun-iwasawa 29ceb2
    if (m_squarePixCB->isChecked()) dpi.x = dpi.y;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy oldPolicy = sl->getProperties()->getDpiPolicy();
shun-iwasawa 29ceb2
    sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi);
shun-iwasawa 29ceb2
    TPointD oldDpi = sl->getProperties()->getDpi();
shun-iwasawa 29ceb2
    sl->getProperties()->setDpi(dpi);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::DpiType,
shun-iwasawa 29ceb2
                              oldPolicy, LevelProperties::DP_CustomDpi));
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::Dpi,
shun-iwasawa 29ceb2
        QPointF(oldDpi.x, oldDpi.y), QPointF(dpi.x, dpi.y)));
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  updateLevelSettings();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::useCameraDpi() {
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl) continue;
shun-iwasawa 29ceb2
    LevelProperties *prop                = sl->getProperties();
shun-iwasawa 29ceb2
    LevelProperties::DpiPolicy oldPolicy = prop->getDpiPolicy();
shun-iwasawa 29ceb2
    prop->setDpiPolicy(LevelProperties::DP_CustomDpi);
shun-iwasawa 29ceb2
    TPointD oldDpi = prop->getDpi();
shun-iwasawa 29ceb2
    TPointD dpi    = getCurrentCameraDpi();
shun-iwasawa 29ceb2
    prop->setDpi(dpi);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::DpiType,
shun-iwasawa 29ceb2
                              oldPolicy, LevelProperties::DP_CustomDpi));
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::Dpi,
shun-iwasawa 29ceb2
        QPointF(oldDpi.x, oldDpi.y), QPointF(dpi.x, dpi.y)));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateLevelSettings();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onSubsamplingChanged() {
shun-iwasawa 29ceb2
  int subsampling = (int)m_subsamplingFld->getValue();
shun-iwasawa 29ceb2
  if (subsampling <= 0) {
shun-iwasawa 29ceb2
    updateLevelSettings();
Shinya Kitaoka 120a6e
    return;
shun-iwasawa 29ceb2
  }
Shinya Kitaoka 120a6e
shun-iwasawa 08548b
  bool somethingChanged = false;
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    if (sl->getProperties()->getDirtyFlag()) continue;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    int oldSubsampling = sl->getProperties()->getSubsampling();
shun-iwasawa 29ceb2
    if (oldSubsampling == subsampling) continue;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    sl->getProperties()->setSubsampling(subsampling);
shun-iwasawa 29ceb2
    sl->invalidateFrames();
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::Subsampling, oldSubsampling,
shun-iwasawa 29ceb2
        subsampling));
shun-iwasawa 08548b
    somethingChanged = true;
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
shun-iwasawa 08548b
  if (!somethingChanged) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  TApp::instance()
Shinya Kitaoka 120a6e
      ->getCurrentXsheet()
Shinya Kitaoka 120a6e
      ->getXsheet()
Shinya Kitaoka 120a6e
      ->getStageObjectTree()
Shinya Kitaoka 120a6e
      ->invalidateAll();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 29ceb2
void LevelSettingsPopup::onDoPremultiplyClicked() {
shun-iwasawa 29ceb2
  Qt::CheckState state = m_doPremultiply->checkState();
shun-iwasawa 29ceb2
  bool on = (state == Qt::Checked || state == Qt::PartiallyChecked);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevel *sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    LevelProperties *prop = sl->getProperties();
shun-iwasawa 29ceb2
    if (on == prop->doPremultiply()) continue;
shun-iwasawa 29ceb2
    if (on && prop->whiteTransp()) {
shun-iwasawa 29ceb2
      prop->setWhiteTransp(false);
shun-iwasawa 29ceb2
      TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
          levelP.getPointer(), LevelSettingsUndo::WhiteTransp, true, false));
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
    prop->setDoPremultiply(on);
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::DoPremulti, !on, on));
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  updateLevelSettings();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LevelSettingsPopup::onAntialiasSoftnessChanged() {
shun-iwasawa 29ceb2
  int softness = m_antialiasSoftness->getValue();
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevel *sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl) continue;
shun-iwasawa 29ceb2
    int oldSoftness = sl->getProperties()->antialiasSoftness();
shun-iwasawa 29ceb2
    sl->getProperties()->setDoAntialias(softness);
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::Softness,
shun-iwasawa 29ceb2
                              oldSoftness, softness));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 29ceb2
void LevelSettingsPopup::onDoAntialiasClicked() {
shun-iwasawa 29ceb2
  Qt::CheckState state = m_doAntialias->checkState();
shun-iwasawa 29ceb2
  bool on      = (state == Qt::Checked || state == Qt::PartiallyChecked);
shun-iwasawa 29ceb2
  int softness = on ? m_antialiasSoftness->getValue() : 0;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevel *sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
    int oldSoftness = sl->getProperties()->antialiasSoftness();
shun-iwasawa 29ceb2
    sl->getProperties()->setDoAntialias(softness);
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(
shun-iwasawa 29ceb2
        new LevelSettingsUndo(levelP.getPointer(), LevelSettingsUndo::Softness,
shun-iwasawa 29ceb2
                              oldSoftness, softness));
shun-iwasawa 29ceb2
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  updateLevelSettings();
shun-iwasawa 29ceb2
  if (on) {
shun-iwasawa 29ceb2
    m_doAntialias->setCheckState(Qt::Checked);
shun-iwasawa 29ceb2
    m_antialiasSoftness->setEnabled(true);
shun-iwasawa 29ceb2
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 29ceb2
void LevelSettingsPopup::onWhiteTranspClicked() {
shun-iwasawa 29ceb2
  Qt::CheckState state = m_whiteTransp->checkState();
shun-iwasawa 29ceb2
  bool on = (state == Qt::Checked || state == Qt::PartiallyChecked);
shun-iwasawa 29ceb2
shun-iwasawa 29ceb2
  TUndoManager::manager()->beginBlock();
shun-iwasawa 29ceb2
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 29ceb2
  while (levelItr.hasNext()) {
shun-iwasawa 29ceb2
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 29ceb2
    TXshSimpleLevel *sl = levelP->getSimpleLevel();
shun-iwasawa 29ceb2
    if (!sl || sl->getType() == PLI_XSHLEVEL) continue;
shun-iwasawa 29ceb2
    LevelProperties *prop = sl->getProperties();
shun-iwasawa 29ceb2
    if (on == prop->whiteTransp()) continue;
shun-iwasawa 29ceb2
    if (on && prop->doPremultiply()) {
shun-iwasawa 29ceb2
      prop->setDoPremultiply(false);
shun-iwasawa 29ceb2
      TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
          levelP.getPointer(), LevelSettingsUndo::DoPremulti, true, false));
shun-iwasawa 29ceb2
    }
shun-iwasawa 29ceb2
    prop->setWhiteTransp(on);
shun-iwasawa 29ceb2
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 29ceb2
        levelP.getPointer(), LevelSettingsUndo::WhiteTransp, !on, on));
Shinya Kitaoka 120a6e
  }
shun-iwasawa 29ceb2
  TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 29ceb2
  updateLevelSettings();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
void LevelSettingsPopup::onColorSpaceGammaFieldChanged() {
shun-iwasawa 481b59
  double colorSpaceGamma = m_colorSpaceGammaFld->getValue();
shun-iwasawa 481b59
shun-iwasawa 481b59
  bool somethingChanged = false;
shun-iwasawa 481b59
  TUndoManager::manager()->beginBlock();
shun-iwasawa 481b59
  QSetIterator<txshlevelp> levelItr(m_selectedLevels);</txshlevelp>
shun-iwasawa 481b59
  while (levelItr.hasNext()) {
shun-iwasawa 481b59
    TXshLevelP levelP   = levelItr.next();
shun-iwasawa 481b59
    TXshSimpleLevelP sl = levelP->getSimpleLevel();
shun-iwasawa 481b59
    if (!sl || sl->getType() != OVL_XSHLEVEL) continue;
shun-iwasawa 481b59
    if (sl->getProperties()->getDirtyFlag()) continue;
shun-iwasawa 481b59
shun-iwasawa 481b59
    double oldGamma = sl->getProperties()->colorSpaceGamma();
shun-iwasawa 481b59
    if (areAlmostEqual(colorSpaceGamma, oldGamma)) continue;
shun-iwasawa 481b59
shun-iwasawa 481b59
    sl->getProperties()->setColorSpaceGamma(colorSpaceGamma);
shun-iwasawa 481b59
    sl->invalidateFrames();
shun-iwasawa 481b59
    TUndoManager::manager()->add(new LevelSettingsUndo(
shun-iwasawa 481b59
        levelP.getPointer(), LevelSettingsUndo::ColorSpaceGamma, oldGamma,
shun-iwasawa 481b59
        colorSpaceGamma));
shun-iwasawa 481b59
    somethingChanged = true;
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
  TUndoManager::manager()->endBlock();
shun-iwasawa 481b59
  if (!somethingChanged) return;
shun-iwasawa 481b59
shun-iwasawa 481b59
  TApp::instance()->getCurrentScene()->setDirtyFlag(true);
shun-iwasawa 481b59
  TApp::instance()
shun-iwasawa 481b59
      ->getCurrentXsheet()
shun-iwasawa 481b59
      ->getXsheet()
shun-iwasawa 481b59
      ->getStageObjectTree()
shun-iwasawa 481b59
      ->invalidateAll();
shun-iwasawa 481b59
  TApp::instance()->getCurrentLevel()->notifyLevelChange();
shun-iwasawa 481b59
}
shun-iwasawa 481b59
shun-iwasawa 481b59
//-----------------------------------------------------------------------------
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
OpenPopupCommandHandler<levelsettingspopup> openLevelSettingsPopup(</levelsettingspopup>
Shinya Kitaoka 120a6e
    MI_LevelSettings);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class ViewLevelFileInfoHandler final : public MenuItemHandler {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ViewLevelFileInfoHandler(CommandId cmdId) : MenuItemHandler(cmdId) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void execute() override {
Shinya Kitaoka 120a6e
    TSelection *selection =
Shinya Kitaoka 120a6e
        TApp::instance()->getCurrentSelection()->getSelection();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (FileSelection *fileSelection =
Shinya Kitaoka 120a6e
            dynamic_cast<fileselection *="">(selection)) {</fileselection>
Shinya Kitaoka 120a6e
      fileSelection->viewFileInfo();
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    std::vector<txshlevel *=""> selectedLevels;</txshlevel>
Shinya Kitaoka 120a6e
    /*-- Cell選択ContextMenu→Infoコマンドの場合は、セル内のLevelの情報を表示する
Shinya Kitaoka 120a6e
     * --*/
Shinya Kitaoka 120a6e
    TCellSelection *cellSelection = dynamic_cast<tcellselection *="">(selection);</tcellselection>
Shinya Kitaoka 120a6e
    if (cellSelection && !cellSelection->isEmpty()) {
Shinya Kitaoka 120a6e
      TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
      int r0, c0, r1, c1;
Shinya Kitaoka 120a6e
      cellSelection->getSelectedCells(r0, c0, r1, c1);
Shinya Kitaoka 120a6e
      for (int c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
        for (int r = r0; r <= r1; r++) {
shun_iwasawa a3d7fb
          TXshLevel *lv = xsh->getCell(r, c).m_level.getPointer();
Shinya Kitaoka 120a6e
          if (!lv) continue;
Shinya Kitaoka 120a6e
          std::vector<txshlevel *="">::iterator lvIt =</txshlevel>
Shinya Kitaoka 120a6e
              find(selectedLevels.begin(), selectedLevels.end(), lv);
Shinya Kitaoka 120a6e
          if (lvIt == selectedLevels.end()) selectedLevels.push_back(lv);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (CastSelection *castSelection =
Shinya Kitaoka 120a6e
                   dynamic_cast<castselection *="">(selection))</castselection>
Shinya Kitaoka 120a6e
      castSelection->getSelectedLevels(selectedLevels);
Shinya Kitaoka 120a6e
    else if (TXshLevel *level = TApp::instance()->getCurrentLevel()->getLevel())
Shinya Kitaoka 120a6e
      selectedLevels.push_back(level);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (selectedLevels.empty()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int i = 0; i < selectedLevels.size(); ++i) {
Shinya Kitaoka 120a6e
      if (selectedLevels[i]->getSimpleLevel() ||
Shinya Kitaoka 120a6e
          selectedLevels[i]->getSoundLevel()) {
Shinya Kitaoka 120a6e
        TFilePath path = selectedLevels[i]->getPath();
Shinya Kitaoka 120a6e
        path           = selectedLevels[i]->getScene()->decodeFilePath(path);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        if (TSystem::doesExistFileOrLevel(path)) {
Shinya Kitaoka 120a6e
          InfoViewer *infoViewer = 0;
Shinya Kitaoka 120a6e
          infoViewer             = new InfoViewer();
Shinya Kitaoka 120a6e
          infoViewer->setItem(0, 0, path);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} viewLevelFileInfoHandler(MI_FileInfo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class ViewLevelHandler final : public MenuItemHandler {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ViewLevelHandler(CommandId cmdId) : MenuItemHandler(cmdId) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void execute() override {
Shinya Kitaoka 120a6e
    TSelection *selection =
Shinya Kitaoka 120a6e
        TApp::instance()->getCurrentSelection()->getSelection();
Shinya Kitaoka 120a6e
    if (FileSelection *fileSelection =
Shinya Kitaoka 120a6e
            dynamic_cast<fileselection *="">(selection)) {</fileselection>
Shinya Kitaoka 120a6e
      fileSelection->viewFile();
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TXshSimpleLevel *sl = 0;
Shinya Kitaoka 120a6e
    int i               = 0;
Shinya Kitaoka 120a6e
    std::vector<txshsimplelevel *=""> simpleLevels;</txshsimplelevel>
Shinya Kitaoka 120a6e
    /*-- セル選択ContextMenu→Viewコマンドの場合 --*/
Shinya Kitaoka 120a6e
    TXsheet *currentXsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
Shinya Kitaoka 120a6e
    TCellSelection *cellSelection = dynamic_cast<tcellselection *="">(selection);</tcellselection>
Shinya Kitaoka 120a6e
    if (currentXsheet && cellSelection && !cellSelection->isEmpty()) {
Shinya Kitaoka 120a6e
      int r0, c0, r1, c1;
Shinya Kitaoka 120a6e
      cellSelection->getSelectedCells(r0, c0, r1, c1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      for (int c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
        for (int r = r0; r <= r1; r++) {
Shinya Kitaoka 120a6e
          TXshSimpleLevel *lv = currentXsheet->getCell(r, c).getSimpleLevel();
Shinya Kitaoka 120a6e
          if (!lv) continue;
Shinya Kitaoka 120a6e
          std::vector<txshsimplelevel *="">::iterator lvIt =</txshsimplelevel>
Shinya Kitaoka 120a6e
              find(simpleLevels.begin(), simpleLevels.end(), lv);
Shinya Kitaoka 120a6e
          if (lvIt == simpleLevels.end()) simpleLevels.push_back(lv);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (CastSelection *castSelection =
Shinya Kitaoka 120a6e
                   dynamic_cast<castselection *="">(selection)) {</castselection>
Shinya Kitaoka 120a6e
      std::vector<txshlevel *=""> selectedLevels;</txshlevel>
Shinya Kitaoka 120a6e
      castSelection->getSelectedLevels(selectedLevels);
Shinya Kitaoka 120a6e
      for (i = 0; i < selectedLevels.size(); i++)
Shinya Kitaoka 120a6e
        simpleLevels.push_back(selectedLevels[i]->getSimpleLevel());
Shinya Kitaoka 120a6e
    } else if (TApp::instance()->getCurrentLevel()->getSimpleLevel())
Shinya Kitaoka 120a6e
      simpleLevels.push_back(
Shinya Kitaoka 120a6e
          TApp::instance()->getCurrentLevel()->getSimpleLevel());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!simpleLevels.size()) return;
Shinya Kitaoka 120a6e
    for (i = 0; i < simpleLevels.size(); i++) {
Jeremy Bullock 0ff1b6
      if (!(simpleLevels[i]->getType() & LEVELCOLUMN_XSHLEVEL)) continue;
manongjohn bced1b
Shinya Kitaoka 120a6e
      TFilePath path = simpleLevels[i]->getPath();
Shinya Kitaoka 120a6e
      path           = simpleLevels[i]->getScene()->decodeFilePath(path);
shun_iwasawa cc002f
      FlipBook *fb;
Shinya Kitaoka 120a6e
      if (TSystem::doesExistFileOrLevel(path))
shun_iwasawa cc002f
        fb = ::viewFile(path);
shun_iwasawa cc002f
      else {
shun_iwasawa cc002f
        fb = FlipBookPool::instance()->pop();
shun_iwasawa cc002f
        fb->setLevel(simpleLevels[i]);
shun_iwasawa cc002f
      }
shun_iwasawa cc002f
      if (fb) {
shun_iwasawa cc002f
        FileBrowserPopup::setModalBrowserToParent(fb->parentWidget());
shun_iwasawa cc002f
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} ViewLevelHandler(MI_ViewFile);