File indexing completed on 2024-05-12 16:35:12

0001 /* This file is part of the KDE project
0002    Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "PageBreakCommand.h"
0021 
0022 #include "Damages.h"
0023 #include "Map.h"
0024 #include "RowColumnFormat.h"
0025 #include "RowFormatStorage.h"
0026 #include "Sheet.h"
0027 #include "SheetPrint.h"
0028 
0029 using namespace Calligra::Sheets;
0030 
0031 PageBreakCommand::PageBreakCommand(KUndo2Command *parent)
0032         : AbstractRegionCommand(parent)
0033         , m_mode(BreakBeforeColumn)
0034 {
0035 }
0036 
0037 PageBreakCommand::~PageBreakCommand()
0038 {
0039 }
0040 
0041 void PageBreakCommand::setMode(Mode mode)
0042 {
0043     m_mode = mode;
0044 }
0045 
0046 bool PageBreakCommand::process(Element *element)
0047 {
0048     // No reverse means setting; reverse means unsetting.
0049     const bool enable = !m_reverse;
0050     Sheet *const sheet = element->sheet();
0051     const QRect range = element->rect();
0052     if (m_mode == BreakBeforeColumn && range.left() > 1) {
0053         sheet->nonDefaultColumnFormat(range.left())->setPageBreak(enable);
0054     } else if (m_mode == BreakBeforeRow && range.top() > 1) {
0055         sheet->rowFormats()->setPageBreak(range.top(), range.top(), enable);
0056     }
0057     return true;
0058 }
0059 
0060 bool PageBreakCommand::postProcessing()
0061 {
0062     const QRect range = boundingRect();
0063     if (m_mode == BreakBeforeColumn && range.left() > 1) {
0064         m_sheet->print()->updateHorizontalPageParameters(range.left() - 1);
0065     } else if (m_mode == BreakBeforeRow && range.top() > 1) {
0066         m_sheet->print()->updateVerticalPageParameters(range.top() - 1);
0067     }
0068     if (m_sheet->isShowPageOutline()) {
0069         m_sheet->map()->addDamage(new SheetDamage(m_sheet, SheetDamage::ContentChanged));
0070     }
0071     return AbstractRegionCommand::postProcessing();
0072 }