1 /* This file is part of the KDE project
2    Copyright (C) 2003 Norbert Andres <nandres@web.de>
3              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
4              (C) 2002 John Dailey <dailey@vt.edu>
5              (C) 2000-2002 Laurent Montel <montel@kde.org>
6 
7    This library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Library General Public
9    License as published by the Free Software Foundation; either
10    version 2 of the License, or (at your option) any later version.
11 
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Library General Public License for more details.
16 
17    You should have received a copy of the GNU Library General Public License
18    along with this library; see the file COPYING.LIB.  If not, write to
19    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20    Boston, MA 02110-1301, USA.
21 */
22 
23 // Local
24 #include "PasteInsertDialog.h"
25 
26 #include <QApplication>
27 #include <QGroupBox>
28 #include <QVBoxLayout>
29 #include <KLocalizedString>
30 
31 #include <QRadioButton>
32 #include <QCheckBox>
33 
34 #include "commands/PasteCommand.h"
35 #include "Map.h"
36 #include "ui/Selection.h"
37 #include "Sheet.h"
38 
39 using namespace Calligra::Sheets;
40 
PasteInsertDialog(QWidget * parent,Selection * selection)41 PasteInsertDialog::PasteInsertDialog(QWidget* parent, Selection* selection)
42         : KoDialog(parent)
43 {
44     setCaption(i18n("Paste Inserting Cells"));
45     setObjectName(QLatin1String("PasteInsertDialog"));
46     setModal(true);
47     setButtons(Ok | Cancel);
48     m_selection = selection;
49     rect = selection->lastRange();
50 
51     QWidget *page = new QWidget();
52     setMainWidget(page);
53     QVBoxLayout *lay1 = new QVBoxLayout(page);
54 
55     QGroupBox *grp = new QGroupBox(i18n("Insert"), page);
56     QVBoxLayout *vbox = new QVBoxLayout;
57     vbox->addWidget(rb1 = new QRadioButton(i18n("Move towards right")));
58     vbox->addWidget(rb2 = new QRadioButton(i18n("Move towards bottom")));
59     rb1->setChecked(true);
60     grp->setLayout(vbox);
61     lay1->addWidget(grp);
62 
63     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
64 }
65 
slotOk()66 void PasteInsertDialog::slotOk()
67 {
68     PasteCommand *const command = new PasteCommand();
69     command->setSheet(m_selection->activeSheet());
70     command->add(*m_selection);
71     command->setMimeData(QApplication::clipboard()->mimeData());
72     if (rb1->isChecked()) {
73         command->setInsertionMode(PasteCommand::ShiftCellsRight);
74     } else if (rb2->isChecked()) {
75         command->setInsertionMode(PasteCommand::ShiftCellsDown);
76     }
77     m_selection->activeSheet()->map()->addCommand(command);
78     accept();
79 }
80