Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
#include "tunit.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tbigmemorymanager.h"
shun-iwasawa 93fdd4
#include "timage_io.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qsettings></qsettings>
Toshihiro Shimizu 890ddd
#include <qstringlist></qstringlist>
shun_iwasawa 4635d8
#include <qaction></qaction>
shun-iwasawa 8fb291
#include <qcolor></qcolor>
shun-iwasawa c54dfb
#include <qtextstream></qtextstream>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// boost includes
Toshihiro Shimizu 890ddd
#include <boost bind.hpp=""></boost>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace  stuff
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef Preferences::LevelFormat LevelFormat;
Toshihiro Shimizu 890ddd
typedef std::vector<levelformat> LevelFormatVector;</levelformat>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
const char *s_levelFormats = "levelFormats";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const char *s_name = "name", *s_regexp = "regexp", *s_priority = "priority";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const char *s_dpiPolicy = "dpiPolicy", *s_dpi = "dpi",
Shinya Kitaoka 120a6e
           *s_subsampling = "subsampling", *s_antialias = "antialias",
Shinya Kitaoka 120a6e
           *s_premultiply = "premultiply", *s_whiteTransp = "whiteTransp";
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================================
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
inline QString colorToString(const QColor &color) {
shun-iwasawa 8fb291
  return QString("%1 %2 %3 %4")
shun-iwasawa 8fb291
      .arg(color.red())
shun-iwasawa 8fb291
      .arg(color.green())
shun-iwasawa 8fb291
      .arg(color.blue())
shun-iwasawa 8fb291
      .arg(color.alpha());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
inline QColor stringToColor(const QString &str) {
shun-iwasawa 8fb291
  QStringList values = str.split(' ');
shun-iwasawa 8fb291
  return QColor(values[0].toInt(), values[1].toInt(), values[2].toInt(),
shun-iwasawa 8fb291
                values[3].toInt());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
inline TPixel colorToTPixel(const QColor &color) {
shun-iwasawa 8fb291
  return TPixel(color.red(), color.green(), color.blue(), color.alpha());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
static void setCurrentUnits(std::string measureName, std::string units) {
shun-iwasawa 8fb291
  TMeasure *m = TMeasureManager::instance()->get(measureName);
shun-iwasawa 8fb291
  if (!m) return;
shun-iwasawa 8fb291
  TUnit *u = m->getUnit(::to_wstring(units));
shun-iwasawa 8fb291
  if (!u) return;
shun-iwasawa 8fb291
  m->setCurrentUnit(u);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline bool formatLess(const Preferences::LevelFormat &a,
Shinya Kitaoka 120a6e
                       const Preferences::LevelFormat &b) {
Shinya Kitaoka 120a6e
  return (
Shinya Kitaoka 120a6e
      a.m_priority > b.m_priority  // Observe '>' used here - we want inverse
Shinya Kitaoka 120a6e
      || (!(b.m_priority >
Shinya Kitaoka 120a6e
            a.m_priority)  // sorting on priority, higher priorities come first
Shinya Kitaoka 120a6e
          && a.m_name < b.m_name));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void getDefaultLevelFormats(LevelFormatVector &lfv) {
shun-iwasawa eeca9f
  lfv.resize(2);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    LevelFormat &lf = lfv[0];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    lf.m_name       = Preferences::tr("Retas Level Format");
Shinya Kitaoka 120a6e
    lf.m_pathFormat = QRegExp(".+[0-9]{4,4}\\.tga", Qt::CaseInsensitive);
Shinya Kitaoka 120a6e
    lf.m_options.m_whiteTransp = true;
Shinya Kitaoka 120a6e
    lf.m_options.m_antialias   = 70;
shun_iwasawa 0becbe
shun_iwasawa 0becbe
    // for all PSD files, set the premultiply options to layers
shun_iwasawa 0becbe
    lfv[1].m_name                  = Preferences::tr("Adobe Photoshop");
shun_iwasawa 0becbe
    lfv[1].m_pathFormat            = QRegExp("..*\\.psd", Qt::CaseInsensitive);
shun_iwasawa 0becbe
    lfv[1].m_options.m_premultiply = true;
Jeremy Bullock 3101a8
Jeremy Bullock 3101a8
    // for all PNG files, set premultiply by default
shun-iwasawa 8b6d1f
    // UPDATE : from V1.5, PNG images are premultiplied on loading
shun-iwasawa 8b6d1f
    // lfv[2].m_name                  = Preferences::tr("PNG");
shun-iwasawa 8b6d1f
    // lfv[2].m_pathFormat            = QRegExp("..*\\.png",
shun-iwasawa 8b6d1f
    // Qt::CaseInsensitive); lfv[2].m_options.m_premultiply = true;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void setValue(QSettings &settings, const LevelOptions &lo) {
Shinya Kitaoka 120a6e
  settings.setValue(s_dpiPolicy, int(lo.m_dpiPolicy));
Shinya Kitaoka 120a6e
  settings.setValue(s_dpi, lo.m_dpi);
Shinya Kitaoka 120a6e
  settings.setValue(s_subsampling, lo.m_subsampling);
Shinya Kitaoka 120a6e
  settings.setValue(s_antialias, lo.m_antialias);
Shinya Kitaoka 120a6e
  settings.setValue(s_premultiply, int(lo.m_premultiply));
Shinya Kitaoka 120a6e
  settings.setValue(s_whiteTransp, int(lo.m_whiteTransp));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void getValue(const QSettings &settings, LevelOptions &lo) {
Shinya Kitaoka 120a6e
  int dpiPolicy    = settings.value(s_dpiPolicy, int(lo.m_dpiPolicy)).toInt();
Shinya Kitaoka 120a6e
  lo.m_dpiPolicy   = LevelOptions::DpiPolicy(dpiPolicy);
Shinya Kitaoka 120a6e
  lo.m_dpi         = settings.value(s_dpi, lo.m_dpi).toDouble();
Shinya Kitaoka 120a6e
  lo.m_subsampling = settings.value(s_subsampling, lo.m_subsampling).toInt();
Shinya Kitaoka 120a6e
  lo.m_antialias   = settings.value(s_antialias, lo.m_antialias).toInt();
Shinya Kitaoka 120a6e
  lo.m_premultiply =
Shinya Kitaoka 120a6e
      (settings.value(s_premultiply, lo.m_premultiply).toInt() != 0);
Shinya Kitaoka 120a6e
  lo.m_whiteTransp =
Shinya Kitaoka 120a6e
      (settings.value(s_whiteTransp, lo.m_whiteTransp).toInt() != 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void setValue(QSettings &settings, const LevelFormat &lf) {
Shinya Kitaoka 120a6e
  settings.setValue(s_name, lf.m_name);
Shinya Kitaoka 120a6e
  settings.setValue(s_regexp, lf.m_pathFormat.pattern());
Shinya Kitaoka 120a6e
  settings.setValue(s_priority, lf.m_priority);
Shinya Kitaoka 120a6e
  setValue(settings, lf.m_options);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void getValue(const QSettings &settings, LevelFormat &lf) {
Shinya Kitaoka 120a6e
  lf.m_name = settings.value(s_name, lf.m_name).toString();
Shinya Kitaoka 120a6e
  lf.m_pathFormat =
Shinya Kitaoka 120a6e
      QRegExp(settings.value(s_regexp, lf.m_pathFormat).toString(),
Shinya Kitaoka 120a6e
              Qt::CaseInsensitive);
Shinya Kitaoka 120a6e
  lf.m_priority = settings.value(s_priority, lf.m_priority).toInt();
Shinya Kitaoka 120a6e
  getValue(settings, lf.m_options);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void _setValue(QSettings &settings, const LevelFormatVector &lfv) {
Shinya Kitaoka 120a6e
  int lf, lfCount = int(lfv.size());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  settings.remove(s_levelFormats);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  settings.beginWriteArray(s_levelFormats, lfCount);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    for (lf = 0; lf != lfCount; ++lf) {
Shinya Kitaoka 120a6e
      settings.setArrayIndex(lf);
Shinya Kitaoka 120a6e
      setValue(settings, lfv[lf]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  settings.endArray();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void getValue(QSettings &settings,
Shinya Kitaoka 120a6e
              LevelFormatVector &lfv)  // Why does QSettings' interface require
Shinya Kitaoka 120a6e
{  // non-const access on reading arrays/groups?
Shinya Kitaoka 120a6e
  if (!settings.childGroups().contains(s_levelFormats))
Shinya Kitaoka 120a6e
    return;  // Default is no level formats - use builtins
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int lfCount = settings.beginReadArray(s_levelFormats);  // lfCount could be 0
Shinya Kitaoka 120a6e
  lfv.resize(lfCount);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int lf = 0; lf != lfCount; ++lf) {
Shinya Kitaoka 120a6e
    settings.setArrayIndex(lf);
Shinya Kitaoka 120a6e
    getValue(settings, lfv[lf]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  settings.endArray();
shun-iwasawa 8b6d1f
shun-iwasawa 8b6d1f
  // from OT V1.5, PNG images are premultiplied on loading.
shun-iwasawa 8b6d1f
  // Leaving the premultiply option will cause unwanted double operation.
shun-iwasawa 8b6d1f
  // So, check the loaded options and modify it "silently".
shun-iwasawa 8b6d1f
  bool changed                   = false;
shun-iwasawa 8b6d1f
  LevelFormatVector::iterator it = lfv.begin();
shun-iwasawa 8b6d1f
  while (it != lfv.end()) {
shun-iwasawa 8b6d1f
    if ((*it).m_name == Preferences::tr("PNG") &&
shun-iwasawa 8b6d1f
        (*it).m_pathFormat == QRegExp("..*\\.png", Qt::CaseInsensitive) &&
shun-iwasawa 8b6d1f
        (*it).m_options.m_premultiply == true) {
shun-iwasawa 8b6d1f
      LevelOptions defaultValue;
shun-iwasawa 8b6d1f
      defaultValue.m_premultiply = true;
luz paz 67b4e9
      // if other parameters are the same as default, just erase the item
shun-iwasawa 8b6d1f
      if ((*it).m_options == defaultValue) it = lfv.erase(it);
shun-iwasawa 8b6d1f
      // if there are some adjustments by user, then disable only premultiply
shun-iwasawa 8b6d1f
      // option
shun-iwasawa 8b6d1f
      else {
shun-iwasawa 8b6d1f
        (*it).m_options.m_premultiply = false;
shun-iwasawa 8b6d1f
        ++it;
shun-iwasawa 8b6d1f
      }
shun-iwasawa 8b6d1f
      changed = true;
shun-iwasawa eeca9f
    }
shun-iwasawa eeca9f
    // remove the "empty" condition which may inserted due to the previous bug
shun-iwasawa eeca9f
    else if ((*it).m_name.isEmpty() &&
shun-iwasawa eeca9f
             (*it).m_pathFormat == QRegExp(".*", Qt::CaseInsensitive) &&
shun-iwasawa eeca9f
             (*it).m_priority == 1 && (*it).m_options == LevelOptions()) {
shun-iwasawa eeca9f
      it      = lfv.erase(it);
shun-iwasawa eeca9f
      changed = true;
shun-iwasawa 8b6d1f
    } else
shun-iwasawa 8b6d1f
      ++it;
shun-iwasawa 8b6d1f
  }
shun-iwasawa 8b6d1f
  // overwrite the setting
shun-iwasawa 8b6d1f
  if (changed) _setValue(settings, lfv);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Preferences::LevelFormat  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool Preferences::LevelFormat::matches(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  return m_pathFormat.exactMatch(fp.getQString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Preferences  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
Preferences::Preferences() {
shun-iwasawa 8fb291
  // load preference file
Shinya Kitaoka 120a6e
  TFilePath layoutDir = ToonzFolder::getMyModuleDir();
shun-iwasawa 5e6203
  TFilePath prefPath  = layoutDir + TFilePath("preferences.ini");
shun-iwasawa 5e6203
  // In case the personal settings is not exist (for new users)
shun-iwasawa 5e6203
  if (!TFileStatus(prefPath).doesExist()) {
shun-iwasawa 5e6203
    TFilePath templatePath =
shun-iwasawa 5e6203
        ToonzFolder::getTemplateModuleDir() + TFilePath("preferences.ini");
shun-iwasawa 5e6203
    // If there is the template, copy it to the personal one
shun-iwasawa 5e6203
    if (TFileStatus(templatePath).doesExist())
shun-iwasawa 5e6203
      TSystem::copyFile(prefPath, templatePath);
shun-iwasawa 5e6203
  }
Shinya Kitaoka 120a6e
  m_settings.reset(new QSettings(
shun-iwasawa 5e6203
      QString::fromStdWString(prefPath.getWideString()), QSettings::IniFormat));
Shinya Kitaoka 120a6e
shun-iwasawa 8fb291
  initializeOptions();
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  definePreferenceItems();
shun-iwasawa 536025
  // resolve compatibility for deprecated items
shun-iwasawa 536025
  resolveCompatibility();
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // initialize environment based on loaded preferences
shun-iwasawa 8fb291
  setUnits();
shun-iwasawa 8fb291
  setCameraUnits();
shun-iwasawa 5f4218
  setUndoMemorySize();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Load level formats
Shinya Kitaoka 120a6e
  getDefaultLevelFormats(m_levelFormats);
Shinya Kitaoka 120a6e
  getValue(*m_settings, m_levelFormats);
Shinya Kitaoka 120a6e
  std::sort(m_levelFormats.begin(),
Shinya Kitaoka 120a6e
            m_levelFormats.end(),  // Format sorting must be
Shinya Kitaoka 120a6e
            formatLess);           // enforced
Shinya Kitaoka 120a6e
shun-iwasawa 8fb291
  if (m_roomMaps.key(getStringValue(CurrentRoomChoice), -1) == -1) {
shun-iwasawa 8fb291
    assert(!m_roomMaps.isEmpty());
shun-iwasawa 8fb291
    setValue(CurrentRoomChoice, m_roomMaps[0]);
shun-iwasawa 8fb291
  }
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  if (!m_styleSheetList.contains(getStringValue(CurrentStyleSheetName)))
shun-iwasawa 8fb291
    setValue(CurrentStyleSheetName, "Default");
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  if (!m_languageList.contains(getStringValue(CurrentLanguageName)))
shun-iwasawa 8fb291
    setValue(CurrentLanguageName, "English");
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  TImageWriter::setBackgroundColor(getColorValue(rasterBackgroundColor));
shun-iwasawa 8fb291
}
shun-iwasawa 8fb291
shun-iwasawa 8fb291
//-----------------------------------------------------------------
shun-iwasawa 8fb291
shun-iwasawa 8fb291
Preferences::~Preferences() {
shun-iwasawa 8fb291
  // DO NOT REMOVE
shun-iwasawa 8fb291
}
shun-iwasawa 8fb291
shun-iwasawa 8fb291
//-----------------------------------------------------------------
shun-iwasawa 8fb291
shun-iwasawa 8fb291
Preferences *Preferences::instance() {
shun-iwasawa 8fb291
  static Preferences _instance;
shun-iwasawa 8fb291
  return &_instance;
shun-iwasawa 8fb291
}
shun-iwasawa 8fb291
shun-iwasawa 8fb291
//-----------------------------------------------------------------
shun-iwasawa 8fb291
// load and initialize options for languages, styles and rooms
shun-iwasawa 8fb291
shun-iwasawa 8fb291
void Preferences::initializeOptions() {
Shinya Kitaoka 120a6e
  // load languages
Shinya Kitaoka 120a6e
  TFilePath lang_path = TEnv::getConfigDir() + "loc";
Shinya Kitaoka 120a6e
  TFilePathSet lang_fpset;
shun-iwasawa 9031b4
  m_languageList.append("English");
Shinya Kitaoka 120a6e
  // m_currentLanguage=0;
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TFileStatus langPathFs(lang_path);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (langPathFs.doesExist() && langPathFs.isDirectory()) {
Shinya Kitaoka 120a6e
      TSystem::readDirectory(lang_fpset, lang_path, true, false);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int i = 0;
Shinya Kitaoka 120a6e
    for (auto const &newPath : lang_fpset) {
Shinya Kitaoka 120a6e
      ++i;
Shinya Kitaoka 120a6e
      if (newPath == lang_path) continue;
Shinya Kitaoka 120a6e
      if (TFileStatus(newPath).isDirectory()) {
shun-iwasawa 9031b4
        QString string = QString::fromStdWString(newPath.getWideName());
shun-iwasawa 9031b4
        m_languageList.append(string);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // load styles
Shinya Kitaoka 120a6e
  TFilePath path(TEnv::getConfigDir() + "qss");
Shinya Kitaoka 120a6e
  TFilePathSet fpset;
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TSystem::readDirectory(fpset, path, true, false);
Shinya Kitaoka 120a6e
    int i = -1;
Shinya Kitaoka 120a6e
    for (auto const &newPath : fpset) {
Shinya Kitaoka 120a6e
      ++i;
Shinya Kitaoka 120a6e
      if (newPath == path) continue;
Shinya Kitaoka 120a6e
      QString fpName = QString::fromStdWString(newPath.getWideName());
shun-iwasawa 9031b4
      m_styleSheetList.append(fpName);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // load rooms or layouts
shun-iwasawa 7af4c5
  TFilePath room_path(ToonzFolder::getRoomsDir());
Shinya Kitaoka 120a6e
  TFilePathSet room_fpset;
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TSystem::readDirectory(room_fpset, room_path, true, false);
Shinya Kitaoka 120a6e
    TFilePathSet::iterator it = room_fpset.begin();
Rozhuk Ivan 823a31
    for (int i = 0; it != room_fpset.end(); it++, i++) {
Shinya Kitaoka 120a6e
      TFilePath newPath = *it;
Shinya Kitaoka 120a6e
      if (newPath == room_path) continue;
Shinya Kitaoka 120a6e
      if (TFileStatus(newPath).isDirectory()) {
Shinya Kitaoka 120a6e
        QString string = QString::fromStdWString(newPath.getWideName());
shun-iwasawa 8fb291
        m_roomMaps[i]  = string;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::definePreferenceItems() {
shun-iwasawa 8fb291
  // General
shun-iwasawa 8fb291
  define(defaultViewerEnabled, "defaultViewerEnabled", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(rasterOptimizedMemory, "rasterOptimizedMemory", QMetaType::Bool,
shun-iwasawa 8fb291
         false);
shun-iwasawa 8fb291
  define(startupPopupEnabled, "startupPopupEnabled", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(undoMemorySize, "undoMemorySize", QMetaType::Int, 100, 0, 2000);
shun-iwasawa 8fb291
  define(taskchunksize, "taskchunksize", QMetaType::Int, 10, 1, 2000);
shun-iwasawa 8fb291
  define(sceneNumberingEnabled, "sceneNumberingEnabled", QMetaType::Bool,
shun-iwasawa 8fb291
         false);
shun-iwasawa 8fb291
  define(watchFileSystemEnabled, "watchFileSystemEnabled", QMetaType::Bool,
shun-iwasawa 8fb291
         true);
shun-iwasawa 8fb291
  define(projectRoot, "projectRoot", QMetaType::Int, 0x08);
shun-iwasawa 8fb291
  define(customProjectRoot, "customProjectRoot", QMetaType::QString, "");
shun-iwasawa 8fb291
  define(pathAliasPriority, "pathAliasPriority", QMetaType::Int,
shun-iwasawa 8fb291
         (int)ProjectFolderOnly);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  setCallBack(undoMemorySize, &Preferences::setUndoMemorySize);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Interface
shun-iwasawa 8fb291
  define(CurrentStyleSheetName, "CurrentStyleSheetName", QMetaType::QString,
shun-iwasawa 8fb291
         "Default");
shun-iwasawa 668c9b
shun-iwasawa 668c9b
  // Qt has a bug in recent versions that Menu item Does not show correctly
shun-iwasawa 668c9b
  // (QTBUG-90242) Since the current OT is made to handle such issue, so we need
shun-iwasawa 668c9b
  // to apply an extra adjustment when it is run on the older versions (5.9.x)
shun-iwasawa 668c9b
  // of Qt
shun-iwasawa 6502cd
  // Update: confirmed that the bug does not appear at least in Qt 5.12.8
shun-iwasawa 668c9b
  QString defaultAditionalSheet = "";
shun-iwasawa 6502cd
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 9)
shun-iwasawa 668c9b
  defaultAditionalSheet = "QMenu::Item{ padding: 3 28 3 28; }";
shun-iwasawa 668c9b
#endif
shun-iwasawa 668c9b
shun-iwasawa 668c9b
  define(additionalStyleSheet, "additionalStyleSheet", QMetaType::QString,
shun-iwasawa 668c9b
         defaultAditionalSheet);
Kite 521c84
  define(iconTheme, "iconTheme", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(pixelsOnly, "pixelsOnly", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(oldUnits, "oldUnits", QMetaType::QString, "mm");
shun-iwasawa 8fb291
  define(oldCameraUnits, "oldCameraUnits", QMetaType::QString, "inch");
shun-iwasawa 8fb291
  define(linearUnits, "linearUnits", QMetaType::QString, "mm");
shun-iwasawa 8fb291
  define(cameraUnits, "cameraUnits", QMetaType::QString, "inch");
shun-iwasawa 8fb291
  define(CurrentRoomChoice, "CurrentRoomChoice", QMetaType::QString, "Default");
shun-iwasawa 8fb291
  define(functionEditorToggle, "functionEditorToggle", QMetaType::Int,
shun-iwasawa 8fb291
         (int)ShowGraphEditorInPopup);
shun-iwasawa 8fb291
  define(moveCurrentFrameByClickCellArea, "moveCurrentFrameByClickCellArea",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(actualPixelViewOnSceneEditingMode, "actualPixelViewOnSceneEditingMode",
shun-iwasawa 8fb291
         QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(showRasterImagesDarkenBlendedInViewer,
shun-iwasawa 8fb291
         "showRasterImagesDarkenBlendedInViewer", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(iconSize, "iconSize", QMetaType::QSize, QSize(80, 45), QSize(10, 10),
shun-iwasawa 8fb291
         QSize(400, 400));
shun-iwasawa 8fb291
  define(viewShrink, "viewShrink", QMetaType::Int, 1, 1, 20);
shun-iwasawa 8fb291
  define(viewStep, "viewStep", QMetaType::Int, 1, 1, 20);
shun-iwasawa 8fb291
  define(viewerZoomCenter, "viewerZoomCenter", QMetaType::Int,
shun-iwasawa 8fb291
         0);  // Mouse Cursor
shun-iwasawa 8fb291
  define(CurrentLanguageName, "CurrentLanguageName", QMetaType::QString,
shun-iwasawa 8fb291
         "English");
shun-iwasawa 8fb291
#ifdef _WIN32
shun-iwasawa 8fb291
  QString defaultFont("Segoe UI");
shun-iwasawa 8fb291
#elif defined Q_OS_MACOS
shun-iwasawa 8fb291
  QString defaultFont("Helvetica Neue");
shun-iwasawa 8fb291
#else
shun-iwasawa 8fb291
  QString defaultFont("Helvetica");
shun-iwasawa 8fb291
#endif
shun-iwasawa 8fb291
  define(interfaceFont, "interfaceFont", QMetaType::QString, defaultFont);
shun-iwasawa 8fb291
  define(interfaceFontStyle, "interfaceFontStyle", QMetaType::QString,
shun-iwasawa 8fb291
         "Regular");
shun-iwasawa 8fb291
  define(colorCalibrationEnabled, "colorCalibrationEnabled", QMetaType::Bool,
shun-iwasawa 8fb291
         false);
shun-iwasawa 8fb291
  define(colorCalibrationLutPaths, "colorCalibrationLutPaths",
shun-iwasawa 8fb291
         QMetaType::QVariantMap, QVariantMap());
shun-iwasawa 215a5b
  define(displayIn30bit, "displayIn30bit", QMetaType::Bool, false);
shun-iwasawa 8fb291
shun-iwasawa bb8132
  // hide menu icons by default in macOS since the icon color may not match with
shun-iwasawa bb8132
  // the system color theme
shun-iwasawa bb8132
#ifdef Q_OS_MACOS
shun-iwasawa bb8132
  bool defIconsVisible = false;
shun-iwasawa bb8132
#else
shun-iwasawa bb8132
  bool defIconsVisible = true;
shun-iwasawa bb8132
#endif
shun-iwasawa bb8132
  define(showIconsInMenu, "showIconsInMenu", QMetaType::Bool, defIconsVisible);
shun-iwasawa bb8132
shun-iwasawa 8fb291
  setCallBack(pixelsOnly, &Preferences::setPixelsOnly);
shun-iwasawa 8fb291
  setCallBack(linearUnits, &Preferences::setUnits);
shun-iwasawa 8fb291
  setCallBack(cameraUnits, &Preferences::setCameraUnits);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Visualization
shun-iwasawa 8fb291
  define(show0ThickLines, "show0ThickLines", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(regionAntialias, "regionAntialias", QMetaType::Bool, false);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Loading
shun-iwasawa 8fb291
  define(importPolicy, "importPolicy", QMetaType::Int, 0);  // Always ask
shun-iwasawa 8fb291
  define(autoExposeEnabled, "autoExposeEnabled", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(subsceneFolderEnabled, "subsceneFolderEnabled", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(removeSceneNumberFromLoadedLevelName,
shun-iwasawa 8fb291
         "removeSceneNumberFromLoadedLevelName", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(IgnoreImageDpi, "IgnoreImageDpi", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(initialLoadTlvCachingBehavior, "initialLoadTlvCachingBehavior",
shun-iwasawa 8fb291
         QMetaType::Int, 0);  // On Demand
shun-iwasawa 8fb291
  define(columnIconLoadingPolicy, "columnIconLoadingPolicy", QMetaType::Int,
shun-iwasawa 8fb291
         (int)LoadAtOnce);
shun-iwasawa 409dec
  define(autoRemoveUnusedLevels, "autoRemoveUnusedLevels", QMetaType::Bool,
shun-iwasawa 409dec
         false);
shun-iwasawa 409dec
shun-iwasawa 8fb291
  //"levelFormats" need to be handle separately
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Saving
shun-iwasawa c9a4a1
  define(autosaveEnabled, "autosaveEnabled", QMetaType::Bool, false);
shun-iwasawa c9a4a1
  define(autosavePeriod, "autosavePeriod", QMetaType::Int, 15, 1, 60);
shun-iwasawa c9a4a1
  define(autosaveSceneEnabled, "autosaveSceneEnabled", QMetaType::Bool, true);
shun-iwasawa c9a4a1
  define(autosaveOtherFilesEnabled, "autosaveOtherFilesEnabled",
shun-iwasawa c9a4a1
         QMetaType::Bool, true);
shun-iwasawa c9a4a1
  define(replaceAfterSaveLevelAs, "replaceAfterSaveLevelAs", QMetaType::Bool,
shun-iwasawa c9a4a1
         true);
shun-iwasawa c9a4a1
  define(backupEnabled, "backupEnabled", QMetaType::Bool, true);
shun-iwasawa c9a4a1
  define(backupKeepCount, "backupKeepCount", QMetaType::Int, 1, 1,
shun-iwasawa c9a4a1
         std::numeric_limits<int>::max());</int>
shun-iwasawa 8fb291
  define(rasterBackgroundColor, "rasterBackgroundColor", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(Qt::white));
shun-iwasawa d2bb27
  define(resetUndoOnSavingLevel, "resetUndoOnSavingLevel", QMetaType::Bool,
shun-iwasawa d2bb27
         true);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  setCallBack(rasterBackgroundColor, &Preferences::setRasterBackgroundColor);
shun-iwasawa c9a4a1
  setCallBack(autosaveEnabled, &Preferences::enableAutosave);
shun-iwasawa c9a4a1
  setCallBack(autosavePeriod, &Preferences::setAutosavePeriod);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Import / Export
shun-iwasawa 8fb291
  define(ffmpegPath, "ffmpegPath", QMetaType::QString, "");
shun-iwasawa 8fb291
  define(ffmpegTimeout, "ffmpegTimeout", QMetaType::Int, 600, 1,
shun-iwasawa 8fb291
         std::numeric_limits<int>::max());</int>
shun-iwasawa 8fb291
  define(fastRenderPath, "fastRenderPath", QMetaType::QString, "desktop");
justburner 69bbaf
  define(ffmpegMultiThread, "ffmpegMultiThread", QMetaType::Bool, false);
justburner 08eb1b
  define(rhubarbPath, "rhubarbPath", QMetaType::QString, "");
justburner 08eb1b
  define(rhubarbTimeout, "rhubarbTimeout", QMetaType::Int, 600, 0,
justburner 08eb1b
         std::numeric_limits<int>::max());</int>
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Drawing
shun-iwasawa fc0d80
  define(DefRasterFormat, "DefRasterFormat", QMetaType::QString, "tif");
shun-iwasawa fc0d80
  // define(scanLevelType, "scanLevelType", QMetaType::QString, "tif");
shun-iwasawa 8fb291
  define(DefLevelType, "DefLevelType", QMetaType::Int, TZP_XSHLEVEL);
shun-iwasawa 8fb291
  define(newLevelSizeToCameraSizeEnabled, "newLevelSizeToCameraSizeEnabled",
shun-iwasawa 8fb291
         QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(DefLevelWidth, "DefLevelWidth", QMetaType::Double,
shun-iwasawa 8fb291
         TCamera().getSize().lx, 0.1, std::numeric_limits<double>::max());</double>
shun-iwasawa 8fb291
  define(DefLevelHeight, "DefLevelHeight", QMetaType::Double,
shun-iwasawa 8fb291
         TCamera().getSize().ly, 0.1, std::numeric_limits<double>::max());</double>
shun-iwasawa 8fb291
  define(DefLevelDpi, "DefLevelDpi", QMetaType::Double, TCamera().getDpi().x,
shun-iwasawa 8fb291
         0.1, std::numeric_limits<double>::max());</double>
shun-iwasawa 536025
shun-iwasawa 536025
  define(EnableAutocreation, "EnableAutocreation", QMetaType::Bool, true);
Kite 521c84
  define(NumberingSystem, "NumberingSystem", QMetaType::Int, 0);  // Incremental
shun-iwasawa 8fb291
  define(EnableAutoStretch, "EnableAutoStretch", QMetaType::Bool, true);
shun-iwasawa 536025
  define(EnableCreationInHoldCells, "EnableCreationInHoldCells",
shun-iwasawa 536025
         QMetaType::Bool, true);
shun-iwasawa 536025
  define(EnableAutoRenumber, "EnableAutoRenumber", QMetaType::Bool, true);
shun-iwasawa 536025
shun-iwasawa 8fb291
  define(vectorSnappingTarget, "vectorSnappingTarget", QMetaType::Int,
shun-iwasawa 8fb291
         (int)SnapAll);
shun-iwasawa 8fb291
  define(saveUnpaintedInCleanup, "saveUnpaintedInCleanup", QMetaType::Bool,
shun-iwasawa 8fb291
         true);
shun-iwasawa 8fb291
  define(minimizeSaveboxAfterEditing, "minimizeSaveboxAfterEditing",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(useNumpadForSwitchingStyles, "useNumpadForSwitchingStyles",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(downArrowInLevelStripCreatesNewFrame,
shun-iwasawa 8fb291
         "downArrowInLevelStripCreatesNewFrame", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(keepFillOnVectorSimplify, "keepFillOnVectorSimplify", QMetaType::Bool,
shun-iwasawa 8fb291
         true);
shun-iwasawa 8fb291
  define(useHigherDpiOnVectorSimplify, "useHigherDpiOnVectorSimplify",
shun-iwasawa 8fb291
         QMetaType::Bool, false);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Tools
shun-iwasawa 390cff
  // define(dropdownShortcutsCycleOptions, "dropdownShortcutsCycleOptions",
shun-iwasawa 390cff
  //       QMetaType::Int,
shun-iwasawa 390cff
  //       1);  // Cycle through the available options (changed from bool to
shun-iwasawa 390cff
  //       int)
shun-iwasawa 8fb291
  define(FillOnlysavebox, "FillOnlysavebox", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(multiLayerStylePickerEnabled, "multiLayerStylePickerEnabled",
shun-iwasawa 8fb291
         QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(cursorBrushType, "cursorBrushType", QMetaType::QString, "Small");
shun-iwasawa 8fb291
  define(cursorBrushStyle, "cursorBrushStyle", QMetaType::QString, "Default");
shun-iwasawa 8fb291
  define(cursorOutlineEnabled, "cursorOutlineEnabled", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(levelBasedToolsDisplay, "levelBasedToolsDisplay", QMetaType::Int,
shun-iwasawa 8fb291
         0);  // Default
Kite 521c84
  define(useCtrlAltToResizeBrush, "useCtrlAltToResizeBrush", QMetaType::Bool,
Kite 521c84
         true);
Kite ce2d82
  define(tempToolSwitchTimer, "tempToolSwitchTimer", QMetaType::Int, 500, 1,
Kite ce2d82
         std::numeric_limits<int>::max());</int>
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Xsheet
shun-iwasawa 8fb291
  define(xsheetLayoutPreference, "xsheetLayoutPreference", QMetaType::QString,
shun-iwasawa 8fb291
         "Classic-revised");
shun-iwasawa 8fb291
  define(xsheetStep, "xsheetStep", QMetaType::Int, 10, 0,
shun-iwasawa 8fb291
         std::numeric_limits<int>::max());</int>
shun-iwasawa 8fb291
  define(xsheetAutopanEnabled, "xsheetAutopanEnabled", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(DragCellsBehaviour, "DragCellsBehaviour", QMetaType::Int,
shun-iwasawa 8fb291
         1);  // Cells and Column Data
shun-iwasawa 8fb291
  define(ignoreAlphaonColumn1Enabled, "ignoreAlphaonColumn1Enabled",
shun-iwasawa 8fb291
         QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(showKeyframesOnXsheetCellArea, "showKeyframesOnXsheetCellArea",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(showXsheetCameraColumn, "showXsheetCameraColumn", QMetaType::Bool,
shun-iwasawa 8fb291
         true);
shun-iwasawa 8fb291
  define(useArrowKeyToShiftCellSelection, "useArrowKeyToShiftCellSelection",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(inputCellsWithoutDoubleClickingEnabled,
shun-iwasawa 8fb291
         "inputCellsWithoutDoubleClickingEnabled", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(shortcutCommandsWhileRenamingCellEnabled,
shun-iwasawa 8fb291
         "shortcutCommandsWhileRenamingCellEnabled", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(showXSheetToolbar, "showXSheetToolbar", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(expandFunctionHeader, "expandFunctionHeader", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(showColumnNumbers, "showColumnNumbers", QMetaType::Bool, false);
justburner c2d6ed
  define(parentColorsInXsheetColumn, "parentColorsInXsheetColumn",
justburner c2d6ed
         QMetaType::Bool, false);
shun-iwasawa fe3506
  define(highlightLineEverySecond, "highlightLineEverySecond", QMetaType::Bool,
shun-iwasawa fe3506
         false);
shun-iwasawa 8fb291
  define(syncLevelRenumberWithXsheet, "syncLevelRenumberWithXsheet",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(currentTimelineEnabled, "currentTimelineEnabled", QMetaType::Bool,
shun-iwasawa 8fb291
         true);
shun-iwasawa 8fb291
  define(currentColumnColor, "currentColumnColor", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(Qt::yellow));
shun-iwasawa 855b12
  // define(levelNameOnEachMarkerEnabled, "levelNameOnEachMarkerEnabled",
shun-iwasawa 855b12
  //  QMetaType::Bool, false);
shun-iwasawa 855b12
  define(levelNameDisplayType, "levelNameDisplayType", QMetaType::Int,
shun-iwasawa 855b12
         0);  // default
shun-iwasawa 855b12
  define(showFrameNumberWithLetters, "showFrameNumberWithLetters",
shun-iwasawa 855b12
         QMetaType::Bool, false);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Animation
shun-iwasawa 8fb291
  define(keyframeType, "keyframeType", QMetaType::Int, 2);  // Linear
shun-iwasawa 8fb291
  define(animationStep, "animationStep", QMetaType::Int, 1, 1, 500);
shun-iwasawa 4a3868
  define(modifyExpressionOnMovingReferences,
shun-iwasawa 4a3868
         "modifyExpressionOnMovingReferences", QMetaType::Bool, false);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Preview
shun-iwasawa 8fb291
  define(blanksCount, "blanksCount", QMetaType::Int, 0, 0, 1000);
shun-iwasawa 8fb291
  define(blankColor, "blankColor", QMetaType::QColor, QColor(Qt::white));
shun-iwasawa 8fb291
  define(rewindAfterPlayback, "rewindAfterPlayback", QMetaType::Bool, true);
Jeremy Bullock 552fd4
  define(shortPlayFrameCount, "shortPlayFrameCount", QMetaType::Int, 8, 1, 100);
shun-iwasawa 8fb291
  define(previewAlwaysOpenNewFlip, "previewAlwaysOpenNewFlip", QMetaType::Bool,
shun-iwasawa 8fb291
         false);
shun-iwasawa 8fb291
  define(fitToFlipbook, "fitToFlipbook", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(generatedMovieViewEnabled, "generatedMovieViewEnabled",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Onion Skin
shun-iwasawa 8fb291
  define(onionSkinEnabled, "onionSkinEnabled", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(onionPaperThickness, "onionPaperThickness", QMetaType::Int, 50, 0,
shun-iwasawa 8fb291
         100);
shun-iwasawa 8fb291
  define(backOnionColor, "backOnionColor", QMetaType::QColor, QColor(Qt::red));
shun-iwasawa 8fb291
  define(frontOnionColor, "frontOnionColor", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(Qt::green));
shun-iwasawa 8fb291
  define(onionInksOnly, "onionInksOnly", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(onionSkinDuringPlayback, "onionSkinDuringPlayback", QMetaType::Bool,
shun-iwasawa 8fb291
         false);
shun-iwasawa 8fb291
  define(useOnionColorsForShiftAndTraceGhosts,
shun-iwasawa 8fb291
         "useOnionColorsForShiftAndTraceGhosts", QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(animatedGuidedDrawing, "animatedGuidedDrawing", QMetaType::Int,
shun-iwasawa 8fb291
         0);  // Arrow Markers (changed from bool to int)
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Colors
shun-iwasawa 8fb291
  define(viewerBGColor, "viewerBGColor", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(128, 128, 128));
shun-iwasawa 8fb291
  define(previewBGColor, "previewBGColor", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(64, 64, 64));
shun-iwasawa 8fb291
  define(levelEditorBoxColor, "levelEditorBoxColor", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(128, 128, 128));
shun-iwasawa 8fb291
  define(chessboardColor1, "chessboardColor1", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(180, 180, 180));
shun-iwasawa 8fb291
  define(chessboardColor2, "chessboardColor2", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(230, 230, 230));
shun-iwasawa 8fb291
  define(transpCheckInkOnWhite, "transpCheckInkOnWhite", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(Qt::black));
shun-iwasawa 8fb291
  define(transpCheckInkOnBlack, "transpCheckInkOnBlack", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(Qt::white));
shun-iwasawa 8fb291
  define(transpCheckPaint, "transpCheckPaint", QMetaType::QColor,
shun-iwasawa 8fb291
         QColor(127, 127, 127));
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Version Control
shun-iwasawa 8fb291
  define(SVNEnabled, "SVNEnabled", QMetaType::Bool, false);
shun-iwasawa 8fb291
  define(automaticSVNFolderRefreshEnabled, "automaticSVNFolderRefreshEnabled",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
  define(latestVersionCheckEnabled, "latestVersionCheckEnabled",
shun-iwasawa 8fb291
         QMetaType::Bool, true);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Touch / Tablet Settings
shun-iwasawa 8fb291
  // TounchGestureControl // Touch Gesture is a checkable command and not in
shun-iwasawa 8fb291
  // preferences.ini
shun-iwasawa 8fb291
  define(winInkEnabled, "winInkEnabled", QMetaType::Bool, false);
shun-iwasawa 19cec1
  // This option will be shown & available only when WITH_WINTAB is defined
shun-iwasawa 19cec1
  define(useQtNativeWinInk, "useQtNativeWinInk", QMetaType::Bool, false);
shun-iwasawa 8fb291
shun-iwasawa 8fb291
  // Others (not appeared in the popup)
shun-iwasawa 8fb291
  // Shortcut popup settings
shun-iwasawa 8fb291
  define(shortcutPreset, "shortcutPreset", QMetaType::QString, "defopentoonz");
shun-iwasawa 8fb291
  // Viewer context menu
shun-iwasawa 8fb291
  define(guidedDrawingType, "guidedDrawingType", QMetaType::Int, 0);  // Off
manongjohn 40a40e
  define(guidedAutoInbetween, "guidedAutoInbetween", QMetaType::Bool,
manongjohn 40a40e
         false);  // Off
manongjohn 40a40e
  define(guidedInterpolationType, "guidedInterpolationType", QMetaType::Int,
manongjohn 40a40e
         1);  // Linear
shun-iwasawa 8fb291
#if defined(MACOSX) && defined(__LP64__)
shun-iwasawa 8fb291
  // OSX shared memory settings
shun-iwasawa 8fb291
  define(shmmax, "shmmax", QMetaType::Int, -1);
shun-iwasawa 8fb291
  define(shmseg, "shmseg", QMetaType::Int, -1);
shun-iwasawa 8fb291
  define(shmall, "shmall", QMetaType::Int, -1);
shun-iwasawa 8fb291
  define(shmmni, "shmmni", QMetaType::Int, -1);
shun-iwasawa 8fb291
#endif
shun_iwasawa 9f6fb4
}
shun_iwasawa 9f6fb4
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::define(PreferencesItemId id, QString idString,
shun-iwasawa 8fb291
                         QMetaType::Type type, QVariant defaultValue,
shun-iwasawa 8fb291
                         QVariant min, QVariant max) {
shun-iwasawa 8fb291
  // load value
shun-iwasawa 8fb291
  QVariant value(defaultValue);
shun-iwasawa 8fb291
  switch (type) {
shun-iwasawa 8fb291
  case QMetaType::Bool:
shun-iwasawa 8fb291
  case QMetaType::Int:
shun-iwasawa 8fb291
  case QMetaType::Double:
shun-iwasawa 8fb291
  case QMetaType::QString:
shun-iwasawa 8fb291
    if (m_settings->contains(idString) &&
shun-iwasawa 8fb291
        m_settings->value(idString).canConvert(type))
shun-iwasawa 8fb291
      value = m_settings->value(idString);
shun-iwasawa 8fb291
    break;
shun-iwasawa 8fb291
  case QMetaType::QSize:  // used in iconSize
shun-iwasawa 8fb291
    if (m_settings->contains(idString) &&
shun-iwasawa 8fb291
        m_settings->value(idString).canConvert(QMetaType::QSize))
shun-iwasawa 8fb291
      value = m_settings->value(idString);
shun-iwasawa 8fb291
    // to keep compatibility with older versions
shun-iwasawa 8fb291
    else if (m_settings->contains(idString + "X")) {
shun-iwasawa 8fb291
      QSize size = value.toSize();
shun-iwasawa 8fb291
      size.setWidth(m_settings->value(idString + "X", size.width()).toInt());
shun-iwasawa 8fb291
      size.setHeight(m_settings->value(idString + "Y", size.height()).toInt());
shun-iwasawa 8fb291
      value.setValue(size);
shun-iwasawa 8fb291
    }
shun-iwasawa 8fb291
    break;
shun-iwasawa 8fb291
  case QMetaType::QMetaType::QColor:
shun-iwasawa 8fb291
    if (m_settings->contains(idString)) {
shun-iwasawa 8fb291
      QString str = m_settings->value(idString).toString();
shun-iwasawa 8fb291
      value.setValue(stringToColor(str));
shun-iwasawa 8fb291
    }
shun-iwasawa 8fb291
    // following two conditions are to keep compatibility with older versions
shun-iwasawa 8fb291
    else if (m_settings->contains(idString + "_R")) {
shun-iwasawa 8fb291
      QColor color = value.value<qcolor>();</qcolor>
shun-iwasawa 8fb291
      color.setRed(m_settings->value(idString + "_R", color.red()).toInt());
shun-iwasawa 8fb291
      color.setGreen(m_settings->value(idString + "_G", color.green()).toInt());
shun-iwasawa 8fb291
      color.setBlue(m_settings->value(idString + "_B", color.blue()).toInt());
shun-iwasawa 8fb291
      color.setAlpha(m_settings->value(idString + "_M", color.alpha()).toInt());
shun-iwasawa 8fb291
      value.setValue(color);
shun-iwasawa 8fb291
    } else if (m_settings->contains(idString + ".r")) {
shun-iwasawa 8fb291
      QColor color = value.value<qcolor>();</qcolor>
shun-iwasawa 8fb291
      color.setRed(m_settings->value(idString + ".r", color.red()).toInt());
shun-iwasawa 8fb291
      color.setGreen(m_settings->value(idString + ".g", color.green()).toInt());
shun-iwasawa 8fb291
      color.setBlue(m_settings->value(idString + ".b", color.blue()).toInt());
shun-iwasawa 8fb291
      color.setAlpha(255);
shun-iwasawa 8fb291
      value.setValue(color);
shun-iwasawa 8fb291
    }
shun-iwasawa 8fb291
    break;
shun-iwasawa 8fb291
  case QMetaType::QVariantMap:  // used in colorCalibrationLutPaths
shun-iwasawa 8fb291
    if (m_settings->contains(idString) &&
shun-iwasawa 8fb291
        m_settings->value(idString).canConvert(type)) {
shun-iwasawa 8fb291
      QMap<qstring, qstring=""> pathMap;</qstring,>
shun-iwasawa 8fb291
      QAssociativeIterable iterable =
shun-iwasawa 8fb291
          m_settings->value(idString).value<qassociativeiterable>();</qassociativeiterable>
shun-iwasawa 8fb291
      QAssociativeIterable::const_iterator it        = iterable.begin();
shun-iwasawa 8fb291
      const QAssociativeIterable::const_iterator end = iterable.end();
shun-iwasawa 8fb291
      for (; it != end; ++it)
shun-iwasawa 8fb291
        pathMap.insert(it.key().toString(), it.value().toString());
shun-iwasawa 8fb291
      value.setValue(pathMap);
shun-iwasawa 8fb291
    }
shun-iwasawa 8fb291
    break;
shun-iwasawa 8fb291
  default:
shun-iwasawa 8fb291
    std::cout << "Unsupported type detected" << std::endl;
shun-iwasawa 8fb291
    // load anyway
shun-iwasawa 8fb291
    value = m_settings->value(idString, value);
shun-iwasawa 8fb291
    break;
shun-iwasawa 8fb291
  }
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
  m_items.insert(id, PreferencesItem(idString, type, value, min, max));
Jeremy Bullock 890b52
}
Jeremy Bullock 890b52
Jeremy Bullock 890b52
//-----------------------------------------------------------------
Jeremy Bullock 890b52
shun-iwasawa 8fb291
void Preferences::setCallBack(const PreferencesItemId id, OnEditedFunc func) {
shun-iwasawa 8fb291
  getItem(id).onEditedFunc = func;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 536025
void Preferences::resolveCompatibility() {
shun-iwasawa 536025
  // autocreation type is divided into "EnableAutocreation" and
shun-iwasawa 536025
  // "NumberingSystem"
shun-iwasawa 536025
  if (m_settings->contains("AutocreationType") &&
shun-iwasawa 536025
      !m_settings->contains("EnableAutocreation")) {
shun-iwasawa 536025
    int type = m_settings->value("AutocreationType").toInt();
shun-iwasawa 536025
    switch (type) {
shun-iwasawa 536025
    case 0:  // former "Disabled"
shun-iwasawa 536025
      setValue(EnableAutocreation, false);
shun-iwasawa 536025
      break;
shun-iwasawa 536025
    case 1:  // former "Enabled"
shun-iwasawa 536025
      setValue(EnableAutocreation, true);
shun-iwasawa 536025
      setValue(NumberingSystem, 0);  // set numbering system to "Incremental"
shun-iwasawa 536025
      break;
shun-iwasawa 536025
    case 2:  // former "Use Xsheet as Animation Sheet"
shun-iwasawa 536025
      setValue(EnableAutocreation, true);
shun-iwasawa 536025
      setValue(NumberingSystem, 1);
shun-iwasawa 536025
      break;
shun-iwasawa 536025
    }
shun-iwasawa 536025
  }
shun-iwasawa 855b12
  // "levelNameOnEachMarkerEnabled" is changed to "levelNameDisplayType", adding
shun-iwasawa 855b12
  // a new option
shun-iwasawa 855b12
  if (m_settings->contains("levelNameOnEachMarkerEnabled") &&
shun-iwasawa 855b12
      !m_settings->contains("levelNameDisplayType")) {
shun-iwasawa 855b12
    if (m_settings->value("levelNameOnEachMarkerEnabled")
shun-iwasawa 855b12
            .toBool())  // show level name on each marker
shun-iwasawa 855b12
      setValue(levelNameDisplayType, ShowLevelNameOnEachMarker);
shun-iwasawa 855b12
    else  // Default (level name on top of each cell block)
shun-iwasawa 855b12
      setValue(levelNameDisplayType, ShowLevelName_Default);
shun-iwasawa 855b12
  }
shun-iwasawa fc0d80
  // "scanLevelType" is changed to "DefRasterFormat", enabling to specify
shun-iwasawa fc0d80
  // default format for both the Scan and the Raster levels.
shun-iwasawa fc0d80
  if (m_settings->contains("scanLevelType") &&
shun-iwasawa fc0d80
      !m_settings->contains("DefRasterFormat")) {
shun-iwasawa fc0d80
    setValue(DefRasterFormat, m_settings->value("scanLevelType").toString());
shun-iwasawa fc0d80
  }
shun-iwasawa 536025
}
shun-iwasawa 536025
shun-iwasawa 536025
//-----------------------------------------------------------------
shun-iwasawa 536025
shun-iwasawa 8fb291
PreferencesItem &Preferences::getItem(const PreferencesItemId id) {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  return m_items[id];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
bool Preferences::getBoolValue(const PreferencesItemId id) const {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return false;
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(id);
shun-iwasawa 8fb291
  assert(item.type == QMetaType::Bool);
shun-iwasawa 8fb291
  if (item.type != QMetaType::Bool) return false;
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
  return item.value.toBool();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
int Preferences::getIntValue(const PreferencesItemId id) const {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return -1;
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(id);
shun-iwasawa 8fb291
  assert(item.type == QMetaType::Int);
shun-iwasawa 8fb291
  if (item.type != QMetaType::Int) return -1;
Jeremy Bullock 33e7d1
shun-iwasawa 8fb291
  return item.value.toInt();
Jeremy Bullock 33e7d1
}
Jeremy Bullock 33e7d1
Jeremy Bullock 33e7d1
//-----------------------------------------------------------------
Jeremy Bullock 33e7d1
shun-iwasawa 8fb291
double Preferences::getDoubleValue(const PreferencesItemId id) const {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return -1.0;
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(id);
shun-iwasawa 8fb291
  assert(item.type == QMetaType::Double);
shun-iwasawa 8fb291
  if (item.type != QMetaType::Double) return -1.0;
Jeremy Bullock bfe861
shun-iwasawa 8fb291
  return item.value.toDouble();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
QString Preferences::getStringValue(const PreferencesItemId id) const {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return QString();
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(id);
shun-iwasawa 8fb291
  assert(item.type == QMetaType::QString);
shun-iwasawa 8fb291
  if (item.type != QMetaType::QString) return QString();
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
  return item.value.toString();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
TPixel Preferences::getColorValue(const PreferencesItemId id) const {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return TPixel();
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(id);
shun-iwasawa 8fb291
  assert(item.type == QMetaType::QColor);
shun-iwasawa 8fb291
  if (item.type != QMetaType::QColor) return TPixel();
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
  return colorToTPixel(item.value.value<qcolor>());</qcolor>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
TDimension Preferences::getSizeValue(const PreferencesItemId id) const {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return TDimension();
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(id);
shun-iwasawa 8fb291
  assert(item.type == QMetaType::QSize);
shun-iwasawa 8fb291
  if (item.type != QMetaType::QSize) return TDimension();
shun-iwasawa 8fb291
  QSize size = item.value.toSize();
shun-iwasawa 8fb291
  return TDimension(size.width(), size.height());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
shun-iwasawa 8fb291
// saveToFile is true by default, becomes false when dragging color field
shun-iwasawa 8fb291
void Preferences::setValue(const PreferencesItemId id, QVariant value,
shun-iwasawa 8fb291
                           bool saveToFile) {
shun-iwasawa 8fb291
  assert(m_items.contains(id));
shun-iwasawa 8fb291
  if (!m_items.contains(id)) return;
shun-iwasawa 8fb291
  m_items[id].value = value;
shun-iwasawa 8fb291
  if (saveToFile) {
shun-iwasawa 8fb291
    if (m_items[id].type ==
shun-iwasawa 8fb291
        QMetaType::QColor)  // write in human-readable format
shun-iwasawa 8fb291
      m_settings->setValue(m_items[id].idString,
shun-iwasawa 8fb291
                           colorToString(value.value<qcolor>()));</qcolor>
shun-iwasawa 8fb291
    else if (m_items[id].type ==
shun-iwasawa 8fb291
             QMetaType::Bool)  // write 1/0 instead of true/false to keep
shun-iwasawa 8fb291
                               // compatibility
shun-iwasawa 8fb291
      m_settings->setValue(m_items[id].idString, value.toBool() ? "1" : "0");
shun-iwasawa 8fb291
    else
shun-iwasawa 8fb291
      m_settings->setValue(m_items[id].idString, value);
shun-iwasawa 8fb291
  }
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
  // execute callback
shun-iwasawa 8fb291
  if (m_items[id].onEditedFunc) (this->*(m_items[id].onEditedFunc))();
shun-iwasawa 133733
}
shun-iwasawa 133733
shun-iwasawa 133733
//-----------------------------------------------------------------
shun-iwasawa 133733
shun-iwasawa 8fb291
void Preferences::enableAutosave() {
shun-iwasawa 8fb291
  bool autoSaveOn = getBoolValue(autosaveEnabled);
shun-iwasawa 8fb291
  if (autoSaveOn)
shun-iwasawa 8fb291
    emit startAutoSave();
shun-iwasawa 8fb291
  else
shun-iwasawa 8fb291
    emit stopAutoSave();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::setAutosavePeriod() {
Shinya Kitaoka 120a6e
  emit stopAutoSave();
Shinya Kitaoka 120a6e
  emit startAutoSave();
Jeremy Bullock 4c6224
  emit autoSavePeriodChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::setUndoMemorySize() {
shun-iwasawa 8fb291
  int memorySize = getIntValue(undoMemorySize);
shun-iwasawa 8fb291
  TUndoManager::manager()->setUndoMemorySize(memorySize);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::setPixelsOnly() {
shun-iwasawa 8fb291
  bool pixelSelected = getBoolValue(pixelsOnly);
shun-iwasawa 8fb291
  if (pixelSelected)
Jeremy Bullock 59dbbf
    storeOldUnits();
shun-iwasawa 8fb291
  else
Jeremy Bullock 59dbbf
    resetOldUnits();
Jeremy Bullock e59b1f
}
Jeremy Bullock e59b1f
Jeremy Bullock e59b1f
//-----------------------------------------------------------------
Jeremy Bullock e59b1f
shun-iwasawa 8fb291
void Preferences::setUnits() {
shun-iwasawa 8fb291
  std::string units = getStringValue(linearUnits).toStdString();
Shinya Kitaoka 120a6e
  setCurrentUnits("length", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("length.x", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("length.y", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("length.lx", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("length.ly", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("fxLength", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("pippo", units);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::setCameraUnits() {
shun-iwasawa 8fb291
  std::string units = getStringValue(cameraUnits).toStdString();
Shinya Kitaoka 120a6e
  setCurrentUnits("camera.lx", units);
Shinya Kitaoka 120a6e
  setCurrentUnits("camera.ly", units);
Toshihiro Shimizu 890ddd
}
turtletooth 8d9ba3
turtletooth 8d9ba3
//-----------------------------------------------------------------
turtletooth 8d9ba3
shun-iwasawa 8fb291
void Preferences::setRasterBackgroundColor() {
shun-iwasawa 8fb291
  TPixel color = getColorValue(rasterBackgroundColor);
shun-iwasawa 8fb291
  TImageWriter::setBackgroundColor(color);
turtletooth 8d9ba3
}
turtletooth 8d9ba3
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::storeOldUnits() {
shun-iwasawa 8fb291
  setValue(oldUnits, getStringValue(linearUnits));
shun-iwasawa 8fb291
  setValue(oldCameraUnits, getStringValue(cameraUnits));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
void Preferences::resetOldUnits() {
shun-iwasawa 8fb291
  QString oldLinearU = getStringValue(oldUnits);
shun-iwasawa 8fb291
  QString oldCameraU = getStringValue(oldCameraUnits);
shun-iwasawa 8fb291
  if (oldLinearU != "" && oldCameraU != "") {
shun-iwasawa 8fb291
    setValue(linearUnits, oldLinearU);
shun-iwasawa 8fb291
    setValue(cameraUnits, oldCameraU);
shun-iwasawa 8fb291
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString Preferences::getCurrentLanguage() const {
shun-iwasawa 8fb291
  QString lang = getStringValue(CurrentLanguageName);
shun-iwasawa 8fb291
  if (m_languageList.contains(lang)) return lang;
shun-iwasawa 9031b4
  // If no valid option selected, then return English
shun-iwasawa 9031b4
  return m_languageList[0];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa c54dfb
QString Preferences::getCurrentStyleSheet() const {
shun-iwasawa 8fb291
  QString currentStyleSheetName = getStringValue(CurrentStyleSheetName);
shun-iwasawa 8fb291
  if (currentStyleSheetName.isEmpty()) return QString();
shun-iwasawa 9031b4
  TFilePath path(TEnv::getConfigDir() + "qss");
shun-iwasawa 8fb291
  QString string = currentStyleSheetName + QString("/") +
shun-iwasawa 8fb291
                   currentStyleSheetName + QString(".qss");
shun-iwasawa c54dfb
  QString styleSheetPath = path.getQString() + "/" + string;
shun-iwasawa c54dfb
shun-iwasawa c54dfb
  QString additionalSheetStr = getStringValue(additionalStyleSheet);
shun-iwasawa c54dfb
  // if there is no additional style sheet, return the path and let
shun-iwasawa c54dfb
  // Qt to load and parse it
shun-iwasawa c54dfb
  if (additionalSheetStr.isEmpty()) return QString("file:///" + styleSheetPath);
shun-iwasawa c54dfb
shun-iwasawa c54dfb
  // if there is any additional style sheet, load the style sheet
shun-iwasawa c54dfb
  // from the file and combine with it
shun-iwasawa c54dfb
  QString styleSheetStr;
shun-iwasawa c54dfb
  QFile f(styleSheetPath);
shun-iwasawa c54dfb
  if (f.open(QFile::ReadOnly | QFile::Text)) {
shun-iwasawa c54dfb
    QTextStream ts(&f);
shun-iwasawa c54dfb
    styleSheetStr = ts.readAll();
shun-iwasawa c54dfb
  }
shun-iwasawa c54dfb
  styleSheetStr += additionalSheetStr;
shun-iwasawa c54dfb
shun-iwasawa c54dfb
  // here we will convert all relative paths to absolute paths
shun-iwasawa c54dfb
  // or Qt will look for images relative to the current working directory
shun-iwasawa c54dfb
  // since it has no idea where the style sheet comes from.
shun-iwasawa c54dfb
shun-iwasawa c54dfb
  QString currentStyleFolderPath =
shun-iwasawa c54dfb
      path.getQString().replace("\\", "/") + "/" + currentStyleSheetName;
shun-iwasawa c54dfb
shun-iwasawa c54dfb
  styleSheetStr.replace(QRegExp("url\\(['\"]([^'\"]+)['\"]\\)"),
shun-iwasawa c54dfb
                        "url(\"" + currentStyleFolderPath + QString("/\\1\")"));
shun-iwasawa c54dfb
shun-iwasawa c54dfb
  return styleSheetStr;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
turtletooth 04d8fd
void Preferences::setPrecompute(bool enabled) { m_precompute = enabled; }
turtletooth 04d8fd
turtletooth 04d8fd
//-----------------------------------------------------------------
turtletooth 04d8fd
Shinya Kitaoka 120a6e
int Preferences::addLevelFormat(const LevelFormat &format) {
Shinya Kitaoka 120a6e
  LevelFormatVector::iterator lft = m_levelFormats.insert(
Shinya Kitaoka 120a6e
      std::upper_bound(m_levelFormats.begin(), m_levelFormats.end(), format,
Shinya Kitaoka 120a6e
                       formatLess),
Shinya Kitaoka 120a6e
      format);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int formatIdx = int(
Shinya Kitaoka 120a6e
      lft -
Shinya Kitaoka 120a6e
      m_levelFormats.begin());  // NOTE: Must be disjoint from the instruction
Shinya Kitaoka 120a6e
  //       above, since operator-'s param evaluation
Shinya Kitaoka 120a6e
  //       order is unspecified
shun-iwasawa 8fb291
  _setValue(*m_settings, m_levelFormats);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return formatIdx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Preferences::removeLevelFormat(int formatIdx) {
Shinya Kitaoka 120a6e
  assert(0 <= formatIdx && formatIdx < int(m_levelFormats.size()));
Shinya Kitaoka 120a6e
  m_levelFormats.erase(m_levelFormats.begin() + formatIdx);
Toshihiro Shimizu 890ddd
shun-iwasawa 8fb291
  _setValue(*m_settings, m_levelFormats);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const Preferences::LevelFormat &Preferences::levelFormat(int formatIdx) const {
Shinya Kitaoka 120a6e
  assert(0 <= formatIdx && formatIdx < int(m_levelFormats.size()));
Shinya Kitaoka 120a6e
  return m_levelFormats[formatIdx];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int Preferences::levelFormatsCount() const {
Shinya Kitaoka 120a6e
  return int(m_levelFormats.size());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int Preferences::matchLevelFormat(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  LevelFormatVector::const_iterator lft =
Shinya Kitaoka 120a6e
      std::find_if(m_levelFormats.begin(), m_levelFormats.end(),
Shinya Kitaoka 120a6e
                   boost::bind(&LevelFormat::matches, _1, boost::cref(fp)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (lft != m_levelFormats.end()) ? lft - m_levelFormats.begin() : -1;
Toshihiro Shimizu 890ddd
}
shun_iwasawa 4635d8
shun_iwasawa 4635d8
//-----------------------------------------------------------------
shun_iwasawa 4635d8
shun-iwasawa ad7711
void Preferences::setColorCalibrationLutPath(QString monitorName,
shun-iwasawa ad7711
                                             QString path) {
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(colorCalibrationLutPaths);
shun-iwasawa 8fb291
  QMap<qstring, qvariant=""> lutPathMap =</qstring,>
shun-iwasawa 8fb291
      item.value.value<qmap<qstring, qvariant="">>();</qmap<qstring,>
shun-iwasawa 8fb291
  lutPathMap.insert(monitorName, path);
shun-iwasawa 8fb291
  setValue(colorCalibrationLutPaths, lutPathMap);
shun-iwasawa ad7711
}
shun-iwasawa ad7711
manongjohn 29ce0b
//-----------------------------------------------------------------
manongjohn 29ce0b
shun-iwasawa 8fb291
QString Preferences::getColorCalibrationLutPath(QString &monitorName) const {
shun-iwasawa 8fb291
  PreferencesItem item = m_items.value(colorCalibrationLutPaths);
shun-iwasawa a8f111
  QMap<qstring, qvariant=""> lutPathMap =</qstring,>
shun-iwasawa a8f111
      item.value.value<qmap<qstring, qvariant="">>();</qmap<qstring,>
John Dancel 421acd
shun-iwasawa a8f111
  return lutPathMap.value(monitorName).toString();
John Dancel 421acd
}