File indexing completed on 2024-05-12 16:35:19
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Norbert Andres <nandres@web.de> 0003 (C) 1999-2002 Laurent Montel <montel@kde.org> 0004 (C) 2002 Philipp Mueller <philipp.mueller@gmx.de> 0005 (C) 2002 John Dailey <dailey@vt.edu> 0006 (C) 2000-2001 Werner Trobin <trobin@kde.org> 0007 (C) 2000 David Faure <faure@kde.org> 0008 (C) 1999 Stephan Kulow <coolo@kde.org> 0009 (C) 1998-2000 Torben Weis <weis@kde.org> 0010 0011 This library is free software; you can redistribute it and/or 0012 modify it under the terms of the GNU Library General Public 0013 License as published by the Free Software Foundation; either 0014 version 2 of the License, or (at your option) any later version. 0015 0016 This library is distributed in the hope that it will be useful, 0017 but WITHOUT ANY WARRANTY; without even the implied warranty of 0018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0019 Library General Public License for more details. 0020 0021 You should have received a copy of the GNU Library General Public License 0022 along with this library; see the file COPYING.LIB. If not, write to 0023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0024 Boston, MA 02110-1301, USA. 0025 */ 0026 0027 // Local 0028 #include "InsertDialog.h" 0029 0030 #include <QRadioButton> 0031 #include <QGroupBox> 0032 #include <QVBoxLayout> 0033 0034 #include <KLocalizedString> 0035 0036 #include "SheetsDebug.h" 0037 #include "ui/Selection.h" 0038 #include "Sheet.h" 0039 0040 // commands 0041 #include "commands/DataManipulators.h" 0042 #include "commands/RowColumnManipulators.h" 0043 0044 using namespace Calligra::Sheets; 0045 0046 InsertDialog::InsertDialog(QWidget* parent, Selection* selection, Mode _mode) 0047 : KoDialog(parent) 0048 { 0049 setCaption(""); 0050 setButtons(Ok | Cancel); 0051 setModal(true); 0052 0053 m_selection = selection; 0054 insRem = _mode; 0055 0056 QWidget *page = new QWidget(); 0057 setMainWidget(page); 0058 QVBoxLayout *lay1 = new QVBoxLayout(page); 0059 0060 QGroupBox *grp = new QGroupBox(i18n("Insert"), page); 0061 QVBoxLayout *vbox = new QVBoxLayout; 0062 if (insRem == Insert) { 0063 vbox->addWidget(rb1 = new QRadioButton(i18n("Move towards right"))); 0064 vbox->addWidget(rb2 = new QRadioButton(i18n("Move towards bottom"))); 0065 vbox->addWidget(rb3 = new QRadioButton(i18n("Insert rows"))); 0066 vbox->addWidget(rb4 = new QRadioButton(i18n("Insert columns"))); 0067 setWindowTitle(i18n("Insert Cells")); 0068 } else if (insRem == Remove) { 0069 grp->setTitle(i18n("Remove")); 0070 vbox->addWidget(rb1 = new QRadioButton(i18n("Move towards left"))); 0071 vbox->addWidget(rb2 = new QRadioButton(i18n("Move towards top"))); 0072 vbox->addWidget(rb3 = new QRadioButton(i18n("Remove rows"))); 0073 vbox->addWidget(rb4 = new QRadioButton(i18n("Remove columns"))); 0074 setWindowTitle(i18n("Remove Cells")); 0075 } else 0076 debugSheets << "Error in kspread_dlg_InsertDialog"; 0077 grp->setLayout(vbox); 0078 lay1->addWidget(grp); 0079 0080 rb1->setChecked(true); 0081 0082 0083 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); 0084 } 0085 0086 void InsertDialog::slotOk() 0087 { 0088 if (rb1->isChecked()) { 0089 if (insRem == Insert) { 0090 ShiftManipulator* manipulator = new ShiftManipulator(); 0091 manipulator->setSheet(m_selection->activeSheet()); 0092 manipulator->setDirection(ShiftManipulator::ShiftRight); 0093 manipulator->add(*m_selection); 0094 manipulator->execute(m_selection->canvas()); 0095 } else if (insRem == Remove) { 0096 ShiftManipulator* manipulator = new ShiftManipulator(); 0097 manipulator->setSheet(m_selection->activeSheet()); 0098 manipulator->setDirection(ShiftManipulator::ShiftRight); 0099 manipulator->setReverse(true); 0100 manipulator->add(*m_selection); 0101 manipulator->execute(m_selection->canvas()); 0102 } 0103 } else if (rb2->isChecked()) { 0104 if (insRem == Insert) { 0105 ShiftManipulator* manipulator = new ShiftManipulator(); 0106 manipulator->setSheet(m_selection->activeSheet()); 0107 manipulator->setDirection(ShiftManipulator::ShiftBottom); 0108 manipulator->add(*m_selection); 0109 manipulator->execute(m_selection->canvas()); 0110 } else if (insRem == Remove) { 0111 ShiftManipulator* manipulator = new ShiftManipulator(); 0112 manipulator->setSheet(m_selection->activeSheet()); 0113 manipulator->setDirection(ShiftManipulator::ShiftBottom); 0114 manipulator->setReverse(true); 0115 manipulator->add(*m_selection); 0116 manipulator->execute(m_selection->canvas()); 0117 } 0118 } else if (rb3->isChecked()) { 0119 if (insRem == Insert) { 0120 InsertDeleteRowManipulator* manipulator = new InsertDeleteRowManipulator(); 0121 manipulator->setSheet(m_selection->activeSheet()); 0122 manipulator->add(*m_selection); 0123 manipulator->execute(m_selection->canvas()); 0124 } else if (insRem == Remove) { 0125 InsertDeleteRowManipulator* manipulator = new InsertDeleteRowManipulator(); 0126 manipulator->setSheet(m_selection->activeSheet()); 0127 manipulator->setReverse(true); 0128 manipulator->add(*m_selection); 0129 manipulator->execute(m_selection->canvas()); 0130 } 0131 } else if (rb4->isChecked()) { 0132 if (insRem == Insert) { 0133 InsertDeleteColumnManipulator* manipulator = new InsertDeleteColumnManipulator(); 0134 manipulator->setSheet(m_selection->activeSheet()); 0135 manipulator->add(*m_selection); 0136 manipulator->execute(m_selection->canvas()); 0137 } else if (insRem == Remove) { 0138 InsertDeleteColumnManipulator* manipulator = new InsertDeleteColumnManipulator(); 0139 manipulator->setSheet(m_selection->activeSheet()); 0140 manipulator->setReverse(true); 0141 manipulator->add(*m_selection); 0142 manipulator->execute(m_selection->canvas()); 0143 } 0144 } else { 0145 debugSheets << "Error in kspread_dlg_InsertDialog"; 0146 } 0147 0148 accept(); 0149 }