kspread

kspread_dlg_insert.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Norbert Andres <nandres@web.de>
3 (C) 1999-2002 Laurent Montel <montel@kde.org>
4 (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
5 (C) 2002 John Dailey <dailey@vt.edu>
6 (C) 2000-2001 Werner Trobin <trobin@kde.org>
7 (C) 2000 David Faure <faure@kde.org>
8 (C) 1999 Stephan Kulow <coolo@kde.org>
9 (C) 1998-2000 Torben Weis <weis@kde.org>
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
20
21 You should have received a copy of the GNU Library General Public License
22 along with this library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
25*/
26
27#include <tqbuttongroup.h>
28#include <tqradiobutton.h>
29#include <tqcheckbox.h>
30#include <tqlayout.h>
31
32#include <kbuttonbox.h>
33#include <kdebug.h>
34#include <tdelocale.h>
35#include <tdemessagebox.h>
36
37#include "kspread_doc.h"
38#include "kspread_sheet.h"
39#include "kspread_view.h"
40
41#include "kspread_dlg_insert.h"
42
43using namespace KSpread;
44
45InsertDialog::InsertDialog( View* parent, const char* name,const TQRect &_rect,Mode _mode)
46 : KDialogBase( parent, name, true,"",Ok|Cancel )
47{
48 m_pView = parent;
49 rect=_rect;
50 insRem=_mode;
51
52 TQWidget *page = new TQWidget( this );
53 setMainWidget(page);
54 TQVBoxLayout *lay1 = new TQVBoxLayout( page, 0, spacingHint() );
55
56 TQButtonGroup *grp = new TQButtonGroup( 1, TQt::Horizontal, i18n("Insert"),page);
57 grp->setRadioButtonExclusive( true );
58 grp->layout();
59 lay1->addWidget(grp);
60 if( insRem==Insert)
61 {
62 rb1 = new TQRadioButton( i18n("Move towards right"), grp );
63 rb2 = new TQRadioButton( i18n("Move towards bottom"), grp );
64 rb3 = new TQRadioButton( i18n("Insert rows"), grp );
65 rb4 = new TQRadioButton( i18n("Insert columns"), grp );
66 setCaption( i18n("Insert Cells") );
67 }
68 else if(insRem==Remove)
69 {
70 grp->setTitle(i18n("Remove"));
71 rb1 = new TQRadioButton( i18n("Move towards left"), grp );
72 rb2 = new TQRadioButton( i18n("Move towards top"), grp );
73 rb3 = new TQRadioButton( i18n("Remove rows"), grp );
74 rb4 = new TQRadioButton( i18n("Remove columns"), grp );
75 setCaption( i18n("Remove Cells") );
76 }
77 else
78 kdDebug(36001) << "Error in kspread_dlg_InsertDialog" << endl;
79
80 rb1->setChecked(true);
81
82
83 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
84}
85
86void InsertDialog::slotOk()
87{
88 m_pView->doc()->emitBeginOperation( false );
89 if( rb1->isChecked() )
90 {
91 if( insRem == Insert )
92 {
93 if ( !m_pView->activeSheet()->shiftRow( rect ) )
94 KMessageBox::error( this, i18n("The row is full. Cannot move cells to the right.") );
95 }
96 else if( insRem == Remove )
97 {
98 m_pView->activeSheet()->unshiftRow(rect);
99 }
100 }
101 else if( rb2->isChecked() )
102 {
103 if( insRem == Insert )
104 {
105 if ( !m_pView->activeSheet()->shiftColumn( rect ) )
106 KMessageBox::error( this, i18n("The column is full. Cannot move cells towards the bottom.") );
107 }
108 else if( insRem == Remove )
109 {
110 m_pView->activeSheet()->unshiftColumn( rect );
111 }
112 }
113 else if( rb3->isChecked() )
114 {
115 if( insRem == Insert )
116 {
117 if ( !m_pView->activeSheet()->insertRow( rect.top(),(rect.bottom()-rect.top() ) ) )
118 KMessageBox::error( this, i18n("The row is full. Cannot move cells to the right.") );
119 }
120 else if( insRem == Remove )
121 {
122 m_pView->activeSheet()->removeRow( rect.top(),(rect.bottom()-rect.top() ) );
123 }
124 }
125 else if( rb4->isChecked() )
126 {
127 if( insRem == Insert )
128 {
129 if ( !m_pView->activeSheet()->insertColumn( rect.left(),(rect.right()-rect.left() )) )
130 KMessageBox::error( this, i18n("The column is full. Cannot move cells towards the bottom.") );
131 }
132 else if( insRem == Remove )
133 {
134 m_pView->activeSheet()->removeColumn( rect.left(),(rect.right()-rect.left() ) );
135 }
136 }
137 else
138 {
139 kdDebug(36001) << "Error in kspread_dlg_InsertDialog" << endl;
140 }
141
142 m_pView->updateEditWidget();
143
144 m_pView->slotUpdateView( m_pView->activeSheet() );
145 accept();
146}
147
148#include "kspread_dlg_insert.moc"
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39