Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/functionsheet.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/functionviewer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/doubleparamcmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Jeremy Bullock 4ce953
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tunit.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "../toonz/menubarcommandids.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qgridlayout></qgridlayout>
Toshihiro Shimizu 890ddd
#include <qpaintevent></qpaintevent>
Toshihiro Shimizu 890ddd
#include <qmenu></qmenu>
Shinya Kitaoka 120a6e
#include <qapplication>  //for drag&drop</qapplication>
Toshihiro Shimizu 890ddd
#include <qdrag></qdrag>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace stuff
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const int cColumnDragHandleWidth = 8;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const int cGroupShortNameY =
Shinya Kitaoka 120a6e
    0;  //!< Column header's y pos for channel groups' short name tabs
Shinya Kitaoka 120a6e
const int cGroupLongNameY = 27;  //!< Same for its long name tabs
Shinya Kitaoka 120a6e
const int cChannelNameY = 50;  //!< Column header's y pos of channel name tabs,
Shinya Kitaoka 38fd86
                               //! up to the widget's height
Shinya Kitaoka 120a6e
const int cColHeadersEndY = 87;  //!< End of column headers y pos
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    Function Sheet Tools
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*--- NumericalColumnsのセグメントの左側のバーをクリックしたとき ---*/
Shinya Kitaoka d1f6c4
class MoveChannelsDragTool final : public Spreadsheet::DragTool {
Shinya Kitaoka 120a6e
  FunctionSheet *m_sheet;
Shinya Kitaoka 120a6e
  std::vector<keyframesetter *=""> m_setters;</keyframesetter>
Shinya Kitaoka 120a6e
  int m_oldRow;
Shinya Kitaoka 120a6e
  QRect m_selectedCells;
Shinya Kitaoka 120a6e
  int m_firstKeyframeRow;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MoveChannelsDragTool(FunctionSheet *sheet)
Shinya Kitaoka 120a6e
      : m_sheet(sheet), m_firstKeyframeRow(-1) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void click(int row, int col, QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    m_firstKeyframeRow                  = -1;
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *channel = m_sheet->getChannel(col);
Shinya Kitaoka 120a6e
    if (!channel) return;
Shinya Kitaoka 120a6e
    TDoubleParam *curve = channel->getParam();
Shinya Kitaoka 120a6e
    int k0 = -1, k1 = -1;
Shinya Kitaoka 120a6e
    if (curve->isKeyframe(row))
Shinya Kitaoka 120a6e
      k0 = k1 = curve->getClosestKeyframe(row);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      k0 = curve->getPrevKeyframe(row);
Shinya Kitaoka 120a6e
      k1 = curve->getNextKeyframe(row);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    // return if clicking outside of the segments
Shinya Kitaoka 120a6e
    if (k0 < 0 || k1 < 0) return;
Shinya Kitaoka 120a6e
    int r0 = tround(curve->keyframeIndexToFrame(k0));
Shinya Kitaoka 120a6e
    int r1 = tround(curve->keyframeIndexToFrame(k1));
Shinya Kitaoka 120a6e
    if (m_sheet->isSelectedCell(row, col)) {
Shinya Kitaoka 120a6e
      m_selectedCells = m_sheet->getSelectedCells();
Shinya Kitaoka 120a6e
      m_selectedCells.setTop(r0);
Shinya Kitaoka 120a6e
      m_selectedCells.setBottom(r1);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      m_selectedCells = QRect(col, r0, 1, r1 - r0 + 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_sheet->selectCells(m_selectedCells);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*---
Shinya Kitaoka 120a6e
シンプルに左のバーをクリックした場合はcolは1つだけ。
Shinya Kitaoka 120a6e
すでに複数Columnが選択されている上でその選択範囲内のセルの左バーをクリックした場合は
Shinya Kitaoka 120a6e
横(Column)幅は選択範囲に順ずるようになる。高さ(row)はクリックしたセグメントと同じになる。
Shinya Kitaoka 120a6e
---*/
Shinya Kitaoka 120a6e
    /*--- セグメントごとドラッグに備えてKeyFrameを格納する ---*/
Shinya Kitaoka 120a6e
    for (int col = m_selectedCells.left(); col <= m_selectedCells.right();
Shinya Kitaoka 120a6e
         ++col) {
Shinya Kitaoka 120a6e
      TDoubleParam *curve = m_sheet->getCurve(col);
Shinya Kitaoka 120a6e
      if (!curve) continue;
Shinya Kitaoka 120a6e
      KeyframeSetter *setter = new KeyframeSetter(curve);
Shinya Kitaoka 120a6e
      for (int k = 0; k < curve->getKeyframeCount(); k++) {
Shinya Kitaoka 120a6e
        int row = (int)curve->keyframeIndexToFrame(k);
Shinya Kitaoka 120a6e
        if (r0 <= row && row <= r1) {
Shinya Kitaoka 120a6e
          if (m_firstKeyframeRow < 0 || row < m_firstKeyframeRow)
Shinya Kitaoka 120a6e
            m_firstKeyframeRow = row;
Shinya Kitaoka 120a6e
          setter->selectKeyframe(k);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      m_setters.push_back(setter);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_oldRow = row;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void drag(int row, int col, QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    int d                             = row - m_oldRow;
Shinya Kitaoka 120a6e
    m_oldRow                          = row;
Shinya Kitaoka 120a6e
    if (d + m_firstKeyframeRow < 0) d = -m_firstKeyframeRow;
Shinya Kitaoka 120a6e
    m_firstKeyframeRow += d;
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)m_setters.size(); i++)
Shinya Kitaoka 120a6e
      m_setters[i]->moveKeyframes(d, 0.0);
Shinya Kitaoka 120a6e
    m_selectedCells.translate(0, d);
Shinya Kitaoka 120a6e
    m_sheet->selectCells(m_selectedCells);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void release(int row, int col, QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    for (int i = 0; i < (int)m_setters.size(); i++) delete m_setters[i];
Shinya Kitaoka 120a6e
    m_setters.clear();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*--- NumericalColumnsのセル部分をクリックしたとき ---*/
Shinya Kitaoka d1f6c4
class FunctionSheetSelectionTool final : public Spreadsheet::DragTool {
Shinya Kitaoka 120a6e
  int m_firstRow, m_firstCol;
Shinya Kitaoka 120a6e
  FunctionSheet *m_sheet;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionSheetSelectionTool(FunctionSheet *sheet)
Shinya Kitaoka 120a6e
      : m_sheet(sheet), m_firstRow(-1), m_firstCol(-1) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void click(int row, int col, QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    if (0 != (e->modifiers() & Qt::ShiftModifier) &&
Shinya Kitaoka 120a6e
        !m_sheet->getSelectedCells().isEmpty()) {
Shinya Kitaoka 120a6e
      QRect selectedCells = m_sheet->getSelectedCells();
Shinya Kitaoka 120a6e
      if (col < selectedCells.center().x()) {
Shinya Kitaoka 120a6e
        m_firstCol = selectedCells.right();
Shinya Kitaoka 120a6e
        selectedCells.setLeft(col);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        m_firstCol = selectedCells.left();
Shinya Kitaoka 120a6e
        selectedCells.setRight(col);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (row < selectedCells.center().y()) {
Shinya Kitaoka 120a6e
        m_firstRow = selectedCells.bottom();
Shinya Kitaoka 120a6e
        selectedCells.setTop(row);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        m_firstRow = selectedCells.top();
Shinya Kitaoka 120a6e
        selectedCells.setBottom(row);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      m_sheet->selectCells(selectedCells);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      // regular click, no shift
Shinya Kitaoka 120a6e
      m_firstCol = col;
Shinya Kitaoka 120a6e
      m_firstRow = row;
Shinya Kitaoka 120a6e
      QRect selectedCells(col, row, 1, 1);
Shinya Kitaoka 120a6e
      m_sheet->selectCells(selectedCells);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void drag(int row, int col, QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    if (row < 0) row = 0;
Shinya Kitaoka 120a6e
    if (col < 0) col = 0;
Shinya Kitaoka 120a6e
    int r0           = qMin(row, m_firstRow);
Shinya Kitaoka 120a6e
    int r1           = qMax(row, m_firstRow);
Shinya Kitaoka 120a6e
    int c0           = qMin(col, m_firstCol);
Shinya Kitaoka 120a6e
    int c1           = qMax(col, m_firstCol);
Shinya Kitaoka 120a6e
    QRect selectedCells(c0, r0, c1 - c0 + 1, r1 - r0 + 1);
Shinya Kitaoka 120a6e
    m_sheet->selectCells(selectedCells);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void release(int row, int col, QMouseEvent *e) override {
Shinya Kitaoka 120a6e
    if (row == m_firstRow && col == m_firstCol) {
Shinya Kitaoka 120a6e
      if (Preferences::instance()->isMoveCurrentEnabled())
Shinya Kitaoka 120a6e
        m_sheet->setCurrentFrame(row);
Shinya Kitaoka 120a6e
      FunctionTreeModel::Channel *channel = m_sheet->getChannel(col);
Shinya Kitaoka 120a6e
      if (channel) channel->setIsCurrent(true);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    FunctionSheetRowViewer  implementation
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FunctionSheetRowViewer::FunctionSheetRowViewer(FunctionSheet *parent)
Shinya Kitaoka 120a6e
    : Spreadsheet::RowPanel(parent), m_sheet(parent) {
Shinya Kitaoka 120a6e
  setMinimumSize(QSize(100, 100));
Shinya Kitaoka 120a6e
  setMouseTracking(true);
Shinya Kitaoka 120a6e
  setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetRowViewer::paintEvent(QPaintEvent *e) {
Shinya Kitaoka 120a6e
  // calls GenericPanel's event
Shinya Kitaoka 120a6e
  Spreadsheet::RowPanel::paintEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetRowViewer::mousePressEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  // calls GenericPanel's event
Shinya Kitaoka 120a6e
  Spreadsheet::RowPanel::mousePressEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetRowViewer::mouseMoveEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  // calls GenericPanel's event
Shinya Kitaoka 120a6e
  Spreadsheet::RowPanel::mouseMoveEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetRowViewer::mouseReleaseEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  Spreadsheet::RowPanel::mouseReleaseEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetRowViewer::contextMenuEvent(QContextMenuEvent *event) {
Shinya Kitaoka 120a6e
  QMenu *menu                = new QMenu(this);
Shinya Kitaoka 120a6e
  CommandManager *cmdManager = CommandManager::instance();
Shinya Kitaoka 120a6e
  menu->addAction(cmdManager->getAction(MI_InsertSceneFrame));
Shinya Kitaoka 120a6e
  menu->addAction(cmdManager->getAction(MI_RemoveSceneFrame));
Shinya Kitaoka 120a6e
  menu->addAction(cmdManager->getAction(MI_InsertGlobalKeyframe));
Shinya Kitaoka 120a6e
  menu->addAction(cmdManager->getAction(MI_RemoveGlobalKeyframe));
Shinya Kitaoka 120a6e
  menu->exec(event->globalPos());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    FunctionSheetColumnHeadViewer  implementation
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FunctionSheetColumnHeadViewer::FunctionSheetColumnHeadViewer(
Shinya Kitaoka 120a6e
    FunctionSheet *parent)
Shinya Kitaoka 120a6e
    : Spreadsheet::ColumnPanel(parent), m_sheet(parent), m_draggingChannel(0) {
Shinya Kitaoka 120a6e
  setMouseTracking(true);  // for updating the tooltip
Shinya Kitaoka 120a6e
  setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetColumnHeadViewer::paintEvent(QPaintEvent *e) {
Shinya Kitaoka 120a6e
  QPainter painter(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QRect toBeUpdated = e->rect();
Shinya Kitaoka 120a6e
  painter.setClipRect(toBeUpdated);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // visible columns range
Jaroslav 203cc8
  CellRange visible = getViewer()->xyRectToRange(toBeUpdated);
Jaroslav 203cc8
  int c0            = visible.from().layer();
Jaroslav 203cc8
  int c1            = visible.to().layer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (c0 > c1) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int n = c1 - c0 + 1 + 2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FunctionTreeModel::ChannelGroup *currentGroup = 0;
Shinya Kitaoka 120a6e
Jaroslav 203cc8
  /*--- Display range + right and left 1 column range ChannelGroup. If there is
Jaroslav 203cc8
   * none, put 0
Shinya Kitaoka 120a6e
   * ---*/
Shinya Kitaoka 120a6e
  std::vector<functiontreemodel::channelgroup *=""> channelGroups(n);</functiontreemodel::channelgroup>
Shinya Kitaoka 120a6e
  for (int i = 0; i < n; ++i) {
Shinya Kitaoka 120a6e
    channelGroups[i] = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int c = c0 - 1 + i;
Shinya Kitaoka 120a6e
    if (c < 0) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *channel = m_sheet->getChannel(c);
Shinya Kitaoka 120a6e
    if (!channel) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    channelGroups[i] = channel->getChannelGroup();
Shinya Kitaoka 120a6e
    if (!currentGroup && channel->isCurrent()) currentGroup = channelGroups[i];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int y0 = 0;
Jaroslav 203cc8
  int y1 = 17;  // needs work
Shinya Kitaoka 120a6e
  int y2 = 34;
Shinya Kitaoka 120a6e
  int y3 = 53;
Shinya Kitaoka 120a6e
Jaroslav 203cc8
  /*--- Fill header with background color ---*/
Shinya Kitaoka 120a6e
  for (int c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *channel = m_sheet->getChannel(c);
Shinya Kitaoka 120a6e
    if (!channel) continue;
Shinya Kitaoka 120a6e
    int x0 = getViewer()->columnToX(c);
Shinya Kitaoka 120a6e
    int x1 = getViewer()->columnToX(c + 1) - 1;
Shinya Kitaoka 120a6e
    // Column Width
Shinya Kitaoka 120a6e
    int width = x1 - x0 + 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    painter.fillRect(x0, y0, width, y3 - y0, getViewer()->getBGColor());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int c = c0; c <= c1; ++c) {
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *channel = m_sheet->getChannel(c);
Shinya Kitaoka 120a6e
    if (!channel) continue;
Shinya Kitaoka 120a6e
    int i = c - c0 + 1;
Jaroslav 203cc8
    /*---- Channel Column of the current Column and the preceding and following
Jaroslav 203cc8
     * Columns ---*/
Shinya Kitaoka 120a6e
    FunctionTreeModel::ChannelGroup *prevGroup = channelGroups[c - c0],
Shinya Kitaoka 120a6e
                                    *group     = channelGroups[c - c0 + 1],
Shinya Kitaoka 120a6e
                                    *nextGroup = channelGroups[c - c0 + 2];
Shinya Kitaoka 120a6e
Jaroslav 203cc8
    /*---- If the group is different from the before and after, flags are set
Jaroslav 203cc8
     * respectively ---*/
Shinya Kitaoka 120a6e
    bool firstGroupColumn = prevGroup != group;
Shinya Kitaoka 120a6e
    bool lastGroupColumn  = nextGroup != group;
Shinya Kitaoka 120a6e
Jaroslav 203cc8
    /*--- The left and right coordinates of the current column ---*/
Shinya Kitaoka 120a6e
    int x0 = getViewer()->columnToX(c);
Shinya Kitaoka 120a6e
    int x1 = getViewer()->columnToX(c + 1) - 1;
Shinya Kitaoka 120a6e
    // Column width
Shinya Kitaoka 120a6e
    int width = x1 - x0 + 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QRect selectedRect = m_sheet->getSelectedCells();
Shinya Kitaoka 120a6e
    bool isSelected =
Shinya Kitaoka 120a6e
        (selectedRect.left() <= c && c <= selectedRect.right()) ? true : false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // paint with light color if selected
Shinya Kitaoka 120a6e
    if (isSelected)
Shinya Kitaoka 120a6e
      painter.fillRect(x0, y1, width, y3 - y1,
Shinya Kitaoka 120a6e
                       getViewer()->getCurrentRowBgColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // draw horizonntal lines
Shinya Kitaoka 120a6e
    painter.setPen(QPen(getViewer()->getColumnHeaderBorderColor(), 3));
Shinya Kitaoka 120a6e
    painter.drawLine(x0, y0, x1, y0);
Shinya Kitaoka 120a6e
    painter.setPen(getViewer()->getColumnHeaderBorderColor());
Shinya Kitaoka 120a6e
    painter.drawLine(x0, y1, x1, y1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // draw vertical bar
Shinya Kitaoka 120a6e
    painter.fillRect(x0, y1, 6, y3 - y1,
Shinya Kitaoka 120a6e
                     getViewer()->getColumnHeaderBorderColor());
Shinya Kitaoka 120a6e
    if (firstGroupColumn)
Shinya Kitaoka 120a6e
      painter.fillRect(x0, y0, 6, y1 - y0,
Shinya Kitaoka 120a6e
                       getViewer()->getColumnHeaderBorderColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // channel name
Shinya Kitaoka 120a6e
    painter.setPen(getViewer()->getTextColor());
Shinya Kitaoka 120a6e
    if (channel->isCurrent())
Shinya Kitaoka 120a6e
      painter.setPen(getViewer()->getSelectedColumnTextColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QString text = channel->getShortName();
Shinya Kitaoka 120a6e
    int d        = 8;
Shinya Kitaoka 120a6e
    painter.drawText(x0 + d, y1, width - d, y3 - y1 + 1,
Shinya Kitaoka 120a6e
                     Qt::TextWrapAnywhere | Qt::AlignLeft | Qt::AlignVCenter,
Shinya Kitaoka 120a6e
                     text);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // group name
Shinya Kitaoka 120a6e
    if (firstGroupColumn) {
Shinya Kitaoka 120a6e
      int tmpwidth = (lastGroupColumn) ? width : width * 2;
Shinya Kitaoka 120a6e
      painter.setPen(getViewer()->getTextColor());
Shinya Kitaoka 120a6e
      if (group == currentGroup)
Shinya Kitaoka 120a6e
        painter.setPen(getViewer()->getSelectedColumnTextColor());
Shinya Kitaoka 120a6e
      text = group->getShortName();
Shinya Kitaoka 120a6e
      painter.drawText(x0 + d, y0, tmpwidth - d, y1 - y0 + 1,
Shinya Kitaoka 120a6e
                       Qt::AlignLeft | Qt::AlignVCenter, text);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! update tooltips
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void FunctionSheetColumnHeadViewer::mouseMoveEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  if ((e->buttons() & Qt::MidButton) && m_draggingChannel &&
Shinya Kitaoka 120a6e
      (e->pos() - m_dragStartPosition).manhattanLength() >=
Shinya Kitaoka 120a6e
          QApplication::startDragDistance()) {
Shinya Kitaoka 120a6e
    QDrag *drag         = new QDrag(this);
Shinya Kitaoka 120a6e
    QMimeData *mimeData = new QMimeData;
Shinya Kitaoka 120a6e
    mimeData->setText(m_draggingChannel->getExprRefName());
Shinya Kitaoka 120a6e
    drag->setMimeData(mimeData);
Shinya Kitaoka 120a6e
    static const QPixmap cursorPixmap(":Resources/dragcursor_exp_text.png");
Shinya Kitaoka 120a6e
    drag->setDragCursor(cursorPixmap, Qt::MoveAction);
Shinya Kitaoka 120a6e
    Qt::DropAction dropAction = drag->exec();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // get the column under the cursor
Jaroslav 203cc8
  int col = getViewer()->xyToPosition(e->pos()).layer();
Shinya Kitaoka 120a6e
  FunctionTreeModel::Channel *channel = m_sheet->getChannel(col);
Shinya Kitaoka 120a6e
  if (!channel) {
Shinya Kitaoka 120a6e
    setToolTip(QString(""));
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    setToolTip(channel->getExprRefName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetColumnHeadViewer::mousePressEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  QPoint pos   = e->pos();
Jaroslav 203cc8
  int currentC = getViewer()->xyToPosition(pos).layer();
Shinya Kitaoka 120a6e
  FunctionTreeModel::Channel *channel;
Shinya Kitaoka 120a6e
  for (int c = 0; c <= m_sheet->getChannelCount(); c++) {
Shinya Kitaoka 120a6e
    channel = m_sheet->getChannel(c);
Shinya Kitaoka 120a6e
    if (!channel || c != currentC) continue;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (channel && e->button() == Qt::MidButton) {
Shinya Kitaoka 120a6e
    m_draggingChannel   = channel;
Shinya Kitaoka 120a6e
    m_dragStartPosition = e->pos();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (channel)
Shinya Kitaoka 120a6e
    channel->setIsCurrent(true);
Shinya Kitaoka 120a6e
  m_draggingChannel = 0;
Shinya Kitaoka 120a6e
  if (!channel) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Open folder
Shinya Kitaoka 120a6e
  FunctionTreeModel::ChannelGroup *channelGroup = channel->getChannelGroup();
Shinya Kitaoka 120a6e
  if (!channelGroup->isOpen())
Shinya Kitaoka 120a6e
    channelGroup->getModel()->setExpandedItem(channelGroup->createIndex(),
Shinya Kitaoka 120a6e
                                              true);
Shinya Kitaoka 120a6e
  // Select all segment
Shinya Kitaoka 120a6e
  std::set<double> frames;</double>
Shinya Kitaoka 120a6e
  channel->getParam()->getKeyframes(frames);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QRect rect(0, 0, 0, 0);
Shinya Kitaoka 120a6e
  if (!frames.empty()) rect = QRect(currentC, 0, 1, (*frames.rbegin()) + 1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  getViewer()->selectCells(rect);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetColumnHeadViewer::contextMenuEvent(QContextMenuEvent *ce) {
Shinya Kitaoka 120a6e
  // First, select column under cursor
Shinya Kitaoka 120a6e
  const QPoint &pos = ce->pos();
Jaroslav 203cc8
  int cursorCol     = getViewer()->xyToPosition(pos).layer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (cursorCol < 0 || cursorCol >= m_sheet->getChannelCount()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FunctionTreeModel::Channel *channel = m_sheet->getChannel(cursorCol);
Shinya Kitaoka 120a6e
  if (!channel) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Ok, now let's summon a context menu with appropriate options
Shinya Kitaoka 120a6e
  FunctionViewer *fv = m_sheet->getViewer();
Shinya Kitaoka 120a6e
  if (!fv) {
Shinya Kitaoka 120a6e
    assert(fv);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const QPoint &globalPos = mapToGlobal(pos);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (pos.y() >= cChannelNameY)
Shinya Kitaoka 120a6e
    fv->openContextMenu(channel, globalPos);
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    FunctionTreeModel::ChannelGroup *group = channel->getChannelGroup();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // In this case, commands are different from the tree view. Rather than
Shinya Kitaoka 120a6e
    // showing in the tree,
Shinya Kitaoka 120a6e
    // channels get ACTIVATED
Shinya Kitaoka 120a6e
    QMenu menu;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QAction showAnimatedOnly(FunctionTreeView::tr("Show Animated Only"), 0);
Shinya Kitaoka 120a6e
    QAction showAll(FunctionTreeView::tr("Show All"), 0);
Shinya Kitaoka 120a6e
    menu.addAction(&showAnimatedOnly);
Shinya Kitaoka 120a6e
    menu.addAction(&showAll);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // execute menu
Shinya Kitaoka 120a6e
    QAction *action = menu.exec(globalPos);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (action != &showAll && action != &showAnimatedOnly) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // Process action
Shinya Kitaoka 120a6e
    if (action == &showAll) {
Shinya Kitaoka 120a6e
      int c, cCount = group->getChildCount();
Shinya Kitaoka 120a6e
      for (c = 0; c != cCount; ++c) {
Shinya Kitaoka 120a6e
        FunctionTreeModel::Channel *channel =
Shinya Kitaoka 120a6e
            dynamic_cast<functiontreemodel::channel *="">(group->getChild(c));</functiontreemodel::channel>
Shinya Kitaoka 120a6e
        if (channel && !channel->isHidden()) channel->setIsActive(true);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (action == &showAnimatedOnly) {
Shinya Kitaoka 120a6e
      int c, cCount = group->getChildCount();
Shinya Kitaoka 120a6e
      for (c = 0; c != cCount; ++c) {
Shinya Kitaoka 120a6e
        FunctionTreeModel::Channel *channel =
Shinya Kitaoka 120a6e
            dynamic_cast<functiontreemodel::channel *="">(group->getChild(c));</functiontreemodel::channel>
Shinya Kitaoka 120a6e
        if (channel && !channel->isHidden())
Shinya Kitaoka 120a6e
          channel->setIsActive(channel->isAnimated());
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    fv->update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    FunctionSheetCellViewer  implementation
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FunctionSheetCellViewer::FunctionSheetCellViewer(FunctionSheet *parent)
Shinya Kitaoka 120a6e
    : Spreadsheet::CellPanel(parent)
Shinya Kitaoka 120a6e
    , m_sheet(parent)
Shinya Kitaoka 120a6e
    , m_editRow(0)
Shinya Kitaoka 120a6e
    , m_editCol(0) {
Shinya Kitaoka 120a6e
  m_lineEdit = new DVGui::LineEdit(this);
Shinya Kitaoka 120a6e
  // lineEdit->setGeometry(10,10,100,30);
Shinya Kitaoka 120a6e
  m_lineEdit->hide();
Shinya Kitaoka 120a6e
  bool ret = connect(m_lineEdit, SIGNAL(editingFinished()), this,
Shinya Kitaoka 120a6e
                     SLOT(onCellEditorEditingFinished()));
Jeremy Bullock 771290
  ret = ret && connect(m_lineEdit, SIGNAL(mouseMoved(QMouseEvent *)), this,
Jeremy Bullock 771290
                       SLOT(onMouseMovedInLineEdit(QMouseEvent *)));
Shinya Kitaoka 120a6e
  assert(ret);
Shinya Kitaoka 120a6e
  setMouseTracking(true);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setFocusProxy(m_lineEdit);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Called when the cell panel is left/right-clicked
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
Spreadsheet::DragTool *FunctionSheetCellViewer::createDragTool(QMouseEvent *e) {
Jaroslav 203cc8
  CellPosition cellPosition = getViewer()->xyToPosition(e->pos());
Jaroslav 203cc8
  int row                   = cellPosition.frame();
Jaroslav 203cc8
  int col                   = cellPosition.layer();
Jaroslav 203cc8
  bool isEmpty              = true;
Jaroslav 203cc8
  TDoubleParam *curve       = m_sheet->getCurve(col);
Shinya Kitaoka 120a6e
  if (curve) {
Shinya Kitaoka 120a6e
    int kCount = curve->getKeyframeCount();
Shinya Kitaoka 120a6e
    if (kCount > 0) {
Shinya Kitaoka 120a6e
      int row0 = (int)curve->keyframeIndexToFrame(0);
Shinya Kitaoka 120a6e
      int row1 = (int)curve->keyframeIndexToFrame(kCount - 1);
Shinya Kitaoka 120a6e
      isEmpty  = row < row0 || row > row1;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!isEmpty) {
Shinya Kitaoka 120a6e
    int x = e->pos().x() - getViewer()->columnToX(col);
Shinya Kitaoka 120a6e
    if (0 <= x && x < cColumnDragHandleWidth + 9)
Shinya Kitaoka 120a6e
      return new MoveChannelsDragTool(m_sheet);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return new FunctionSheetSelectionTool(m_sheet);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // return Spreadsheet::CellPanel::createDragTool(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::drawCells(QPainter &painter, int r0, int c0,
Shinya Kitaoka 120a6e
                                        int r1, int c1) {
Shinya Kitaoka 120a6e
  // key frames
Shinya Kitaoka 120a6e
  QColor KeyFrameColor         = getViewer()->getKeyFrameColor();
Shinya Kitaoka 120a6e
  QColor KeyFrameBorderColor   = getViewer()->getKeyFrameBorderColor();
Shinya Kitaoka 120a6e
  QColor SelectedKeyFrameColor = getViewer()->getSelectedKeyFrameColor();
Shinya Kitaoka 120a6e
  // inbetween
Shinya Kitaoka 120a6e
  QColor InBetweenColor         = getViewer()->getInBetweenColor();
Shinya Kitaoka 120a6e
  QColor InBetweenBorderColor   = getViewer()->getInBetweenBorderColor();
Shinya Kitaoka 120a6e
  QColor SelectedInBetweenColor = getViewer()->getSelectedInBetweenColor();
Shinya Kitaoka 120a6e
  // empty cells
Shinya Kitaoka 120a6e
  QColor SelectedEmptyColor = getViewer()->getSelectedEmptyColor();
Shinya Kitaoka 120a6e
  // empty cells in scene frame range
Shinya Kitaoka 120a6e
  QColor SelectedSceneRangeEmptyColor =
Shinya Kitaoka 120a6e
      getViewer()->getSelectedSceneRangeEmptyColor();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // top and bottom pos
Shinya Kitaoka 120a6e
  int y0 = getViewer()->rowToY(r0);
Shinya Kitaoka 120a6e
  int y1 = getViewer()->rowToY(r1 + 1) - 1;
Shinya Kitaoka 120a6e
  for (int c = c0; c <= c1; c++) {
Shinya Kitaoka 120a6e
    TDoubleParam *curve = m_sheet->getCurve(c);
Shinya Kitaoka 120a6e
    /*--- もしカラムcにパラメータが無ければcurveには0が返る ---*/
Shinya Kitaoka 120a6e
    if (!curve) continue;
Shinya Kitaoka 120a6e
    // left and right pos
Shinya Kitaoka 120a6e
    int x0 = getViewer()->columnToX(c);
Shinya Kitaoka 120a6e
    int x1 = getViewer()->columnToX(c + 1) - 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // find the curve keyframe range
Shinya Kitaoka 120a6e
    int kr0 = 0, kr1 = -1;
Shinya Kitaoka 120a6e
    int kCount = curve->getKeyframeCount();
Shinya Kitaoka 120a6e
    if (kCount > 0) {
Shinya Kitaoka 120a6e
      kr0 = curve->keyframeIndexToFrame(0);
Shinya Kitaoka 120a6e
      kr1 = curve->keyframeIndexToFrame(kCount - 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // get the unit
Shinya Kitaoka 120a6e
    TMeasure *measure = curve->getMeasure();
Shinya Kitaoka 120a6e
    const TUnit *unit = measure ? measure->getCurrentUnit() : 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // draw each cell
Shinya Kitaoka 120a6e
    for (int row = r0; row <= r1; row++) {
Shinya Kitaoka 120a6e
      int ya = m_sheet->rowToY(row);
Shinya Kitaoka 120a6e
      int yb = m_sheet->rowToY(row + 1) - 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      bool isSelected = getViewer()->isSelectedCell(row, c);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      double value    = curve->getValue(row);
Shinya Kitaoka 120a6e
      if (unit) value = unit->convertTo(value);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      QRect cellRect(x0, ya, x1 - x0 + 1, yb - ya + 1);
Shinya Kitaoka 120a6e
      QRect borderRect(x0, ya, 7, yb - ya + 1);
Shinya Kitaoka 120a6e
      QColor cellColor, borderColor;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      /*--- キーフレーム間の範囲だけ色をつける ---*/
Shinya Kitaoka 120a6e
      if (kr0 <= row && row <= kr1) {
Shinya Kitaoka 120a6e
        if (curve->isKeyframe(row)) {
Shinya Kitaoka 120a6e
          cellColor   = (isSelected) ? SelectedKeyFrameColor : KeyFrameColor;
Shinya Kitaoka 120a6e
          borderColor = KeyFrameBorderColor;
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          cellColor   = (isSelected) ? SelectedInBetweenColor : InBetweenColor;
Shinya Kitaoka 120a6e
          borderColor = InBetweenBorderColor;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        painter.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
        painter.fillRect(cellRect, cellColor);
Shinya Kitaoka 120a6e
        painter.fillRect(borderRect, borderColor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // display whether segment are Linked
Shinya Kitaoka 120a6e
        if (curve->isKeyframe(row)) {
Shinya Kitaoka 120a6e
          TDoubleKeyframe kf = curve->getKeyframeAt(row);
Shinya Kitaoka 120a6e
          // if the segments are NOT linked, then cut off the side bar
Shinya Kitaoka 120a6e
          if (!kf.m_linkedHandles) {
Shinya Kitaoka 120a6e
            int rowCenterPos = (ya + yb) / 2;
Shinya Kitaoka 120a6e
            QPoint points[4] = {
Shinya Kitaoka 120a6e
                QPoint(x0, rowCenterPos), QPoint(x0 + 7, rowCenterPos + 3),
Shinya Kitaoka 120a6e
                QPoint(x0 + 7, rowCenterPos - 3), QPoint(x0, rowCenterPos)};
Shinya Kitaoka 120a6e
            QBrush oldBrush = painter.brush();
Shinya Kitaoka 120a6e
            painter.setBrush(QBrush(cellColor));
Shinya Kitaoka 120a6e
            painter.drawPolygon(points, 4);
Shinya Kitaoka 120a6e
            painter.setBrush(oldBrush);
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // draw cell value
Shinya Kitaoka 120a6e
        painter.setPen(getViewer()->getTextColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        /*--- 整数から小数点以下3桁以内の場合はそれ以降の0000を描かない ---*/
Shinya Kitaoka 120a6e
        QString text;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        double thousandValue = value * 1000.0;
Shinya Kitaoka 120a6e
        if (areAlmostEqual(thousandValue, (double)tround(thousandValue),
Shinya Kitaoka 120a6e
                           0.0001)) {
Shinya Kitaoka 120a6e
          text = QString::number(value, 'f', 3);
Shinya Kitaoka 120a6e
          while (text.endsWith("0")) {
Shinya Kitaoka 120a6e
            text.chop(1);
Shinya Kitaoka 120a6e
            if (text.endsWith(".")) {
Shinya Kitaoka 120a6e
              text.chop(1);
Shinya Kitaoka 120a6e
              break;
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          text = QString::number(value, 'f', 4);
Shinya Kitaoka 120a6e
          text.truncate(5);
Shinya Kitaoka 120a6e
          text.append("~");
Shinya Kitaoka 120a6e
        }
Toshihiro Shimizu 890ddd
Jeremy Bullock 807052
        QString fontName = Preferences::instance()->getInterfaceFont();
Jeremy Bullock 807052
        if (fontName == "") {
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Jeremy Bullock 807052
          fontName = "Arial";
Toshihiro Shimizu 890ddd
#else
Jeremy Bullock 807052
          fontName = "Helvetica";
Toshihiro Shimizu 890ddd
#endif
Jeremy Bullock 807052
        }
Jeremy Bullock 807052
        static QFont font(fontName, -1, QFont::Bold);
shun_iwasawa 01e417
        font.setPixelSize(12);
Shinya Kitaoka 120a6e
        painter.setFont(font);
Shinya Kitaoka 120a6e
        painter.drawText(cellRect.adjusted(10, 0, 0, 0),
Shinya Kitaoka 120a6e
                         Qt::AlignVCenter | Qt::AlignLeft, text);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      // empty and selected cell
Shinya Kitaoka 120a6e
      else if (isSelected) {
Shinya Kitaoka 120a6e
        int rowCount = getViewer()->getRowCount();
Shinya Kitaoka 120a6e
        cellColor    = (row >= rowCount) ? SelectedEmptyColor
Shinya Kitaoka 120a6e
                                      : SelectedSceneRangeEmptyColor;
Shinya Kitaoka 120a6e
        painter.setPen(Qt::NoPen);
Shinya Kitaoka 120a6e
        painter.fillRect(cellRect, cellColor);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::mouseDoubleClickEvent(QMouseEvent *e) {
Jaroslav 203cc8
  CellPosition cellPosition = getViewer()->xyToPosition(e->pos());
Jaroslav 203cc8
  int row                   = cellPosition.frame();
Jaroslav 203cc8
  int col                   = cellPosition.layer();
Shinya Kitaoka 120a6e
  int x0, y0, x1, y1;
Shinya Kitaoka 120a6e
  x0 = getViewer()->columnToX(col);
Shinya Kitaoka 120a6e
  x1 = getViewer()->columnToX(col + 1) - 1;
Shinya Kitaoka 120a6e
  y0 = getViewer()->rowToY(row);
Shinya Kitaoka 120a6e
  y1 = getViewer()->rowToY(row + 1) - 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_editRow = row;
Shinya Kitaoka 120a6e
  m_editCol = col;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParam *curve = m_sheet->getCurve(col);
Shinya Kitaoka 120a6e
  if (curve) {
Shinya Kitaoka 120a6e
    double v          = curve->getValue(row);
Shinya Kitaoka 120a6e
    TMeasure *measure = curve->getMeasure();
Shinya Kitaoka 120a6e
    const TUnit *unit = measure ? measure->getCurrentUnit() : 0;
Shinya Kitaoka 120a6e
    if (unit) v       = unit->convertTo(v);
Jeremy Bullock 771290
    m_currentValue    = v;
Shinya Kitaoka 120a6e
    m_lineEdit->setText(QString::number(v, 'f', 4));
Shinya Kitaoka 120a6e
    // in order to put the cursor to the left end
Shinya Kitaoka 120a6e
    m_lineEdit->setSelection(m_lineEdit->text().length(),
Shinya Kitaoka 120a6e
                             -m_lineEdit->text().length());
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_lineEdit->setText("");
Toshihiro Shimizu 890ddd
Jeremy Bullock 807052
  QString fontName = Preferences::instance()->getInterfaceFont();
Jeremy Bullock 807052
  if (fontName == "") {
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Jeremy Bullock 807052
    fontName = "Arial";
Toshihiro Shimizu 890ddd
#else
Jeremy Bullock 807052
    fontName = "Helvetica";
Toshihiro Shimizu 890ddd
#endif
Jeremy Bullock 807052
  }
Jeremy Bullock 807052
  static QFont font(fontName, 9, QFont::Normal);
Shinya Kitaoka 120a6e
  m_lineEdit->setFont(font);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_lineEdit->setGeometry(x0 - 2, y0 - 2, x1 - x0 + 1 + 4,
Shinya Kitaoka 120a6e
                          y1 - y0 + 1 + 4);  // x0,y0,x1-x0+1,y0-y1+1);
Shinya Kitaoka 120a6e
  m_lineEdit->show();
Shinya Kitaoka 120a6e
  m_lineEdit->raise();
Shinya Kitaoka 120a6e
  m_lineEdit->setFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::onCellEditorEditingFinished() {
Shinya Kitaoka 120a6e
  QString text = m_lineEdit->text();
Jeremy Bullock 771290
  if (!text.isEmpty() &&
Jeremy Bullock 771290
      (m_lineEdit->isReturnPressed() || m_lineEdit->getMouseDragEditing())) {
Shinya Kitaoka 120a6e
    double value        = text.toDouble();
Shinya Kitaoka 120a6e
    TDoubleParam *curve = m_sheet->getCurve(m_editCol);
Shinya Kitaoka 120a6e
    if (curve) {
Shinya Kitaoka 120a6e
      TMeasure *measure = curve->getMeasure();
Shinya Kitaoka 120a6e
      const TUnit *unit = measure ? measure->getCurrentUnit() : 0;
Shinya Kitaoka 120a6e
      if (unit) value   = unit->convertFrom(value);
Shinya Kitaoka 120a6e
      KeyframeSetter::setValue(curve, m_editRow, value);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_lineEdit->hide();
Shinya Kitaoka 120a6e
  m_lineEdit->clearFocus();
Shinya Kitaoka 120a6e
  m_sheet->setFocus();
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::mousePressEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  // escape from the line edit by clicking outside
Shinya Kitaoka 120a6e
  if (m_lineEdit->isVisible()) {
Shinya Kitaoka 120a6e
    m_lineEdit->hide();
Shinya Kitaoka 120a6e
    m_lineEdit->clearFocus();
Shinya Kitaoka 120a6e
    m_sheet->setFocus();
Shinya Kitaoka 120a6e
  }
Jeremy Bullock 771290
  if (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier) {
Jeremy Bullock 771290
    mouseDoubleClickEvent(e);
Jeremy Bullock 771290
    if (m_lineEdit->text() != "") {
Jeremy Bullock 771290
      m_lineEdit->setMouseDragEditing(true);
Jeremy Bullock 771290
      m_mouseXPosition = e->x();
Jeremy Bullock 771290
    }
Jeremy Bullock 771290
  } else if (e->button() == Qt::LeftButton &&
Jeremy Bullock 771290
             e->modifiers() == Qt::AltModifier) {
Jeremy Bullock 771290
    CellPosition cellPosition = getViewer()->xyToPosition(e->pos());
Jeremy Bullock 771290
    int row                   = cellPosition.frame();
Jeremy Bullock 771290
    int col                   = cellPosition.layer();
Jeremy Bullock 771290
    TDoubleParam *curve       = m_sheet->getCurve(col);
Jeremy Bullock 771290
    if (curve) {
Jeremy Bullock 771290
      KeyframeSetter::removeKeyframeAt(curve, row);
Jeremy Bullock 771290
    }
Jeremy Bullock 771290
  } else if (e->button() == Qt::LeftButton || e->button() == Qt::MidButton)
Shinya Kitaoka 120a6e
    Spreadsheet::CellPanel::mousePressEvent(e);
Shinya Kitaoka 120a6e
  else if (e->button() == Qt::RightButton) {
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
    openContextMenu(e);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::mouseReleaseEvent(QMouseEvent *e) {
Jeremy Bullock 771290
  if (m_lineEdit->getMouseDragEditing()) {
Jeremy Bullock 771290
    std::string textValue = m_lineEdit->text().toStdString();
Jeremy Bullock 771290
    onCellEditorEditingFinished();
Jeremy Bullock 771290
    m_lineEdit->setMouseDragEditing(false);
Jeremy Bullock 771290
  } else
Jeremy Bullock 771290
    Spreadsheet::CellPanel::mouseReleaseEvent(e);
Shinya Kitaoka 120a6e
  /*
Jaroslav 203cc8
  CellPosition cellPosition = getViewer ()->xyToPosition (e->pos ());
Jaroslav 203cc8
int row = cellPosition.frame ();
Jaroslav 203cc8
int col = cellPosition.layer ();
Shinya Kitaoka 120a6e
FunctionSheet::DragTool *dragTool = m_sheet->getDragTool();
Shinya Kitaoka 120a6e
if(dragTool) dragTool->release(row,col);
Shinya Kitaoka 120a6e
m_sheet->setDragTool(0);
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::mouseMoveEvent(QMouseEvent *e) {
Jeremy Bullock 771290
  if (m_lineEdit->getMouseDragEditing()) {
Jeremy Bullock 771290
    double newValue = m_currentValue + ((e->x() - m_mouseXPosition) / 2);
Jeremy Bullock 771290
    m_lineEdit->setText(QString::number(newValue, 'f', 4));
Jeremy Bullock 771290
    m_updatedValue = newValue;
Jeremy Bullock 771290
  } else
Jeremy Bullock 771290
    Spreadsheet::CellPanel::mouseMoveEvent(e);
Jeremy Bullock 771290
}
Jeremy Bullock 771290
Jeremy Bullock 771290
//-----------------------------------------------------------------------------
Jeremy Bullock 771290
Jeremy Bullock 771290
void FunctionSheetCellViewer::onMouseMovedInLineEdit(QMouseEvent *event) {
Jeremy Bullock 771290
  if (m_lineEdit->getMouseDragEditing()) mouseMoveEvent(event);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TODO: refactor: cfr functionpanel.cpp
Shinya Kitaoka 120a6e
void FunctionSheetCellViewer::openContextMenu(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  struct locals {
Shinya Kitaoka 120a6e
    static void sheet__setSegmentType(FunctionSelection *selection,
Shinya Kitaoka 120a6e
                                      TDoubleParam *curve, int segmentIndex,
Shinya Kitaoka 120a6e
                                      TDoubleKeyframe::Type type) {
Shinya Kitaoka 120a6e
      selection->selectSegment(curve, segmentIndex);
Shinya Kitaoka 120a6e
      KeyframeSetter setter(curve, segmentIndex);
Shinya Kitaoka 120a6e
      setter.setType(type);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };  // locals
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction deleteKeyframeAction(tr("Delete Key"), 0);
Shinya Kitaoka 120a6e
  QAction insertKeyframeAction(tr("Set Key"), 0);
Shinya Kitaoka 120a6e
  QAction setLinearAction(tr("Linear Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setSpeedInOutAction(tr("Speed In / Speed Out Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setEaseInOutAction(tr("Ease In / Ease Out Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setEaseInOut2Action(tr("Ease In / Ease Out (%) Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setExponentialAction(tr("Exponential Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setExpressionAction(tr("Expression Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setFileAction(tr("File Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setConstantAction(tr("Constant Interpolation"), 0);
Shinya Kitaoka 120a6e
  QAction setStep1Action(tr("Step 1"), 0);
Shinya Kitaoka 120a6e
  QAction setStep2Action(tr("Step 2"), 0);
Shinya Kitaoka 120a6e
  QAction setStep3Action(tr("Step 3"), 0);
Shinya Kitaoka 120a6e
  QAction setStep4Action(tr("Step 4"), 0);
Shinya Kitaoka 120a6e
Jaroslav 203cc8
  CellPosition cellPosition = getViewer()->xyToPosition(e->pos());
Jaroslav 203cc8
  int row                   = cellPosition.frame();
Jaroslav 203cc8
  int col                   = cellPosition.layer();
Jaroslav 203cc8
  TDoubleParam *curve       = m_sheet->getCurve(col);
Shinya Kitaoka 120a6e
  if (!curve) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isEmpty    = true;
Shinya Kitaoka 120a6e
  bool isKeyframe = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // find the curve keyframe range
Shinya Kitaoka 120a6e
  int kCount = curve->getKeyframeCount();
Shinya Kitaoka 120a6e
  if (kCount > 0) {
Shinya Kitaoka 120a6e
    if (curve->keyframeIndexToFrame(0) <= row &&
Shinya Kitaoka 120a6e
        row <= curve->keyframeIndexToFrame(kCount - 1)) {
Shinya Kitaoka 120a6e
      isEmpty    = false;
Shinya Kitaoka 120a6e
      isKeyframe = curve->isKeyframe(row);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int kIndex = curve->getPrevKeyframe(row);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // build menu
Shinya Kitaoka 120a6e
  QMenu menu(0);
Shinya Kitaoka 120a6e
  if (!isKeyframe)  // menu.addAction(&deleteKeyframeAction); else
Shinya Kitaoka 120a6e
    menu.addAction(&insertKeyframeAction);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!isEmpty && !isKeyframe && kIndex >= 0) {
Shinya Kitaoka 120a6e
    menu.addSeparator();
Shinya Kitaoka 120a6e
    TDoubleKeyframe kf = curve->getKeyframe(kIndex);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::Linear) menu.addAction(&setLinearAction);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::SpeedInOut)
Shinya Kitaoka 120a6e
      menu.addAction(&setSpeedInOutAction);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::EaseInOut)
Shinya Kitaoka 120a6e
      menu.addAction(&setEaseInOutAction);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::EaseInOutPercentage)
Shinya Kitaoka 120a6e
      menu.addAction(&setEaseInOut2Action);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::Exponential)
Shinya Kitaoka 120a6e
      menu.addAction(&setExponentialAction);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::Expression)
Shinya Kitaoka 120a6e
      menu.addAction(&setExpressionAction);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::File) menu.addAction(&setFileAction);
Shinya Kitaoka 120a6e
    if (kf.m_type != TDoubleKeyframe::Constant)
Shinya Kitaoka 120a6e
      menu.addAction(&setConstantAction);
Shinya Kitaoka 120a6e
    menu.addSeparator();
Shinya Kitaoka 120a6e
    if (kf.m_step != 1) menu.addAction(&setStep1Action);
Shinya Kitaoka 120a6e
    if (kf.m_step != 2) menu.addAction(&setStep2Action);
Shinya Kitaoka 120a6e
    if (kf.m_step != 3) menu.addAction(&setStep3Action);
Shinya Kitaoka 120a6e
    if (kf.m_step != 4) menu.addAction(&setStep4Action);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.addSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CommandManager *cmdManager = CommandManager::instance();
Shinya Kitaoka 120a6e
  menu.addAction(cmdManager->getAction("MI_Cut"));
Shinya Kitaoka 120a6e
  menu.addAction(cmdManager->getAction("MI_Copy"));
Shinya Kitaoka 120a6e
  menu.addAction(cmdManager->getAction("MI_Paste"));
Shinya Kitaoka 120a6e
  menu.addAction(cmdManager->getAction("MI_Clear"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.addAction(cmdManager->getAction("MI_Insert"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FunctionSelection *selection = m_sheet->getSelection();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // execute menu
Shinya Kitaoka 120a6e
  QAction *action = menu.exec(e->globalPos());  // QCursor::pos());
Shinya Kitaoka 120a6e
  if (action == &deleteKeyframeAction) {
Shinya Kitaoka 120a6e
    KeyframeSetter::removeKeyframeAt(curve, row);
Shinya Kitaoka 120a6e
  } else if (action == &insertKeyframeAction) {
Shinya Kitaoka 120a6e
    KeyframeSetter(curve).createKeyframe(row);
Shinya Kitaoka 120a6e
  } else if (action == &setLinearAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::Linear);
Shinya Kitaoka 120a6e
  else if (action == &setSpeedInOutAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::SpeedInOut);
Shinya Kitaoka 120a6e
  else if (action == &setEaseInOutAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::EaseInOut);
Shinya Kitaoka 120a6e
  else if (action == &setEaseInOut2Action)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::EaseInOutPercentage);
Shinya Kitaoka 120a6e
  else if (action == &setExponentialAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::Exponential);
Shinya Kitaoka 120a6e
  else if (action == &setExpressionAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::Expression);
Shinya Kitaoka 120a6e
  else if (action == &setFileAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::File);
Shinya Kitaoka 120a6e
  else if (action == &setConstantAction)
Shinya Kitaoka 120a6e
    locals::sheet__setSegmentType(selection, curve, kIndex,
Shinya Kitaoka 120a6e
                                  TDoubleKeyframe::Constant);
Shinya Kitaoka 120a6e
  else if (action == &setStep1Action)
Shinya Kitaoka 120a6e
    KeyframeSetter(curve, kIndex).setStep(1);
Shinya Kitaoka 120a6e
  else if (action == &setStep2Action)
Shinya Kitaoka 120a6e
    KeyframeSetter(curve, kIndex).setStep(2);
Shinya Kitaoka 120a6e
  else if (action == &setStep3Action)
Shinya Kitaoka 120a6e
    KeyframeSetter(curve, kIndex).setStep(3);
Shinya Kitaoka 120a6e
  else if (action == &setStep4Action)
Shinya Kitaoka 120a6e
    KeyframeSetter(curve, kIndex).setStep(4);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    FunctionSheetColumnToCurveMapper  implementation
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FunctionSheetColumnToCurveMapper final : public ColumnToCurveMapper {
Shinya Kitaoka 120a6e
  FunctionSheet *m_sheet;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionSheetColumnToCurveMapper(FunctionSheet *sheet) : m_sheet(sheet) {}
Shinya Kitaoka 473e70
  TDoubleParam *getCurve(int columnIndex) const override {
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *channel = m_sheet->getChannel(columnIndex);
Shinya Kitaoka 120a6e
    if (channel)
Shinya Kitaoka 120a6e
      return channel->getParam();
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
//    FunctionSheet  implementation
Toshihiro Shimizu 890ddd
//********************************************************************************
Toshihiro Shimizu 890ddd
Jeremy Bullock 4ce953
FunctionSheet::FunctionSheet(QWidget *parent, bool isFloating)
Jeremy Bullock 4ce953
    : SpreadsheetViewer(parent)
Jeremy Bullock 4ce953
    , m_selectedCells()
Jeremy Bullock 4ce953
    , m_selection(0)
Jeremy Bullock 4ce953
    , m_isFloating(isFloating) {
Shinya Kitaoka 120a6e
  setColumnsPanel(m_columnHeadViewer = new FunctionSheetColumnHeadViewer(this));
Shinya Kitaoka 120a6e
  setRowsPanel(m_rowViewer = new FunctionSheetRowViewer(this));
Shinya Kitaoka 120a6e
  setCellsPanel(m_cellViewer = new FunctionSheetCellViewer(this));
Toshihiro Shimizu 890ddd
Jeremy Bullock 4ce953
  setWindowFlag(Qt::Window);
Shinya Kitaoka 120a6e
  setColumnCount(20);
Jeremy Bullock 4ce953
  setWindowTitle(tr("Function Editor"));
Jeremy Bullock 4ce953
  setFocusPolicy(Qt::ClickFocus);
Jeremy Bullock 4ce953
Jeremy Bullock 4ce953
  if (m_isFloating) {
Jeremy Bullock 4ce953
    // load the dialog size
shun-iwasawa 784640
    TFilePath fp(ToonzFolder::getMyModuleDir() + TFilePath("popups.ini"));
shun-iwasawa 784640
    QSettings settings(toQString(fp), QSettings::IniFormat);
shun-iwasawa 784640
shun-iwasawa 784640
    setGeometry(settings.value("FunctionSpreadsheet", QRect(500, 500, 400, 300))
shun-iwasawa 784640
                    .toRect());
Jeremy Bullock 4ce953
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 4ce953
FunctionSheet::~FunctionSheet() {
Jeremy Bullock 4ce953
  if (m_isFloating) {
shun-iwasawa 784640
    TFilePath fp(ToonzFolder::getMyModuleDir() + TFilePath("popups.ini"));
shun-iwasawa 784640
    QSettings settings(toQString(fp), QSettings::IniFormat);
Jeremy Bullock 4ce953
shun-iwasawa 784640
    settings.setValue("FunctionSpreadsheet", geometry());
Jeremy Bullock 4ce953
  }
Jeremy Bullock 4ce953
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FunctionSheet::anyWidgetHasFocus() {
Shinya Kitaoka 120a6e
  return hasFocus() || m_rowViewer->hasFocus() ||
Shinya Kitaoka 120a6e
         m_columnHeadViewer->hasFocus() || m_cellViewer->hasFocus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::setSelection(FunctionSelection *selection) {
Shinya Kitaoka 120a6e
  m_selection = selection;
Shinya Kitaoka 120a6e
  m_selection->setColumnToCurveMapper(
Shinya Kitaoka 120a6e
      new FunctionSheetColumnToCurveMapper(this));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::showEvent(QShowEvent *e) {
Jaroslav 203cc8
  m_frameScroller.registerFrameScroller();
Shinya Kitaoka 120a6e
  SpreadsheetViewer::showEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::hideEvent(QHideEvent *e) {
Jaroslav 203cc8
  m_frameScroller.unregisterFrameScroller();
Shinya Kitaoka 120a6e
  SpreadsheetViewer::hideEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::onFrameSwitched() {
Shinya Kitaoka 120a6e
  setCurrentRow(getCurrentFrame());
Shinya Kitaoka 120a6e
  m_rowViewer->update();
Shinya Kitaoka 120a6e
  m_cellViewer->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::setCurrentFrame(int frame) {
Shinya Kitaoka 120a6e
  if (getFrameHandle()) getFrameHandle()->setFrame(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FunctionSheet::getCurrentFrame() const {
Shinya Kitaoka 120a6e
  return getFrameHandle() ? getFrameHandle()->getFrame() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FunctionSheet::getChannelCount() {
Shinya Kitaoka 120a6e
  if (m_functionTreeModel == 0)
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return m_functionTreeModel->getActiveChannelCount();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FunctionTreeModel::Channel *FunctionSheet::getChannel(int column) {
Shinya Kitaoka 120a6e
  if (m_functionTreeModel == 0)
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return m_functionTreeModel->getActiveChannel(column);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParam *FunctionSheet::getCurve(int column) {
Shinya Kitaoka 120a6e
  FunctionTreeModel::Channel *channel = getChannel(column);
Shinya Kitaoka 120a6e
  return channel ? channel->getParam() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::setModel(FunctionTreeModel *model) {
Shinya Kitaoka 120a6e
  m_functionTreeModel = model;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::setViewer(FunctionViewer *viewer) {
Shinya Kitaoka 120a6e
  m_functionViewer = viewer;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QRect FunctionSheet::getSelectedCells() const {
Shinya Kitaoka 120a6e
  if (getSelection())
Shinya Kitaoka 120a6e
    return getSelection()->getSelectedCells();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return QRect();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::selectCells(const QRect &selectedCells) {
Shinya Kitaoka 120a6e
  m_selectedCells = selectedCells;
Shinya Kitaoka 120a6e
  if (getSelection()) {
Shinya Kitaoka 120a6e
    QList<tdoubleparam *=""> curves;</tdoubleparam>
Shinya Kitaoka 120a6e
    for (int c = selectedCells.left(); c <= selectedCells.right(); c++) {
Shinya Kitaoka 120a6e
      TDoubleParam *param              = 0;
Shinya Kitaoka 120a6e
      if (c < getChannelCount()) param = getChannel(c)->getParam();
Shinya Kitaoka 120a6e
      curves.push_back(param);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    getSelection()->selectCells(selectedCells, curves);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (selectedCells.width() == 1 && curves[0] &&
Shinya Kitaoka 120a6e
        !getChannel(selectedCells.x())->isCurrent())
Shinya Kitaoka 120a6e
      getChannel(selectedCells.x())->setIsCurrent(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  updateAll();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FunctionSheet::updateAll() {
Shinya Kitaoka 120a6e
  m_rowViewer->update();
Shinya Kitaoka 120a6e
  m_columnHeadViewer->update();
Shinya Kitaoka 120a6e
  m_cellViewer->update();
Shinya Kitaoka 120a6e
  setColumnCount(getChannelCount());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Display expression name of the current segment
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
QString FunctionSheet::getSelectedParamName() {
Shinya Kitaoka 120a6e
  if (m_functionTreeModel->getCurrentChannel())
Shinya Kitaoka 120a6e
    return m_functionTreeModel->getCurrentChannel()->getExprRefName();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return QString();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FunctionSheet::getColumnIndexByCurve(TDoubleParam *param) const {
Shinya Kitaoka 120a6e
  return m_functionTreeModel->getColumnIndexByCurve(param);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
/*! scroll column to show the current one
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void FunctionSheet::onCurrentChannelChanged(
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *channel) {
Shinya Kitaoka 120a6e
  if (!channel) return;
Shinya Kitaoka 120a6e
  for (int c = 0; c < getChannelCount(); c++) {
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *tmpChan = getChannel(c);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (tmpChan == channel) {
Shinya Kitaoka 120a6e
      ensureVisibleCol(c);
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}