void StudioPaletteCmd::replaceWithCurrentPalette( TPaletteHandle *paletteHandle, TPaletteHandle *stdPaletteHandle, const TFilePath &fp) { StudioPalette *sp = StudioPalette::instance(); TPalette *palette = sp->getPalette(fp); if (!palette || palette->isLocked()) return; assert(paletteHandle); TPalette *current = paletteHandle->getPalette(); if (!current) return; // keep the studio palette's global name unchanged std::wstring oldGlobalName = palette->getGlobalName(); TPalette *old = palette->clone(); palette->assign(current); // put back the global name palette->setGlobalName(oldGlobalName); sp->setPalette(fp, current, true); TUndoManager::manager()->add( new StudioPaletteAssignUndo(fp, old, current->clone(), paletteHandle)); // Cambio la studioPalette correntette(palette); stdPaletteHandle->setPalette(palette); stdPaletteHandle->notifyPaletteSwitched(); }
void StudioPaletteCmd::updateAllLinkedStyles(TPaletteHandle *paletteHandle, TXsheetHandle *xsheetHandle) { if (!xsheetHandle) return; TXsheet *xsheet = xsheetHandle->getXsheet(); if (!xsheet) return; ToonzScene *scene = xsheet->getScene(); if (!scene) return; // emit signal only if something changed bool somethingChanged = false; StudioPalette *sp = StudioPalette::instance(); TLevelSet *levelSet = scene->getLevelSet(); for (int i = 0; i < levelSet->getLevelCount(); i++) { TXshLevel *xl = levelSet->getLevel(i); TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0; if (!sl) continue; TPalette *palette = sl->getPalette(); if (palette) { somethingChanged = somethingChanged | sp->updateLinkedColors(palette); if (sl->getType() == TZP_XSHLEVEL) { std::vector<TFrameId> fids; sl->getFids(fids); std::vector<TFrameId>::iterator it; for (it = fids.begin(); it != fids.end(); ++it) { TFrameId fid = *it; std::string id = sl->getImageId(fid); } } } } if (!paletteHandle || !paletteHandle->getPalette()) return; if (somethingChanged) paletteHandle->notifyColorStyleChanged(); }
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; }
QTreeWidgetItem *StudioPaletteTreeViewer::createItem(const TFilePath path) { StudioPalette *studioPalette = StudioPalette::instance(); QString itemName = toQString(TFilePath(path.getWideName())); QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget *)0, QStringList(itemName)); if (studioPalette->isPalette(path)) { if (studioPalette->hasGlobalName(path)) item->setIcon(0, m_studioPaletteIcon); else item->setIcon(0, m_levelPaletteIcon); } else if (studioPalette->isFolder(path)) item->setIcon(0, m_folderIcon); item->setData(1, Qt::UserRole, toQString(path)); item->setFlags(item->flags() | Qt::ItemIsEditable); return item; }
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]); }
/*! Convert level palette to studio palette. */ void StudioPaletteTreeViewer::convertToStudioPalette() { TFilePath path = getItemPath(currentItem()); StudioPalette *studioPalette = StudioPalette::instance(); if (studioPalette->isPalette(path)) { TPalette *palette = studioPalette->getPalette(path); if (!palette) { error("Can't touch palette"); return; } if (m_currentPalette->getPaletteName() != palette->getPaletteName()) { error("Can't touch palette"); return; } QString question; question = QString::fromStdWString( L"Convert " + path.getWideString() + L" to Studio Palette and Overwrite. \nAre you sure ?"); int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No")); if (ret == 0 || ret == 2) return; // apply global name time_t ltime; time(<ime); wstring gname = std::to_wstring(ltime) + L"_" + std::to_wstring(rand()); m_currentPalette->setGlobalName(gname); studioPalette->setStylesGlobalNames(m_currentPalette.getPointer()); studioPalette->save(path, m_currentPalette.getPointer()); m_currentPalette->setDirtyFlag(false); currentItem()->setIcon(0, m_studioPaletteIcon); } else error("Can't find palette"); }
void StudioPaletteTreeViewer::deleteItem(QTreeWidgetItem *item) { QTreeWidgetItem *parent = item->parent(); if (!parent) return; if (item->childCount() > 0) { QString question; question = tr("This folder is not empty. Delete anyway?"); int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No")); if (ret == 0 || ret == 2) return; } TFilePath path = getItemPath(item); StudioPalette *studioPalette = StudioPalette::instance(); if (studioPalette->isFolder(path)) { try { StudioPaletteCmd::deleteFolder(path); } catch (TException &e) { error("Can't delete folder: " + QString(::to_string(e.getMessage()).c_str())); } catch (...) { error("Can't delete folder"); } } else { assert(studioPalette->isPalette(path)); try { StudioPaletteCmd::deletePalette(path); } catch (TException &e) { error("Can't delete palette: " + QString(::to_string(e.getMessage()).c_str())); } catch (...) { error("Can't delete palette"); } } refreshItem(parent); }
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); }
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()); }