Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/paletteviewergui.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/styleselection.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/trepetitionguard.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/paletteviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/selectioncommandids.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/stylenameeditor.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/viewcommandids.h"
Toshihiro Shimizu 890ddd
#include "palettedata.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/palettecmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/studiopalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/imagestyles.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qkeyevent></qkeyevent>
Toshihiro Shimizu 890ddd
#include <qmenubar></qmenubar>
Toshihiro Shimizu 890ddd
#include <qtooltip></qtooltip>
Toshihiro Shimizu 890ddd
#include <qdrag></qdrag>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qshortcut></qshortcut>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// enable to set font size for style name separately from other texts
Toshihiro Shimizu 890ddd
TEnv::IntVar EnvSoftwareCurrentFontSize_StyleName("SoftwareCurrentFontSize_StyleName", 11);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace PaletteViewerGUI;
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \namespace PaletteViewerGUI
Toshihiro Shimizu 890ddd
		\brief Provides a collection of widget to show \b palette.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \enum PaletteViewerGUI::PaletteViewType
Toshihiro Shimizu 890ddd
		\brief Useful to mark different palette viewer type.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		There are three possible palette to view:
Toshihiro Shimizu 890ddd
		\li level palette, palette of current level;
Toshihiro Shimizu 890ddd
		\li cleanup palette, current scene cleanup palette;
Toshihiro Shimizu 890ddd
		\li studio palette.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class PaletteViewerGUI::PageViewer
Toshihiro Shimizu 890ddd
		\brief The PageViewer class provides an object to view and manage palettes page.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Inherits \b QFrame and \b TSelection::View.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		This object allows to show and manage a single palette page. An enum type
Toshihiro Shimizu 890ddd
		\b PaletteViewerGUI::PageViewer::ViewMode, getViewMode(), specify visualization
Toshihiro Shimizu 890ddd
		mode, it is possible set it using setViewMode(). Class manage all mouse event,
Toshihiro Shimizu 890ddd
		move, press, drag and drop.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
