Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/styleselection.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/selectioncommandids.h"
Toshihiro Shimizu 890ddd
#include "styledata.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/studiopalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/palettecmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/cleanupcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "../toonz/menubarcommandids.h"
Toshihiro Shimizu 890ddd
#include "historytypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
#include <qclipboard></qclipboard>
Toshihiro Shimizu 890ddd
#include <qbytearray></qbytearray>
Toshihiro Shimizu 890ddd
#include <qbuffer></qbuffer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Campbell Barton 0b592f
enum StyleType {
Toshihiro Shimizu 890ddd
	NORMALSTYLE,
Toshihiro Shimizu 890ddd
	STUDIOSTYLE,
Toshihiro Shimizu 890ddd
	LINKEDSTYLE
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void copyStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, int pageIndex,
Toshihiro Shimizu 890ddd
						   std::set<int> *styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!palette || pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int n = styleIndicesInPage->size();
Toshihiro Shimizu 890ddd
	if (n == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
	StyleData *data = new StyleData();
Toshihiro Shimizu 890ddd
	std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
	for (it = styleIndicesInPage->begin(); it != styleIndicesInPage->end(); ++it) {
Toshihiro Shimizu 890ddd
		int indexInPage = *it;
Toshihiro Shimizu 890ddd
		int styleId = page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
		TColorStyle *style = page->getStyle(indexInPage);
Toshihiro Shimizu 890ddd
		if (!style)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		TColorStyle *newStyle = style->clone();
Toshihiro Shimizu 890ddd
		data->addStyle(styleId, newStyle);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QApplication::clipboard()->setMimeData(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Paste styles contained in \b data in the end of current palette page.
Toshihiro Shimizu 890ddd
		Add to styleIndicesInPage pasted styles index.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
bool pasteStylesDataWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, const StyleData *data, int indexInPage,
Toshihiro Shimizu 890ddd
								int pageIndex, std::set<int> *styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		palette = pltHandle->getPalette();
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	// page = pagina corrente
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(pageIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!data)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// comincio a fare paste
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	int styleId = 0;
Toshihiro Shimizu 890ddd
	for (i = 0; i < data->getStyleCount(); i++) {
Toshihiro Shimizu 890ddd
		styleId = data->getStyleIndex(i);
Toshihiro Shimizu 890ddd
		TColorStyle *style = data->getStyle(i)->clone();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Se la palette e' di cleanup gli stili devono essere 8.
Toshihiro Shimizu 890ddd
		if (palette->isCleanupPalette() && palette->getStyleInPagesCount() >= 8) {
Toshihiro Shimizu 890ddd
			delete style;
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (palette->getStylePage(styleId) < 0) {
Toshihiro Shimizu 890ddd
			// styleId non e' utilizzato: uso quello
Toshihiro Shimizu 890ddd
			// (cut/paste utilizzato per spostare stili)
Toshihiro Shimizu 890ddd
			palette->setStyle(styleId, style);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			// styleId e' gia' utilizzato. ne devo prendere un altro
Toshihiro Shimizu 890ddd
			styleId = palette->getFirstUnpagedStyle();
Toshihiro Shimizu 890ddd
			if (styleId >= 0)
Toshihiro Shimizu 890ddd
				palette->setStyle(styleId, style);
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				styleId = palette->addStyle(style);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//check the type of the original(copied) style
Toshihiro Shimizu 890ddd
		// If the original is NormalStyle
Toshihiro Shimizu 890ddd
		if (style->getGlobalName() == L"") {
Toshihiro Shimizu 890ddd
			// 1. If pasting normal style to level palette, do nothing
Toshihiro Shimizu 890ddd
			if (palette->getGlobalName() == L"") {
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			// 2. If pasting normal style to studio palette, add a new link and make it linkable
Toshihiro Shimizu 890ddd
			else {
Shinya Kitaoka 3bfa54
				std::wstring gname = L"-" + palette->getGlobalName() + L"-" + toWideString(styleId);
Toshihiro Shimizu 890ddd
				style->setGlobalName(gname);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		// If the original is StudioPaletteStyle
Toshihiro Shimizu 890ddd
		else if (style->getOriginalName() == L"") {
Toshihiro Shimizu 890ddd
			// 3. If pasting StudioPaletteStyle to level palette, set the style name into the original name.
Toshihiro Shimizu 890ddd
			// 4. If pasting StudioPaletteStyle to studio palette, set the style name into the original name and keep the link.
Toshihiro Shimizu 890ddd
			style->setOriginalName(style->getName());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		// If the original is linked style, do nothing
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// move in the page
Toshihiro Shimizu 890ddd
		// inserisco lo stile nella pagina
Toshihiro Shimizu 890ddd
		int index = indexInPage + i;
Toshihiro Shimizu 890ddd
		page->insertStyle(index, styleId);
Toshihiro Shimizu 890ddd
		// e lo seleziono
Toshihiro Shimizu 890ddd
		if (styleIndicesInPage)
Toshihiro Shimizu 890ddd
			styleIndicesInPage->insert(index);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (palette == pltHandle->getPalette())
Toshihiro Shimizu 890ddd
		pltHandle->setStyleIndex(styleId);
Toshihiro Shimizu 890ddd
	pltHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	pltHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Paste styles contained in application data after current style. Clear styleIndicesInPage
Toshihiro Shimizu 890ddd
		and add to it pasted styles. If currentStyleIndex == -1 take paletteHandle current style.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
bool pasteStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, int pageIndex,
Toshihiro Shimizu 890ddd
							std::set<int> *styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		palette = pltHandle->getPalette();
Toshihiro Shimizu 890ddd
	// page = pagina corrente
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
	// cerco il punto di inserimento (dopo lo stile corrente)
Toshihiro Shimizu 890ddd
	int currentStyleIndex = pltHandle->getStyleIndex();
Toshihiro Shimizu 890ddd
	int indexInPage = page->search(currentStyleIndex) + 1;
Toshihiro Shimizu 890ddd
	const StyleData *data = dynamic_cast<const *="" styledata="">(QApplication::clipboard()->mimeData());</const>
Toshihiro Shimizu 890ddd
	if (!data)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// cancello la selezione
Toshihiro Shimizu 890ddd
	if (styleIndicesInPage)
Toshihiro Shimizu 890ddd
		styleIndicesInPage->clear();
Toshihiro Shimizu 890ddd
	return pasteStylesDataWithoutUndo(palette, pltHandle, data, indexInPage, pageIndex, styleIndicesInPage);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void deleteStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, int pageIndex,
Toshihiro Shimizu 890ddd
							 std::set<int> *styleIndicesInPage, int fir = 0)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		palette = pltHandle->getPalette();
Toshihiro Shimizu 890ddd
	int n = styleIndicesInPage->size();
Toshihiro Shimizu 890ddd
	if (n == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
	int currentStyleIndexInPage = page->search(pltHandle->getStyleIndex());
Toshihiro Shimizu 890ddd
	bool mustChangeCurrentStyle =
Toshihiro Shimizu 890ddd
		currentStyleIndexInPage >= 0 && styleIndicesInPage->count(currentStyleIndexInPage) > 0;
Toshihiro Shimizu 890ddd
	std::set<int>::reverse_iterator it;</int>
Toshihiro Shimizu 890ddd
	for (it = styleIndicesInPage->rbegin(); it != styleIndicesInPage->rend(); ++it) {
Toshihiro Shimizu 890ddd
		int j = *it;
Toshihiro Shimizu 890ddd
		int styleId = page->getStyleId(j);
Toshihiro Shimizu 890ddd
		if (styleId < 2) {
Toshihiro Shimizu 890ddd
			error(QObject::tr("It is not possible to delete the style #") + QString::number(styleId));
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			if (styleId == pltHandle->getStyleIndex())
Toshihiro Shimizu 890ddd
				pltHandle->setStyleIndex(1);
Toshihiro Shimizu 890ddd
			palette->setStyle(styleId, TPixel32::Red);
Toshihiro Shimizu 890ddd
			page->removeStyle(j);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	styleIndicesInPage->clear();
Toshihiro Shimizu 890ddd
	if (mustChangeCurrentStyle) {
Toshihiro Shimizu 890ddd
		// ho cancellato lo stile corrente
Toshihiro Shimizu 890ddd
		if (currentStyleIndexInPage < page->getStyleCount()) {
Toshihiro Shimizu 890ddd
			// posso fare in modo che lo stile selezionato sia nella stessa posizione
Toshihiro Shimizu 890ddd
			pltHandle->setStyleIndex(page->getStyleId(currentStyleIndexInPage));
Toshihiro Shimizu 890ddd
		} else if (page->getStyleCount() > 0) {
Toshihiro Shimizu 890ddd
			// almeno faccio in modo che sia nella stessa pagina
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(page->getStyleCount() - 1);
Toshihiro Shimizu 890ddd
			pltHandle->setStyleIndex(styleId);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			// seleziono lo stile #1 (che c'e' sempre). n.b. questo puo' comportare un cambio pagina
Toshihiro Shimizu 890ddd
			pltHandle->setStyleIndex(1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	//This function is used in undo and redo. So do not activate dirtyflag.
Toshihiro Shimizu 890ddd
	pltHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
	pltHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void cutStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, int pageIndex,
Toshihiro Shimizu 890ddd
						  std::set<int> *styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	copyStylesWithoutUndo(palette, pltHandle, pageIndex, styleIndicesInPage);
Toshihiro Shimizu 890ddd
	deleteStylesWithoutUndo(palette, pltHandle, pageIndex, styleIndicesInPage);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void insertStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle, int pageIndex,
Toshihiro Shimizu 890ddd
							 std::set<int> *styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		palette = pltHandle->getPalette();
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(pageIndex);
Toshihiro Shimizu 890ddd
	if (!page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const StyleData *data = dynamic_cast<const *="" styledata="">(QApplication::clipboard()->mimeData());</const>
Toshihiro Shimizu 890ddd
	if (!data)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int styleId = 0;
Toshihiro Shimizu 890ddd
	// comincio a fare paste
Toshihiro Shimizu 890ddd
	std::set<int>::iterator it = styleIndicesInPage->begin();</int>
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < data->getStyleCount(); i++, it++) {
Toshihiro Shimizu 890ddd
		styleId = data->getStyleIndex(i);
Toshihiro Shimizu 890ddd
		TColorStyle *style = data->getStyle(i)->clone();
Toshihiro Shimizu 890ddd
		palette->setStyle(styleId, style);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// inserisco lo stile nella pagina
Toshihiro Shimizu 890ddd
		int index = *it;
Toshihiro Shimizu 890ddd
		page->insertStyle(index, styleId);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (palette == pltHandle->getPalette())
Toshihiro Shimizu 890ddd
		pltHandle->setStyleIndex(styleId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	pltHandle->notifyColorStyleChanged(false);
Toshihiro Shimizu 890ddd
	pltHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// PasteStylesUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class PasteStylesUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStyleSelection *m_selection;
Toshihiro Shimizu 890ddd
	int m_oldStyleIndex;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	std::set<int> m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
	QMimeData *m_data;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PasteStylesUndo(TStyleSelection *selection, int oldStyleIndex, QMimeData *data)
Toshihiro Shimizu 890ddd
		: m_selection(selection), m_oldStyleIndex(oldStyleIndex), m_data(data)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_pageIndex = m_selection->getPageIndex();
Toshihiro Shimizu 890ddd
		m_styleIndicesInPage = m_selection->getIndicesInPage();
Toshihiro Shimizu 890ddd
		m_palette = m_selection->getPaletteHandle()->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~PasteStylesUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		delete m_data;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		cutStylesWithoutUndo(m_palette.getPointer(), paletteHandle, m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_selection->selectNone();
Toshihiro Shimizu 890ddd
		m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Setto l'indice corrente.
Toshihiro Shimizu 890ddd
		if (m_palette.getPointer() == paletteHandle->getPalette())
Toshihiro Shimizu 890ddd
			paletteHandle->setStyleIndex(m_oldStyleIndex);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		//Se e' la paletta corrente setto l'indice corrente.
Toshihiro Shimizu 890ddd
		TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
Toshihiro Shimizu 890ddd
		if (m_palette.getPointer() == paletteHandle->getPalette())
Toshihiro Shimizu 890ddd
			paletteHandle->setStyleIndex(m_oldStyleIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		assert(page);
Toshihiro Shimizu 890ddd
		int indexInPage = page->search(m_oldStyleIndex) + 1;
Toshihiro Shimizu 890ddd
		const StyleData *data = dynamic_cast<const *="" styledata="">(m_data);</const>
Toshihiro Shimizu 890ddd
		assert(data);
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		pasteStylesDataWithoutUndo(m_palette.getPointer(), paletteHandle, data, indexInPage, m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Se e' la paletta corrente aggiorno la selezione
Toshihiro Shimizu 890ddd
		if (m_selection && m_palette.getPointer() == paletteHandle->getPalette()) {
Toshihiro Shimizu 890ddd
			m_selection->selectNone();
Toshihiro Shimizu 890ddd
			m_selection->select(m_pageIndex);
Toshihiro Shimizu 890ddd
			std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
			for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end(); ++it)
Toshihiro Shimizu 890ddd
				m_selection->select(m_pageIndex, *it, true);
Toshihiro Shimizu 890ddd
			m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Paste Style  in Palette : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DeleteStylesUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DeleteStylesUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStyleSelection *m_selection;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	std::set<int> m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
	QMimeData *m_data;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DeleteStylesUndo(TStyleSelection *selection, QMimeData *data)
Toshihiro Shimizu 890ddd
		: m_selection(selection), m_data(data)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_pageIndex = m_selection->getPageIndex();
Toshihiro Shimizu 890ddd
		m_styleIndicesInPage = m_selection->getIndicesInPage();
Toshihiro Shimizu 890ddd
		m_palette = m_selection->getPaletteHandle()->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setStyleIndicesInPage(const std::set<int> &styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_styleIndicesInPage = styleIndicesInPage;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setPageIndex(int pageIndex)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_pageIndex = pageIndex;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~DeleteStylesUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		delete m_data;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
Toshihiro Shimizu 890ddd
		//Prendo il data corrente
Toshihiro Shimizu 890ddd
		QClipboard *clipboard = QApplication::clipboard();
Toshihiro Shimizu 890ddd
		QMimeData *currentData = cloneData(clipboard->mimeData());
Toshihiro Shimizu 890ddd
		//Setto il vecchio data
Toshihiro Shimizu 890ddd
		clipboard->setMimeData(cloneData(m_data), QClipboard::Clipboard);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		insertStylesWithoutUndo(m_palette.getPointer(), paletteHandle, m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_selection && m_palette.getPointer() == paletteHandle->getPalette()) {
Toshihiro Shimizu 890ddd
			m_selection->selectNone();
Toshihiro Shimizu 890ddd
			m_selection->select(m_pageIndex);
Toshihiro Shimizu 890ddd
			std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
			for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end(); ++it)
Toshihiro Shimizu 890ddd
				m_selection->select(m_pageIndex, *it, true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//Rimetto il data corrente.
Toshihiro Shimizu 890ddd
		clipboard->setMimeData(currentData, QClipboard::Clipboard);
Toshihiro Shimizu 890ddd
		//do not activate dirty flag here in case that the m_palette is not current when undo
Toshihiro Shimizu 890ddd
		paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		deleteStylesWithoutUndo(m_palette.getPointer(), m_selection->getPaletteHandle(), m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
		if (m_selection) {
Toshihiro Shimizu 890ddd
			m_selection->selectNone();
Toshihiro Shimizu 890ddd
			m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Delete Style  from Palette : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// CutStylesUndo
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CutStylesUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStyleSelection *m_selection;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	std::set<int> m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
	QMimeData *m_oldData; //!< data before cut
Toshihiro Shimizu 890ddd
	QMimeData *m_data;	//!< data containing cut styles
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CutStylesUndo(TStyleSelection *selection, QMimeData *data, QMimeData *oldData)
Toshihiro Shimizu 890ddd
		: m_selection(selection), m_oldData(oldData), m_data(data)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_pageIndex = m_selection->getPageIndex();
Toshihiro Shimizu 890ddd
		m_styleIndicesInPage = m_selection->getIndicesInPage();
Toshihiro Shimizu 890ddd
		m_palette = m_selection->getPaletteHandle()->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~CutStylesUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		delete m_oldData;
Toshihiro Shimizu 890ddd
		delete m_data;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Setto il data del cut
Toshihiro Shimizu 890ddd
		QClipboard *clipboard = QApplication::clipboard();
Toshihiro Shimizu 890ddd
		clipboard->setMimeData(cloneData(m_data), QClipboard::Clipboard);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		insertStylesWithoutUndo(m_palette.getPointer(), paletteHandle, m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_selection && m_palette.getPointer() == paletteHandle->getPalette()) {
Toshihiro Shimizu 890ddd
			m_selection->selectNone();
Toshihiro Shimizu 890ddd
			m_selection->select(m_pageIndex);
Toshihiro Shimizu 890ddd
			std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
			for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end(); ++it)
Toshihiro Shimizu 890ddd
				m_selection->select(m_pageIndex, *it, true);
Toshihiro Shimizu 890ddd
			m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Setto il che c'era prima del cut
Toshihiro Shimizu 890ddd
		clipboard->setMimeData(cloneData(m_oldData), QClipboard::Clipboard);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		cutStylesWithoutUndo(m_palette.getPointer(), m_selection->getPaletteHandle(), m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_selection->selectNone();
Toshihiro Shimizu 890ddd
		m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const { return sizeof(*this); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Cut Style  from Palette : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TStyleSelection
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStyleSelection::TStyleSelection()
Toshihiro Shimizu 890ddd
	: m_paletteHandle(0), m_xsheetHandle(0), m_pageIndex(-1), m_levelHandle(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStyleSelection::~TStyleSelection()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::enableCommands()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_paletteHandle && m_paletteHandle->getPalette() && !m_paletteHandle->getPalette()->isCleanupPalette()) {
Toshihiro Shimizu 890ddd
		enableCommand(this, MI_Cut, &TStyleSelection::cutStyles);
Toshihiro Shimizu 890ddd
		enableCommand(this, MI_Copy, &TStyleSelection::copyStyles);
Toshihiro Shimizu 890ddd
		enableCommand(this, MI_Paste, &TStyleSelection::pasteStyles);
Toshihiro Shimizu 890ddd
		enableCommand(this, MI_PasteValues, &TStyleSelection::pasteStylesValue);
Toshihiro Shimizu 890ddd
		enableCommand(this, MI_PasteColors, &TStyleSelection::pasteStylesColor);
Toshihiro Shimizu 890ddd
		enableCommand(this, MI_PasteNames, &TStyleSelection::pasteStylesName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//available only for level palette
Toshihiro Shimizu 890ddd
		if (m_paletteHandle->getPalette()->getGlobalName() == L"")
Toshihiro Shimizu 890ddd
			enableCommand(this, MI_GetColorFromStudioPalette, &TStyleSelection::getBackOriginalStyle);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	enableCommand(this, MI_Clear, &TStyleSelection::deleteStyles);
Toshihiro Shimizu 890ddd
	enableCommand(this, MI_EraseUnusedStyles, &TStyleSelection::eraseUnsedStyle);
Toshihiro Shimizu 890ddd
	enableCommand(this, MI_BlendColors, &TStyleSelection::blendStyles);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::select(int pageIndex)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_pageIndex = pageIndex;
Toshihiro Shimizu 890ddd
	m_styleIndicesInPage.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::select(int pageIndex, int styleIndexInPage, bool on)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (on) {
Toshihiro Shimizu 890ddd
		if (pageIndex != m_pageIndex)
Toshihiro Shimizu 890ddd
			m_styleIndicesInPage.clear();
Toshihiro Shimizu 890ddd
		m_pageIndex = pageIndex;
Toshihiro Shimizu 890ddd
		m_styleIndicesInPage.insert(styleIndexInPage);
Toshihiro Shimizu 890ddd
	} else if (pageIndex == m_pageIndex)
Toshihiro Shimizu 890ddd
		m_styleIndicesInPage.erase(styleIndexInPage);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TStyleSelection::isSelected(int pageIndex, int id) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_pageIndex == pageIndex &&
Toshihiro Shimizu 890ddd
		   m_styleIndicesInPage.find(id) != m_styleIndicesInPage.end();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TStyleSelection::isPageSelected(int pageIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_pageIndex == pageIndex;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TStyleSelection::canHandleStyles()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	if (!page)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	if ((isSelected(m_pageIndex, 0) && page->getStyleId(0) == 0) ||
Toshihiro Shimizu 890ddd
		(isSelected(m_pageIndex, 1) && page->getStyleId(1) == 1))
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::selectNone()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_pageIndex = -1;
Toshihiro Shimizu 890ddd
	m_styleIndicesInPage.clear();
Toshihiro Shimizu 890ddd
	notifyView();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TStyleSelection::isEmpty() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_pageIndex < 0 && m_styleIndicesInPage.empty();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TStyleSelection::getStyleCount() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::cutStyles()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	QClipboard *clipboard = QApplication::clipboard();
Toshihiro Shimizu 890ddd
	QMimeData *oldData = cloneData(clipboard->mimeData());
Toshihiro Shimizu 890ddd
	if (!canHandleStyles()) {
Toshihiro Shimizu 890ddd
		error(QObject::tr("It is not possible to delete styles #0 and #1."));
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TPalette *palette = m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (palette->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	StyleData *data = new StyleData();
Toshihiro Shimizu 890ddd
	std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	std::vector<int> styleIds;</int>
Toshihiro Shimizu 890ddd
	for (it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
		int j = *it;
Toshihiro Shimizu 890ddd
		int styleId = page->getStyleId(j);
Toshihiro Shimizu 890ddd
		if (styleId < 0)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		TColorStyle *style = page->getStyle(j)->clone();
Toshihiro Shimizu 890ddd
		data->addStyle(styleId, style);
Toshihiro Shimizu 890ddd
		styleIds.push_back(page->getStyleId(*it));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::auto_ptr<tundo> undo(new CutStylesUndo(this, data, oldData));</tundo>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_xsheetHandle) {
Toshihiro Shimizu 890ddd
		if (eraseStylesInDemand(palette, styleIds, m_xsheetHandle) == 0)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	cutStylesWithoutUndo(palette, m_paletteHandle, m_pageIndex, &m_styleIndicesInPage);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo.release());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::copyStyles()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	copyStylesWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle, m_pageIndex, &m_styleIndicesInPage);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::pasteStyles()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	// se non c'e' palette o pagina corrente esco
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (palette->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	if (!page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (isSelected(m_pageIndex, 0) && page->getStyleId(0) == 0) {
Toshihiro Shimizu 890ddd
		error(QObject::tr("Can't paste styles there"));
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int oldStyleIndex = m_paletteHandle->getStyleIndex();
Toshihiro Shimizu 890ddd
	QClipboard *clipboard = QApplication::clipboard();
Toshihiro Shimizu 890ddd
	QMimeData *oldData = cloneData(clipboard->mimeData());
Toshihiro Shimizu 890ddd
	pasteStylesWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle, m_pageIndex, &m_styleIndicesInPage);
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(new PasteStylesUndo(this, oldStyleIndex, oldData));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::deleteStyles()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (palette->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (!canHandleStyles()) {
Toshihiro Shimizu 890ddd
		error(QObject::tr("It is not possible to delete styles #0 and #1."));
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (getStyleCount() == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	StyleData *data = new StyleData();
Toshihiro Shimizu 890ddd
	std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	std::vector<int> styleIds;</int>
Toshihiro Shimizu 890ddd
	for (it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
		int j = *it;
Toshihiro Shimizu 890ddd
		int styleId = page->getStyleId(j);
Toshihiro Shimizu 890ddd
		if (styleId < 0)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		TColorStyle *style = page->getStyle(j)->clone();
Toshihiro Shimizu 890ddd
		data->addStyle(styleId, style);
Toshihiro Shimizu 890ddd
		styleIds.push_back(page->getStyleId(*it));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoScopedBlock undoBlock;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_xsheetHandle) {
Toshihiro Shimizu 890ddd
		if (eraseStylesInDemand(palette, styleIds, m_xsheetHandle) == 0) // Could add an undo
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::auto_ptr<tundo> undo(new DeleteStylesUndo(this, data));</tundo>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	deleteStylesWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle, m_pageIndex, &m_styleIndicesInPage);
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo.release());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::eraseUnsedStyle()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::set<txshsimplelevel *=""> levels;</txshsimplelevel>
Toshihiro Shimizu 890ddd
	int row, column, i, j;
Toshihiro Shimizu 890ddd
	TPalette *palette = m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	findPaletteLevels(levels, row, column, palette, m_xsheetHandle->getXsheet());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Verifico quali stili sono usati e quali no
Toshihiro Shimizu 890ddd
	std::map<int, bool=""> usedStyleIds;</int,>
Toshihiro Shimizu 890ddd
	int pageCount = palette->getPageCount();
Toshihiro Shimizu 890ddd
	std::set<txshsimplelevel *="">::const_iterator it = levels.begin();</txshsimplelevel>
Toshihiro Shimizu 890ddd
	for (it; it != levels.end(); it++) {
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *level = *it;
Shinya Kitaoka 3bfa54
		std::vector<tframeid> fids;</tframeid>
Toshihiro Shimizu 890ddd
		level->getFids(fids);
Toshihiro Shimizu 890ddd
		int m, i, j;
Toshihiro Shimizu 890ddd
		for (m = 0; m < (int)fids.size(); m++) {
Toshihiro Shimizu 890ddd
			TImageP image = level->getFrame(fids[m], false);
Toshihiro Shimizu 890ddd
			if (!image)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			for (i = 0; i < pageCount; i++) {
Toshihiro Shimizu 890ddd
				TPalette::Page *page = palette->getPage(i);
Toshihiro Shimizu 890ddd
				assert(page);
Toshihiro Shimizu 890ddd
				for (j = 0; j < page->getStyleCount(); j++) {
Toshihiro Shimizu 890ddd
					int styleId = page->getStyleId(j);
Toshihiro Shimizu 890ddd
					if (m != 0 && usedStyleIds[styleId])
Toshihiro Shimizu 890ddd
						continue;
Toshihiro Shimizu 890ddd
					if (i == 0 && j == 0) //Il primo stile della prima pagina non deve essere mai cancellato
Toshihiro Shimizu 890ddd
					{
Toshihiro Shimizu 890ddd
						usedStyleIds[styleId] = true;
Toshihiro Shimizu 890ddd
						continue;
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
					usedStyleIds[styleId] = isStyleUsed(image, styleId);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Butto gli stili non usati
Toshihiro Shimizu 890ddd
	for (i = 0; i < pageCount; i++) {
Toshihiro Shimizu 890ddd
		//Variabili usate per l'undo
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		StyleData *data = new StyleData();
Toshihiro Shimizu 890ddd
		TPalette::Page *page = palette->getPage(i);
Toshihiro Shimizu 890ddd
		assert(page);
Toshihiro Shimizu 890ddd
		for (j = 0; j < page->getStyleCount(); j++) {
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(j);
Toshihiro Shimizu 890ddd
			if (usedStyleIds[styleId])
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			styleIndicesInPage.insert(j);
Toshihiro Shimizu 890ddd
			data->addStyle(styleId, page->getStyle(j)->clone());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//Se styleIndicesInPage e' vuoto ci sono stili da cancellare.
Toshihiro Shimizu 890ddd
		if (styleIndicesInPage.empty()) {
Toshihiro Shimizu 890ddd
			delete data;
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//Cancello gli stili
Toshihiro Shimizu 890ddd
		std::set<int>::reverse_iterator it;</int>
Toshihiro Shimizu 890ddd
		for (it = styleIndicesInPage.rbegin(); it != styleIndicesInPage.rend(); ++it)
Toshihiro Shimizu 890ddd
			page->removeStyle(*it);
Toshihiro Shimizu 890ddd
		//Undo
Toshihiro Shimizu 890ddd
		DeleteStylesUndo *undo = new DeleteStylesUndo(this, data);
Toshihiro Shimizu 890ddd
		undo->setPageIndex(i);
Toshihiro Shimizu 890ddd
		undo->setStyleIndicesInPage(styleIndicesInPage);
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
	m_paletteHandle->setStyleIndex(1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// UndoPasteValues
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class UndoPasteValues : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStyleSelection *m_selection;
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_pasteName;
Toshihiro Shimizu 890ddd
	bool m_pasteColor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	class Item
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		int m_index;
Toshihiro Shimizu 890ddd
		TColorStyle *m_oldStyle;
Toshihiro Shimizu 890ddd
		TColorStyle *m_newStyle;
Toshihiro Shimizu 890ddd
		Item(int index, const TColorStyle *oldStyle, const TColorStyle *newStyle)
Toshihiro Shimizu 890ddd
			: m_index(index), m_oldStyle(oldStyle->clone()), m_newStyle(newStyle->clone())
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		Item(int index, const TColorStyle *newStyle)
Toshihiro Shimizu 890ddd
			: m_index(index), m_oldStyle(0), m_newStyle(newStyle->clone())
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		~Item()
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			delete m_oldStyle;
Toshihiro Shimizu 890ddd
			delete m_newStyle;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<item *=""> m_items;</item>
Toshihiro Shimizu 890ddd
	std::vector<item *=""> m_itemsInserted;</item>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *getPalette() const { return m_palette.getPointer(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	UndoPasteValues(TStyleSelection *selection, bool pasteName, bool pasteColor = true)
Toshihiro Shimizu 890ddd
		: m_selection(selection), m_pasteName(pasteName), m_pasteColor(pasteColor)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_pageIndex = m_selection->getPageIndex();
Toshihiro Shimizu 890ddd
		m_paletteHandle = m_selection->getPaletteHandle();
Toshihiro Shimizu 890ddd
		m_palette = m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~UndoPasteValues()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		clearPointerContainer(m_items);
Toshihiro Shimizu 890ddd
		clearPointerContainer(m_itemsInserted);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addItem(int index, const TColorStyle *oldStyle, const TColorStyle *newStyle)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_items.push_back(new Item(index, oldStyle, newStyle));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addItemToInsert(const std::set<int> styleIndicesInPage)</int>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPalette::Page *page = getPalette()->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		std::set<int>::const_iterator it;</int>
Toshihiro Shimizu 890ddd
		for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end(); it++)
Toshihiro Shimizu 890ddd
			m_itemsInserted.push_back(new Item(*it, page->getStyle(*it)));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void pasteValue(int styleId, const TColorStyle *newStyle) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		// preserva il vecchio nome se m_pasteOnlyColor e' falso
Shinya Kitaoka 3bfa54
		std::wstring str = newStyle->getName();
Toshihiro Shimizu 890ddd
		if (m_pasteColor) {
Toshihiro Shimizu 890ddd
			getPalette()->setStyle(styleId, newStyle->clone());
Toshihiro Shimizu 890ddd
			if (!m_pasteName)
Toshihiro Shimizu 890ddd
				getPalette()->getStyle(styleId)->setName(str);
Toshihiro Shimizu 890ddd
		} else if (m_pasteName)
Toshihiro Shimizu 890ddd
			getPalette()->getStyle(styleId)->setName(newStyle->getName());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_selection->selectNone();
Toshihiro Shimizu 890ddd
		TPalette::Page *page = getPalette()->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_items.size(); i++) {
Toshihiro Shimizu 890ddd
			int indexInPage = m_items[i]->m_index;
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
			pasteValue(styleId, m_items[i]->m_oldStyle);
Toshihiro Shimizu 890ddd
			m_selection->select(m_pageIndex, indexInPage, true);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Se avevo aggiunto degli stili devo rimuoverli.
Toshihiro Shimizu 890ddd
		int j;
Toshihiro Shimizu 890ddd
		for (j = (int)m_itemsInserted.size() - 1; j >= 0; j--) {
Toshihiro Shimizu 890ddd
			int indexInPage = m_itemsInserted[j]->m_index;
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
			if (getPalette() == m_paletteHandle->getPalette() && styleId == m_paletteHandle->getStyleIndex())
Toshihiro Shimizu 890ddd
				m_paletteHandle->setStyleIndex(page->getStyleId(indexInPage - 1));
Toshihiro Shimizu 890ddd
			getPalette()->setStyle(styleId, TPixel32::Red);
Toshihiro Shimizu 890ddd
			page->removeStyle(indexInPage);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
		//do not activate a dirty flag here in case that m_palette is not currentpalette
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_selection->selectNone();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPalette::Page *page = getPalette()->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		int indexInPage = 0;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_items.size(); i++) {
Shinya Kitaoka 3bfa54
			std::wstring oldName = m_items[i]->m_oldStyle->getName();
Toshihiro Shimizu 890ddd
			TColorStyle *style = m_items[i]->m_newStyle;
Toshihiro Shimizu 890ddd
			indexInPage = m_items[i]->m_index;
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//first, check out the types of copied and pasted styles
Toshihiro Shimizu 890ddd
			StyleType srcType, dstType;
Toshihiro Shimizu 890ddd
			//copied (source)
Toshihiro Shimizu 890ddd
			if (style->getGlobalName() == L"")
Toshihiro Shimizu 890ddd
				srcType = NORMALSTYLE;
Toshihiro Shimizu 890ddd
			else if (style->getOriginalName() == L"")
Toshihiro Shimizu 890ddd
				srcType = STUDIOSTYLE;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				srcType = LINKEDSTYLE;
Toshihiro Shimizu 890ddd
			//pasted (destination)
Toshihiro Shimizu 890ddd
			TColorStyle *dstStyle = m_items[i]->m_oldStyle;
Toshihiro Shimizu 890ddd
			std::wstring dstGlobalName = dstStyle->getGlobalName();
Toshihiro Shimizu 890ddd
			std::wstring dstOriginalName = dstStyle->getOriginalName();
Toshihiro Shimizu 890ddd
			if (dstGlobalName == L"")
Toshihiro Shimizu 890ddd
				dstType = NORMALSTYLE;
Toshihiro Shimizu 890ddd
			else if (dstOriginalName == L"")
Toshihiro Shimizu 890ddd
				dstType = STUDIOSTYLE;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				dstType = LINKEDSTYLE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			pasteValue(styleId, style);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//Process the global and original names according to the pasted style
Toshihiro Shimizu 890ddd
			TColorStyle *pastedStyle = getPalette()->getStyle(styleId);
Toshihiro Shimizu 890ddd
			if (srcType == NORMALSTYLE) {
Toshihiro Shimizu 890ddd
				if (dstType == NORMALSTYLE) {
Toshihiro Shimizu 890ddd
				}								 //1. From normal to normal. Do nothing.
Toshihiro Shimizu 890ddd
				else if (dstType == STUDIOSTYLE) //2. From normal to studio. Restore the global name
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
				else //dstType == LINKEDSTYLE		//3. From normal to linked. Restore both the global and the original name. Activate the edited flag.
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(dstOriginalName);
Toshihiro Shimizu 890ddd
					pastedStyle->setIsEditedFlag(true);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else if (srcType == STUDIOSTYLE) {
Toshihiro Shimizu 890ddd
				if (dstType == NORMALSTYLE) //4. From studio to normal. Set the studio style's name to the original name.
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(style->getName());
Toshihiro Shimizu 890ddd
				else if (dstType == STUDIOSTYLE) //5. From studio to studio. Restore the global name.
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
				else //dstStyle == LINKEDSTYLE		//6. From studio to linked. Set the studio style's name to the original name, and set the edited flag to off.
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(style->getName());
Toshihiro Shimizu 890ddd
					pastedStyle->setIsEditedFlag(false);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else //srcType == LINKEDSTYLE
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				if (dstType == NORMALSTYLE) {
Toshihiro Shimizu 890ddd
				}								 //7. From linked to normal. Do nothing.
Toshihiro Shimizu 890ddd
				else if (dstType == STUDIOSTYLE) //8. From linked to studio. Restore the global name. Delete the original name. Set the edited flag to off.
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(L"");
Toshihiro Shimizu 890ddd
					pastedStyle->setIsEditedFlag(false);
Toshihiro Shimizu 890ddd
				} else //dstStyle == LINKEDSTYLE		//9. From linked to linked. Do nothing (bring all information from the original).
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (!m_pasteName) // devo settare al nuovo stile il vecchio nome
Toshihiro Shimizu 890ddd
				getPalette()->getStyle(styleId)->setName(oldName);
Toshihiro Shimizu 890ddd
			m_selection->select(m_pageIndex, indexInPage, true);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_itemsInserted.size() != 0) {
Toshihiro Shimizu 890ddd
			StyleData *newData = new StyleData();
Toshihiro Shimizu 890ddd
			int j;
Toshihiro Shimizu 890ddd
			for (j = 0; j < (int)m_itemsInserted.size(); j++)
Toshihiro Shimizu 890ddd
				newData->addStyle(m_itemsInserted[j]->m_index, m_itemsInserted[j]->m_newStyle->clone());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			std::set<int> styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
			pasteStylesDataWithoutUndo(getPalette(), m_paletteHandle, newData, indexInPage + 1, m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			std::set<int>::iterator styleIt;</int>
Toshihiro Shimizu 890ddd
			for (styleIt = styleIndicesInPage.begin(); styleIt != styleIndicesInPage.end(); ++styleIt)
Toshihiro Shimizu 890ddd
				m_selection->select(m_pageIndex, *styleIt, true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			delete newData;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_selection->makeCurrent();
Toshihiro Shimizu 890ddd
		//do not activate a dirty flag here in case that m_palette is not currentpalette
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + (int)m_items.size() * 100; // forfait
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		QString palNameStr = QObject::tr("  to Palette : %1")
Toshihiro Shimizu 890ddd
								 .arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
		if (m_pasteName && m_pasteColor)
Toshihiro Shimizu 890ddd
			return QObject::tr("Paste Color && Name%1").arg(palNameStr);
Toshihiro Shimizu 890ddd
		else if (m_pasteName && !m_pasteColor)
Toshihiro Shimizu 890ddd
			return QObject::tr("Paste Name%1").arg(palNameStr);
Toshihiro Shimizu 890ddd
		else if (!m_pasteName && m_pasteColor)
Toshihiro Shimizu 890ddd
			return QObject::tr("Paste Color%1").arg(palNameStr);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return QObject::tr("Paste%1").arg(palNameStr);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::pasteStylesValues(bool pasteName, bool pasteColor)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (palette->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	if (!page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (isSelected(m_pageIndex, 0) && page->getStyleId(0) == 0) {
Toshihiro Shimizu 890ddd
		error(QObject::tr("Can't modify color #0"));
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const StyleData *data = dynamic_cast<const *="" styledata="">(QApplication::clipboard()->mimeData());</const>
Toshihiro Shimizu 890ddd
	if (!data)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int dataStyleCount = data->getStyleCount();
Toshihiro Shimizu 890ddd
	if (dataStyleCount > (int)m_styleIndicesInPage.size()) {
Toshihiro Shimizu 890ddd
		QString question = QObject::tr("There are more cut/copied styles than selected. Paste anyway (adding styles)?");
Shinya Kitaoka eabf18
		int ret = DVGui::MsgBox(question, QObject::tr("Paste"), QObject::tr("Cancel"), 0);
Toshihiro Shimizu 890ddd
		if (ret == 2 || ret == 0)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int i = 0;
Toshihiro Shimizu 890ddd
	UndoPasteValues *undo = new UndoPasteValues(this, pasteName, pasteColor);
Toshihiro Shimizu 890ddd
	std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
	int indexInPage = 0;
Toshihiro Shimizu 890ddd
	for (it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end() && i < data->getStyleCount(); ++it, i++) {
Toshihiro Shimizu 890ddd
		if (page->getStyleCount() < i)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		indexInPage = *it;
Toshihiro Shimizu 890ddd
		int styleId = page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
		undo->addItem(indexInPage, palette->getStyle(styleId), data->getStyle(i));
Toshihiro Shimizu 890ddd
		TColorStyle *colorStyle = page->getStyle(indexInPage);
Shinya Kitaoka 3bfa54
		std::wstring styleName = colorStyle->getName();
Toshihiro Shimizu 890ddd
		unsigned int flags = colorStyle->getFlags();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (pasteColor) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//first, check out the types of copied and pasted styles
Toshihiro Shimizu 890ddd
			StyleType srcType, dstType;
Toshihiro Shimizu 890ddd
			//copied (source)
Toshihiro Shimizu 890ddd
			if (data->getStyle(i)->getGlobalName() == L"")
Toshihiro Shimizu 890ddd
				srcType = NORMALSTYLE;
Toshihiro Shimizu 890ddd
			else if (data->getStyle(i)->getOriginalName() == L"")
Toshihiro Shimizu 890ddd
				srcType = STUDIOSTYLE;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				srcType = LINKEDSTYLE;
Toshihiro Shimizu 890ddd
			//pasted (destination)
Toshihiro Shimizu 890ddd
			TColorStyle *dstStyle = page->getStyle(indexInPage);
Toshihiro Shimizu 890ddd
			std::wstring dstGlobalName = dstStyle->getGlobalName();
Toshihiro Shimizu 890ddd
			std::wstring dstOriginalName = dstStyle->getOriginalName();
Toshihiro Shimizu 890ddd
			if (dstGlobalName == L"")
Toshihiro Shimizu 890ddd
				dstType = NORMALSTYLE;
Toshihiro Shimizu 890ddd
			else if (dstOriginalName == L"")
Toshihiro Shimizu 890ddd
				dstType = STUDIOSTYLE;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				dstType = LINKEDSTYLE;
Toshihiro Shimizu 890ddd
			//---- 追加ここまで iwasawa
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//For cleanup styles, do not duplicate the cleanup information. Just paste color information.
Toshihiro Shimizu 890ddd
			TCleanupStyle *cleanupStyle = dynamic_cast<tcleanupstyle *="">(data->getStyle(i));</tcleanupstyle>
Toshihiro Shimizu 890ddd
			if (cleanupStyle && !palette->isCleanupPalette())
Toshihiro Shimizu 890ddd
				palette->setStyle(styleId, cleanupStyle->getMainColor());
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				palette->setStyle(styleId, data->getStyle(i)->clone());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//Process the global and original names according to the pasted style
Toshihiro Shimizu 890ddd
			TColorStyle *pastedStyle = getPalette()->getStyle(styleId);
Toshihiro Shimizu 890ddd
			if (srcType == NORMALSTYLE) {
Toshihiro Shimizu 890ddd
				if (dstType == NORMALSTYLE) {
Toshihiro Shimizu 890ddd
				}								 //1. From normal to normal. Do nothing.
Toshihiro Shimizu 890ddd
				else if (dstType == STUDIOSTYLE) //2. From normal to studio. Restore the global name
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
				else //dstType == LINKEDSTYLE		//3. From normal to linked. Restore both the global and the original name. Activate the edited flag.
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(dstOriginalName);
Toshihiro Shimizu 890ddd
					pastedStyle->setIsEditedFlag(true);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else if (srcType == STUDIOSTYLE) {
Toshihiro Shimizu 890ddd
				if (dstType == NORMALSTYLE) //4. From studio to normal. Set the studio style's name to the original name.
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(data->getStyle(i)->getName());
Toshihiro Shimizu 890ddd
				else if (dstType == STUDIOSTYLE) //5. From studio to studio. Restore the global name.
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
				else //dstStyle == LINKEDSTYLE		//6. From studio to linked. Set the studio style's name to the original name, and set the edited flag to off.
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(data->getStyle(i)->getName());
Toshihiro Shimizu 890ddd
					pastedStyle->setIsEditedFlag(false);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			} else //srcType == LINKEDSTYLE
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				if (dstType == NORMALSTYLE) {
Toshihiro Shimizu 890ddd
				}								 //7. From linked to normal. Do nothing.
Toshihiro Shimizu 890ddd
				else if (dstType == STUDIOSTYLE) //8. From linked to studio. Restore the global name. Delete the original name. Set the edited flag to off.
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					pastedStyle->setGlobalName(dstGlobalName);
Toshihiro Shimizu 890ddd
					pastedStyle->setOriginalName(L"");
Toshihiro Shimizu 890ddd
					pastedStyle->setIsEditedFlag(false);
Toshihiro Shimizu 890ddd
				} else //dstStyle == LINKEDSTYLE		//9. From linked to linked. Do nothing (bring all information from the original).
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// put back the name when "paste color"
Toshihiro Shimizu 890ddd
			if (!pasteName) {
Toshihiro Shimizu 890ddd
				page->getStyle(indexInPage)->setName(styleName);
Toshihiro Shimizu 890ddd
				page->getStyle(indexInPage)->setFlags(flags);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//when "paste name"
Toshihiro Shimizu 890ddd
		if (pasteName)
Toshihiro Shimizu 890ddd
			page->getStyle(indexInPage)->setName(data->getStyle(i)->getName());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Se gli stili del data sono piu' di quelli selezionati faccio un paste degli stili che restano,
Toshihiro Shimizu 890ddd
	// inserisco i nuovi stili dopo indexInPage.
Toshihiro Shimizu 890ddd
	if (i < dataStyleCount) {
Toshihiro Shimizu 890ddd
		StyleData *newData = new StyleData();
Toshihiro Shimizu 890ddd
		int j;
Toshihiro Shimizu 890ddd
		for (j = i; j < dataStyleCount; j++)
Toshihiro Shimizu 890ddd
			newData->addStyle(data->getStyleIndex(j), data->getStyle(j)->clone());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::set<int> styleIndicesInPage;</int>
Toshihiro Shimizu 890ddd
		pasteStylesDataWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle, newData, indexInPage + 1, m_pageIndex, &styleIndicesInPage);
Toshihiro Shimizu 890ddd
		undo->addItemToInsert(styleIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::set<int>::iterator styleIt;</int>
Toshihiro Shimizu 890ddd
		for (styleIt = styleIndicesInPage.begin(); styleIt != styleIndicesInPage.end(); ++styleIt)
Toshihiro Shimizu 890ddd
			m_styleIndicesInPage.insert(*styleIt);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		delete newData;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//clear cache(invalidate) of the level
Toshihiro Shimizu 890ddd
	if (m_levelHandle && m_levelHandle->getSimpleLevel() && !m_levelHandle->getSimpleLevel()->getProperties()->getDirtyFlag())
Toshihiro Shimizu 890ddd
		m_levelHandle->getSimpleLevel()->invalidateFrames();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_paletteHandle->notifyColorStyleChanged(false);
Toshihiro Shimizu 890ddd
	m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//this is to redraw the style editor with colorStyleSwitched() signal
Toshihiro Shimizu 890ddd
	m_paletteHandle->setStyleIndex(m_paletteHandle->getStyleIndex());
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::pasteStylesValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	pasteStylesValues(true, true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::pasteStylesColor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	pasteStylesValues(false, true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::pasteStylesName()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	pasteStylesValues(true, false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// UndoBlendColor
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class UndoBlendColor : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	std::vector<std::pair<int, *="" tcolorstyle="">> m_colorStyles;</std::pair<int,>
Toshihiro Shimizu 890ddd
	TPixel32 m_c0, m_c1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	UndoBlendColor(TPaletteHandle *paletteHandle, int pageIndex, std::vector<std::pair<int, *="" tcolorstyle="">> colorStyles,</std::pair<int,>
Toshihiro Shimizu 890ddd
				   const TPixel32 &c0, const TPixel32 &c1)
Toshihiro Shimizu 890ddd
		: m_paletteHandle(paletteHandle), m_pageIndex(pageIndex), m_colorStyles(colorStyles), m_c0(c0), m_c1(c1)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_palette = m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~UndoBlendColor()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_palette)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		if (!page)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		int count = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (UINT i = 0; i < m_colorStyles.size(); i++) {
Toshihiro Shimizu 890ddd
			TColorStyle *st = page->getStyle(m_colorStyles[i].first);
Toshihiro Shimizu 890ddd
			QString gname = QString::fromStdWString(st->getGlobalName());
Toshihiro Shimizu 890ddd
			if (!gname.isEmpty() && gname[0] != L'-')
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			m_palette->setStyle(page->getStyleId(m_colorStyles[i].first), m_colorStyles[i].second->clone());
Toshihiro Shimizu 890ddd
			m_colorStyles[i].second->invalidateIcon();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//do not activate a dirty flag here in case that m_palette is not currentpalette
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_palette)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		if (!page)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		for (UINT i = 0; i < m_colorStyles.size(); i++) {
Toshihiro Shimizu 890ddd
			TColorStyle *cs = page->getStyle(m_colorStyles[i].first);
Toshihiro Shimizu 890ddd
			QString gname = QString::fromStdWString(cs->getGlobalName());
Toshihiro Shimizu 890ddd
			if (!gname.isEmpty() && gname[0] != L'-')
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			assert(cs);
Toshihiro Shimizu 890ddd
			if (!cs)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			cs->setMainColor(blend(m_c0, m_c1, (double)i / (double)(m_colorStyles.size() - 1)));
Toshihiro Shimizu 890ddd
			cs->invalidateIcon();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//do not activate a dirty flag here in case that m_palette is not currentpalette
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this); //+500*m_oldStyles.size(); //dipende da che stile ha salvato
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Blend Colors  in Palette : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} //namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::blendStyles()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (palette->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int n = m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
	if (n < 2)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<tcolorstyle *=""> styles;</tcolorstyle>
Toshihiro Shimizu 890ddd
	std::vector<std::pair<int, *="" tcolorstyle="">> oldStyles;</std::pair<int,>
Toshihiro Shimizu 890ddd
	for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
Toshihiro Shimizu 890ddd
		 it != m_styleIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
		TColorStyle *cs = page->getStyle(*it);
Toshihiro Shimizu 890ddd
		assert(cs);
Toshihiro Shimizu 890ddd
		styles.push_back(cs);
Toshihiro Shimizu 890ddd
		oldStyles.push_back(std::pair<int, *="" tcolorstyle="">(*it, cs->clone()));</int,>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	assert(styles.size() >= 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel32 c0 = styles.front()->getMainColor();
Toshihiro Shimizu 890ddd
	TPixel32 c1 = styles.back()->getMainColor();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool areAllStyleLincked = true;
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 1; i < n - 1; i++) {
Toshihiro Shimizu 890ddd
		QString gname = QString::fromStdWString(styles[i]->getGlobalName());
Toshihiro Shimizu 890ddd
		if (!gname.isEmpty() && gname[0] != L'-')
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		areAllStyleLincked = false;
Toshihiro Shimizu 890ddd
		styles[i]->setMainColor(blend(c0, c1, (double)i / (double)(n - 1)));
Toshihiro Shimizu 890ddd
		styles[i]->invalidateIcon();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (areAllStyleLincked)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_paletteHandle->notifyColorStyleChanged(false);
Toshihiro Shimizu 890ddd
	m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UndoBlendColor *undo = new UndoBlendColor(m_paletteHandle, m_pageIndex, oldStyles, c0, c1);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// UndoLinkToStudioPalette
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class UndoLinkToStudioPalette : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	struct ColorStyleData {
Toshihiro Shimizu 890ddd
		int m_indexInPage;
Toshihiro Shimizu 890ddd
		TColorStyle *m_oldStyle;
Shinya Kitaoka 3bfa54
		std::wstring m_newName;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	std::vector<colorstyledata> m_styles;</colorstyledata>
Toshihiro Shimizu 890ddd
	bool m_updateLinkedColors;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	UndoLinkToStudioPalette(TPaletteHandle *paletteHandle, int pageIndex)
Toshihiro Shimizu 890ddd
		: m_paletteHandle(paletteHandle), m_pageIndex(pageIndex), m_updateLinkedColors(false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_palette = m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~UndoLinkToStudioPalette()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setUpdateLinkedColors(bool updateLinkedColors)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_updateLinkedColors = updateLinkedColors;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void setColorStyle(int indexInPage, TColorStyle *oldStyle, std::wstring newName)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		ColorStyleData data;
Toshihiro Shimizu 890ddd
		data.m_indexInPage = indexInPage;
Toshihiro Shimizu 890ddd
		data.m_newName = newName;
Toshihiro Shimizu 890ddd
		data.m_oldStyle = oldStyle;
Toshihiro Shimizu 890ddd
		m_styles.push_back(data);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		assert(page);
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_styles.size(); i++) {
Toshihiro Shimizu 890ddd
			ColorStyleData data = m_styles[i];
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(m_styles[i].m_indexInPage);
Toshihiro Shimizu 890ddd
			TColorStyle *oldStyle = m_styles[i].m_oldStyle;
Toshihiro Shimizu 890ddd
			m_palette->setStyle(styleId, oldStyle->clone());
Toshihiro Shimizu 890ddd
			m_palette->getStyle(styleId)->assignNames(oldStyle);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		assert(page);
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_styles.size(); i++) {
Toshihiro Shimizu 890ddd
			ColorStyleData data = m_styles[i];
Toshihiro Shimizu 890ddd
			TColorStyle *cs = page->getStyle(data.m_indexInPage);
Toshihiro Shimizu 890ddd
			cs->setGlobalName(data.m_newName);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
		if (m_updateLinkedColors)
Toshihiro Shimizu 890ddd
			StudioPalette::instance()->updateLinkedColors(m_palette.getPointer());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Toggle Link  in Palette : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} //namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::toggleLink()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int n = m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
	if (n <= 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::vector<std::pair<int, std::wstring="">> oldColorStylesLinked;</std::pair<int,>
Shinya Kitaoka 3bfa54
	std::vector<std::pair<int, std::wstring="">> newColorStylesLinked;</std::pair<int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool somethingHasBeenLinked = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool currentStyleIsInSelection = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UndoLinkToStudioPalette *undo = new UndoLinkToStudioPalette(m_paletteHandle, m_pageIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
Toshihiro Shimizu 890ddd
		 it != m_styleIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
		int index = *it;
Toshihiro Shimizu 890ddd
		TColorStyle *cs = page->getStyle(index);
Toshihiro Shimizu 890ddd
		assert(cs);
Shinya Kitaoka 3bfa54
		std::wstring name = cs->getGlobalName();
Toshihiro Shimizu 890ddd
		TColorStyle *oldCs = cs->clone();
Toshihiro Shimizu 890ddd
		if (name != L"" && (name[0] == L'-' || name[0] == L'+')) {
Toshihiro Shimizu 890ddd
			name[0] = name[0] == L'-' ? L'+' : L'-';
Toshihiro Shimizu 890ddd
			cs->setGlobalName(name);
Toshihiro Shimizu 890ddd
			if (name[0] == L'+')
Toshihiro Shimizu 890ddd
				somethingHasBeenLinked = true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		undo->setColorStyle(index, oldCs, name);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (*it == palette->getPage(m_pageIndex)->search(m_paletteHandle->getStyleIndex()))
Toshihiro Shimizu 890ddd
			currentStyleIsInSelection = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (somethingHasBeenLinked)
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->updateLinkedColors(palette);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_paletteHandle->notifyColorStyleChanged(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (currentStyleIsInSelection)
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	undo->setUpdateLinkedColors(somethingHasBeenLinked);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::eraseToggleLink()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int n = m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
	if (n <= 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool currentStyleIsInSelection = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::vector<std::pair<int, std::wstring="">> oldColorStylesLinked;</std::pair<int,>
Shinya Kitaoka 3bfa54
	std::vector<std::pair<int, std::wstring="">> newColorStylesLinked;</std::pair<int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UndoLinkToStudioPalette *undo = new UndoLinkToStudioPalette(m_paletteHandle, m_pageIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (std::set<int>::iterator it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end(); ++it) {</int>
Toshihiro Shimizu 890ddd
		int index = *it;
Toshihiro Shimizu 890ddd
		TColorStyle *cs = page->getStyle(index);
Toshihiro Shimizu 890ddd
		assert(cs);
Toshihiro Shimizu 890ddd
		TColorStyle *oldCs = cs->clone();
Shinya Kitaoka 3bfa54
		std::wstring name = cs->getGlobalName();
Toshihiro Shimizu 890ddd
		if (name != L"" && (name[0] == L'-' || name[0] == L'+'))
Toshihiro Shimizu 890ddd
			cs->setGlobalName(L"");
Toshihiro Shimizu 890ddd
		undo->setColorStyle(index, oldCs, L"");
Toshihiro Shimizu 890ddd
		if (*it == palette->getPage(m_pageIndex)->search(m_paletteHandle->getStyleIndex()))
Toshihiro Shimizu 890ddd
			currentStyleIsInSelection = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_paletteHandle->notifyColorStyleChanged(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (currentStyleIsInSelection)
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TStyleSelection::toggleKeyframe(int frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int n = m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
	for (std::set<int>::iterator it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end(); ++it) {</int>
Toshihiro Shimizu 890ddd
		int styleId = page->getStyleId(*it);
Toshihiro Shimizu 890ddd
		palette->setKeyframe(styleId, frame);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class UndoRemoveLink : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
	int m_pageIndex;
Toshihiro Shimizu 890ddd
	struct ColorStyleData {
Toshihiro Shimizu 890ddd
		int m_indexInPage;
Shinya Kitaoka 3bfa54
		std::wstring m_oldGlobalName;
Shinya Kitaoka 3bfa54
		std::wstring m_oldOriginalName;
Toshihiro Shimizu 890ddd
		bool m_oldEdittedFlag;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	std::vector<colorstyledata> m_styles;</colorstyledata>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	UndoRemoveLink(TPaletteHandle *paletteHandle, int pageIndex)
Toshihiro Shimizu 890ddd
		: m_paletteHandle(paletteHandle), m_pageIndex(pageIndex)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_palette = m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~UndoRemoveLink() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setColorStyle(int indexInPage, TColorStyle *oldStyle)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		ColorStyleData data;
Toshihiro Shimizu 890ddd
		data.m_indexInPage = indexInPage;
Toshihiro Shimizu 890ddd
		data.m_oldGlobalName = oldStyle->getGlobalName();
Toshihiro Shimizu 890ddd
		data.m_oldOriginalName = oldStyle->getOriginalName();
Toshihiro Shimizu 890ddd
		data.m_oldEdittedFlag = oldStyle->getIsEditedFlag();
Toshihiro Shimizu 890ddd
		m_styles.push_back(data);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		assert(page);
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_styles.size(); i++) {
Toshihiro Shimizu 890ddd
			ColorStyleData data = m_styles[i];
Toshihiro Shimizu 890ddd
			int styleId = page->getStyleId(m_styles[i].m_indexInPage);
Toshihiro Shimizu 890ddd
			m_palette->getStyle(styleId)->setGlobalName(data.m_oldGlobalName);
Toshihiro Shimizu 890ddd
			m_palette->getStyle(styleId)->setOriginalName(data.m_oldOriginalName);
Toshihiro Shimizu 890ddd
			m_palette->getStyle(styleId)->setIsEditedFlag(data.m_oldEdittedFlag);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPalette::Page *page = m_palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
		assert(page);
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_styles.size(); i++) {
Toshihiro Shimizu 890ddd
			ColorStyleData data = m_styles[i];
Toshihiro Shimizu 890ddd
			TColorStyle *cs = page->getStyle(data.m_indexInPage);
Toshihiro Shimizu 890ddd
			cs->setGlobalName(L"");
Toshihiro Shimizu 890ddd
			cs->setOriginalName(L"");
Toshihiro Shimizu 890ddd
			cs->setIsEditedFlag(false);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Remove Link  in Palette : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_palette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! remove link from studio palette. Delete the global and the orginal names. return true if something changed
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
bool TStyleSelection::removeLink()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	int n = m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
	if (n <= 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool somethingChanged = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UndoRemoveLink *undo = new UndoRemoveLink(m_paletteHandle, m_pageIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
Toshihiro Shimizu 890ddd
		 it != m_styleIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
		TColorStyle *cs = page->getStyle(*it);
Toshihiro Shimizu 890ddd
		assert(cs);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (cs->getGlobalName() != L"" || cs->getOriginalName() != L"") {
Toshihiro Shimizu 890ddd
			undo->setColorStyle(*it, cs);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			cs->setGlobalName(L"");
Toshihiro Shimizu 890ddd
			cs->setOriginalName(L"");
Toshihiro Shimizu 890ddd
			cs->setIsEditedFlag(false);
Toshihiro Shimizu 890ddd
			somethingChanged = true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (somethingChanged) {
Toshihiro Shimizu 890ddd
		palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		delete undo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return somethingChanged;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
class getBackOriginalStyleUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStyleSelection m_selection;
Toshihiro Shimizu 890ddd
	std::vector<tpixel32> m_oldColors, m_newColors;</tpixel32>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//remember the edited flags
Toshihiro Shimizu 890ddd
	std::vector<bool> m_oldEditedFlags, m_newEditedFlags;</bool>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	getBackOriginalStyleUndo(const TStyleSelection &selection) : m_selection(selection)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		getColors(m_oldColors, m_oldEditedFlags);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~getBackOriginalStyleUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getStyles(std::vector<tcolorstyle *=""> &styles, const TStyleSelection &selection) const</tcolorstyle>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		styles.clear();
Toshihiro Shimizu 890ddd
		int pageIndex = selection.getPageIndex();
Toshihiro Shimizu 890ddd
		TPaletteP palette = selection.getPalette();
Toshihiro Shimizu 890ddd
		TPalette::Page *page = palette->getPage(pageIndex);
Toshihiro Shimizu 890ddd
		if (!page)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		std::set<int> indices = selection.getIndicesInPage();</int>
Toshihiro Shimizu 890ddd
		// non si puo' modificare il BG
Toshihiro Shimizu 890ddd
		if (pageIndex == 0)
Toshihiro Shimizu 890ddd
			indices.erase(0);
Toshihiro Shimizu 890ddd
		styles.reserve(indices.size());
Toshihiro Shimizu 890ddd
		for (std::set<int>::iterator it = indices.begin(); it != indices.end(); ++it)</int>
Toshihiro Shimizu 890ddd
			styles.push_back(page->getStyle(*it));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof *this + (m_oldColors.size() + m_newColors.size()) * sizeof(TPixel32);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onAdd()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		getColors(m_newColors, m_newEditedFlags);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getColors(std::vector<tpixel32> &colors, std::vector<bool> &flags) const</bool></tpixel32>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::vector<tcolorstyle *=""> styles;</tcolorstyle>
Toshihiro Shimizu 890ddd
		getStyles(styles, m_selection);
Toshihiro Shimizu 890ddd
		colors.resize(styles.size());
Toshihiro Shimizu 890ddd
		flags.resize(styles.size());
Toshihiro Shimizu 890ddd
		for (int i = 0; i < (int)styles.size(); i++) {
Toshihiro Shimizu 890ddd
			colors[i] = styles[i]->getMainColor();
Toshihiro Shimizu 890ddd
			flags[i] = styles[i]->getIsEditedFlag();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setColors(const std::vector<tpixel32> &colors, const std::vector<bool> &flags) const</bool></tpixel32>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::vector<tcolorstyle *=""> styles;</tcolorstyle>
Toshihiro Shimizu 890ddd
		getStyles(styles, m_selection);
Toshihiro Shimizu 890ddd
		int n = tmin(styles.size(), colors.size());
Toshihiro Shimizu 890ddd
		for (int i = 0; i < n; i++) {
Toshihiro Shimizu 890ddd
			QString gname = QString::fromStdWString(styles[i]->getGlobalName());
Toshihiro Shimizu 890ddd
			if (!gname.isEmpty() && gname[0] != L'-')
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			styles[i]->setMainColor(colors[i]);
Toshihiro Shimizu 890ddd
			styles[i]->setIsEditedFlag(flags[i]);
Toshihiro Shimizu 890ddd
			styles[i]->invalidateIcon();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_selection.getPaletteHandle()->notifyColorStyleChanged(false, false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		setColors(m_oldColors, m_oldEditedFlags);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		setColors(m_newColors, m_newEditedFlags);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Get Color from Studio Palette");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! get the color from the linked style of the studio palette
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void TStyleSelection::getBackOriginalStyle()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || m_pageIndex < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isEmpty() || palette->isLocked())
Toshihiro Shimizu 890ddd
		return; //110804 iwasawa
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int n = m_styleIndicesInPage.size();
Toshihiro Shimizu 890ddd
	if (n <= 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette::Page *page = palette->getPage(m_pageIndex);
Toshihiro Shimizu 890ddd
	assert(page);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool somethingChanged = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::map<std::wstring, tpalettep=""> table;</std::wstring,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUndo *undo = new getBackOriginalStyleUndo(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//for each selected style
Toshihiro Shimizu 890ddd
	for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
Toshihiro Shimizu 890ddd
		 it != m_styleIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
		TColorStyle *cs = page->getStyle(*it);
Toshihiro Shimizu 890ddd
		assert(cs);
Shinya Kitaoka 3bfa54
		std::wstring gname = cs->getGlobalName();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// if the style has no link
Toshihiro Shimizu 890ddd
		if (gname == L"")
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Find the palette from the table
Toshihiro Shimizu 890ddd
		int k = gname.find_first_of(L'-', 1);
Shinya Kitaoka 3bfa54
		if (k == (int)std::wstring::npos)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
		std::wstring paletteId = gname.substr(1, k - 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
		std::map<std::wstring, tpalettep="">::iterator palIt;</std::wstring,>
Toshihiro Shimizu 890ddd
		palIt = table.find(paletteId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPalette *spPalette = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//If not found in the table, then search for a new studio palette.
Toshihiro Shimizu 890ddd
		if (palIt == table.end()) {
Toshihiro Shimizu 890ddd
			spPalette =
Toshihiro Shimizu 890ddd
				StudioPalette::instance()
Toshihiro Shimizu 890ddd
					->getPalette(paletteId);
Toshihiro Shimizu 890ddd
			if (!spPalette)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			table[paletteId] = spPalette;
Toshihiro Shimizu 890ddd
			assert(spPalette->getRefCount() == 1);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			spPalette = palIt->second.getPointer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//j is StudioPaletteID
Toshihiro Shimizu 890ddd
		int j = toInt(gname.substr(k + 1));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (spPalette && 0 <= j && j < spPalette->getStyleCount()) {
Toshihiro Shimizu 890ddd
			TColorStyle *spStyle = spPalette->getStyle(j);
Toshihiro Shimizu 890ddd
			assert(spStyle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//edit flag is also copied here
Toshihiro Shimizu 890ddd
			spStyle = spStyle->clone();
Toshihiro Shimizu 890ddd
			spStyle->setGlobalName(gname);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//get the original name from the studio palette
Toshihiro Shimizu 890ddd
			spStyle->setOriginalName(spStyle->getName());
Toshihiro Shimizu 890ddd
			//do not change the style name
Toshihiro Shimizu 890ddd
			spStyle->setName(cs->getName());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			palette->setStyle(page->getStyleId(*it), spStyle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			somethingChanged = true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (somethingChanged) {
Toshihiro Shimizu 890ddd
		palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleChanged(false);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyColorStyleSwitched();
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		delete undo;
Toshihiro Shimizu 890ddd
}