1 /* This file is part of the KDE project
2 Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20 #include "PageBreakCommand.h"
21
22 #include "Damages.h"
23 #include "Map.h"
24 #include "RowColumnFormat.h"
25 #include "RowFormatStorage.h"
26 #include "Sheet.h"
27 #include "SheetPrint.h"
28
29 using namespace Calligra::Sheets;
30
PageBreakCommand(KUndo2Command * parent)31 PageBreakCommand::PageBreakCommand(KUndo2Command *parent)
32 : AbstractRegionCommand(parent)
33 , m_mode(BreakBeforeColumn)
34 {
35 }
36
~PageBreakCommand()37 PageBreakCommand::~PageBreakCommand()
38 {
39 }
40
setMode(Mode mode)41 void PageBreakCommand::setMode(Mode mode)
42 {
43 m_mode = mode;
44 }
45
process(Element * element)46 bool PageBreakCommand::process(Element *element)
47 {
48 // No reverse means setting; reverse means unsetting.
49 const bool enable = !m_reverse;
50 Sheet *const sheet = element->sheet();
51 const QRect range = element->rect();
52 if (m_mode == BreakBeforeColumn && range.left() > 1) {
53 sheet->nonDefaultColumnFormat(range.left())->setPageBreak(enable);
54 } else if (m_mode == BreakBeforeRow && range.top() > 1) {
55 sheet->rowFormats()->setPageBreak(range.top(), range.top(), enable);
56 }
57 return true;
58 }
59
postProcessing()60 bool PageBreakCommand::postProcessing()
61 {
62 const QRect range = boundingRect();
63 if (m_mode == BreakBeforeColumn && range.left() > 1) {
64 m_sheet->print()->updateHorizontalPageParameters(range.left() - 1);
65 } else if (m_mode == BreakBeforeRow && range.top() > 1) {
66 m_sheet->print()->updateVerticalPageParameters(range.top() - 1);
67 }
68 if (m_sheet->isShowPageOutline()) {
69 m_sheet->map()->addDamage(new SheetDamage(m_sheet, SheetDamage::ContentChanged));
70 }
71 return AbstractRegionCommand::postProcessing();
72 }
73