|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/spreadsheetviewer.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.h"
|
|
Jeremy Bullock |
807052 |
#include "toonz/preferences.h"
|
|
Jeremy Bullock |
4ce953 |
#include "toonz/toonzfolders.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Jaroslav |
203cc8 |
#include "orientation.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>
|
|
Jeremy Bullock |
4ce953 |
#include <qsettings></qsettings>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace Spreadsheet {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Jaroslav |
203cc8 |
FrameScroller::FrameScroller()
|
|
Jaroslav |
203cc8 |
: m_orientation(Orientations::topToBottom())
|
|
Jaroslav |
203cc8 |
, m_scrollArea(nullptr)
|
|
Jaroslav |
203cc8 |
, m_lastX(0)
|
|
Jaroslav |
203cc8 |
, m_lastY(0)
|
|
shun_iwasawa |
0cae24 |
, m_syncing(false) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
FrameScroller::~FrameScroller() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Jaroslav |
203cc8 |
void FrameScroller::setFrameScrollArea(QScrollArea *scrollArea) {
|
|
Jaroslav |
203cc8 |
disconnectScrollbars();
|
|
Jaroslav |
203cc8 |
m_scrollArea = scrollArea;
|
|
Jaroslav |
203cc8 |
connectScrollbars();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jaroslav |
203cc8 |
void FrameScroller::disconnectScrollbars() {
|
|
Jaroslav |
203cc8 |
if (!m_scrollArea) return;
|
|
Jaroslav |
203cc8 |
disconnect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this,
|
|
Jaroslav |
203cc8 |
&FrameScroller::onVScroll);
|
|
Jaroslav |
203cc8 |
disconnect(m_scrollArea->horizontalScrollBar(), &QScrollBar::valueChanged,
|
|
Jaroslav |
203cc8 |
this, &FrameScroller::onHScroll);
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
|
|
Jaroslav |
203cc8 |
void FrameScroller::connectScrollbars() {
|
|
Jaroslav |
203cc8 |
if (!m_scrollArea) return;
|
|
Jaroslav |
203cc8 |
m_lastX = m_scrollArea->horizontalScrollBar()->value();
|
|
Jaroslav |
203cc8 |
m_lastY = m_scrollArea->verticalScrollBar()->value();
|
|
Jaroslav |
203cc8 |
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this,
|
|
Jaroslav |
203cc8 |
&FrameScroller::onVScroll);
|
|
Jaroslav |
203cc8 |
connect(m_scrollArea->horizontalScrollBar(), &QScrollBar::valueChanged, this,
|
|
Jaroslav |
203cc8 |
&FrameScroller::onHScroll);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Jaroslav |
203cc8 |
void FrameScroller::onVScroll(int y) {
|
|
Jaroslav |
203cc8 |
QPoint offset(0, y - m_lastY);
|
|
Jaroslav |
203cc8 |
if (isSyncing()) return;
|
|
Jaroslav |
203cc8 |
m_lastY = y;
|
|
shun-iwasawa |
6ca609 |
|
|
shun-iwasawa |
6ca609 |
int senderMaximum = 0;
|
|
shun-iwasawa |
6ca609 |
QScrollBar *scrollBar = dynamic_cast<qscrollbar *="">(sender());</qscrollbar>
|
|
shun-iwasawa |
6ca609 |
if (scrollBar) senderMaximum = scrollBar->maximum();
|
|
shun-iwasawa |
6ca609 |
|
|
Jaroslav |
203cc8 |
setSyncing(true);
|
|
shun-iwasawa |
6ca609 |
handleScroll(offset, senderMaximum, y);
|
|
Jaroslav |
203cc8 |
setSyncing(false);
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
void FrameScroller::onHScroll(int x) {
|
|
Jaroslav |
203cc8 |
QPoint offset(x - m_lastX, 0);
|
|
Jaroslav |
203cc8 |
if (isSyncing()) return;
|
|
Jaroslav |
203cc8 |
m_lastX = x;
|
|
shun-iwasawa |
6ca609 |
|
|
shun-iwasawa |
6ca609 |
int senderMaximum = 0;
|
|
shun-iwasawa |
6ca609 |
QScrollBar *scrollBar = dynamic_cast<qscrollbar *="">(sender());</qscrollbar>
|
|
shun-iwasawa |
6ca609 |
if (scrollBar) senderMaximum = scrollBar->maximum();
|
|
shun-iwasawa |
6ca609 |
|
|
Jaroslav |
203cc8 |
setSyncing(true);
|
|
shun-iwasawa |
6ca609 |
handleScroll(offset, senderMaximum, x);
|
|
Jaroslav |
203cc8 |
setSyncing(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static QList<framescroller *=""> frameScrollers;</framescroller>
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
6ca609 |
void FrameScroller::handleScroll(QPoint &offset, int senderMaximum,
|
|
shun-iwasawa |
6ca609 |
int senderValue) {
|
|
shun_iwasawa |
0cae24 |
if ((m_orientation->isVerticalTimeline() && offset.x()) ||
|
|
shun_iwasawa |
0cae24 |
(!m_orientation->isVerticalTimeline() &&
|
|
shun_iwasawa |
0cae24 |
offset.y())) // only synchronize changes by frames axis
|
|
Jaroslav |
203cc8 |
return;
|
|
Jaroslav |
203cc8 |
|
|
shun-iwasawa |
6ca609 |
// If the scroller has the same maximum size, assume it as the scroll bar in
|
|
shun-iwasawa |
6ca609 |
// the neighbor panel with the same height & scale. In such case just set the
|
|
shun-iwasawa |
6ca609 |
// same value as the sender without zoom adjusting whichi may cause error due
|
|
shun-iwasawa |
6ca609 |
// to rounding off.
|
|
shun-iwasawa |
6ca609 |
QList<framescroller *=""> scrollBarCue;</framescroller>
|
|
shun-iwasawa |
6ca609 |
for (auto frameScroller : frameScrollers)
|
|
shun-iwasawa |
6ca609 |
if (frameScroller != this) {
|
|
shun-iwasawa |
6ca609 |
if (!frameScroller->isSyncing()) {
|
|
shun-iwasawa |
6ca609 |
if (!frameScroller->exactScroll(senderMaximum, senderValue)) {
|
|
shun-iwasawa |
6ca609 |
// If the size is different from the sender, then put it in the cue
|
|
shun-iwasawa |
6ca609 |
// for adjusting offset and scrolling.
|
|
shun-iwasawa |
6ca609 |
scrollBarCue.append(frameScroller);
|
|
shun-iwasawa |
6ca609 |
}
|
|
shun-iwasawa |
6ca609 |
}
|
|
shun-iwasawa |
6ca609 |
}
|
|
shun-iwasawa |
6ca609 |
|
|
shun-iwasawa |
6ca609 |
if (scrollBarCue.isEmpty()) return;
|
|
shun-iwasawa |
6ca609 |
|
|
shun-iwasawa |
692990 |
QPointF offsetF(offset);
|
|
manongjohn |
f643b0 |
// In case of a zoomed viewer is sending this out, adjust the
|
|
manongjohn |
f643b0 |
// zoomed offset back to a standardized offset
|
|
shun-iwasawa |
692990 |
emit zoomScrollAdjust(offsetF, false);
|
|
manongjohn |
f643b0 |
|
|
shun-iwasawa |
692990 |
CellPositionRatio ratio = orientation()->xyToPositionRatio(offsetF);
|
|
manongjohn |
f643b0 |
|
|
shun-iwasawa |
6ca609 |
for (auto frameScroller : scrollBarCue)
|
|
shun-iwasawa |
6ca609 |
if (frameScroller != this) {
|
|
shun-iwasawa |
6ca609 |
if (!frameScroller->isSyncing()) {
|
|
shun-iwasawa |
6ca609 |
frameScroller->onScroll(ratio);
|
|
shun_iwasawa |
0cae24 |
break;
|
|
shun_iwasawa |
0cae24 |
}
|
|
shun_iwasawa |
0cae24 |
}
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
|
|
Jaroslav |
203cc8 |
void adjustScrollbar(QScrollBar *scrollBar, int add);
|
|
Jaroslav |
203cc8 |
|
|
shun-iwasawa |
6ca609 |
// Check if the scroll bar has the same size as the sender and just put the
|
|
shun-iwasawa |
6ca609 |
// value
|
|
shun-iwasawa |
6ca609 |
bool FrameScroller::exactScroll(const int senderMaximum,
|
|
shun-iwasawa |
6ca609 |
const int senderValue) {
|
|
shun-iwasawa |
6ca609 |
QScrollBar *scrollBar = (m_orientation->isVerticalTimeline())
|
|
shun-iwasawa |
6ca609 |
? m_scrollArea->verticalScrollBar()
|
|
shun-iwasawa |
6ca609 |
: m_scrollArea->horizontalScrollBar();
|
|
shun-iwasawa |
6ca609 |
|
|
shun-iwasawa |
6ca609 |
if (scrollBar->maximum() == senderMaximum) {
|
|
shun-iwasawa |
6ca609 |
scrollBar->setValue(senderValue);
|
|
shun-iwasawa |
6ca609 |
return true;
|
|
shun-iwasawa |
6ca609 |
}
|
|
shun-iwasawa |
6ca609 |
|
|
shun-iwasawa |
6ca609 |
return false;
|
|
shun-iwasawa |
6ca609 |
}
|
|
shun-iwasawa |
6ca609 |
|
|
Jaroslav |
203cc8 |
void FrameScroller::onScroll(const CellPositionRatio &ratio) {
|
|
shun-iwasawa |
692990 |
QPointF offset = orientation()->positionRatioToXY(ratio);
|
|
manongjohn |
f643b0 |
|
|
manongjohn |
f643b0 |
// In case of a zoomed viewer is receiving this, adjust the
|
|
manongjohn |
f643b0 |
// standardized offset to zoomed offset
|
|
shun-iwasawa |
692990 |
|
|
manongjohn |
f643b0 |
emit zoomScrollAdjust(offset, true);
|
|
manongjohn |
f643b0 |
|
|
shun_iwasawa |
22312d |
// scroll area should be resized before moving down the scroll bar.
|
|
shun_iwasawa |
22312d |
// SpreadsheetViewer::onPrepareToScrollOffset() will be invoked immediately
|
|
shun_iwasawa |
22312d |
// since the receiver is in the same thread.
|
|
shun_iwasawa |
22312d |
// when moving up the scroll bar, resizing will be done in
|
|
shun_iwasawa |
22312d |
// SpreadsheetViewer::onVSliderChanged().
|
|
shun-iwasawa |
692990 |
if (offset.x() > 0.0 || offset.y() > 0.0) emit prepareToScrollOffset(offset);
|
|
shun-iwasawa |
692990 |
if ((int)offset.x())
|
|
shun-iwasawa |
692990 |
adjustScrollbar(m_scrollArea->horizontalScrollBar(), (int)offset.x());
|
|
shun-iwasawa |
692990 |
if ((int)offset.y())
|
|
shun-iwasawa |
692990 |
adjustScrollbar(m_scrollArea->verticalScrollBar(), (int)offset.y());
|
|
Jaroslav |
203cc8 |
}
|
|
shun_iwasawa |
22312d |
|
|
Jaroslav |
203cc8 |
void adjustScrollbar(QScrollBar *scrollBar, int add) {
|
|
Jaroslav |
203cc8 |
scrollBar->setValue(scrollBar->value() + add);
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
|
|
Shinya Kitaoka |
120a6e |
void FrameScroller::registerFrameScroller() {
|
|
Jaroslav |
203cc8 |
if (!frameScrollers.contains(this)) frameScrollers.append(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void FrameScroller::unregisterFrameScroller() {
|
|
Jaroslav |
203cc8 |
if (frameScrollers.contains(this)) frameScrollers.removeAll(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
692990 |
void FrameScroller::prepareToScrollOthers(const QPointF &offset) {
|
|
Jaroslav |
203cc8 |
CellPositionRatio ratio = orientation()->xyToPositionRatio(offset);
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < frameScrollers.size(); i++)
|
|
Jaroslav |
203cc8 |
if (frameScrollers[i] != this)
|
|
shun_iwasawa |
0cae24 |
frameScrollers[i]->prepareToScrollRatio(ratio);
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
void FrameScroller::prepareToScrollRatio(const CellPositionRatio &ratio) {
|
|
shun-iwasawa |
692990 |
QPointF offset = orientation()->positionRatioToXY(ratio);
|
|
Jaroslav |
203cc8 |
emit prepareToScrollOffset(offset);
|
|
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) {
|
|
shun-iwasawa |
a0d489 |
int r0 = std::min(row, m_firstRow);
|
|
shun-iwasawa |
a0d489 |
int r1 = std::max(row, m_firstRow);
|
|
shun-iwasawa |
a0d489 |
int c0 = std::min(col, m_firstCol);
|
|
shun-iwasawa |
a0d489 |
int c1 = std::max(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 |
ScrollArea::ScrollArea(QWidget *parent, Qt::WindowFlags flags)
|
|
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);
|
|
shun-iwasawa |
443318 |
if (e->button() == Qt::MiddleButton)
|
|
Shinya Kitaoka |
120a6e |
m_dragTool = new PanTool(this);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
m_dragTool = createDragTool(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 |
if (m_dragTool) m_dragTool->click(row, col, e);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void GenericPanel::mouseReleaseEvent(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 |
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) {
|
|
Jaroslav |
203cc8 |
CellPosition cellPosition = getViewer()->xyToPosition(e->pos());
|
|
Jaroslav |
203cc8 |
int row = cellPosition.frame();
|
|
Jaroslav |
203cc8 |
int col = cellPosition.layer();
|
|
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) {
|
|
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 |
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 |
|
|
shun-iwasawa |
692990 |
bool simpleView = getViewer()->getFrameZoomFactor() <=
|
|
shun-iwasawa |
692990 |
Orientations::topToBottom()->dimension(
|
|
shun-iwasawa |
692990 |
PredefinedDimension::SCALE_THRESHOLD);
|
|
shun-iwasawa |
aebc0b |
int currentRow = getViewer()->getCurrentRow();
|
|
Shinya Kitaoka |
120a6e |
int r;
|
|
shun-iwasawa |
692990 |
int y = getViewer()->rowToY(r0);
|
|
Shinya Kitaoka |
120a6e |
for (r = r0; r <= r1; r++) {
|
|
shun-iwasawa |
692990 |
int next_y = getViewer()->rowToY(r + 1);
|
|
Shinya Kitaoka |
120a6e |
// draw horizontal line
|
|
shun-iwasawa |
fe3506 |
bool isMarkSecRow = getViewer()->isMarkSecRow(r);
|
|
shun-iwasawa |
aebc0b |
bool isMarkRow = getViewer()->isMarkRow(r);
|
|
shun-iwasawa |
443318 |
QColor color = (isMarkSecRow) ? getViewer()->getSecMarkerLineColor()
|
|
shun-iwasawa |
443318 |
: (isMarkRow) ? getViewer()->getMarkerLineColor()
|
|
shun-iwasawa |
443318 |
: getViewer()->getLightLineColor();
|
|
shun-iwasawa |
443318 |
p.setPen(QPen(color,
|
|
shun-iwasawa |
443318 |
(isMarkSecRow) ? 3.
|
|
shun-iwasawa |
443318 |
: (getViewer()->isSecMarkerActive() && isMarkRow) ? 2.
|
|
shun-iwasawa |
443318 |
: 1.,
|
|
shun-iwasawa |
443318 |
Qt::SolidLine, Qt::FlatCap));
|
|
Shinya Kitaoka |
120a6e |
p.drawLine(x0, y, x1, y);
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
692990 |
if (simpleView && r > 0 && !getViewer()->isMarkRow(r + 1)) {
|
|
shun-iwasawa |
692990 |
y = next_y;
|
|
shun-iwasawa |
692990 |
continue;
|
|
shun-iwasawa |
692990 |
}
|
|
shun-iwasawa |
692990 |
|
|
Shinya Kitaoka |
120a6e |
// draw numbers
|
|
shun-iwasawa |
aebc0b |
p.setPen((r == currentRow) ? getViewer()->getCurrentRowTextColor()
|
|
shun-iwasawa |
aebc0b |
: getViewer()->getTextColor());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QString number = QString::number(r + 1);
|
|
shun-iwasawa |
692990 |
p.drawText(QRect(x0, y + 1, width() - 4, next_y - y - 1),
|
|
shun-iwasawa |
692990 |
Qt::AlignVCenter | Qt::AlignRight, number);
|
|
shun-iwasawa |
692990 |
y = next_y;
|
|
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();
|
|
shun-iwasawa |
692990 |
// int y = getViewer()->rowToY(currentRow);
|
|
Shinya Kitaoka |
120a6e |
if (currentRow < r0 || r1 < currentRow) return;
|
|
shun-iwasawa |
692990 |
int top = getViewer()->rowToY(currentRow);
|
|
shun-iwasawa |
692990 |
int bottom = getViewer()->rowToY(currentRow + 1) - 1;
|
|
shun-iwasawa |
692990 |
QRect rect(1, top, width() - 1, bottom - top);
|
|
shun-iwasawa |
692990 |
|
|
shun-iwasawa |
692990 |
p.fillRect(rect, 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 |
|
|
Jaroslav |
203cc8 |
CellRange visible = getViewer()->xyRectToRange(toBeUpdated);
|
|
Jaroslav |
203cc8 |
// range of visible rows
|
|
Jaroslav |
203cc8 |
int r0 = visible.from().frame();
|
|
Jaroslav |
203cc8 |
int r1 = visible.to().frame();
|
|
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 |
|
|
Jaroslav |
203cc8 |
QRect alteredRect(QPoint(x0, y0), QPoint(x1, y1));
|
|
Jaroslav |
203cc8 |
CellRange cellRange = getViewer()->xyRectToRange(alteredRect);
|
|
Shinya Kitaoka |
120a6e |
// visible rows range
|
|
Jaroslav |
203cc8 |
int r0 = cellRange.from().frame();
|
|
Jaroslav |
203cc8 |
int r1 = cellRange.to().frame();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// visible columns range
|
|
Jaroslav |
203cc8 |
int c0 = cellRange.from().layer();
|
|
Jaroslav |
203cc8 |
int c1 = cellRange.to().layer();
|
|
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++) {
|
|
shun-iwasawa |
fe3506 |
int y = getViewer()->rowToY(r);
|
|
shun-iwasawa |
fe3506 |
bool isMarkSecRow = getViewer()->isMarkSecRow(r);
|
|
shun-iwasawa |
aebc0b |
bool isMarkRow = getViewer()->isMarkRow(r);
|
|
shun-iwasawa |
443318 |
QColor color = (isMarkSecRow) ? getViewer()->getSecMarkerLineColor()
|
|
shun-iwasawa |
443318 |
: (isMarkRow) ? getViewer()->getMarkerLineColor()
|
|
shun-iwasawa |
443318 |
: getViewer()->getLightLineColor();
|
|
shun-iwasawa |
443318 |
painter.setPen(QPen(color,
|
|
shun-iwasawa |
443318 |
(isMarkSecRow) ? 3.
|
|
shun-iwasawa |
443318 |
: (getViewer()->isSecMarkerActive() && isMarkRow) ? 2.
|
|
shun-iwasawa |
443318 |
: 1.,
|
|
shun-iwasawa |
443318 |
Qt::SolidLine, Qt::FlatCap));
|
|
Shinya Kitaoka |
120a6e |
painter.drawLine(x0, y, x1, y);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
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)
|
|
Jeremy Bullock |
4ce953 |
: QDialog(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)
|
|
shun-iwasawa |
692990 |
, m_scaleFactor(100)
|
|
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)
|
|
shun-iwasawa |
fe3506 |
, m_markSecRowDistance(-1)
|
|
Jaroslav |
203cc8 |
, m_isComputingSize(false)
|
|
Jaroslav |
203cc8 |
, m_frameScroller() {
|
|
Jaroslav |
203cc8 |
// m_orientation = Orientations::topToBottom ();
|
|
Jaroslav |
203cc8 |
|
|
Shinya Kitaoka |
120a6e |
setFocusPolicy(Qt::NoFocus);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jeremy Bullock |
4ce953 |
// setFrameStyle(QFrame::StyledPanel);
|
|
Shinya Kitaoka |
120a6e |
setObjectName("Viewer");
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// column header
|
|
Shinya Kitaoka |
120a6e |
m_columnScrollArea = new Spreadsheet::ScrollArea;
|
|
shun-iwasawa |
caf3c6 |
m_columnScrollArea->setObjectName("ScrollColumnArea");
|
|
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;
|
|
shun-iwasawa |
caf3c6 |
m_rowScrollArea->setObjectName("ScrollRowArea");
|
|
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;
|
|
shun-iwasawa |
caf3c6 |
m_cellScrollArea->setObjectName("ScrollCellArea");
|
|
Shinya Kitaoka |
120a6e |
m_cellScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
Shinya Kitaoka |
120a6e |
m_cellScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
shun_iwasawa |
ffb2f0 |
// m_cellScrollArea->horizontalScrollBar()->setObjectName("XsheetScrollBar");
|
|
shun_iwasawa |
ffb2f0 |
// 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);
|
|
shun-iwasawa |
855b12 |
|
|
shun-iwasawa |
855b12 |
if (Preferences::instance()->getLoadedXsheetLayout() == QString("Minimum") &&
|
|
shun-iwasawa |
855b12 |
!Preferences::instance()->isShowXSheetToolbarEnabled() &&
|
|
shun-iwasawa |
855b12 |
Preferences::instance()->isExpandFunctionHeaderEnabled() &&
|
|
shun-iwasawa |
855b12 |
Preferences::instance()->getFunctionEditorToggle() !=
|
|
shun-iwasawa |
855b12 |
Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup)
|
|
shun-iwasawa |
855b12 |
m_columnScrollArea->setFixedHeight(m_rowHeight * 2 - 4);
|
|
shun-iwasawa |
855b12 |
else
|
|
shun-iwasawa |
855b12 |
m_columnScrollArea->setFixedHeight(m_rowHeight * 3 - 4);
|
|
Shinya Kitaoka |
120a6e |
|
|
Jaroslav |
203cc8 |
m_frameScroller.setFrameScrollArea(m_cellScrollArea);
|
|
Jaroslav |
203cc8 |
connect(&m_frameScroller, &Spreadsheet::FrameScroller::prepareToScrollOffset,
|
|
Jaroslav |
203cc8 |
this, &SpreadsheetViewer::onPrepareToScrollOffset);
|
|
shun-iwasawa |
692990 |
connect(&m_frameScroller, &Spreadsheet::FrameScroller::zoomScrollAdjust, this,
|
|
shun-iwasawa |
692990 |
&SpreadsheetViewer::onZoomScrollAdjust);
|
|
Jaroslav |
203cc8 |
|
|
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 |
|
|
shun_iwasawa |
ffb2f0 |
int scrollBarWidth = 16;
|
|
Shinya Kitaoka |
120a6e |
// upper-right
|
|
Shinya Kitaoka |
120a6e |
QWidget *w = new QWidget(this);
|
|
shun-iwasawa |
692990 |
w->setFixedWidth(scrollBarWidth);
|
|
shun-iwasawa |
692990 |
w->setFixedHeight(m_columnScrollArea->height());
|
|
Shinya Kitaoka |
120a6e |
layout->addWidget(w, 0, 2);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// lower-left
|
|
Shinya Kitaoka |
120a6e |
w = new QWidget(this);
|
|
shun_iwasawa |
ffb2f0 |
w->setFixedSize(QSize(30, scrollBarWidth));
|
|
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 |
|
|
shun-iwasawa |
692990 |
void SpreadsheetViewer::setButtonAreaWidget(QWidget *widget) {
|
|
shun-iwasawa |
692990 |
QGridLayout *lay = dynamic_cast<qgridlayout *="">(layout());</qgridlayout>
|
|
shun-iwasawa |
692990 |
lay->addWidget(widget, 0, 0);
|
|
shun-iwasawa |
692990 |
}
|
|
shun-iwasawa |
692990 |
|
|
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();
|
|
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 |
|
|
shun-iwasawa |
692990 |
// Recheck in case refreshContentSize changed the max
|
|
shun-iwasawa |
692990 |
if (!notUpdateSizeH) maxValueH = hSc->maximum();
|
|
shun-iwasawa |
692990 |
if (!notUpdateSizeV) maxValueV = vSc->maximum();
|
|
shun-iwasawa |
692990 |
|
|
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 |
|
|
shun-iwasawa |
692990 |
void SpreadsheetViewer::onPrepareToScrollOffset(const QPointF &offset) {
|
|
shun-iwasawa |
692990 |
refreshContentSize((int)offset.x(), (int)offset.y());
|
|
shun-iwasawa |
692990 |
}
|
|
shun-iwasawa |
692990 |
|
|
shun-iwasawa |
692990 |
void SpreadsheetViewer::onZoomScrollAdjust(QPointF &offset, bool toZoom) {
|
|
shun-iwasawa |
692990 |
double frameZoomFactor = (double)getFrameZoomFactor();
|
|
shun-iwasawa |
692990 |
|
|
shun-iwasawa |
692990 |
// toZoom = true: Adjust standardized offset down to zoom factor
|
|
shun-iwasawa |
692990 |
// toZoom = false: Adjust zoomed offset up to standardized offset
|
|
shun-iwasawa |
692990 |
double newY;
|
|
shun-iwasawa |
692990 |
if (toZoom)
|
|
shun-iwasawa |
692990 |
newY = (offset.y() * frameZoomFactor) / 100.0;
|
|
shun-iwasawa |
692990 |
else
|
|
shun-iwasawa |
692990 |
newY = (offset.y() * 100.0) / frameZoomFactor;
|
|
shun-iwasawa |
692990 |
|
|
shun-iwasawa |
692990 |
offset.setY(newY);
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
|
|
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 |
|
|
Campbell Barton |
ccd505 |
static 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 |
|
|
Shinya Kitaoka |
120a6e |
int SpreadsheetViewer::xToColumn(int x) const {
|
|
Jaroslav |
203cc8 |
CellPosition pos = xyToPosition(QPoint(x, 0));
|
|
Jaroslav |
203cc8 |
return pos.layer();
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
int SpreadsheetViewer::yToRow(int y) const {
|
|
Jaroslav |
203cc8 |
CellPosition pos = xyToPosition(QPoint(0, y));
|
|
Jaroslav |
203cc8 |
return pos.frame();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
int SpreadsheetViewer::columnToX(int col) const {
|
|
Jaroslav |
203cc8 |
QPoint xy = positionToXY(CellPosition(0, col));
|
|
Jaroslav |
203cc8 |
return xy.x();
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
int SpreadsheetViewer::rowToY(int row) const {
|
|
Jaroslav |
203cc8 |
QPoint xy = positionToXY(CellPosition(row, 0));
|
|
Jaroslav |
203cc8 |
return xy.y();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Shift is a consequence of style sheet border.*/
|
|
Jaroslav |
203cc8 |
CellPosition SpreadsheetViewer::xyToPosition(const QPoint &point) const {
|
|
shun-iwasawa |
692990 |
int row = (point.y() * 100 / m_scaleFactor) / m_rowHeight;
|
|
shun-iwasawa |
caf3c6 |
int col = (point.x()) / m_columnWidth;
|
|
Jaroslav |
203cc8 |
return CellPosition(row, col);
|
|
Jaroslav |
203cc8 |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Shift is a consequence of style sheet border.*/
|
|
Jaroslav |
203cc8 |
QPoint SpreadsheetViewer::positionToXY(const CellPosition &pos) const {
|
|
shun-iwasawa |
caf3c6 |
int x = (pos.layer() * m_columnWidth);
|
|
shun-iwasawa |
692990 |
int y = pos.frame() * m_rowHeight * m_scaleFactor / 100;
|
|
shun-iwasawa |
692990 |
// int y = (pos.frame() * m_rowHeight * m_scaleFactor / 100) - 1;
|
|
Jaroslav |
203cc8 |
return QPoint(x, y);
|
|
Jaroslav |
203cc8 |
}
|
|
Jaroslav |
203cc8 |
|
|
Jaroslav |
203cc8 |
CellRange SpreadsheetViewer::xyRectToRange(const QRect &rect) const {
|
|
Jaroslav |
203cc8 |
CellPosition topLeft = xyToPosition(rect.topLeft());
|
|
Jaroslav |
203cc8 |
CellPosition bottomRight = xyToPosition(rect.bottomRight());
|
|
Jaroslav |
203cc8 |
return CellRange(topLeft, bottomRight);
|
|
Jaroslav |
203cc8 |
}
|
|
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();
|
|
shun-iwasawa |
caf3c6 |
offset = QPoint(std::min(0, offset.x() - scrollDx),
|
|
shun-iwasawa |
443318 |
std::min(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;
|
|
shun-iwasawa |
692990 |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SpreadsheetViewer::showEvent(QShowEvent *) {
|
|
shun-iwasawa |
caf3c6 |
int viewportHeight = m_cellScrollArea->height();
|
|
shun-iwasawa |
caf3c6 |
int contentHeight = rowToY(m_rowCount * 0 + 50);
|
|
shun-iwasawa |
caf3c6 |
QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
|
|
shun-iwasawa |
caf3c6 |
int actualContentHeight =
|
|
shun-iwasawa |
caf3c6 |
std::max(contentHeight, vSc->value() + viewportHeight);
|
|
shun-iwasawa |
692990 |
m_rowScrollArea->widget()->setFixedSize(m_rowScrollArea->viewport()->width(),
|
|
shun-iwasawa |
692990 |
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) {
|
|
Jeremy Bullock |
4ce953 |
QDialog::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
|
|
shun-iwasawa |
caf3c6 |
{
|
|
shun-iwasawa |
caf3c6 |
std::cout << "not supported wheelEvent.source(): "
|
|
shun-iwasawa |
caf3c6 |
"Qt::MouseEventSynthesizedByQt, "
|
|
shun-iwasawa |
caf3c6 |
"Qt::MouseEventSynthesizedByApplication"
|
|
shun-iwasawa |
caf3c6 |
<< std::endl;
|
|
shun-iwasawa |
caf3c6 |
break;
|
|
shun-iwasawa |
caf3c6 |
}
|
|
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 |
}
|
|
shun-iwasawa |
855b12 |
|
|
shun-iwasawa |
855b12 |
bool SpreadsheetViewer::isSmallHeader() {
|
|
shun-iwasawa |
855b12 |
return (
|
|
shun-iwasawa |
855b12 |
Preferences::instance()->getLoadedXsheetLayout() == QString("Minimum") &&
|
|
shun-iwasawa |
855b12 |
!Preferences::instance()->isShowXSheetToolbarEnabled() &&
|
|
shun-iwasawa |
855b12 |
Preferences::instance()->isExpandFunctionHeaderEnabled() &&
|
|
shun-iwasawa |
855b12 |
Preferences::instance()->getFunctionEditorToggle() !=
|
|
shun-iwasawa |
855b12 |
Preferences::FunctionEditorToggle::ShowFunctionSpreadsheetInPopup);
|
|
shun-iwasawa |
855b12 |
}
|
|
shun-iwasawa |
855b12 |
|
|
shun-iwasawa |
855b12 |
void SpreadsheetViewer::updateHeaderHeight() {
|
|
shun-iwasawa |
855b12 |
if (isSmallHeader())
|
|
shun-iwasawa |
855b12 |
m_columnScrollArea->setFixedHeight(m_rowHeight * 2 - 4);
|
|
shun-iwasawa |
855b12 |
else
|
|
shun-iwasawa |
855b12 |
m_columnScrollArea->setFixedHeight(m_rowHeight * 3 - 4);
|
|
shun-iwasawa |
855b12 |
}
|