From 75546946db5398c1bf6245278c52eb5d2f4b3d50 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 12 Jun 2022 21:49:45 +0800 Subject: [PATCH] Spreadsheet: fix border rendering for merged cells --- src/Mod/Spreadsheet/App/Sheet.cpp | 21 ++++++++++++------- .../Spreadsheet/Gui/SpreadsheetDelegate.cpp | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index 69dd1f81eb..b8189e4567 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -850,25 +850,30 @@ Sheet::getCellBinding(Range &range, return PropertySheet::BindingNone; } -static inline unsigned _getBorder( - const std::vector &ranges, const App::CellAddress &address) +static inline unsigned _getBorder(const Sheet *sheet, + const std::vector &ranges, + const App::CellAddress &address) { unsigned flags = 0; + int rows, cols; + sheet->getSpans(address, rows, cols); + --rows; + --cols; for(auto &range : ranges) { auto from = range.from(); auto to = range.to(); if(address.row() < from.row() - || address.row() > to.row() + || address.row() + rows > to.row() || address.col() < from.col() - || address.col() > to.col()) + || address.col() + cols > to.col()) continue; if(address.row() == from.row()) flags |= Sheet::BorderTop; - if(address.row() == to.row()) + if(address.row() == to.row() || address.row() + rows == to.row()) flags |= Sheet::BorderBottom; if(address.col() == from.col()) flags |= Sheet::BorderLeft; - if(address.col() == to.col()) + if(address.col() == to.col() || address.col() + cols == to.col()) flags |= Sheet::BorderRight; if(flags == Sheet::BorderAll) break; @@ -877,7 +882,7 @@ static inline unsigned _getBorder( } unsigned Sheet::getCellBindingBorder(App::CellAddress address) const { - return _getBorder(boundRanges, address); + return _getBorder(this, boundRanges, address); } void Sheet::updateBindings() @@ -1597,7 +1602,7 @@ unsigned Sheet::getCopyOrCutBorder(CellAddress address, bool copy) const { if(hasCopyRange != copy) return 0; - return _getBorder(copyCutRanges, address); + return _getBorder(this, copyCutRanges, address); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp index 4d083259f9..4d9a9cde71 100644 --- a/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp +++ b/src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp @@ -109,7 +109,7 @@ static inline void drawBorder(QPainter *painter, const QStyleOptionViewItem &opt QRect rect = option.rect.adjusted(1,1,0,0); if(flags == Sheet::BorderAll) { - painter->drawRect(rect); + painter->drawRect(rect.adjusted(0,0,-1,-1)); return; } if(flags & Sheet::BorderLeft)