kspread
kspread_dlg_insert.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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"
|