2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
#include "generalsettingspage.h"
|
|
|
|
|
|
2009-07-08 15:03:40 +02:00
|
|
|
#include "bookmarkmanager.h"
|
2009-06-26 16:50:50 +02:00
|
|
|
#include "centralwidget.h"
|
2010-03-16 14:47:27 +01:00
|
|
|
#include "helpconstants.h"
|
2009-06-26 16:50:50 +02:00
|
|
|
#include "helpviewer.h"
|
2010-11-16 14:15:23 +01:00
|
|
|
#include "localhelpmanager.h"
|
2009-07-08 15:03:40 +02:00
|
|
|
#include "xbelsupport.h"
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2010-03-16 14:47:27 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-08-02 16:32:18 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2010-07-23 16:36:08 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2010-03-16 14:47:27 +01:00
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QTextStream>
|
2010-03-16 14:47:27 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QFileDialog>
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2010-03-30 17:44:28 +02:00
|
|
|
#if !defined(QT_NO_WEBKIT)
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QWebSettings>
|
2010-03-30 17:44:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
2009-06-25 17:16:16 +02:00
|
|
|
using namespace Help::Internal;
|
|
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
GeneralSettingsPage::GeneralSettingsPage()
|
2010-12-02 18:28:16 +01:00
|
|
|
: m_ui(0)
|
2009-06-25 17:16:16 +02:00
|
|
|
{
|
2010-03-30 17:44:28 +02:00
|
|
|
m_font = qApp->font();
|
2009-06-25 17:16:16 +02:00
|
|
|
#if !defined(QT_NO_WEBKIT)
|
|
|
|
|
QWebSettings* webSettings = QWebSettings::globalSettings();
|
2010-03-16 14:47:27 +01:00
|
|
|
m_font.setPointSize(webSettings->fontSize(QWebSettings::DefaultFontSize));
|
2009-06-25 17:16:16 +02:00
|
|
|
#endif
|
2012-05-22 11:17:13 +02:00
|
|
|
setId(QLatin1String("A.General settings"));
|
|
|
|
|
setDisplayName(tr("General"));
|
|
|
|
|
setCategory(QLatin1String(Help::Constants::HELP_CATEGORY));
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("Help", Help::Constants::HELP_TR_CATEGORY));
|
|
|
|
|
setCategoryIcon(QLatin1String(Help::Constants::HELP_CATEGORY_ICON));
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-25 17:16:16 +02:00
|
|
|
QWidget *GeneralSettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
2010-03-16 14:47:27 +01:00
|
|
|
QWidget *widget = new QWidget(parent);
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui = new Ui::GeneralSettingsPage;
|
|
|
|
|
m_ui->setupUi(widget);
|
|
|
|
|
m_ui->sizeComboBox->setEditable(false);
|
|
|
|
|
m_ui->styleComboBox->setEditable(false);
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2010-08-02 16:32:18 +02:00
|
|
|
Core::HelpManager *manager = Core::HelpManager::instance();
|
|
|
|
|
m_font = qVariantValue<QFont>(manager->customValue(QLatin1String("font"),
|
|
|
|
|
m_font));
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
updateFontSize();
|
|
|
|
|
updateFontStyle();
|
|
|
|
|
updateFontFamily();
|
|
|
|
|
|
2010-08-02 16:32:18 +02:00
|
|
|
m_homePage = manager->customValue(QLatin1String("HomePage"), QString())
|
|
|
|
|
.toString();
|
2010-03-16 14:47:27 +01:00
|
|
|
if (m_homePage.isEmpty()) {
|
2010-08-02 16:32:18 +02:00
|
|
|
m_homePage = manager->customValue(QLatin1String("DefaultHomePage"),
|
2010-03-29 14:00:41 +02:00
|
|
|
Help::Constants::AboutBlank).toString();
|
2009-06-26 16:50:50 +02:00
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->homePageLineEdit->setText(m_homePage);
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2012-05-24 16:19:44 +02:00
|
|
|
m_startOption = manager->customValue(QLatin1String("StartOption"),
|
2010-07-23 12:44:22 +02:00
|
|
|
Help::Constants::ShowLastPages).toInt();
|
2012-05-24 16:19:44 +02:00
|
|
|
m_ui->helpStartComboBox->setCurrentIndex(m_startOption);
|
2009-07-14 13:20:26 +02:00
|
|
|
|
2010-08-02 16:32:18 +02:00
|
|
|
m_contextOption = manager->customValue(QLatin1String("ContextHelpOption"),
|
2010-07-23 12:44:22 +02:00
|
|
|
Help::Constants::SideBySideIfPossible).toInt();
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->contextHelpComboBox->setCurrentIndex(m_contextOption);
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
connect(m_ui->currentPageButton, SIGNAL(clicked()), this, SLOT(setCurrentPage()));
|
|
|
|
|
connect(m_ui->blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage()));
|
|
|
|
|
connect(m_ui->defaultPageButton, SIGNAL(clicked()), this, SLOT(setDefaultPage()));
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2010-03-16 14:47:27 +01:00
|
|
|
HelpViewer *viewer = CentralWidget::instance()->currentHelpViewer();
|
2010-06-02 14:51:03 +02:00
|
|
|
if (!viewer)
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->currentPageButton->setEnabled(false);
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->errorLabel->setVisible(false);
|
|
|
|
|
connect(m_ui->importButton, SIGNAL(clicked()), this, SLOT(importBookmarks()));
|
|
|
|
|
connect(m_ui->exportButton, SIGNAL(clicked()), this, SLOT(exportBookmarks()));
|
2009-07-08 15:03:40 +02:00
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
if (m_searchKeywords.isEmpty()) {
|
2010-12-02 18:28:16 +01:00
|
|
|
QTextStream(&m_searchKeywords) << ' ' << m_ui->contextHelpLabel->text()
|
2012-12-14 12:17:30 +01:00
|
|
|
<< ' ' << m_ui->startPageLabel->text() << ' ' << m_ui->homePageLabel->text();
|
2009-11-24 15:05:02 +01:00
|
|
|
m_searchKeywords.remove(QLatin1Char('&'));
|
|
|
|
|
}
|
2010-09-21 17:00:41 +02:00
|
|
|
|
|
|
|
|
m_returnOnClose = manager->customValue(QLatin1String("ReturnOnClose"),
|
|
|
|
|
false).toBool();
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->m_returnOnClose->setChecked(m_returnOnClose);
|
2010-09-21 17:00:41 +02:00
|
|
|
|
2010-03-16 14:47:27 +01:00
|
|
|
return widget;
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettingsPage::apply()
|
2010-03-16 14:47:27 +01:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_ui) // page was never shown
|
|
|
|
|
return;
|
2010-03-16 14:47:27 +01:00
|
|
|
QFont newFont;
|
2010-12-02 18:28:16 +01:00
|
|
|
const QString &family = m_ui->familyComboBox->currentFont().family();
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setFamily(family);
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
int fontSize = 14;
|
2010-12-02 18:28:16 +01:00
|
|
|
int currentIndex = m_ui->sizeComboBox->currentIndex();
|
2009-06-25 17:16:16 +02:00
|
|
|
if (currentIndex != -1)
|
2010-12-02 18:28:16 +01:00
|
|
|
fontSize = m_ui->sizeComboBox->itemData(currentIndex).toInt();
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setPointSize(fontSize);
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
QString fontStyle = QLatin1String("Normal");
|
2010-12-02 18:28:16 +01:00
|
|
|
currentIndex = m_ui->styleComboBox->currentIndex();
|
2009-06-25 17:16:16 +02:00
|
|
|
if (currentIndex != -1)
|
2010-12-02 18:28:16 +01:00
|
|
|
fontStyle = m_ui->styleComboBox->itemText(currentIndex);
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setBold(m_fontDatabase.bold(family, fontStyle));
|
2009-11-16 17:58:59 +01:00
|
|
|
if (fontStyle.contains(QLatin1String("Italic")))
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setStyle(QFont::StyleItalic);
|
2009-11-16 17:58:59 +01:00
|
|
|
else if (fontStyle.contains(QLatin1String("Oblique")))
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setStyle(QFont::StyleOblique);
|
2009-11-16 17:58:59 +01:00
|
|
|
else
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setStyle(QFont::StyleNormal);
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2010-03-16 14:47:27 +01:00
|
|
|
const int weight = m_fontDatabase.weight(family, fontStyle);
|
2009-06-25 17:16:16 +02:00
|
|
|
if (weight >= 0) // Weight < 0 asserts...
|
2010-03-16 14:47:27 +01:00
|
|
|
newFont.setWeight(weight);
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2010-08-02 16:32:18 +02:00
|
|
|
Core::HelpManager *manager = Core::HelpManager::instance();
|
2010-07-23 16:36:08 +02:00
|
|
|
if (newFont != m_font) {
|
|
|
|
|
m_font = newFont;
|
2010-08-02 16:32:18 +02:00
|
|
|
manager->setCustomValue(QLatin1String("font"), newFont);
|
2010-03-30 17:44:28 +02:00
|
|
|
emit fontChanged();
|
2010-07-23 16:36:08 +02:00
|
|
|
}
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2012-05-23 15:05:37 +02:00
|
|
|
QString homePage = QUrl::fromUserInput(m_ui->homePageLineEdit->text()).toString();
|
2009-06-26 16:50:50 +02:00
|
|
|
if (homePage.isEmpty())
|
2010-03-29 14:00:41 +02:00
|
|
|
homePage = Help::Constants::AboutBlank;
|
2012-05-23 15:05:37 +02:00
|
|
|
m_ui->homePageLineEdit->setText(homePage);
|
2012-05-24 16:19:44 +02:00
|
|
|
if (m_homePage != homePage) {
|
|
|
|
|
m_homePage = homePage;
|
|
|
|
|
manager->setCustomValue(QLatin1String("HomePage"), homePage);
|
|
|
|
|
}
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
const int startOption = m_ui->helpStartComboBox->currentIndex();
|
2012-05-24 16:19:44 +02:00
|
|
|
if (m_startOption != startOption) {
|
|
|
|
|
m_startOption = startOption;
|
|
|
|
|
manager->setCustomValue(QLatin1String("StartOption"), startOption);
|
|
|
|
|
}
|
2009-07-14 13:20:26 +02:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
const int helpOption = m_ui->contextHelpComboBox->currentIndex();
|
2010-07-23 16:36:08 +02:00
|
|
|
if (m_contextOption != helpOption) {
|
|
|
|
|
m_contextOption = helpOption;
|
2010-08-02 16:32:18 +02:00
|
|
|
manager->setCustomValue(QLatin1String("ContextHelpOption"), helpOption);
|
2010-07-23 16:36:08 +02:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2010-07-23 16:36:08 +02:00
|
|
|
settings->beginGroup(Help::Constants::ID_MODE_HELP);
|
|
|
|
|
settings->setValue(QLatin1String("ContextHelpOption"), helpOption);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
|
|
emit contextHelpOptionChanged();
|
|
|
|
|
}
|
2010-09-21 17:00:41 +02:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
const bool close = m_ui->m_returnOnClose->isChecked();
|
2010-09-21 17:00:41 +02:00
|
|
|
if (m_returnOnClose != close) {
|
|
|
|
|
m_returnOnClose = close;
|
|
|
|
|
manager->setCustomValue(QLatin1String("ReturnOnClose"), close);
|
|
|
|
|
emit returnOnCloseChanged();
|
|
|
|
|
}
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-26 16:50:50 +02:00
|
|
|
void GeneralSettingsPage::setCurrentPage()
|
|
|
|
|
{
|
2010-03-16 14:47:27 +01:00
|
|
|
HelpViewer *viewer = CentralWidget::instance()->currentHelpViewer();
|
2009-06-26 16:50:50 +02:00
|
|
|
if (viewer)
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->homePageLineEdit->setText(viewer->source().toString());
|
2009-06-26 16:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettingsPage::setBlankPage()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->homePageLineEdit->setText(Help::Constants::AboutBlank);
|
2009-06-26 16:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettingsPage::setDefaultPage()
|
|
|
|
|
{
|
2010-08-02 16:32:18 +02:00
|
|
|
const QString &defaultHomePage = Core::HelpManager::instance()
|
|
|
|
|
->customValue(QLatin1String("DefaultHomePage"), QString()).toString();
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->homePageLineEdit->setText(defaultHomePage);
|
2009-06-26 16:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-08 15:03:40 +02:00
|
|
|
void GeneralSettingsPage::importBookmarks()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->errorLabel->setVisible(false);
|
2009-07-08 15:03:40 +02:00
|
|
|
|
2010-09-01 10:32:28 +02:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(0, tr("Import Bookmarks"),
|
2009-07-08 15:03:40 +02:00
|
|
|
QDir::currentPath(), tr("Files (*.xbel)"));
|
|
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QFile file(fileName);
|
|
|
|
|
if (file.open(QIODevice::ReadOnly)) {
|
2010-06-11 13:11:37 +02:00
|
|
|
const BookmarkManager &manager = LocalHelpManager::bookmarkManager();
|
2010-03-23 18:11:43 +01:00
|
|
|
XbelReader reader(manager.treeBookmarkModel(), manager.listBookmarkModel());
|
2009-07-08 15:03:40 +02:00
|
|
|
if (reader.readFromFile(&file))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->errorLabel->setVisible(true);
|
2011-06-21 17:07:45 +02:00
|
|
|
m_ui->errorLabel->setText(tr("Cannot import bookmarks."));
|
2009-07-08 15:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettingsPage::exportBookmarks()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->errorLabel->setVisible(false);
|
2009-07-08 15:03:40 +02:00
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(0, tr("Save File"),
|
|
|
|
|
"untitled.xbel", tr("Files (*.xbel)"));
|
|
|
|
|
|
|
|
|
|
QLatin1String suffix(".xbel");
|
|
|
|
|
if (!fileName.endsWith(suffix))
|
|
|
|
|
fileName.append(suffix);
|
|
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileSaver saver(fileName);
|
|
|
|
|
if (!saver.hasError()) {
|
2010-06-11 13:11:37 +02:00
|
|
|
XbelWriter writer(LocalHelpManager::bookmarkManager().treeBookmarkModel());
|
2011-03-30 15:15:15 +02:00
|
|
|
writer.writeToFile(saver.file());
|
|
|
|
|
saver.setResult(&writer);
|
|
|
|
|
}
|
|
|
|
|
if (!saver.finalize()) {
|
|
|
|
|
m_ui->errorLabel->setVisible(true);
|
|
|
|
|
m_ui->errorLabel->setText(saver.errorString());
|
2009-07-08 15:03:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 17:16:16 +02:00
|
|
|
void GeneralSettingsPage::updateFontSize()
|
|
|
|
|
{
|
2010-03-16 14:47:27 +01:00
|
|
|
const QString &family = m_font.family();
|
|
|
|
|
const QString &fontStyle = m_fontDatabase.styleString(m_font);
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2010-03-16 14:47:27 +01:00
|
|
|
QList<int> pointSizes = m_fontDatabase.pointSizes(family, fontStyle);
|
2009-06-25 17:16:16 +02:00
|
|
|
if (pointSizes.empty())
|
|
|
|
|
pointSizes = QFontDatabase::standardSizes();
|
|
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->sizeComboBox->clear();
|
|
|
|
|
m_ui->sizeComboBox->setCurrentIndex(-1);
|
|
|
|
|
m_ui->sizeComboBox->setEnabled(!pointSizes.empty());
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
// try to maintain selection or select closest.
|
|
|
|
|
if (!pointSizes.empty()) {
|
|
|
|
|
QString n;
|
|
|
|
|
foreach (int pointSize, pointSizes)
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->sizeComboBox->addItem(n.setNum(pointSize), QVariant(pointSize));
|
2010-03-16 14:47:27 +01:00
|
|
|
const int closestIndex = closestPointSizeIndex(m_font.pointSize());
|
2009-06-25 17:16:16 +02:00
|
|
|
if (closestIndex != -1)
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->sizeComboBox->setCurrentIndex(closestIndex);
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettingsPage::updateFontStyle()
|
|
|
|
|
{
|
2010-03-16 14:47:27 +01:00
|
|
|
const QString &fontStyle = m_fontDatabase.styleString(m_font);
|
|
|
|
|
const QStringList &styles = m_fontDatabase.styles(m_font.family());
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->styleComboBox->clear();
|
|
|
|
|
m_ui->styleComboBox->setCurrentIndex(-1);
|
|
|
|
|
m_ui->styleComboBox->setEnabled(!styles.empty());
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
if (!styles.empty()) {
|
|
|
|
|
int normalIndex = -1;
|
|
|
|
|
const QString normalStyle = QLatin1String("Normal");
|
|
|
|
|
foreach (const QString &style, styles) {
|
|
|
|
|
// try to maintain selection or select 'normal' preferably
|
2010-12-02 18:28:16 +01:00
|
|
|
const int newIndex = m_ui->styleComboBox->count();
|
|
|
|
|
m_ui->styleComboBox->addItem(style);
|
2009-06-25 17:16:16 +02:00
|
|
|
if (fontStyle == style) {
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->styleComboBox->setCurrentIndex(newIndex);
|
2009-06-25 17:16:16 +02:00
|
|
|
} else {
|
|
|
|
|
if (fontStyle == normalStyle)
|
|
|
|
|
normalIndex = newIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
if (m_ui->styleComboBox->currentIndex() == -1 && normalIndex != -1)
|
|
|
|
|
m_ui->styleComboBox->setCurrentIndex(normalIndex);
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettingsPage::updateFontFamily()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->familyComboBox->setCurrentFont(m_font);
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GeneralSettingsPage::closestPointSizeIndex(int desiredPointSize) const
|
|
|
|
|
{
|
|
|
|
|
// try to maintain selection or select closest.
|
|
|
|
|
int closestIndex = -1;
|
|
|
|
|
int closestAbsError = 0xFFFF;
|
|
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
const int pointSizeCount = m_ui->sizeComboBox->count();
|
2009-06-25 17:16:16 +02:00
|
|
|
for (int i = 0; i < pointSizeCount; i++) {
|
2010-12-02 18:28:16 +01:00
|
|
|
const int itemPointSize = m_ui->sizeComboBox->itemData(i).toInt();
|
2009-06-25 17:16:16 +02:00
|
|
|
const int absError = qAbs(desiredPointSize - itemPointSize);
|
|
|
|
|
if (absError < closestAbsError) {
|
|
|
|
|
closestIndex = i;
|
|
|
|
|
closestAbsError = absError;
|
|
|
|
|
if (closestAbsError == 0)
|
|
|
|
|
break;
|
|
|
|
|
} else { // past optimum
|
|
|
|
|
if (absError > closestAbsError) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return closestIndex;
|
|
|
|
|
}
|
2009-11-24 15:05:02 +01:00
|
|
|
|
|
|
|
|
bool GeneralSettingsPage::matches(const QString &s) const
|
|
|
|
|
{
|
|
|
|
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
|
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
|
|
|
|
|
void GeneralSettingsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
if (!m_ui) // page was never shown
|
|
|
|
|
return;
|
|
|
|
|
delete m_ui;
|
|
|
|
|
m_ui = 0;
|
|
|
|
|
}
|