PsdSettingsPopup::PsdSettingsPopup()
    : Dialog(TApp::instance()->getMainWindow(), true, true, "PsdSettings")
    , m_mode(FLAT) {
  bool ret = true;

  setWindowTitle(tr("Load PSD File"));

  m_filename = new QLabel(tr(""));
  m_filename->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  m_filename->setFixedHeight(WidgetHeight);
  m_parentDir = new QLabel(tr(""));
  m_parentDir->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  m_parentDir->setFixedHeight(WidgetHeight);
  QLabel *nmLbl = new QLabel(tr("Name:"));
  nmLbl->setObjectName("TitleTxtLabel");
  QLabel *ptLbl = new QLabel(tr("Path:"));
  ptLbl->setObjectName("TitleTxtLabel");
  QGridLayout *grid = new QGridLayout();
  grid->setColumnMinimumWidth(0, 65);
  grid->addWidget(nmLbl, 0, 0, Qt::AlignRight);
  grid->addWidget(m_filename, 0, 1, Qt::AlignLeft);
  grid->addWidget(ptLbl, 1, 0, Qt::AlignRight);
  grid->addWidget(m_parentDir, 1, 1, Qt::AlignLeft);
  QHBoxLayout *layinfo = new QHBoxLayout;
  layinfo->addLayout(grid);
  layinfo->addStretch();
  addLayout(layinfo, false);

  /*
          m_psdTree = new QTreeWidget();
          m_psdTree->setIconSize(QSize(21,17));
          m_psdTree->setColumnCount(1);
          m_psdTree->setMaximumHeight(7*WidgetHeight);
          m_psdTree->setHeaderLabel("PSD Info");
          addWidget(m_psdTree);			 */

  addSeparator();

  m_loadMode = new QComboBox();
  QStringList modes;
  modes.push_back("Single Image");
  modes.push_back("Frames");
  modes.push_back("Columns");
  m_loadMode->addItems(modes);
  m_loadMode->setFixedHeight(WidgetHeight);
  m_loadMode->setFixedWidth(120);

  m_modeDescription = new QTextEdit(modesDescription[0]);
  m_modeDescription->setFixedHeight(40);
  m_modeDescription->setMinimumWidth(250);
  m_modeDescription->setReadOnly(true);
  m_createSubXSheet = new CheckBox(tr("Expose in a Sub-xsheet"));
  m_createSubXSheet->setMaximumHeight(WidgetHeight);
  m_createSubXSheet->setEnabled(false);

  m_levelNameType = new QComboBox();
  QStringList types;
  types << tr("FileName#LayerName") << tr("LayerName");
  m_levelNameType->addItems(types);
  m_levelNameType->setFixedHeight(WidgetHeight);
  m_levelNameType->setEnabled(false);

  QLabel *modeLbl = new QLabel(tr("Load As:"));
  modeLbl->setObjectName("TitleTxtLabel");

  QLabel *levelNameLbl = new QLabel(tr("Level Name:"));
  levelNameLbl->setObjectName("TitleTxtLabel");

  QGridLayout *gridMode = new QGridLayout();
  gridMode->setColumnMinimumWidth(0, 65);
  gridMode->setMargin(0);
  gridMode->addWidget(modeLbl, 0, 0, Qt::AlignRight);
  gridMode->addWidget(m_loadMode, 0, 1, Qt::AlignLeft);
  gridMode->addWidget(m_modeDescription, 1, 1, Qt::AlignLeft);
  gridMode->addWidget(m_createSubXSheet, 2, 1, Qt::AlignLeft);
  gridMode->addWidget(levelNameLbl, 3, 0, Qt::AlignRight);
  gridMode->addWidget(m_levelNameType, 3, 1, Qt::AlignLeft);
  QHBoxLayout *modeLayout = new QHBoxLayout;
  modeLayout->addLayout(gridMode);
  modeLayout->addStretch();
  addLayout(modeLayout, false);

  addSeparator(tr("Group Option"));
  m_psdFolderOptions = new QButtonGroup(this);
  QList<QString> folderOptionsList;
  folderOptionsList << tr("Ignore groups");
  folderOptionsList << tr(
      "Expose layers in a group as columns in a sub-xsheet");
  folderOptionsList << tr("Expose layers in a group as frames in a column");

  QGridLayout *gridButton = new QGridLayout();
  gridButton->setColumnMinimumWidth(0, 70);
  int i;
  for (i = 0; i < folderOptionsList.count(); i++) {
    QRadioButton *radioButton = new QRadioButton(folderOptionsList.at(i));
    if (i == 0) radioButton->setChecked(true);

    radioButton->setMaximumHeight(WidgetHeight);
    if (m_mode != COLUMNS) {
      radioButton->setEnabled(false);
    }
    m_psdFolderOptions->addButton(radioButton);
    m_psdFolderOptions->setId(radioButton, i);
    gridButton->addWidget(radioButton, i, 1);
  }
  QHBoxLayout *folderOptLayout = new QHBoxLayout;
  folderOptLayout->addLayout(gridButton);
  folderOptLayout->addStretch();
  addLayout(folderOptLayout, false);

  ret = ret && connect(m_loadMode, SIGNAL(currentIndexChanged(const QString &)),
                       SLOT(onModeChanged(const QString &)));
  assert(ret);
  ret = ret && connect(m_psdFolderOptions, SIGNAL(buttonClicked(int)), this,
                       SLOT(onFolderOptionChange(int)));
  assert(ret);
  m_okBtn     = new QPushButton("OK", this);
  m_cancelBtn = new QPushButton("Cancel", this);
  connect(m_okBtn, SIGNAL(clicked()), this, SLOT(onOk()));
  connect(m_cancelBtn, SIGNAL(clicked()), this, SLOT(close()));
  addButtonBarWidget(m_okBtn, m_cancelBtn);
}