File indexing completed on 2024-05-12 16:35:18

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
0003              (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
0004              (C) 2002-2003 Norbert Andres <nandres@web.de>
0005              (C) 2000-2005 Laurent Montel <montel@kde.org>
0006              (C) 2002 John Dailey <dailey@vt.edu>
0007              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
0008              (C) 2001-2002 David Faure <faure@kde.org>
0009              (C) 2001 Werner Trobin <trobin@kde.org>
0010              (C) 2000 Bernd Johannes Wuebben <wuebben@kde.org>
0011 
0012    This library is free software; you can redistribute it and/or
0013    modify it under the terms of the GNU Library General Public
0014    License as published by the Free Software Foundation; either
0015    version 2 of the License, or (at your option) any later version.
0016 
0017    This library is distributed in the hope that it will be useful,
0018    but WITHOUT ANY WARRANTY; without even the implied warranty of
0019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0020    Library General Public License for more details.
0021 
0022    You should have received a copy of the GNU Library General Public License
0023    along with this library; see the file COPYING.LIB.  If not, write to
0024    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0025    Boston, MA 02110-1301, USA.
0026 */
0027 
0028 // Local
0029 #include "DocumentSettingsDialog.h"
0030 
0031 #include <QCheckBox>
0032 #include <QGridLayout>
0033 #include <QGroupBox>
0034 #include <QLabel>
0035 #include <QPushButton>
0036 #include <QScrollBar>
0037 #include <QComboBox>
0038 #include <QSpinBox>
0039 
0040 #include <KoVBox.h>
0041 
0042 #include <sonnet/configwidget.h>
0043 
0044 #include <KoIcon.h>
0045 #include "CalculationSettings.h"
0046 #include "Localization.h"
0047 #include "Map.h"
0048 #include "ui/Selection.h"
0049 #include "Sheet.h"
0050 
0051 using namespace Calligra::Sheets;
0052 
0053 class DocumentSettingsDialog::Private
0054 {
0055 public:
0056     KPageWidgetItem *page1, *page2;
0057     // Calculation Settings
0058     calcSettings* calcPage;
0059     // Locale Options
0060     parameterLocale* localePage;
0061 };
0062 
0063 
0064 DocumentSettingsDialog::DocumentSettingsDialog(Selection* selection, QWidget* parent)
0065         : KPageDialog(parent)
0066         , d(new Private)
0067 {
0068     setObjectName(QLatin1String("DocumentSettingsDialog"));
0069     setWindowTitle(i18n("Document Settings"));
0070 //     setFaceType(List);
0071     setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel/* | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Reset*/);
0072     button(QDialogButtonBox::Ok)->setDefault(true);
0073 
0074     connect(this, SIGNAL(accepted()), this, SLOT(slotApply()));
0075 //     connect(button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked(bool)), this, SLOT(slotDefault()));
0076 //     connect(button(QDialogButtonBox::Reset), SIGNAL(clicked(bool)), this, SLOT(slotReset()));
0077 
0078     KoVBox *p1 = new KoVBox();
0079     d->page1 = addPage(p1, i18n("Calculation"));
0080     d->page1->setHeader(QString(""));
0081     d->page1->setIcon(koIcon("application-vnd.oasis.opendocument.spreadsheet"));
0082     d->calcPage = new calcSettings(selection, p1);
0083 
0084     KoVBox *p2 = new KoVBox();
0085     d->page2 = addPage(p2, i18n("Locale"));
0086     d->page2->setHeader(QString(""));
0087     d->page2->setIcon(koIcon("preferences-desktop-locale"));
0088     d->localePage = new parameterLocale(selection, p2);
0089 }
0090 
0091 DocumentSettingsDialog::~DocumentSettingsDialog()
0092 {
0093     delete d;
0094 }
0095 
0096 void DocumentSettingsDialog::slotApply()
0097 {
0098     d->calcPage->apply();
0099     d->localePage->apply();
0100 }
0101 
0102 void DocumentSettingsDialog::slotDefault()
0103 {
0104 }
0105 
0106 void DocumentSettingsDialog::slotReset()
0107 {
0108 }
0109 
0110 
0111 calcSettings::calcSettings(Selection* selection, KoVBox *box)
0112         : QObject(box->parent())
0113 {
0114     m_cs = selection->activeSheet()->map()->calculationSettings();
0115 
0116     m_caseSensitiveCheckbox = new QCheckBox(i18n("Case sensitive"), box);
0117     m_caseSensitiveCheckbox->setChecked(m_cs->caseSensitiveComparisons() == Qt::CaseSensitive);
0118 
0119     m_precisionAsShownCheckbox = new QCheckBox(i18n("Precision as shown"), box);
0120     m_precisionAsShownCheckbox->setChecked(m_cs->precisionAsShown());
0121 
0122     m_searchCriteriaMustApplyToWholeCellCheckbox = new QCheckBox(i18n("Search criteria must apply to whole cell"), box);
0123     m_searchCriteriaMustApplyToWholeCellCheckbox->setChecked(m_cs->wholeCellSearchCriteria());
0124 
0125     m_automaticFindLabelsCheckbox = new QCheckBox(i18n("Automatic find labels"), box);
0126     m_automaticFindLabelsCheckbox->setChecked(m_cs->automaticFindLabels());
0127 
0128     QHBoxLayout *matchModeLayout = new QHBoxLayout();
0129     matchModeLayout->setMargin(0);
0130     box->layout()->addItem(matchModeLayout);
0131     QLabel *matchModeLabel = new QLabel(i18n("String comparison:"), box);
0132     matchModeLayout->addWidget(matchModeLabel);
0133     m_matchModeCombobox = new QComboBox(box);
0134     matchModeLayout->addWidget(m_matchModeCombobox);
0135     matchModeLabel->setBuddy(m_matchModeCombobox);
0136     m_matchModeCombobox->setEditable(false);
0137     m_matchModeCombobox->addItems(QStringList() << i18n("None") << i18n("Wildcards") << i18n("Regular Expressions"));
0138     m_matchModeCombobox->setCurrentIndex(m_cs->useWildcards() ? 1 : m_cs->useRegularExpressions() ? 2 : 0 );
0139 
0140     QHBoxLayout *m_nullYearLayout = new QHBoxLayout();
0141     m_nullYearLayout->setMargin(0);
0142     box->layout()->addItem(m_nullYearLayout);
0143     QLabel *m_nullYearLabel = new QLabel(i18n("Null Year:"), box);
0144     m_nullYearLayout->addWidget(m_nullYearLabel);
0145     m_nullYearEdit = new QSpinBox(box);
0146     m_nullYearLayout->addWidget(m_nullYearEdit);
0147     m_nullYearLabel->setBuddy(m_nullYearEdit);
0148     m_nullYearEdit->setRange(0, 32767);
0149     m_nullYearEdit->setValue(m_cs->referenceYear());
0150 
0151     box->layout()->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
0152 }
0153 
0154 void calcSettings::apply()
0155 {
0156     m_cs->setCaseSensitiveComparisons(m_caseSensitiveCheckbox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
0157     m_cs->setPrecisionAsShown(m_precisionAsShownCheckbox->isChecked());
0158     m_cs->setWholeCellSearchCriteria(m_searchCriteriaMustApplyToWholeCellCheckbox->isChecked());
0159     m_cs->setAutomaticFindLabels(m_automaticFindLabelsCheckbox->isChecked());
0160     m_cs->setUseWildcards(m_matchModeCombobox->currentIndex() == 1);
0161     m_cs->setUseRegularExpressions(m_matchModeCombobox->currentIndex() == 2);
0162     m_cs->setReferenceYear(m_nullYearEdit->value());
0163 }
0164 
0165 parameterLocale::parameterLocale(Selection* selection, KoVBox *box)
0166         : QObject(box->parent())
0167 {
0168     m_selection = selection;
0169     m_bUpdateLocale = false;
0170 
0171     KLocale* locale = selection->activeSheet()->map()->calculationSettings()->locale();
0172 
0173     m_language = new QLabel(box);
0174     m_number = new QLabel(box);
0175     m_date = new QLabel(box);
0176     m_shortDate = new QLabel(box);
0177     m_time = new QLabel(box);
0178     m_money = new QLabel(box);
0179 
0180     updateToMatchLocale(locale);
0181 
0182     m_updateButton = new QPushButton(i18n("&Use System's Locale Settings"), box);
0183     connect(m_updateButton, SIGNAL(clicked()), this, SLOT(updateDefaultSystemConfig()));
0184 
0185     box->layout()->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
0186 }
0187 
0188 void parameterLocale::apply()
0189 {
0190     if (m_bUpdateLocale) {
0191         const QList<Sheet*> sheets = m_selection->activeSheet()->map()->sheetList();
0192         foreach(Sheet* sheet, sheets) {
0193             sheet->updateLocale();
0194         }
0195     }
0196 }
0197 
0198 void parameterLocale::updateDefaultSystemConfig()
0199 {
0200     m_bUpdateLocale = true;
0201     KLocale* const locale = m_selection->activeSheet()->map()->calculationSettings()->locale();
0202     static_cast<Localization*>(locale)->defaultSystemConfig();
0203     updateToMatchLocale(locale);
0204 }
0205 
0206 void parameterLocale::updateToMatchLocale(KLocale* locale)
0207 {
0208     m_language->setText(i18n("Language: %1", locale->language()));
0209     m_number->setText(i18n("Default number format: %1", locale->formatNumber(12.55)));   // krazy:exclude=i18ncheckarg
0210     m_date->setText(i18n("Long date format: %1", locale->formatDate(QDate::currentDate())));
0211     m_shortDate->setText(i18n("Short date format: %1", locale->formatDate(QDate::currentDate() , KLocale::ShortDate)));
0212     m_time->setText(i18n("Time format: %1", locale->formatTime(QTime::currentTime())));
0213     m_money->setText(i18n("Currency format: %1", locale->formatMoney(12.55)));
0214 }