2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-06-25 17:16:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-06-25 17:16:16 +02:00
|
|
|
|
|
|
|
|
#include "generalsettingspage.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
|
|
|
|
2013-09-02 14:04:12 +02:00
|
|
|
#include <bookmarkmanager.h>
|
|
|
|
|
|
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
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
using namespace Core;
|
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
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId("A.General settings");
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayName(tr("General"));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(Help::Constants::HELP_CATEGORY);
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayCategory(QCoreApplication::translate("Help", Help::Constants::HELP_TR_CATEGORY));
|
2016-07-20 10:11:35 +02:00
|
|
|
setCategoryIcon(Help::Constants::HELP_CATEGORY_ICON);
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *GeneralSettingsPage::widget()
|
2009-06-25 17:16:16 +02:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
|
|
|
|
m_widget = new QWidget;
|
|
|
|
|
m_ui = new Ui::GeneralSettingsPage;
|
|
|
|
|
m_ui->setupUi(m_widget);
|
|
|
|
|
m_ui->sizeComboBox->setEditable(false);
|
|
|
|
|
m_ui->styleComboBox->setEditable(false);
|
|
|
|
|
|
2015-04-02 16:49:04 +02:00
|
|
|
m_font = LocalHelpManager::fallbackFont();
|
2013-12-03 14:17:03 +01:00
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
updateFontSizeSelector();
|
|
|
|
|
updateFontStyleSelector();
|
|
|
|
|
updateFontFamilySelector();
|
|
|
|
|
|
|
|
|
|
connect(m_ui->familyComboBox, &QFontComboBox::currentFontChanged, this, [this]() {
|
|
|
|
|
updateFont();
|
|
|
|
|
updateFontStyleSelector();
|
|
|
|
|
updateFontSizeSelector();
|
|
|
|
|
updateFont(); // changes that might have happened when updating the selectors
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_ui->styleComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, [this]() {
|
|
|
|
|
updateFont();
|
|
|
|
|
updateFontSizeSelector();
|
|
|
|
|
updateFont(); // changes that might have happened when updating the selectors
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_ui->sizeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &GeneralSettingsPage::updateFont);
|
2013-12-03 14:17:03 +01:00
|
|
|
|
2014-10-22 14:47:04 +02:00
|
|
|
m_homePage = LocalHelpManager::homePage();
|
2013-12-03 14:17:03 +01:00
|
|
|
m_ui->homePageLineEdit->setText(m_homePage);
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2015-04-02 16:49:04 +02:00
|
|
|
m_startOption = LocalHelpManager::startOption();
|
2013-12-03 14:17:03 +01:00
|
|
|
m_ui->helpStartComboBox->setCurrentIndex(m_startOption);
|
2009-07-14 13:20:26 +02:00
|
|
|
|
2015-04-02 16:49:04 +02:00
|
|
|
m_contextOption = LocalHelpManager::contextHelpOption();
|
2013-12-03 14:17:03 +01:00
|
|
|
m_ui->contextHelpComboBox->setCurrentIndex(m_contextOption);
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2015-01-29 14:32:36 +01:00
|
|
|
connect(m_ui->currentPageButton, &QPushButton::clicked,
|
|
|
|
|
this, &GeneralSettingsPage::setCurrentPage);
|
|
|
|
|
connect(m_ui->blankPageButton, &QPushButton::clicked,
|
|
|
|
|
this, &GeneralSettingsPage::setBlankPage);
|
|
|
|
|
connect(m_ui->defaultPageButton, &QPushButton::clicked,
|
|
|
|
|
this, &GeneralSettingsPage::setDefaultPage);
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2014-09-25 16:29:56 +02:00
|
|
|
HelpViewer *viewer = CentralWidget::instance()->currentViewer();
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!viewer)
|
|
|
|
|
m_ui->currentPageButton->setEnabled(false);
|
2009-06-26 16:50:50 +02:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
m_ui->errorLabel->setVisible(false);
|
2015-01-29 14:32:36 +01:00
|
|
|
connect(m_ui->importButton, &QPushButton::clicked,
|
|
|
|
|
this, &GeneralSettingsPage::importBookmarks);
|
|
|
|
|
connect(m_ui->exportButton, &QPushButton::clicked,
|
|
|
|
|
this, &GeneralSettingsPage::exportBookmarks);
|
2009-07-08 15:03:40 +02:00
|
|
|
|
2015-04-02 16:49:04 +02:00
|
|
|
m_returnOnClose = LocalHelpManager::returnOnClose();
|
2013-12-03 14:17:03 +01:00
|
|
|
m_ui->m_returnOnClose->setChecked(m_returnOnClose);
|
2009-11-24 15:05:02 +01:00
|
|
|
}
|
2013-12-03 14:17:03 +01:00
|
|
|
return m_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;
|
2009-06-25 17:16:16 +02:00
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
if (m_font != LocalHelpManager::fallbackFont()) {
|
|
|
|
|
LocalHelpManager::setFallbackFont(m_font);
|
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;
|
2014-10-22 14:47:04 +02:00
|
|
|
LocalHelpManager::setHomePage(homePage);
|
2012-05-24 16:19:44 +02:00
|
|
|
}
|
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;
|
2015-04-02 16:49:04 +02:00
|
|
|
LocalHelpManager::setStartOption((LocalHelpManager::StartOption)m_startOption);
|
2012-05-24 16:19:44 +02:00
|
|
|
}
|
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;
|
2015-04-02 16:49:04 +02:00
|
|
|
LocalHelpManager::setContextHelpOption((HelpManager::HelpViewerLocation)m_contextOption);
|
2010-07-23 16:36:08 +02:00
|
|
|
}
|
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;
|
2015-04-02 16:49:04 +02:00
|
|
|
LocalHelpManager::setReturnOnClose(m_returnOnClose);
|
2010-09-21 17:00:41 +02:00
|
|
|
}
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-26 16:50:50 +02:00
|
|
|
void GeneralSettingsPage::setCurrentPage()
|
|
|
|
|
{
|
2014-09-25 16:29:56 +02:00
|
|
|
HelpViewer *viewer = CentralWidget::instance()->currentViewer();
|
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()
|
|
|
|
|
{
|
2014-10-22 14:47:04 +02:00
|
|
|
m_ui->homePageLineEdit->setText(LocalHelpManager::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
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(ICore::dialogParent(),
|
2014-01-30 16:37:21 +01:00
|
|
|
tr("Import Bookmarks"), QDir::currentPath(), tr("Files (*.xbel)"));
|
2009-07-08 15:03:40 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(ICore::dialogParent(),
|
2016-07-20 10:11:35 +02:00
|
|
|
tr("Save File"), "untitled.xbel", tr("Files (*.xbel)"));
|
2009-07-08 15:03:40 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
void GeneralSettingsPage::updateFontSizeSelector()
|
2009-06-25 17:16:16 +02:00
|
|
|
{
|
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();
|
|
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
bool blocked = m_ui->sizeComboBox->blockSignals(true);
|
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
|
|
|
}
|
2016-07-19 14:16:22 +02:00
|
|
|
m_ui->sizeComboBox->blockSignals(blocked);
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
void GeneralSettingsPage::updateFontStyleSelector()
|
2009-06-25 17:16:16 +02:00
|
|
|
{
|
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
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
bool blocked = m_ui->styleComboBox->blockSignals(true);
|
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;
|
2016-07-20 10:11:35 +02:00
|
|
|
const QString normalStyle = "Normal";
|
2009-06-25 17:16:16 +02:00
|
|
|
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
|
|
|
}
|
2016-07-19 14:16:22 +02:00
|
|
|
m_ui->styleComboBox->blockSignals(blocked);
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
void GeneralSettingsPage::updateFontFamilySelector()
|
2009-06-25 17:16:16 +02:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
m_ui->familyComboBox->setCurrentFont(m_font);
|
2009-06-25 17:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-19 14:16:22 +02:00
|
|
|
void GeneralSettingsPage::updateFont()
|
|
|
|
|
{
|
|
|
|
|
const QString &family = m_ui->familyComboBox->currentFont().family();
|
|
|
|
|
m_font.setFamily(family);
|
|
|
|
|
|
|
|
|
|
int fontSize = 14;
|
|
|
|
|
int currentIndex = m_ui->sizeComboBox->currentIndex();
|
|
|
|
|
if (currentIndex != -1)
|
|
|
|
|
fontSize = m_ui->sizeComboBox->itemData(currentIndex).toInt();
|
|
|
|
|
m_font.setPointSize(fontSize);
|
|
|
|
|
|
2016-07-20 10:11:35 +02:00
|
|
|
QString fontStyle = "Normal";
|
2016-07-19 14:16:22 +02:00
|
|
|
currentIndex = m_ui->styleComboBox->currentIndex();
|
|
|
|
|
if (currentIndex != -1)
|
|
|
|
|
fontStyle = m_ui->styleComboBox->itemText(currentIndex);
|
|
|
|
|
m_font.setBold(m_fontDatabase.bold(family, fontStyle));
|
2016-07-20 10:11:35 +02:00
|
|
|
if (fontStyle.contains("Italic"))
|
2016-07-19 14:16:22 +02:00
|
|
|
m_font.setStyle(QFont::StyleItalic);
|
2016-07-20 10:11:35 +02:00
|
|
|
else if (fontStyle.contains("Oblique"))
|
2016-07-19 14:16:22 +02:00
|
|
|
m_font.setStyle(QFont::StyleOblique);
|
|
|
|
|
else
|
|
|
|
|
m_font.setStyle(QFont::StyleNormal);
|
|
|
|
|
|
|
|
|
|
const int weight = m_fontDatabase.weight(family, fontStyle);
|
|
|
|
|
if (weight >= 0) // Weight < 0 asserts...
|
|
|
|
|
m_font.setWeight(weight);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (absError > closestAbsError)
|
2009-06-25 17:16:16 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return closestIndex;
|
|
|
|
|
}
|
2009-11-24 15:05:02 +01:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
void GeneralSettingsPage::finish()
|
|
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete m_widget;
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_ui) // page was never shown
|
|
|
|
|
return;
|
|
|
|
|
delete m_ui;
|
|
|
|
|
m_ui = 0;
|
|
|
|
|
}
|