kword

KWDeleteDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005 Thomas Zander <zander@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KWTableFrameSet.h"
22#include "KWDeleteDia.h"
23#include "KWView.h"
24
25#include <tdelocale.h>
26#include <tqlabel.h>
27#include <tqlayout.h>
28
29KWDeleteDia::KWDeleteDia( KWView *parent, KWTableFrameSet *table, DeleteType type, TQValueList<uint> remove)
30 : KDialogBase( Plain, (type==deleteRow?i18n("Delete Row") : i18n("Delete Column")), Ok | Cancel, Ok, parent, "Delete Table items dialog", true )
31{
32 Q_ASSERT(type == deleteRow || type == deleteColumn);
33 m_type = type;
34 m_table = table;
35 m_toRemove = remove;
36 m_view = parent;
37
38 setupTab1();
39 setButtonOK( KGuiItem(
40 i18n("&Delete"), "edit-delete", type == deleteRow ?
41 i18n("Delete the row from the table.") :
42 i18n("Delete the column from the table.")) );
43}
44
45void KWDeleteDia::setupTab1() {
46 TQWidget *tab1 = plainPage();
47 TQGridLayout *grid1 = new TQGridLayout( tab1, 4, 1, 0, spacingHint() );
48 unsigned int count = m_toRemove.count();
49 Q_ASSERT(count > 0);
50
51 TQString message;
52 if ( count == ( (m_type == deleteRow) ? m_table->getRows() : m_table->getColumns() ) )
53 // all the columns are selected and the user asked to remove columns or the same with rows
54 // => we want to delete the whole table
55 message = i18n("Delete the whole table?");
56 else if ( count > 10 )
57 // do not display hugely long dialogs if many rows/cells are selected
58 message = m_type == deleteRow ? i18n("Delete all selected rows?") : i18n("Delete all selected cells?");
59 else if ( count == 1 ) {
60 message = m_type == deleteRow ? i18n( "Delete row number %1?" ) : i18n( "Delete column number %1?" );
61 message = message.arg( m_toRemove.first() + 1 ); // +1 because humans count from 1
62 }
63 else {
64 message = m_type == deleteRow ? i18n( "Delete rows: %1 ?" ) : i18n( "Delete columns: %1 ?" );
65
66 TQValueListIterator<uint> items = m_toRemove.begin();
67 TQString rows;
68 for(;items != m_toRemove.end(); ++items) {
69 if(! rows.isEmpty())
70 rows += ", ";
71 rows += TQString().setNum((*items) +1);
72 }
73 message = message.arg( rows );
74 }
75
76 TQLabel *rc = new TQLabel( message , tab1 );
77 rc->resize( rc->sizeHint() );
78 rc->setAlignment( AlignLeft | AlignBottom );
79 grid1->addWidget( rc, 1, 0 );
80}
81
82void KWDeleteDia::slotOk() {
83 if(m_type == deleteRow)
84 m_view->tableDeleteRow(m_toRemove);
85 else
86 m_view->tableDeleteCol(m_toRemove);
87 KDialogBase::slotOk();
88}
89
90#include "KWDeleteDia.moc"
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...