2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "texteditorsettings.h"
|
2009-11-27 16:12:12 +01:00
|
|
|
#include "texteditorconstants.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-17 18:17:51 +01:00
|
|
|
#include "basetexteditor.h"
|
2009-12-08 17:37:40 +01:00
|
|
|
#include "behaviorsettings.h"
|
2009-01-27 15:12:32 +01:00
|
|
|
#include "behaviorsettingspage.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "displaysettings.h"
|
2009-01-27 15:12:32 +01:00
|
|
|
#include "displaysettingspage.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fontsettingspage.h"
|
|
|
|
|
#include "storagesettings.h"
|
|
|
|
|
#include "tabsettings.h"
|
|
|
|
|
#include "texteditorplugin.h"
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtGui/QApplication>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace TextEditor::Constants;
|
|
|
|
|
|
|
|
|
|
TextEditorSettings *TextEditorSettings::m_instance = 0;
|
|
|
|
|
|
2009-01-23 19:13:00 +01:00
|
|
|
TextEditorSettings::TextEditorSettings(QObject *parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(!m_instance, return);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_instance = this;
|
|
|
|
|
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
|
|
|
|
|
|
// Note: default background colors are coming from FormatDescription::background()
|
|
|
|
|
|
|
|
|
|
// Add font preference page
|
|
|
|
|
FormatDescriptions formatDescriptions;
|
2009-07-14 08:50:27 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_TEXT), tr("Text")));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Special categories
|
|
|
|
|
const QPalette p = QApplication::palette();
|
2009-07-14 08:50:27 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_LINK), tr("Link"), Qt::blue));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_SELECTION), tr("Selection"), p.color(QPalette::HighlightedText)));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_LINE_NUMBER), tr("Line Number")));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_SEARCH_RESULT), tr("Search Result")));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_SEARCH_SCOPE), tr("Search Scope")));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_PARENTHESES), tr("Parentheses")));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_CURRENT_LINE), tr("Current Line")));
|
2009-06-12 15:28:51 +02:00
|
|
|
|
|
|
|
|
FormatDescription currentLineNumber = FormatDescription(QLatin1String(C_CURRENT_LINE_NUMBER), tr("Current Line Number"), Qt::darkGray);
|
|
|
|
|
currentLineNumber.format().setBold(true);
|
2009-07-14 08:50:27 +02:00
|
|
|
formatDescriptions.append(currentLineNumber);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-14 10:34:17 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_OCCURRENCES), tr("Occurrences")));
|
2009-09-23 18:06:59 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_OCCURRENCES_UNUSED), tr("Unused Occurrence")));
|
2009-07-14 10:34:17 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_OCCURRENCES_RENAME), tr("Renaming Occurrence")));
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Standard categories
|
2009-07-14 08:50:27 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_NUMBER), tr("Number"), Qt::darkBlue));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_STRING), tr("String"), Qt::darkGreen));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_TYPE), tr("Type"), Qt::darkMagenta));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_KEYWORD), tr("Keyword"), Qt::darkYellow));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_OPERATOR), tr("Operator")));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_PREPROCESSOR), tr("Preprocessor"), Qt::darkBlue));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_LABEL), tr("Label"), Qt::darkRed));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_COMMENT), tr("Comment"), Qt::darkGreen));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_COMMENT), tr("Doxygen Comment"), Qt::darkBlue));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_TAG), tr("Doxygen Tag"), Qt::blue));
|
2009-10-01 13:34:02 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_VISUAL_WHITESPACE), tr("Visual Whitespace"), Qt::lightGray));
|
2009-10-08 12:57:26 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DISABLED_CODE), tr("Disabled Code")));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Diff categories
|
2009-07-14 08:50:27 +02:00
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_ADDED_LINE), tr("Added Line"), QColor(0, 170, 0)));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_REMOVED_LINE), tr("Removed Line"), Qt::red));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_FILE), tr("Diff File"), Qt::darkBlue));
|
|
|
|
|
formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_LOCATION), tr("Diff Location"), Qt::blue));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_fontSettingsPage = new FontSettingsPage(formatDescriptions,
|
2009-11-27 16:12:12 +01:00
|
|
|
QLatin1String("A.FontSettings"),
|
2010-04-12 15:53:17 +02:00
|
|
|
this);
|
2008-12-02 12:01:29 +01:00
|
|
|
pm->addObject(m_fontSettingsPage);
|
|
|
|
|
|
2009-01-27 15:12:32 +01:00
|
|
|
// Add the GUI used to configure the tab, storage and interaction settings
|
|
|
|
|
TextEditor::BehaviorSettingsPageParameters behaviorSettingsPageParameters;
|
2009-11-27 16:12:12 +01:00
|
|
|
behaviorSettingsPageParameters.id = QLatin1String("B.BehaviourSettings");
|
2010-01-07 18:17:24 +01:00
|
|
|
behaviorSettingsPageParameters.displayName = tr("Behavior");
|
2009-01-27 15:12:32 +01:00
|
|
|
behaviorSettingsPageParameters.settingsPrefix = QLatin1String("text");
|
|
|
|
|
m_behaviorSettingsPage = new BehaviorSettingsPage(behaviorSettingsPageParameters, this);
|
|
|
|
|
pm->addObject(m_behaviorSettingsPage);
|
|
|
|
|
|
|
|
|
|
TextEditor::DisplaySettingsPageParameters displaySettingsPageParameters;
|
2009-11-27 16:12:12 +01:00
|
|
|
displaySettingsPageParameters.id = QLatin1String("D.DisplaySettings"),
|
2010-01-07 18:17:24 +01:00
|
|
|
displaySettingsPageParameters.displayName = tr("Display");
|
2009-01-27 15:12:32 +01:00
|
|
|
displaySettingsPageParameters.settingsPrefix = QLatin1String("text");
|
|
|
|
|
m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
|
|
|
|
|
pm->addObject(m_displaySettingsPage);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
|
|
|
|
|
this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
|
2009-01-27 15:12:32 +01:00
|
|
|
connect(m_behaviorSettingsPage, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
|
2008-12-02 12:01:29 +01:00
|
|
|
this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)));
|
2009-01-27 15:12:32 +01:00
|
|
|
connect(m_behaviorSettingsPage, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
|
2008-12-02 12:01:29 +01:00
|
|
|
this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)));
|
2009-12-08 17:37:40 +01:00
|
|
|
connect(m_behaviorSettingsPage, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
|
|
|
|
|
this, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)));
|
2009-01-27 15:12:32 +01:00
|
|
|
connect(m_displaySettingsPage, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
|
2008-12-02 12:01:29 +01:00
|
|
|
this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditorSettings::~TextEditorSettings()
|
|
|
|
|
{
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
|
pm->removeObject(m_fontSettingsPage);
|
2009-01-27 15:12:32 +01:00
|
|
|
pm->removeObject(m_behaviorSettingsPage);
|
|
|
|
|
pm->removeObject(m_displaySettingsPage);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditorSettings *TextEditorSettings::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-17 18:17:51 +01:00
|
|
|
/**
|
|
|
|
|
* Initializes editor settings. Also connects signals to keep them up to date
|
|
|
|
|
* when they are changed.
|
|
|
|
|
*/
|
|
|
|
|
void TextEditorSettings::initializeEditor(BaseTextEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
// Connect to settings change signals
|
|
|
|
|
connect(this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
|
2009-09-23 18:06:59 +02:00
|
|
|
editor, SLOT(setFontSettingsIfVisible(TextEditor::FontSettings)));
|
2009-03-17 18:17:51 +01:00
|
|
|
connect(this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
|
|
|
|
|
editor, SLOT(setTabSettings(TextEditor::TabSettings)));
|
|
|
|
|
connect(this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
|
|
|
|
|
editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
|
2009-12-08 17:37:40 +01:00
|
|
|
connect(this, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
|
|
|
|
|
editor, SLOT(setBehaviorSettings(TextEditor::BehaviorSettings)));
|
2009-03-17 18:17:51 +01:00
|
|
|
connect(this, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
|
|
|
|
|
editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings)));
|
|
|
|
|
|
2009-11-30 19:00:36 +01:00
|
|
|
connect(editor, SIGNAL(requestFontZoom(int)),
|
|
|
|
|
this, SLOT(fontZoomRequested(int)));
|
|
|
|
|
connect(editor, SIGNAL(requestZoomReset()),
|
|
|
|
|
this, SLOT(zoomResetRequested()));
|
2009-06-17 19:12:19 +02:00
|
|
|
|
2009-03-17 18:17:51 +01:00
|
|
|
// Apply current settings (tab settings depend on font settings)
|
|
|
|
|
editor->setFontSettings(fontSettings());
|
|
|
|
|
editor->setTabSettings(tabSettings());
|
|
|
|
|
editor->setStorageSettings(storageSettings());
|
2009-12-08 17:37:40 +01:00
|
|
|
editor->setBehaviorSettings(behaviorSettings());
|
2009-03-17 18:17:51 +01:00
|
|
|
editor->setDisplaySettings(displaySettings());
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 19:12:19 +02:00
|
|
|
|
2009-11-30 19:00:36 +01:00
|
|
|
void TextEditorSettings::fontZoomRequested(int zoom)
|
2009-06-17 19:12:19 +02:00
|
|
|
{
|
2010-01-20 11:27:08 +01:00
|
|
|
FontSettings &fs = const_cast<FontSettings&>(fontSettings());
|
2009-11-30 19:00:36 +01:00
|
|
|
fs.setFontZoom(qMax(10, fs.fontZoom() + zoom));
|
|
|
|
|
m_fontSettingsPage->saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextEditorSettings::zoomResetRequested()
|
|
|
|
|
{
|
2010-01-20 11:27:08 +01:00
|
|
|
FontSettings &fs = const_cast<FontSettings&>(fontSettings());
|
2009-11-30 19:00:36 +01:00
|
|
|
fs.setFontZoom(100);
|
2009-06-18 16:12:24 +02:00
|
|
|
m_fontSettingsPage->saveSettings();
|
2009-06-17 19:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const FontSettings &TextEditorSettings::fontSettings() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_fontSettingsPage->fontSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const TabSettings &TextEditorSettings::tabSettings() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-27 15:12:32 +01:00
|
|
|
return m_behaviorSettingsPage->tabSettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const StorageSettings &TextEditorSettings::storageSettings() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-27 15:12:32 +01:00
|
|
|
return m_behaviorSettingsPage->storageSettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const BehaviorSettings &TextEditorSettings::behaviorSettings() const
|
2009-12-08 17:37:40 +01:00
|
|
|
{
|
|
|
|
|
return m_behaviorSettingsPage->behaviorSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const DisplaySettings &TextEditorSettings::displaySettings() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-27 15:12:32 +01:00
|
|
|
return m_displaySettingsPage->displaySettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|