File indexing completed on 2024-05-12 16:35:19
0001 /* This file is part of the KDE project 0002 Copyright (C) 1999-2003 Laurent Montel <montel@kde.org> 0003 (C) 2003 Philipp Mueller <philipp.mueller@gmx.de> 0004 (C) 2003 Ariya Hidayat <ariya@kde.org> 0005 (C) 2003 Norbert Andres <nandres@web.de> 0006 (C) 1999 Stephan Kulow <coolo@kde.org> 0007 (C) 1998-2000 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 "GotoDialog.h" 0027 0028 #include <QLabel> 0029 #include <QVBoxLayout> 0030 0031 #include <kcombobox.h> 0032 0033 #include "Cell.h" 0034 #include "Localization.h" 0035 #include "Map.h" 0036 #include "NamedAreaManager.h" 0037 #include "ui/Selection.h" 0038 #include "Sheet.h" 0039 #include "Util.h" 0040 0041 using namespace Calligra::Sheets; 0042 0043 GotoDialog::GotoDialog(QWidget* parent, Selection* selection) 0044 : KoDialog(parent) 0045 { 0046 setCaption(i18n("Goto Cell")); 0047 setObjectName(QLatin1String("GotoDialog")); 0048 setModal(true); 0049 setButtons(Ok | Cancel); 0050 0051 m_selection = selection; 0052 QWidget *page = new QWidget(); 0053 setMainWidget(page); 0054 QVBoxLayout *lay1 = new QVBoxLayout(page); 0055 0056 QLabel *label = new QLabel(i18n("Enter cell:"), page); 0057 lay1->addWidget(label); 0058 0059 m_nameCell = new KComboBox(page); 0060 m_nameCell->setEditable(true); 0061 lay1->addWidget(m_nameCell); 0062 0063 const Sheet* sheet = m_selection->activeSheet(); 0064 if (sheet && selection) { 0065 Cell cell(sheet, selection->cursor()); 0066 m_nameCell->addItem(cell.name()); 0067 m_nameCell->addItem(cell.fullName()); 0068 } 0069 NamedAreaManager *manager = m_selection->activeSheet()->map()->namedAreaManager(); 0070 m_nameCell->addItems(manager->areaNames()); 0071 m_nameCell->setFocus(); 0072 0073 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); 0074 connect(m_nameCell, SIGNAL(editTextChanged(QString)), 0075 this, SLOT(textChanged(QString))); 0076 0077 resize(QSize(320, 50).expandedTo(minimumSizeHint())); 0078 } 0079 0080 void GotoDialog::textChanged(const QString &_text) 0081 { 0082 enableButtonOk(!_text.isEmpty()); 0083 } 0084 0085 void GotoDialog::slotOk() 0086 { 0087 QString tmp_upper = m_nameCell->currentText(); 0088 Region region(tmp_upper, m_selection->activeSheet()->map(), m_selection->activeSheet()); 0089 if (region.isValid()) { 0090 if (region.firstSheet() != m_selection->activeSheet()) 0091 m_selection->emitVisibleSheetRequested(region.firstSheet()); 0092 m_selection->initialize(region); 0093 accept(); 0094 } else { 0095 m_nameCell->setItemText(m_nameCell->currentIndex(), ""); 0096 } 0097 }