kword

KWDeleteDia.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C)  2005 Thomas Zander <zander@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KWTableFrameSet.h"
00022 #include "KWDeleteDia.h"
00023 #include "KWView.h"
00024 
00025 #include <klocale.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 
00029 KWDeleteDia::KWDeleteDia( KWView *parent, KWTableFrameSet *table, DeleteType type, QValueList<uint> remove)
00030     : KDialogBase( Plain, (type==deleteRow?i18n("Delete Row") : i18n("Delete Column")), Ok | Cancel, Ok, parent, "Delete Table items dialog", true )
00031 {
00032     Q_ASSERT(type == deleteRow || type == deleteColumn);
00033     m_type = type;
00034     m_table = table;
00035     m_toRemove = remove;
00036     m_view = parent;
00037 
00038     setupTab1();
00039     setButtonOK( KGuiItem(
00040         i18n("&Delete"), "editdelete", type == deleteRow ?
00041         i18n("Delete the row from the table.") :
00042         i18n("Delete the column from the table.")) );
00043 }
00044 
00045 void KWDeleteDia::setupTab1() {
00046     QWidget *tab1 = plainPage();
00047     QGridLayout *grid1 = new QGridLayout( tab1, 4, 1, 0, spacingHint() );
00048     unsigned int count = m_toRemove.count();
00049     Q_ASSERT(count > 0);
00050 
00051     QString message;
00052     if ( count == ( (m_type == deleteRow) ? m_table->getRows() : m_table->getColumns() ) )
00053         // all the columns are selected and the user asked to remove columns or the same with rows
00054         // => we want to delete the whole table
00055         message = i18n("Delete the whole table?");
00056     else if ( count > 10 )
00057     // do not display hugely long dialogs if many rows/cells are selected
00058         message = m_type == deleteRow ? i18n("Delete all selected rows?") : i18n("Delete all selected cells?");
00059     else if ( count == 1 ) {
00060         message = m_type == deleteRow ? i18n( "Delete row number %1?" ) : i18n( "Delete column number %1?" );
00061         message = message.arg( m_toRemove.first() + 1 ); // +1 because humans count from 1
00062     }
00063     else {
00064         message = m_type == deleteRow ? i18n( "Delete rows: %1 ?" ) : i18n( "Delete columns: %1 ?" );
00065 
00066         QValueListIterator<uint> items = m_toRemove.begin();
00067         QString rows;
00068         for(;items != m_toRemove.end(); ++items) {
00069             if(! rows.isEmpty())
00070                 rows += ", ";
00071             rows += QString().setNum((*items) +1);
00072         }
00073         message = message.arg( rows );
00074     }
00075 
00076     QLabel *rc = new QLabel( message , tab1 );
00077     rc->resize( rc->sizeHint() );
00078     rc->setAlignment( AlignLeft | AlignBottom );
00079     grid1->addWidget( rc, 1, 0 );
00080 }
00081 
00082 void KWDeleteDia::slotOk() {
00083     if(m_type == deleteRow)
00084         m_view->tableDeleteRow(m_toRemove);
00085     else
00086         m_view->tableDeleteCol(m_toRemove);
00087     KDialogBase::slotOk();
00088 }
00089 
00090 #include "KWDeleteDia.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys