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"
shun-iwasawa ad7711
#include "toonzqt/lutcalibrator.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
Shinya Kitaoka 120a6e
TEnv::IntVar EnvSoftwareCurrentFontSize_StyleName(
Shinya Kitaoka 120a6e
    "SoftwareCurrentFontSize_StyleName", 11);
shun-iwasawa 726b1d
extern TEnv::IntVar ShowNewStyleButton;
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
Shinya Kitaoka 120a6e
                \brief Provides a collection of widget to show \b palette.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \enum PaletteViewerGUI::PaletteViewType
Shinya Kitaoka 120a6e
                \brief Useful to mark different palette viewer type.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                There are three possible palette to view:
Shinya Kitaoka 120a6e
                \li level palette, palette of current level;
Shinya Kitaoka 120a6e
                \li cleanup palette, current scene cleanup palette;
Shinya Kitaoka 120a6e
                \li studio palette.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class PaletteViewerGUI::PageViewer
Shinya Kitaoka 120a6e
                \brief The PageViewer class provides an object to view and
Shinya Kitaoka 120a6e
   manage palettes page.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                Inherits \b QFrame and \b TSelection::View.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                This object allows to show and manage a single palette page. An
Shinya Kitaoka 120a6e
   enum type
Shinya Kitaoka 120a6e
                \b PaletteViewerGUI::PageViewer::ViewMode, getViewMode(),
Shinya Kitaoka 120a6e
   specify visualization
Shinya Kitaoka 120a6e
                mode, it is possible set it using setViewMode(). Class manage
Shinya Kitaoka 120a6e
   all mouse event,
Shinya Kitaoka 120a6e
                move, press, drag and drop.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*! \enum PaletteViewerGUI::PageViewer::ViewMode
Shinya Kitaoka 120a6e
                Useful to mark different page view moed:
Shinya Kitaoka 120a6e
                \li SmallChips: displays styles as small squares; the name of
Shinya Kitaoka 120a6e
   the style is
Shinya Kitaoka 120a6e
                displayed as tooltip.
Shinya Kitaoka 120a6e
                \li SmallChipsWithName:
luz paz 6454c4
                displays styles as small squares with the name inside.
Shinya Kitaoka 120a6e
                \li LargeChips: displays the styles on top of the name of the
Shinya Kitaoka 120a6e
   style.
Shinya Kitaoka 120a6e
                \li List:				List displays style
Shinya Kitaoka 120a6e
   thumbnails next to their names in a list;
Shinya Kitaoka 120a6e
                if the palette styles are referring to a studio palette, its
Shinya Kitaoka 120a6e
                path will be displayed along with the style name.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*!	\fn TPalette::Page* PageViewer::getPage() const
Shinya Kitaoka 120a6e
                Return current page.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*!	\fn ViewMode PageViewer::getViewMode() const
Shinya Kitaoka 120a6e
                Return current page view mode \b
Shinya Kitaoka 120a6e
   PaletteViewerGUI::PageViewer::ViewMode.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*! \fn void TPalette::onSelectionChanged()
Shinya Kitaoka 120a6e
                Update current page view.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
PageViewer::PageViewer(QWidget *parent, PaletteViewType viewType,
Shinya Kitaoka 120a6e
                       bool hasPasteColors)
Shinya Kitaoka 120a6e
    : QFrame(parent)
Shinya Kitaoka 120a6e
    , m_page(0)
Shinya Kitaoka 120a6e
    , m_chipsOrigin(2, 2)
Shinya Kitaoka 120a6e
    , m_chipPerRow(0)
Shinya Kitaoka 120a6e
    , m_viewMode(SmallChips)
Shinya Kitaoka 120a6e
    , m_styleSelection(new TStyleSelection())
Shinya Kitaoka 120a6e
    , m_frameHandle(0)
Shinya Kitaoka 120a6e
    , m_renameTextField(new LineEdit(this))
Shinya Kitaoka 120a6e
    , m_dropPositionIndex(-1)
Shinya Kitaoka 120a6e
    , m_dropPageCreated(false)
Shinya Kitaoka 120a6e
    , m_startDrag(false)
Shinya Kitaoka 120a6e
    , m_viewType(viewType)
Shinya Kitaoka 120a6e
    , m_nameDisplayMode(Style)
Shinya Kitaoka 120a6e
    , m_hasPasteColors(hasPasteColors)
shun_iwasawa 03feed
    , m_changeStyleCommand(0)
