modify sync scroll between xsheet and function editor

This commit is contained in:
shun-iwasawa 2021-06-09 17:54:31 +09:00 committed by manongjohn
parent 7a36f869ec
commit 4a619a2ef7
3 changed files with 56 additions and 8 deletions

View file

@ -70,8 +70,9 @@ private:
void connectScrollbars();
void disconnectScrollbars();
void handleScroll(QPoint &offset);
void handleScroll(QPoint &offset, int senderMaximum, int senderValue);
void onScroll(const CellPositionRatio &offset);
bool exactScroll(const int senderMaximum, const int senderValue);
void prepareToScrollRatio(const CellPositionRatio &offset);

View file

@ -1589,6 +1589,7 @@ void XsheetViewer::updateColumnArea() {
//-----------------------------------------------------------------------------
void XsheetViewer::updateCellColumnAree() {
if (!m_isComputingSize) refreshContentSize(0, 0);
m_columnArea->update(m_columnArea->visibleRegion());
m_cellArea->update(m_cellArea->visibleRegion());
}
@ -1596,6 +1597,7 @@ void XsheetViewer::updateCellColumnAree() {
//-----------------------------------------------------------------------------
void XsheetViewer::updateCellRowAree() {
if (!m_isComputingSize) refreshContentSize(0, 0);
m_rowArea->update(m_rowArea->visibleRegion());
m_cellArea->update(m_cellArea->visibleRegion());
}

View file

@ -67,27 +67,56 @@ void FrameScroller::onVScroll(int y) {
QPoint offset(0, y - m_lastY);
if (isSyncing()) return;
m_lastY = y;
int senderMaximum = 0;
QScrollBar *scrollBar = dynamic_cast<QScrollBar *>(sender());
if (scrollBar) senderMaximum = scrollBar->maximum();
setSyncing(true);
handleScroll(offset);
handleScroll(offset, senderMaximum, y);
setSyncing(false);
}
void FrameScroller::onHScroll(int x) {
QPoint offset(x - m_lastX, 0);
if (isSyncing()) return;
m_lastX = x;
int senderMaximum = 0;
QScrollBar *scrollBar = dynamic_cast<QScrollBar *>(sender());
if (scrollBar) senderMaximum = scrollBar->maximum();
setSyncing(true);
handleScroll(offset);
handleScroll(offset, senderMaximum, x);
setSyncing(false);
}
static QList<FrameScroller *> frameScrollers;
void FrameScroller::handleScroll(QPoint &offset) {
void FrameScroller::handleScroll(QPoint &offset, int senderMaximum,
int senderValue) {
if ((m_orientation->isVerticalTimeline() && offset.x()) ||
(!m_orientation->isVerticalTimeline() &&
offset.y())) // only synchronize changes by frames axis
return;
// If the scroller has the same maximum size, assume it as the scroll bar in
// the neighbor panel with the same height & scale. In such case just set the
// same value as the sender without zoom adjusting whichi may cause error due
// to rounding off.
QList<FrameScroller *> scrollBarCue;
for (auto frameScroller : frameScrollers)
if (frameScroller != this) {
if (!frameScroller->isSyncing()) {
if (!frameScroller->exactScroll(senderMaximum, senderValue)) {
// If the size is different from the sender, then put it in the cue
// for adjusting offset and scrolling.
scrollBarCue.append(frameScroller);
}
}
}
if (scrollBarCue.isEmpty()) return;
QPointF offsetF(offset);
// In case of a zoomed viewer is sending this out, adjust the
// zoomed offset back to a standardized offset
@ -95,10 +124,10 @@ void FrameScroller::handleScroll(QPoint &offset) {
CellPositionRatio ratio = orientation()->xyToPositionRatio(offsetF);
for (int i = 0; i < frameScrollers.size(); i++)
if (frameScrollers[i] != this) {
if (!frameScrollers[i]->isSyncing()) {
frameScrollers[i]->onScroll(ratio);
for (auto frameScroller : scrollBarCue)
if (frameScroller != this) {
if (!frameScroller->isSyncing()) {
frameScroller->onScroll(ratio);
break;
}
}
@ -106,6 +135,22 @@ void FrameScroller::handleScroll(QPoint &offset) {
void adjustScrollbar(QScrollBar *scrollBar, int add);
// Check if the scroll bar has the same size as the sender and just put the
// value
bool FrameScroller::exactScroll(const int senderMaximum,
const int senderValue) {
QScrollBar *scrollBar = (m_orientation->isVerticalTimeline())
? m_scrollArea->verticalScrollBar()
: m_scrollArea->horizontalScrollBar();
if (scrollBar->maximum() == senderMaximum) {
scrollBar->setValue(senderValue);
return true;
}
return false;
}
void FrameScroller::onScroll(const CellPositionRatio &ratio) {
QPointF offset = orientation()->positionRatioToXY(ratio);