void PsdSettingsPopup::doPsdParser() {
  TFilePath psdpath =
      TApp::instance()->getCurrentScene()->getScene()->decodeFilePath(m_path);
  std::string mode = "";
  switch (m_mode) {
  case FLAT: {
    break;
  }
  case FRAMES: {
    mode = "#frames";
    std::string name =
        psdpath.getName() + "#1" + mode + psdpath.getDottedType();
    psdpath = psdpath.getParentDir() + TFilePath(name);
    break;
  }
  case COLUMNS: {
    std::string name = psdpath.getName() + "#1" + psdpath.getDottedType();
    psdpath          = psdpath.getParentDir() + TFilePath(name);
    break;
  }
  case FOLDER: {
    mode = "#group";
    std::string name =
        psdpath.getName() + "#1" + mode + psdpath.getDottedType();
    psdpath = psdpath.getParentDir() + TFilePath(name);
    break;
  }
  default: {
    assert(false);
    return;
  }
  }
  try {
    m_psdparser = new TPSDParser(psdpath);
    m_psdLevelPaths.clear();
    for (int i = 0; i < m_psdparser->getLevelsCount(); i++) {
      int layerId      = m_psdparser->getLevelId(i);
      std::string name = m_path.getName();
      if (layerId > 0 && m_mode != FRAMES) {
        if (m_levelNameType->currentIndex() == 0)  // FileName#LevelName
          name += "#" + std::to_string(layerId);
        else  // LevelName
          name += "##" + std::to_string(layerId);
      }
      if (mode != "") name += mode;
      name += m_path.getDottedType();
      TFilePath psdpath = m_path.getParentDir() + TFilePath(name);
      m_psdLevelPaths.push_back(psdpath);
    }
  } catch (TImageException &e) {
    error(QString::fromStdString(::to_string(e.getMessage())));
    return;
  }
}
Exemplo n.º 2
0
bool TSystem::doesExistFileOrLevel(const TFilePath &fp) {
  if (TFileStatus(fp).doesExist()) return true;

  if (fp.isLevelName()) {
    const TFilePath &parentDir = fp.getParentDir();
    if (!TFileStatus(parentDir).doesExist()) return false;

    TFilePathSet files;
    try {
      files = TSystem::readDirectory(parentDir, false, true, true);
    } catch (...) {
    }

    TFilePathSet::iterator it, end = files.end();
    for (it = files.begin(); it != end; ++it) {
      if (it->getLevelNameW() == fp.getLevelNameW()) return true;
    }
  } else if (fp.getType() == "psd") {
    QString name(QString::fromStdWString(fp.getWideName()));
    name.append(QString::fromStdString(fp.getDottedType()));

    int sepPos                               = name.indexOf("#");
    int dotPos                               = name.indexOf(".", sepPos);
    int removeChars                          = dotPos - sepPos;
    int doubleUnderscorePos                  = name.indexOf("__", sepPos);
    if (doubleUnderscorePos > 0) removeChars = doubleUnderscorePos - sepPos;

    name.remove(sepPos, removeChars);

    TFilePath psdpath(fp.getParentDir() + TFilePath(name.toStdWString()));
    if (TFileStatus(psdpath).doesExist()) return true;
  }

  return false;
}
Exemplo n.º 3
0
void StudioPaletteTreeViewer::dropEvent(QDropEvent *event) {
  TFilePath newPath = getItemPath(m_dropItem);

  resetDropItem();

  if (newPath.isEmpty()) return;

  const QMimeData *mimeData      = event->mimeData();
  const PaletteData *paletteData = dynamic_cast<const PaletteData *>(mimeData);
  if (paletteData) {
    if (paletteData->hasOnlyPalette()) {
      TPalette *palette = paletteData->getPalette();
      if (!palette) return;

      try {
        StudioPaletteCmd::createPalette(
            newPath, ::to_string(palette->getPaletteName()), palette);
      } catch (TException &e) {
        error("Can't create palette: " +
              QString(::to_string(e.getMessage()).c_str()));
      } catch (...) {
        error("Can't create palette");
      }
    }
    return;
  }

  if (!mimeData->hasUrls() || mimeData->urls().size() == 0) return;

  QList<QUrl> urls = mimeData->urls();
  TUndoManager::manager()->beginBlock();
  int i;
  for (i = 0; i < urls.size(); i++) {
    QUrl url       = urls[i];
    TFilePath path = TFilePath(url.toLocalFile().toStdWString());

    StudioPalette *studioPalette = StudioPalette::instance();
    if (path == newPath || path.getParentDir() == newPath) continue;

    if (isInStudioPalette(path)) {
      TFilePath newPalettePath =
          newPath +
          TFilePath(path.getWideName() + ::to_wstring(path.getDottedType()));
      try {
        StudioPaletteCmd::movePalette(newPalettePath, path);
      } catch (TException &e) {
        error("Can't rename palette: " +
              QString(::to_string(e.getMessage()).c_str()));
      } catch (...) {
        error("Can't rename palette");
      }
    }
  }
  TUndoManager::manager()->endBlock();
  event->setDropAction(Qt::CopyAction);
  event->accept();
}
Exemplo n.º 4
0
void StudioPaletteTreeViewer::onItemChanged(QTreeWidgetItem *item, int column) {
  if (item != currentItem() || isRootItem(item)) return;
  wstring name      = item->text(column).toStdWString();
  TFilePath oldPath = getCurrentFolderPath();
  if (oldPath.isEmpty() || name.empty() || oldPath.getWideName() == name)
    return;
  TFilePath newPath(oldPath.getParentDir() +
                    TFilePath(name + ::to_wstring(oldPath.getDottedType())));
  try {
    StudioPaletteCmd::movePalette(newPath, oldPath);
  } catch (TException &e) {
    error(QString(::to_string(e.getMessage()).c_str()));
    item->setText(column, QString::fromStdWString(oldPath.getWideName()));
  } catch (...) {
    error("Can't rename file");
    item->setText(column, QString::fromStdWString(oldPath.getWideName()));
  }
  refreshItem(getItem(oldPath.getParentDir()));
  setCurrentItem(getItem(newPath));
}
// Per adesso non appare
// Costruisce la stringa delle info della psd da caricare che comparirà nel
// popup:
// Path, Dimensioni, numero di livelli, ecc..
static void doPSDInfo(TFilePath psdpath, QTreeWidget *psdTree) {
  psdTree->clear();
  try {
    TPSDReader *psdreader = new TPSDReader(psdpath);

    TPSDHeaderInfo header = psdreader->getPSDHeaderInfo();
    int width             = header.cols;
    int height            = header.rows;
    int depth             = header.depth;
    int channels          = header.channels;
    int layersCount       = header.layersCount;
    QString filename =
        QString::fromStdString(psdpath.getName() + psdpath.getDottedType());
    QString parentDir =
        QString::fromStdWString(psdpath.getParentDir().getWideString());
    QString dimension = QString::number(width) + "x" + QString::number(height);
    QList<QTreeWidgetItem *> items;
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0, QStringList(QString("Filename: %1").arg(filename))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Parent dir: %1").arg(parentDir))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Dimension: %1").arg(dimension))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Depth: %1").arg(QString::number(depth)))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Channels: %1").arg(QString::number(channels)))));
    QTreeWidgetItem *layersItem = new QTreeWidgetItem((QTreeWidget *)0);
    int count                   = 0;
    QList<QTreeWidgetItem *> layersItemChildren;
    layersItemChildren.append(layersItem);
    int scavenge = 0;
    for (int i = layersCount - 1; i >= 0; i--) {
      TPSDLayerInfo *li = psdreader->getLayerInfo(i);
      int width         = li->right - li->left;
      int height        = li->bottom - li->top;
      QString layerName = li->name;
      if (strcmp(li->name, "</Layer group>") == 0 ||
          strcmp(li->name, "</Layer set>") == 0) {
        scavenge--;
      } else if (li->section > 0 && li->section <= 3) {
        QTreeWidgetItem *child = new QTreeWidgetItem((QTreeWidget *)0);
        child->setText(0, layerName);
        layersItemChildren[scavenge]->addChild(child);
        layersItemChildren.append(child);
        scavenge++;
      } else if (width > 0 && height > 0) {
        if (scavenge >= 0) {
          layersItemChildren[scavenge]->addChild(new QTreeWidgetItem(
              (QTreeWidget *)0, QStringList(QString("%1").arg(layerName))));
          count++;
        }
      }
    }
    QString layerItemText =
        "Layers: " +
        QString::number(count);  //+" ("+QString::number(layersCount)+")";
    layersItem->setText(0, layerItemText);
    items.append(layersItem);

    psdTree->insertTopLevelItems(0, items);
  } catch (TImageException &e) {
    error(QString::fromStdString(::to_string(e.getMessage())));
    return;
  }
}