shun_iwasawa 03feed
    , m_styleNameEditor(NULL) {
Shinya Kitaoka 120a6e
  setFrameStyle(QFrame::StyledPanel);
Shinya Kitaoka 120a6e
  setObjectName("PageViewer");
Shinya Kitaoka 120a6e
  setFocusPolicy(Qt::StrongFocus);
Shinya Kitaoka 120a6e
  CommandManager *cmd    = CommandManager::instance();
Shinya Kitaoka 120a6e
  QAction *pasteValueAct = cmd->getAction(MI_PasteInto);
Shinya Kitaoka 120a6e
  addAction(pasteValueAct);
Shinya Kitaoka 120a6e
  if (m_hasPasteColors) {
Shinya Kitaoka 120a6e
    QAction *pasteColorsAct = cmd->getAction(MI_PasteColors);
Shinya Kitaoka 120a6e
    addAction(pasteColorsAct);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_renameTextField->hide();
Shinya Kitaoka 120a6e
  m_renameTextField->setObjectName("RenameColorTextField");
Shinya Kitaoka 120a6e
  connect(m_renameTextField, SIGNAL(editingFinished()), this,
Shinya Kitaoka 120a6e
          SLOT(onStyleRenamed()));
Shinya Kitaoka 120a6e
  m_styleSelection->setView(this);
Shinya Kitaoka 120a6e
  setAcceptDrops(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // applying default chip sizes
Shinya Kitaoka 120a6e
  ViewMode defaultChipSize;
Shinya Kitaoka 120a6e
  switch (m_viewType) {
Shinya Kitaoka 120a6e
  case LEVEL_PALETTE:
shun-iwasawa 784640
    defaultChipSize = LargeChips;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case CLEANUP_PALETTE:
shun-iwasawa 784640
    defaultChipSize = SmallChips;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case STUDIO_PALETTE:
shun-iwasawa 784640
    defaultChipSize = MediumChips;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
shun-iwasawa 784640
    defaultChipSize = LargeChips;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setViewMode(defaultChipSize);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PageViewer::~PageViewer() { delete m_styleSelection; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::setPaletteHandle(TPaletteHandle *paletteHandle) {
Shinya Kitaoka 120a6e
  TPaletteHandle *previousPalette = getPaletteHandle();
Shinya Kitaoka 120a6e
  if (previousPalette == paletteHandle) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (previousPalette)
shun_iwasawa e553fc
    disconnect(previousPalette, SIGNAL(colorStyleChanged(bool)), this,
Shinya Kitaoka 120a6e
               SLOT(update()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_styleSelection->setPaletteHandle(paletteHandle);
shun_iwasawa e553fc
  connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), SLOT(update()));
Toshihiro Shimizu 890ddd
shun_iwasawa 03feed
  if (m_styleNameEditor) m_styleNameEditor->setPaletteHandle(paletteHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPaletteHandle *PageViewer::getPaletteHandle() const {
Shinya Kitaoka 120a6e
  return m_styleSelection->getPaletteHandle();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::setXsheetHandle(TXsheetHandle *xsheetHandle) {
Shinya Kitaoka 120a6e
  m_styleSelection->setXsheetHandle(xsheetHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXsheetHandle *PageViewer::getXsheetHandle() const {
Shinya Kitaoka 120a6e
  return m_styleSelection->getXsheetHandle();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! for clearing the cache when executing paste style command from
Shinya Kitaoka 120a6e
 * StyleSelection
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::setLevelHandle(TXshLevelHandle *levelHandle) {
Shinya Kitaoka 120a6e
  m_styleSelection->setLevelHandle(levelHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::setFrameHandle(TFrameHandle *frameHandle) {
Shinya Kitaoka 120a6e
  m_frameHandle = frameHandle;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFrameHandle *PageViewer::getFrameHandle() const { return m_frameHandle; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::setCurrentStyleIndex(int index) {
shun-iwasawa fcbc0a
  // When clicking and switching between studio palette and level palette, the
shun-iwasawa fcbc0a
  // signal broadcastColorStyleSwitched is not emitted if the clicked style is
shun-iwasawa fcbc0a
  // previously selected one.
shun-iwasawa fcbc0a
  // Therefore here I introduced the "forceEmit" flag here in order to emit the
shun-iwasawa fcbc0a
  // signal whenever the style is clicked.
shun-iwasawa fcbc0a
  getPaletteHandle()->setStyleIndex(index, true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int PageViewer::getCurrentStyleIndex() const {
Shinya Kitaoka 120a6e
  return getPaletteHandle()->getStyleIndex();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set current page to \b page and update view.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::setPage(TPalette::Page *page) {
shun-iwasawa 726b1d
  if (m_page == page) return;
Shinya Kitaoka 120a6e
  m_page = page;
Shinya Kitaoka 120a6e
  computeSize();
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return chip count contained in current page.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
int PageViewer::getChipCount() const {
Shinya Kitaoka 120a6e
  return m_page ? m_page->getStyleCount() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Set current view mode \b PaletteViewerGUI::PageViewer::ViewMode to \b
Shinya Kitaoka 120a6e
 * viewMode and update view.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::setViewMode(ViewMode viewMode) {
Shinya Kitaoka 120a6e
  if (m_viewMode == viewMode) return;
Shinya Kitaoka 120a6e
  m_viewMode = viewMode;
Shinya Kitaoka 120a6e
  computeSize();
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Return current chip index by position \b pos.
Shinya Kitaoka 120a6e
                N.B. Cannot return chip index > max.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
int PageViewer::posToIndex(const QPoint &pos) const {
Shinya Kitaoka 120a6e
  if (m_chipPerRow == 0) return -1;
Shinya Kitaoka 120a6e
  QSize chipSize = getChipSize();
Shinya Kitaoka 120a6e
  int j          = (pos.x() - m_chipsOrigin.x()) / chipSize.width();
Shinya Kitaoka 120a6e
  int i          = (pos.y() - m_chipsOrigin.y()) / chipSize.height();
Shinya Kitaoka 120a6e
  int index      = i * m_chipPerRow + j;
Shinya Kitaoka 120a6e
  // if(index<0 || index>=getChipCount()) return -1;
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
                chip + name.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
QRect PageViewer::getItemRect(int index) const {
Shinya Kitaoka 120a6e
  if (m_chipPerRow == 0) return QRect();
Shinya Kitaoka 120a6e
  int row        = index / m_chipPerRow;
Shinya Kitaoka 120a6e
  int col        = index - (row * m_chipPerRow);
Shinya Kitaoka 120a6e
  int x0         = m_chipsOrigin.x();
Shinya Kitaoka 120a6e
  int y0         = m_chipsOrigin.y();
Shinya Kitaoka 120a6e
  QSize chipSize = getChipSize();
Shinya Kitaoka 120a6e
  int chipLx     = chipSize.width();
Shinya Kitaoka 120a6e
  int chipLy     = chipSize.height();
Shinya Kitaoka 120a6e
  QRect rect(x0 + chipLx * col, y0 + chipLy * row, chipLx, chipLy);
Shinya Kitaoka 120a6e
  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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
QRect PageViewer::getColorChipRect(int index) const {
Shinya Kitaoka 120a6e
  QRect rect = getItemRect(index);
Shinya Kitaoka 120a6e
  if (rect.isNull()) return rect;
Shinya Kitaoka 120a6e
  if (m_viewMode == LargeChips)
Shinya Kitaoka 120a6e
    rect.setHeight(20);
Shinya Kitaoka 120a6e
  else if (m_viewMode == List)
Shinya Kitaoka 120a6e
    rect.setWidth(rect.height());
Shinya Kitaoka 120a6e
  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).
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
QRect PageViewer::getColorNameRect(int index) const {
Shinya Kitaoka 120a6e
  QRect rect = getItemRect(index);
Shinya Kitaoka 120a6e
  if (rect.isNull()) return rect;
Shinya Kitaoka 120a6e
  if (m_viewMode == LargeChips)
Shinya Kitaoka 120a6e
    rect.adjust(-10, 14, 10, -14);
Shinya Kitaoka 120a6e
  else if (m_viewMode == MediumChips)
Shinya Kitaoka 120a6e
    rect.adjust(-15, 7, 15, -7);
Shinya Kitaoka 120a6e
  else if (m_viewMode == List)
Shinya Kitaoka 120a6e
    rect.setLeft(rect.left() + rect.height());
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return rect;
Shinya Kitaoka 120a6e
  return rect;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Add color to current page; if indexInPage == -1 add color at the bottom of
Shinya Kitaoka 120a6e
 * page.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::drop(int dstIndexInPage, const QMimeData *mimeData) {
Shinya Kitaoka 120a6e
  assert(m_page);
Shinya Kitaoka 120a6e
  TPalette *palette = m_page->getPalette();
Shinya Kitaoka 120a6e
  if (!palette) return;
Shinya Kitaoka 120a6e
  int dstPageIndex = m_page->getIndex();
Shinya Kitaoka 120a6e
  if ((m_page->getStyleId(0) == 0 || m_page->getStyleId(1) == 1) &&
Shinya Kitaoka 120a6e
      dstIndexInPage < 2)
shun-iwasawa 443318
    dstIndexInPage = 2;
Shinya Kitaoka 120a6e
  if (dstIndexInPage < 0) dstIndexInPage = m_page->getStyleCount();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const PaletteData *paletteData = dynamic_cast<const *="" palettedata="">(mimeData);</const>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!paletteData || !paletteData->hasStyleIndeces()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPalette *srcPalette           = paletteData->getPalette();
Shinya Kitaoka 120a6e
  int srcPageIndex               = paletteData->getPageIndex();
Shinya Kitaoka 120a6e
  std::set<int> srcIndicesInPage = paletteData->getIndicesInPage();</int>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_dropPageCreated) {
Shinya Kitaoka 120a6e
    // Rimuovo e reinserisco la pagina inizializzando l'undo.
Shinya Kitaoka 120a6e
    palette->setDirtyFlag(true);
Shinya Kitaoka 120a6e
    int pageIndex = palette->getPageCount() - 1;
Shinya Kitaoka 120a6e
    palette->erasePage(pageIndex);
Shinya Kitaoka 120a6e
    if (dstPageIndex != srcPageIndex && pageIndex == dstPageIndex) {
Shinya Kitaoka 120a6e
      TUndoManager::manager()->beginBlock();
Shinya Kitaoka 120a6e
      PaletteCmd::addPage(getPaletteHandle());
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      m_dropPageCreated = false;
Shinya Kitaoka 120a6e
    getPaletteHandle()->notifyPaletteChanged();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (srcPalette == palette) {
Shinya Kitaoka 120a6e
    PaletteCmd::arrangeStyles(getPaletteHandle(), dstPageIndex, dstIndexInPage,
Shinya Kitaoka 120a6e
                              srcPageIndex, srcIndicesInPage);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // seleziono gli stili spostati
Shinya Kitaoka 120a6e
    clearSelection();
Shinya Kitaoka 120a6e
    std::set<int>::const_reverse_iterator i;</int>
Shinya Kitaoka 120a6e
    int k = 0;
Shinya Kitaoka 120a6e
    for (i = srcIndicesInPage.rbegin(); i != srcIndicesInPage.rend();
Shinya Kitaoka 120a6e
         ++i, ++k) {
Shinya Kitaoka 120a6e
      int index = 0;
Shinya Kitaoka 120a6e
      if (*i <= dstIndexInPage)
Shinya Kitaoka 120a6e
        index = dstIndexInPage - k - 1;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        index = dstIndexInPage + k;
Shinya Kitaoka 120a6e
      m_styleSelection->select(dstPageIndex, index, true);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else  // when dropping the style into another palette
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    std::vector<tcolorstyle *=""> styles;</tcolorstyle>
Shinya Kitaoka 120a6e
    std::set<int>::iterator it;</int>
Shinya Kitaoka 120a6e
    for (it = srcIndicesInPage.begin(); it != srcIndicesInPage.end(); ++it) {
Shinya Kitaoka 120a6e
      int indexInPage = *it;
Shinya Kitaoka 120a6e
      styles.push_back(
Shinya Kitaoka 120a6e
          srcPalette->getPage(srcPageIndex)->getStyle(indexInPage));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    PaletteCmd::addStyles(getPaletteHandle(), dstPageIndex, dstIndexInPage,
Shinya Kitaoka 120a6e
                          styles);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_dropPageCreated) {
Shinya Kitaoka 120a6e
    m_dropPageCreated = false;
Shinya Kitaoka 120a6e
    TUndoManager::manager()->endBlock();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create an empty page to receive drop.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::createDropPage() {
Shinya Kitaoka 120a6e
  if (m_dropPageCreated) return;
Shinya Kitaoka 120a6e
  m_dropPageCreated = true;
Shinya Kitaoka 120a6e
  assert(m_page);
Shinya Kitaoka 120a6e
  TPalette *palette = m_page->getPalette();
Shinya Kitaoka 120a6e
  if (palette) PaletteCmd::addPage(getPaletteHandle(), L"", false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::clearSelection() { m_styleSelection->selectNone(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Return page chip size, it depend from current \b
Shinya Kitaoka 120a6e
 * PaletteViewerGUI::PageViewer::ViewMode.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
QSize PageViewer::getChipSize() const {
Shinya Kitaoka 120a6e
  if (m_viewMode == SmallChips || m_viewMode == SmallChipsWithName)
Shinya Kitaoka 120a6e
    return QSize(48, 33);
Shinya Kitaoka 120a6e
  else if (m_viewMode == MediumChips)
Shinya Kitaoka 120a6e
    return QSize(98, 38);
Shinya Kitaoka 120a6e
  else if (m_viewMode == LargeChips)
Shinya Kitaoka 120a6e
    return QSize(155, 53);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::drawColorChip(QPainter &p, QRect &chipRect,
Shinya Kitaoka 120a6e
                               TColorStyle *style) {
shun-iwasawa 388550
  // draw with MainColor for TSolidColorStyle(3), TColorCleanupStyle(2001)
shun-iwasawa 388550
  // and TBlackCleanupStyle(2002)
shun-iwasawa 388550
  if (style->getTagId() == 3 || style->getTagId() == 2001 ||
shun-iwasawa 388550
      style->getTagId() == 2002) {
shun-iwasawa 388550
    QColor styleColor((int)style->getMainColor().r,
shun-iwasawa 388550
                      (int)style->getMainColor().g,
shun-iwasawa 388550
                      (int)style->getMainColor().b);
shun-iwasawa 388550
    if (LutManager::instance()->isValid())
shun-iwasawa 388550
      LutManager::instance()->convert(styleColor);
shun-iwasawa 388550
    p.fillRect(chipRect, QBrush(styleColor));
shun-iwasawa 388550
  } else {
shun-iwasawa 388550
    TRaster32P icon = style->getIcon(qsize2Dimension(chipRect.size()));
shun-iwasawa 388550
    p.drawPixmap(chipRect.left(), chipRect.top(), rasterToQPixmap(icon, false));
shun-iwasawa 388550
  }
Shinya Kitaoka 120a6e
  p.drawRect(chipRect);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Draw style \b style name in \b nameRect.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::drawColorName(QPainter &p, QRect &nameRect, TColorStyle *style,
Shinya Kitaoka 120a6e
                               int styleIndex) {
Shinya Kitaoka 120a6e
  if (m_viewMode == SmallChips && style->getFlags() == 0) return;
Shinya Kitaoka 120a6e
  TPalette *palette = (m_page) ? m_page->getPalette() : 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString name = QString::fromStdWString(style->getName());
Shinya Kitaoka 120a6e
  if (m_viewMode == List) {
Shinya Kitaoka 120a6e
    p.setPen(getTextColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    std::pair<tfilepath, int=""> g =</tfilepath,>
Shinya Kitaoka 120a6e
        StudioPalette::instance()->getSourceStyle(style);
Shinya Kitaoka 120a6e
    if (g.first != TFilePath() && g.second >= 0)
Shinya Kitaoka 120a6e
      name += "  " + toQString(g.first) + ":" + QString::number(g.second);
Kite 521c84
    if (style->getFlags() != 0) name += " (autopaint)";
Shinya Kitaoka 120a6e
shun-iwasawa dd780b
    TPoint pickedPos = style->getPickedPosition().pos;
shun_iwasawa 9cbd0e
    if (pickedPos != TPoint())
shun_iwasawa 9cbd0e
      name += QString(" (%1,%2)").arg(pickedPos.x).arg(pickedPos.y);
shun_iwasawa 9cbd0e
Kite 521c84
    p.drawText(nameRect.adjusted(10, 4, -6, -4), name);
Shinya Kitaoka 120a6e
Kite 521c84
    p.setPen(getSeparatorColor());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_viewMode == SmallChips && style->getFlags() != 0) {
Shinya Kitaoka 120a6e
    QRect rect(nameRect.left(), nameRect.top(), 9, 9);
Shinya Kitaoka 120a6e
    p.fillRect(rect, QBrush(Qt::white));
Shinya Kitaoka 120a6e
    p.drawRect(rect);
Shinya Kitaoka 120a6e
    p.drawText(rect, Qt::AlignCenter, "a");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_viewMode == SmallChipsWithName && name != "" && name != "color") {
Shinya Kitaoka 120a6e
    QRect rect     = nameRect;
Shinya Kitaoka 120a6e
    QPen oldPen    = p.pen();
Shinya Kitaoka 120a6e
    TPixel32 color = style->getMainColor();
Shinya Kitaoka 120a6e
    int v          = (int)(0.299 * color.r + 0.587 * color.g + 0.114 * color.b);
Shinya Kitaoka 120a6e
    p.setPen(v > 127 ? Qt::black : Qt::white);
shun-iwasawa 443318
    int textWidth = QFontMetrics(p.font()).horizontalAdvance(name);
Shinya Kitaoka 120a6e
    if (textWidth < rect.width() - 2)
Shinya Kitaoka 120a6e
      p.drawText(rect, Qt::AlignCenter, name);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      p.drawText(rect.adjusted(2, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter,
Shinya Kitaoka 120a6e
                 name);
Shinya Kitaoka 120a6e
    p.setPen(oldPen);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_viewMode == LargeChips) {
shun-iwasawa 443318
    QString index = QString::number(styleIndex);
shun-iwasawa 443318
    QFont font    = p.font();
shun-iwasawa 443318
    int fontSize  = font.pointSize();
Shinya Kitaoka 120a6e
    if (fontSize == -1) fontSize = font.pixelSize();
shun-iwasawa 443318
    int length = index.length() * fontSize;
shun-iwasawa 443318
    int w      = (length > 11) ? (length) : 11;
shun-iwasawa 443318
    int h      = 11;
shun-iwasawa 443318
    int x0     = nameRect.right() - w + 1;
shun-iwasawa 443318
    int y0     = nameRect.top() - h - 1;
Shinya Kitaoka 120a6e
    p.drawText(nameRect.adjusted(6, 1, -6, -1), name);
Shinya Kitaoka 120a6e
    QRect indexRect(x0, y0, w, h);
Shinya Kitaoka 120a6e
    p.fillRect(indexRect, QBrush(Qt::white));
Shinya Kitaoka 120a6e
    p.drawRect(indexRect);
Shinya Kitaoka 120a6e
    p.drawText(indexRect, Qt::AlignCenter, index);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QFont f = p.font();
Shinya Kitaoka 120a6e
    f.setFamily("Calibri");
Shinya Kitaoka 120a6e
    p.setFont(f);
Shinya Kitaoka 120a6e
    if (style->getFlags() != 0) {
Shinya Kitaoka 120a6e
      QRect rect(nameRect.left(), y0, w, h);
Shinya Kitaoka 120a6e
      p.fillRect(rect, QBrush(Qt::white));
Shinya Kitaoka 120a6e
      p.drawRect(rect);
Shinya Kitaoka 120a6e
      p.drawText(rect.adjusted(0, +1, 0, +1), Qt::AlignCenter, "A");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    TTextureStyle *ts = dynamic_cast<ttexturestyle *="">(style);</ttexturestyle>
Shinya Kitaoka 120a6e
    if (ts) {
Shinya Kitaoka 120a6e
      QRect rect(nameRect.left() + ((style->getFlags() != 0) ? w : 0), y0, w,
Shinya Kitaoka 120a6e
                 h);
Shinya Kitaoka 120a6e
      p.fillRect(rect, QBrush(Qt::white));
Shinya Kitaoka 120a6e
      p.drawRect(rect);
Shinya Kitaoka 120a6e
      p.drawText(rect.adjusted(0, +1, 0, +1), Qt::AlignCenter,
Shinya Kitaoka 120a6e
                 ts->isPattern() ? "P" : "T");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect,
Shinya Kitaoka 120a6e
                                TColorStyle *style) {
Shinya Kitaoka 120a6e
  std::wstring globalName = style->getGlobalName();
Shinya Kitaoka 120a6e
  if (globalName != L"" && (globalName[0] == L'-' || globalName[0] == L'+')) {
Shinya Kitaoka 120a6e
    TPixel32 c = style->getMainColor();
Shinya Kitaoka 120a6e
    int x      = chipRect.topRight().x() - 6;
Shinya Kitaoka 120a6e
    int y      = chipRect.topRight().y();
Shinya Kitaoka 120a6e
    QRect rect(x, y, 7, 7);
Shinya Kitaoka 120a6e
konero 34e2aa
    p.save();
konero 34e2aa
Shinya Kitaoka 120a6e
    p.fillRect(rect, QBrush(Qt::white));
Shinya Kitaoka 120a6e
    p.setPen(Qt::black);
Shinya Kitaoka 120a6e
    p.drawRect(rect);
Shinya Kitaoka 120a6e
shun-iwasawa 2d063f
    if (style->getOriginalName().empty()) {
shun-iwasawa 2d063f
      p.setBrush(Qt::black);
shun-iwasawa 2d063f
      p.drawRect(rect.adjusted(2, 2, -2, -2));
shun-iwasawa 2d063f
    } else if (globalName[0] == L'+') {
Shinya Kitaoka 120a6e
      QPointF a(x + 2, y + 2);
Shinya Kitaoka 120a6e
      QPointF b(x + 2, y + 5);
Shinya Kitaoka 120a6e
      QPointF c(x + 5, y + 2);
Shinya Kitaoka 120a6e
      QPointF d(x + 5, y + 5);
Shinya Kitaoka 120a6e
      p.drawLine(a, b);
Shinya Kitaoka 120a6e
      p.drawLine(a, c);
Shinya Kitaoka 120a6e
      p.drawLine(a, d);
Shinya Kitaoka 120a6e
    }
konero 34e2aa
konero 34e2aa
    p.restore();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Martin van Zijl 085a23
/*! Draw the chip name \b name inside rectangle \b chipRect using painter \b p.
shun-iwasawa 726b1d
 * If the name is too wide to fit on the chip, use left align - to show the
shun-iwasawa 726b1d
 * start of the name. Otherwise, use center align.
shun-iwasawa 726b1d
 */
Martin van Zijl 085a23
static void drawChipName(QPainter &p, const QRect &chipRect,
shun-iwasawa 726b1d
                         const std::wstring &name) {
Martin van Zijl 085a23
  const QString nameQString = QString::fromStdWString(name);
Martin van Zijl 085a23
  QRect textRect = p.boundingRect(chipRect, Qt::AlignCenter, nameQString);
Martin van Zijl 085a23
Martin van Zijl 085a23
  if (chipRect.width() < textRect.width()) {
Martin van Zijl 085a23
    // align left if the name is too wide to fit on the chip
shun-iwasawa 726b1d
    p.drawText(chipRect.adjusted(4, 0, -4, 0), Qt::AlignLeft | Qt::AlignVCenter,
shun-iwasawa 726b1d
               nameQString);
shun-iwasawa 726b1d
  } else {
Martin van Zijl 085a23
    // otherwise align by center
Martin van Zijl 085a23
    p.drawText(chipRect, Qt::AlignCenter, nameQString);
Martin van Zijl 085a23
  }
Martin van Zijl 085a23
}
Martin van Zijl 085a23
Martin van Zijl 085a23
//-----------------------------------------------------------------------------
Kite 521c84
/*! Paint current page styles using current view mode.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::paintEvent(QPaintEvent *e) {
Shinya Kitaoka 120a6e
  QPainter p(this);
shun-iwasawa 726b1d
  QColor textColor = p.pen().color();
Shinya Kitaoka 120a6e
  if (m_chipPerRow == 0) {
Shinya Kitaoka 120a6e
    p.drawText(QPoint(5, 25), tr("- No Styles -"));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // currentStyle e palette
Shinya Kitaoka 120a6e
  TPalette *palette = (m_page) ? m_page->getPalette() : 0;
Shinya Kitaoka 120a6e
  if (!palette) return;
Shinya Kitaoka 120a6e
shun-iwasawa 2d063f
  bool isStudioPalette = palette->getGlobalName() != L"";
shun-iwasawa 2d063f
Kite 521c84
  // [i0,i1] = visible cell range
shun-iwasawa 443318
  QRect visibleRect = e->rect();
shun-iwasawa 443318
  int i0            = posToIndex(visibleRect.topLeft());
shun-iwasawa 443318
  if (i0 < 0) i0 = 0;
shun-iwasawa 443318
  int i1 = posToIndex(visibleRect.bottomRight());
Shinya Kitaoka 120a6e
  if (i1 >= getChipCount()) i1 = getChipCount() - 1;
Shinya Kitaoka 120a6e
DoctorRyan 16d12c
  QFont preFont = p.font();
DoctorRyan 16d12c
  QFont tmpFont = p.font();
DoctorRyan 16d12c
Shinya Kitaoka 120a6e
  if (m_viewMode == List) {
Kite 521c84
    // draw the cells
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    int currentStyleIndexInPage = -1;
Shinya Kitaoka 120a6e
    for (i = i0; i <= i1; i++) {
Shinya Kitaoka 120a6e
      TColorStyle *style = m_page->getStyle(i);
Shinya Kitaoka 120a6e
      int styleIndex     = m_page->getStyleId(i);
Shinya Kitaoka 120a6e
      if (getCurrentStyleIndex() == styleIndex) currentStyleIndexInPage = i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      QRect chipRect = getColorChipRect(i);
shun_iwasawa fd6c3c
      p.setPen(Qt::black);
Shinya Kitaoka 120a6e
      drawColorChip(p, chipRect, style);
Shinya Kitaoka 120a6e
Kite 521c84
      // current style
Kite 521c84
      if (i == currentStyleIndexInPage && 0 <= i && i < getChipCount()) {
Kite 521c84
        QRect rect = getItemRect(i);
Kite 521c84
        if (!m_styleSelection->isSelected(m_page->getIndex(), i)) {
Kite 521c84
          p.fillRect(rect.adjusted(23, 0, 0, 0), getCurrentCellColor());
Kite 521c84
        }
Kite 521c84
      }
Kite 521c84
Kite 521c84
      // selected
Kite 521c84
      if (m_styleSelection->isSelected(m_page->getIndex(), i)) {
Kite 521c84
        QRect itemRect = getItemRect(i);
Kite 521c84
        p.fillRect(itemRect.adjusted(23, 0, 0, 0), getSelectedCellColor());
Kite 521c84
      }
Kite 521c84
Shinya Kitaoka 120a6e
      // name, index and shortcut
Shinya Kitaoka 120a6e
      QRect nameRect = getColorNameRect(i);
Shinya Kitaoka 120a6e
      drawColorName(p, nameRect, style, styleIndex);
Shinya Kitaoka 120a6e
shun_iwasawa 4635d8
      // if numpad shortcut is activated, draw shortcut scope
shun_iwasawa 4635d8
      if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&
shun_iwasawa cede7c
          m_viewType == LEVEL_PALETTE &&
shun_iwasawa 4635d8
          palette->getStyleShortcut(styleIndex) >= 0) {
Kite 521c84
        p.setPen(QPen(QColor(getListNumpadShortcutBorderColor()), 2));
shun_iwasawa 4635d8
        p.drawLine(nameRect.topLeft() + QPoint(4, 1),
shun_iwasawa 4635d8
                   nameRect.bottomLeft() + QPoint(4, 0));
Kite 521c84
        p.setPen(QPen(QColor(getListNumpadShortcutBorderColor()), 2));
Kite 521c84
        p.drawLine(nameRect.topLeft() + QPoint(2, 1),
Kite 521c84
                   nameRect.bottomLeft() + QPoint(2, 0));
Shinya Kitaoka 120a6e
Kite 521c84
        // draw a separator line between shortcut border and name
Kite 521c84
        p.setPen(QPen(QColor(getSeparatorColor())));
Kite 521c84
        p.drawLine(nameRect.topLeft() + QPoint(5, 1),
Kite 521c84
                   nameRect.bottomLeft() + QPoint(5, 0));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // toggle link
shun-iwasawa 2d063f
      drawToggleLink(p, chipRect, style);
Shinya Kitaoka 120a6e
    }
shun-iwasawa 726b1d
    if (ShowNewStyleButton && !m_page->getPalette()->isLocked()) {
DoctorRyan 16d12c
      int j      = getChipCount();
DoctorRyan 16d12c
      QRect rect = getItemRect(j);
shun-iwasawa 726b1d
      p.setPen(
shun-iwasawa 726b1d
          QColor(textColor.red(), textColor.green(), textColor.blue(), 128));
DoctorRyan 16d12c
      // p.fillRect(rect, QBrush(QColor(0, 0, 0, 64)));
DoctorRyan 16d12c
      // p.drawRect(rect);
DoctorRyan 16d12c
      tmpFont.setPointSize(16);
DoctorRyan 16d12c
      tmpFont.setBold(true);
DoctorRyan 16d12c
      p.setFont(tmpFont);
DoctorRyan 16d12c
      QString newLabel = tr(" + ");
DoctorRyan 16d12c
      p.drawText(rect.adjusted(0, -6, 0, 0), Qt::AlignCenter, newLabel);
DoctorRyan 16d12c
DoctorRyan 16d12c
      // revert font set
DoctorRyan 16d12c
      p.setFont(preFont);
DoctorRyan 16d12c
      p.setPen(Qt::black);
shun-iwasawa 726b1d
    }
DoctorRyan 16d12c
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    int currentStyleIndex = getCurrentStyleIndex();
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i = i0; i <= i1; i++) {
Shinya Kitaoka 120a6e
      TColorStyle *style = m_page->getStyle(i);
Shinya Kitaoka 120a6e
      int styleIndex     = m_page->getStyleId(i);
Shinya Kitaoka 120a6e
shun_iwasawa 4635d8
      // if numpad shortcut is activated, draw shortcut scope
shun_iwasawa 4635d8
      if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&
shun_iwasawa cede7c
          m_viewType == LEVEL_PALETTE &&
shun_iwasawa 4635d8
          palette->getStyleShortcut(styleIndex) >= 0) {
shun_iwasawa 4635d8
        QRect itemRect = getItemRect(i);
shun_iwasawa 4635d8
        // paint dark
shun_iwasawa 4635d8
        p.setPen(Qt::NoPen);
Kite 521c84
        p.setBrush(QColor(getNumpadShortcutBgColor()));
shun_iwasawa 4635d8
        p.drawRect(itemRect);
shun_iwasawa 4635d8
        // check the neighbours and draw light lines
Kite 521c84
        p.setPen(QPen(QColor(getNumpadShortcutBorderColor()), 2));
shun_iwasawa 4635d8
        // top
shun_iwasawa 4635d8
        if (!hasShortcut(i - m_chipPerRow))
shun_iwasawa 4635d8
          p.drawLine(itemRect.topLeft(), itemRect.topRight() - QPoint(1, 0));
shun_iwasawa 4635d8
        // left
shun_iwasawa 4635d8
        if (i % m_chipPerRow == 0 || !hasShortcut(i - 1))
shun_iwasawa 4635d8
          p.drawLine(itemRect.topLeft() + QPoint(0, 1), itemRect.bottomLeft());
shun_iwasawa 4635d8
        // bottom
shun_iwasawa 4635d8
        if (!hasShortcut(i + m_chipPerRow))
shun_iwasawa 4635d8
          p.drawLine(itemRect.bottomLeft() + QPoint(1, 0),
shun_iwasawa 4635d8
                     itemRect.bottomRight());
shun_iwasawa 4635d8
        // right
shun_iwasawa 4635d8
        if ((i + 1) % m_chipPerRow == 0 || !hasShortcut(i + 1))
shun_iwasawa 4635d8
          p.drawLine(itemRect.topRight(),
shun_iwasawa 4635d8
                     itemRect.bottomRight() - QPoint(0, 1));
shun_iwasawa 4635d8
      }
shun_iwasawa 4635d8
Kite 521c84
      // draw frame if the style is selected or current
justburner b1f3a4
      if (m_styleSelection->isSelected(m_page->getIndex(), i)) {
shun_iwasawa 4635d8
        QRect itemRect = getItemRect(i).adjusted(0, -1, 0, 1);
Shinya Kitaoka 120a6e
        p.setPen(Qt::NoPen);
Kite 521c84
        p.setBrush(getSelectedBorderColor());
shun-iwasawa 443318
        p.drawRoundedRect(itemRect, 7, 25, Qt::RelativeSize);
justburner b1f3a4
      } else if (currentStyleIndex == styleIndex) {
justburner b1f3a4
        QRect itemRect = getItemRect(i).adjusted(1, 0, -1, 0);
justburner b1f3a4
        p.setPen(Qt::NoPen);
justburner b1f3a4
        p.setBrush(getSelectedBorderColor());
shun-iwasawa 443318
        p.drawRoundedRect(itemRect, 7, 25, Qt::RelativeSize);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      // paint style
Shinya Kitaoka 120a6e
      QRect chipRect = getItemRect(i).adjusted(4, 4, -5, -5);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      QColor styleColor((int)style->getMainColor().r,
Shinya Kitaoka 120a6e
                        (int)style->getMainColor().g,
Shinya Kitaoka 120a6e
                        (int)style->getMainColor().b);
Shinya Kitaoka 120a6e
      // draw with MainColor for TSolidColorStyle(3), TColorCleanupStyle(2001)
Shinya Kitaoka 120a6e
      // and TBlackCleanupStyle(2002)
Shinya Kitaoka 120a6e
      if (style->getTagId() == 3 || style->getTagId() == 2001 ||
Shinya Kitaoka 120a6e
          style->getTagId() == 2002) {
shun-iwasawa 388550
        if (LutManager::instance()->isValid())
shun-iwasawa 388550
          LutManager::instance()->convert(styleColor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        p.fillRect(chipRect, QBrush(styleColor));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // if the style is not 100% opac, draw the bottom part of the chip with
Shinya Kitaoka 120a6e
        // the pixmap with alpha
Shinya Kitaoka 120a6e
        if ((int)style->getMainColor().m !=
Shinya Kitaoka 120a6e
            (int)style->getMainColor().maxChannelValue) {
Shinya Kitaoka 120a6e
          QRect bottomRect = chipRect;
Shinya Kitaoka 120a6e
          if (m_viewMode == LargeChips) {
Shinya Kitaoka 120a6e
            bottomRect.adjust(0, bottomRect.height() - 12, 0, 0);
Shinya Kitaoka 120a6e
          } else
Shinya Kitaoka 120a6e
            bottomRect.adjust(0, bottomRect.height() - 6, 0, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          TRaster32P icon = style->getIcon(qsize2Dimension(bottomRect.size()));
Shinya Kitaoka 120a6e
          p.drawPixmap(bottomRect.left(), bottomRect.top(),
Shinya Kitaoka 120a6e
                       rasterToQPixmap(icon));
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        // Use white line for dark color. Use black line for light color.
Shinya Kitaoka 120a6e
        int val = (int)style->getMainColor().r * 30 +
Shinya Kitaoka 120a6e
                  (int)style->getMainColor().g * 59 +
Shinya Kitaoka 120a6e
                  (int)style->getMainColor().b * 11;
Shinya Kitaoka 120a6e
        if (val < 12800)
Shinya Kitaoka 120a6e
          p.setPen(Qt::white);
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          p.setPen(Qt::black);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        TRaster32P icon = style->getIcon(qsize2Dimension(chipRect.size()));
Shinya Kitaoka 120a6e
        p.drawPixmap(chipRect.left(), chipRect.top(), rasterToQPixmap(icon));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        if (m_viewMode == LargeChips) {
Shinya Kitaoka 120a6e
          p.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
          p.setBrush(QColor(0, 0, 0, 140));
Shinya Kitaoka 120a6e
          QRect zabutonRect = chipRect.adjusted(0, 12, 0, -12);
Shinya Kitaoka 120a6e
          p.drawRect(zabutonRect);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        p.setPen(Qt::white);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      p.setBrush(Qt::NoBrush);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // diagonal line indicates that the style color is changed after linked
Shinya Kitaoka 120a6e
      // from studio palette
Shinya Kitaoka 120a6e
      if (style->getIsEditedFlag()) {
Shinya Kitaoka 120a6e
        // draw diagonal line
Shinya Kitaoka 120a6e
        p.drawLine(chipRect.topRight(), chipRect.bottomLeft());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // keep center blank for style name
Shinya Kitaoka 120a6e
        if (m_viewMode != SmallChips) {
Shinya Kitaoka 120a6e
          QRect colorNameRect = chipRect;
Shinya Kitaoka 120a6e
          if (m_viewMode == MediumChips)
Shinya Kitaoka 120a6e
            colorNameRect.adjust(2, 9, -2, -8);
Shinya Kitaoka 120a6e
          else  // LargeChip
Shinya Kitaoka 120a6e
            colorNameRect.adjust(2, 16, -2, -13);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          p.fillRect(colorNameRect, QBrush(styleColor));
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // draw style name
Shinya Kitaoka 120a6e
      QFont preFont = p.font();
Shinya Kitaoka 120a6e
      QFont tmpFont = p.font();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (m_viewMode != SmallChips) {
Shinya Kitaoka 120a6e
        if (m_viewMode == MediumChips) {
Shinya Kitaoka 120a6e
          tmpFont.setPixelSize(EnvSoftwareCurrentFontSize_StyleName);
Shinya Kitaoka 120a6e
          p.setFont(tmpFont);
Shinya Kitaoka 120a6e
        } else if (m_viewMode == LargeChips) {
Shinya Kitaoka 120a6e
          tmpFont.setPixelSize(EnvSoftwareCurrentFontSize_StyleName + 2);
Shinya Kitaoka 120a6e
          p.setFont(tmpFont);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        std::wstring name     = style->getName();
Shinya Kitaoka 120a6e
        std::wstring origName = style->getOriginalName();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // display the name (style name and original name) according to the name
Shinya Kitaoka 120a6e
        // display mode
Martin van Zijl 085a23
        if (m_nameDisplayMode == Style) {
Martin van Zijl 085a23
          drawChipName(p, chipRect, name);
shun-iwasawa 726b1d
        } else if (m_nameDisplayMode == Original) {
Shinya Kitaoka 120a6e
          if (origName != L"") {
Shinya Kitaoka 120a6e
            tmpFont.setItalic(true);
Shinya Kitaoka 120a6e
            p.setFont(tmpFont);
Martin van Zijl 085a23
            drawChipName(p, chipRect, origName);
Shinya Kitaoka 120a6e
          } else  // if there is no original name, then display the style name
Shinya Kitaoka 120a6e
                  // in brackets
Martin van Zijl 085a23
            drawChipName(p, chipRect, L"( " + name + L" )");
Shinya Kitaoka 120a6e
        } else if (m_nameDisplayMode == StyleAndOriginal) {
Martin van Zijl 085a23
          drawChipName(p, chipRect, name);
Shinya Kitaoka 120a6e
luz paz 6454c4
          // display original name only when LargeChip view
Shinya Kitaoka 120a6e
          if (m_viewMode == LargeChips && origName != L"") {
Shinya Kitaoka 120a6e
            tmpFont.setItalic(true);
Shinya Kitaoka 120a6e
            tmpFont.setPixelSize(tmpFont.pixelSize() - 3);
Shinya Kitaoka 120a6e
            p.setFont(tmpFont);
Shinya Kitaoka 120a6e
            p.drawText(chipRect.adjusted(4, 4, -4, -4),
Shinya Kitaoka 120a6e
                       Qt::AlignLeft | Qt::AlignTop,
Shinya Kitaoka 120a6e
                       QString::fromStdWString(origName));
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // draw the frame border if the style is selected or current
Shinya Kitaoka 120a6e
      if (m_styleSelection->isSelected(m_page->getIndex(), i) ||
Shinya Kitaoka 120a6e
          currentStyleIndex == styleIndex) {
Shinya Kitaoka 120a6e
        p.setBrush(Qt::NoBrush);
Shinya Kitaoka 120a6e
        p.drawRect(chipRect.adjusted(3, 3, -3, -3));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // draw border
Shinya Kitaoka 120a6e
      p.setPen(Qt::black);
Shinya Kitaoka 120a6e
      p.setBrush(Qt::NoBrush);
Shinya Kitaoka 120a6e
      p.drawRect(chipRect);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // draw style index
Shinya Kitaoka 120a6e
      tmpFont.setPointSize(9);
Shinya Kitaoka 120a6e
      tmpFont.setItalic(false);
Shinya Kitaoka 120a6e
      p.setFont(tmpFont);
shun-iwasawa 443318
      int indexWidth =
shun-iwasawa 443318
          fontMetrics().horizontalAdvance(QString().setNum(styleIndex)) + 4;
Shinya Kitaoka 120a6e
      QRect indexRect(chipRect.bottomRight() + QPoint(-indexWidth, -14),
Shinya Kitaoka 120a6e
                      chipRect.bottomRight());
Shinya Kitaoka 120a6e
      p.setPen(Qt::black);
Shinya Kitaoka 120a6e
      p.setBrush(Qt::white);
Shinya Kitaoka 120a6e
      p.drawRect(indexRect);
Shinya Kitaoka 120a6e
      p.drawText(indexRect, Qt::AlignCenter, QString().setNum(styleIndex));
shun_iwasawa 24d635
Shinya Kitaoka d1f6c4
      // draw "Autopaint for lines" indicator
shun_iwasawa 9cbd0e
      int offset = 0;
shun_iwasawa 24d635
      if (style->getFlags() != 0) {
Shinya Kitaoka d1f6c4
        QRect aflRect(chipRect.bottomLeft() + QPoint(0, -14), QSize(12, 15));
shun_iwasawa 24d635
        p.drawRect(aflRect);
shun_iwasawa 24d635
        p.drawText(aflRect, Qt::AlignCenter, "A");
shun_iwasawa 9cbd0e
        offset += 12;
shun_iwasawa 9cbd0e
      }
shun_iwasawa 9cbd0e
shun_iwasawa 9cbd0e
      // draw "Picked Position" indicator (not show on small chip mode)
shun-iwasawa dd780b
      if (style->getPickedPosition().pos != TPoint() &&
shun-iwasawa dd780b
          m_viewMode != SmallChips) {
shun_iwasawa 9cbd0e
        QRect ppRect(chipRect.bottomLeft() + QPoint(offset, -14),
shun_iwasawa 9cbd0e
                     QSize(12, 15));
shun_iwasawa 9cbd0e
        p.drawRect(ppRect);
shun_iwasawa 9cbd0e
        QPoint markPos = ppRect.center() + QPoint(1, 0);
shun_iwasawa 9cbd0e
        p.drawEllipse(markPos, 3, 3);
shun_iwasawa 9cbd0e
        p.drawLine(markPos - QPoint(5, 0), markPos + QPoint(5, 0));
shun_iwasawa 9cbd0e
        p.drawLine(markPos - QPoint(0, 5), markPos + QPoint(0, 5));
shun_iwasawa 24d635
      }
shun_iwasawa 24d635
shun_iwasawa cede7c
      // if numpad shortcut is activated, draw shortcut number on top
shun_iwasawa cede7c
      if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&
shun_iwasawa cede7c
          m_viewType == LEVEL_PALETTE &&
shun_iwasawa cede7c
          palette->getStyleShortcut(styleIndex) >= 0 &&
shun_iwasawa cede7c
          m_viewMode != SmallChips) {
shun_iwasawa cede7c
        int key      = palette->getStyleShortcut(styleIndex);
shun_iwasawa cede7c
        int shortcut = key - Qt::Key_0;
shun_iwasawa cede7c
        QRect ssRect(chipRect.center().x() - 8, chipRect.top() - 11, 16, 20);
shun_iwasawa cede7c
        p.setBrush(Qt::gray);
shun_iwasawa cede7c
        p.drawChord(ssRect, 0, -180 * 16);
shun_iwasawa cede7c
        tmpFont.setPointSize(6);
shun_iwasawa cede7c
        p.setFont(tmpFont);
shun_iwasawa bb97ee
        // make sure the text is visible with any font
shun_iwasawa bb97ee
        static int rectTopAdjust = 19 - QFontMetrics(tmpFont).overlinePos();
shun_iwasawa bb97ee
        p.drawText(ssRect.adjusted(0, rectTopAdjust, 0, 0), Qt::AlignCenter,
shun_iwasawa cede7c
                   QString().setNum(shortcut));
shun_iwasawa cede7c
      }
shun_iwasawa cede7c
Shinya Kitaoka 120a6e
      // revert font set
Shinya Kitaoka 120a6e
      p.setFont(preFont);
Shinya Kitaoka 120a6e
      // revert brush
Shinya Kitaoka 120a6e
      p.setBrush(Qt::NoBrush);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // draw link indicator
Shinya Kitaoka 120a6e
      drawToggleLink(p, chipRect, style);
Shinya Kitaoka 120a6e
    }
shun-iwasawa 726b1d
    // draw new style chip
shun-iwasawa 726b1d
    if (ShowNewStyleButton && !m_page->getPalette()->isLocked()) {
DoctorRyan 16d12c
      i              = getChipCount();
shun-iwasawa 726b1d
      QRect chipRect = getItemRect(i).adjusted(4, 4, -5, -5);
shun-iwasawa 726b1d
      p.setPen(
shun-iwasawa 726b1d
          QColor(textColor.red(), textColor.green(), textColor.blue(), 128));
DoctorRyan 16d12c
      p.fillRect(chipRect, QBrush(QColor(0, 0, 0, 64)));
DoctorRyan 16d12c
      p.drawRect(chipRect);
DoctorRyan 16d12c
      tmpFont.setPointSize(16);
DoctorRyan 16d12c
      tmpFont.setBold(true);
DoctorRyan 16d12c
      p.setFont(tmpFont);
DoctorRyan 16d12c
      QString newLabel = tr(" + ");
DoctorRyan 16d12c
      p.drawText(chipRect.adjusted(0, -6, 0, 0), Qt::AlignCenter, newLabel);
DoctorRyan 16d12c
DoctorRyan 16d12c
      // revert font set
DoctorRyan 16d12c
      p.setFont(preFont);
DoctorRyan 16d12c
      // revert brush
DoctorRyan 16d12c
      p.setBrush(Qt::NoBrush);
DoctorRyan 16d12c
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // indicatore di drop
Shinya Kitaoka 120a6e
  if (m_dropPositionIndex >= 0) {
Shinya Kitaoka 120a6e
    QRect itemRect = getItemRect(m_dropPositionIndex);
Shinya Kitaoka 120a6e
    QRect rect;
Shinya Kitaoka 120a6e
    if (m_viewMode == List)
Shinya Kitaoka 120a6e
      rect = QRect(itemRect.left(), itemRect.top() - 1, itemRect.width(), 2);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      rect = QRect(itemRect.left() - 1, itemRect.top(), 2, itemRect.height());
Shinya Kitaoka 120a6e
    p.setPen(Qt::black);
Shinya Kitaoka 120a6e
    p.drawRect(rect);
Shinya Kitaoka 120a6e
    p.setPen(Qt::white);
Shinya Kitaoka 120a6e
    p.drawRect(rect.adjusted(-1, -1, 1, 1));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Recall computeSize().
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::resizeEvent(QResizeEvent *) { computeSize(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! If current page is empty return; otherwise select or unselect chip in regard
Shinya Kitaoka 120a6e
                to event position.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PageViewer::mousePressEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  TPalette *palette = m_page->getPalette();
Shinya Kitaoka 120a6e
  QPoint pos        = event->pos();
Shinya Kitaoka 120a6e
  int indexInPage   = posToIndex(pos);
Shinya Kitaoka 120a6e
  m_startDrag       = false;
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  int pageIndex = m_page->getIndex();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // disable style selection in the cleanup palette in order to avoid editing
Shinya Kitaoka 120a6e
  // the styles by mistake.
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) {
Shinya Kitaoka 120a6e
    if (0 <= indexInPage && indexInPage < getChipCount()) {
Shinya Kitaoka 120a6e
      // Right-click is available
Shinya Kitaoka 120a6e
      if (event->button() == Qt::RightButton) {
Shinya Kitaoka 120a6e
        m_styleSelection->makeCurrent();
Shinya Kitaoka 120a6e
        m_styleSelection->selectNone();
Shinya Kitaoka 120a6e
        m_styleSelection->select(pageIndex);
Shinya Kitaoka 120a6e
        m_styleSelection->select(pageIndex, indexInPage, true);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      // Changing the current style is still available
Shinya Kitaoka 120a6e
      setCurrentStyleIndex(m_page->getStyleId(indexInPage));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (event->button() == Qt::RightButton) {
Shinya Kitaoka 120a6e
    m_styleSelection->makeCurrent();
Shinya Kitaoka 120a6e
    // if you are clicking on the color chip
Shinya Kitaoka 120a6e
    if (0 <= indexInPage && indexInPage < getChipCount()) {
Shinya Kitaoka 120a6e
      // Se pageIndex non e' selezionato lo seleziono
Shinya Kitaoka 120a6e
      if (!m_styleSelection->isSelected(pageIndex, indexInPage)) {
Shinya Kitaoka 120a6e
        m_styleSelection->select(pageIndex);
Shinya Kitaoka 120a6e
        m_styleSelection->select(pageIndex, indexInPage, true);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      // Cambio l'indice corrente
Shinya Kitaoka 120a6e
      setCurrentStyleIndex(m_page->getStyleId(indexInPage));
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_styleSelection->selectNone();
Shinya Kitaoka 120a6e
      m_styleSelection->select(pageIndex);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
    // update locks when the styleSelection becomes current
Shinya Kitaoka 120a6e
    updateCommandLocks();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_dragStartPosition = pos;
Shinya Kitaoka 120a6e
  if (indexInPage < 0 || indexInPage >= getChipCount()) {
shun-iwasawa 726b1d
    if (ShowNewStyleButton && indexInPage == getChipCount() &&
shun-iwasawa 726b1d
        !m_page->getPalette()->isLocked()) {
DoctorRyan 16d12c
      PaletteCmd::createStyle(getPaletteHandle(), getPage());
DoctorRyan 89d621
      m_styleSelection->select(pageIndex);
DoctorRyan 89d621
      m_styleSelection->select(pageIndex, indexInPage, true);
DoctorRyan 16d12c
    } else {
DoctorRyan 16d12c
      // the user clicked out of the color chips.wants to deselect everything
DoctorRyan 16d12c
      // (leaving the selection active, for a possible paste)
shun-iwasawa 726b1d
      m_styleSelection->select(pageIndex);
shun-iwasawa 726b1d
      m_styleSelection->makeCurrent();
DoctorRyan 16d12c
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
    // update locks when the styleSelection becomes current
Shinya Kitaoka 120a6e
    updateCommandLocks();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    // O si sta selezonando un nuovo item O si vuole iniziare un drag
Shinya Kitaoka 120a6e
    if (m_styleSelection->isSelected(pageIndex, indexInPage) &&
Shinya Kitaoka 120a6e
        event->modifiers() == Qt::ControlModifier &&
Shinya Kitaoka 120a6e
        !m_page->getPalette()->isLocked())
Shinya Kitaoka 120a6e
      m_startDrag = true;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      select(indexInPage, event);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
luz paz 6454c4
/*! If left button is pressed start drag.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::mouseMoveEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  if (m_viewType == CLEANUP_PALETTE) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // continuo solo se e' un drag (bottone sinistro premuto)
Shinya Kitaoka 120a6e
  if (!(event->buttons() & Qt::LeftButton)) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_page->getPalette()->isLocked()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Se spingo ctrl mentre mi sto muovendo con almeno un item selezionato
Shinya Kitaoka 120a6e
  // abilito la possibilita' di fare drag.
Shinya Kitaoka 120a6e
  if (!m_startDrag && event->modifiers() == Qt::ControlModifier &&
Shinya Kitaoka 120a6e
      !m_styleSelection->isEmpty() &&
Shinya Kitaoka 120a6e
      (event->pos() - m_dragStartPosition).manhattanLength() > 12)
Shinya Kitaoka 120a6e
    m_startDrag = true;
Shinya Kitaoka 120a6e
  // faccio partire il drag&drop solo se mi sono mosso di una certa quantita'
Shinya Kitaoka 120a6e
  if ((event->pos() - m_dragStartPosition).manhattanLength() > 20 &&
Shinya Kitaoka 120a6e
      m_startDrag) {
Shinya Kitaoka 120a6e
    assert(m_styleSelection && !m_styleSelection->isEmpty());
Shinya Kitaoka 120a6e
    startDragDrop();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::mouseReleaseEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  TPalette *palette = m_page->getPalette();
Shinya Kitaoka 120a6e
  QPoint pos        = event->pos();
Shinya Kitaoka 120a6e
  int indexInPage   = posToIndex(pos);
Shinya Kitaoka 120a6e
  if (m_startDrag && m_dropPositionIndex == -1 &&
Shinya Kitaoka 120a6e
      event->modifiers() == Qt::ControlModifier)
Shinya Kitaoka 120a6e
    select(indexInPage, event);
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
                name rect open a text field, if is in color rect open a style
Shinya Kitaoka 120a6e
   editor.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PageViewer::mouseDoubleClickEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  int index = posToIndex(e->pos());
Shinya Kitaoka 120a6e
  if (index < 0 || index >= getChipCount()) return;
Shinya Kitaoka 120a6e
  TColorStyle *style = m_page->getStyle(index);
Shinya Kitaoka 120a6e
  if (!style) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_page->getPalette()->isLocked()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_viewMode != SmallChips) {
Shinya Kitaoka 120a6e
    QRect nameRect = getColorNameRect(index);
Shinya Kitaoka 120a6e
    if (nameRect.contains(e->pos())) {
Shinya Kitaoka 120a6e
      std::wstring styleName = style->getName();
Shinya Kitaoka 120a6e
      LineEdit *fld          = m_renameTextField;
Shinya Kitaoka 120a6e
      fld->setText(QString::fromStdWString(styleName));
Shinya Kitaoka 120a6e
      fld->setGeometry(nameRect);
Shinya Kitaoka 120a6e
      fld->show();
Shinya Kitaoka 120a6e
      fld->selectAll();
Shinya Kitaoka 120a6e
      fld->setFocus(Qt::OtherFocusReason);
shun_iwasawa fd6c3c
      fld->setAlignment((m_viewMode == List) ? Qt::AlignLeft : Qt::AlignCenter);
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
shun_iwasawa fd6c3c
  CommandManager::instance()->execute("MI_OpenStyleControl");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
void PageViewer::createMenuAction(QMenu &menu, const char *id, QString name,
Shinya Kitaoka 120a6e
                                  const char *slot) {
Shinya Kitaoka 120a6e
  bool ret     = true;
Shinya Kitaoka 120a6e
  QAction *act = menu.addAction(name);
Shinya Kitaoka 120a6e
  std::string slotName(slot);
Shinya Kitaoka 120a6e
  slotName = std::string("1") + slotName;
Shinya Kitaoka 120a6e
  ret      = connect(act, SIGNAL(triggered()), slotName.c_str());
Shinya Kitaoka 120a6e
  assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::addNewColor() {
Shinya Kitaoka 120a6e
  PaletteCmd::createStyle(getPaletteHandle(), getPage());
Shinya Kitaoka 120a6e
  computeSize();
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::addNewPage() {
manongjohn 649b9a
  TPaletteHandle *paletteHandle = getPaletteHandle();
manongjohn 649b9a
  PaletteCmd::addPage(paletteHandle);
manongjohn 649b9a
  if (paletteHandle)
manongjohn 649b9a
    emit switchToPage(paletteHandle->getPalette()->getPageCount() - 1);
Shinya Kitaoka 120a6e
  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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::contextMenuEvent(QContextMenuEvent *event) {
Shinya Kitaoka 120a6e
  QMenu menu(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CommandManager *cmd = CommandManager::instance();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.addAction(cmd->getAction(MI_Copy));
Shinya Kitaoka 120a6e
  QAction *pasteValueAct = cmd->getAction(MI_PasteValues);
Shinya Kitaoka 120a6e
  menu.addAction(pasteValueAct);
Shinya Kitaoka 120a6e
  QAction *pasteColorsAct = cmd->getAction(MI_PasteColors);
Shinya Kitaoka 120a6e
  menu.addAction(pasteColorsAct);
Shinya Kitaoka 120a6e
  QAction *pasteNamesAct = cmd->getAction(MI_PasteNames);
Shinya Kitaoka 120a6e
  menu.addAction(pasteNamesAct);
Shinya Kitaoka 120a6e
  QAction *pasteAct = cmd->getAction(MI_Paste);
Shinya Kitaoka 120a6e
  menu.addAction(pasteAct);
Shinya Kitaoka 120a6e
  QAction *cutAct = cmd->getAction(MI_Cut);
Shinya Kitaoka 120a6e
  menu.addAction(cutAct);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.addSeparator();
Shinya Kitaoka 120a6e
  QAction *clearAct = cmd->getAction(MI_Clear);
Shinya Kitaoka 120a6e
  menu.addAction(clearAct);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.addSeparator();
justburner b1f3a4
  // currently palette gizmo can only change colors from the current level
justburner b1f3a4
  // palette due to the way modifyColor works.
justburner b1f3a4
  if (m_viewType == LEVEL_PALETTE) {
justburner b1f3a4
    QAction *openPltGizmoAct = cmd->getAction("MI_OpenPltGizmo");
justburner b1f3a4
    menu.addAction(openPltGizmoAct);
justburner b1f3a4
  }
Shinya Kitaoka 120a6e
  QAction *openStyleControlAct = cmd->getAction("MI_OpenStyleControl");
Shinya Kitaoka 120a6e
  menu.addAction(openStyleControlAct);
shun_iwasawa fd6c3c
  QAction *openStyleNameEditorAct = menu.addAction(tr("Name Editor"));
justburner ebb16a
  openStyleNameEditorAct->setIcon(createQIcon("rename", false, true));
shun_iwasawa fd6c3c
  connect(openStyleNameEditorAct, &QAction::triggered, [&]() {
shun_iwasawa 03feed
    if (!m_styleNameEditor) {
shun_iwasawa 03feed
      m_styleNameEditor = new StyleNameEditor(this);
shun_iwasawa 03feed
      m_styleNameEditor->setPaletteHandle(getPaletteHandle());
shun_iwasawa 03feed
    }
shun_iwasawa fd6c3c
    m_styleNameEditor->show();
shun_iwasawa fd6c3c
    m_styleNameEditor->raise();
shun_iwasawa fd6c3c
    m_styleNameEditor->activateWindow();
shun_iwasawa fd6c3c
  });
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Verifica se lo stile e' link.
Shinya Kitaoka 120a6e
  // Abilita e disabilita le voci di menu' in base a dove si e' cliccato.
Shinya Kitaoka 120a6e
  int index     = posToIndex(event->pos());
Shinya Kitaoka 120a6e
  int indexPage = m_page ? m_page->getIndex() : -1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isLocked = m_page ? m_page->getPalette()->isLocked() : false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // remove links from studio palette
shun-iwasawa 2d063f
  if (m_styleSelection && !m_styleSelection->isEmpty() && !isLocked &&
shun_iwasawa 9f19cf
      m_styleSelection->hasLinkedStyle()) {
shun-iwasawa 2d063f
    if (m_viewType == LEVEL_PALETTE) {
shun-iwasawa 2d063f
      menu.addSeparator();
shun-iwasawa 2d063f
      menu.addAction(cmd->getAction("MI_ToggleLinkToStudioPalette"));
shun-iwasawa 2d063f
      menu.addAction(cmd->getAction("MI_RemoveReferenceToStudioPalette"));
shun-iwasawa 2d063f
      menu.addAction(cmd->getAction("MI_GetColorFromStudioPalette"));
shun-iwasawa 2d063f
    } else if (m_viewType == STUDIO_PALETTE) {
shun-iwasawa 2d063f
      menu.addSeparator();
shun-iwasawa 2d063f
      menu.addAction(cmd->getAction("MI_RemoveReferenceToStudioPalette"));
shun-iwasawa 2d063f
      menu.addAction(cmd->getAction("MI_GetColorFromStudioPalette"));
shun-iwasawa 2d063f
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (((indexPage == 0 && index > 0) || (indexPage > 0 && index >= 0)) &&
Shinya Kitaoka 120a6e
      index < getChipCount() && !isLocked) {
Shinya Kitaoka 120a6e
    if (pasteValueAct) pasteValueAct->setEnabled(true);
Shinya Kitaoka 120a6e
    if (pasteColorsAct) pasteColorsAct->setEnabled(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    pasteNamesAct->setEnabled(true);
Shinya Kitaoka 120a6e
    pasteAct->setEnabled(true);
Shinya Kitaoka 120a6e
    cutAct->setEnabled(true);
Shinya Kitaoka 120a6e
    clearAct->setEnabled(true);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (pasteValueAct) pasteValueAct->setEnabled(false);
Shinya Kitaoka 120a6e
    if (pasteColorsAct) pasteColorsAct->setEnabled(false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    pasteNamesAct->setEnabled(false);
Shinya Kitaoka 120a6e
    pasteAct->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
    cutAct->setEnabled(false);
Shinya Kitaoka 120a6e
    clearAct->setEnabled(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_page) {
Shinya Kitaoka 120a6e
    menu.addSeparator();
konero e746f3
    QIcon newStyleIco = createQIcon("newstyle", false, true);
justburner ebb16a
    QAction *newStyle = menu.addAction(newStyleIco, tr("New Style"));
Shinya Kitaoka 120a6e
    connect(newStyle, SIGNAL(triggered()), SLOT(addNewColor()));
konero e746f3
    QIcon newPageIco = createQIcon("newpage", false, true);
justburner ebb16a
    QAction *newPage = menu.addAction(newPageIco, tr("New Page"));
Shinya Kitaoka 120a6e
    connect(newPage, SIGNAL(triggered()), SLOT(addNewPage()));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.exec(event->globalPos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! Accept drag enter event if evant data ha format \b
Shinya Kitaoka 120a6e
 * TStyleSelection::getMimeType().
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::dragEnterEvent(QDragEnterEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  const PaletteData *paletteData =
Shinya Kitaoka 120a6e
      dynamic_cast<const *="" palettedata="">(event->mimeData());</const>
Shinya Kitaoka 120a6e
  if (paletteData && paletteData->hasStyleIndeces()) {
Shinya Kitaoka 120a6e
    if ((m_viewType == CLEANUP_PALETTE &&
Shinya Kitaoka 120a6e
         !paletteData->getPalette()->isCleanupPalette()) ||
Shinya Kitaoka 120a6e
        (m_viewType == LEVEL_PALETTE &&
Shinya Kitaoka 120a6e
         paletteData->getPalette()->isCleanupPalette())) {
Shinya Kitaoka 120a6e
      event->ignore();
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    int index = posToIndex(event->pos());
Shinya Kitaoka 120a6e
    // non si puo' spostare qualcosa nelle prime due posizioni di pagina 0
Shinya Kitaoka 120a6e
    // (occupate da BG e FG)
Shinya Kitaoka 120a6e
    if (m_page->getIndex() == 0 && index < 2) index = 2;
Shinya Kitaoka 120a6e
    if (index < 0)
Shinya Kitaoka 120a6e
      index = 0;
Shinya Kitaoka 120a6e
    else if (index > m_page->getStyleCount())
shun-iwasawa 443318
      index = m_page->getStyleCount();
Shinya Kitaoka 120a6e
    m_dropPositionIndex = index;
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
    event->acceptProposedAction();
Shinya Kitaoka 120a6e
  }
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
Shinya Kitaoka 120a6e
                index set right drop position index and accept event.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PageViewer::dragMoveEvent(QDragMoveEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  int index = posToIndex(event->pos());
Shinya Kitaoka 120a6e
  if (index != m_dropPositionIndex) {
Shinya Kitaoka 120a6e
    if ((m_page->getStyleId(0) == 0 || m_page->getStyleId(1) == 1) && index < 2)
Shinya Kitaoka 120a6e
      index = 2;
Shinya Kitaoka 120a6e
    if (index < 0)
Shinya Kitaoka 120a6e
      index = 0;
Shinya Kitaoka 120a6e
    else if (index > m_page->getStyleCount())
shun-iwasawa 443318
      index = m_page->getStyleCount();
Shinya Kitaoka 120a6e
    m_dropPositionIndex = index;
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
    event->acceptProposedAction();
Shinya Kitaoka 120a6e
  }
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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::dropEvent(QDropEvent *event) {
Shinya Kitaoka 120a6e
  int dstIndexInPage  = m_dropPositionIndex;
Shinya Kitaoka 120a6e
  m_dropPositionIndex = -1;
Shinya Kitaoka 120a6e
  update();
Shinya Kitaoka 120a6e
  if (!dynamic_cast<const *="" palettedata="">(event->mimeData())) return;</const>
Shinya Kitaoka 120a6e
  drop(dstIndexInPage, event->mimeData());
Shinya Kitaoka 120a6e
  event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Set to -1 drag position index and update view.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::dragLeaveEvent(QDragLeaveEvent *event) {
Shinya Kitaoka 120a6e
  m_dropPositionIndex = -1;
Shinya Kitaoka 120a6e
  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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::startDragDrop() {
Shinya Kitaoka 120a6e
  TRepetitionGuard guard;
Shinya Kitaoka 120a6e
  if (!guard.hasLock()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(m_page);
Shinya Kitaoka 120a6e
  TPalette *palette = m_page->getPalette();
Shinya Kitaoka 120a6e
  if (!palette || !m_page || !m_styleSelection) return;
Shinya Kitaoka 120a6e
  int pageIndex = m_page->getIndex();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_styleSelection->canHandleStyles()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  PaletteData *paletteData = new PaletteData();
Shinya Kitaoka 120a6e
  paletteData->setPaletteData(palette, pageIndex,
Shinya Kitaoka 120a6e
                              m_styleSelection->getIndicesInPage());
Shinya Kitaoka 120a6e
  QDrag *drag = new QDrag(this);
Shinya Kitaoka 120a6e
  drag->setMimeData(paletteData);
Shinya Kitaoka 120a6e
  Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
Shinya Kitaoka 120a6e
  if (m_dropPageCreated) {
Shinya Kitaoka 120a6e
    m_dropPageCreated = false;
Shinya Kitaoka 120a6e
    int pageIndex     = palette->getPageCount() - 1;
Shinya Kitaoka 120a6e
    if (palette->getPage(pageIndex)->getStyleCount() == 0) {
Shinya Kitaoka 120a6e
      palette->erasePage(pageIndex);
Shinya Kitaoka 120a6e
      getPaletteHandle()->notifyPaletteChanged();
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      palette->setDirtyFlag(true);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::keyPressEvent(QKeyEvent *e) {
Shinya Kitaoka 120a6e
  int key = e->key();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (key == Qt::Key_Up) {  // Row = frame precedente a quello settato
Shinya Kitaoka 120a6e
    int frameIndex = m_frameHandle->getFrameIndex() - 1;
Shinya Kitaoka 120a6e
    if (frameIndex < 0) return;
Shinya Kitaoka 120a6e
    m_frameHandle->setFrameIndex(frameIndex);
Shinya Kitaoka 120a6e
  } else if (key == Qt::Key_Down) {  // Row = frame successivo a quello settato
Shinya Kitaoka 120a6e
    int frameIndex = m_frameHandle->getFrameIndex() + 1;
Shinya Kitaoka 120a6e
    m_frameHandle->setFrameIndex(frameIndex);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    CommandManager *cManager = CommandManager::instance();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (key ==
Shinya Kitaoka 120a6e
        cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomIn)))
Shinya Kitaoka 120a6e
      zoomInChip();
shun-iwasawa 443318
    else if (key == cManager->getKeyFromShortcut(
shun-iwasawa 443318
                        cManager->getShortcutFromId(V_ZoomOut)))
Shinya Kitaoka 120a6e
      zoomOutChip();
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      e->ignore();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::showEvent(QShowEvent *) {
Shinya Kitaoka 120a6e
  TPaletteHandle *paletteHandle = getPaletteHandle();
Shinya Kitaoka 120a6e
  if (!paletteHandle) return;
shun_iwasawa e553fc
  connect(paletteHandle, SIGNAL(colorStyleChanged(bool)), SLOT(update()),
Shinya Kitaoka 120a6e
          Qt::UniqueConnection);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::hideEvent(QHideEvent *) {
Shinya Kitaoka 120a6e
  TPaletteHandle *paletteHandle = getPaletteHandle();
Shinya Kitaoka 120a6e
  if (!paletteHandle) return;
shun_iwasawa e553fc
  disconnect(paletteHandle, SIGNAL(colorStyleChanged(bool)), this,
shun_iwasawa e553fc
             SLOT(update()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Manage page tooltip.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
bool PageViewer::event(QEvent *e) {
Shinya Kitaoka 120a6e
  if (m_page && e->type() == QEvent::ToolTip) {
Shinya Kitaoka 120a6e
    QHelpEvent *helpEvent = dynamic_cast<qhelpevent *="">(e);</qhelpevent>
Shinya Kitaoka 120a6e
    QString toolTip;
Shinya Kitaoka 120a6e
    QPoint pos      = helpEvent->pos();
Shinya Kitaoka 120a6e
    int indexInPage = posToIndex(pos);
Shinya Kitaoka 120a6e
    if (0 <= indexInPage && indexInPage < m_page->getStyleCount()) {
Shinya Kitaoka 120a6e
      TColorStyle *style = m_page->getStyle(indexInPage);
Shinya Kitaoka 120a6e
      if (style) {
shun-iwasawa 726b1d
        int styleIndex = m_page->getStyleId(indexInPage);
shun-iwasawa 726b1d
        toolTip        = "#" + QString::number(styleIndex) + " " +
Shinya Kitaoka 120a6e
                  QString::fromStdWString(style->getName());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        int shortcutKey = m_page->getPalette()->getStyleShortcut(styleIndex);
Shinya Kitaoka 120a6e
        if (shortcutKey > 0)
Shinya Kitaoka 120a6e
          toolTip += QString::fromStdWString(std::wstring(L" (") +
Shinya Kitaoka 120a6e
                                             (wchar_t)shortcutKey + L")");
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
shun-iwasawa 726b1d
    if (ShowNewStyleButton && indexInPage == m_page->getStyleCount()) {
shun-iwasawa 726b1d
      toolTip = tr("New Style");
DoctorRyan 16d12c
    }
Shinya Kitaoka 120a6e
    if (toolTip != "")
Shinya Kitaoka 120a6e
      QToolTip::showText(helpEvent->globalPos(), toolTip);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      QToolTip::hideText();
Shinya Kitaoka 120a6e
    e->accept();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
                selected; remove it from style selection otherwise. Manage CTRL
Shinya Kitaoka 120a6e
   SHIFT
Shinya Kitaoka 120a6e
                pressed case.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PageViewer::select(int indexInPage, QMouseEvent *event) {
Shinya Kitaoka 120a6e
  bool selected = false;
Shinya Kitaoka 120a6e
  assert(m_page);
Shinya Kitaoka 120a6e
  TPalette *palette = m_page->getPalette();
Shinya Kitaoka 120a6e
  int pageIndex     = m_page->getIndex();
Shinya Kitaoka 120a6e
  bool on           = true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool wasSelected = m_styleSelection->isSelected(pageIndex, indexInPage);
Shinya Kitaoka 120a6e
  if (event->modifiers() == Qt::NoModifier)
Shinya Kitaoka 120a6e
    m_styleSelection->selectNone();
Shinya Kitaoka 120a6e
  else if (event->modifiers() == Qt::CTRL && wasSelected)
Shinya Kitaoka 120a6e
    on = false;
Shinya Kitaoka 120a6e
  else if (event->modifiers() == Qt::SHIFT && !m_styleSelection->isEmpty()) {
Shinya Kitaoka 120a6e
    // premuto shift. la selezione si estende fino ai piu' vicini colori
Shinya Kitaoka 120a6e
    // selezionati (prima e dopo)
Shinya Kitaoka 120a6e
    // a e' b diventeranno gli estremi della selezione
Shinya Kitaoka 120a6e
    int a = -1, b = -1, i = 0;
Shinya Kitaoka 120a6e
    for (i = 0; i < m_page->getStyleCount(); i++)
Shinya Kitaoka 120a6e
      if (m_styleSelection->isSelected(pageIndex, i)) {
Shinya Kitaoka 120a6e
        if (i < indexInPage)
Shinya Kitaoka 120a6e
          a = i;
Shinya Kitaoka 120a6e
        else if (i > indexInPage) {
Shinya Kitaoka 120a6e
          b = i;
Shinya Kitaoka 120a6e
          break;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    if (a >= 0 && b >= 0) {
Shinya Kitaoka 120a6e
      assert(a < indexInPage && indexInPage < b);
Shinya Kitaoka 120a6e
      a++;
Shinya Kitaoka 120a6e
      b--;
Shinya Kitaoka 120a6e
    } else if (a >= 0) {
Shinya Kitaoka 120a6e
      assert(b < 0 && a < indexInPage);
Shinya Kitaoka 120a6e
      a++;
Shinya Kitaoka 120a6e
      b = indexInPage;
Shinya Kitaoka 120a6e
    } else if (b >= 0) {
Shinya Kitaoka 120a6e
      assert(a < 0 && indexInPage < b);
Shinya Kitaoka 120a6e
      b--;
Shinya Kitaoka 120a6e
      a = indexInPage;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      a = b = indexInPage;
Shinya Kitaoka 120a6e
    for (i = a; i <= b; i++) {
Shinya Kitaoka 120a6e
      m_styleSelection->select(pageIndex, i, true);
Shinya Kitaoka 120a6e
      selected = true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isStyleChanged = false;
shun-iwasawa 443318
  if (on) selected = true;
shun-iwasawa 443318
  int styleIndex = m_page->getStyleId(indexInPage);
Shinya Kitaoka 120a6e
  if (selected) {
Shinya Kitaoka 120a6e
    setCurrentStyleIndex(styleIndex);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ChangeStyleCommand *changeStyleCommand = getChangeStyleCommand();
Shinya Kitaoka 120a6e
    if (changeStyleCommand)
Shinya Kitaoka 120a6e
      isStyleChanged = changeStyleCommand->onStyleChanged();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (!isStyleChanged) {
Shinya Kitaoka 120a6e
    m_styleSelection->select(pageIndex, indexInPage, on);
Shinya Kitaoka 120a6e
    m_styleSelection->makeCurrent();
Shinya Kitaoka 120a6e
    updateCommandLocks();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Compute page size in regard to chip count.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::computeSize() {
Shinya Kitaoka 120a6e
  if (!m_page) {
Shinya Kitaoka 120a6e
    m_chipPerRow = 0;
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int w          = parentWidget()->width();
Shinya Kitaoka 120a6e
  int chipCount  = getChipCount();
Shinya Kitaoka 120a6e
  QSize chipSize = getChipSize();
Shinya Kitaoka 120a6e
  m_chipPerRow   = m_viewMode == List ? 1 : (w - 8) / chipSize.width();
Shinya Kitaoka 120a6e
  if (m_chipPerRow == 0) m_chipPerRow = 1;
shun-iwasawa 726b1d
  if (ShowNewStyleButton) chipCount++;
shun-iwasawa 726b1d
  int rowCount = (chipCount + m_chipPerRow - 1) / m_chipPerRow;
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
                current frame.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PageViewer::onFrameChanged() {
Shinya Kitaoka 120a6e
  TPalette *palette = (m_page) ? m_page->getPalette() : 0;
Shinya Kitaoka 120a6e
  if (palette && palette->isAnimated()) update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Rename current style and update its view in current page.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
// recall from m_renameTextField
Shinya Kitaoka 120a6e
void PageViewer::onStyleRenamed() {
Shinya Kitaoka 120a6e
  m_renameTextField->hide();
Shinya Kitaoka 120a6e
  std::wstring newName = m_renameTextField->text().toStdWString();
Shinya Kitaoka 120a6e
  assert(getPaletteHandle());
Shinya Kitaoka 120a6e
  PaletteCmd::renamePaletteStyle(getPaletteHandle(), newName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
shun_iwasawa 4635d8
shun_iwasawa 4635d8
bool PageViewer::hasShortcut(int indexInPage) {
shun_iwasawa 4635d8
  if (!m_page) return false;
shun_iwasawa 4635d8
  if (indexInPage < 0 || indexInPage >= m_page->getStyleCount()) return false;
shun_iwasawa 4635d8
  int styleIndex = m_page->getStyleId(indexInPage);
shun_iwasawa 4635d8
  return (m_page->getPalette()->getStyleShortcut(styleIndex) >= 0);
shun_iwasawa 4635d8
}
shun_iwasawa 4635d8
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*! \class PaletteViewerGUI::PaletteTabBar
Shinya Kitaoka 120a6e
                \brief The PaletteTabBar class provides a bar with tab to show
Shinya Kitaoka 120a6e
   and manage palette
Shinya Kitaoka 120a6e
                page.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                Inherits \b QTabBar.
Shinya Kitaoka 120a6e
                This object allows to move a tab with mouseMoveEvent, rename a
Shinya Kitaoka 120a6e
   tab in
Shinya Kitaoka 120a6e
                doubleClickevent and create a new tab in drag and drop.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
/*!	\fn void PaletteTabBar::setPageViewer(PageViewer *pageViewer)
Shinya Kitaoka 120a6e
                Set current tab bar page to \b pageViewer.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                \fn void PaletteTabBar::tabTextChanged(int index)
Shinya Kitaoka 120a6e
                This signal is emitted when tab associated text change.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
                \fn void PaletteTabBar::movePage(int srcIndex, int dstIndex)
Shinya Kitaoka 120a6e
                This signal is emitted to notify tab position change.
Shinya Kitaoka 120a6e
                */
Toshihiro Shimizu 890ddd
PaletteTabBar::PaletteTabBar(QWidget *parent, bool hasPageCommand)
Shinya Kitaoka 120a6e
    : QTabBar(parent)
Shinya Kitaoka 120a6e
    , m_renameTextField(new LineEdit(this))
Shinya Kitaoka 120a6e
    , m_renameTabIndex(-1)
Shinya Kitaoka 120a6e
    , m_pageViewer(0)
Shinya Kitaoka 120a6e
    , m_hasPageCommand(hasPageCommand) {
Shinya Kitaoka 120a6e
  setObjectName("PaletteTabBar");
Shinya Kitaoka 120a6e
  setDrawBase(false);
Shinya Kitaoka 120a6e
  m_renameTextField->hide();
Shinya Kitaoka 120a6e
  connect(m_renameTextField, SIGNAL(editingFinished()), this,
Shinya Kitaoka 120a6e
          SLOT(updateTabName()));
Shinya Kitaoka 120a6e
  if (m_hasPageCommand) setAcceptDrops(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Hide rename text field and recall \b QTabBar::mousePressEvent().
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PaletteTabBar::mousePressEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  m_renameTextField->hide();
Shinya Kitaoka 120a6e
  QTabBar::mousePressEvent(event);
Shinya Kitaoka 120a6e
  m_pageViewer->getSelection()->select(currentIndex());
Shinya Kitaoka 120a6e
  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.
Shinya Kitaoka 120a6e
                In any case recall \b QTabBar::mousePressEvent().
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteTabBar::mouseMoveEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  if (event->buttons() == Qt::LeftButton &&
Shinya Kitaoka 120a6e
      event->modifiers() == Qt::ControlModifier &&
Shinya Kitaoka 120a6e
      !m_pageViewer->getPage()->getPalette()->isLocked()) {
Shinya Kitaoka 120a6e
    int srcIndex = currentIndex();
Shinya Kitaoka 120a6e
    int dstIndex = tabAt(event->pos());
Shinya Kitaoka 120a6e
    if (dstIndex >= 0 && dstIndex < count() && dstIndex != srcIndex) {
Shinya Kitaoka 120a6e
      QRect rect = tabRect(srcIndex);
Shinya Kitaoka 120a6e
      int x      = event->pos().x();
Shinya Kitaoka 120a6e
      if (x < rect.left() || x > rect.right()) {
Shinya Kitaoka 120a6e
        emit movePage(srcIndex, dstIndex);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PaletteTabBar::mouseDoubleClickEvent(QMouseEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_hasPageCommand) return;
Shinya Kitaoka 120a6e
  if (m_pageViewer->getPage()->getPalette()->isLocked()) return;
Shinya Kitaoka 120a6e
  int index = tabAt(event->pos());
Shinya Kitaoka 120a6e
  if (index < 0) return;
Shinya Kitaoka 120a6e
  m_renameTabIndex = index;
Shinya Kitaoka 120a6e
  LineEdit *fld    = m_renameTextField;
Shinya Kitaoka 120a6e
  fld->setText(tabText(index));
Shinya Kitaoka 120a6e
  fld->setGeometry(tabRect(index));
Shinya Kitaoka 120a6e
  fld->setAlignment(Qt::AlignCenter);
Shinya Kitaoka 120a6e
  fld->show();
Shinya Kitaoka 120a6e
  fld->selectAll();
Shinya Kitaoka 120a6e
  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.
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PaletteTabBar::dragEnterEvent(QDragEnterEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_hasPageCommand) return;
Shinya Kitaoka 120a6e
  const PaletteData *paletteData =
Shinya Kitaoka 120a6e
      dynamic_cast<const *="" palettedata="">(event->mimeData());</const>
Shinya Kitaoka 120a6e
  if (!paletteData) return;
Shinya Kitaoka 120a6e
  if ((m_pageViewer->getViewType() == CLEANUP_PALETTE &&
Shinya Kitaoka 120a6e
       !paletteData->getPalette()->isCleanupPalette()) ||
Shinya Kitaoka 120a6e
      (m_pageViewer->getViewType() == LEVEL_PALETTE &&
Shinya Kitaoka 120a6e
       paletteData->getPalette()->isCleanupPalette())) {
Shinya Kitaoka 120a6e
    event->ignore();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
                recalling PageViewer::createDropPage().
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteTabBar::dragMoveEvent(QDragMoveEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_hasPageCommand) return;
Shinya Kitaoka 120a6e
  const PaletteData *paletteData =
Shinya Kitaoka 120a6e
      dynamic_cast<const *="" palettedata="">(event->mimeData());</const>
Shinya Kitaoka 120a6e
  if (!paletteData) return;
Shinya Kitaoka 120a6e
  if (paletteData->getPalette() == m_pageViewer->getPage()->getPalette() &&
Shinya Kitaoka 120a6e
      paletteData->hasOnlyPalette())
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  int tabIndex = tabAt(event->pos());
Shinya Kitaoka 120a6e
  if (0 <= tabIndex && tabIndex < count())
Shinya Kitaoka 120a6e
    setCurrentIndex(tabIndex);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_pageViewer->createDropPage();
Shinya Kitaoka 120a6e
  event->acceptProposedAction();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Recall PageViewer::drop().
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PaletteTabBar::dropEvent(QDropEvent *event) {
Shinya Kitaoka 120a6e
  if (!m_hasPageCommand) return;
Shinya Kitaoka 120a6e
  if (!dynamic_cast<const *="" palettedata="">(event->mimeData())) return;</const>
Shinya Kitaoka 120a6e
  m_pageViewer->drop(-1, event->mimeData());
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
                field text; hide the rename text field and emit tabTextChanged()
Shinya Kitaoka 120a6e
   signal.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
void PaletteTabBar::updateTabName() {
Shinya Kitaoka 120a6e
  int index = m_renameTabIndex;
Shinya Kitaoka 120a6e
  if (index < 0) return;
Shinya Kitaoka 120a6e
  m_renameTabIndex = -1;
Shinya Kitaoka 120a6e
  if (m_renameTextField->text() != "")
Shinya Kitaoka 120a6e
    setTabText(index, m_renameTextField->text());
Shinya Kitaoka 120a6e
  m_renameTextField->hide();
Shinya Kitaoka 120a6e
  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
PaletteIconWidget::PaletteIconWidget(QWidget *parent, Qt::WindowFlags flags)
Shinya Kitaoka 120a6e
    : QWidget(parent, flags), m_isOver(false) {
Shinya Kitaoka 120a6e
  setFixedSize(30, 20);
Kite 521c84
  setToolTip(QObject::tr("Click & Drag Palette into Studio Palette"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PaletteIconWidget::~PaletteIconWidget() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteIconWidget::paintEvent(QPaintEvent *) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Kite 521c84
  // generate icon and extract the pixmaps
Kite 521c84
  QIcon dragPaletteIcon = createQIcon("dragpalette");
Shinya Kitaoka 120a6e
  if (m_isOver) {
shun_iwasawa 3cc41f
    static QPixmap dragPaletteIconPixmapOver(
Kite 521c84
        dragPaletteIcon.pixmap(20, QIcon::Active));
shun_iwasawa 3cc41f
    p.drawPixmap(5, 1, dragPaletteIconPixmapOver);
Shinya Kitaoka 120a6e
  } else {
shun_iwasawa 3cc41f
    static QPixmap dragPaletteIconPixmap(
Kite 521c84
        dragPaletteIcon.pixmap(20, QIcon::Normal, QIcon::Off));
shun_iwasawa 3cc41f
    p.drawPixmap(5, 1, dragPaletteIconPixmap);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteIconWidget::mousePressEvent(QMouseEvent *me) {
Shinya Kitaoka 120a6e
  if (me->button() != Qt::LeftButton) {
Shinya Kitaoka 120a6e
    me->ignore();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_mousePressPos = me->pos();
Shinya Kitaoka 120a6e
  m_dragged       = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteIconWidget::mouseMoveEvent(QMouseEvent *me) {
Shinya Kitaoka 120a6e
  if ((me->pos() - m_mousePressPos).manhattanLength() > 20 && !m_dragged) {
Shinya Kitaoka 120a6e
    m_dragged = true;
Shinya Kitaoka 120a6e
    emit startDrag();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteIconWidget::enterEvent(QEvent *event) { m_isOver = true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PaletteIconWidget::leaveEvent(QEvent *event) { m_isOver = false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::zoomInChip() {
Shinya Kitaoka 120a6e
  ViewMode currentView = getViewMode();
Shinya Kitaoka 120a6e
  if (currentView == List || currentView == LargeChips)
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  else if (currentView == SmallChips)
Shinya Kitaoka 120a6e
    setViewMode(MediumChips);
Shinya Kitaoka 120a6e
  else if (currentView == MediumChips)
Shinya Kitaoka 120a6e
    setViewMode(LargeChips);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void PageViewer::zoomOutChip() {
Shinya Kitaoka 120a6e
  ViewMode currentView = getViewMode();
Shinya Kitaoka 120a6e
  if (currentView == List || currentView == SmallChips)
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  else if (currentView == LargeChips)
Shinya Kitaoka 120a6e
    setViewMode(MediumChips);
Shinya Kitaoka 120a6e
  else if (currentView == MediumChips)
Shinya Kitaoka 120a6e
    setViewMode(SmallChips);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PageViewer::setNameDisplayMode(NameDisplayMode mode) {
Shinya Kitaoka 120a6e
  if (m_nameDisplayMode == mode) return;
Shinya Kitaoka 120a6e
  m_nameDisplayMode = mode;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! lock the commands when the styleSelection set to current
shun-iwasawa b37337
 */
Shinya Kitaoka 120a6e
void PageViewer::updateCommandLocks() {
Shinya Kitaoka 120a6e
  if (!m_page) return;
Shinya Kitaoka 120a6e
  // iwasawa
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isLocked = m_page->getPalette()->isLocked();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CommandManager *cmd = CommandManager::instance();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  cmd->getAction("MI_Paste")->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
  cmd->getAction("MI_PasteValues")->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
  cmd->getAction("MI_PasteColors")->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
  cmd->getAction("MI_Clear")->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
  cmd->getAction("MI_BlendColors")->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
  cmd->getAction("MI_PasteNames")->setEnabled(!isLocked);
Shinya Kitaoka 120a6e
  cmd->getAction("MI_GetColorFromStudioPalette")->setEnabled(!isLocked);
Jeremy Bullock 0b1ad7
  cmd->getAction("MI_ToggleLinkToStudioPalette")->setEnabled(!isLocked);
Jeremy Bullock 0b1ad7
  cmd->getAction("MI_RemoveReferenceToStudioPalette")->setEnabled(!isLocked);
shun-iwasawa b37337
  cmd->getAction("MI_EraseUnusedStyles")->setEnabled(!isLocked);
DoctorRyan 16d12c
  update();
Toshihiro Shimizu 890ddd
}