kspread

kspread_dlg_showColRow.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Norbert Andres <nandres@web.de>
3 (C) 2000-2002 Laurent Montel <montel@kde.org>
4 (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
5 (C) 2002 John Dailey <dailey@vt.edu>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22
23#include <tqlabel.h>
24#include <tqlayout.h>
25
26#include <tdelocale.h>
27
28#include "kspread_doc.h"
29#include "kspread_sheet.h"
30#include "kspread_util.h"
31#include "kspread_view.h"
32#include "region.h"
33
34#include "kspread_dlg_showColRow.h"
35
36using namespace KSpread;
37
38ShowColRow::ShowColRow( View* parent, const char* name, Type _type )
39 : KDialogBase( parent, name,true,"",Ok|Cancel )
40{
41 m_pView = parent;
42 typeShow=_type;
43
44 TQWidget *page = new TQWidget( this );
45 setMainWidget(page);
46 TQVBoxLayout *lay1 = new TQVBoxLayout( page, 0, spacingHint() );
47
48 TQLabel *label = new TQLabel( page );
49
50 if(_type==Column) {
51 setCaption( i18n("Show Columns") );
52 label->setText(i18n("Select hidden columns to show:"));
53 }
54 else if(_type==Row) {
55 setCaption( i18n("Show Rows") );
56 label->setText(i18n("Select hidden rows to show:"));
57 }
58
59 list=new TQListBox(page);
60
61 lay1->addWidget( label );
62 lay1->addWidget( list );
63
64 bool showColNumber=m_pView->activeSheet()->getShowColumnNumber();
65 if(_type==Column)
66 {
67 ColumnFormat *col=m_pView->activeSheet()->firstCol();
68
69 TQString text;
70 TQStringList listCol;
71 for( ; col; col = col->next() )
72 {
73 if(col->isHide())
74 listInt.append(col->column());
75 }
76 qHeapSort(listInt);
77 TQValueList<int>::Iterator it;
78 for( it = listInt.begin(); it != listInt.end(); ++it )
79 {
80 if(!showColNumber)
81 listCol+=i18n("Column: %1").arg(Cell::columnName(*it));
82 else
83 listCol+=i18n("Column: %1").arg(text.setNum(*it));
84 }
85 list->insertStringList(listCol);
86 }
87 else if(_type==Row)
88 {
89 RowFormat *row=m_pView->activeSheet()->firstRow();
90
91 TQString text;
92 TQStringList listRow;
93 for( ; row; row = row->next() )
94 {
95 if(row->isHide())
96 listInt.append(row->row());
97 }
98 qHeapSort(listInt);
99 TQValueList<int>::Iterator it;
100 for( it = listInt.begin(); it != listInt.end(); ++it )
101 listRow+=i18n("Row: %1").arg(text.setNum(*it));
102
103 list->insertStringList(listRow);
104 }
105
106 if(!list->count())
107 enableButtonOK(false);
108
109 //selection multiple
110 list->setSelectionMode(TQListBox::Multi);
111 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
112 connect( list, TQ_SIGNAL(doubleClicked(TQListBoxItem *)),this,TQ_SLOT(slotDoubleClicked(TQListBoxItem *)));
113 resize( 200, 150 );
114 setFocus();
115}
116
117void ShowColRow::slotDoubleClicked(TQListBoxItem *)
118{
119 slotOk();
120}
121
122void ShowColRow::slotOk()
123{
124 Region region;
125 for(unsigned int i=0; i < list->count(); i++)
126 {
127 if (list->isSelected(i))
128 {
129 if (typeShow == Column)
130 {
131 region.add(TQRect(*listInt.at(i), 1, 1, KS_rowMax));
132 }
133 if (typeShow == Row)
134 {
135 region.add(TQRect(1, *listInt.at(i), KS_colMax, 1));
136 }
137 }
138 }
139
140 if (typeShow == Column)
141 {
142 m_pView->activeSheet()->showColumn(region);
143 }
144 if (typeShow == Row)
145 {
146 m_pView->activeSheet()->showRow(region);
147 }
148
149 accept();
150}
151
152#include "kspread_dlg_showColRow.moc"
TQString columnName() const
Returns the column name of the cell.
The one for all class for points and ranges.
Definition region.h:44
Element * add(const TQPoint &point, Sheet *sheet=0)
Adds the point point to this region.
Definition region.cpp:245
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39