File indexing completed on 2024-05-12 16:35:25
0001 /* This file is part of the KDE project 0002 Copyright (C) 1999-2004 Laurent Montel <montel@kde.org> 0003 (C) 2002-2004 Ariya Hidayat <ariya@kde.org> 0004 (C) 2003 Norbert Andres <nandres@web.de> 0005 (C) 2002 John Dailey <dailey@vt.edu> 0006 (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de> 0007 (C) 1998-1999 Torben Weis <weis@kde.org> 0008 0009 This library is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU Library General Public 0011 License as published by the Free Software Foundation; either 0012 version 2 of the License, or (at your option) any later version. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Library General Public License for more details. 0018 0019 You should have received a copy of the GNU Library General Public License 0020 along with this library; see the file COPYING.LIB. If not, write to 0021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 Boston, MA 02110-1301, USA. 0023 */ 0024 0025 // Local 0026 #include "ShowDialog.h" 0027 0028 #include <QLabel> 0029 #include <QListWidget> 0030 #include <QVBoxLayout> 0031 0032 #include <KLocalizedString> 0033 0034 #include "Damages.h" 0035 #include "Map.h" 0036 #include "ui/Selection.h" 0037 #include "Sheet.h" 0038 0039 // commands 0040 #include "commands/SheetCommands.h" 0041 0042 using namespace Calligra::Sheets; 0043 0044 ShowDialog::ShowDialog(QWidget* parent, Selection* selection) 0045 : KoDialog(parent) 0046 , m_selection(selection) 0047 { 0048 setCaption(i18n("Show Sheet")); 0049 setModal(true); 0050 setButtons(Ok | Cancel); 0051 setObjectName(QLatin1String("ShowDialog")); 0052 0053 QWidget *page = new QWidget(this); 0054 setMainWidget(page); 0055 QVBoxLayout *lay1 = new QVBoxLayout(page); 0056 lay1->setMargin(0); 0057 0058 QLabel *label = new QLabel(i18n("Select hidden sheets to show:"), page); 0059 lay1->addWidget(label); 0060 0061 m_listWidget = new QListWidget(page); 0062 lay1->addWidget(m_listWidget); 0063 0064 m_listWidget->setSelectionMode(QListWidget::MultiSelection); 0065 QStringList tabsList = m_selection->activeSheet()->map()->hiddenSheets(); 0066 m_listWidget->addItems(tabsList); 0067 if (!m_listWidget->count()) 0068 enableButtonOk(false); 0069 connect(m_listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), 0070 this, SLOT(accept())); 0071 resize(200, 150); 0072 setFocus(); 0073 } 0074 0075 void ShowDialog::accept() 0076 { 0077 const QList<QListWidgetItem *> items = m_listWidget->selectedItems(); 0078 0079 if (items.count() == 0) { 0080 return; 0081 } 0082 0083 Map *const map = m_selection->activeSheet()->map(); 0084 Sheet *sheet; 0085 KUndo2Command* macroCommand = new KUndo2Command(kundo2_i18n("Show Sheet")); 0086 for (int i = 0; i < items.count(); ++i) { 0087 sheet = map->findSheet(items[i]->text()); 0088 if (!sheet) 0089 continue; 0090 new ShowSheetCommand(sheet, macroCommand); 0091 } 0092 map->addCommand(macroCommand); 0093 // Just repaint everything visible; no need to invalidate the visual cache. 0094 map->addDamage(new SheetDamage(m_selection->activeSheet(), SheetDamage::ContentChanged)); 0095 KoDialog::accept(); 0096 }