/*! \enum PaletteViewerGUI::PageViewer::ViewMode
Toshihiro Shimizu 890ddd
		Useful to mark different page view moed:
Toshihiro Shimizu 890ddd
		\li SmallChips: displays styles as small squares; the name of the style is
Toshihiro Shimizu 890ddd
		displayed as tooltip.
Toshihiro Shimizu 890ddd
		\li SmallChipsWithName:
Toshihiro Shimizu 890ddd
		displays styles as small squares with the name insde.
Toshihiro Shimizu 890ddd
		\li LargeChips: displays the styles on top of the name of the style.
Toshihiro Shimizu 890ddd
		\li List:				List displays style thumbnails next to their names in a list;
Toshihiro Shimizu 890ddd
		if the palette styles are referring to a studio palette, its
Toshihiro Shimizu 890ddd
		path will be displayed along with the style name.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
/*!	\fn TPalette::Page* PageViewer::getPage() const
Toshihiro Shimizu 890ddd
		Return current page.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
/*!	\fn ViewMode PageViewer::getViewMode() const
Toshihiro Shimizu 890ddd
		Return current page view mode \b PaletteViewerGUI::PageViewer::ViewMode.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
/*! \fn void TPalette::onSelectionChanged()
Toshihiro Shimizu 890ddd
		Update current page view.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
PageViewer::PageViewer(QWidget *parent, PaletteViewType viewType, bool hasPasteColors)
Toshihiro Shimizu 890ddd
	: QFrame(parent), m_page(0), m_chipsOrigin(2, 2), m_chipPerRow(0), m_viewMode(SmallChips), m_styleSelection(new TStyleSelection()), m_frameHandle(0), m_renameTextField(new LineEdit(this)), m_dropPositionIndex(-1), m_dropPageCreated(false), m_startDrag(false), m_viewType(viewType), m_nameDisplayMode(Style), m_hasPasteColors(hasPasteColors), m_changeStyleCommand(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFrameStyle(QFrame::StyledPanel);
Toshihiro Shimizu 890ddd
	setObjectName("PageViewer");
Toshihiro Shimizu 890ddd
	setFocusPolicy(Qt::StrongFocus);
Toshihiro Shimizu 890ddd
	CommandManager *cmd = CommandManager::instance();
Toshihiro Shimizu 890ddd
	QAction *pasteValueAct = cmd->getAction(MI_PasteInto);
Toshihiro Shimizu 890ddd
	addAction(pasteValueAct);
Toshihiro Shimizu 890ddd
	if (m_hasPasteColors) {
Toshihiro Shimizu 890ddd
		QAction *pasteColorsAct = cmd->getAction(MI_PasteColors);
Toshihiro Shimizu 890ddd
		addAction(pasteColorsAct);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_styleNameEditor = new StyleNameEditor(this);
Toshihiro Shimizu 890ddd
	m_styleNameEditor->hide();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_renameTextField->hide();
Toshihiro Shimizu 890ddd
	m_renameTextField->setObjectName("RenameColorTextField");
Toshihiro Shimizu 890ddd
	connect(m_renameTextField, SIGNAL(editingFinished()), this, SLOT(onStyleRenamed()));
Toshihiro Shimizu 890ddd
	m_styleSelection->setView(this);
Toshihiro Shimizu 890ddd
	setAcceptDrops(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// applying default chip sizes
Toshihiro Shimizu 890ddd
	ViewMode defaultChipSize;
Toshihiro Shimizu 890ddd
	switch (m_viewType) {
Toshihiro Shimizu 890ddd
	case LEVEL_PALETTE:
Toshihiro Shimizu 890ddd
		defaultChipSize = (ViewMode)ChipSizeManager::instance()->chipSize_Palette;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case CLEANUP_PALETTE:
Toshihiro Shimizu 890ddd
		defaultChipSize = (ViewMode)ChipSizeManager::instance()->chipSize_Cleanup;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case STUDIO_PALETTE:
Toshihiro Shimizu 890ddd
		defaultChipSize = (ViewMode)ChipSizeManager::instance()->chipSize_Studio;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	default:
Toshihiro Shimizu 890ddd
		defaultChipSize = (ViewMode)2;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setViewMode(defaultChipSize);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PageViewer::~PageViewer()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_styleSelection;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::setPaletteHandle(TPaletteHandle *paletteHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *previousPalette = getPaletteHandle();
Toshihiro Shimizu 890ddd
	if (previousPalette == paletteHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (previousPalette)
Toshihiro Shimizu 890ddd
		disconnect(previousPalette, SIGNAL(colorStyleChanged()), this, SLOT(update()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_styleSelection->setPaletteHandle(paletteHandle);
Toshihiro Shimizu 890ddd
	connect(paletteHandle, SIGNAL(colorStyleChanged()), SLOT(update()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_styleNameEditor->setPaletteHandle(paletteHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPaletteHandle *PageViewer::getPaletteHandle() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_styleSelection->getPaletteHandle();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::setXsheetHandle(TXsheetHandle *xsheetHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_styleSelection->setXsheetHandle(xsheetHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXsheetHandle *PageViewer::getXsheetHandle() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_styleSelection->getXsheetHandle();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! for clearing the cache when executing paste style command from StyleSelection
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::setLevelHandle(TXshLevelHandle *levelHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_styleSelection->setLevelHandle(levelHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::setFrameHandle(TFrameHandle *frameHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_frameHandle = frameHandle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFrameHandle *PageViewer::getFrameHandle() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_frameHandle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::setCurrentStyleIndex(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	getPaletteHandle()->setStyleIndex(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int PageViewer::getCurrentStyleIndex() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return getPaletteHandle()->getStyleIndex();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set current page to \b page and update view.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::setPage(TPalette::Page *page)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_page = page;
Toshihiro Shimizu 890ddd
	computeSize();
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return chip count contained in current page.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
int PageViewer::getChipCount() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_page ? m_page->getStyleCount() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set current view mode \b PaletteViewerGUI::PageViewer::ViewMode to \b viewMode and update view.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::setViewMode(ViewMode viewMode)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_viewMode == viewMode)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_viewMode = viewMode;
Toshihiro Shimizu 890ddd
	computeSize();
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//keep new view mode for reproducing the same mode when a new palette is made
Toshihiro Shimizu 890ddd
	switch (m_viewType) {
Toshihiro Shimizu 890ddd
	case LEVEL_PALETTE:
Toshihiro Shimizu 890ddd
		ChipSizeManager::instance()->chipSize_Palette = (int)m_viewMode;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case CLEANUP_PALETTE:
Toshihiro Shimizu 890ddd
		ChipSizeManager::instance()->chipSize_Cleanup = (int)m_viewMode;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	case STUDIO_PALETTE:
Toshihiro Shimizu 890ddd
		ChipSizeManager::instance()->chipSize_Studio = (int)m_viewMode;
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	default:
Toshihiro Shimizu 890ddd
		break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return current chip index by position \b pos.
Toshihiro Shimizu 890ddd
		N.B. Cannot return chip index > max.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
int PageViewer::posToIndex(const QPoint &pos) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_chipPerRow == 0)
Toshihiro Shimizu 890ddd
		return -1;
Toshihiro Shimizu 890ddd
	QSize chipSize = getChipSize();
Toshihiro Shimizu 890ddd
	int j = (pos.x() - m_chipsOrigin.x()) / chipSize.width();
Toshihiro Shimizu 890ddd
	int i = (pos.y() - m_chipsOrigin.y()) / chipSize.height();
Toshihiro Shimizu 890ddd
	int index = i * m_chipPerRow + j;
Toshihiro Shimizu 890ddd
	// if(index<0 || index>=getChipCount()) return -1;
Toshihiro Shimizu 890ddd
	return index;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return item rect of chip identified by \b index. Item rect is the rect of
Toshihiro Shimizu 890ddd
		chip + name.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
QRect PageViewer::getItemRect(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_chipPerRow == 0)
Toshihiro Shimizu 890ddd
		return QRect();
Toshihiro Shimizu 890ddd
	int row = index / m_chipPerRow;
Toshihiro Shimizu 890ddd
	int col = index - (row * m_chipPerRow);
Toshihiro Shimizu 890ddd
	int x0 = m_chipsOrigin.x();
Toshihiro Shimizu 890ddd
	int y0 = m_chipsOrigin.y();
Toshihiro Shimizu 890ddd
	QSize chipSize = getChipSize();
Toshihiro Shimizu 890ddd
	int chipLx = chipSize.width();
Toshihiro Shimizu 890ddd
	int chipLy = chipSize.height();
Toshihiro Shimizu 890ddd
	QRect rect(x0 + chipLx * col, y0 + chipLy * row, chipLx, chipLy);
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return rect of color area of chip identified by \b index.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
QRect PageViewer::getColorChipRect(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRect rect = getItemRect(index);
Toshihiro Shimizu 890ddd
	if (rect.isNull())
Toshihiro Shimizu 890ddd
		return rect;
Toshihiro Shimizu 890ddd
	if (m_viewMode == LargeChips)
Toshihiro Shimizu 890ddd
		rect.setHeight(20);
Toshihiro Shimizu 890ddd
	else if (m_viewMode == List)
Toshihiro Shimizu 890ddd
		rect.setWidth(rect.height());
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return rect of chip identified by \b index name. (Not in \b SmallChips).
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
QRect PageViewer::getColorNameRect(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QRect rect = getItemRect(index);
Toshihiro Shimizu 890ddd
	if (rect.isNull())
Toshihiro Shimizu 890ddd
		return rect;
Toshihiro Shimizu 890ddd
	if (m_viewMode == LargeChips)
Toshihiro Shimizu 890ddd
		rect.adjust(-10, 14, 10, -14);
Toshihiro Shimizu 890ddd
	else if (m_viewMode == MediumChips)
Toshihiro Shimizu 890ddd
		rect.adjust(-15, 7, 15, -7);
Toshihiro Shimizu 890ddd
	else if (m_viewMode == List)
Toshihiro Shimizu 890ddd
		rect.setLeft(rect.left() + rect.height());
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return rect;
Toshihiro Shimizu 890ddd
	return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add color to current page; if indexInPage == -1 add color at the bottom of page.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::drop(int dstIndexInPage, const QMimeData *mimeData)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_page);
Toshihiro Shimizu 890ddd
	TPalette *palette = m_page->getPalette();
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int dstPageIndex = m_page->getIndex();
Toshihiro Shimizu 890ddd
	if ((m_page->getStyleId(0) == 0 || m_page->getStyleId(1) == 1) && dstIndexInPage < 2)
Toshihiro Shimizu 890ddd
		dstIndexInPage = 2;
Toshihiro Shimizu 890ddd
	if (dstIndexInPage < 0)
Toshihiro Shimizu 890ddd
		dstIndexInPage = m_page->getStyleCount();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(mimeData);</const>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!paletteData || !paletteData->hasStyleIndeces())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *srcPalette = paletteData->getPalette();
Toshihiro Shimizu 890ddd
	int srcPageIndex = paletteData->getPageIndex();
Toshihiro Shimizu 890ddd
	std::set<int> srcIndicesInPage = paletteData->getIndicesInPage();</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_dropPageCreated) {
Toshihiro Shimizu 890ddd
		//Rimuovo e reinserisco la pagina inizializzando l'undo.
Toshihiro Shimizu 890ddd
		palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		int pageIndex = palette->getPageCount() - 1;
Toshihiro Shimizu 890ddd
		palette->erasePage(pageIndex);
Toshihiro Shimizu 890ddd
		if (dstPageIndex != srcPageIndex && pageIndex == dstPageIndex) {
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
			PaletteCmd::addPage(getPaletteHandle());
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_dropPageCreated = false;
Toshihiro Shimizu 890ddd
		getPaletteHandle()->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (srcPalette == palette) {
Toshihiro Shimizu 890ddd
		PaletteCmd::arrangeStyles(getPaletteHandle(), dstPageIndex, dstIndexInPage, srcPageIndex, srcIndicesInPage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//seleziono gli stili spostati
Toshihiro Shimizu 890ddd
		clearSelection();
Toshihiro Shimizu 890ddd
		std::set<int>::const_reverse_iterator i;</int>
Toshihiro Shimizu 890ddd
		int k = 0;
Toshihiro Shimizu 890ddd
		for (i = srcIndicesInPage.rbegin(); i != srcIndicesInPage.rend(); ++i, ++k) {
Toshihiro Shimizu 890ddd
			int index = 0;
Toshihiro Shimizu 890ddd
			if (*i <= dstIndexInPage)
Toshihiro Shimizu 890ddd
				index = dstIndexInPage - k - 1;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				index = dstIndexInPage + k;
Toshihiro Shimizu 890ddd
			m_styleSelection->select(dstPageIndex, index, true);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else //when dropping the style into another palette
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::vector<tcolorstyle *=""> styles;</tcolorstyle>
Toshihiro Shimizu 890ddd
		std::set<int>::iterator it;</int>
Toshihiro Shimizu 890ddd
		for (it = srcIndicesInPage.begin(); it != srcIndicesInPage.end(); ++it) {
Toshihiro Shimizu 890ddd
			int indexInPage = *it;
Toshihiro Shimizu 890ddd
			styles.push_back(srcPalette->getPage(srcPageIndex)->getStyle(indexInPage));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		PaletteCmd::addStyles(getPaletteHandle(), dstPageIndex, dstIndexInPage, styles);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_dropPageCreated) {
Toshihiro Shimizu 890ddd
		m_dropPageCreated = false;
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create an empty page to receive drop.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::createDropPage()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_dropPageCreated)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_dropPageCreated = true;
Toshihiro Shimizu 890ddd
	assert(m_page);
Toshihiro Shimizu 890ddd
	TPalette *palette = m_page->getPalette();
Toshihiro Shimizu 890ddd
	if (palette)
Toshihiro Shimizu 890ddd
		PaletteCmd::addPage(getPaletteHandle(), L"", false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::clearSelection()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_styleSelection->selectNone();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return page chip size, it depend from current \b PaletteViewerGUI::PageViewer::ViewMode.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
QSize PageViewer::getChipSize() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_viewMode == SmallChips || m_viewMode == SmallChipsWithName)
Toshihiro Shimizu 890ddd
		return QSize(48, 33);
Toshihiro Shimizu 890ddd
	else if (m_viewMode == MediumChips)
Toshihiro Shimizu 890ddd
		return QSize(98, 38);
Toshihiro Shimizu 890ddd
	else if (m_viewMode == LargeChips)
Toshihiro Shimizu 890ddd
		return QSize(155, 53);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return QSize(width(), 22);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Draw a single chip style \b style in \b chipRect.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::drawColorChip(QPainter &p, QRect &chipRect, TColorStyle *style)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P icon = style->getIcon(qsize2Dimension(chipRect.size()));
Toshihiro Shimizu 890ddd
	p.drawPixmap(chipRect.left(), chipRect.top(), rasterToQPixmap(icon, false));
Toshihiro Shimizu 890ddd
	p.drawRect(chipRect);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Draw style \b style name in \b nameRect.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::drawColorName(QPainter &p, QRect &nameRect, TColorStyle *style, int styleIndex)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_viewMode == SmallChips && style->getFlags() == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette *palette = (m_page) ? m_page->getPalette() : 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString name = QString::fromStdWString(style->getName());
Toshihiro Shimizu 890ddd
	if (m_viewMode == List) {
Toshihiro Shimizu 890ddd
		p.setPen(getTextColor());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::pair<tfilepath, int=""> g = StudioPalette::instance()->getSourceStyle(style);</tfilepath,>
Toshihiro Shimizu 890ddd
		if (g.first != TFilePath() && g.second >= 0)
Toshihiro Shimizu 890ddd
			name += "  " + toQString(g.first) + ":" + QString::number(g.second);
Toshihiro Shimizu 890ddd
		if (style->getFlags() != 0)
Toshihiro Shimizu 890ddd
			name += "(autopaint)";
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		p.drawText(nameRect.adjusted(6, 4, -6, -4), name);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QColor borderCol(getTextColor());
Toshihiro Shimizu 890ddd
		borderCol.setAlphaF(0.3);
Toshihiro Shimizu 890ddd
		p.setPen(borderCol);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_viewMode == SmallChips && style->getFlags() != 0) {
Toshihiro Shimizu 890ddd
		QRect rect(nameRect.left(), nameRect.top(), 9, 9);
Toshihiro Shimizu 890ddd
		p.fillRect(rect, QBrush(Qt::white));
Toshihiro Shimizu 890ddd
		p.drawRect(rect);
Toshihiro Shimizu 890ddd
		p.drawText(rect, Qt::AlignCenter, "a");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_viewMode == SmallChipsWithName && name != "" && name != "color") {
Toshihiro Shimizu 890ddd
		QRect rect = nameRect;
Toshihiro Shimizu 890ddd
		QPen oldPen = p.pen();
Toshihiro Shimizu 890ddd
		TPixel32 color = style->getMainColor();
Toshihiro Shimizu 890ddd
		int v = (int)(0.299 * color.r + 0.587 * color.g + 0.114 * color.b);
Toshihiro Shimizu 890ddd
		p.setPen(v > 127 ? Qt::black : Qt::white);
Toshihiro Shimizu 890ddd
		int textWidth = QFontMetrics(p.font()).width(name);
Toshihiro Shimizu 890ddd
		if (textWidth < rect.width() - 2)
Toshihiro Shimizu 890ddd
			p.drawText(rect, Qt::AlignCenter, name);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			p.drawText(rect.adjusted(2, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, name);
Toshihiro Shimizu 890ddd
		p.setPen(oldPen);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_viewMode == LargeChips) {
Toshihiro Shimizu 890ddd
		QString index = QString::number(styleIndex);
Toshihiro Shimizu 890ddd
		QFont font = p.font();
Toshihiro Shimizu 890ddd
		int fontSize = font.pointSize();
Toshihiro Shimizu 890ddd
		if (fontSize == -1)
Toshihiro Shimizu 890ddd
			fontSize = font.pixelSize();
Toshihiro Shimizu 890ddd
		int lenght = index.length() * fontSize;
Toshihiro Shimizu 890ddd
		int w = (lenght > 11) ? (lenght) : 11;
Toshihiro Shimizu 890ddd
		int h = 11;
Toshihiro Shimizu 890ddd
		int x0 = nameRect.right() - w + 1;
Toshihiro Shimizu 890ddd
		int y0 = nameRect.top() - h - 1;
Toshihiro Shimizu 890ddd
		p.drawText(nameRect.adjusted(6, 1, -6, -1), name);
Toshihiro Shimizu 890ddd
		QRect indexRect(x0, y0, w, h);
Toshihiro Shimizu 890ddd
		p.fillRect(indexRect, QBrush(Qt::white));
Toshihiro Shimizu 890ddd
		p.drawRect(indexRect);
Toshihiro Shimizu 890ddd
		p.drawText(indexRect, Qt::AlignCenter, index);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QFont f = p.font();
Toshihiro Shimizu 890ddd
		f.setFamily("Calibri");
Toshihiro Shimizu 890ddd
		p.setFont(f);
Toshihiro Shimizu 890ddd
		if (style->getFlags() != 0) {
Toshihiro Shimizu 890ddd
			QRect rect(nameRect.left(), y0, w, h);
Toshihiro Shimizu 890ddd
			p.fillRect(rect, QBrush(Qt::white));
Toshihiro Shimizu 890ddd
			p.drawRect(rect);
Toshihiro Shimizu 890ddd
			p.drawText(rect.adjusted(0, +1, 0, +1), Qt::AlignCenter, "A");
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		TTextureStyle *ts = dynamic_cast<ttexturestyle *="">(style);</ttexturestyle>
Toshihiro Shimizu 890ddd
		if (ts) {
Toshihiro Shimizu 890ddd
			QRect rect(nameRect.left() + ((style->getFlags() != 0) ? w : 0), y0, w, h);
Toshihiro Shimizu 890ddd
			p.fillRect(rect, QBrush(Qt::white));
Toshihiro Shimizu 890ddd
			p.drawRect(rect);
Toshihiro Shimizu 890ddd
			p.drawText(rect.adjusted(0, +1, 0, +1), Qt::AlignCenter, ts->isPattern() ? "P" : "T");
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	p.drawRect(nameRect);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Draw the toggle to know if \b style is linked to a studio palette.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect, TColorStyle *style)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::wstring globalName = style->getGlobalName();
Toshihiro Shimizu 890ddd
	if (globalName != L"" &&
Toshihiro Shimizu 890ddd
		(globalName[0] == L'-' || globalName[0] == L'+')) {
Toshihiro Shimizu 890ddd
		TPixel32 c = style->getMainColor();
Toshihiro Shimizu 890ddd
		int x = chipRect.topRight().x() - 6;
Toshihiro Shimizu 890ddd
		int y = chipRect.topRight().y();
Toshihiro Shimizu 890ddd
		QRect rect(x, y, 7, 7);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		p.fillRect(rect, QBrush(Qt::white));
Toshihiro Shimizu 890ddd
		p.setPen(Qt::black);
Toshihiro Shimizu 890ddd
		p.drawRect(rect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (globalName[0] == L'+') {
Toshihiro Shimizu 890ddd
			QPointF a(x + 2, y + 2);
Toshihiro Shimizu 890ddd
			QPointF b(x + 2, y + 5);
Toshihiro Shimizu 890ddd
			QPointF c(x + 5, y + 2);
Toshihiro Shimizu 890ddd
			QPointF d(x + 5, y + 5);
Toshihiro Shimizu 890ddd
			p.drawLine(a, b);
Toshihiro Shimizu 890ddd
			p.drawLine(a, c);
Toshihiro Shimizu 890ddd
			p.drawLine(a, d);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Pain current page styles using current view mode.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::paintEvent(QPaintEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPainter p(this);
Toshihiro Shimizu 890ddd
	if (m_chipPerRow == 0) {
Toshihiro Shimizu 890ddd
		p.drawText(QPoint(5, 25), tr("- No Styles -"));
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// currentStyle e palette
Toshihiro Shimizu 890ddd
	TPalette *palette = (m_page) ? m_page->getPalette() : 0;
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// [i0,i1] = range celle visibili
Toshihiro Shimizu 890ddd
	QRect visibleRect = e->rect();
Toshihiro Shimizu 890ddd
	int i0 = posToIndex(visibleRect.topLeft());
Toshihiro Shimizu 890ddd
	if (i0 < 0)
Toshihiro Shimizu 890ddd
		i0 = 0;
Toshihiro Shimizu 890ddd
	int i1 = posToIndex(visibleRect.bottomRight());
Toshihiro Shimizu 890ddd
	if (i1 >= getChipCount())
Toshihiro Shimizu 890ddd
		i1 = getChipCount() - 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_viewMode == List) {
Toshihiro Shimizu 890ddd
		// disegno le celle
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		int currentStyleIndexInPage = -1;
Toshihiro Shimizu 890ddd
		for (i = i0; i <= i1; i++) {
Toshihiro Shimizu 890ddd
			TColorStyle *style = m_page->getStyle(i);
Toshihiro Shimizu 890ddd
			int styleIndex = m_page->getStyleId(i);
Toshihiro Shimizu 890ddd
			if (getCurrentStyleIndex() == styleIndex)
Toshihiro Shimizu 890ddd
				currentStyleIndexInPage = i;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			QRect chipRect = getColorChipRect(i);
Toshihiro Shimizu 890ddd
			drawColorChip(p, chipRect, style);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// name, index and shortcut
Toshihiro Shimizu 890ddd
			QRect nameRect = getColorNameRect(i);
Toshihiro Shimizu 890ddd
			drawColorName(p, nameRect, style, styleIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// selezione
Toshihiro Shimizu 890ddd
			if (m_styleSelection->isSelected(m_page->getIndex(), i)) {
Toshihiro Shimizu 890ddd
				p.setPen(Qt::white);
Toshihiro Shimizu 890ddd
				QRect itemRect = getItemRect(i);
Toshihiro Shimizu 890ddd
				p.drawRect(itemRect);
Toshihiro Shimizu 890ddd
				p.drawRect(chipRect.adjusted(1, 1, -1, -1));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			// stile corrente
Toshihiro Shimizu 890ddd
			if (i == currentStyleIndexInPage && 0 <= i && i < getChipCount()) {
Toshihiro Shimizu 890ddd
				QRect rect = getItemRect(i);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				p.setPen(QColor(180, 210, 255));
Toshihiro Shimizu 890ddd
				p.drawRect(rect.adjusted(1, 1, -1, -1));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				p.setPen(Qt::white);
Toshihiro Shimizu 890ddd
				p.drawRect(rect.adjusted(2, 2, -2, -2));
Toshihiro Shimizu 890ddd
				p.setPen(Qt::black);
Toshihiro Shimizu 890ddd
				p.drawRect(rect.adjusted(3, 3, -3, -3));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if (!m_styleSelection->isSelected(m_page->getIndex(), i)) {
Toshihiro Shimizu 890ddd
					p.setPen(QColor(225, 225, 225));
Toshihiro Shimizu 890ddd
					p.drawRect(rect.adjusted(1, 1, -1, -1));
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// toggle link
Toshihiro Shimizu 890ddd
			drawToggleLink(p, chipRect, m_page->getStyle(i));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		int currentStyleIndex = getCurrentStyleIndex();
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = i0; i <= i1; i++) {
Toshihiro Shimizu 890ddd
			TColorStyle *style = m_page->getStyle(i);
Toshihiro Shimizu 890ddd
			int styleIndex = m_page->getStyleId(i);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//draw white frame if the style is selected or current
Toshihiro Shimizu 890ddd
			if (m_styleSelection->isSelected(m_page->getIndex(), i) || currentStyleIndex == styleIndex) {
Toshihiro Shimizu 890ddd
				QRect itemRect = getItemRect(i).adjusted(-1, -2, 1, 2);
Toshihiro Shimizu 890ddd
				p.setPen(Qt::NoPen);
Toshihiro Shimizu 890ddd
				p.setBrush(Qt::white);
Toshihiro Shimizu 890ddd
				p.drawRoundRect(itemRect, 7, 25);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			//paint style
Toshihiro Shimizu 890ddd
			QRect chipRect = getItemRect(i).adjusted(4, 4, -5, -5);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			QColor styleColor((int)style->getMainColor().r,
Toshihiro Shimizu 890ddd
							  (int)style->getMainColor().g,
Toshihiro Shimizu 890ddd
							  (int)style->getMainColor().b);
Toshihiro Shimizu 890ddd
			// draw with MainColor for TSolidColorStyle(3), TColorCleanupStyle(2001) and TBlackCleanupStyle(2002)
Toshihiro Shimizu 890ddd
			if (style->getTagId() == 3 || style->getTagId() == 2001 || style->getTagId() == 2002) {
Toshihiro Shimizu 890ddd
				//iwsw commented out temporaly
Toshihiro Shimizu 890ddd
				//if (Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
Toshihiro Shimizu 890ddd
				//	Ghibli3DLutConverter::instance()->convert(styleColor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				p.fillRect(chipRect, QBrush(styleColor));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				// if the style is not 100% opac, draw the bottom part of the chip with the pixmap with alpha
Toshihiro Shimizu 890ddd
				if ((int)style->getMainColor().m != (int)style->getMainColor().maxChannelValue) {
Toshihiro Shimizu 890ddd
					QRect bottomRect = chipRect;
Toshihiro Shimizu 890ddd
					if (m_viewMode == LargeChips) {
Toshihiro Shimizu 890ddd
						bottomRect.adjust(0, bottomRect.height() - 12, 0, 0);
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						bottomRect.adjust(0, bottomRect.height() - 6, 0, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
					TRaster32P icon = style->getIcon(qsize2Dimension(bottomRect.size()));
Toshihiro Shimizu 890ddd
					p.drawPixmap(bottomRect.left(), bottomRect.top(), rasterToQPixmap(icon));
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				//Use white line for dark color. Use black line for light color.
Toshihiro Shimizu 890ddd
				int val = (int)style->getMainColor().r * 30 +
Toshihiro Shimizu 890ddd
						  (int)style->getMainColor().g * 59 +
Toshihiro Shimizu 890ddd
						  (int)style->getMainColor().b * 11;
Toshihiro Shimizu 890ddd
				if (val < 12800)
Toshihiro Shimizu 890ddd
					p.setPen(Qt::white);
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					p.setPen(Qt::black);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				TRaster32P icon = style->getIcon(qsize2Dimension(chipRect.size()));
Toshihiro Shimizu 890ddd
				p.drawPixmap(chipRect.left(), chipRect.top(), rasterToQPixmap(icon));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if (m_viewMode == LargeChips) {
Toshihiro Shimizu 890ddd
					p.setPen(Qt::NoPen);
Toshihiro Shimizu 890ddd
					p.setBrush(QColor(0, 0, 0, 140));
Toshihiro Shimizu 890ddd
					QRect zabutonRect = chipRect.adjusted(0, 12, 0, -12);
Toshihiro Shimizu 890ddd
					p.drawRect(zabutonRect);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				p.setPen(Qt::white);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			p.setBrush(Qt::NoBrush);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//diagonal line indicates that the style color is changed after linked from studio palette
Toshihiro Shimizu 890ddd
			if (style->getIsEditedFlag()) {
Toshihiro Shimizu 890ddd
				//draw diagonal line
Toshihiro Shimizu 890ddd
				p.drawLine(chipRect.topRight(), chipRect.bottomLeft());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				//keep center blank for style name
Toshihiro Shimizu 890ddd
				if (m_viewMode != SmallChips) {
Toshihiro Shimizu 890ddd
					QRect colorNameRect = chipRect;
Toshihiro Shimizu 890ddd
					if (m_viewMode == MediumChips)
Toshihiro Shimizu 890ddd
						colorNameRect.adjust(2, 9, -2, -8);
Toshihiro Shimizu 890ddd
					else //LargeChip
Toshihiro Shimizu 890ddd
						colorNameRect.adjust(2, 16, -2, -13);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
					p.fillRect(colorNameRect, QBrush(styleColor));
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//draw style name
Toshihiro Shimizu 890ddd
			QFont preFont = p.font();
Toshihiro Shimizu 890ddd
			QFont tmpFont = p.font();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (m_viewMode != SmallChips) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if (m_viewMode == MediumChips) {
Toshihiro Shimizu 890ddd
					tmpFont.setPixelSize(EnvSoftwareCurrentFontSize_StyleName);
Toshihiro Shimizu 890ddd
					p.setFont(tmpFont);
Toshihiro Shimizu 890ddd
				} else if (m_viewMode == LargeChips) {
Toshihiro Shimizu 890ddd
					tmpFont.setPixelSize(EnvSoftwareCurrentFontSize_StyleName + 2);
Toshihiro Shimizu 890ddd
					p.setFont(tmpFont);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
				std::wstring name = style->getName();
Shinya Kitaoka 3bfa54
				std::wstring origName = style->getOriginalName();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				//display the name (style name and original name) according to the name display mode
Toshihiro Shimizu 890ddd
				if (m_nameDisplayMode == Style)
Toshihiro Shimizu 890ddd
					p.drawText(chipRect, Qt::AlignCenter, QString::fromStdWString(name));
Toshihiro Shimizu 890ddd
				else if (m_nameDisplayMode == Original) {
Toshihiro Shimizu 890ddd
					if (origName != L"") {
Toshihiro Shimizu 890ddd
						tmpFont.setItalic(true);
Toshihiro Shimizu 890ddd
						p.setFont(tmpFont);
Toshihiro Shimizu 890ddd
						p.drawText(chipRect, Qt::AlignCenter, QString::fromStdWString(origName));
Toshihiro Shimizu 890ddd
					} else // if there is no original name, then display the style name in brackets
Toshihiro Shimizu 890ddd
						p.drawText(chipRect, Qt::AlignCenter, QString::fromStdWString(L"( " + name + L" )"));
Toshihiro Shimizu 890ddd
				} else if (m_nameDisplayMode == StyleAndOriginal) {
Toshihiro Shimizu 890ddd
					p.drawText(chipRect, Qt::AlignCenter, QString::fromStdWString(name));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
					//display original name only whne LargeChip view
Toshihiro Shimizu 890ddd
					if (m_viewMode == LargeChips && origName != L"") {
Toshihiro Shimizu 890ddd
						tmpFont.setItalic(true);
Toshihiro Shimizu 890ddd
						tmpFont.setPixelSize(tmpFont.pixelSize() - 3);
Toshihiro Shimizu 890ddd
						p.setFont(tmpFont);
Toshihiro Shimizu 890ddd
						p.drawText(chipRect.adjusted(4, 4, -4, -4), Qt::AlignLeft | Qt::AlignTop, QString::fromStdWString(origName));
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// draw the frame border if the style is selected or current
Toshihiro Shimizu 890ddd
			if (m_styleSelection->isSelected(m_page->getIndex(), i) || currentStyleIndex == styleIndex) {
Toshihiro Shimizu 890ddd
				p.setBrush(Qt::NoBrush);
Toshihiro Shimizu 890ddd
				p.drawRect(chipRect.adjusted(3, 3, -3, -3));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// draw border
Toshihiro Shimizu 890ddd
			p.setPen(Qt::black);
Toshihiro Shimizu 890ddd
			p.setBrush(Qt::NoBrush);
Toshihiro Shimizu 890ddd
			p.drawRect(chipRect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// draw style index
Toshihiro Shimizu 890ddd
			tmpFont.setPointSize(9);
Toshihiro Shimizu 890ddd
			tmpFont.setItalic(false);
Toshihiro Shimizu 890ddd
			p.setFont(tmpFont);
Toshihiro Shimizu 890ddd
			int indexWidth = fontMetrics().width(QString().setNum(styleIndex)) + 4;
Toshihiro Shimizu 890ddd
			QRect indexRect(chipRect.bottomRight() + QPoint(-indexWidth, -14), chipRect.bottomRight());
Toshihiro Shimizu 890ddd
			p.setPen(Qt::black);
Toshihiro Shimizu 890ddd
			p.setBrush(Qt::white);
Toshihiro Shimizu 890ddd
			p.drawRect(indexRect);
Toshihiro Shimizu 890ddd
			p.drawText(indexRect, Qt::AlignCenter, QString().setNum(styleIndex));
Toshihiro Shimizu 890ddd
			// revert font set
Toshihiro Shimizu 890ddd
			p.setFont(preFont);
Toshihiro Shimizu 890ddd
			// revert brush
Toshihiro Shimizu 890ddd
			p.setBrush(Qt::NoBrush);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//draw link indicator
Toshihiro Shimizu 890ddd
			drawToggleLink(p, chipRect, style);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// indicatore di drop
Toshihiro Shimizu 890ddd
	if (m_dropPositionIndex >= 0) {
Toshihiro Shimizu 890ddd
		QRect itemRect = getItemRect(m_dropPositionIndex);
Toshihiro Shimizu 890ddd
		QRect rect;
Toshihiro Shimizu 890ddd
		if (m_viewMode == List)
Toshihiro Shimizu 890ddd
			rect = QRect(itemRect.left(), itemRect.top() - 1, itemRect.width(), 2);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			rect = QRect(itemRect.left() - 1, itemRect.top(), 2, itemRect.height());
Toshihiro Shimizu 890ddd
		p.setPen(Qt::black);
Toshihiro Shimizu 890ddd
		p.drawRect(rect);
Toshihiro Shimizu 890ddd
		p.setPen(Qt::white);
Toshihiro Shimizu 890ddd
		p.drawRect(rect.adjusted(-1, -1, 1, 1));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Recall computeSize().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::resizeEvent(QResizeEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	computeSize();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current page is empty return; otherwise select or unselect chip in regard
Toshihiro Shimizu 890ddd
		to event position.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PageViewer::mousePressEvent(QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette *palette = m_page->getPalette();
Toshihiro Shimizu 890ddd
	QPoint pos = event->pos();
Toshihiro Shimizu 890ddd
	int indexInPage = posToIndex(pos);
Toshihiro Shimizu 890ddd
	m_startDrag = false;
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int pageIndex = m_page->getIndex();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// disable style selection in the cleanup palette in order to avoid editing the styles by mistake.
Toshihiro Shimizu 890ddd
	if (m_viewType == CLEANUP_PALETTE) {
Toshihiro Shimizu 890ddd
		if (0 <= indexInPage && indexInPage < getChipCount()) {
Toshihiro Shimizu 890ddd
			//Right-click is available
Toshihiro Shimizu 890ddd
			if (event->button() == Qt::RightButton) {
Toshihiro Shimizu 890ddd
				m_styleSelection->makeCurrent();
Toshihiro Shimizu 890ddd
				m_styleSelection->selectNone();
Toshihiro Shimizu 890ddd
				m_styleSelection->select(pageIndex);
Toshihiro Shimizu 890ddd
				m_styleSelection->select(pageIndex, indexInPage, true);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			//Changing the current style is still available
Toshihiro Shimizu 890ddd
			setCurrentStyleIndex(m_page->getStyleId(indexInPage));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (event->button() == Qt::RightButton) {
Toshihiro Shimizu 890ddd
		m_styleSelection->makeCurrent();
Toshihiro Shimizu 890ddd
		//if you are clicking on the color chip
Toshihiro Shimizu 890ddd
		if (0 <= indexInPage && indexInPage < getChipCount()) {
Toshihiro Shimizu 890ddd
			//Se pageIndex non e' selezionato lo seleziono
Toshihiro Shimizu 890ddd
			if (!m_styleSelection->isSelected(pageIndex, indexInPage)) {
Toshihiro Shimizu 890ddd
				m_styleSelection->select(pageIndex);
Toshihiro Shimizu 890ddd
				m_styleSelection->select(pageIndex, indexInPage, true);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			//Cambio l'indice corrente
Toshihiro Shimizu 890ddd
			setCurrentStyleIndex(m_page->getStyleId(indexInPage));
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			m_styleSelection->selectNone();
Toshihiro Shimizu 890ddd
			m_styleSelection->select(pageIndex);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
		//update locks when the styleSelection becomes current
Toshihiro Shimizu 890ddd
		updateCommandLocks();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_dragStartPosition = pos;
Toshihiro Shimizu 890ddd
	if (indexInPage < 0 || indexInPage >= getChipCount()) {
Toshihiro Shimizu 890ddd
		// l'utente ha fatto click fuori dai color chip. vuole deselezionare tutto
Toshihiro Shimizu 890ddd
		// (lasciando la selezione attiva, per un eventuale paste)
Toshihiro Shimizu 890ddd
		m_styleSelection->select(pageIndex);
Toshihiro Shimizu 890ddd
		m_styleSelection->makeCurrent();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
		//update locks when the styleSelection becomes current
Toshihiro Shimizu 890ddd
		updateCommandLocks();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		//O si sta selezonando un nuovo item O si vuole iniziare un drag
Toshihiro Shimizu 890ddd
		if (m_styleSelection->isSelected(pageIndex, indexInPage) &&
Toshihiro Shimizu 890ddd
			event->modifiers() == Qt::ControlModifier &&
Toshihiro Shimizu 890ddd
			!m_page->getPalette()->isLocked())
Toshihiro Shimizu 890ddd
			m_startDrag = true;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			select(indexInPage, event);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If left botton is pressed start drag.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::mouseMoveEvent(QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (m_viewType == CLEANUP_PALETTE)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// continuo solo se e' un drag (bottone sinistro premuto)
Toshihiro Shimizu 890ddd
	if (!(event->buttons() & Qt::LeftButton))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_page->getPalette()->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Se spingo ctrl mentre mi sto muovendo con almeno un item selezionato abilito la possibilita' di fare drag.
Toshihiro Shimizu 890ddd
	if (!m_startDrag &&
Toshihiro Shimizu 890ddd
		event->modifiers() == Qt::ControlModifier &&
Toshihiro Shimizu 890ddd
		!m_styleSelection->isEmpty() &&
Toshihiro Shimizu 890ddd
		(event->pos() - m_dragStartPosition).manhattanLength() > 12)
Toshihiro Shimizu 890ddd
		m_startDrag = true;
Toshihiro Shimizu 890ddd
	// faccio partire il drag&drop solo se mi sono mosso di una certa quantita'
Toshihiro Shimizu 890ddd
	if ((event->pos() - m_dragStartPosition).manhattanLength() > 20 && m_startDrag) {
Toshihiro Shimizu 890ddd
		assert(m_styleSelection && !m_styleSelection->isEmpty());
Toshihiro Shimizu 890ddd
		startDragDrop();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::mouseReleaseEvent(QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TPalette *palette = m_page->getPalette();
Toshihiro Shimizu 890ddd
	QPoint pos = event->pos();
Toshihiro Shimizu 890ddd
	int indexInPage = posToIndex(pos);
Toshihiro Shimizu 890ddd
	if (m_startDrag && m_dropPositionIndex == -1 && event->modifiers() == Qt::ControlModifier)
Toshihiro Shimizu 890ddd
		select(indexInPage, event);
Toshihiro Shimizu 890ddd
	m_startDrag = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If double click position is not in a chip rect return; otherwise if is in
Toshihiro Shimizu 890ddd
		name rect open a text field, if is in color rect open a style editor.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PageViewer::mouseDoubleClickEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int index = posToIndex(e->pos());
Toshihiro Shimizu 890ddd
	if (index < 0 || index >= getChipCount())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TColorStyle *style = m_page->getStyle(index);
Toshihiro Shimizu 890ddd
	if (!style)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_page->getPalette()->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_viewMode != SmallChips) {
Toshihiro Shimizu 890ddd
		QRect nameRect = getColorNameRect(index);
Toshihiro Shimizu 890ddd
		if (nameRect.contains(e->pos())) {
Shinya Kitaoka 3bfa54
			std::wstring styleName = style->getName();
Toshihiro Shimizu 890ddd
			LineEdit *fld = m_renameTextField;
Toshihiro Shimizu 890ddd
			fld->setText(QString::fromStdWString(styleName));
Toshihiro Shimizu 890ddd
			fld->setGeometry(nameRect);
Toshihiro Shimizu 890ddd
			fld->show();
Toshihiro Shimizu 890ddd
			fld->selectAll();
Toshihiro Shimizu 890ddd
			fld->setFocus(Qt::OtherFocusReason);
Toshihiro Shimizu 890ddd
			fld->setAlignment(Qt::AlignCenter);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_styleNameEditor->show();
Toshihiro Shimizu 890ddd
	m_styleNameEditor->raise();
Toshihiro Shimizu 890ddd
	m_styleNameEditor->activateWindow();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
void PageViewer::createMenuAction(QMenu &menu, const char *id, QString name, const char *slot)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret = true;
Toshihiro Shimizu 890ddd
	QAction *act = menu.addAction(name);
Shinya Kitaoka 3bfa54
	std::string slotName(slot);
Shinya Kitaoka 3bfa54
	slotName = std::string("1") + slotName;
Toshihiro Shimizu 890ddd
	ret = connect(act, SIGNAL(triggered()), slotName.c_str());
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::addNewColor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	PaletteCmd::createStyle(getPaletteHandle(), getPage());
Toshihiro Shimizu 890ddd
	computeSize();
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::addNewPage()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	PaletteCmd::addPage(getPaletteHandle());
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! Create and open the Right-click menu in page.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::contextMenuEvent(QContextMenuEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QMenu menu(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	CommandManager *cmd = CommandManager::instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	menu.addAction(cmd->getAction(MI_Copy));
Toshihiro Shimizu 890ddd
	QAction *pasteValueAct = cmd->getAction(MI_PasteValues);
Toshihiro Shimizu 890ddd
	menu.addAction(pasteValueAct);
Toshihiro Shimizu 890ddd
	QAction *pasteColorsAct = cmd->getAction(MI_PasteColors);
Toshihiro Shimizu 890ddd
	menu.addAction(pasteColorsAct);
Toshihiro Shimizu 890ddd
	QAction *pasteNamesAct = cmd->getAction(MI_PasteNames);
Toshihiro Shimizu 890ddd
	menu.addAction(pasteNamesAct);
Toshihiro Shimizu 890ddd
	QAction *pasteAct = cmd->getAction(MI_Paste);
Toshihiro Shimizu 890ddd
	menu.addAction(pasteAct);
Toshihiro Shimizu 890ddd
	QAction *cutAct = cmd->getAction(MI_Cut);
Toshihiro Shimizu 890ddd
	menu.addAction(cutAct);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	menu.addSeparator();
Toshihiro Shimizu 890ddd
	QAction *clearAct = cmd->getAction(MI_Clear);
Toshihiro Shimizu 890ddd
	menu.addAction(clearAct);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	menu.addSeparator();
Toshihiro Shimizu 890ddd
	QAction *openPltGizmoAct = cmd->getAction("MI_OpenPltGizmo");
Toshihiro Shimizu 890ddd
	menu.addAction(openPltGizmoAct);
Toshihiro Shimizu 890ddd
	QAction *openStyleControlAct = cmd->getAction("MI_OpenStyleControl");
Toshihiro Shimizu 890ddd
	menu.addAction(openStyleControlAct);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Verifica se lo stile e' link.
Toshihiro Shimizu 890ddd
	//Abilita e disabilita le voci di menu' in base a dove si e' cliccato.
Toshihiro Shimizu 890ddd
	int index = posToIndex(event->pos());
Toshihiro Shimizu 890ddd
	int indexPage = m_page ? m_page->getIndex() : -1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isLocked = m_page ? m_page->getPalette()->isLocked() : false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//remove links from studio palette
Toshihiro Shimizu 890ddd
	if (m_viewType == LEVEL_PALETTE && m_styleSelection && !m_styleSelection->isEmpty() && !isLocked) {
Toshihiro Shimizu 890ddd
		menu.addSeparator();
Toshihiro Shimizu 890ddd
		QAction *removeLinkAct = menu.addAction(tr("Remove Links"));
Toshihiro Shimizu 890ddd
		connect(removeLinkAct, SIGNAL(triggered()), this, SLOT(removeLink()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (((indexPage == 0 && index > 0) || (indexPage > 0 && index >= 0)) && index < getChipCount() && !isLocked) {
Toshihiro Shimizu 890ddd
		//iwsw commented out temporarly
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
		wstring globalName = m_page->getStyle(index)->getGlobalName();
Toshihiro Shimizu 890ddd
		if (m_viewType != STUDIO_PALETTE &&
Toshihiro Shimizu 890ddd
			globalName != L"" &&
Toshihiro Shimizu 890ddd
			(globalName[0] == L'-' || globalName[0] == L'+'))
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			createMenuAction(menu, "MI_ToggleLinkToStudioPalette", tr("Toggle Link to Studio Palette"), "toggleLink()");
Toshihiro Shimizu 890ddd
			createMenuAction(menu, "MI_RemoveReferenceToStudioPalette", tr("Remove Reference to Studio Palette"), "eraseToggleLink()");
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
		if (pasteValueAct)
Toshihiro Shimizu 890ddd
			pasteValueAct->setEnabled(true);
Toshihiro Shimizu 890ddd
		if (pasteColorsAct)
Toshihiro Shimizu 890ddd
			pasteColorsAct->setEnabled(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		pasteNamesAct->setEnabled(true);
Toshihiro Shimizu 890ddd
		pasteAct->setEnabled(true);
Toshihiro Shimizu 890ddd
		cutAct->setEnabled(true);
Toshihiro Shimizu 890ddd
		clearAct->setEnabled(true);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (pasteValueAct)
Toshihiro Shimizu 890ddd
			pasteValueAct->setEnabled(false);
Toshihiro Shimizu 890ddd
		if (pasteColorsAct)
Toshihiro Shimizu 890ddd
			pasteColorsAct->setEnabled(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		pasteNamesAct->setEnabled(false);
Toshihiro Shimizu 890ddd
		pasteAct->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
		cutAct->setEnabled(false);
Toshihiro Shimizu 890ddd
		clearAct->setEnabled(false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// get color from the original studio palette
Toshihiro Shimizu 890ddd
	if (m_viewType == LEVEL_PALETTE && m_styleSelection && !m_styleSelection->isEmpty() && !isLocked) {
Toshihiro Shimizu 890ddd
		menu.addSeparator();
Toshihiro Shimizu 890ddd
		QAction *getBackOriginalAct = cmd->getAction("MI_GetColorFromStudioPalette");
Toshihiro Shimizu 890ddd
		menu.addAction(getBackOriginalAct);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//iwsw commented out temporarly
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
	if (m_viewType != STUDIO_PALETTE)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		menu.addSeparator();
Toshihiro Shimizu 890ddd
		menu.addAction(cmd->getAction(MI_EraseUnusedStyles));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	*/
