Example #1
0
bool StudioPaletteTreeViewer::isRootItem(QTreeWidgetItem *item) {
  assert(item);
  TFilePath path = getItemPath(item);

  StudioPalette *studioPalette = StudioPalette::instance();
  if (path == studioPalette->getLevelPalettesRoot() ||
      path == studioPalette->getProjectPalettesRoot())
    return true;

  return false;
}
Example #2
0
void StudioPaletteTreeViewer::refresh() {
  m_openedItems.clear();

  StudioPalette *studioPalette = StudioPalette::instance();

  TFilePath levelPalettePath = studioPalette->getLevelPalettesRoot();
  refreshItem(getItem(levelPalettePath));

  TFilePath projectPalettePath = studioPalette->getProjectPalettesRoot();
  if (!TSystem::doesExistFileOrLevel(projectPalettePath)) return;
  refreshItem(getItem(projectPalettePath));

  // refresh all expanded items
  QList<QTreeWidgetItem *> items =
      findItems(QString(""), Qt::MatchContains | Qt::MatchRecursive, 0);
  if (items.isEmpty()) return;

  for (int i = 0; i < (int)items.size(); i++)
    if (items[i]->isExpanded()) refreshItem(items[i]);
}
Example #3
0
StudioPaletteTreeViewer::StudioPaletteTreeViewer(
    QWidget *parent, TPaletteHandle *studioPaletteHandle,
    TPaletteHandle *levelPaletteHandle, TXsheetHandle *xsheetHandle,
    TXshLevelHandle *currentLevelHandle)
    : QTreeWidget(parent)
    , m_dropItem(0)
    , m_studioPaletteHandle(studioPaletteHandle)
    , m_levelPaletteHandle(levelPaletteHandle)
    , m_currentLevelHandle(currentLevelHandle)
    , m_xsheetHandle(xsheetHandle)
    , m_folderIcon(QIcon())
    , m_levelPaletteIcon(QIcon())
    , m_studioPaletteIcon(QIcon()) {
  setIndentation(14);
  setAlternatingRowColors(true);

  header()->close();
  setUniformRowHeights(true);
  setIconSize(QSize(21, 17));

  QList<QTreeWidgetItem *> paletteItems;

  QString open  = QString(":Resources/folder_close.svg");
  QString close = QString(":Resources/folder_open.svg");
  m_folderIcon.addFile(close, QSize(21, 17), QIcon::Normal, QIcon::On);
  m_folderIcon.addFile(open, QSize(21, 17), QIcon::Normal, QIcon::Off);

  QString levelPaletteIcon = QString(":Resources/palette.svg");
  m_levelPaletteIcon.addPixmap(levelPaletteIcon, QIcon::Normal, QIcon::On);
  QString studioPaletteIcon = QString(":Resources/studiopalette.svg");
  m_studioPaletteIcon.addPixmap(studioPaletteIcon, QIcon::Normal, QIcon::On);

  StudioPalette *studioPalette = StudioPalette::instance();

  TFilePath levelPalettePath = studioPalette->getLevelPalettesRoot();
  paletteItems.append(createRootItem(levelPalettePath));

  TFilePath projectPalettePath = studioPalette->getProjectPalettesRoot();
  if (TSystem::doesExistFileOrLevel(projectPalettePath))
    paletteItems.append(createRootItem(projectPalettePath));

  insertTopLevelItems(0, paletteItems);

  bool ret = connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
                     SLOT(onItemChanged(QTreeWidgetItem *, int)));
  ret = ret && connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
                       SLOT(onItemClicked(QTreeWidgetItem *, int)));
  ret =
      ret &&
      connect(this,
              SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
              SLOT(onCurrentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
  ret = ret && connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
                       SLOT(onTreeItemExpanded(QTreeWidgetItem *)));

  // refresh tree with shortcut key
  QAction *refreshAct = CommandManager::instance()->getAction(MI_RefreshTree);
  ret                 = ret && connect(refreshAct, SIGNAL(triggered()), this,
                       SLOT(onRefreshTreeShortcutTriggered()));
  addAction(refreshAct);

  m_palettesScanPopup = new PalettesScanPopup();

  setAcceptDrops(true);

  // Per la selezione multipla
  setSelectionMode(QAbstractItemView::ExtendedSelection);

  StudioPalette::instance()->addListener(this);
  TProjectManager::instance()->addListener(this);

  refresh();

  assert(ret);
}
Example #4
0
void StudioPaletteTreeViewer::contextMenuEvent(QContextMenuEvent *event) {
  TFilePath path = getCurrentFolderPath();

  StudioPalette *studioPalette = StudioPalette::instance();

  // Menu' per la selezione singola
  QList<QTreeWidgetItem *> items = selectedItems();
  int count                      = items.size();
  if (count == 1) {
    // Verify if click position is in a row containing an item.
    QRect rect = visualItemRect(currentItem());
    if (!QRect(0, rect.y(), width(), rect.height()).contains(event->pos()))
      return;

    bool isFolder = (studioPalette->isFolder(path));

    QMenu menu(this);
    if (isFolder) {
      createMenuAction(menu, "", tr("New Palette"), "addNewPalette()");
      createMenuAction(menu, "", tr("New Folder"), "addNewFolder()");
    }

    if (studioPalette->isFolder(path) &&
        studioPalette->getLevelPalettesRoot() != path &&
        studioPalette->getProjectPalettesRoot() != path) {
      menu.addSeparator();
      createMenuAction(menu, "", tr("Delete Folder"), "deleteItems()");
    } else if (studioPalette->isPalette(path)) {
      if (m_studioPaletteHandle->getPalette()) {
        createMenuAction(menu, "MI_LoadIntoCurrentPalette",
                         tr("Load into Current Palette"),
                         "loadInCurrentPalette()");
        createMenuAction(menu, "MI_AdjustCurrentLevelToPalette",
                         tr("Adjust Current Level to This Palette"),
                         "loadInCurrentPaletteAndAdaptLevel()");
        createMenuAction(menu, "MI_MergeToCurrentPalette",
                         tr("Merge to Current Palette"),
                         "mergeToCurrentPalette()");
        if (!m_studioPaletteHandle->getPalette()->isLocked()) {
          createMenuAction(menu, "MI_ReplaceWithCurrentPalette",
                           tr("Replace with Current Palette"),
                           "replaceCurrentPalette()");
          menu.addSeparator();
          createMenuAction(menu, "MI_DeletePalette", tr("Delete Palette"),
                           "deleteItems()");
        }
      }
      if (!studioPalette->hasGlobalName(path)) {
        menu.addSeparator();
        createMenuAction(menu, "",
                         tr("Convert to Studio Palette and Overwrite"),
                         "convertToStudioPalette()");
      }
    }

    if (isFolder) {
      menu.addSeparator();
      createMenuAction(menu, "", tr("Search for Palettes"),
                       "searchForPalette()");
    }
    menu.exec(event->globalPos());
    return;
  }

  // Menu' per la selezione multipla
  // Verify if click position is in a row containing an item.
  bool areAllPalette      = true;
  bool isClickInSelection = false;
  int i;
  for (i = 0; i < count; i++) {
    QTreeWidgetItem *item = items[i];
    QRect rect            = visualItemRect(item);
    if (QRect(0, rect.y(), width(), rect.height()).contains(event->pos()))
      isClickInSelection                             = true;
    TFilePath path                                   = getItemPath(item);
    if (studioPalette->isFolder(path)) areAllPalette = false;
  }
  if (!isClickInSelection) return;

  QMenu menu(this);
  if (areAllPalette) {
    createMenuAction(menu, "", tr("Load into Current Palette"),
                     "loadInCurrentPalette()");
    createMenuAction(menu, "", tr("Merge to Current Palette"),
                     "mergeToCurrentPalette()");
    createMenuAction(menu, "", tr("Replace with Current Palette"),
                     "replaceCurrentPalette()");
    menu.addSeparator();
  }
  createMenuAction(menu, "", tr("Delete"), "deleteItems()");

  menu.exec(event->globalPos());
}