1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "editorsettingspropertiespage.h"
35 #include "editorconfiguration.h"
38 #include <QtCore/QTextCodec>
40 using namespace ProjectExplorer;
41 using namespace ProjectExplorer::Internal;
43 QString EditorSettingsPanelFactory::id() const
45 return QLatin1String(EDITORSETTINGS_PANEL_ID);
48 QString EditorSettingsPanelFactory::displayName() const
50 return QCoreApplication::translate("EditorSettingsPanelFactory", "Editor Settings");
53 bool EditorSettingsPanelFactory::supports(Project *project)
59 IPropertiesPanel *EditorSettingsPanelFactory::createPanel(Project *project)
61 return new EditorSettingsPanel(project);
64 EditorSettingsPanel::EditorSettingsPanel(Project *project) :
65 m_widget(new EditorSettingsWidget(project)),
66 m_icon(":/projectexplorer/images/EditorSettings.png")
70 EditorSettingsPanel::~EditorSettingsPanel()
75 QString EditorSettingsPanel::displayName() const
77 return QCoreApplication::translate("EditorSettingsPanel", "Editor Settings");
80 QWidget *EditorSettingsPanel::widget() const
85 QIcon EditorSettingsPanel::icon() const
90 EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_project(project)
94 const EditorConfiguration *config = m_project->editorConfiguration();
97 setGlobalSettingsEnabled(config->useGlobalSettings());
99 connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)),
100 this, SLOT(setGlobalSettingsEnabled(bool)));
101 connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)),
102 config, SLOT(setUseGlobalSettings(bool)));
103 connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues()));
104 connect(m_ui.behaviorSettingsWidget, SIGNAL(insertSpacesChanged(bool)),
105 config, SLOT(setInsertSpaces(bool)));
106 connect(m_ui.behaviorSettingsWidget, SIGNAL(autoInsertSpacesChanged(bool)),
107 config, SLOT(setAutoInsertSpaces(bool)));
108 connect(m_ui.behaviorSettingsWidget, SIGNAL(autoIndentChanged(bool)),
109 config, SLOT(setAutoIndent(bool)));
110 connect(m_ui.behaviorSettingsWidget, SIGNAL(smartBackSpaceChanged(bool)),
111 config, SLOT(setSmartBackSpace(bool)));
112 connect(m_ui.behaviorSettingsWidget, SIGNAL(tabSizeChanged(int)),
113 config, SLOT(setTabSize(int)));
114 connect(m_ui.behaviorSettingsWidget, SIGNAL(indentSizeChanged(int)),
115 config, SLOT(setIndentSize(int)));
116 connect(m_ui.behaviorSettingsWidget, SIGNAL(indentBlocksBehaviorChanged(int)),
117 config, SLOT(setIndentBlocksBehavior(int)));
118 connect(m_ui.behaviorSettingsWidget, SIGNAL(tabKeyBehaviorChanged(int)),
119 config, SLOT(setTabKeyBehavior(int)));
120 connect(m_ui.behaviorSettingsWidget, SIGNAL(continuationAlignBehaviorChanged(int)),
121 config, SLOT(setContinuationAlignBehavior(int)));
122 connect(m_ui.behaviorSettingsWidget, SIGNAL(cleanWhiteSpaceChanged(bool)),
123 config, SLOT(setCleanWhiteSpace(bool)));
124 connect(m_ui.behaviorSettingsWidget, SIGNAL(inEntireDocumentChanged(bool)),
125 config, SLOT(setInEntireDocument(bool)));
126 connect(m_ui.behaviorSettingsWidget, SIGNAL(addFinalNewLineChanged(bool)),
127 config, SLOT(setAddFinalNewLine(bool)));
128 connect(m_ui.behaviorSettingsWidget, SIGNAL(cleanIndentationChanged(bool)),
129 config, SLOT(setCleanIndentation(bool)));
130 connect(m_ui.behaviorSettingsWidget, SIGNAL(mouseNavigationChanged(bool)),
131 config, SLOT(setMouseNavigation(bool)));
132 connect(m_ui.behaviorSettingsWidget, SIGNAL(scrollWheelZoomingChanged(bool)),
133 config, SLOT(setScrollWheelZooming(bool)));
134 connect(m_ui.behaviorSettingsWidget, SIGNAL(utf8BomSettingsChanged(int)),
135 config, SLOT(setUtf8BomSettings(int)));
136 connect(m_ui.behaviorSettingsWidget, SIGNAL(textCodecChanged(QTextCodec*)),
137 config, SLOT(setTextCodec(QTextCodec*)));
140 void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
142 m_ui.useGlobalCheckBox->setChecked(config->useGlobalSettings());
143 m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec());
144 m_ui.behaviorSettingsWidget->setAssignedTabSettings(config->tabSettings());
145 m_ui.behaviorSettingsWidget->setAssignedStorageSettings(config->storageSettings());
146 m_ui.behaviorSettingsWidget->setAssignedBehaviorSettings(config->behaviorSettings());
147 m_ui.behaviorSettingsWidget->setAssignedExtraEncodingSettings(config->extraEncodingSettings());
150 void EditorSettingsWidget::setGlobalSettingsEnabled(bool enabled)
152 m_ui.behaviorSettingsWidget->setActive(!enabled);
153 m_ui.restoreButton->setEnabled(!enabled);
156 void EditorSettingsWidget::restoreDefaultValues()
158 EditorConfiguration *config = m_project->editorConfiguration();
159 config->cloneGlobalSettings();
160 settingsToUi(config);