kspread

ShowDialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1999-2004 Laurent Montel <montel@kde.org>
00003              (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
00004              (C) 2003 Norbert Andres <nandres@web.de>
00005              (C) 2002 John Dailey <dailey@vt.edu>
00006              (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
00007              (C) 1998-1999 Torben Weis <weis@kde.org>
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License as published by the Free Software Foundation; either
00012    version 2 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Library General Public License for more details.
00018 
00019    You should have received a copy of the GNU Library General Public License
00020    along with this library; see the file COPYING.LIB.  If not, write to
00021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022    Boston, MA 02110-1301, USA.
00023 */
00024 
00025 // Local
00026 #include "ShowDialog.h"
00027 
00028 #include <QLabel>
00029 #include <QVBoxLayout>
00030 #include <QListWidget>
00031 
00032 #include <klocale.h>
00033 
00034 #include "part/Doc.h" // FIXME detach from part
00035 #include "Map.h"
00036 #include "part/View.h" // FIXME detach from part
00037 
00038 // commands
00039 #include "commands/SheetCommands.h"
00040 
00041 using namespace KSpread;
00042 
00043 ShowDialog::ShowDialog(View* parent, const char* name)
00044         : KDialog(parent)
00045 {
00046     setCaption(i18n("Show Sheet"));
00047     setModal(true);
00048     setButtons(Ok | Cancel);
00049     setObjectName(name);
00050 
00051     m_pView = parent;
00052     QWidget *page = new QWidget(this);
00053     setMainWidget(page);
00054     QVBoxLayout *lay1 = new QVBoxLayout(page);
00055     lay1->setMargin(0);
00056     lay1->setSpacing(spacingHint());
00057 
00058     QLabel *label = new QLabel(i18n("Select hidden sheets to show:"), page);
00059     lay1->addWidget(label);
00060 
00061     list = new QListWidget(page);
00062     lay1->addWidget(list);
00063 
00064     list->setSelectionMode(QAbstractItemView::MultiSelection);
00065     QString text;
00066     QStringList::Iterator it;
00067     QStringList tabsList = m_pView->doc()->map()->hiddenSheets();
00068     for (it = tabsList.begin(); it != tabsList.end(); ++it) {
00069         text = *it;
00070         list->addItem(text);
00071     }
00072     if (!list->count())
00073         enableButtonOk(false);
00074     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
00075     connect(list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotDoubleClicked(QListWidgetItem *)));
00076     resize(200, 150);
00077     setFocus();
00078 }
00079 
00080 void ShowDialog::slotDoubleClicked(QListWidgetItem *)
00081 {
00082     slotOk();
00083 }
00084 
00085 
00086 
00087 void ShowDialog::slotOk()
00088 {
00089     QStringList listSheet;
00090 
00091     for (int i = 0; i < list->count(); i++) {
00092         if (list->item(i)->isSelected()) {
00093             listSheet.append(list->item(i)->text());
00094         }
00095     }
00096 
00097     //m_pView->tabBar()->showSheet(listSheet);
00098 
00099     if (listSheet.count() == 0)
00100         return;
00101 
00102     Sheet *sheet;
00103     QUndoCommand* macroCommand = new QUndoCommand(i18n("Show Sheet"));
00104     for (QStringList::Iterator it = listSheet.begin(); it != listSheet.end(); ++it) {
00105         sheet = m_pView->doc()->map()->findSheet(*it);
00106         if (!sheet)
00107             continue;
00108         new ShowSheetCommand(sheet, macroCommand);
00109     }
00110     m_pView->doc()->addCommand(macroCommand);
00111     m_pView->slotUpdateView(m_pView->activeSheet());
00112     accept();
00113 }
00114 
00115 #include "ShowDialog.moc"