Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/spreadsheetviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qkeyevent></qkeyevent>
Toshihiro Shimizu 890ddd
#include <qwheelevent></qwheelevent>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Campbell Barton d0e335
#include <qscrollbar></qscrollbar>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qgridlayout></qgridlayout>
Toshihiro Shimizu 890ddd
#include <qpaintevent></qpaintevent>
Toshihiro Shimizu 890ddd
#include <qtooltip></qtooltip>
Toshihiro Shimizu 890ddd
#include <assert.h></assert.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qmainwindow></qmainwindow>
Toshihiro Shimizu 890ddd
#include <qdockwidget></qdockwidget>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace Spreadsheet {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Shinya Kitaoka 120a6e
FrameScroller::FrameScroller() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FrameScroller::~FrameScroller() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FrameScroller::connectScroller(FrameScroller *scroller) {
Shinya Kitaoka 120a6e
  if (scroller != this && !m_connectedScrollers.contains(scroller)) {
Shinya Kitaoka 120a6e
    m_connectedScrollers.append(scroller);
Shinya Kitaoka 120a6e
    scroller->connectScroller(this);
Shinya Kitaoka 120a6e
    QScrollBar *sb0 = getFrameScrollArea()->verticalScrollBar();
Shinya Kitaoka 120a6e
    QScrollBar *sb1 = scroller->getFrameScrollArea()->verticalScrollBar();
Shinya Kitaoka 120a6e
    QObject::connect(sb0, SIGNAL(valueChanged(int)), sb1, SLOT(setValue(int)));
Shinya Kitaoka 120a6e
    QObject::connect(sb1, SIGNAL(valueChanged(int)), sb0, SLOT(setValue(int)));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameScroller::disconnectScroller(FrameScroller *scroller) {
Shinya Kitaoka 120a6e
  if (m_connectedScrollers.contains(scroller)) {
Shinya Kitaoka 120a6e
    m_connectedScrollers.removeAll(scroller);
Shinya Kitaoka 120a6e
    scroller->disconnectScroller(this);
Shinya Kitaoka 120a6e
    QScrollBar *sb0 = getFrameScrollArea()->verticalScrollBar();
Shinya Kitaoka 120a6e
    QScrollBar *sb1 = scroller->getFrameScrollArea()->verticalScrollBar();
Shinya Kitaoka 120a6e
    QObject::disconnect(sb0, SIGNAL(valueChanged(int)), sb1,
Shinya Kitaoka 120a6e
                        SLOT(setValue(int)));
Shinya Kitaoka 120a6e
    QObject::disconnect(sb1, SIGNAL(valueChanged(int)), sb0,
Shinya Kitaoka 120a6e
                        SLOT(setValue(int)));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FrameScroller::isScrollerConnected(FrameScroller *scroller) {
Shinya Kitaoka 120a6e
  return m_connectedScrollers.contains(scroller);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static QList<framescroller *=""> frameScrollers;</framescroller>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameScroller::registerFrameScroller() {
Shinya Kitaoka 120a6e
  if (!frameScrollers.contains(this)) {
Shinya Kitaoka 120a6e
    for (int i = 0; i < frameScrollers.size(); i++)
Shinya Kitaoka 120a6e
      connectScroller(frameScrollers[i]);
Shinya Kitaoka 120a6e
    frameScrollers.append(this);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameScroller::unregisterFrameScroller() {
Shinya Kitaoka 120a6e
  if (frameScrollers.contains(this)) {
Shinya Kitaoka 120a6e
    frameScrollers.removeAll(this);
Shinya Kitaoka 120a6e
    for (int i = 0; i < frameScrollers.size(); i++)
Shinya Kitaoka 120a6e
      disconnectScroller(frameScrollers[i]);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FrameScroller::prepareToScroll(int dy) {
Shinya Kitaoka 120a6e
  if (dy == 0) return;
Shinya Kitaoka 120a6e
  for (int i = 0; i < frameScrollers.size(); i++)
Shinya Kitaoka 120a6e
    if (frameScrollers[i] != this) frameScrollers[i]->onPrepareToScroll(dy);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetFrameDragTool::click(int row, int col, QMouseEvent *e) {
Shinya Kitaoka 120a6e
  m_frameHandle->setFrame(row);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetFrameDragTool::drag(int row, int col, QMouseEvent *e) {
Shinya Kitaoka 120a6e
  if (row < 0) row = 0;
Shinya Kitaoka 120a6e
  m_frameHandle->setFrame(row);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetFrameDragTool::release(int row, int col, QMouseEvent *e) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SelectionDragTool
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SelectionDragTool::SelectionDragTool(SpreadsheetViewer *viewer)
Shinya Kitaoka 120a6e
    : m_viewer(viewer), m_firstRow(-1), m_firstCol(-1) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SelectionDragTool::click(int row, int col, QMouseEvent *e) {
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_viewer->selectCells(selectedCells);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SelectionDragTool::drag(int row, int col, QMouseEvent *e) {
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_viewer->selectCells(selectedCells);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SelectionDragTool::release(int row, int col, QMouseEvent *e) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PanTool::PanTool(Spreadsheet::GenericPanel *panel)
Shinya Kitaoka 120a6e
    : m_panel(panel), m_viewer(panel->getViewer()), m_lastPos() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void PanTool::click(int row, int col, QMouseEvent *e) {
Shinya Kitaoka 120a6e
  m_lastPos = e->pos();  // m_panel->mapToGlobal(e->pos());
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void PanTool::drag(int row, int col, QMouseEvent *e) {
Shinya Kitaoka 120a6e
  QPoint pos = e->pos();  // m_panel->mapToGlobal(e->pos());
Shinya Kitaoka 120a6e
  // QPoint delta = p - m_lastPos;
Shinya Kitaoka 120a6e
  // m_lastPos = p;
Shinya Kitaoka 120a6e
  // QToolTip::showText(p,"delta="+QString::number(delta.x())+","+QString::number(delta.y()));
Shinya Kitaoka 120a6e
  m_viewer->scroll(m_lastPos - pos);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void PanTool::release(int row, int col, QMouseEvent *e) {
Shinya Kitaoka 120a6e
  // QToolTip::hideText();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Toshihiro Shimizu 890ddd
ScrollArea::ScrollArea(QWidget *parent, Qt::WindowFlags flags)
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
ScrollArea::ScrollArea(QWidget *parent, Qt::WFlags flags)
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    : QScrollArea(parent) {
Shinya Kitaoka 120a6e
  setFrameStyle(QFrame::Panel | QFrame::Raised);
Shinya Kitaoka 120a6e
  setLineWidth(6);
Shinya Kitaoka 120a6e
  setContentsMargins(10, 10, 10, 10);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ScrollArea::~ScrollArea() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ScrollArea::keyPressEvent(QKeyEvent *e) { e->ignore(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ScrollArea::wheelEvent(QWheelEvent *e) { e->ignore(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
GenericPanel::GenericPanel(SpreadsheetViewer *viewer)
Shinya Kitaoka 120a6e
    : QWidget(viewer), m_viewer(viewer), m_dragTool(0) {
Shinya Kitaoka 120a6e
  setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
GenericPanel::~GenericPanel() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GenericPanel::paintEvent(QPaintEvent *e) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
  p.setPen(m_viewer->getLightLineColor());
Shinya Kitaoka 120a6e
  for (int c = 0;; c++) {
Shinya Kitaoka 120a6e
    int x = getViewer()->columnToX(c);
Shinya Kitaoka 120a6e
    if (x > width()) break;
Shinya Kitaoka 120a6e
    p.drawLine(x, 0, x, height());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (int r = 0;; r++) {
Shinya Kitaoka 120a6e
    int y = getViewer()->rowToY(r);
Shinya Kitaoka 120a6e
    if (y > height()) break;
Shinya Kitaoka 120a6e
    p.drawLine(0, y, width(), y);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  p.setPen(Qt::magenta);
Shinya Kitaoka 120a6e
  p.drawLine(e->rect().topLeft(), e->rect().bottomRight());
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void GenericPanel::mousePressEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  assert(!m_dragTool);
Shinya Kitaoka 120a6e
  if (e->button() == Qt::MidButton)
Shinya Kitaoka 120a6e
    m_dragTool = new PanTool(this);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_dragTool = createDragTool(e);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int row = getViewer()->yToRow(e->pos().y());
Shinya Kitaoka 120a6e
  int col = getViewer()->xToColumn(e->pos().x());
Shinya Kitaoka 120a6e
  if (m_dragTool) m_dragTool->click(row, col, e);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void GenericPanel::mouseReleaseEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  int row = getViewer()->yToRow(e->pos().y());
Shinya Kitaoka 120a6e
  int col = getViewer()->xToColumn(e->pos().x());
Shinya Kitaoka 120a6e
  m_viewer->stopAutoPan();
Shinya Kitaoka 120a6e
  if (m_dragTool) {
Shinya Kitaoka 120a6e
    m_dragTool->release(row, col, e);
Shinya Kitaoka 120a6e
    delete m_dragTool;
Shinya Kitaoka 120a6e
    m_dragTool = 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GenericPanel::mouseMoveEvent(QMouseEvent *e) {
Shinya Kitaoka 120a6e
  int row = getViewer()->yToRow(e->pos().y());
Shinya Kitaoka 120a6e
  int col = getViewer()->xToColumn(e->pos().x());
Shinya Kitaoka 120a6e
  if (e->buttons() != 0 && m_dragTool != 0) {
Shinya Kitaoka 120a6e
    if ((e->buttons() & Qt::LeftButton) != 0 &&
Shinya Kitaoka 120a6e
        !visibleRegion().contains(e->pos())) {
Shinya Kitaoka 120a6e
      QRect bounds = visibleRegion().boundingRect();
Shinya Kitaoka 120a6e
      m_viewer->setAutoPanSpeed(bounds, e->pos());
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      m_viewer->stopAutoPan();
Shinya Kitaoka 120a6e
    m_dragTool->drag(row, col, e);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
RowPanel::RowPanel(SpreadsheetViewer *viewer)
Shinya Kitaoka 120a6e
    : GenericPanel(viewer), m_xa(12) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DragTool *RowPanel::createDragTool(QMouseEvent *) {
Shinya Kitaoka 120a6e
  TFrameHandle *frameHandle = getViewer()->getFrameHandle();
Shinya Kitaoka 120a6e
  if (frameHandle)
Shinya Kitaoka 120a6e
    return new SetFrameDragTool(frameHandle);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RowPanel::drawRows(QPainter &p, int r0, int r1) {
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  static QFont font("Arial", 9, QFont::Bold);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  static QFont font("Helvetica", 9, QFont::Bold);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  p.setFont(font);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QRect visibleRect = visibleRegion().boundingRect();
Shinya Kitaoka 120a6e
  int x0            = visibleRect.left();
Shinya Kitaoka 120a6e
  int x1            = visibleRect.right();
Shinya Kitaoka 120a6e
  int y0            = visibleRect.top();
Shinya Kitaoka 120a6e
  int y1            = visibleRect.bottom();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int r;
Shinya Kitaoka 120a6e
  for (r = r0; r <= r1; r++) {
Shinya Kitaoka 120a6e
    int y = getViewer()->rowToY(r);
Shinya Kitaoka 120a6e
    // draw horizontal line
Shinya Kitaoka 120a6e
    QColor color = (getViewer()->isMarkRow(r))
Shinya Kitaoka 120a6e
                       ? getViewer()->getMarkerLineColor()
Shinya Kitaoka 120a6e
                       : getViewer()->getLightLineColor();
Shinya Kitaoka 120a6e
    p.setPen(color);
Shinya Kitaoka 120a6e
    p.drawLine(x0, y, x1, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // draw numbers
Shinya Kitaoka 120a6e
    p.setPen(getViewer()->getTextColor());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QString number = QString::number(r + 1);
Shinya Kitaoka 120a6e
    p.drawText(QRect(x0, y + 1, width(), 18),
Shinya Kitaoka 120a6e
               Qt::AlignHCenter | Qt::AlignBottom, number);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // erase the marker interval at upper-end
Shinya Kitaoka 120a6e
  if (r0 == 0) {
Shinya Kitaoka 120a6e
    p.setPen(getViewer()->getLightLineColor());
Shinya Kitaoka 120a6e
    p.drawLine(x0, getViewer()->rowToY(0), x1, getViewer()->rowToY(0));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RowPanel::drawCurrentRowGadget(QPainter &p, int r0, int r1) {
Shinya Kitaoka 120a6e
  int currentRow = getViewer()->getCurrentRow();
Shinya Kitaoka 120a6e
  int y          = getViewer()->rowToY(currentRow);
Shinya Kitaoka 120a6e
  if (currentRow < r0 || r1 < currentRow) return;
Shinya Kitaoka 120a6e
  p.fillRect(1, y + 1, width() - 2, 19, getViewer()->getCurrentRowBgColor());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RowPanel::paintEvent(QPaintEvent *e) {
Shinya Kitaoka 120a6e
  QRect toBeUpdated = e->rect();
Shinya Kitaoka 120a6e
  QPainter p(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // range di righe visibili
Shinya Kitaoka 120a6e
  int r0 = getViewer()->yToRow(toBeUpdated.top());
Shinya Kitaoka 120a6e
  int r1 = getViewer()->yToRow(toBeUpdated.bottom());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p.setClipRect(toBeUpdated);
Shinya Kitaoka 120a6e
  p.fillRect(toBeUpdated, QBrush(getViewer()->getLightLightBGColor()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  drawCurrentRowGadget(p, r0, r1);
Shinya Kitaoka 120a6e
  drawRows(p, r0, r1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ColumnPanel::ColumnPanel(SpreadsheetViewer *viewer) : GenericPanel(viewer) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
CellPanel::CellPanel(SpreadsheetViewer *viewer) : GenericPanel(viewer) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DragTool *CellPanel::createDragTool(QMouseEvent *) {
Shinya Kitaoka 120a6e
  // FunctionSheetCellViewer::createDragTool is called instead
Shinya Kitaoka 120a6e
  // when clicking on the CellPanel in NumericalColumns
Shinya Kitaoka 120a6e
  return new SelectionDragTool(getViewer());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CellPanel::paintEvent(QPaintEvent *e) {
Shinya Kitaoka 120a6e
  QPainter painter(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QRect toBeUpdated = e->rect();
Shinya Kitaoka 120a6e
  painter.setClipRect(toBeUpdated);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int x0 = toBeUpdated.left() - 1;
Shinya Kitaoka 120a6e
  int y0 = toBeUpdated.top();
Shinya Kitaoka 120a6e
  int x1 = toBeUpdated.right(), y1 = toBeUpdated.bottom();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // visible rows range
Shinya Kitaoka 120a6e
  int r0 = getViewer()->yToRow(y0);
Shinya Kitaoka 120a6e
  int r1 = getViewer()->yToRow(y1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // visible columns range
Shinya Kitaoka 120a6e
  int c0 = getViewer()->xToColumn(x0);
Shinya Kitaoka 120a6e
  int c1 = getViewer()->xToColumn(x1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // cambia colore alle celle prima di rowCount()
Shinya Kitaoka 120a6e
  int rowCount = getViewer()->getRowCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // fill with bg color
Shinya Kitaoka 120a6e
  painter.fillRect(toBeUpdated, getViewer()->getLightLightBGColor());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // scene range bg
Shinya Kitaoka 120a6e
  int yLast = getViewer()->rowToY(rowCount);
Shinya Kitaoka 120a6e
  if (yLast < y1)
Shinya Kitaoka 120a6e
    painter.fillRect(x0, y0, x1 - x0, yLast - y0, getViewer()->getBGColor());
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    painter.fillRect(toBeUpdated, getViewer()->getBGColor());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // draw cells
Shinya Kitaoka 120a6e
  drawCells(painter, r0, c0, r1, c1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // draw columns
Shinya Kitaoka 120a6e
  painter.setPen(getViewer()->getVerticalLineColor());
Shinya Kitaoka 120a6e
  for (int col = c0; col <= c1; col++) {
Shinya Kitaoka 120a6e
    int x = getViewer()->columnToX(col);
Shinya Kitaoka 120a6e
    painter.drawLine(x, y0, x, y1);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // draw rows
Shinya Kitaoka 120a6e
  int currentRow = getViewer()->getCurrentRow();
Shinya Kitaoka 120a6e
  for (int r = r0; r <= r1; r++) {
Shinya Kitaoka 120a6e
    int y        = getViewer()->rowToY(r);
Shinya Kitaoka 120a6e
    QColor color = getViewer()->isMarkRow(r) ? getViewer()->getMarkerLineColor()
Shinya Kitaoka 120a6e
                                             : getViewer()->getLightLineColor();
Shinya Kitaoka 120a6e
    painter.setPen(color);
Shinya Kitaoka 120a6e
    painter.drawLine(x0, y, x1, y);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // erase the marker interval at upper-end
Shinya Kitaoka 120a6e
  painter.setPen(getViewer()->getLightLineColor());
Shinya Kitaoka 120a6e
  painter.drawLine(x0, 0, x1, 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace Spreadsheet
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SpreadsheetViewer::SpreadsheetViewer(QWidget *parent)
Shinya Kitaoka 120a6e
    : QFrame(parent)
Shinya Kitaoka 120a6e
    , m_columnScrollArea(0)
Shinya Kitaoka 120a6e
    , m_rowScrollArea(0)
Shinya Kitaoka 120a6e
    , m_cellScrollArea(0)
Shinya Kitaoka 120a6e
    , m_frameHandle(0)
Shinya Kitaoka 120a6e
    , m_columnWidth(50)
Shinya Kitaoka 120a6e
    , m_rowHeight(20)
Shinya Kitaoka 120a6e
    , m_timerId(0)
Shinya Kitaoka 120a6e
    , m_autoPanSpeed(0, 0)
Shinya Kitaoka 120a6e
    , m_lastAutoPanPos(0, 0)
Shinya Kitaoka 120a6e
    , m_rowCount(0)
Shinya Kitaoka 120a6e
    , m_columnCount(0)
Shinya Kitaoka 120a6e
    , m_currentRow(0)
Shinya Kitaoka 120a6e
    , m_markRowDistance(6)
Shinya Kitaoka 120a6e
    , m_markRowOffset(0)
Shinya Kitaoka 120a6e
    , m_isComputingSize(false) {
Shinya Kitaoka 120a6e
  setFocusPolicy(Qt::NoFocus);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  setFrameStyle(QFrame::StyledPanel);
Shinya Kitaoka 120a6e
  setObjectName("Viewer");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // column header
Shinya Kitaoka 120a6e
  m_columnScrollArea = new Spreadsheet::ScrollArea;
Shinya Kitaoka 120a6e
  m_columnScrollArea->setObjectName("ScrollArea");
Shinya Kitaoka 120a6e
  m_columnScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  m_columnScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  m_columnScrollArea->setFocusPolicy(Qt::NoFocus);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // row area
Shinya Kitaoka 120a6e
  m_rowScrollArea = new Spreadsheet::ScrollArea;
Shinya Kitaoka 120a6e
  m_rowScrollArea->setObjectName("ScrollArea");
Shinya Kitaoka 120a6e
  m_rowScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  m_rowScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Shinya Kitaoka 120a6e
  m_rowScrollArea->setFocusPolicy(Qt::NoFocus);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // cell area
Shinya Kitaoka 120a6e
  m_cellScrollArea = new Spreadsheet::ScrollArea;
Shinya Kitaoka 120a6e
  m_cellScrollArea->setObjectName("ScrollArea");
Shinya Kitaoka 120a6e
  m_cellScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
Shinya Kitaoka 120a6e
  m_cellScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
Shinya Kitaoka 120a6e
  m_cellScrollArea->horizontalScrollBar()->setObjectName("XsheetScrollBar");
Shinya Kitaoka 120a6e
  m_cellScrollArea->verticalScrollBar()->setObjectName("XsheetScrollBar");
Shinya Kitaoka 120a6e
  m_cellScrollArea->setFocusPolicy(Qt::NoFocus);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_columnScrollArea->setSizePolicy(
Shinya Kitaoka 120a6e
      QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
Shinya Kitaoka 120a6e
  m_rowScrollArea->setSizePolicy(
Shinya Kitaoka 120a6e
      QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_rowScrollArea->setFixedWidth(30);
Shinya Kitaoka 120a6e
  m_columnScrollArea->setFixedHeight(m_rowHeight * 3 - 3);
Shinya Kitaoka 120a6e
  // m_columnScrollArea->setFixedHeight(m_rowHeight * 3 + 60 - 63);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //---- layout
Shinya Kitaoka 120a6e
  QGridLayout *layout = new QGridLayout();
Shinya Kitaoka 120a6e
  layout->setMargin(0);
Shinya Kitaoka 120a6e
  layout->setSpacing(0);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    layout->addWidget(m_columnScrollArea, 0, 1);
Shinya Kitaoka 120a6e
    layout->addWidget(m_rowScrollArea, 1, 0);
Shinya Kitaoka 120a6e
    layout->addWidget(m_cellScrollArea, 1, 1, 2, 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // upper-right
Shinya Kitaoka 120a6e
    QWidget *w = new QWidget(this);
Shinya Kitaoka 120a6e
    w->setFixedSize(QSize(20, m_rowHeight * 3 + 60 - 63));
Shinya Kitaoka 120a6e
    layout->addWidget(w, 0, 2);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    // lower-left
Shinya Kitaoka 120a6e
    w = new QWidget(this);
Shinya Kitaoka 120a6e
    w->setFixedSize(QSize(30, 20));
Shinya Kitaoka 120a6e
    layout->addWidget(w, 2, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    layout->setColumnStretch(0, 0);
Shinya Kitaoka 120a6e
    layout->setColumnStretch(1, 1);
Shinya Kitaoka 120a6e
    layout->setColumnStretch(2, 0);
Shinya Kitaoka 120a6e
    layout->setRowStretch(0, 0);
Shinya Kitaoka 120a6e
    layout->setRowStretch(1, 1);
Shinya Kitaoka 120a6e
    layout->setRowStretch(2, 0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setLayout(layout);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //---signal-slot connections
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // vertical slider: cell <=> row
Shinya Kitaoka 120a6e
  connect(m_rowScrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
Shinya Kitaoka 120a6e
          m_cellScrollArea->verticalScrollBar(), SLOT(setValue(int)));
Shinya Kitaoka 120a6e
  connect(m_cellScrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
Shinya Kitaoka 120a6e
          m_rowScrollArea->verticalScrollBar(), SLOT(setValue(int)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // horizontal slider: cell <=> column
Shinya Kitaoka 120a6e
  connect(m_columnScrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
Shinya Kitaoka 120a6e
          m_cellScrollArea->horizontalScrollBar(), SLOT(setValue(int)));
Shinya Kitaoka 120a6e
  connect(m_cellScrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
Shinya Kitaoka 120a6e
          m_columnScrollArea->horizontalScrollBar(), SLOT(setValue(int)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  connect(m_cellScrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)),
Shinya Kitaoka 120a6e
          SLOT(onVSliderChanged(int)));
Shinya Kitaoka 120a6e
  connect(m_cellScrollArea->horizontalScrollBar(), SIGNAL(valueChanged(int)),
Shinya Kitaoka 120a6e
          SLOT(onHSliderChanged(int)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SpreadsheetViewer::~SpreadsheetViewer() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setFrameHandle(TFrameHandle *frameHandle) {
Shinya Kitaoka 120a6e
  if (m_frameHandle == frameHandle) return;
Shinya Kitaoka 120a6e
  if (m_frameHandle) m_frameHandle->disconnect(this);
Shinya Kitaoka 120a6e
  m_frameHandle = frameHandle;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (isVisible() && m_frameHandle) {
Shinya Kitaoka 120a6e
    connect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
            SLOT(onFrameSwitched()));
Shinya Kitaoka 120a6e
    update();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setRowsPanel(Spreadsheet::RowPanel *rows) {
Shinya Kitaoka 120a6e
  m_rowScrollArea->setWidget(rows);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setColumnsPanel(Spreadsheet::ColumnPanel *columns) {
Shinya Kitaoka 120a6e
  m_columnScrollArea->setWidget(columns);
Shinya Kitaoka 120a6e
  // columns->setFixedHeight(200);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setCellsPanel(Spreadsheet::CellPanel *cells) {
Shinya Kitaoka 120a6e
  m_cellScrollArea->setWidget(cells);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setRowCount(int rowCount) {
Shinya Kitaoka 120a6e
  if (m_rowCount != rowCount) {
Shinya Kitaoka 120a6e
    m_rowCount = rowCount;
Shinya Kitaoka 120a6e
    refreshContentSize(0, 0);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setColumnCount(int columnCount) {
Shinya Kitaoka 120a6e
  if (m_columnCount != columnCount) {
Shinya Kitaoka 120a6e
    m_columnCount = columnCount;
Shinya Kitaoka 120a6e
    refreshContentSize(0, 0);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
tomosu de525f
Shinya Kitaoka 120a6e
void SpreadsheetViewer::scroll(QPoint delta) {
Shinya Kitaoka 120a6e
  int x = delta.x();
Shinya Kitaoka 120a6e
  int y = delta.y();
Shinya Kitaoka 120a6e
  prepareToScroll(y);
tomosu de525f
Shinya Kitaoka 120a6e
  QScrollBar *hSc = m_cellScrollArea->horizontalScrollBar();
Shinya Kitaoka 120a6e
  QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
tomosu de525f
Shinya Kitaoka 120a6e
  int valueH    = hSc->value() + x;
Shinya Kitaoka 120a6e
  int valueV    = vSc->value() + y;
Shinya Kitaoka 120a6e
  int maxValueH = hSc->maximum();
Shinya Kitaoka 120a6e
  int maxValueV = vSc->maximum();
tomosu de525f
Shinya Kitaoka 120a6e
  bool notUpdateSizeH = maxValueH > valueH && x >= 0;
Shinya Kitaoka 120a6e
  bool notUpdateSizeV = maxValueV > valueV && y >= 0;
Shinya Kitaoka 120a6e
  if ((!notUpdateSizeH) && (!notUpdateSizeV))
Shinya Kitaoka 120a6e
    refreshContentSize(x, y);
Shinya Kitaoka 120a6e
  else if (notUpdateSizeH && !notUpdateSizeV)
Shinya Kitaoka 120a6e
    refreshContentSize(0, y);
Shinya Kitaoka 120a6e
  else if (!notUpdateSizeH && notUpdateSizeV)
Shinya Kitaoka 120a6e
    refreshContentSize(x, 0);
tomosu de525f
Shinya Kitaoka 120a6e
  if (valueH > maxValueH && x > 0) valueH = hSc->maximum();
tomosu de525f
Shinya Kitaoka 120a6e
  if (valueV > maxValueV && y > 0) valueV = vSc->maximum();
tomosu de525f
Shinya Kitaoka 120a6e
  hSc->setValue(valueH);
Shinya Kitaoka 120a6e
  vSc->setValue(valueV);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setAutoPanSpeed(const QPoint &speed) {
Shinya Kitaoka 120a6e
  bool wasAutoPanning = isAutoPanning();
Shinya Kitaoka 120a6e
  m_autoPanSpeed      = speed;
Shinya Kitaoka 120a6e
  if (isAutoPanning() && !wasAutoPanning && m_timerId == 0)
Shinya Kitaoka 120a6e
    m_timerId = startTimer(40);
Shinya Kitaoka 120a6e
  else if (!isAutoPanning() && wasAutoPanning && m_timerId != 0) {
Shinya Kitaoka 120a6e
    killTimer(m_timerId);
Shinya Kitaoka 120a6e
    m_timerId = 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int getAutoPanSpeed(int pixels) {
Shinya Kitaoka 120a6e
  int f = 40;
Shinya Kitaoka 120a6e
  return std::min(100, (f - 1 + pixels * f) / 100);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::setAutoPanSpeed(const QRect &widgetBounds,
Shinya Kitaoka 120a6e
                                        const QPoint &mousePos) {
Shinya Kitaoka 120a6e
  QPoint speed;
Shinya Kitaoka 120a6e
  int limit = 100, factor = 30;
Shinya Kitaoka 120a6e
  if (mousePos.x() < widgetBounds.left())
Shinya Kitaoka 120a6e
    speed.setX(-getAutoPanSpeed(widgetBounds.left() - mousePos.x()));
Shinya Kitaoka 120a6e
  else if (mousePos.x() > widgetBounds.right())
Shinya Kitaoka 120a6e
    speed.setX(getAutoPanSpeed(mousePos.x() - widgetBounds.right()));
Shinya Kitaoka 120a6e
  if (mousePos.y() < widgetBounds.top())
Shinya Kitaoka 120a6e
    speed.setY(-getAutoPanSpeed(widgetBounds.top() - mousePos.y()));
Shinya Kitaoka 120a6e
  else if (mousePos.y() > widgetBounds.bottom())
Shinya Kitaoka 120a6e
    speed.setY(getAutoPanSpeed(mousePos.y() - widgetBounds.bottom()));
Shinya Kitaoka 120a6e
  setAutoPanSpeed(speed);
Shinya Kitaoka 120a6e
  m_lastAutoPanPos = mousePos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Shinya Kitaoka 120a6e
int SpreadsheetViewer::xToColumn(int x) const {
Shinya Kitaoka 120a6e
  return (x + 1) / m_columnWidth;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Shinya Kitaoka 120a6e
int SpreadsheetViewer::columnToX(int col) const {
Shinya Kitaoka 120a6e
  return (col * m_columnWidth) - 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Shinya Kitaoka 120a6e
int SpreadsheetViewer::yToRow(int y) const { return (y + 1) / m_rowHeight; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!Shift is a consequence of style sheet border.*/
Shinya Kitaoka 120a6e
int SpreadsheetViewer::rowToY(int row) const { return (row * m_rowHeight) - 1; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool SpreadsheetViewer::refreshContentSize(int scrollDx, int scrollDy) {
Shinya Kitaoka 120a6e
  QSize viewportSize = m_cellScrollArea->viewport()->size();
Shinya Kitaoka 120a6e
  QPoint offset      = m_cellScrollArea->widget()->pos();
Shinya Kitaoka 120a6e
  offset =
Shinya Kitaoka 120a6e
      QPoint(qMin(0, offset.x() - scrollDx), qMin(0, offset.y() - scrollDy));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QSize contentSize(columnToX(m_columnCount + 1), rowToY(m_rowCount + 1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QSize actualSize(contentSize);
Shinya Kitaoka 120a6e
  int x = viewportSize.width() - offset.x();
Shinya Kitaoka 120a6e
  int y = viewportSize.height() - offset.y();
Shinya Kitaoka 120a6e
  if (x > actualSize.width()) actualSize.setWidth(x);
Shinya Kitaoka 120a6e
  if (y > actualSize.height()) actualSize.setHeight(y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (actualSize == m_cellScrollArea->widget()->size())
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    m_isComputingSize = true;
Shinya Kitaoka 120a6e
    m_cellScrollArea->widget()->setFixedSize(actualSize);
Shinya Kitaoka 120a6e
    m_rowScrollArea->widget()->setFixedSize(
Shinya Kitaoka 120a6e
        m_rowScrollArea->viewport()->width(), actualSize.height());
Shinya Kitaoka 120a6e
    m_columnScrollArea->widget()->setFixedSize(
Shinya Kitaoka 120a6e
        actualSize.width(), m_columnScrollArea->viewport()->height());
Shinya Kitaoka 120a6e
    m_isComputingSize = false;
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::showEvent(QShowEvent *) {
Shinya Kitaoka 120a6e
  int viewportHeight      = m_cellScrollArea->height();
Shinya Kitaoka 120a6e
  int contentHeight       = rowToY(m_rowCount * 0 + 50);
Shinya Kitaoka 120a6e
  QScrollBar *vSc         = m_cellScrollArea->verticalScrollBar();
Shinya Kitaoka 120a6e
  int actualContentHeight = qMax(contentHeight, vSc->value() + viewportHeight);
Shinya Kitaoka 120a6e
  m_rowScrollArea->widget()->setFixedHeight(actualContentHeight);
Shinya Kitaoka 120a6e
  m_cellScrollArea->widget()->setFixedHeight(actualContentHeight);
Shinya Kitaoka 120a6e
  if (m_frameHandle)
Shinya Kitaoka 120a6e
    connect(m_frameHandle, SIGNAL(frameSwitched()), this,
Shinya Kitaoka 120a6e
            SLOT(onFrameSwitched()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // updateAreasSize();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::hideEvent(QHideEvent *) {
Shinya Kitaoka 120a6e
  if (m_frameHandle) m_frameHandle->disconnect(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::resizeEvent(QResizeEvent *e) {
Shinya Kitaoka 120a6e
  QFrame::resizeEvent(e);
Shinya Kitaoka 120a6e
  refreshContentSize(0, 0);
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
  int w = width();
Shinya Kitaoka 120a6e
  int h = height();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int hSpacing = 4;
Shinya Kitaoka 120a6e
int vSpacing = 4;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int x = m_rowScrollAreaWidth + hSpacing;
Shinya Kitaoka 120a6e
int y = m_columnScrollAreaHeight + vSpacing;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_cellScrollArea->setGeometry(x,y, w-x, h-y);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int sh = m_cellScrollArea->horizontalScrollBar()->height();
Shinya Kitaoka 120a6e
int sw = m_cellScrollArea->verticalScrollBar()->width();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_columnScrollArea->setGeometry(x, 0, w-x-sw, m_columnScrollAreaHeight);
Shinya Kitaoka 120a6e
m_rowScrollArea->setGeometry(0, y, m_rowScrollAreaWidth, h-y-sh);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
updateSizeToScroll(0,0); //Non updateAreeSize() perche' si deve tener conto
Shinya Kitaoka 120a6e
degli scrollbar.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::wheelEvent(QWheelEvent *event) {
Shinya Kitaoka 120a6e
  switch (event->source()) {
Shinya Kitaoka 120a6e
  case Qt::MouseEventNotSynthesized: {
Shinya Kitaoka 120a6e
    if (event->angleDelta().x() == 0) {  // vertical scroll
Shinya Kitaoka 120a6e
      int scrollPixels = (event->angleDelta().y() > 0 ? 1 : -1) *
Shinya Kitaoka 120a6e
                         m_markRowDistance * m_rowHeight;
Shinya Kitaoka 120a6e
      scroll(QPoint(0, -scrollPixels));
Shinya Kitaoka 120a6e
    } else {  // horizontal scroll
Shinya Kitaoka 120a6e
      int scrollPixels = (event->angleDelta().x() > 0 ? 1 : -1) * m_columnWidth;
Shinya Kitaoka 120a6e
      scroll(QPoint(-scrollPixels, 0));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case Qt::MouseEventSynthesizedBySystem:  // macbook touch-pad
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    QPoint numPixels  = event->pixelDelta();
Shinya Kitaoka 120a6e
    QPoint numDegrees = event->angleDelta() / 8;
Shinya Kitaoka 120a6e
    if (!numPixels.isNull()) {
Shinya Kitaoka 120a6e
      scroll(-numPixels);
Shinya Kitaoka 120a6e
    } else if (!numDegrees.isNull()) {
Shinya Kitaoka 120a6e
      QPoint numSteps = numDegrees / 15;
Shinya Kitaoka 120a6e
      scroll(-numSteps);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  default:  // Qt::MouseEventSynthesizedByQt,
Shinya Kitaoka 120a6e
            // Qt::MouseEventSynthesizedByApplication
Shinya Kitaoka 38fd86
    {
Shinya Kitaoka 38fd86
      std::cout << "not supported wheelEvent.source(): "
Shinya Kitaoka 38fd86
                   "Qt::MouseEventSynthesizedByQt, "
Shinya Kitaoka 38fd86
                   "Qt::MouseEventSynthesizedByApplication"
Shinya Kitaoka 38fd86
                << std::endl;
Shinya Kitaoka 38fd86
      break;
Shinya Kitaoka 38fd86
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  }  // end switch
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::timerEvent(QTimerEvent *e) {
Shinya Kitaoka 120a6e
  if (!isAutoPanning()) return;
Shinya Kitaoka 120a6e
  scroll(m_autoPanSpeed);
Shinya Kitaoka 120a6e
  m_lastAutoPanPos += m_autoPanSpeed;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
if(m_dragTool)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
QMouseEvent mouseEvent(QEvent::MouseMove, m_lastAutoPanPos, Qt::NoButton, 0, 0);
Shinya Kitaoka 120a6e
m_dragTool->onDrag(&mouseEvent);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SpreadsheetViewer::keyPressEvent(QKeyEvent *e) {
Shinya Kitaoka 120a6e
  int frameCount = m_rowCount;
Shinya Kitaoka 120a6e
  int row        = m_frameHandle->getFrame();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (e->key() == Qt::Key_Up &&
Shinya Kitaoka 120a6e
      row > 0) {  // Row = frame precedente a quello settato
Shinya Kitaoka 120a6e
    m_frameHandle->setFrame(row - 1);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (e->key() ==
Shinya Kitaoka 120a6e
             Qt::Key_Down) {  // Row = frame successivo a quello settato
Shinya Kitaoka 120a6e
    m_frameHandle->setFrame(row + 1);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (e->key() == '0') {
Shinya Kitaoka 120a6e
    QWidget *panel       = parentWidget();
Shinya Kitaoka 120a6e
    QWidget *panelParent = panel->parentWidget();
Shinya Kitaoka 120a6e
    while (panelParent != 0 && dynamic_cast<qmainwindow *="">(panelParent) == 0) {</qmainwindow>
Shinya Kitaoka 120a6e
      panel       = panelParent;
Shinya Kitaoka 120a6e
      panelParent = panel->parentWidget();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (panelParent) {
Shinya Kitaoka 120a6e
      QList<qdockwidget *=""> panels = panelParent->findChildren<qdockwidget *="">();</qdockwidget></qdockwidget>
Shinya Kitaoka 120a6e
      for (int i = 0; i < panels.size(); i++) {
Shinya Kitaoka 120a6e
        QWidget *w = panels[i];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int y = 0;
Shinya Kitaoka 120a6e
  QRect visibleRect =
Shinya Kitaoka 120a6e
      m_cellScrollArea->widget()->visibleRegion().boundingRect();
Shinya Kitaoka 120a6e
  int visibleRowCount = visibleRect.height() / m_rowHeight;
Shinya Kitaoka 120a6e
  if (e->key() ==
Shinya Kitaoka 120a6e
      Qt::Key_PageUp)  // Setto la visualizzazione della pagina precedente
Shinya Kitaoka 120a6e
    y = visibleRect.top() - (visibleRowCount + 1) * m_rowHeight;
Shinya Kitaoka 120a6e
  else if (e->key() == Qt::Key_PageDown)  // Setto la visualizzazione della
Shinya Kitaoka 120a6e
                                          // pagina successiva
Shinya Kitaoka 120a6e
    y = visibleRect.bottom() + (visibleRowCount + 1) * m_rowHeight;
Shinya Kitaoka 120a6e
  else if (e->key() == Qt::Key_Home)
Shinya Kitaoka 120a6e
    y = 0;
Shinya Kitaoka 120a6e
  else if (e->key() == Qt::Key_End)
Shinya Kitaoka 120a6e
    y = (frameCount + 1) * m_rowHeight;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int deltaY = 0;
Shinya Kitaoka 120a6e
  if (y < visibleRect.top())
Shinya Kitaoka 120a6e
    deltaY = y - visibleRect.top();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    deltaY = y - visibleRect.bottom();
Shinya Kitaoka 120a6e
  scroll(QPoint(0, deltaY));
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SpreadsheetViewer::frameSwitched() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateAllAree()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateCellColumnAree()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SpreadsheetViewer::updateCellRowAree()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::updateAreas() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void SpreadsheetViewer::onVSliderChanged(int) {
Shinya Kitaoka 120a6e
  if (!m_isComputingSize) refreshContentSize(0, 0);
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
Shinya Kitaoka 120a6e
int h = qMax(vSc->value() + m_cellScrollArea->height(), rowToY(getRowCount()));
Shinya Kitaoka 120a6e
if(m_cellScrollArea->widget())
Shinya Kitaoka 120a6e
m_cellScrollArea->widget()->setFixedHeight(h);
Shinya Kitaoka 120a6e
if(m_rowScrollArea->widget())
Shinya Kitaoka 120a6e
m_rowScrollArea->widget()->setFixedHeight(h);
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
int viewportHeight = m_cellScrollArea->height();
Shinya Kitaoka 120a6e
int contentHeight = rowToY(m_rowCount*0 + 50);
Shinya Kitaoka 120a6e
QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
Shinya Kitaoka 120a6e
int actualContentHeight = qMax(contentHeight, vSc->value() + viewportHeight);
Shinya Kitaoka 120a6e
m_rowScrollArea->widget()->setFixedHeight(actualContentHeight);
Shinya Kitaoka 120a6e
m_cellScrollArea->widget()->setFixedHeight(actualContentHeight);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::onHSliderChanged(int) {
Shinya Kitaoka 120a6e
  if (!m_isComputingSize) refreshContentSize(0, 0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SpreadsheetViewer::ensureVisibleCol(int col) {
Shinya Kitaoka 120a6e
  int x = columnToX(col) + m_columnWidth / 2;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int vertValue = m_cellScrollArea->verticalScrollBar()->value();
Shinya Kitaoka 120a6e
  m_cellScrollArea->ensureVisible(x, vertValue, m_columnWidth / 2, 0);
Toshihiro Shimizu 890ddd
}