Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/paletteviewer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/keyframenavigator.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/trepetitionguard.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvscrollwidget.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/studiopaletteviewer.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/studiopalettecmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/studiopalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
Toshihiro Shimizu 890ddd
#include <qtoolbar></qtoolbar>
Toshihiro Shimizu 890ddd
#include <qscrollarea></qscrollarea>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qmenubar></qmenubar>
Toshihiro Shimizu 890ddd
#include <qtoolbutton></qtoolbutton>
Toshihiro Shimizu 890ddd
#include <qurl></qurl>
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qdrag></qdrag>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace PaletteViewerGUI;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class PaletteViewer
Shinya Kitaoka 120a6e
                \brief The PaletteViewer class provides an object to view and
Shinya Kitaoka 120a6e
   manage palette view.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                Inherits \b QWidget.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                This object allows to show and manage palette; it's possible
Shinya Kitaoka 120a6e
   distinguish three
Shinya Kitaoka 120a6e
                view type, class can show: current level palette, current studio
Shinya Kitaoka 120a6e
   palette or
Shinya Kitaoka 120a6e
                current cleanup palette, using setPalette() to set palette
Shinya Kitaoka 120a6e
   viewer.
Shinya Kitaoka 120a6e
                The object is composed of a vertical layout with three widget:
Shinya Kitaoka 120a6e
                \li a tab bar \b PaletteViewerGUI::TabBar in which are displayed
Shinya Kitaoka 120a6e
   palette page
Shinya Kitaoka 120a6e
                \b createTabBar();
Shinya Kitaoka 120a6e
                \li a central frame \b PaletteViewerGUI::PageViewer in which are
Shinya Kitaoka 120a6e
   displayed
Shinya Kitaoka 120a6e
                all style of current page in palette
Shinya Kitaoka 120a6e
                \li a button bar, \b createToolBar(), \b createPaletteToolBar()
Shinya Kitaoka 120a6e
                and \b createSavePaletteToolBar();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                A collection of method allows you to manage this object and its
Shinya Kitaoka 120a6e
   interaction
Shinya Kitaoka 120a6e
                with palette.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*!	\fn const TPaletteP PaletteViewer::&getPalette() const
Shinya Kitaoka 120a6e
                Return current viewer palette.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*!	\fn void PaletteViewer::createToolBar()
Shinya Kitaoka 120a6e
                Create down button bar.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*!	\fn void PaletteViewer::updateToolBar()
Shinya Kitaoka 120a6e
                Update button bar.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
PaletteViewer::PaletteViewer(QWidget *parent, PaletteViewType viewType,
Shinya Kitaoka 120a6e
                             bool hasSaveToolBar, bool hasPageCommand,
Shinya Kitaoka 120a6e
                             bool hasPasteColors)
Shinya Kitaoka 120a6e
    : QFrame(parent)
Shinya Kitaoka 120a6e
    , m_tabBarContainer(0)
Shinya Kitaoka 120a6e
    , m_pagesBar(0)
Shinya Kitaoka 120a6e
    , m_paletteToolBar(0)
Shinya Kitaoka 120a6e
    , m_savePaletteToolBar(0)
Shinya Kitaoka 120a6e
    , m_pageViewer(0)
Shinya Kitaoka 120a6e
    , m_pageViewerScrollArea(0)
Shinya Kitaoka 120a6e
    , m_indexPageToDelete(-1)
Shinya Kitaoka 120a6e
    , m_viewType(viewType)
Shinya Kitaoka 120a6e
    , m_frameHandle(0)
Shinya Kitaoka 120a6e
    , m_paletteHandle(0)
Shinya Kitaoka 120a6e
    , m_changeStyleCommand(0)
Shinya Kitaoka 120a6e
    , m_xsheetHandle(0)
Shinya Kitaoka 120a6e
    , m_hasSavePaletteToolbar(hasSaveToolBar)
Shinya Kitaoka 120a6e
    , m_hasPageCommand(hasPageCommand)
Shinya Kitaoka 120a6e
    , m_isSaveActionEnabled(true)
Shinya Kitaoka 120a6e
    , m_lockPaletteAction(0)
