Jaroslav 203cc8
#include "orientation.h"
Jaroslav 203cc8
#include "toonz/columnfan.h"
Jaroslav 203cc8
Jaroslav 203cc8
#include <qpainterpath></qpainterpath>
Jaroslav 203cc8
#include <qboxlayout></qboxlayout>
Jaroslav 203cc8
#include <math.h></math.h>
Jaroslav 203cc8
Jaroslav 203cc8
using std::pair;
Jaroslav 203cc8
Jaroslav 203cc8
namespace {
Jaroslav 203cc8
const int KEY_ICON_WIDTH     = 11;
Jaroslav 203cc8
const int KEY_ICON_HEIGHT    = 13;
Jaroslav 203cc8
const int EASE_TRIANGLE_SIZE = 4;
Jaroslav 203cc8
const int PLAY_MARKER_SIZE   = 10;
Jaroslav 203cc8
const int ONION_SIZE         = 19;
Jaroslav 203cc8
const int ONION_DOT_SIZE     = 8;
Jaroslav 203cc8
const int PINNED_SIZE        = 10;
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
class TopToBottomOrientation : public Orientation {
shun_iwasawa 0cae24
  const int CELL_WIDTH                 = 74;
shun_iwasawa 0cae24
  const int CELL_HEIGHT                = 20;
shun_iwasawa 0cae24
  const int CELL_DRAG_WIDTH            = 7;
shun_iwasawa 0cae24
  const int EXTENDER_WIDTH             = 18;
shun_iwasawa 0cae24
  const int EXTENDER_HEIGHT            = 8;
shun_iwasawa 0cae24
  const int SOUND_PREVIEW_WIDTH        = 7;
shun_iwasawa 0cae24
  const int LAYER_HEADER_HEIGHT        = CELL_HEIGHT * 3 + 60;
Jaroslav 203cc8
  const int FOLDED_LAYER_HEADER_HEIGHT = LAYER_HEADER_HEIGHT;
shun_iwasawa 0cae24
  const int FOLDED_LAYER_HEADER_WIDTH  = 8;
shun_iwasawa 0cae24
  const int FRAME_HEADER_WIDTH         = CELL_WIDTH;
shun_iwasawa 0cae24
  const int PLAY_RANGE_X = FRAME_HEADER_WIDTH / 2 - PLAY_MARKER_SIZE;
Jaroslav 203cc8
  const int ONION_X = 0, ONION_Y = 0;
Jaroslav 203cc8
  const int ICON_WIDTH = CELL_HEIGHT;
Jaroslav 203cc8
Jaroslav 203cc8
public:
Jaroslav 203cc8
  TopToBottomOrientation();
Jaroslav 203cc8
Jaroslav 203cc8
  virtual CellPosition xyToPosition(const QPoint &xy,
Jaroslav 203cc8
                                    const ColumnFan *fan) const override;
Jaroslav 203cc8
  virtual QPoint positionToXY(const CellPosition &position,
Jaroslav 203cc8
                              const ColumnFan *fan) const override;
Jaroslav 203cc8
  virtual CellPositionRatio xyToPositionRatio(const QPoint &xy) const override;
Jaroslav 203cc8
  virtual QPoint positionRatioToXY(
Jaroslav 203cc8
      const CellPositionRatio &ratio) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual int colToLayerAxis(int layer, const ColumnFan *fan) const override;
Jaroslav 203cc8
  virtual int rowToFrameAxis(int frame) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual QPoint frameLayerToXY(int frameAxis, int layerAxis) const override;
Jaroslav 203cc8
  virtual int layerAxis(const QPoint &xy) const override;
Jaroslav 203cc8
  virtual int frameAxis(const QPoint &xy) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual NumberRange layerSide(const QRect &area) const override;
Jaroslav 203cc8
  virtual NumberRange frameSide(const QRect &area) const override;
Jaroslav 203cc8
  virtual QPoint topRightCorner(const QRect &area) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual CellPosition arrowShift(int direction) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual QString name() const override { return "TopToBottom"; }
Jaroslav 203cc8
  virtual QString caption() const override { return "Xsheet"; }
Jaroslav 203cc8
  virtual const Orientation *next() const override {
Jaroslav 203cc8
    return Orientations::leftToRight();
Jaroslav 203cc8
  }
Jaroslav 203cc8
Jaroslav 203cc8
  virtual bool isVerticalTimeline() const override { return true; }
Jaroslav 203cc8
  virtual bool flipVolume() const override { return true; }
Jaroslav 203cc8
Jaroslav 203cc8
  virtual int cellWidth() const override { return CELL_WIDTH; }
Jaroslav 203cc8
  virtual int cellHeight() const override { return CELL_HEIGHT; }
Jaroslav 203cc8
};
Jaroslav 203cc8
Jaroslav 203cc8
class LeftToRightOrientation : public Orientation {
Jaroslav 203cc8
  const int CELL_WIDTH           = 50;
Jaroslav 203cc8
  const int CELL_HEIGHT          = 20;
Jaroslav 203cc8
  const int CELL_DRAG_HEIGHT     = 5;
Jaroslav 203cc8
  const int EXTENDER_WIDTH       = 8;
Jaroslav 203cc8
  const int EXTENDER_HEIGHT      = 12;
Jaroslav 203cc8
  const int SOUND_PREVIEW_HEIGHT = 6;
Jaroslav 203cc8
  const int FRAME_HEADER_HEIGHT  = 50;
Jaroslav 203cc8
  const int ONION_X = (CELL_WIDTH - ONION_SIZE) / 2, ONION_Y = 0;
Jaroslav 203cc8
  const int PLAY_RANGE_Y       = ONION_SIZE;
Jaroslav 203cc8
  const int ICON_WIDTH         = CELL_HEIGHT;
Jaroslav 203cc8
  const int ICON_OFFSET        = ICON_WIDTH;
Jaroslav 203cc8
  const int ICONS_WIDTH        = ICON_OFFSET * 3;  // 88
Jaroslav 203cc8
  const int LAYER_NUMBER_WIDTH = 20;
Jaroslav 203cc8
  const int LAYER_NAME_WIDTH   = 170;
Jaroslav 203cc8
  const int LAYER_HEADER_WIDTH =
Jaroslav 203cc8
      ICONS_WIDTH + LAYER_NUMBER_WIDTH + LAYER_NAME_WIDTH;
Jaroslav 203cc8
  const int FOLDED_LAYER_HEADER_HEIGHT = 8;
shun_iwasawa 0cae24
  const int FOLDED_LAYER_HEADER_WIDTH  = LAYER_HEADER_WIDTH;
Jaroslav 203cc8
Jaroslav 203cc8
public:
Jaroslav 203cc8
  LeftToRightOrientation();
Jaroslav 203cc8
Jaroslav 203cc8
  virtual CellPosition xyToPosition(const QPoint &xy,
Jaroslav 203cc8
                                    const ColumnFan *fan) const override;
Jaroslav 203cc8
  virtual QPoint positionToXY(const CellPosition &position,
Jaroslav 203cc8
                              const ColumnFan *fan) const override;
Jaroslav 203cc8
  virtual CellPositionRatio xyToPositionRatio(const QPoint &xy) const override;
Jaroslav 203cc8
  virtual QPoint positionRatioToXY(
Jaroslav 203cc8
      const CellPositionRatio &ratio) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual int colToLayerAxis(int layer, const ColumnFan *fan) const override;
Jaroslav 203cc8
  virtual int rowToFrameAxis(int frame) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual QPoint frameLayerToXY(int frameAxis, int layerAxis) const override;
Jaroslav 203cc8
  virtual int layerAxis(const QPoint &xy) const override;
Jaroslav 203cc8
  virtual int frameAxis(const QPoint &xy) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual NumberRange layerSide(const QRect &area) const override;
Jaroslav 203cc8
  virtual NumberRange frameSide(const QRect &area) const override;
Jaroslav 203cc8
  virtual QPoint topRightCorner(const QRect &area) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual CellPosition arrowShift(int direction) const override;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual QString name() const override { return "LeftToRight"; }
Jaroslav 203cc8
  virtual QString caption() const override { return "Timeline"; }
Jaroslav 203cc8
  virtual const Orientation *next() const override {
Jaroslav 203cc8
    return Orientations::topToBottom();
Jaroslav 203cc8
  }
Jaroslav 203cc8
Jaroslav 203cc8
  virtual bool isVerticalTimeline() const override { return false; }
Jaroslav 203cc8
  virtual bool flipVolume() const override { return false; }
Jaroslav 203cc8
Jaroslav 203cc8
  virtual int cellWidth() const override { return CELL_WIDTH; }
Jaroslav 203cc8
  virtual int cellHeight() const override { return CELL_HEIGHT; }
Jaroslav 203cc8
};
Jaroslav 203cc8
Jaroslav 203cc8
/// -------------------------------------------------------------------------------
Jaroslav 203cc8
Jaroslav 203cc8
int NumberRange::weight(double toWeight) const {  // weight ranging 0..1
Jaroslav 203cc8
  return _from + (_to - _from) * toWeight;
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
NumberRange NumberRange::adjusted(int addFrom, int addTo) const {
Jaroslav 203cc8
  return NumberRange(_from + addFrom, _to + addTo);
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
double NumberRange::ratio(int at) const {
Jaroslav 203cc8
  double result          = ((double)at - _from) / (_to - _from);
Jaroslav 203cc8
  if (result < 0) result = 0;
Jaroslav 203cc8
  if (result > 1) result = 1;
Jaroslav 203cc8
  return result;
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
/// -------------------------------------------------------------------------------
Jaroslav 203cc8
Jaroslav 203cc8
// const int Orientations::COUNT = 2;
Jaroslav 203cc8
Jaroslav 203cc8
Orientations::Orientations() : _topToBottom(nullptr), _leftToRight(nullptr) {
Jaroslav 203cc8
  _topToBottom = new TopToBottomOrientation();
Jaroslav 203cc8
  _leftToRight = new LeftToRightOrientation();
Jaroslav 203cc8
Jaroslav 203cc8
  _all.push_back(_topToBottom);
Jaroslav 203cc8
  _all.push_back(_leftToRight);
Jaroslav 203cc8
}
Jaroslav 203cc8
Orientations::~Orientations() {
Jaroslav 203cc8
  delete _topToBottom;
Jaroslav 203cc8
  _topToBottom = nullptr;
Jaroslav 203cc8
  delete _leftToRight;
Jaroslav 203cc8
  _leftToRight = nullptr;
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
const Orientations &Orientations::instance() {
Jaroslav 203cc8
  static Orientations singleton;
Jaroslav 203cc8
  return singleton;
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
const Orientation *Orientations::topToBottom() {
Jaroslav 203cc8
  return instance()._topToBottom;
Jaroslav 203cc8
}
Jaroslav 203cc8
const Orientation *Orientations::leftToRight() {
Jaroslav 203cc8
  return instance()._leftToRight;
Jaroslav 203cc8
}
Jaroslav 203cc8
const vector<const *="" orientation=""> &Orientations::all() {</const>
Jaroslav 203cc8
  return instance()._all;
Jaroslav 203cc8
}
Jaroslav 203cc8
const Orientation *Orientations::byName(const QString &name) {
Jaroslav 203cc8
  vector<const *="" orientation=""> m_all = all();</const>
Jaroslav 203cc8
  for (auto it = m_all.begin(); it != m_all.end(); it++)
Jaroslav 203cc8
    if ((*it)->name() == name) return *it;
Jaroslav 203cc8
  throw std::runtime_error(
Jaroslav 203cc8
      (QString("no such orientation: ") + name).toStdString().c_str());
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
/// -------------------------------------------------------------------------------
Jaroslav 203cc8
Jaroslav 203cc8
QLine Orientation::verticalLine(int layerAxis,
Jaroslav 203cc8
                                const NumberRange &frameAxis) const {
Jaroslav 203cc8
  QPoint first  = frameLayerToXY(frameAxis.from(), layerAxis);
Jaroslav 203cc8
  QPoint second = frameLayerToXY(frameAxis.to(), layerAxis);
Jaroslav 203cc8
  return QLine(first, second);
Jaroslav 203cc8
}
Jaroslav 203cc8
QLine Orientation::horizontalLine(int frameAxis,
Jaroslav 203cc8
                                  const NumberRange &layerAxis) const {
Jaroslav 203cc8
  QPoint first  = frameLayerToXY(frameAxis, layerAxis.from());
Jaroslav 203cc8
  QPoint second = frameLayerToXY(frameAxis, layerAxis.to());
Jaroslav 203cc8
  return QLine(first, second);
Jaroslav 203cc8
}
Jaroslav 203cc8
QRect Orientation::frameLayerRect(const NumberRange &frameAxis,
Jaroslav 203cc8
                                  const NumberRange &layerAxis) const {
Jaroslav 203cc8
  QPoint topLeft     = frameLayerToXY(frameAxis.from(), layerAxis.from());
Jaroslav 203cc8
  QPoint bottomRight = frameLayerToXY(frameAxis.to(), layerAxis.to());
Jaroslav 203cc8
  return QRect(topLeft, bottomRight);
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
QRect Orientation::foldedRectangle(int layerAxis, const NumberRange &frameAxis,
Jaroslav 203cc8
                                   int i) const {
Jaroslav 203cc8
  QPoint topLeft = frameLayerToXY(frameAxis.from(), layerAxis + 1 + i * 3);
Jaroslav 203cc8
  QPoint size    = frameLayerToXY(frameAxis.length(), 2);
Jaroslav 203cc8
  return QRect(topLeft, QSize(size.x(), size.y()));
Jaroslav 203cc8
}
Jaroslav 203cc8
QLine Orientation::foldedRectangleLine(int layerAxis,
Jaroslav 203cc8
                                       const NumberRange &frameAxis,
Jaroslav 203cc8
                                       int i) const {
Jaroslav 203cc8
  return verticalLine(layerAxis + i * 3, frameAxis);
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
void Orientation::addRect(PredefinedRect which, const QRect &rect) {
Jaroslav 203cc8
  _rects.insert(pair<predefinedrect, qrect="">(which, rect));</predefinedrect,>
Jaroslav 203cc8
}
Jaroslav 203cc8
void Orientation::addLine(PredefinedLine which, const QLine &line) {
Jaroslav 203cc8
  _lines.insert(pair<predefinedline, qline="">(which, line));</predefinedline,>
Jaroslav 203cc8
}
Jaroslav 203cc8
void Orientation::addDimension(PredefinedDimension which, int dimension) {
Jaroslav 203cc8
  _dimensions.insert(pair<predefineddimension, int="">(which, dimension));</predefineddimension,>
Jaroslav 203cc8
}
Jaroslav 203cc8
void Orientation::addPath(PredefinedPath which, const QPainterPath &path) {
Jaroslav 203cc8
  _paths.insert(pair<predefinedpath, qpainterpath="">(which, path));</predefinedpath,>
Jaroslav 203cc8
}
Jaroslav 203cc8
void Orientation::addPoint(PredefinedPoint which, const QPoint &point) {
Jaroslav 203cc8
  _points.insert(pair<predefinedpoint, qpoint="">(which, point));</predefinedpoint,>
Jaroslav 203cc8
}
Jaroslav 203cc8
void Orientation::addRange(PredefinedRange which, const NumberRange &range) {
Jaroslav 203cc8
  _ranges.insert(pair<predefinedrange, numberrange="">(which, range));</predefinedrange,>
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
/// -------------------------------------------------------------------------------
Jaroslav 203cc8
Jaroslav 203cc8
TopToBottomOrientation::TopToBottomOrientation() {
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Area rectangles
Jaroslav 203cc8
  //
Jaroslav 203cc8
Jaroslav 203cc8
  // Cell viewer
Jaroslav 203cc8
  QRect cellRect(0, 0, CELL_WIDTH, CELL_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::CELL, cellRect);
shun_iwasawa 0cae24
  addRect(PredefinedRect::DRAG_HANDLE_CORNER,
shun_iwasawa 0cae24
          QRect(0, 0, CELL_DRAG_WIDTH, CELL_HEIGHT));
shun_iwasawa 0cae24
  QRect keyRect(CELL_WIDTH - KEY_ICON_WIDTH,
shun_iwasawa 0cae24
                (CELL_HEIGHT - KEY_ICON_HEIGHT) / 2, KEY_ICON_WIDTH,
shun_iwasawa 0cae24
                KEY_ICON_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::KEY_ICON, keyRect);
Jaroslav 203cc8
  QRect nameRect = cellRect.adjusted(8, 0, -6, 0);
Jaroslav 203cc8
  addRect(PredefinedRect::CELL_NAME, nameRect);
shun_iwasawa 0cae24
  addRect(PredefinedRect::CELL_NAME_WITH_KEYFRAME,
shun_iwasawa 0cae24
          nameRect.adjusted(0, 0, -KEY_ICON_WIDTH, 0));
shun_iwasawa 0cae24
  addRect(PredefinedRect::END_EXTENDER,
shun_iwasawa 0cae24
          QRect(-EXTENDER_WIDTH - KEY_ICON_WIDTH, 0, EXTENDER_WIDTH,
shun_iwasawa 0cae24
                EXTENDER_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::BEGIN_EXTENDER,
shun_iwasawa 0cae24
          QRect(-EXTENDER_WIDTH - KEY_ICON_WIDTH, -EXTENDER_HEIGHT,
shun_iwasawa 0cae24
                EXTENDER_WIDTH, EXTENDER_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::KEYFRAME_AREA,
shun_iwasawa 0cae24
          QRect(CELL_WIDTH - KEY_ICON_WIDTH, 0, KEY_ICON_WIDTH, CELL_HEIGHT));
Jaroslav 203cc8
  addRect(PredefinedRect::DRAG_AREA, QRect(0, 0, CELL_DRAG_WIDTH, CELL_HEIGHT));
shun_iwasawa 0cae24
  QRect soundRect(CELL_DRAG_WIDTH, 0,
shun_iwasawa 0cae24
                  CELL_WIDTH - CELL_DRAG_WIDTH - SOUND_PREVIEW_WIDTH,
shun_iwasawa 0cae24
                  CELL_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::SOUND_TRACK, soundRect);
shun_iwasawa 0cae24
  addRect(PredefinedRect::PREVIEW_TRACK,
shun_iwasawa 0cae24
          QRect(CELL_WIDTH - SOUND_PREVIEW_WIDTH + 1, 0, SOUND_PREVIEW_WIDTH,
shun_iwasawa 0cae24
                CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::BEGIN_SOUND_EDIT,
shun_iwasawa 0cae24
          QRect(CELL_DRAG_WIDTH, 0, CELL_WIDTH - CELL_DRAG_WIDTH, 2));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::END_SOUND_EDIT,
shun_iwasawa 0cae24
      QRect(CELL_DRAG_WIDTH, CELL_HEIGHT - 2, CELL_WIDTH - CELL_DRAG_WIDTH, 2));
Jaroslav 203cc8
  addRect(PredefinedRect::LOOP_ICON, QRect(keyRect.left(), 0, 10, 11));
Jaroslav 203cc8
Jaroslav 203cc8
  // Note viewer
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::NOTE_AREA,
shun_iwasawa 0cae24
      QRect(QPoint(0, 0), QSize(FRAME_HEADER_WIDTH, LAYER_HEADER_HEIGHT - 1)));
shun_iwasawa 0cae24
  addRect(PredefinedRect::NOTE_ICON,
shun_iwasawa 0cae24
          QRect(QPoint(0, 0), QSize(CELL_WIDTH - 2, CELL_HEIGHT - 2)));
Jaroslav 203cc8
  addRect(PredefinedRect::LAYER_HEADER_PANEL, QRect(0, 0, -1, -1));  // hide
Jaroslav 203cc8
Jaroslav 203cc8
  // Row viewer
shun_iwasawa 0cae24
  addRect(PredefinedRect::FRAME_LABEL,
shun_iwasawa 0cae24
          QRect(CELL_WIDTH / 2, 1, CELL_WIDTH / 2, CELL_HEIGHT - 2));
shun_iwasawa 0cae24
  addRect(PredefinedRect::FRAME_HEADER,
shun_iwasawa 0cae24
          QRect(0, 0, FRAME_HEADER_WIDTH - 1, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::PLAY_RANGE,
shun_iwasawa 0cae24
          QRect(PLAY_RANGE_X, 0, PLAY_MARKER_SIZE, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION,
shun_iwasawa 0cae24
          QRect(ONION_X + (3 * ONION_DOT_SIZE - ONION_SIZE) / 2, ONION_Y,
shun_iwasawa 0cae24
                ONION_SIZE, ONION_SIZE));
Jaroslav 203cc8
  int adjustOnion = (ONION_SIZE - ONION_DOT_SIZE) / 2;
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_DOT,
shun_iwasawa 0cae24
          QRect(ONION_X + ONION_DOT_SIZE, ONION_Y + adjustOnion, ONION_DOT_SIZE,
shun_iwasawa 0cae24
                ONION_DOT_SIZE));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::ONION_DOT_FIXED,
shun_iwasawa 0cae24
      QRect(ONION_X, ONION_Y + adjustOnion, ONION_DOT_SIZE, ONION_DOT_SIZE));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_AREA,
shun_iwasawa 0cae24
          QRect(ONION_X, ONION_Y, PLAY_RANGE_X, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_FIXED_DOT_AREA,
shun_iwasawa 0cae24
          QRect(ONION_X, ONION_Y, ONION_DOT_SIZE, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::ONION_DOT_AREA,
shun_iwasawa 0cae24
      QRect(ONION_X + ONION_DOT_SIZE, ONION_Y, ONION_DOT_SIZE, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::PINNED_CENTER_KEY,
shun_iwasawa 0cae24
          QRect((FRAME_HEADER_WIDTH - PINNED_SIZE) / 2,
shun_iwasawa 0cae24
                (CELL_HEIGHT - PINNED_SIZE) / 2, PINNED_SIZE, PINNED_SIZE));
Jaroslav 203cc8
Jaroslav 203cc8
  // Column viewer
shun_iwasawa 0cae24
  static int INDENT  = 9;
shun_iwasawa 0cae24
  static int HDRROW1 = 6;                          // Name/eye
shun_iwasawa 0cae24
  static int HDRROW2 = HDRROW1 + CELL_HEIGHT;      // lock, preview
shun_iwasawa 0cae24
  static int HDRROW3 = HDRROW2 + CELL_HEIGHT + 1;  // thumbnail
shun_iwasawa 0cae24
  static int HDRROW4 = HDRROW3 + 48;               // pegbar, parenthandle
shun_iwasawa 0cae24
shun_iwasawa 0cae24
  addRect(PredefinedRect::LAYER_HEADER,
shun_iwasawa 0cae24
          QRect(0, 1, CELL_WIDTH, LAYER_HEADER_HEIGHT - 3));
shun_iwasawa 0cae24
  addRect(PredefinedRect::DRAG_LAYER,
shun_iwasawa 0cae24
          QRect(0, 0, CELL_DRAG_WIDTH, LAYER_HEADER_HEIGHT - 3));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::FOLDED_LAYER_HEADER,
shun_iwasawa 0cae24
      QRect(0, 1, FOLDED_LAYER_HEADER_WIDTH, FOLDED_LAYER_HEADER_HEIGHT - 3));
shun_iwasawa 0cae24
shun_iwasawa 0cae24
  addRect(PredefinedRect::RENAME_COLUMN,
shun_iwasawa 0cae24
          QRect(0, 6, CELL_WIDTH, CELL_HEIGHT - 3));
Jaroslav 203cc8
Jaroslav 203cc8
  QRect layername(INDENT, HDRROW1, CELL_WIDTH - 11, CELL_HEIGHT - 3);
Jaroslav 203cc8
  addRect(PredefinedRect::LAYER_NAME, layername);
Jaroslav 203cc8
  addRect(PredefinedRect::LAYER_NUMBER, QRect(0, 0, -1, -1));  // hide
Jaroslav 203cc8
Jaroslav 203cc8
  QRect eyeArea(INDENT, HDRROW1, CELL_WIDTH - 11, CELL_HEIGHT - 3);
Jaroslav 203cc8
  addRect(PredefinedRect::EYE_AREA, eyeArea);
Jaroslav 203cc8
  QRect eye(eyeArea.right() - 18, HDRROW1, 18, 15);
Jaroslav 203cc8
  addRect(PredefinedRect::EYE, eye);
Jaroslav 203cc8
Jaroslav 203cc8
  QRect previewArea(INDENT, HDRROW2, CELL_WIDTH - 11, CELL_HEIGHT - 3);
Jaroslav 203cc8
  addRect(PredefinedRect::PREVIEW_LAYER_AREA, previewArea);
Jaroslav 203cc8
  QRect preview(previewArea.right() - 18, HDRROW2, 18, 15);
Jaroslav 203cc8
  addRect(PredefinedRect::PREVIEW_LAYER, preview);
Jaroslav 203cc8
Jaroslav 203cc8
  QRect lockArea(INDENT, HDRROW2, 16, 16);
Jaroslav 203cc8
  addRect(PredefinedRect::LOCK_AREA, lockArea);
Jaroslav 203cc8
  QRect lock(INDENT, HDRROW2, 16, 16);
Jaroslav 203cc8
  addRect(PredefinedRect::LOCK, lock);
Jaroslav 203cc8
Jaroslav 203cc8
  QRect thumbnailArea(INDENT, HDRROW3, CELL_WIDTH - 11, 42);
Jaroslav 203cc8
  addRect(PredefinedRect::THUMBNAIL_AREA, thumbnailArea);
Jaroslav 203cc8
  QRect thumbnail(INDENT, HDRROW3, CELL_WIDTH - 11, 42);
Jaroslav 203cc8
  addRect(PredefinedRect::THUMBNAIL, thumbnail);
shun_iwasawa 0cae24
  addRect(PredefinedRect::FILTER_COLOR,
shun_iwasawa 0cae24
          QRect(thumbnailArea.right() - 14, thumbnailArea.top() + 3, 12, 12));
shun_iwasawa 0cae24
  addRect(PredefinedRect::SOUND_ICON,
shun_iwasawa 0cae24
          QRect(thumbnailArea.right() - 40, 3 * CELL_HEIGHT + 4, 40, 30));
Jaroslav 203cc8
  int trackLen = 60;
shun_iwasawa 0cae24
  QRect volumeArea(thumbnailArea.left(), thumbnailArea.top() + 1,
shun_iwasawa 0cae24
                   29 - CELL_DRAG_WIDTH, trackLen + 7);
Jaroslav 203cc8
  addRect(PredefinedRect::VOLUME_AREA, volumeArea);
Jaroslav 203cc8
  QPoint soundTopLeft(volumeArea.left() + 12, volumeArea.top() + 4);
shun_iwasawa 0cae24
  addRect(PredefinedRect::VOLUME_TRACK,
shun_iwasawa 0cae24
          QRect(soundTopLeft, QSize(3, trackLen)));
Jaroslav 203cc8
Jaroslav 203cc8
  QRect pegbarname(INDENT, HDRROW4, CELL_WIDTH - 11, CELL_HEIGHT - 3);
Jaroslav 203cc8
  addRect(PredefinedRect::PEGBAR_NAME, pegbarname);
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::PARENT_HANDLE_NAME,
shun_iwasawa 0cae24
      QRect(INDENT + pegbarname.width() - 20, HDRROW4, 20, CELL_HEIGHT - 3));
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Lines
Jaroslav 203cc8
  //
shun_iwasawa 0cae24
  addLine(PredefinedLine::LOCKED,
shun_iwasawa 0cae24
          verticalLine((CELL_DRAG_WIDTH + 1) / 2, NumberRange(0, CELL_HEIGHT)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::SEE_MARKER_THROUGH,
shun_iwasawa 0cae24
          horizontalLine(0, NumberRange(0, CELL_DRAG_WIDTH)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::CONTINUE_LEVEL,
shun_iwasawa 0cae24
          verticalLine(CELL_WIDTH / 2, NumberRange(0, CELL_HEIGHT)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::CONTINUE_LEVEL_WITH_NAME,
shun_iwasawa 0cae24
          verticalLine(CELL_WIDTH - 11, NumberRange(0, CELL_HEIGHT)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::EXTENDER_LINE,
shun_iwasawa 0cae24
          horizontalLine(0, NumberRange(-EXTENDER_WIDTH - KEY_ICON_WIDTH, 0)));
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Dimensions
Jaroslav 203cc8
  //
Jaroslav 203cc8
  addDimension(PredefinedDimension::LAYER, CELL_WIDTH);
Jaroslav 203cc8
  addDimension(PredefinedDimension::FRAME, CELL_HEIGHT);
Jaroslav 203cc8
  addDimension(PredefinedDimension::INDEX, 0);
shun_iwasawa 0cae24
  addDimension(PredefinedDimension::SOUND_AMPLITUDE,
shun_iwasawa 0cae24
               int(sqrt(CELL_HEIGHT * soundRect.width()) / 2));
Jaroslav 203cc8
  addDimension(PredefinedDimension::FRAME_LABEL_ALIGN, Qt::AlignCenter);
Jaroslav 203cc8
  addDimension(PredefinedDimension::ONION_TURN, 0);
shun_iwasawa 0cae24
  addDimension(PredefinedDimension::QBOXLAYOUT_DIRECTION,
shun_iwasawa 0cae24
               QBoxLayout::Direction::TopToBottom);
Jaroslav 203cc8
  addDimension(PredefinedDimension::CENTER_ALIGN, Qt::AlignHCenter);
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Paths
Jaroslav 203cc8
  //
Jaroslav 203cc8
  QPainterPath corner(QPointF(0, CELL_HEIGHT));
Jaroslav 203cc8
  corner.lineTo(QPointF(CELL_DRAG_WIDTH, CELL_HEIGHT));
Jaroslav 203cc8
  corner.lineTo(QPointF(CELL_DRAG_WIDTH, CELL_HEIGHT - CELL_DRAG_WIDTH));
Jaroslav 203cc8
  corner.lineTo(QPointF(0, CELL_HEIGHT));
Jaroslav 203cc8
  addPath(PredefinedPath::DRAG_HANDLE_CORNER, corner);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath fromTriangle(QPointF(0, EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  fromTriangle.lineTo(QPointF(EASE_TRIANGLE_SIZE, -EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  fromTriangle.lineTo(QPointF(-EASE_TRIANGLE_SIZE, -EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  fromTriangle.lineTo(QPointF(0, EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  fromTriangle.translate(keyRect.center());
Jaroslav 203cc8
  addPath(PredefinedPath::BEGIN_EASE_TRIANGLE, fromTriangle);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath toTriangle(QPointF(0, -EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  toTriangle.lineTo(QPointF(EASE_TRIANGLE_SIZE, EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  toTriangle.lineTo(QPointF(-EASE_TRIANGLE_SIZE, EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  toTriangle.lineTo(QPointF(0, -EASE_TRIANGLE_SIZE / 2));
Jaroslav 203cc8
  toTriangle.translate(keyRect.center());
Jaroslav 203cc8
  addPath(PredefinedPath::END_EASE_TRIANGLE, toTriangle);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath playFrom(QPointF(0, 0));
Jaroslav 203cc8
  playFrom.lineTo(QPointF(PLAY_MARKER_SIZE, 0));
Jaroslav 203cc8
  playFrom.lineTo(QPointF(0, PLAY_MARKER_SIZE));
Jaroslav 203cc8
  playFrom.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  playFrom.translate(PLAY_RANGE_X, 1);
Jaroslav 203cc8
  addPath(PredefinedPath::BEGIN_PLAY_RANGE, playFrom);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath playTo(QPointF(0, 0));
Jaroslav 203cc8
  playTo.lineTo(QPointF(PLAY_MARKER_SIZE, 0));
Jaroslav 203cc8
  playTo.lineTo(QPointF(0, -PLAY_MARKER_SIZE));
Jaroslav 203cc8
  playTo.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  playTo.translate(PLAY_RANGE_X, CELL_HEIGHT - 1);
Jaroslav 203cc8
  addPath(PredefinedPath::END_PLAY_RANGE, playTo);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath track(QPointF(0, 0));
Jaroslav 203cc8
  track.lineTo(QPointF(1, 1));
Jaroslav 203cc8
  track.lineTo(QPointF(1, trackLen - 1));
Jaroslav 203cc8
  track.lineTo(QPointF(0, trackLen));
Jaroslav 203cc8
  track.lineTo(QPointF(-1, trackLen - 1));
Jaroslav 203cc8
  track.lineTo(QPointF(-1, 1));
Jaroslav 203cc8
  track.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  track.translate(soundTopLeft);
Jaroslav 203cc8
  addPath(PredefinedPath::VOLUME_SLIDER_TRACK, track);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath head(QPointF(0, 0));
Jaroslav 203cc8
  head.lineTo(QPointF(4, 4));
Jaroslav 203cc8
  head.lineTo(QPointF(8, 4));
Jaroslav 203cc8
  head.lineTo(QPointF(8, -4));
Jaroslav 203cc8
  head.lineTo(QPointF(4, -4));
Jaroslav 203cc8
  head.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  addPath(PredefinedPath::VOLUME_SLIDER_HEAD, head);
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Points
Jaroslav 203cc8
  //
Jaroslav 203cc8
  addPoint(PredefinedPoint::KEY_HIDDEN, QPoint(KEY_ICON_WIDTH, 0));
Jaroslav 203cc8
  addPoint(PredefinedPoint::EXTENDER_XY_RADIUS, QPoint(30, 75));
shun_iwasawa 0cae24
  addPoint(PredefinedPoint::VOLUME_DIVISIONS_TOP_LEFT,
shun_iwasawa 0cae24
           soundTopLeft - QPoint(5, 0));
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Ranges
Jaroslav 203cc8
  //
Jaroslav 203cc8
  addRange(PredefinedRange::HEADER_LAYER, NumberRange(0, FRAME_HEADER_WIDTH));
Jaroslav 203cc8
  addRange(PredefinedRange::HEADER_FRAME, NumberRange(0, LAYER_HEADER_HEIGHT));
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
CellPosition TopToBottomOrientation::xyToPosition(const QPoint &xy,
Jaroslav 203cc8
                                                  const ColumnFan *fan) const {
Jaroslav 203cc8
  int layer = fan->layerAxisToCol(xy.x());
Jaroslav 203cc8
  int frame = xy.y() / CELL_HEIGHT;
Jaroslav 203cc8
  return CellPosition(frame, layer);
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint TopToBottomOrientation::positionToXY(const CellPosition &position,
Jaroslav 203cc8
                                            const ColumnFan *fan) const {
Jaroslav 203cc8
  int x = colToLayerAxis(position.layer(), fan);
Jaroslav 203cc8
  int y = rowToFrameAxis(position.frame());
Jaroslav 203cc8
  return QPoint(x, y);
Jaroslav 203cc8
}
Jaroslav 203cc8
CellPositionRatio TopToBottomOrientation::xyToPositionRatio(
Jaroslav 203cc8
    const QPoint &xy) const {
Jaroslav 203cc8
  Ratio frame{xy.y(), CELL_HEIGHT};
Jaroslav 203cc8
  Ratio layer{xy.x(), CELL_WIDTH};
Jaroslav 203cc8
  return CellPositionRatio{frame, layer};
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint TopToBottomOrientation::positionRatioToXY(
Jaroslav 203cc8
    const CellPositionRatio &ratio) const {
Jaroslav 203cc8
  int x = ratio.layer() * CELL_WIDTH;
Jaroslav 203cc8
  int y = ratio.frame() * CELL_HEIGHT;
Jaroslav 203cc8
  return QPoint(x, y);
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
int TopToBottomOrientation::colToLayerAxis(int layer,
Jaroslav 203cc8
                                           const ColumnFan *fan) const {
Jaroslav 203cc8
  return fan->colToLayerAxis(layer);
Jaroslav 203cc8
}
Jaroslav 203cc8
int TopToBottomOrientation::rowToFrameAxis(int frame) const {
Jaroslav 203cc8
  return frame * CELL_HEIGHT;
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint TopToBottomOrientation::frameLayerToXY(int frameAxis,
Jaroslav 203cc8
                                              int layerAxis) const {
Jaroslav 203cc8
  return QPoint(layerAxis, frameAxis);
Jaroslav 203cc8
}
Jaroslav 203cc8
int TopToBottomOrientation::layerAxis(const QPoint &xy) const { return xy.x(); }
Jaroslav 203cc8
int TopToBottomOrientation::frameAxis(const QPoint &xy) const { return xy.y(); }
Jaroslav 203cc8
NumberRange TopToBottomOrientation::layerSide(const QRect &area) const {
Jaroslav 203cc8
  return NumberRange(area.left(), area.right());
Jaroslav 203cc8
}
Jaroslav 203cc8
NumberRange TopToBottomOrientation::frameSide(const QRect &area) const {
Jaroslav 203cc8
  return NumberRange(area.top(), area.bottom());
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint TopToBottomOrientation::topRightCorner(const QRect &area) const {
Jaroslav 203cc8
  return area.topRight();
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
CellPosition TopToBottomOrientation::arrowShift(int direction) const {
Jaroslav 203cc8
  switch (direction) {
Jaroslav 203cc8
  case Qt::Key_Up:
Jaroslav 203cc8
    return CellPosition(-1, 0);
Jaroslav 203cc8
  case Qt::Key_Down:
Jaroslav 203cc8
    return CellPosition(1, 0);
Jaroslav 203cc8
  case Qt::Key_Left:
Jaroslav 203cc8
    return CellPosition(0, -1);
Jaroslav 203cc8
  case Qt::Key_Right:
Jaroslav 203cc8
    return CellPosition(0, 1);
Jaroslav 203cc8
  default:
Jaroslav 203cc8
    return CellPosition(0, 0);
Jaroslav 203cc8
  }
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
/// --------------------------------------------------------------------------------
Jaroslav 203cc8
Jaroslav 203cc8
LeftToRightOrientation::LeftToRightOrientation() {
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Ranges
Jaroslav 203cc8
  //
Jaroslav 203cc8
Jaroslav 203cc8
  // Cell viewer
Jaroslav 203cc8
  QRect cellRect(0, 0, CELL_WIDTH, CELL_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::CELL, cellRect);
shun_iwasawa 0cae24
  addRect(PredefinedRect::DRAG_HANDLE_CORNER,
shun_iwasawa 0cae24
          QRect(0, 0, CELL_WIDTH, CELL_DRAG_HEIGHT));
shun_iwasawa 0cae24
  QRect keyRect((CELL_WIDTH - KEY_ICON_WIDTH) / 2,
shun_iwasawa 0cae24
                CELL_HEIGHT - KEY_ICON_HEIGHT, KEY_ICON_WIDTH, KEY_ICON_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::KEY_ICON, keyRect);
Jaroslav 203cc8
  QRect nameRect = cellRect.adjusted(4, 4, -6, 0);
Jaroslav 203cc8
  addRect(PredefinedRect::CELL_NAME, nameRect);
Jaroslav 203cc8
  addRect(PredefinedRect::CELL_NAME_WITH_KEYFRAME, nameRect);
shun_iwasawa 0cae24
  addRect(PredefinedRect::END_EXTENDER,
shun_iwasawa 0cae24
          QRect(0, -EXTENDER_HEIGHT - 10, EXTENDER_WIDTH, EXTENDER_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::BEGIN_EXTENDER,
shun_iwasawa 0cae24
          QRect(-EXTENDER_WIDTH, -EXTENDER_HEIGHT - 10, EXTENDER_WIDTH,
shun_iwasawa 0cae24
                EXTENDER_HEIGHT));
Jaroslav 203cc8
  addRect(PredefinedRect::KEYFRAME_AREA, keyRect);
Jaroslav 203cc8
  addRect(PredefinedRect::DRAG_AREA, QRect(0, 0, CELL_WIDTH, CELL_DRAG_HEIGHT));
shun_iwasawa 0cae24
  QRect soundRect(0, CELL_DRAG_HEIGHT, CELL_WIDTH,
shun_iwasawa 0cae24
                  CELL_HEIGHT - CELL_DRAG_HEIGHT - SOUND_PREVIEW_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::SOUND_TRACK, soundRect);
shun_iwasawa 0cae24
  addRect(PredefinedRect::PREVIEW_TRACK,
shun_iwasawa 0cae24
          QRect(0, CELL_HEIGHT - SOUND_PREVIEW_HEIGHT + 1, CELL_WIDTH,
shun_iwasawa 0cae24
                SOUND_PREVIEW_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::BEGIN_SOUND_EDIT,
shun_iwasawa 0cae24
          QRect(0, CELL_DRAG_HEIGHT, 2, CELL_HEIGHT - CELL_DRAG_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::END_SOUND_EDIT,
shun_iwasawa 0cae24
          QRect(CELL_WIDTH - 2, CELL_DRAG_HEIGHT, 2,
shun_iwasawa 0cae24
                CELL_HEIGHT - CELL_DRAG_HEIGHT));
Jaroslav 203cc8
  addRect(PredefinedRect::LOOP_ICON, QRect(0, keyRect.top(), 10, 11));
Jaroslav 203cc8
Jaroslav 203cc8
  // Notes viewer
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::NOTE_AREA,
shun_iwasawa 0cae24
      QRect(QPoint(0, 0), QSize(LAYER_HEADER_WIDTH - 1, FRAME_HEADER_HEIGHT)));
shun_iwasawa 0cae24
  addRect(PredefinedRect::NOTE_ICON,
shun_iwasawa 0cae24
          QRect(QPoint(0, 0), QSize(CELL_WIDTH - 2, CELL_HEIGHT - 2)));
shun_iwasawa 0cae24
  addRect(PredefinedRect::LAYER_HEADER_PANEL,
shun_iwasawa 0cae24
          QRect(0, FRAME_HEADER_HEIGHT - CELL_HEIGHT, LAYER_HEADER_WIDTH,
shun_iwasawa 0cae24
                CELL_HEIGHT));
Jaroslav 203cc8
Jaroslav 203cc8
  // Row viewer
shun_iwasawa 0cae24
  addRect(PredefinedRect::FRAME_LABEL,
shun_iwasawa 0cae24
          QRect(CELL_WIDTH / 4, 1, CELL_WIDTH / 2, FRAME_HEADER_HEIGHT - 2));
shun_iwasawa 0cae24
  addRect(PredefinedRect::FRAME_HEADER,
shun_iwasawa 0cae24
          QRect(0, 0, CELL_WIDTH, FRAME_HEADER_HEIGHT - 1));
shun_iwasawa 0cae24
  addRect(PredefinedRect::PLAY_RANGE,
shun_iwasawa 0cae24
          QRect(0, PLAY_RANGE_Y, CELL_WIDTH, PLAY_MARKER_SIZE));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION,
shun_iwasawa 0cae24
          QRect(ONION_X, ONION_Y + (3 * ONION_DOT_SIZE - ONION_SIZE) / 2,
shun_iwasawa 0cae24
                ONION_SIZE, ONION_SIZE));
Jaroslav 203cc8
  int adjustOnion = (ONION_SIZE - ONION_DOT_SIZE) / 2;
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_DOT,
shun_iwasawa 0cae24
          QRect(ONION_X + adjustOnion, ONION_Y + ONION_DOT_SIZE, ONION_DOT_SIZE,
shun_iwasawa 0cae24
                ONION_DOT_SIZE));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::ONION_DOT_FIXED,
shun_iwasawa 0cae24
      QRect(ONION_X + adjustOnion, ONION_Y, ONION_DOT_SIZE, ONION_DOT_SIZE));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_AREA,
shun_iwasawa 0cae24
          QRect(ONION_X, ONION_Y, CELL_WIDTH, ONION_SIZE));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_FIXED_DOT_AREA,
shun_iwasawa 0cae24
          QRect(ONION_X, ONION_Y, CELL_WIDTH, ONION_DOT_SIZE));
shun_iwasawa 0cae24
  addRect(PredefinedRect::ONION_DOT_AREA,
shun_iwasawa 0cae24
          QRect(ONION_X, ONION_Y + ONION_DOT_SIZE, CELL_WIDTH, ONION_DOT_SIZE));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::PINNED_CENTER_KEY,
shun_iwasawa 0cae24
      QRect((CELL_WIDTH - PINNED_SIZE) / 2,
shun_iwasawa 0cae24
            (FRAME_HEADER_HEIGHT - PINNED_SIZE) / 2, PINNED_SIZE, PINNED_SIZE));
Jaroslav 203cc8
Jaroslav 203cc8
  // Column viewer
shun_iwasawa 0cae24
  addRect(PredefinedRect::LAYER_HEADER,
shun_iwasawa 0cae24
          QRect(1, 0, LAYER_HEADER_WIDTH - 3, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(
shun_iwasawa 0cae24
      PredefinedRect::FOLDED_LAYER_HEADER,
shun_iwasawa 0cae24
      QRect(1, 0, FOLDED_LAYER_HEADER_WIDTH - 3, FOLDED_LAYER_HEADER_HEIGHT));
shun_iwasawa 0cae24
  QRect columnName(ICONS_WIDTH + 1, 0,
shun_iwasawa 0cae24
                   LAYER_NAME_WIDTH + LAYER_NUMBER_WIDTH - 3, CELL_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::RENAME_COLUMN, columnName);
Jaroslav 203cc8
  QRect eye(1, 0, ICON_WIDTH, CELL_HEIGHT);
Jaroslav 203cc8
  addRect(PredefinedRect::EYE_AREA, eye);
Jaroslav 203cc8
  addRect(PredefinedRect::EYE, eye.adjusted(1, 1, 0, 0));
Jaroslav 203cc8
  addRect(PredefinedRect::PREVIEW_LAYER_AREA, eye.translated(ICON_OFFSET, 0));
shun_iwasawa 0cae24
  addRect(PredefinedRect::PREVIEW_LAYER,
shun_iwasawa 0cae24
          eye.translated(ICON_OFFSET + 1, 0).adjusted(-1, 1, -1, 0));
Jaroslav 203cc8
  addRect(PredefinedRect::LOCK_AREA, eye.translated(2 * ICON_OFFSET, 0));
shun_iwasawa 0cae24
  addRect(PredefinedRect::LOCK,
shun_iwasawa 0cae24
          eye.translated(2 * ICON_OFFSET + 1, 0).adjusted(-1, 1, -1, 0));
shun_iwasawa 0cae24
  addRect(PredefinedRect::DRAG_LAYER,
shun_iwasawa 0cae24
          QRect(ICONS_WIDTH + 1, 0, LAYER_HEADER_WIDTH - ICONS_WIDTH - 3,
shun_iwasawa 0cae24
                CELL_DRAG_HEIGHT));
Jaroslav 203cc8
  addRect(PredefinedRect::LAYER_NAME, columnName);
shun_iwasawa 0cae24
  addRect(PredefinedRect::LAYER_NUMBER,
shun_iwasawa 0cae24
          QRect(ICONS_WIDTH + 1, 0, LAYER_NUMBER_WIDTH, CELL_HEIGHT));
shun_iwasawa 0cae24
  addRect(PredefinedRect::THUMBNAIL_AREA, QRect(0, 0, -1, -1));  // hide
shun_iwasawa 0cae24
  addRect(PredefinedRect::FILTER_COLOR,
shun_iwasawa 0cae24
          QRect(LAYER_HEADER_WIDTH - 17, 6, 12, 12));
shun_iwasawa 0cae24
  addRect(PredefinedRect::PEGBAR_NAME, QRect(0, 0, -1, -1));         // hide
shun_iwasawa 0cae24
  addRect(PredefinedRect::PARENT_HANDLE_NAME, QRect(0, 0, -1, -1));  // hide
Jaroslav 203cc8
Jaroslav 203cc8
  int trackLen = 60;
shun_iwasawa 0cae24
  QRect volumeArea(
shun_iwasawa 0cae24
      QRect(columnName.topRight(), QSize(trackLen + 8, columnName.height()))
shun_iwasawa 0cae24
          .adjusted(-97, 0, -97, 0));
Jaroslav 203cc8
  addRect(PredefinedRect::VOLUME_AREA, volumeArea);
Jaroslav 203cc8
  QPoint soundTopLeft(volumeArea.left() + 4, volumeArea.top() + 12);
shun_iwasawa 0cae24
  addRect(PredefinedRect::VOLUME_TRACK,
shun_iwasawa 0cae24
          QRect(soundTopLeft, QSize(trackLen, 3)));
shun_iwasawa 0cae24
  addRect(PredefinedRect::SOUND_ICON,
shun_iwasawa 0cae24
          QRect(columnName.topRight(), QSize(27, columnName.height()))
shun_iwasawa 0cae24
              .adjusted(-28, 0, -28, 0));
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Lines
Jaroslav 203cc8
  //
shun_iwasawa 0cae24
  addLine(PredefinedLine::LOCKED,
shun_iwasawa 0cae24
          verticalLine(CELL_DRAG_HEIGHT / 2, NumberRange(0, CELL_WIDTH)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::SEE_MARKER_THROUGH,
shun_iwasawa 0cae24
          horizontalLine(0, NumberRange(0, CELL_DRAG_HEIGHT)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::CONTINUE_LEVEL,
shun_iwasawa 0cae24
          verticalLine(CELL_HEIGHT / 2, NumberRange(0, CELL_WIDTH)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::CONTINUE_LEVEL_WITH_NAME,
shun_iwasawa 0cae24
          verticalLine(CELL_HEIGHT / 2, NumberRange(0, CELL_WIDTH)));
shun_iwasawa 0cae24
  addLine(PredefinedLine::EXTENDER_LINE,
shun_iwasawa 0cae24
          horizontalLine(0, NumberRange(-EXTENDER_WIDTH - KEY_ICON_WIDTH, 0)));
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Dimensions
Jaroslav 203cc8
  //
Jaroslav 203cc8
  addDimension(PredefinedDimension::LAYER, CELL_HEIGHT);
Jaroslav 203cc8
  addDimension(PredefinedDimension::FRAME, CELL_WIDTH);
Jaroslav 203cc8
  addDimension(PredefinedDimension::INDEX, 1);
Jaroslav 203cc8
  addDimension(PredefinedDimension::SOUND_AMPLITUDE, soundRect.height() / 2);
shun_iwasawa 0cae24
  addDimension(PredefinedDimension::FRAME_LABEL_ALIGN,
shun_iwasawa 0cae24
               Qt::AlignHCenter | Qt::AlignBottom | Qt::TextWordWrap);
Jaroslav 203cc8
  addDimension(PredefinedDimension::ONION_TURN, 90);
shun_iwasawa 0cae24
  addDimension(PredefinedDimension::QBOXLAYOUT_DIRECTION,
shun_iwasawa 0cae24
               QBoxLayout::Direction::LeftToRight);
Jaroslav 203cc8
  addDimension(PredefinedDimension::CENTER_ALIGN, Qt::AlignVCenter);
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Paths
Jaroslav 203cc8
  //
Jaroslav 203cc8
  QPainterPath corner(QPointF(CELL_WIDTH, 0));
Jaroslav 203cc8
  corner.lineTo(QPointF(CELL_WIDTH, CELL_DRAG_HEIGHT));
Jaroslav 203cc8
  corner.lineTo(QPointF(CELL_WIDTH - CELL_DRAG_HEIGHT, CELL_DRAG_HEIGHT));
Jaroslav 203cc8
  corner.lineTo(QPointF(CELL_WIDTH, 0));
Jaroslav 203cc8
  addPath(PredefinedPath::DRAG_HANDLE_CORNER, corner);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath fromTriangle(QPointF(EASE_TRIANGLE_SIZE / 2, 0));
Jaroslav 203cc8
  fromTriangle.lineTo(QPointF(-EASE_TRIANGLE_SIZE / 2, EASE_TRIANGLE_SIZE));
Jaroslav 203cc8
  fromTriangle.lineTo(QPointF(-EASE_TRIANGLE_SIZE / 2, -EASE_TRIANGLE_SIZE));
Jaroslav 203cc8
  fromTriangle.lineTo(QPointF(EASE_TRIANGLE_SIZE / 2, 0));
Jaroslav 203cc8
  fromTriangle.translate(keyRect.center());
Jaroslav 203cc8
  addPath(PredefinedPath::BEGIN_EASE_TRIANGLE, fromTriangle);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath toTriangle(QPointF(-EASE_TRIANGLE_SIZE / 2, 0));
Jaroslav 203cc8
  toTriangle.lineTo(QPointF(EASE_TRIANGLE_SIZE / 2, EASE_TRIANGLE_SIZE));
Jaroslav 203cc8
  toTriangle.lineTo(QPointF(EASE_TRIANGLE_SIZE / 2, -EASE_TRIANGLE_SIZE));
Jaroslav 203cc8
  toTriangle.lineTo(QPointF(-EASE_TRIANGLE_SIZE / 2, 0));
Jaroslav 203cc8
  toTriangle.translate(keyRect.center());
Jaroslav 203cc8
  addPath(PredefinedPath::END_EASE_TRIANGLE, toTriangle);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath playFrom(QPointF(0, 0));
Jaroslav 203cc8
  playFrom.lineTo(QPointF(PLAY_MARKER_SIZE, 0));
Jaroslav 203cc8
  playFrom.lineTo(QPointF(0, PLAY_MARKER_SIZE));
Jaroslav 203cc8
  playFrom.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  playFrom.translate(1, PLAY_RANGE_Y);
Jaroslav 203cc8
  addPath(PredefinedPath::BEGIN_PLAY_RANGE, playFrom);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath playTo(QPointF(0, 0));
Jaroslav 203cc8
  playTo.lineTo(QPointF(-PLAY_MARKER_SIZE, 0));
Jaroslav 203cc8
  playTo.lineTo(QPointF(0, PLAY_MARKER_SIZE));
Jaroslav 203cc8
  playTo.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  playTo.translate(CELL_WIDTH - 1, PLAY_RANGE_Y);
Jaroslav 203cc8
  addPath(PredefinedPath::END_PLAY_RANGE, playTo);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath track(QPointF(0, 0));
Jaroslav 203cc8
  track.lineTo(QPointF(1, 1));
Jaroslav 203cc8
  track.lineTo(QPointF(trackLen - 1, 1));
Jaroslav 203cc8
  track.lineTo(QPointF(trackLen, 0));
Jaroslav 203cc8
  track.lineTo(QPointF(trackLen - 1, -1));
Jaroslav 203cc8
  track.lineTo(QPointF(1, -1));
Jaroslav 203cc8
  track.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  track.translate(soundTopLeft);
Jaroslav 203cc8
  addPath(PredefinedPath::VOLUME_SLIDER_TRACK, track);
Jaroslav 203cc8
Jaroslav 203cc8
  QPainterPath head(QPointF(0, 0));
Jaroslav 203cc8
  head.lineTo(QPointF(4, -4));
Jaroslav 203cc8
  head.lineTo(QPointF(4, -8));
Jaroslav 203cc8
  head.lineTo(QPointF(-4, -8));
Jaroslav 203cc8
  head.lineTo(QPointF(-4, -4));
Jaroslav 203cc8
  head.lineTo(QPointF(0, 0));
Jaroslav 203cc8
  addPath(PredefinedPath::VOLUME_SLIDER_HEAD, head);
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Points
Jaroslav 203cc8
  //
Jaroslav 203cc8
  addPoint(PredefinedPoint::KEY_HIDDEN, QPoint(0, 10));
Jaroslav 203cc8
  addPoint(PredefinedPoint::EXTENDER_XY_RADIUS, QPoint(75, 30));
shun_iwasawa 0cae24
  addPoint(PredefinedPoint::VOLUME_DIVISIONS_TOP_LEFT,
shun_iwasawa 0cae24
           soundTopLeft + QPoint(0, 3));
Jaroslav 203cc8
Jaroslav 203cc8
  //
Jaroslav 203cc8
  // Ranges
Jaroslav 203cc8
  //
Jaroslav 203cc8
  addRange(PredefinedRange::HEADER_LAYER, NumberRange(0, FRAME_HEADER_HEIGHT));
Jaroslav 203cc8
  addRange(PredefinedRange::HEADER_FRAME, NumberRange(0, LAYER_HEADER_WIDTH));
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
CellPosition LeftToRightOrientation::xyToPosition(const QPoint &xy,
Jaroslav 203cc8
                                                  const ColumnFan *fan) const {
Jaroslav 203cc8
  int layer = fan->layerAxisToCol(xy.y());
Jaroslav 203cc8
  int frame = xy.x() / CELL_WIDTH;
Jaroslav 203cc8
  return CellPosition(frame, layer);
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint LeftToRightOrientation::positionToXY(const CellPosition &position,
Jaroslav 203cc8
                                            const ColumnFan *fan) const {
Jaroslav 203cc8
  int y = colToLayerAxis(position.layer(), fan);
Jaroslav 203cc8
  int x = rowToFrameAxis(position.frame());
Jaroslav 203cc8
  return QPoint(x, y);
Jaroslav 203cc8
}
Jaroslav 203cc8
CellPositionRatio LeftToRightOrientation::xyToPositionRatio(
Jaroslav 203cc8
    const QPoint &xy) const {
Jaroslav 203cc8
  Ratio frame{xy.x(), CELL_WIDTH};
Jaroslav 203cc8
  Ratio layer{xy.y(), CELL_HEIGHT};
Jaroslav 203cc8
  return CellPositionRatio{frame, layer};
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint LeftToRightOrientation::positionRatioToXY(
Jaroslav 203cc8
    const CellPositionRatio &ratio) const {
Jaroslav 203cc8
  int x = ratio.frame() * CELL_WIDTH;
Jaroslav 203cc8
  int y = ratio.layer() * CELL_HEIGHT;
Jaroslav 203cc8
  return QPoint(x, y);
Jaroslav 203cc8
}
Jaroslav 203cc8
Jaroslav 203cc8
int LeftToRightOrientation::colToLayerAxis(int layer,
Jaroslav 203cc8
                                           const ColumnFan *fan) const {
Jaroslav 203cc8
  return fan->colToLayerAxis(layer);
Jaroslav 203cc8
}
Jaroslav 203cc8
int LeftToRightOrientation::rowToFrameAxis(int frame) const {
Jaroslav 203cc8
  return frame * CELL_WIDTH;
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint LeftToRightOrientation::frameLayerToXY(int frameAxis,
Jaroslav 203cc8
                                              int layerAxis) const {
Jaroslav 203cc8
  return QPoint(frameAxis, layerAxis);
Jaroslav 203cc8
}
Jaroslav 203cc8
int LeftToRightOrientation::layerAxis(const QPoint &xy) const { return xy.y(); }
Jaroslav 203cc8
int LeftToRightOrientation::frameAxis(const QPoint &xy) const { return xy.x(); }
Jaroslav 203cc8
NumberRange LeftToRightOrientation::layerSide(const QRect &area) const {
Jaroslav 203cc8
  return NumberRange(area.top(), area.bottom());
Jaroslav 203cc8
}
Jaroslav 203cc8
NumberRange LeftToRightOrientation::frameSide(const QRect &area) const {
Jaroslav 203cc8
  return NumberRange(area.left(), area.right());
Jaroslav 203cc8
}
Jaroslav 203cc8
QPoint LeftToRightOrientation::topRightCorner(const QRect &area) const {
Jaroslav 203cc8
  return area.bottomLeft();
Jaroslav 203cc8
}
Jaroslav 203cc8
CellPosition LeftToRightOrientation::arrowShift(int direction) const {
Jaroslav 203cc8
  switch (direction) {
Jaroslav 203cc8
  case Qt::Key_Up:
Jaroslav 203cc8
    return CellPosition(0, -1);
Jaroslav 203cc8
  case Qt::Key_Down:
Jaroslav 203cc8
    return CellPosition(0, 1);
Jaroslav 203cc8
  case Qt::Key_Left:
Jaroslav 203cc8
    return CellPosition(-1, 0);
Jaroslav 203cc8
  case Qt::Key_Right:
Jaroslav 203cc8
    return CellPosition(1, 0);
Jaroslav 203cc8
  default:
Jaroslav 203cc8
    return CellPosition(0, 0);
Jaroslav 203cc8
  }
Jaroslav 203cc8
}