kspread

kspread_dlg_insert.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Norbert Andres <nandres@web.de>
00003              (C) 1999-2002 Laurent Montel <montel@kde.org>
00004              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
00005              (C) 2002 John Dailey <dailey@vt.edu>
00006              (C) 2000-2001 Werner Trobin <trobin@kde.org>
00007              (C) 2000 David Faure <faure@kde.org>
00008              (C) 1999 Stephan Kulow <coolo@kde.org>
00009              (C) 1998-2000 Torben Weis <weis@kde.org>
00010              
00011    This library is free software; you can redistribute it and/or
00012    modify it under the terms of the GNU Library General Public
00013    License as published by the Free Software Foundation; either
00014    version 2 of the License, or (at your option) any later version.
00015 
00016    This library is distributed in the hope that it will be useful,
00017    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019    Library General Public License for more details.
00020 
00021    You should have received a copy of the GNU Library General Public License
00022    along with this library; see the file COPYING.LIB.  If not, write to
00023    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00024  * Boston, MA 02110-1301, USA.
00025 */
00026 
00027 #include <qbuttongroup.h>
00028 #include <qradiobutton.h>
00029 #include <qcheckbox.h>
00030 #include <qlayout.h>
00031 
00032 #include <kbuttonbox.h>
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kmessagebox.h>
00036 
00037 #include "kspread_doc.h"
00038 #include "kspread_sheet.h"
00039 #include "kspread_view.h"
00040 
00041 #include "kspread_dlg_insert.h"
00042 
00043 using namespace KSpread;
00044 
00045 InsertDialog::InsertDialog( View* parent, const char* name,const QRect &_rect,Mode _mode)
00046     : KDialogBase( parent, name, TRUE,"",Ok|Cancel )
00047 {
00048   m_pView = parent;
00049   rect=_rect;
00050   insRem=_mode;
00051 
00052   QWidget *page = new QWidget( this );
00053   setMainWidget(page);
00054   QVBoxLayout *lay1 = new QVBoxLayout( page, 0, spacingHint() );
00055 
00056   QButtonGroup *grp = new QButtonGroup( 1, QGroupBox::Horizontal, i18n("Insert"),page);
00057   grp->setRadioButtonExclusive( TRUE );
00058   grp->layout();
00059   lay1->addWidget(grp);
00060   if( insRem==Insert)
00061   {
00062     rb1 = new QRadioButton( i18n("Move towards right"), grp );
00063     rb2 = new QRadioButton( i18n("Move towards bottom"), grp );
00064     rb3 = new QRadioButton( i18n("Insert rows"), grp );
00065     rb4 = new QRadioButton( i18n("Insert columns"), grp );
00066     setCaption( i18n("Insert Cells") );
00067   }
00068   else if(insRem==Remove)
00069   {
00070     grp->setTitle(i18n("Remove"));
00071     rb1 = new QRadioButton( i18n("Move towards left"), grp );
00072     rb2 = new QRadioButton( i18n("Move towards top"), grp );
00073     rb3 = new QRadioButton( i18n("Remove rows"), grp );
00074     rb4 = new QRadioButton( i18n("Remove columns"), grp );
00075     setCaption( i18n("Remove Cells") );
00076   }
00077   else
00078     kdDebug(36001) << "Error in kspread_dlg_InsertDialog" << endl;
00079 
00080   rb1->setChecked(true);
00081 
00082 
00083   connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00084 }
00085 
00086 void InsertDialog::slotOk()
00087 {
00088     m_pView->doc()->emitBeginOperation( false );
00089     if( rb1->isChecked() )
00090     {
00091     if( insRem == Insert )
00092         {
00093         if ( !m_pView->activeSheet()->shiftRow( rect ) )
00094         KMessageBox::error( this, i18n("The row is full. Cannot move cells to the right.") );
00095     }
00096     else if( insRem == Remove )
00097         {
00098         m_pView->activeSheet()->unshiftRow(rect);
00099     }
00100     }
00101     else if( rb2->isChecked() )
00102     {
00103     if( insRem == Insert )
00104         {
00105         if ( !m_pView->activeSheet()->shiftColumn( rect ) )
00106         KMessageBox::error( this, i18n("The column is full. Cannot move cells towards the bottom.") );
00107     }
00108     else if( insRem == Remove )
00109         {
00110         m_pView->activeSheet()->unshiftColumn( rect );
00111     }
00112     }
00113     else if( rb3->isChecked() )
00114     {
00115     if( insRem == Insert )
00116         {
00117         if ( !m_pView->activeSheet()->insertRow( rect.top(),(rect.bottom()-rect.top() ) ) )
00118         KMessageBox::error( this, i18n("The row is full. Cannot move cells to the right.") );
00119     }
00120     else if( insRem == Remove )
00121         {
00122         m_pView->activeSheet()->removeRow( rect.top(),(rect.bottom()-rect.top() ) );
00123     }
00124     }
00125     else if( rb4->isChecked() )
00126     {
00127     if( insRem == Insert )
00128         {
00129         if ( !m_pView->activeSheet()->insertColumn( rect.left(),(rect.right()-rect.left() )) )
00130         KMessageBox::error( this, i18n("The column is full. Cannot move cells towards the bottom.") );
00131     }
00132     else if( insRem == Remove )
00133         {
00134         m_pView->activeSheet()->removeColumn( rect.left(),(rect.right()-rect.left() ) );
00135     }
00136     }
00137     else
00138     {
00139     kdDebug(36001) << "Error in kspread_dlg_InsertDialog" << endl;
00140     }
00141 
00142     m_pView->updateEditWidget();
00143 
00144     m_pView->slotUpdateView( m_pView->activeSheet() );
00145     accept();
00146 }
00147 
00148 #include "kspread_dlg_insert.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys