1 /* This file is part of the KDE project
2    Copyright (C) 1999-2004 Laurent Montel <montel@kde.org>
3              (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
4              (C) 2003 Norbert Andres <nandres@web.de>
5              (C) 2002 John Dailey <dailey@vt.edu>
6              (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
7              (C) 1998-1999 Torben Weis <weis@kde.org>
8 
9    This library is free software; you can redistribute it and/or
10    modify it under the terms of the GNU Library General Public
11    License as published by the Free Software Foundation; either
12    version 2 of the License, or (at your option) any later version.
13 
14    This library is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    Library General Public License for more details.
18 
19    You should have received a copy of the GNU Library General Public License
20    along with this library; see the file COPYING.LIB.  If not, write to
21    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22    Boston, MA 02110-1301, USA.
23 */
24 
25 // Local
26 #include "ShowDialog.h"
27 
28 #include <QLabel>
29 #include <QListWidget>
30 #include <QVBoxLayout>
31 
32 #include <KLocalizedString>
33 
34 #include "Damages.h"
35 #include "Map.h"
36 #include "ui/Selection.h"
37 #include "Sheet.h"
38 
39 // commands
40 #include "commands/SheetCommands.h"
41 
42 using namespace Calligra::Sheets;
43 
ShowDialog(QWidget * parent,Selection * selection)44 ShowDialog::ShowDialog(QWidget* parent, Selection* selection)
45         : KoDialog(parent)
46         , m_selection(selection)
47 {
48     setCaption(i18n("Show Sheet"));
49     setModal(true);
50     setButtons(Ok | Cancel);
51     setObjectName(QLatin1String("ShowDialog"));
52 
53     QWidget *page = new QWidget(this);
54     setMainWidget(page);
55     QVBoxLayout *lay1 = new QVBoxLayout(page);
56     lay1->setMargin(0);
57 
58     QLabel *label = new QLabel(i18n("Select hidden sheets to show:"), page);
59     lay1->addWidget(label);
60 
61     m_listWidget = new QListWidget(page);
62     lay1->addWidget(m_listWidget);
63 
64     m_listWidget->setSelectionMode(QListWidget::MultiSelection);
65     QStringList tabsList = m_selection->activeSheet()->map()->hiddenSheets();
66     m_listWidget->addItems(tabsList);
67     if (!m_listWidget->count())
68         enableButtonOk(false);
69     connect(m_listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
70             this, SLOT(accept()));
71     resize(200, 150);
72     setFocus();
73 }
74 
accept()75 void ShowDialog::accept()
76 {
77     const QList<QListWidgetItem *> items = m_listWidget->selectedItems();
78 
79     if (items.count() == 0) {
80         return;
81     }
82 
83     Map *const map = m_selection->activeSheet()->map();
84     Sheet *sheet;
85     KUndo2Command* macroCommand = new KUndo2Command(kundo2_i18n("Show Sheet"));
86     for (int i = 0; i < items.count(); ++i) {
87         sheet = map->findSheet(items[i]->text());
88         if (!sheet)
89             continue;
90         new ShowSheetCommand(sheet, macroCommand);
91     }
92     map->addCommand(macroCommand);
93     // Just repaint everything visible; no need to invalidate the visual cache.
94     map->addDamage(new SheetDamage(m_selection->activeSheet(), SheetDamage::ContentChanged));
95     KoDialog::accept();
96 }
97