shun_iwasawa 01874c
	if (m_page)
shun_iwasawa 01874c
	{
shun_iwasawa 01874c
		QAction *newStyle = menu.addAction(tr("New Style"));
shun_iwasawa 01874c
		connect(newStyle, SIGNAL(triggered()), SLOT(addNewColor()));
shun_iwasawa 01874c
		QAction *newPage = menu.addAction(tr("New Page"));
shun_iwasawa 01874c
		connect(newPage, SIGNAL(triggered()), SLOT(addNewPage()));
shun_iwasawa 01874c
	}
Toshihiro Shimizu 890ddd
	menu.exec(event->globalPos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Accept drag enter event if evant data ha format \b TStyleSelection::getMimeType().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::dragEnterEvent(QDragEnterEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(event->mimeData());</const>
Toshihiro Shimizu 890ddd
	if (paletteData && paletteData->hasStyleIndeces()) {
Toshihiro Shimizu 890ddd
		if ((m_viewType == CLEANUP_PALETTE && !paletteData->getPalette()->isCleanupPalette()) ||
Toshihiro Shimizu 890ddd
			(m_viewType == LEVEL_PALETTE && paletteData->getPalette()->isCleanupPalette())) {
Toshihiro Shimizu 890ddd
			event->ignore();
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		int index = posToIndex(event->pos());
Toshihiro Shimizu 890ddd
		// non si puo' spostare qualcosa nelle prime due posizioni di pagina 0
Toshihiro Shimizu 890ddd
		// (occupate da BG e FG)
Toshihiro Shimizu 890ddd
		if (m_page->getIndex() == 0 && index < 2)
Toshihiro Shimizu 890ddd
			index = 2;
Toshihiro Shimizu 890ddd
		if (index < 0)
Toshihiro Shimizu 890ddd
			index = 0;
Toshihiro Shimizu 890ddd
		else if (index > m_page->getStyleCount())
Toshihiro Shimizu 890ddd
			index = m_page->getStyleCount();
Toshihiro Shimizu 890ddd
		m_dropPositionIndex = index;
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
		event->acceptProposedAction();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current page exist and index in event position is different from dropped
Toshihiro Shimizu 890ddd
		index set right drop position index and accept event.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PageViewer::dragMoveEvent(QDragMoveEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int index = posToIndex(event->pos());
Toshihiro Shimizu 890ddd
	if (index != m_dropPositionIndex) {
Toshihiro Shimizu 890ddd
		if ((m_page->getStyleId(0) == 0 || m_page->getStyleId(1) == 1) && index < 2)
Toshihiro Shimizu 890ddd
			index = 2;
Toshihiro Shimizu 890ddd
		if (index < 0)
Toshihiro Shimizu 890ddd
			index = 0;
Toshihiro Shimizu 890ddd
		else if (index > m_page->getStyleCount())
Toshihiro Shimizu 890ddd
			index = m_page->getStyleCount();
Toshihiro Shimizu 890ddd
		m_dropPositionIndex = index;
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
		event->acceptProposedAction();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If event data has correct format drop it in current drop position index.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::dropEvent(QDropEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int dstIndexInPage = m_dropPositionIndex;
Toshihiro Shimizu 890ddd
	m_dropPositionIndex = -1;
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
	if (!dynamic_cast<const *="" palettedata="">(event->mimeData()))</const>
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	drop(dstIndexInPage, event->mimeData());
Toshihiro Shimizu 890ddd
	event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to -1 drag position index and update view.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::dragLeaveEvent(QDragLeaveEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_dropPositionIndex = -1;
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Start drag and drop; if current page exist set drag and drop event data.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::startDragDrop()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRepetitionGuard guard;
Toshihiro Shimizu 890ddd
	if (!guard.hasLock())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(m_page);
Toshihiro Shimizu 890ddd
	TPalette *palette = m_page->getPalette();
Toshihiro Shimizu 890ddd
	if (!palette || !m_page || !m_styleSelection)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int pageIndex = m_page->getIndex();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_styleSelection->canHandleStyles())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	PaletteData *paletteData = new PaletteData();
Toshihiro Shimizu 890ddd
	paletteData->setPaletteData(palette, pageIndex, m_styleSelection->getIndicesInPage());
Toshihiro Shimizu 890ddd
	QDrag *drag = new QDrag(this);
Toshihiro Shimizu 890ddd
	drag->setMimeData(paletteData);
Toshihiro Shimizu 890ddd
	Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
Toshihiro Shimizu 890ddd
	if (m_dropPageCreated) {
Toshihiro Shimizu 890ddd
		m_dropPageCreated = false;
Toshihiro Shimizu 890ddd
		int pageIndex = palette->getPageCount() - 1;
Toshihiro Shimizu 890ddd
		if (palette->getPage(pageIndex)->getStyleCount() == 0) {
Toshihiro Shimizu 890ddd
			palette->erasePage(pageIndex);
Toshihiro Shimizu 890ddd
			getPaletteHandle()->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::keyPressEvent(QKeyEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int key = e->key();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (key == Qt::Key_Up) { //Row = frame precedente a quello settato
Toshihiro Shimizu 890ddd
		int frameIndex = m_frameHandle->getFrameIndex() - 1;
Toshihiro Shimizu 890ddd
		if (frameIndex < 0)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_frameHandle->setFrameIndex(frameIndex);
Toshihiro Shimizu 890ddd
	} else if (key == Qt::Key_Down) { //Row = frame successivo a quello settato
Toshihiro Shimizu 890ddd
		int frameIndex = m_frameHandle->getFrameIndex() + 1;
Toshihiro Shimizu 890ddd
		m_frameHandle->setFrameIndex(frameIndex);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		CommandManager *cManager = CommandManager::instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (key == cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomIn)))
Toshihiro Shimizu 890ddd
			zoomInChip();
Toshihiro Shimizu 890ddd
		else if (key == cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomOut)))
Toshihiro Shimizu 890ddd
			zoomOutChip();
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			e->ignore();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::showEvent(QShowEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *paletteHandle = getPaletteHandle();
Toshihiro Shimizu 890ddd
	if (!paletteHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	connect(paletteHandle, SIGNAL(colorStyleChanged()), SLOT(update()), Qt::UniqueConnection);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::hideEvent(QHideEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *paletteHandle = getPaletteHandle();
Toshihiro Shimizu 890ddd
	if (!paletteHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	disconnect(paletteHandle, SIGNAL(colorStyleChanged()), this, SLOT(update()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Manage page tooltip.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
bool PageViewer::event(QEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_page && e->type() == QEvent::ToolTip) {
Toshihiro Shimizu 890ddd
		QHelpEvent *helpEvent = dynamic_cast<qhelpevent *="">(e);</qhelpevent>
Toshihiro Shimizu 890ddd
		QString toolTip;
Toshihiro Shimizu 890ddd
		QPoint pos = helpEvent->pos();
Toshihiro Shimizu 890ddd
		int indexInPage = posToIndex(pos);
Toshihiro Shimizu 890ddd
		if (0 <= indexInPage && indexInPage < m_page->getStyleCount()) {
Toshihiro Shimizu 890ddd
			TColorStyle *style = m_page->getStyle(indexInPage);
Toshihiro Shimizu 890ddd
			if (style) {
Toshihiro Shimizu 890ddd
				int styleIndex = m_page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
				toolTip = "#" + QString::number(styleIndex) + " " + QString::fromStdWString(style->getName());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				int shortcutKey = m_page->getPalette()->getStyleShortcut(styleIndex);
Toshihiro Shimizu 890ddd
				if (shortcutKey > 0)
Shinya Kitaoka 3bfa54
					toolTip += QString::fromStdWString(std::wstring(L" (") + (wchar_t)shortcutKey + L")");
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (toolTip != "")
Toshihiro Shimizu 890ddd
			QToolTip::showText(helpEvent->globalPos(), toolTip);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			QToolTip::hideText();
Toshihiro Shimizu 890ddd
		e->accept();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return QFrame::event(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add chip identified by \b indexInPage to style selection if it was not
Toshihiro Shimizu 890ddd
		selected; remove it from style selection otherwise. Manage CTRL SHIFT
Toshihiro Shimizu 890ddd
		pressed case.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PageViewer::select(int indexInPage, QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool selected = false;
Toshihiro Shimizu 890ddd
	assert(m_page);
Toshihiro Shimizu 890ddd
	TPalette *palette = m_page->getPalette();
Toshihiro Shimizu 890ddd
	int pageIndex = m_page->getIndex();
Toshihiro Shimizu 890ddd
	bool on = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool wasSelected = m_styleSelection->isSelected(pageIndex, indexInPage);
Toshihiro Shimizu 890ddd
	if (event->modifiers() == Qt::NoModifier)
Toshihiro Shimizu 890ddd
		m_styleSelection->selectNone();
Toshihiro Shimizu 890ddd
	else if (event->modifiers() == Qt::CTRL && wasSelected)
Toshihiro Shimizu 890ddd
		on = false;
Toshihiro Shimizu 890ddd
	else if (event->modifiers() == Qt::SHIFT && !m_styleSelection->isEmpty()) {
Toshihiro Shimizu 890ddd
		// premuto shift. la selezione si estende fino ai piu' vicini colori selezionati (prima e dopo)
Toshihiro Shimizu 890ddd
		// a e' b diventeranno gli estremi della selezione
Toshihiro Shimizu 890ddd
		int a = -1, b = -1, i = 0;
Toshihiro Shimizu 890ddd
		for (i = 0; i < m_page->getStyleCount(); i++)
Toshihiro Shimizu 890ddd
			if (m_styleSelection->isSelected(pageIndex, i)) {
Toshihiro Shimizu 890ddd
				if (i < indexInPage)
Toshihiro Shimizu 890ddd
					a = i;
Toshihiro Shimizu 890ddd
				else if (i > indexInPage) {
Toshihiro Shimizu 890ddd
					b = i;
Toshihiro Shimizu 890ddd
					break;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		if (a >= 0 && b >= 0) {
Toshihiro Shimizu 890ddd
			assert(a < indexInPage && indexInPage < b);
Toshihiro Shimizu 890ddd
			a++;
Toshihiro Shimizu 890ddd
			b--;
Toshihiro Shimizu 890ddd
		} else if (a >= 0) {
Toshihiro Shimizu 890ddd
			assert(b < 0 && a < indexInPage);
Toshihiro Shimizu 890ddd
			a++;
Toshihiro Shimizu 890ddd
			b = indexInPage;
Toshihiro Shimizu 890ddd
		} else if (b >= 0) {
Toshihiro Shimizu 890ddd
			assert(a < 0 && indexInPage < b);
Toshihiro Shimizu 890ddd
			b--;
Toshihiro Shimizu 890ddd
			a = indexInPage;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			a = b = indexInPage;
Toshihiro Shimizu 890ddd
		for (i = a; i <= b; i++) {
Toshihiro Shimizu 890ddd
			m_styleSelection->select(pageIndex, i, true);
Toshihiro Shimizu 890ddd
			selected = true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isStyleChanged = false;
Toshihiro Shimizu 890ddd
	if (on)
Toshihiro Shimizu 890ddd
		selected = true;
Toshihiro Shimizu 890ddd
	int styleIndex = m_page->getStyleId(indexInPage);
Toshihiro Shimizu 890ddd
	if (selected) {
Toshihiro Shimizu 890ddd
		setCurrentStyleIndex(styleIndex);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ChangeStyleCommand *changeStyleCommand = getChangeStyleCommand();
Toshihiro Shimizu 890ddd
		if (changeStyleCommand)
Toshihiro Shimizu 890ddd
			isStyleChanged = changeStyleCommand->onStyleChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!isStyleChanged) {
Toshihiro Shimizu 890ddd
		m_styleSelection->select(pageIndex, indexInPage, on);
Toshihiro Shimizu 890ddd
		m_styleSelection->makeCurrent();
Toshihiro Shimizu 890ddd
		updateCommandLocks();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Compute page size in regard to chip count.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::computeSize()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page) {
Toshihiro Shimizu 890ddd
		m_chipPerRow = 0;
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int w = parentWidget()->width();
Toshihiro Shimizu 890ddd
	int chipCount = getChipCount();
Toshihiro Shimizu 890ddd
	QSize chipSize = getChipSize();
Toshihiro Shimizu 890ddd
	m_chipPerRow = m_viewMode == List ? 1 : (w - 8) / chipSize.width();
Toshihiro Shimizu 890ddd
	if (m_chipPerRow == 0)
Toshihiro Shimizu 890ddd
		m_chipPerRow = 1;
Toshihiro Shimizu 890ddd
	int rowCount = (chipCount + m_chipPerRow - 1) / m_chipPerRow;
Toshihiro Shimizu 890ddd
	setMinimumSize(w, rowCount * chipSize.height() + 10);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If palette, referred to current page, exist and is animated set it to
Toshihiro Shimizu 890ddd
		current frame.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PageViewer::onFrameChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = (m_page) ? m_page->getPalette() : 0;
Toshihiro Shimizu 890ddd
	if (palette && palette->isAnimated())
Toshihiro Shimizu 890ddd
		update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Rename current style and update its view in current page.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//recall from m_renameTextField
Toshihiro Shimizu 890ddd
void PageViewer::onStyleRenamed()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_renameTextField->hide();
Shinya Kitaoka 3bfa54
	std::wstring newName = m_renameTextField->text().toStdWString();
Toshihiro Shimizu 890ddd
	assert(getPaletteHandle());
Toshihiro Shimizu 890ddd
	PaletteCmd::renamePaletteStyle(getPaletteHandle(), newName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Recall \b TStyleSelection::toggleLink() to current page style selection.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::toggleLink()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page || !m_styleSelection || m_styleSelection->isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_styleSelection->toggleLink();
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
	emit changeWindowTitleSignal();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Recall \b TStyleSelection::eraseToggleLink() to current page style selection.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::eraseToggleLink()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page || !m_styleSelection || m_styleSelection->isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_styleSelection->eraseToggleLink();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class PaletteViewerGUI::PaletteTabBar
Toshihiro Shimizu 890ddd
		\brief The PaletteTabBar class provides a bar with tab to show and manage palette
Toshihiro Shimizu 890ddd
		page.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Inherits \b QTabBar.
Toshihiro Shimizu 890ddd
		This object allows to move a tab with mouseMoveEvent, rename a tab in
Toshihiro Shimizu 890ddd
		doubleClickevent and create a new tab in drag and drop.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
/*!	\fn void PaletteTabBar::setPageViewer(PageViewer *pageViewer)
Toshihiro Shimizu 890ddd
		Set current tab bar page to \b pageViewer.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		\fn void PaletteTabBar::tabTextChanged(int index)
Toshihiro Shimizu 890ddd
		This signal is emitted when tab associated text change.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		\fn void PaletteTabBar::movePage(int srcIndex, int dstIndex)
Toshihiro Shimizu 890ddd
		This signal is emitted to notify tab position change.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
PaletteTabBar::PaletteTabBar(QWidget *parent, bool hasPageCommand)
Toshihiro Shimizu 890ddd
	: QTabBar(parent), m_renameTextField(new LineEdit(this)), m_renameTabIndex(-1), m_pageViewer(0), m_hasPageCommand(hasPageCommand)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setObjectName("PaletteTabBar");
Toshihiro Shimizu 890ddd
	setDrawBase(false);
Toshihiro Shimizu 890ddd
	m_renameTextField->hide();
Toshihiro Shimizu 890ddd
	connect(m_renameTextField, SIGNAL(editingFinished()), this, SLOT(updateTabName()));
Toshihiro Shimizu 890ddd
	if (m_hasPageCommand)
Toshihiro Shimizu 890ddd
		setAcceptDrops(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Hide rename text field and recall \b QTabBar::mousePressEvent().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::mousePressEvent(QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_renameTextField->hide();
Toshihiro Shimizu 890ddd
	QTabBar::mousePressEvent(event);
Toshihiro Shimizu 890ddd
	m_pageViewer->getSelection()->select(currentIndex());
Toshihiro Shimizu 890ddd
	m_pageViewer->getSelection()->makeCurrent();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If left button is pressed and a tab is selected emit signal \b movePage.
Toshihiro Shimizu 890ddd
		In any case recall \b QTabBar::mousePressEvent().
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::mouseMoveEvent(QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (event->buttons() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier && !m_pageViewer->getPage()->getPalette()->isLocked()) {
Toshihiro Shimizu 890ddd
		int srcIndex = currentIndex();
Toshihiro Shimizu 890ddd
		int dstIndex = tabAt(event->pos());
Toshihiro Shimizu 890ddd
		if (dstIndex >= 0 && dstIndex < count() && dstIndex != srcIndex) {
Toshihiro Shimizu 890ddd
			QRect rect = tabRect(srcIndex);
Toshihiro Shimizu 890ddd
			int x = event->pos().x();
Toshihiro Shimizu 890ddd
			if (x < rect.left() || x > rect.right()) {
Toshihiro Shimizu 890ddd
				emit movePage(srcIndex, dstIndex);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QTabBar::mouseMoveEvent(event);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set a text field with focus in event position to edit tab name.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::mouseDoubleClickEvent(QMouseEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_hasPageCommand)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (m_pageViewer->getPage()->getPalette()->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int index = tabAt(event->pos());
Toshihiro Shimizu 890ddd
	if (index < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_renameTabIndex = index;
Toshihiro Shimizu 890ddd
	LineEdit *fld = m_renameTextField;
Toshihiro Shimizu 890ddd
	fld->setText(tabText(index));
Toshihiro Shimizu 890ddd
	fld->setGeometry(tabRect(index));
Toshihiro Shimizu 890ddd
	fld->setAlignment(Qt::AlignCenter);
Toshihiro Shimizu 890ddd
	fld->show();
Toshihiro Shimizu 890ddd
	fld->selectAll();
Toshihiro Shimizu 890ddd
	fld->setFocus(Qt::OtherFocusReason);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If event data is a paletteData accept drag event; otherwise return.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::dragEnterEvent(QDragEnterEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_hasPageCommand)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(event->mimeData());</const>
Toshihiro Shimizu 890ddd
	if (!paletteData)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if ((m_pageViewer->getViewType() == CLEANUP_PALETTE && !paletteData->getPalette()->isCleanupPalette()) ||
Toshihiro Shimizu 890ddd
		(m_pageViewer->getViewType() == LEVEL_PALETTE && paletteData->getPalette()->isCleanupPalette())) {
Toshihiro Shimizu 890ddd
		event->ignore();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If tab in event position exist set it as current, otherwise create a new tab
Toshihiro Shimizu 890ddd
		recalling PageViewer::createDropPage().
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::dragMoveEvent(QDragMoveEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_hasPageCommand)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(event->mimeData());</const>
Toshihiro Shimizu 890ddd
	if (!paletteData)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (paletteData->getPalette() == m_pageViewer->getPage()->getPalette() && paletteData->hasOnlyPalette())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int tabIndex = tabAt(event->pos());
Toshihiro Shimizu 890ddd
	if (0 <= tabIndex && tabIndex < count())
Toshihiro Shimizu 890ddd
		setCurrentIndex(tabIndex);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_pageViewer->createDropPage();
Toshihiro Shimizu 890ddd
	event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Recall PageViewer::drop().
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::dropEvent(QDropEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_hasPageCommand)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (!dynamic_cast<const *="" palettedata="">(event->mimeData()))</const>
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_pageViewer->drop(-1, event->mimeData());
Toshihiro Shimizu 890ddd
	event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current rename tab index is a valid index, set tab text to rename text
Toshihiro Shimizu 890ddd
		field text; hide the rename text field and emit tabTextChanged() signal.
Toshihiro Shimizu 890ddd
		*/
Toshihiro Shimizu 890ddd
void PaletteTabBar::updateTabName()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int index = m_renameTabIndex;
Toshihiro Shimizu 890ddd
	if (index < 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_renameTabIndex = -1;
Toshihiro Shimizu 890ddd
	if (m_renameTextField->text() != "")
Toshihiro Shimizu 890ddd
		setTabText(index, m_renameTextField->text());
Toshihiro Shimizu 890ddd
	m_renameTextField->hide();
Toshihiro Shimizu 890ddd
	emit tabTextChanged(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  \class  PaletteViewerGUI::PaletteIconWidget
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \brief  PaletteIconWidget class provides a widget to show a palette icon.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Toshihiro Shimizu 890ddd
PaletteIconWidget::PaletteIconWidget(QWidget *parent, Qt::WindowFlags flags)
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
PaletteIconWidget::PaletteIconWidget(QWidget *parent, Qt::WFlags flags)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	: QWidget(parent, flags), m_isOver(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFixedSize(30, 20);
Toshihiro Shimizu 890ddd
	setToolTip(QObject::tr("Palette"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PaletteIconWidget::~PaletteIconWidget()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PaletteIconWidget::paintEvent(QPaintEvent *)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPainter p(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_isOver) {
Toshihiro Shimizu 890ddd
		static QPixmap dragPaletteIconPixmapOver(":Resources/dragpalette_over.png");
Toshihiro Shimizu 890ddd
		p.drawPixmap(5, 2, dragPaletteIconPixmapOver);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		static QPixmap dragPaletteIconPixmap(":Resources/dragpalette.png");
Toshihiro Shimizu 890ddd
		p.drawPixmap(5, 2, dragPaletteIconPixmap);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PaletteIconWidget::mousePressEvent(QMouseEvent *me)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (me->button() != Qt::LeftButton) {
Toshihiro Shimizu 890ddd
		me->ignore();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_mousePressPos = me->pos();
Toshihiro Shimizu 890ddd
	m_dragged = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PaletteIconWidget::mouseMoveEvent(QMouseEvent *me)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if ((me->pos() - m_mousePressPos).manhattanLength() > 20 &&
Toshihiro Shimizu 890ddd
		!m_dragged) {
Toshihiro Shimizu 890ddd
		m_dragged = true;
Toshihiro Shimizu 890ddd
		emit startDrag();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PaletteIconWidget::enterEvent(QEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_isOver = true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PaletteIconWidget::leaveEvent(QEvent *event)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_isOver = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::zoomInChip()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ViewMode currentView = getViewMode();
Toshihiro Shimizu 890ddd
	if (currentView == List || currentView == LargeChips)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	else if (currentView == SmallChips)
Toshihiro Shimizu 890ddd
		setViewMode(MediumChips);
Toshihiro Shimizu 890ddd
	else if (currentView == MediumChips)
Toshihiro Shimizu 890ddd
		setViewMode(LargeChips);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
void PageViewer::zoomOutChip()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ViewMode currentView = getViewMode();
Toshihiro Shimizu 890ddd
	if (currentView == List || currentView == SmallChips)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	else if (currentView == LargeChips)
Toshihiro Shimizu 890ddd
		setViewMode(MediumChips);
Toshihiro Shimizu 890ddd
	else if (currentView == MediumChips)
Toshihiro Shimizu 890ddd
		setViewMode(SmallChips);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void PageViewer::setNameDisplayMode(NameDisplayMode mode)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_nameDisplayMode == mode)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_nameDisplayMode = mode;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! lock the commands when the styleSelection set to current
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::updateCommandLocks()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	//iwasawa
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isLocked = m_page->getPalette()->isLocked();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	CommandManager *cmd = CommandManager::instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_Paste")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_PasteValues")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_PasteColors")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_Clear")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_BlendColors")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_PasteNames")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
	cmd->getAction("MI_GetColorFromStudioPalette")->setEnabled(!isLocked);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! remove link and revert to the normal style
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void PageViewer::removeLink()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_page || !m_styleSelection || m_styleSelection->isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_styleSelection->removeLink())
Toshihiro Shimizu 890ddd
		emit changeWindowTitleSignal();
Toshihiro Shimizu 890ddd
}