File indexing completed on 2024-05-19 16:08:12
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Norbert Andres <nandres@web.de> 0003 (C) 2000-2002 Laurent Montel <montel@kde.org> 0004 (C) 2001-2002 Philipp Mueller <philipp.mueller@gmx.de> 0005 (C) 2002 John Dailey <dailey@vt.edu> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 // Local 0024 #include "ShowColRowDialog.h" 0025 0026 // Qt 0027 #include <QLabel> 0028 #include <QVBoxLayout> 0029 #include <QListWidget> 0030 0031 // KF5 0032 #include <KLocalizedString> 0033 0034 // Sheets 0035 #include "calligra_sheets_limits.h" 0036 #include "Region.h" 0037 #include "RowColumnFormat.h" 0038 #include "RowFormatStorage.h" 0039 #include "ui/Selection.h" 0040 #include "Sheet.h" 0041 0042 // commands 0043 #include "commands/RowColumnManipulators.h" 0044 0045 // Other 0046 #include <algorithm> 0047 0048 using namespace Calligra::Sheets; 0049 0050 ShowColRow::ShowColRow(QWidget* parent, Selection* selection, Type _type) 0051 : KoDialog(parent) 0052 { 0053 setModal(true); 0054 setButtons(Ok | Cancel); 0055 m_selection = selection; 0056 typeShow = _type; 0057 0058 QWidget *page = new QWidget(); 0059 setMainWidget(page); 0060 QVBoxLayout *lay1 = new QVBoxLayout(page); 0061 0062 QLabel *label = new QLabel(page); 0063 0064 if (_type == Column) { 0065 setWindowTitle(i18n("Show Columns")); 0066 label->setText(i18n("Select hidden columns to show:")); 0067 } else if (_type == Row) { 0068 setWindowTitle(i18n("Show Rows")); 0069 label->setText(i18n("Select hidden rows to show:")); 0070 } 0071 0072 list = new QListWidget(page); 0073 0074 lay1->addWidget(label); 0075 lay1->addWidget(list); 0076 0077 bool showColNumber = m_selection->activeSheet()->getShowColumnNumber(); 0078 if (_type == Column) { 0079 ColumnFormat *col = m_selection->activeSheet()->firstCol(); 0080 0081 QString text; 0082 QStringList listCol; 0083 for (; col; col = col->next()) { 0084 if (col->isHidden()) 0085 listInt.append(col->column()); 0086 } 0087 std::sort(listInt.begin(), listInt.end()); 0088 for (QList<int>::ConstIterator it = listInt.constBegin(); it != listInt.constEnd(); ++it) { 0089 if (!showColNumber) 0090 listCol += i18n("Column: %1", Cell::columnName(*it)); 0091 else 0092 listCol += i18n("Column: %1", text.setNum(*it)); 0093 } 0094 list->addItems(listCol); 0095 } else if (_type == Row) { 0096 QString text; 0097 QStringList listRow; 0098 int lastRow, row = 1; 0099 while (row <= KS_rowMax) { 0100 if (m_selection->activeSheet()->rowFormats()->isHidden(row, &lastRow)) { 0101 for (int i = row; i <= lastRow; ++i) 0102 listInt.append(i); 0103 } 0104 row = lastRow+1; 0105 } 0106 for (QList<int>::ConstIterator it = listInt.constBegin(); it != listInt.constEnd(); ++it) 0107 listRow += i18n("Row: %1", text.setNum(*it)); 0108 0109 list->addItems(listRow); 0110 } 0111 0112 if (!list->count()) 0113 enableButtonOk(false); 0114 0115 //selection multiple 0116 list->setSelectionMode(QAbstractItemView::MultiSelection); 0117 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); 0118 connect(list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotDoubleClicked(QListWidgetItem*))); 0119 resize(200, 150); 0120 setFocus(); 0121 } 0122 0123 void ShowColRow::slotDoubleClicked(QListWidgetItem *) 0124 { 0125 slotOk(); 0126 } 0127 0128 void ShowColRow::slotOk() 0129 { 0130 Region region; 0131 for (unsigned int i = 0; i < (unsigned int)list->count(); i++) { 0132 if (list->item(i)->isSelected()) { 0133 if (typeShow == Column) { 0134 region.add(QRect(listInt.at(i), 1, 1, KS_rowMax)); 0135 } 0136 if (typeShow == Row) { 0137 region.add(QRect(1, listInt.at(i), KS_colMax, 1)); 0138 } 0139 } 0140 } 0141 0142 HideShowManipulator* manipulator = new HideShowManipulator(); 0143 manipulator->setSheet(m_selection->activeSheet()); 0144 if (typeShow == Column) { 0145 manipulator->setManipulateColumns(true); 0146 } 0147 if (typeShow == Row) { 0148 manipulator->setManipulateRows(true); 0149 } 0150 manipulator->setReverse(true); 0151 manipulator->add(region); 0152 manipulator->execute(m_selection->canvas()); 0153 0154 accept(); 0155 }