File indexing completed on 2025-01-12 13:05:50
0001 /* This file is part of the KDE project 0002 Copyright (C) 2005 Bram Schoenmakers <bramschoenmakers@kde.nl> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "exportdialog.h" 0021 0022 #include <QCheckBox> 0023 #include <QComboBox> 0024 #include <QListWidget> 0025 #include <QRadioButton> 0026 #include <QSpinBox> 0027 #include <QTextCodec> 0028 #include <QApplication> 0029 #include <QUrl> 0030 0031 #include <kglobal.h> 0032 #include <klocale.h> 0033 0034 ExportDialog::ExportDialog(QWidget *parent) 0035 : KoDialog(parent), m_mainwidget(new ExportWidget(this)) 0036 { 0037 setCaption(i18n("Export Sheet to HTML")); 0038 setButtons(Ok | Cancel); 0039 setDefaultButton(Cancel); 0040 QApplication::restoreOverrideCursor(); 0041 0042 connect(m_mainwidget->mCustomButton, SIGNAL(toggled(bool)), 0043 m_mainwidget->mCustomURL, SLOT(setEnabled(bool))); 0044 connect(m_mainwidget->mSelectAllButton, SIGNAL(clicked()), SLOT(selectAll())); 0045 connect(m_mainwidget->mDeselectAllButton, SIGNAL(clicked()), 0046 m_mainwidget->mSheets, SLOT(clearSelection())); 0047 0048 m_mainwidget->mEncodingBox->addItem(i18n("Recommended: UTF-8")); 0049 m_mainwidget->mEncodingBox->addItem(i18n("Locale (%1)", QString::fromLatin1(KGlobal::locale()->codecForEncoding()->name()))); 0050 0051 m_mainwidget->mCustomURL->setMode(KFile::ExistingOnly); 0052 0053 setMainWidget(m_mainwidget); 0054 } 0055 0056 void ExportDialog::selectAll() 0057 { 0058 0059 QListWidget *view = m_mainwidget->mSheets; 0060 QAbstractItemModel *model = view->model(); 0061 QModelIndex topLeft = model->index(0, 0); 0062 QModelIndex bottomRight = model->index(model->rowCount() - 1, model->columnCount() - 1); 0063 QItemSelection selection(topLeft, bottomRight); 0064 view->selectionModel()->select(selection , QItemSelectionModel::QItemSelectionModel::Select); 0065 } 0066 0067 ExportDialog::~ExportDialog() 0068 { 0069 QApplication::setOverrideCursor(Qt::WaitCursor); 0070 } 0071 0072 QTextCodec *ExportDialog::encoding() const 0073 { 0074 if (m_mainwidget->mEncodingBox->currentIndex() == 1) // locale selected 0075 return KGlobal::locale()->codecForEncoding(); 0076 0077 return QTextCodec::codecForName("utf8"); // utf8 is default 0078 } 0079 0080 bool ExportDialog::useBorders() const 0081 { 0082 return m_mainwidget->mUseBorders->isChecked(); 0083 } 0084 0085 bool ExportDialog::separateFiles() const 0086 { 0087 return m_mainwidget->mSeparateFiles->isChecked(); 0088 } 0089 0090 QUrl ExportDialog::customStyleURL() const 0091 { 0092 QUrl url = m_mainwidget->mCustomURL->url(); 0093 if (m_mainwidget->mCustomButton->isChecked() && url.isValid()) 0094 return url; 0095 0096 return QUrl(); 0097 } 0098 0099 void ExportDialog::setSheets(const QStringList &list) 0100 { 0101 m_mainwidget->mSheets->addItems(list); 0102 selectAll(); 0103 } 0104 0105 QStringList ExportDialog::sheets() const 0106 { 0107 QListWidget* view = m_mainwidget->mSheets; 0108 QStringList list; 0109 for (uint i = 0; i < (uint)view->count() ; i++) { 0110 QListWidgetItem* item = view->item(i); 0111 if (item->isSelected()) { 0112 list.append(item->text()); 0113 } 0114 } 0115 return list; 0116 } 0117 0118 int ExportDialog::pixelsBetweenCells() const 0119 { 0120 return m_mainwidget->mPixelsBetweenCells->value(); 0121 }