1 /* This file is part of the KDE project
2 Copyright 2008 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 "AutoFillStrategy.h"
21
22 #include "commands/AutoFillCommand.h"
23 #include "Selection.h"
24
25 using namespace Calligra::Sheets;
26
27 class Q_DECL_HIDDEN AutoFillStrategy::Private
28 {
29 public:
30 // If we use the lower right corner of the marker to start autofilling, then this
31 // rectangle contains all cells that were already marker when the user started
32 // to mark the rectangle which the user wants to become autofilled.
33 QRect autoFillSource;
34 };
35
AutoFillStrategy(CellToolBase * cellTool,const QPointF & documentPos,Qt::KeyboardModifiers modifiers)36 AutoFillStrategy::AutoFillStrategy(CellToolBase *cellTool,
37 const QPointF &documentPos, Qt::KeyboardModifiers modifiers)
38 : AbstractSelectionStrategy(cellTool, documentPos, modifiers)
39 , d(new Private)
40 {
41 d->autoFillSource = selection()->lastRange();
42 }
43
~AutoFillStrategy()44 AutoFillStrategy::~AutoFillStrategy()
45 {
46 delete d;
47 }
48
createCommand()49 KUndo2Command* AutoFillStrategy::createCommand()
50 {
51 if (d->autoFillSource == selection()->lastRange()) {
52 return 0;
53 }
54 AutoFillCommand* command = new AutoFillCommand();
55 command->setSheet(selection()->activeSheet());
56 command->setSourceRange(d->autoFillSource);
57 command->setTargetRange(selection()->lastRange());
58 return command;
59 }
60