File indexing completed on 2024-05-12 16:35:26
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 (C) 1999-2004 Laurent Montel <montel@kde.org> 0004 (C) 2003 Norbert Andres <nandres@web.de> 0005 (C) 2002 Philipp Mueller <philipp.mueller@gmx.de> 0006 (C) 2002 John Dailey <dailey@vt.edu> 0007 (C) 1998-1999 Torben Weis <weis@kde.org> 0008 This library is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU Library General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Library General Public License for more details. 0017 0018 You should have received a copy of the GNU Library General Public License 0019 along with this library; see the file COPYING.LIB. If not, write to 0020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 Boston, MA 02110-1301, USA. 0022 */ 0023 0024 // Local 0025 #include "SpecialPasteDialog.h" 0026 0027 0028 #include <KLocalizedString> 0029 0030 #include "commands/PasteCommand.h" 0031 #include "Map.h" 0032 #include "ui/Selection.h" 0033 #include "Sheet.h" 0034 0035 using namespace Calligra::Sheets; 0036 0037 SpecialPasteDialog::SpecialPasteDialog(QWidget* parent, Selection* selection) 0038 : KoDialog(parent), 0039 m_selection(selection) 0040 { 0041 setButtons(Ok | Cancel); 0042 setCaption(i18n("Special Paste")); 0043 QWidget* widget = new QWidget(this); 0044 setupUi(widget); 0045 setMainWidget(widget); 0046 0047 connect(this, SIGNAL(okClicked()), 0048 this, SLOT(slotOk())); 0049 connect(formatButton, SIGNAL(toggled(bool)), 0050 this, SLOT(slotToggled(bool))); 0051 connect(commentButton, SIGNAL(toggled(bool)), 0052 this, SLOT(slotToggled(bool))); 0053 } 0054 0055 void SpecialPasteDialog::slotOk() 0056 { 0057 Paste::Mode sp = Paste::Normal; 0058 Paste::Operation op = Paste::OverWrite; 0059 0060 /* if( everythingButton->isChecked() ) 0061 sp = cb->isChecked() ? NormalAndTranspose : Normal; 0062 else if( textButton->isChecked() ) 0063 sp = cb->isChecked() ? TextAndTranspose : Text; 0064 else if( formatButton->isChecked() ) 0065 sp = cb->isChecked() ? FormatAndTranspose : Format; 0066 else if( noBorderButton->isChecked() ) 0067 sp = cb->isChecked() ? NoBorderAndTranspose : NoBorder; */ 0068 0069 if (everythingButton->isChecked()) 0070 sp = Paste::Normal; 0071 else if (textButton->isChecked()) 0072 sp = Paste::Text; 0073 else if (formatButton->isChecked()) 0074 sp = Paste::Format; 0075 else if (noBorderButton->isChecked()) 0076 sp = Paste::NoBorder; 0077 else if (commentButton->isChecked()) 0078 sp = Paste::Comment; 0079 else if (resultButton->isChecked()) 0080 sp = Paste::Result; 0081 0082 if (overwriteButton->isChecked()) 0083 op = Paste::OverWrite; 0084 if (additionButton->isChecked()) 0085 op = Paste::Add; 0086 if (subtractionButton->isChecked()) 0087 op = Paste::Sub; 0088 if (multiplicationButton->isChecked()) 0089 op = Paste::Mul; 0090 if (divisionButton->isChecked()) 0091 op = Paste::Div; 0092 0093 PasteCommand *const command = new PasteCommand(); 0094 command->setSheet(m_selection->activeSheet()); 0095 command->add(*m_selection); 0096 command->setMimeData(QApplication::clipboard()->mimeData()); 0097 command->setMode(sp); 0098 command->setOperation(op); 0099 m_selection->activeSheet()->map()->addCommand(command); 0100 accept(); 0101 } 0102 0103 void SpecialPasteDialog::slotToggled(bool b) 0104 { 0105 overwriteButton->setEnabled(!b); 0106 additionButton->setEnabled(!b); 0107 subtractionButton->setEnabled(!b); 0108 multiplicationButton->setEnabled(!b); 0109 divisionButton->setEnabled(!b); 0110 }