Shinya Kitaoka 120a6e
    , m_lockPaletteToolButton(0) {
Shinya Kitaoka 120a6e
  setObjectName("OnePixelMarginFrame");
Shinya Kitaoka 120a6e
  setFrameStyle(QFrame::StyledPanel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  createTabBar();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Create pageView
Shinya Kitaoka 120a6e
  m_pageViewerScrollArea = new QScrollArea();
Shinya Kitaoka 120a6e
  m_pageViewerScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  m_pageViewerScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
Shinya Kitaoka 120a6e
  m_pageViewerScrollArea->setWidgetResizable(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_pageViewer =
Shinya Kitaoka 120a6e
      new PageViewer(m_pageViewerScrollArea, m_viewType, hasPasteColors);
Shinya Kitaoka 120a6e
  m_pageViewerScrollArea->setWidget(m_pageViewer);
Shinya Kitaoka 120a6e
  m_pagesBar->setPageViewer(m_pageViewer);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Create toolbar. It is an horizontal layout with three internal toolbar.
Shinya Kitaoka 120a6e
  DvScrollWidget *toolbarScrollWidget = new DvScrollWidget;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  toolbarScrollWidget->setObjectName(
Shinya Kitaoka 120a6e
      "ToolBarContainer");  // Toonz's qss files are instructed to leave a
Shinya Kitaoka 120a6e
  // 1px grey margin on top for scroll buttons
Shinya Kitaoka 120a6e
  QWidget *toolBarWidget = new QWidget;  // children of this parent name.
Shinya Kitaoka 120a6e
  toolbarScrollWidget->setWidget(toolBarWidget);
Shinya Kitaoka 120a6e
  toolBarWidget->setSizePolicy(QSizePolicy::MinimumExpanding,
Shinya Kitaoka 120a6e
                               QSizePolicy::Fixed);
Shinya Kitaoka 120a6e
  toolBarWidget->setFixedHeight(22);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_paletteToolBar     = new QToolBar(toolBarWidget);
Shinya Kitaoka 120a6e
  m_savePaletteToolBar = new QToolBar(toolBarWidget);
Shinya Kitaoka 120a6e
  createToolBar();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QHBoxLayout *toolBarLayout = new QHBoxLayout(toolBarWidget);
Shinya Kitaoka 120a6e
  toolBarLayout->setMargin(0);
Shinya Kitaoka 120a6e
  toolBarLayout->setSpacing(0);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    toolBarLayout->addWidget(m_savePaletteToolBar, 0, Qt::AlignRight);
Shinya Kitaoka 120a6e
    toolBarLayout->addWidget(m_paletteToolBar, 0, Qt::AlignRight);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  toolBarWidget->setLayout(toolBarLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // This widget is used to set the background color of the tabBar
Shinya Kitaoka 120a6e
  // using the styleSheet.
Shinya Kitaoka 120a6e
  // It is also used to take 6px on the left before the tabBar
Shinya Kitaoka 120a6e
  // and to draw the two lines on the bottom size
Shinya Kitaoka 120a6e
  m_tabBarContainer = new TabBarContainter(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QVBoxLayout *mainLayout = new QVBoxLayout(this);
Shinya Kitaoka 120a6e
  mainLayout->setMargin(0);
Shinya Kitaoka 120a6e
  mainLayout->setSpacing(0);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    // To add 6px (on the left) before the TabBar
Shinya Kitaoka 120a6e
    QHBoxLayout *hLayout = new QHBoxLayout;
Shinya Kitaoka 120a6e
    hLayout->setMargin(0);
Shinya Kitaoka 120a6e
    // hLayout->setAlignment(Qt::AlignLeft);
Shinya Kitaoka 120a6e
    // hLayout->addSpacing(6);
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      hLayout->addWidget(m_pagesBar, 0);
Shinya Kitaoka 120a6e
      hLayout->addStretch(1);
Shinya Kitaoka 120a6e
      hLayout->addWidget(toolbarScrollWidget, 0);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_tabBarContainer->setLayout(hLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // To align this panel with the style Editor
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_tabBarContainer, 0);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_pageViewerScrollArea, 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setLayout(mainLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  connect(m_pagesBar, SIGNAL(currentChanged(int)), this,
Shinya Kitaoka 120a6e
          SLOT(setPageView(int)));
Shinya Kitaoka 120a6e
  connect(m_pagesBar, SIGNAL(movePage(int, int)), this,
Shinya Kitaoka 120a6e
          SLOT(movePage(int, int)));
Shinya Kitaoka 120a6e
  connect(m_pageViewer, SIGNAL(changeWindowTitleSignal()), this,
Shinya Kitaoka 120a6e
          SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  changeWindowTitle();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setAcceptDrops(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PaletteViewer::~PaletteViewer() { delete m_changeStyleCommand; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::setPaletteHandle(TPaletteHandle *paletteHandle) {
Shinya Kitaoka 120a6e
  if (m_paletteHandle == paletteHandle) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool ret                 = true;
Shinya Kitaoka 120a6e
  if (m_paletteHandle) ret = ret && disconnect(m_paletteHandle, 0, this, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_paletteHandle = paletteHandle;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_paletteHandle && isVisible()) {
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
Shinya Kitaoka 120a6e
                         SLOT(onPaletteSwitched()));
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(paletteChanged()), this,
Shinya Kitaoka 120a6e
                         SLOT(onPaletteChanged()));
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(paletteChanged()), this,
Shinya Kitaoka 120a6e
                         SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(paletteTitleChanged()), this,
Shinya Kitaoka 120a6e
                         SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
Shinya Kitaoka 120a6e
                         SLOT(onColorStyleSwitched()));
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(colorStyleChanged()), this,
Shinya Kitaoka 120a6e
                         SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
    ret = ret && connect(m_paletteHandle, SIGNAL(paletteDirtyFlagChanged()),
Shinya Kitaoka 120a6e
                         this, SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_viewType != CLEANUP_PALETTE)
Shinya Kitaoka 120a6e
    m_keyFrameButton->setPaletteHandle(m_paletteHandle);
Shinya Kitaoka 120a6e
  m_pageViewer->setPaletteHandle(m_paletteHandle);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setPageView(0);
Shinya Kitaoka 120a6e
  updateTabBar();
Shinya Kitaoka 120a6e
  updatePaletteToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::setFrameHandle(TFrameHandle *frameHandle) {
Shinya Kitaoka 120a6e
  m_frameHandle = frameHandle;
Shinya Kitaoka 120a6e
  if (m_viewType != CLEANUP_PALETTE)
Shinya Kitaoka 120a6e
    m_keyFrameButton->setFrameHandle(m_frameHandle);
Shinya Kitaoka 120a6e
  m_pageViewer->setFrameHandle(m_frameHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::setXsheetHandle(TXsheetHandle *xsheetHandle) {
Shinya Kitaoka 120a6e
  m_xsheetHandle = xsheetHandle;
Shinya Kitaoka 120a6e
  m_pageViewer->setXsheetHandle(m_xsheetHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*!for clearing level cache after "paste style" command called from style
Shinya Kitaoka 120a6e
 * selection
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::setLevelHandle(TXshLevelHandle *levelHandle) {
Shinya Kitaoka 120a6e
  m_pageViewer->setLevelHandle(levelHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPalette *PaletteViewer::getPalette() {
Shinya Kitaoka 120a6e
  if (!m_paletteHandle) return 0;
Shinya Kitaoka 120a6e
  return m_paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::updateView() {
Shinya Kitaoka 120a6e
  changeWindowTitle();
Shinya Kitaoka 120a6e
  setPageView(0);
Shinya Kitaoka 120a6e
  clearStyleSelection();
Shinya Kitaoka 120a6e
  updateTabBar();
Shinya Kitaoka 120a6e
  updatePaletteToolBar();
Shinya Kitaoka 120a6e
  updateSavePaletteToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::enableSaveAction(bool enable) {
Shinya Kitaoka 120a6e
  if (!m_savePaletteToolBar) return;
Shinya Kitaoka 120a6e
  QList<qaction *=""> actions;</qaction>
Shinya Kitaoka 120a6e
  actions               = m_savePaletteToolBar->actions();
Shinya Kitaoka 120a6e
  enable                = !getPalette() ? false : enable;
Shinya Kitaoka 120a6e
  m_isSaveActionEnabled = enable;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < actions.count() - 1; i++) {
Shinya Kitaoka 120a6e
    QAction *act = actions[i];
Shinya Kitaoka 120a6e
    if (act->text() == tr("&Save Palette As") ||
Shinya Kitaoka 120a6e
        act->text() == tr("&Save Palette"))
Shinya Kitaoka 120a6e
      act->setEnabled(enable);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create tab bar to select palette page.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::createTabBar() {
Shinya Kitaoka 120a6e
  m_pagesBar = new PaletteTabBar(this, m_hasPageCommand);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(m_pagesBar, SIGNAL(tabTextChanged(int)), this,
Shinya Kitaoka 120a6e
          SLOT(onTabTextChanged(int)));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!getPalette()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  updateTabBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create right part of button bar.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::createPaletteToolBar() {
Shinya Kitaoka 120a6e
  m_paletteToolBar->clear();
Shinya Kitaoka 120a6e
  m_paletteToolBar->setMovable(false);
Shinya Kitaoka 120a6e
  m_paletteToolBar->setIconSize(QSize(23, 20));
Shinya Kitaoka 120a6e
  m_paletteToolBar->setLayoutDirection(Qt::RightToLeft);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Lock button to avoid editing the palette by mistake
Shinya Kitaoka 120a6e
  if (m_viewType == LEVEL_PALETTE) {
Shinya Kitaoka 120a6e
    QIcon lockIcon = createQIconOnOffPNG("lockpalette");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_lockPaletteToolButton = new QToolButton(this);
Shinya Kitaoka 120a6e
    m_lockPaletteToolButton->setIcon(lockIcon);
Shinya Kitaoka 120a6e
    m_lockPaletteToolButton->setCheckable(true);
Shinya Kitaoka 120a6e
    m_lockPaletteToolButton->setObjectName("PaletteLockButton");
Shinya Kitaoka 120a6e
    m_lockPaletteToolButton->setToolTip(tr("Lock Palette"));
Shinya Kitaoka 120a6e
    if (getPalette()) {
Shinya Kitaoka 120a6e
      m_lockPaletteToolButton->setChecked(getPalette()->isLocked());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    connect(m_lockPaletteToolButton, SIGNAL(clicked(bool)), this,
Shinya Kitaoka 120a6e
            SLOT(setIsLocked(bool)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_paletteToolBar->addWidget(m_lockPaletteToolButton);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  } else if (m_viewType == STUDIO_PALETTE) {
Shinya Kitaoka 120a6e
    QToolButton *toolButton = new QToolButton(this);
Shinya Kitaoka 120a6e
    toolButton->setPopupMode(QToolButton::InstantPopup);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QIcon lockIcon = createQIconOnOffPNG("lockpalette");
Shinya Kitaoka 120a6e
    toolButton->setIcon(lockIcon);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    toolButton->setObjectName("PaletteLockButton");
Shinya Kitaoka 120a6e
    toolButton->setToolTip(tr("Lock Palette"));
Shinya Kitaoka 120a6e
    toolButton->setCheckable(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QMenu *lockMenu     = new QMenu(toolButton);
Shinya Kitaoka 120a6e
    m_lockPaletteAction = new QAction(tr("&Lock Palette"), toolButton);
Shinya Kitaoka 120a6e
    m_lockPaletteAction->setCheckable(true);
Shinya Kitaoka 120a6e
    lockMenu->addAction(m_lockPaletteAction);
Shinya Kitaoka 120a6e
    toolButton->setMenu(lockMenu);
Shinya Kitaoka 120a6e
    if (getPalette()) {
Shinya Kitaoka 120a6e
      m_lockPaletteAction->setChecked(getPalette()->isLocked());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    connect(m_lockPaletteAction, SIGNAL(triggered(bool)), this,
Shinya Kitaoka 120a6e
            SLOT(setIsLocked(bool)));
Shinya Kitaoka 120a6e
    connect(m_lockPaletteAction, SIGNAL(toggled(bool)), toolButton,
Shinya Kitaoka 120a6e
            SLOT(setChecked(bool)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_paletteToolBar->addWidget(toolButton);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Attenzione: alcune modifiche sono state fatte a livello di stylesheet
Shinya Kitaoka 120a6e
  QToolButton *viewModeButton = new QToolButton(this);
Shinya Kitaoka 120a6e
  viewModeButton->setPopupMode(QToolButton::InstantPopup);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QIcon viewModeIcon = createQIconPNG("options");
Shinya Kitaoka 120a6e
  viewModeButton->setIcon(viewModeIcon);
Shinya Kitaoka 120a6e
  QMenu *viewMode = new QMenu(QString("Options"), viewModeButton);
Shinya Kitaoka 120a6e
  viewMode->setToolTip(tr("Options"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QActionGroup *viewModeGroup = new QActionGroup(viewMode);
Shinya Kitaoka 120a6e
  connect(viewModeGroup, SIGNAL(triggered(QAction *)), this,
Shinya Kitaoka 120a6e
          SLOT(onViewMode(QAction *)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction *smallThumbAct =
Shinya Kitaoka 120a6e
      new QAction(tr("&Small Thumbnails View"), viewModeButton);
Shinya Kitaoka 120a6e
  smallThumbAct->setData(PageViewer::SmallChips);
Shinya Kitaoka 120a6e
  QAction *mediumThumbAct =
Shinya Kitaoka 120a6e
      new QAction(tr("&Medium Thumbnails View"), viewModeButton);
Shinya Kitaoka 120a6e
  mediumThumbAct->setData(PageViewer::MediumChips);
Shinya Kitaoka 120a6e
  QAction *largeThumbAct =
Shinya Kitaoka 120a6e
      new QAction(tr("&Large Thumbnails View"), viewModeButton);
Shinya Kitaoka 120a6e
  largeThumbAct->setData(PageViewer::LargeChips);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction *listAct = new QAction(tr("&List View"), viewModeButton);
Shinya Kitaoka 120a6e
  listAct->setData(PageViewer::List);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  viewModeGroup->addAction(smallThumbAct);
Shinya Kitaoka 120a6e
  viewModeGroup->addAction(mediumThumbAct);
Shinya Kitaoka 120a6e
  viewModeGroup->addAction(largeThumbAct);
Shinya Kitaoka 120a6e
  viewModeGroup->addAction(listAct);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction *styleDisplayAct = new QAction(tr("Style Name"), viewModeButton);
Shinya Kitaoka 120a6e
  styleDisplayAct->setData(PageViewer::Style);
Shinya Kitaoka 120a6e
  QAction *originalDisplayAct =
Shinya Kitaoka 120a6e
      new QAction(tr("StudioPalette Name"), viewModeButton);
Shinya Kitaoka 120a6e
  originalDisplayAct->setData(PageViewer::Original);
Shinya Kitaoka 120a6e
  QAction *bothDisplayAct = new QAction(tr("Both Names"), viewModeButton);
Shinya Kitaoka 120a6e
  bothDisplayAct->setData(PageViewer::StyleAndOriginal);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QActionGroup *nameDisplayModeGroup = new QActionGroup(viewMode);
Shinya Kitaoka 120a6e
  connect(nameDisplayModeGroup, SIGNAL(triggered(QAction *)), this,
Shinya Kitaoka 120a6e
          SLOT(onNameDisplayMode(QAction *)));
Shinya Kitaoka 120a6e
  nameDisplayModeGroup->addAction(styleDisplayAct);
Shinya Kitaoka 120a6e
  nameDisplayModeGroup->addAction(originalDisplayAct);
Shinya Kitaoka 120a6e
  nameDisplayModeGroup->addAction(bothDisplayAct);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  viewMode->addAction(smallThumbAct);
shun_iwasawa aa32e9
  viewMode->addAction(mediumThumbAct);
Shinya Kitaoka 120a6e
  viewMode->addAction(largeThumbAct);
Shinya Kitaoka 120a6e
  viewMode->addAction(listAct);
Shinya Kitaoka 120a6e
  viewMode->addSeparator();
Shinya Kitaoka 120a6e
  viewMode->addAction(styleDisplayAct);
Shinya Kitaoka 120a6e
  viewMode->addAction(originalDisplayAct);
Shinya Kitaoka 120a6e
  viewMode->addAction(bothDisplayAct);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  viewModeButton->setMenu(viewMode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Attenzione: avendo invertito la direzione devo aggiungere gli oggetti al
Shinya Kitaoka 120a6e
  // contrario
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_paletteToolBar->addWidget(viewModeButton);
Shinya Kitaoka 120a6e
  m_paletteToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_hasPageCommand) {
Shinya Kitaoka 120a6e
    QAction *addPage;
Shinya Kitaoka 120a6e
    QIcon addPageIcon = createQIconPNG("newpage");
Shinya Kitaoka 120a6e
    addPage = new QAction(addPageIcon, tr("&New Page"), m_paletteToolBar);
Shinya Kitaoka 120a6e
    connect(addPage, SIGNAL(triggered()), this, SLOT(addNewPage()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_paletteToolBar->addAction(addPage);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QIcon newColorIcon = createQIconPNG("newstyle");
Shinya Kitaoka 120a6e
  QAction *addColor =
Shinya Kitaoka 120a6e
      new QAction(newColorIcon, tr("&New Style"), m_paletteToolBar);
Shinya Kitaoka 120a6e
  connect(addColor, SIGNAL(triggered()), this, SLOT(addNewColor()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_paletteToolBar->addAction(addColor);
Shinya Kitaoka 120a6e
  m_paletteToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // KeyFrame button
Shinya Kitaoka 120a6e
  if (m_viewType != CLEANUP_PALETTE) {
Shinya Kitaoka 120a6e
    m_keyFrameButton = new PaletteKeyframeNavigator(m_paletteToolBar);
Shinya Kitaoka 120a6e
    m_paletteToolBar->addWidget(m_keyFrameButton);
Shinya Kitaoka 120a6e
    m_paletteToolBar->addSeparator();
Shinya Kitaoka 120a6e
    m_keyFrameButton->setSelection(m_pageViewer->getSelection());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updatePaletteToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create left part of button bar; insert different actions in according to
Shinya Kitaoka 120a6e
                current viewer palette type.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteViewer::createSavePaletteToolBar() {
Shinya Kitaoka 120a6e
  m_savePaletteToolBar->clear();
Shinya Kitaoka 120a6e
  m_savePaletteToolBar->setMovable(false);
Shinya Kitaoka 120a6e
  m_savePaletteToolBar->setIconSize(QSize(22, 20));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_hasSavePaletteToolbar || m_viewType == CLEANUP_PALETTE) {
Shinya Kitaoka 120a6e
    m_savePaletteToolBar->hide();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // save palette as
Shinya Kitaoka 120a6e
  QIcon saveAsPaletteIcon = createQIconOnOffPNG("savepaletteas", false);
Shinya Kitaoka 120a6e
  QAction *saveAsPalette  = new QAction(
Shinya Kitaoka 120a6e
      saveAsPaletteIcon, tr("&Save Palette As"), m_savePaletteToolBar);
Shinya Kitaoka 120a6e
  // overwrite palette
Shinya Kitaoka 120a6e
  QIcon savePaletteIcon = createQIconOnOffPNG("savepalette", false);
Shinya Kitaoka 120a6e
  QAction *savePalette =
Shinya Kitaoka 120a6e
      new QAction(savePaletteIcon, tr("&Save Palette"), m_savePaletteToolBar);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_viewType == STUDIO_PALETTE) {
Shinya Kitaoka 120a6e
    connect(savePalette, SIGNAL(triggered()), this, SLOT(saveStudioPalette()));
Shinya Kitaoka 120a6e
    m_savePaletteToolBar->addAction(savePalette);
Shinya Kitaoka 120a6e
  } else if (m_viewType == LEVEL_PALETTE) {
Shinya Kitaoka 120a6e
    // save load palette
Shinya Kitaoka 120a6e
    PaletteIconWidget *movePalette =
Shinya Kitaoka 120a6e
        new PaletteIconWidget(m_savePaletteToolBar);
Shinya Kitaoka 120a6e
    connect(movePalette, SIGNAL(startDrag()), this, SLOT(startDragDrop()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QAction *act = m_savePaletteToolBar->addWidget(movePalette);
Shinya Kitaoka 120a6e
    act->setText(tr("&Move Palette"));
Shinya Kitaoka 120a6e
    m_savePaletteToolBar->addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // save palette as
Shinya Kitaoka 120a6e
    connect(saveAsPalette, SIGNAL(triggered()),
Shinya Kitaoka 120a6e
            CommandManager::instance()->getAction("MI_SavePaletteAs"),
Shinya Kitaoka 120a6e
            SIGNAL(triggered()));
Shinya Kitaoka 120a6e
    m_savePaletteToolBar->addAction(saveAsPalette);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // overwrite palette
Shinya Kitaoka 120a6e
    connect(savePalette, SIGNAL(triggered()),
Shinya Kitaoka 120a6e
            CommandManager::instance()->getAction("MI_OverwritePalette"),
Shinya Kitaoka 120a6e
            SIGNAL(triggered()));
Shinya Kitaoka 120a6e
    m_savePaletteToolBar->addAction(savePalette);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateSavePaletteToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Update page tab bar adding or removing tab in accord with viewer palette.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::updateTabBar() {
Shinya Kitaoka 120a6e
  int tabCount = m_pagesBar->count();
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Se ci sono tab li butto
Shinya Kitaoka 120a6e
  for (i = tabCount - 1; i >= 0; i--) m_pagesBar->removeTab(i);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (!palette) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QIcon tabIcon(":Resources/palette_tabicon.png");
Shinya Kitaoka 120a6e
  m_pagesBar->setIconSize(QSize(20, 15));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Aggiungo i tab in funzione delle pagine di m_palette
Shinya Kitaoka 120a6e
  for (i = 0; i < palette->getPageCount(); i++) {
Shinya Kitaoka 120a6e
    TPalette::Page *page = palette->getPage(i);
Shinya Kitaoka 120a6e
    std::wstring ws      = page->getName();
Shinya Kitaoka 120a6e
    QString pageName     = QString::fromStdWString(ws);
Shinya Kitaoka 120a6e
    m_pagesBar->addTab(tabIcon, pageName);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_pagesBar->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Update right button bar, enable its action if current viewer palette is
Shinya Kitaoka 120a6e
 * empty.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::updatePaletteToolBar() {
Shinya Kitaoka 120a6e
  if (!m_paletteToolBar) return;
Shinya Kitaoka 120a6e
  QList<qaction *=""> actions;</qaction>
Shinya Kitaoka 120a6e
  actions                = m_paletteToolBar->actions();
Shinya Kitaoka 120a6e
  TPalette *palette      = getPalette();
Shinya Kitaoka 120a6e
  bool enable            = !palette ? false : true;
Shinya Kitaoka 120a6e
  bool enableNewStyleAct = enable;
Shinya Kitaoka 120a6e
  // limit the number of cleanup styles to 7
Shinya Kitaoka 120a6e
  if (palette && palette->isCleanupPalette())
Shinya Kitaoka 120a6e
    enableNewStyleAct = (palette->getStyleInPagesCount() < 8);
Shinya Kitaoka 120a6e
  if (m_viewType != CLEANUP_PALETTE) m_keyFrameButton->setEnabled(enable);
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < actions.count(); i++) {
Shinya Kitaoka 120a6e
    QAction *act = actions[i];
Shinya Kitaoka 120a6e
    if (act->text() == tr("&New Style")) {
Shinya Kitaoka 120a6e
      act->setEnabled(enableNewStyleAct);
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    act->setEnabled(enable);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Update left button bar, enable its action if current viewer palette is
Shinya Kitaoka 120a6e
 * empty.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::updateSavePaletteToolBar() {
Shinya Kitaoka 120a6e
  if (!m_savePaletteToolBar) return;
Shinya Kitaoka 120a6e
  QList<qaction *=""> actions;</qaction>
Shinya Kitaoka 120a6e
  actions     = m_savePaletteToolBar->actions();
Shinya Kitaoka 120a6e
  bool enable = !getPalette() ? false : true;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < actions.count(); i++) {
Shinya Kitaoka 120a6e
    QAction *act = actions[i];
Shinya Kitaoka 120a6e
    if (act->text() == tr("&Save Palette As") ||
Shinya Kitaoka 120a6e
        act->text() == tr("&Save Palette") ||
Shinya Kitaoka 120a6e
        act->text() == tr("&Palette Gizmo"))
Shinya Kitaoka 120a6e
      act->setEnabled(enable);
Shinya Kitaoka 120a6e
    else if (m_viewType != STUDIO_PALETTE && i == 0)  // move action
Shinya Kitaoka 120a6e
      actions[i]->setVisible(enable);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      actions[i]->setEnabled(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Resize the widget and its child.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::resizeEvent(QResizeEvent *event) {
Shinya Kitaoka 120a6e
  QWidget::resizeEvent(event);
Shinya Kitaoka 120a6e
  if (m_pageViewer) m_pageViewer->computeSize();
Shinya Kitaoka 120a6e
  if (m_pagesBar) m_pagesBar->setMaximumWidth(width() - 12);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::setChangeStyleCommand(
Shinya Kitaoka 120a6e
    ChangeStyleCommand *changeStyleCommand) {
Shinya Kitaoka 120a6e
  if (m_changeStyleCommand) delete m_changeStyleCommand;
Shinya Kitaoka 120a6e
  m_changeStyleCommand = changeStyleCommand;
Shinya Kitaoka 120a6e
  m_pageViewer->setChangeStyleCommand(m_changeStyleCommand);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create and open the Right-click menu.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::contextMenuEvent(QContextMenuEvent *event) {
Shinya Kitaoka 120a6e
  m_indexPageToDelete = -1;
Shinya Kitaoka 120a6e
  QPoint pos          = event->pos();
Shinya Kitaoka 120a6e
  if (!getPalette() || !m_tabBarContainer->geometry().contains(pos)) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QMenu *menu = new QMenu(this);
Shinya Kitaoka 120a6e
  if (m_hasPageCommand) {
Shinya Kitaoka 120a6e
    QAction *newPage = menu->addAction(tr("New Page"));
Shinya Kitaoka 120a6e
    connect(newPage, SIGNAL(triggered()), SLOT(addNewPage()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_pagesBar->geometry().contains(pos)) {
Shinya Kitaoka 120a6e
      int tabIndex         = m_pagesBar->tabAt(pos);
Shinya Kitaoka 120a6e
      TPalette::Page *page = getPalette()->getPage(tabIndex);
Shinya Kitaoka 120a6e
      if (page) {
Shinya Kitaoka 120a6e
        bool canRemovePage = true;
Shinya Kitaoka 120a6e
        if (page->getStyleId(0) == 0 || page->getStyleId(1) == 1)
Shinya Kitaoka 120a6e
          canRemovePage = false;
Shinya Kitaoka 120a6e
        if (canRemovePage) {
Shinya Kitaoka 120a6e
          m_indexPageToDelete = tabIndex;
Shinya Kitaoka 120a6e
          QAction *deletePage = menu->addAction(tr("Delete Page"));
Shinya Kitaoka 120a6e
          connect(deletePage, SIGNAL(triggered()), SLOT(deletePage()));
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_viewType == LEVEL_PALETTE && m_isSaveActionEnabled) {
Shinya Kitaoka 120a6e
    menu->addSeparator();
Shinya Kitaoka 120a6e
    menu->addAction(
Shinya Kitaoka 120a6e
        CommandManager::instance()->getAction("MI_OverwritePalette"));
Shinya Kitaoka 120a6e
    menu->addAction(CommandManager::instance()->getAction("MI_SavePaletteAs"));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu->exec(event->globalPos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::showEvent(QShowEvent *) {
Shinya Kitaoka 120a6e
  onPaletteSwitched();
Shinya Kitaoka 120a6e
  changeWindowTitle();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_paletteHandle) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  connect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
Shinya Kitaoka 120a6e
          SLOT(onPaletteSwitched()));
Shinya Kitaoka 120a6e
  connect(m_paletteHandle, SIGNAL(paletteChanged()), this,
Shinya Kitaoka 120a6e
          SLOT(onPaletteChanged()));
Shinya Kitaoka 120a6e
  connect(m_paletteHandle, SIGNAL(paletteTitleChanged()), this,
Shinya Kitaoka 120a6e
          SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
  connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
Shinya Kitaoka 120a6e
          SLOT(onColorStyleSwitched()));
Shinya Kitaoka 120a6e
  connect(m_paletteHandle, SIGNAL(colorStyleChanged()), this,
Shinya Kitaoka 120a6e
          SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
  connect(m_paletteHandle, SIGNAL(paletteDirtyFlagChanged()), this,
Shinya Kitaoka 120a6e
          SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_frameHandle) return;
Shinya Kitaoka 120a6e
  // Connessione necessaria per aggiornare lo stile in caso di palette animate.
Shinya Kitaoka 120a6e
  connect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
          SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::hideEvent(QHideEvent *) {
Shinya Kitaoka 120a6e
  disconnect(m_paletteHandle, SIGNAL(paletteSwitched()), this,
Shinya Kitaoka 120a6e
             SLOT(onPaletteSwitched()));
Shinya Kitaoka 120a6e
  disconnect(m_paletteHandle, SIGNAL(paletteChanged()), this,
Shinya Kitaoka 120a6e
             SLOT(onPaletteChanged()));
Shinya Kitaoka 120a6e
  disconnect(m_paletteHandle, SIGNAL(paletteTitleChanged()), this,
Shinya Kitaoka 120a6e
             SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
  disconnect(m_paletteHandle, SIGNAL(colorStyleSwitched()), this,
Shinya Kitaoka 120a6e
             SLOT(onColorStyleSwitched()));
Shinya Kitaoka 120a6e
  disconnect(m_paletteHandle, SIGNAL(colorStyleChanged()), this,
Shinya Kitaoka 120a6e
             SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
  disconnect(m_paletteHandle, SIGNAL(paletteDirtyFlagChanged()), this,
Shinya Kitaoka 120a6e
             SLOT(changeWindowTitle()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_frameHandle) return;
Shinya Kitaoka 120a6e
  disconnect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
             SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If currente palette viewer exist verify event data, if is a PaletteData or
Shinya Kitaoka 120a6e
                has urls accept event.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteViewer::dragEnterEvent(QDragEnterEvent *event) {
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (!palette || m_viewType == CLEANUP_PALETTE) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const QMimeData *mimeData      = event->mimeData();
Shinya Kitaoka 120a6e
  const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(mimeData);</const>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (paletteData) {
Shinya Kitaoka 120a6e
    // Sto "draggando" stili.
Shinya Kitaoka 120a6e
    if (paletteData->hasStyleIndeces()) {
Shinya Kitaoka 120a6e
      m_pageViewer->createDropPage();
Shinya Kitaoka 120a6e
      if (!palette) m_pagesBar->setCurrentIndex(palette->getPageCount() - 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    // Accetto l'evento
Shinya Kitaoka 120a6e
    event->acceptProposedAction();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!acceptResourceDrop(mimeData->urls())) return;
Shinya Kitaoka 120a6e
  QList<qurl> urls = mimeData->urls();</qurl>
Shinya Kitaoka 120a6e
  int count        = urls.size();
Shinya Kitaoka 120a6e
  if (count == 0) return;
Shinya Kitaoka 120a6e
  // Accetto l'evento solo se ho tutte palette.
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < count; i++) {
Shinya Kitaoka 120a6e
    TFilePath path(urls[i].toLocalFile().toStdWString());
Shinya Kitaoka 120a6e
    if (!path.getType().empty() && path.getType() != "tpl") return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Execute drop event.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::dropEvent(QDropEvent *event) {
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) return;
Shinya Kitaoka 120a6e
  const QMimeData *mimeData = event->mimeData();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPoint tollBarPos      = m_savePaletteToolBar->mapFrom(this, event->pos());
Shinya Kitaoka 120a6e
  QAction *currentAction = m_savePaletteToolBar->actionAt(tollBarPos);
Shinya Kitaoka 120a6e
  bool loadPalette =
Shinya Kitaoka 120a6e
      currentAction && currentAction->text() == QString(tr("&Move Palette"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // ho i path delle palette
Shinya Kitaoka 120a6e
  if (mimeData->hasUrls()) {
Shinya Kitaoka 120a6e
    QList<qurl> urls = mimeData->urls();</qurl>
Shinya Kitaoka 120a6e
    int count        = urls.size();
Shinya Kitaoka 120a6e
    if (count == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i = 0; i < count; i++) {
Shinya Kitaoka 120a6e
      TFilePath path(urls[i].toLocalFile().toStdWString());
Shinya Kitaoka 120a6e
      if (!path.getType().empty() && path.getType() != "tpl") return;
Shinya Kitaoka 120a6e
      if (loadPalette && i == 0) {
Shinya Kitaoka 120a6e
        if (m_xsheetHandle) {
Shinya Kitaoka 120a6e
          TPalette *newPalette =
Shinya Kitaoka 120a6e
              StudioPalette::instance()->getPalette(path, false);
Shinya Kitaoka 120a6e
          if (!newPalette) return;
Shinya Kitaoka 120a6e
          int ret = DVGui::eraseStylesInDemand(getPalette(), m_xsheetHandle,
Shinya Kitaoka 120a6e
                                               newPalette);
Shinya Kitaoka 120a6e
          if (ret == 0) return;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        StudioPaletteCmd::loadIntoCurrentPalette(m_paletteHandle, path);
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        StudioPaletteCmd::mergeIntoCurrentPalette(m_paletteHandle, path);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (loadPalette) {
Shinya Kitaoka 120a6e
        TFilePath refImagePath =
Shinya Kitaoka 120a6e
            StudioPalette::instance()->getPalette(path, true)->getRefImgPath();
Shinya Kitaoka 120a6e
        if (!refImagePath.isEmpty() &&
Shinya Kitaoka 120a6e
            getPalette()->getRefImgPath().isEmpty()) {
Shinya Kitaoka 120a6e
          getPalette()->setRefImgPath(refImagePath);
Shinya Kitaoka 120a6e
          m_paletteHandle->notifyPaletteChanged();
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    event->acceptProposedAction();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(mimeData);</const>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!paletteData) return;
Shinya Kitaoka 120a6e
  // Sto inserendo stili
Shinya Kitaoka 120a6e
  if (paletteData->hasStyleIndeces()) {
Shinya Kitaoka 120a6e
    m_pageViewer->drop(-1, mimeData);
Shinya Kitaoka 120a6e
    event->acceptProposedAction();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    // Ho la palette da inserire
Shinya Kitaoka 120a6e
    TPalette *palette = paletteData->getPalette();
Shinya Kitaoka 120a6e
    if (getPalette() == palette) return;
Shinya Kitaoka 120a6e
    if (loadPalette) {
Shinya Kitaoka 120a6e
      if (m_xsheetHandle) {
Shinya Kitaoka 120a6e
        int ret =
Shinya Kitaoka 120a6e
            DVGui::eraseStylesInDemand(getPalette(), m_xsheetHandle, palette);
Shinya Kitaoka 120a6e
        if (ret == 0) return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      StudioPaletteCmd::loadIntoCurrentPalette(m_paletteHandle, palette);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      StudioPaletteCmd::mergeIntoCurrentPalette(m_paletteHandle, palette);
Shinya Kitaoka 120a6e
  }
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
*/
Shinya Kitaoka 120a6e
void PaletteViewer::startDragDrop() {
Shinya Kitaoka 120a6e
  TRepetitionGuard guard;
Shinya Kitaoka 120a6e
  if (!guard.hasLock()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(m_viewType != STUDIO_PALETTE && m_viewType != CLEANUP_PALETTE);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (!palette) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QDrag *drag              = new QDrag(this);
Shinya Kitaoka 120a6e
  PaletteData *paletteData = new PaletteData();
Shinya Kitaoka 120a6e
  paletteData->setPalette(palette);
Shinya Kitaoka 120a6e
  drag->setMimeData(paletteData);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::clearStyleSelection() { m_pageViewer->clearSelection(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set current view page to \b currentIndexPage
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::setPageView(int currentIndexPage) {
Shinya Kitaoka 120a6e
  TPalette *palette    = getPalette();
Shinya Kitaoka 120a6e
  TPalette::Page *page = palette ? palette->getPage(currentIndexPage) : 0;
Shinya Kitaoka 120a6e
  m_pageViewer->setPage(page);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current palette viewer is not empty create emit a signal to create new
Shinya Kitaoka 120a6e
                palette page.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteViewer::addNewPage() {
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (palette) {
Shinya Kitaoka 120a6e
    if (palette->isLocked()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    updateTabBar();
Shinya Kitaoka 120a6e
    PaletteCmd::addPage(m_paletteHandle);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Create a new style in current page view of current palette viewer emit a
Shinya Kitaoka 120a6e
   signal
Shinya Kitaoka 120a6e
                to create a new style.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteViewer::addNewColor() {
Shinya Kitaoka 120a6e
  if (!getPalette() || getPalette()->isLocked()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPalette::Page *page = m_pageViewer->getPage();
Shinya Kitaoka 120a6e
  update();
Shinya Kitaoka 120a6e
  PaletteCmd::createStyle(m_paletteHandle, page);
Shinya Kitaoka 120a6e
  m_pageViewer->computeSize();
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) updatePaletteToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Emit a signal to delete a page of current palette viewer.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::deletePage() {
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (!palette || palette->isLocked()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_xsheetHandle) {
Shinya Kitaoka 120a6e
    std::vector<int> styleIds;</int>
Shinya Kitaoka 120a6e
    TPalette::Page *page = palette->getPage(m_indexPageToDelete);
Shinya Kitaoka 120a6e
    if (!page) return;  // La pagina dovrebbe esserci sempre
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i = 0; i < page->getStyleCount(); i++)
Shinya Kitaoka 120a6e
      styleIds.push_back(page->getStyleId(i));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int ret = DVGui::eraseStylesInDemand(palette, styleIds, m_xsheetHandle);
Shinya Kitaoka 120a6e
    if (ret == 0) return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PaletteCmd::destroyPage(m_paletteHandle, m_indexPageToDelete);
Shinya Kitaoka 120a6e
  updateTabBar();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  palette->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) updatePaletteToolBar();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current palette view is studio palette and palette has a global name
Shinya Kitaoka 120a6e
                save current viewer palette in studio palette.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteViewer::saveStudioPalette() {
Shinya Kitaoka 120a6e
  StudioPalette *sp = StudioPalette::instance();
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (!palette) {
Shinya Kitaoka 120a6e
    DVGui::warning("No current palette");
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  std::wstring gname = palette->getGlobalName();
Shinya Kitaoka 120a6e
  if (gname.empty()) {
Shinya Kitaoka 120a6e
    StudioPaletteViewer *parentSPV =
Shinya Kitaoka 120a6e
        qobject_cast<studiopaletteviewer *="">(parentWidget());</studiopaletteviewer>
Shinya Kitaoka 120a6e
    if (!parentSPV) {
Shinya Kitaoka 120a6e
      DVGui::warning("No GlobalName");
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      TFilePath palettePath = parentSPV->getCurrentItemPath();
Shinya Kitaoka 120a6e
      if (palettePath.isEmpty())
Shinya Kitaoka 120a6e
        DVGui::warning("No GlobalName, No Filepath");
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        QString question;
Shinya Kitaoka 120a6e
        question = "Do you want to overwrite current palette to " +
Shinya Kitaoka 120a6e
                   toQString(palettePath) + " ?";
Shinya Kitaoka 120a6e
        int ret = DVGui::MsgBox(question, QObject::tr("Overwrite"),
Shinya Kitaoka 120a6e
                                QObject::tr("Don't Overwrite"), 0);
Shinya Kitaoka 120a6e
        if (ret == 2 || ret == 0) return;
Shinya Kitaoka 120a6e
        StudioPalette::instance()->save(palettePath, palette);
Shinya Kitaoka 120a6e
        palette->setDirtyFlag(false);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFilePath fp = sp->getPalettePath(gname);
Shinya Kitaoka 120a6e
  if (fp != TFilePath()) {
Shinya Kitaoka 120a6e
    QString question;
Shinya Kitaoka 120a6e
    question = "Do you want to overwrite current studio palette to " +
Shinya Kitaoka 120a6e
               toQString(fp) + " ?";
Shinya Kitaoka 120a6e
    int ret =
Shinya Kitaoka 120a6e
        DVGui::MsgBox(question, tr("Overwrite"), tr("Don't Overwrite"), 0);
Shinya Kitaoka 120a6e
    if (ret == 2 || ret == 0) return;
Shinya Kitaoka 120a6e
    sp->setPalette(fp, getPalette(), false);
Shinya Kitaoka 120a6e
shun_iwasawa 640862
    StudioPaletteCmd::updateAllLinkedStyles(m_paletteHandle, m_xsheetHandle);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    palette->setDirtyFlag(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current color switched update current page view.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::onColorStyleSwitched() {
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // se non c'e' palette, pageviewer p pagina corrente esco (non dovrebbe
Shinya Kitaoka 120a6e
  // succedere mai)
Shinya Kitaoka 120a6e
  if (!palette || !m_pageViewer) return;
Shinya Kitaoka 120a6e
  int styleIndex = m_paletteHandle->getStyleIndex();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setPageView(m_pagesBar->currentIndex());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPalette::Page *page = m_pageViewer->getPage();
Shinya Kitaoka 120a6e
  if (!page) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // faccio in modo che la pagina che contiene il colore selezionato diventi
Shinya Kitaoka 120a6e
  // corrente
Shinya Kitaoka 120a6e
  int indexInPage = page->search(styleIndex);
Shinya Kitaoka 120a6e
  if (indexInPage == -1) {
Shinya Kitaoka 120a6e
    if (!palette->getStylePage(styleIndex)) return;
Shinya Kitaoka 120a6e
    int pageIndex = palette->getStylePage(styleIndex)->getIndex();
Shinya Kitaoka 120a6e
    m_pagesBar->setCurrentIndex(pageIndex);
Shinya Kitaoka 120a6e
    indexInPage = m_pageViewer->getPage()->search(styleIndex);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QRect colorStyleRect = m_pageViewer->getItemRect(indexInPage);
Shinya Kitaoka 120a6e
  m_pageViewerScrollArea->ensureVisible(colorStyleRect.center().x(),
Shinya Kitaoka 120a6e
                                        colorStyleRect.center().y(),
Shinya Kitaoka 120a6e
                                        colorStyleRect.size().width() / 2 + 4,
Shinya Kitaoka 120a6e
                                        colorStyleRect.size().height() / 2 + 4);
Shinya Kitaoka 120a6e
  m_pageViewer->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Update view. Remember current page bar index.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::onPaletteChanged() {
Shinya Kitaoka 120a6e
  int index = m_pagesBar->currentIndex();
Shinya Kitaoka 120a6e
  updateTabBar();
Shinya Kitaoka 120a6e
  m_pagesBar->setCurrentIndex(index);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_pageViewer->update();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) updatePaletteToolBar();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  changeWindowTitle();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::onPaletteSwitched() {
Shinya Kitaoka 120a6e
  updateView();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // update GUI according to the "lock" property
Shinya Kitaoka 120a6e
  if (getPalette() && m_viewType != CLEANUP_PALETTE &&
Shinya Kitaoka 120a6e
      (m_lockPaletteAction || m_lockPaletteToolButton)) {
Shinya Kitaoka 120a6e
    if (m_lockPaletteAction) {
Shinya Kitaoka 120a6e
      m_lockPaletteAction->setEnabled(true);
Shinya Kitaoka 120a6e
      m_lockPaletteAction->setChecked(getPalette()->isLocked());
Shinya Kitaoka 120a6e
    } else if (m_lockPaletteToolButton) {
Shinya Kitaoka 120a6e
      m_lockPaletteToolButton->setEnabled(true);
Shinya Kitaoka 120a6e
      m_lockPaletteToolButton->setChecked(getPalette()->isLocked());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    // update commands
Shinya Kitaoka 120a6e
    m_pageViewer->updateCommandLocks();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (m_lockPaletteAction)
Shinya Kitaoka 120a6e
      m_lockPaletteAction->setEnabled(false);
Shinya Kitaoka 120a6e
    else if (m_lockPaletteToolButton)
Shinya Kitaoka 120a6e
      m_lockPaletteToolButton->setEnabled(false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteViewer::onFrameSwitched() {
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (!palette) return;
Shinya Kitaoka 120a6e
  palette->setFrame(m_frameHandle->getFrameIndex());
Shinya Kitaoka 120a6e
  m_pageViewer->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set a new name to palette page of index \b tabIndex.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::onTabTextChanged(int tabIndex) {
Shinya Kitaoka 120a6e
  if (!m_paletteHandle) return;
Shinya Kitaoka 120a6e
  QString newName = m_pagesBar->tabText(tabIndex);
Shinya Kitaoka 120a6e
  PaletteCmd::renamePalettePage(m_paletteHandle, tabIndex,
Shinya Kitaoka 120a6e
                                newName.toStdWString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Change page style view mode.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::onViewMode(QAction *action) {
Shinya Kitaoka 120a6e
  int viewMode = action->data().toInt();
Shinya Kitaoka 120a6e
  m_pageViewer->setViewMode((PageViewer::ViewMode)viewMode);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*!  Change name display mode on the style chips
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::onNameDisplayMode(QAction *action) {
Shinya Kitaoka 120a6e
  int nameDisplayMode = action->data().toInt();
Shinya Kitaoka 120a6e
  m_pageViewer->setNameDisplayMode(
Shinya Kitaoka 120a6e
      (PageViewer::NameDisplayMode)nameDisplayMode);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current view type is LEVEL_PALETTE add to window title current level
Shinya Kitaoka 120a6e
                name and current frame.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteViewer::changeWindowTitle() {
Shinya Kitaoka 120a6e
  QString name = tr("Palette");
Shinya Kitaoka 120a6e
  QWidget *titleOwner;
Shinya Kitaoka 120a6e
  TPalette *palette = getPalette();
Shinya Kitaoka 120a6e
  if (m_viewType == LEVEL_PALETTE) {
Shinya Kitaoka 120a6e
    name = tr("Level Palette: ");
Shinya Kitaoka 120a6e
    if (palette) {
Shinya Kitaoka 120a6e
      name = name + QString::fromStdWString(palette->getPaletteName());
Shinya Kitaoka 120a6e
      if (palette->getDirtyFlag()) name += QString(" *");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    titleOwner = parentWidget();
Shinya Kitaoka 120a6e
  } else if (m_viewType == CLEANUP_PALETTE) {
Shinya Kitaoka 120a6e
    name       = tr("Cleanup Palette");
Shinya Kitaoka 120a6e
    titleOwner = parentWidget();
Shinya Kitaoka 120a6e
  } else if (m_viewType == STUDIO_PALETTE) {
Shinya Kitaoka 120a6e
    name = QString();
Shinya Kitaoka 120a6e
    if (palette) {
Shinya Kitaoka 120a6e
      if (palette->getDirtyFlag()) {
Shinya Kitaoka 120a6e
        name = QString("* ");
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      name = name + QString::fromStdWString(palette->getPaletteName()) +
Shinya Kitaoka 120a6e
             QString(" : ");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    name += tr("Studio Palette");
Shinya Kitaoka 120a6e
    titleOwner = parentWidget()->parentWidget();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // add color model name, if exists
Shinya Kitaoka 120a6e
  TFilePath refImagePath = (palette) ? palette->getRefImgPath() : TFilePath();
Shinya Kitaoka 120a6e
  if (!refImagePath.isEmpty()) {
Shinya Kitaoka 120a6e
    QString cmName = tr("     (Color Model: ") +
Shinya Kitaoka 120a6e
                     QString::fromStdWString(refImagePath.getWideName()) +
Shinya Kitaoka 120a6e
                     tr(")");
Shinya Kitaoka 120a6e
    name += cmName;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  titleOwner->setWindowTitle(name);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Move palette view page from \b srcIndex page index to \b dstIndex page
Shinya Kitaoka 120a6e
 * index.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::movePage(int srcIndex, int dstIndex) {
Shinya Kitaoka 120a6e
  PaletteCmd::movePalettePage(m_paletteHandle, srcIndex, dstIndex);
Shinya Kitaoka 120a6e
  m_pagesBar->setCurrentIndex(dstIndex);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Process when the lock button toggled
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void PaletteViewer::setIsLocked(bool lock) {
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  getPalette()->setIsLocked(lock);
Shinya Kitaoka 120a6e
  getPalette()->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  m_pageViewer->updateCommandLocks();
Shinya Kitaoka 120a6e
  // notify for updating the style editor
Shinya Kitaoka 120a6e
  m_paletteHandle->notifyPaletteLockChanged();
Toshihiro Shimizu 890ddd
}