kspread Library API Documentation

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., 59 Temple Place - Suite 330,
00024    Boston, MA 02111-1307, USA.
00025 */
00026 
00027 
00028 #include "kspread_dlg_insert.h"
00029 #include "kspread_view.h"
00030 #include "kspread_doc.h"
00031 #include "kspread_sheet.h"
00032 
00033 #include <qlayout.h>
00034 #include <kbuttonbox.h>
00035 #include <klocale.h>
00036 #include <qbuttongroup.h>
00037 #include <kdebug.h>
00038 #include <qradiobutton.h>
00039 #include <qcheckbox.h>
00040 #include <kmessagebox.h>
00041 
00042 KSpreadinsert::KSpreadinsert( KSpreadView* parent, const char* name,const QRect &_rect,Mode _mode)
00043     : KDialogBase( parent, name, TRUE,"",Ok|Cancel )
00044 {
00045   m_pView = parent;
00046   rect=_rect;
00047   insRem=_mode;
00048 
00049   QWidget *page = new QWidget( this );
00050   setMainWidget(page);
00051   QVBoxLayout *lay1 = new QVBoxLayout( page, 0, spacingHint() );
00052 
00053   QButtonGroup *grp = new QButtonGroup( 1, QGroupBox::Horizontal, i18n("Insert"),page);
00054   grp->setRadioButtonExclusive( TRUE );
00055   grp->layout();
00056   lay1->addWidget(grp);
00057   if( insRem==Insert)
00058   {
00059     rb1 = new QRadioButton( i18n("Move towards right"), grp );
00060     rb2 = new QRadioButton( i18n("Move towards bottom"), grp );
00061     rb3 = new QRadioButton( i18n("Insert rows"), grp );
00062     rb4 = new QRadioButton( i18n("Insert columns"), grp );
00063     setCaption( i18n("Insert Cells") );
00064   }
00065   else if(insRem==Remove)
00066   {
00067     grp->setTitle(i18n("Remove"));
00068     rb1 = new QRadioButton( i18n("Move towards left"), grp );
00069     rb2 = new QRadioButton( i18n("Move towards top"), grp );
00070     rb3 = new QRadioButton( i18n("Remove rows"), grp );
00071     rb4 = new QRadioButton( i18n("Remove columns"), grp );
00072     setCaption( i18n("Remove Cells") );
00073   }
00074   else
00075     kdDebug(36001) << "Error in kspread_dlg_insert" << endl;
00076 
00077   rb1->setChecked(true);
00078 
00079 
00080   connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00081 }
00082 
00083 void KSpreadinsert::slotOk()
00084 {
00085     m_pView->doc()->emitBeginOperation( false );
00086     if( rb1->isChecked() )
00087     {
00088     if( insRem == Insert )
00089         {
00090         if ( !m_pView->activeSheet()->shiftRow( rect ) )
00091         KMessageBox::error( this, i18n("The row is full. Cannot move cells to the right.") );
00092     }
00093     else if( insRem == Remove )
00094         {
00095         m_pView->activeSheet()->unshiftRow(rect);
00096     }
00097     }
00098     else if( rb2->isChecked() )
00099     {
00100     if( insRem == Insert )
00101         {
00102         if ( !m_pView->activeSheet()->shiftColumn( rect ) )
00103         KMessageBox::error( this, i18n("The column is full. Cannot move cells towards the bottom.") );
00104     }
00105     else if( insRem == Remove )
00106         {
00107         m_pView->activeSheet()->unshiftColumn( rect );
00108     }
00109     }
00110     else if( rb3->isChecked() )
00111     {
00112     if( insRem == Insert )
00113         {
00114         if ( !m_pView->activeSheet()->insertRow( rect.top(),(rect.bottom()-rect.top() ) ) )
00115         KMessageBox::error( this, i18n("The row is full. Cannot move cells to the right.") );
00116     }
00117     else if( insRem == Remove )
00118         {
00119         m_pView->activeSheet()->removeRow( rect.top(),(rect.bottom()-rect.top() ) );
00120     }
00121     }
00122     else if( rb4->isChecked() )
00123     {
00124     if( insRem == Insert )
00125         {
00126         if ( !m_pView->activeSheet()->insertColumn( rect.left(),(rect.right()-rect.left() )) )
00127         KMessageBox::error( this, i18n("The column is full. Cannot move cells towards the bottom.") );
00128     }
00129     else if( insRem == Remove )
00130         {
00131         m_pView->activeSheet()->removeColumn( rect.left(),(rect.right()-rect.left() ) );
00132     }
00133     }
00134     else
00135     {
00136     kdDebug(36001) << "Error in kspread_dlg_insert" << endl;
00137     }
00138 
00139     m_pView->updateEditWidget();
00140 
00141     m_pView->slotUpdateView( m_pView->activeSheet() );
00142     accept();
00143 }
00144 
00145 
00146 #include "kspread_dlg_insert.moc"
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:42:54 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003