kspread

kspread_dlg_showColRow.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Norbert Andres <nandres@web.de>
00003              (C) 2000-2002 Laurent Montel <montel@kde.org>
00004              (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
00005              (C) 2002 John Dailey <dailey@vt.edu>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <qlabel.h>
00024 #include <qlayout.h>
00025 
00026 #include <klocale.h>
00027 
00028 #include "kspread_doc.h"
00029 #include "kspread_sheet.h"
00030 #include "kspread_util.h"
00031 #include "kspread_view.h"
00032 #include "region.h"
00033 
00034 #include "kspread_dlg_showColRow.h"
00035 
00036 using namespace KSpread;
00037 
00038 ShowColRow::ShowColRow( View* parent, const char* name, Type _type )
00039     : KDialogBase( parent, name,TRUE,"",Ok|Cancel )
00040 {
00041   m_pView = parent;
00042   typeShow=_type;
00043 
00044   QWidget *page = new QWidget( this );
00045   setMainWidget(page);
00046   QVBoxLayout *lay1 = new QVBoxLayout( page, 0, spacingHint() );
00047 
00048   QLabel *label = new QLabel( page );
00049 
00050   if(_type==Column) {
00051         setCaption( i18n("Show Columns") );
00052         label->setText(i18n("Select hidden columns to show:"));
00053   }
00054   else if(_type==Row) {
00055         setCaption( i18n("Show Rows") );
00056         label->setText(i18n("Select hidden rows to show:"));
00057   }
00058 
00059   list=new QListBox(page);
00060 
00061   lay1->addWidget( label );
00062   lay1->addWidget( list );
00063 
00064   bool showColNumber=m_pView->activeSheet()->getShowColumnNumber();
00065   if(_type==Column)
00066         {
00067         ColumnFormat *col=m_pView->activeSheet()->firstCol();
00068 
00069         QString text;
00070         QStringList listCol;
00071         for( ; col; col = col->next() )
00072       {
00073         if(col->isHide())
00074           listInt.append(col->column());
00075       }
00076         qHeapSort(listInt);
00077         QValueList<int>::Iterator it;
00078         for( it = listInt.begin(); it != listInt.end(); ++it )
00079       {
00080         if(!showColNumber)
00081           listCol+=i18n("Column: %1").arg(Cell::columnName(*it));
00082         else
00083           listCol+=i18n("Column: %1").arg(text.setNum(*it));
00084       }
00085         list->insertStringList(listCol);
00086         }
00087   else if(_type==Row)
00088         {
00089         RowFormat *row=m_pView->activeSheet()->firstRow();
00090 
00091         QString text;
00092         QStringList listRow;
00093         for( ; row; row = row->next() )
00094       {
00095         if(row->isHide())
00096           listInt.append(row->row());
00097       }
00098         qHeapSort(listInt);
00099         QValueList<int>::Iterator it;
00100         for( it = listInt.begin(); it != listInt.end(); ++it )
00101       listRow+=i18n("Row: %1").arg(text.setNum(*it));
00102 
00103         list->insertStringList(listRow);
00104         }
00105 
00106   if(!list->count())
00107       enableButtonOK(false);
00108 
00109   //selection multiple
00110   list->setSelectionMode(QListBox::Multi);
00111   connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00112   connect( list, SIGNAL(doubleClicked(QListBoxItem *)),this,SLOT(slotDoubleClicked(QListBoxItem *)));
00113   resize( 200, 150 );
00114   setFocus();
00115 }
00116 
00117 void ShowColRow::slotDoubleClicked(QListBoxItem *)
00118 {
00119     slotOk();
00120 }
00121 
00122 void ShowColRow::slotOk()
00123 {
00124   Region region;
00125   for(unsigned int i=0; i < list->count(); i++)
00126   {
00127     if (list->isSelected(i))
00128     {
00129       if (typeShow == Column)
00130       {
00131         region.add(QRect(*listInt.at(i), 1, 1, KS_rowMax));
00132       }
00133       if (typeShow == Row)
00134       {
00135         region.add(QRect(1, *listInt.at(i), KS_colMax, 1));
00136       }
00137     }
00138   }
00139 
00140   if (typeShow == Column)
00141   {
00142     m_pView->activeSheet()->showColumn(region);
00143   }
00144   if (typeShow == Row)
00145   {
00146     m_pView->activeSheet()->showRow(region);
00147   }
00148 
00149   accept();
00150 }
00151 
00152 #include "kspread_dlg_showColRow.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys