OSDN Git Service

6d8a4194e4670eb9e012db9c60cab4a10895a1d8
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / editorsettingspropertiespage.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "editorsettingspropertiespage.h"
35 #include "editorconfiguration.h"
36 #include "project.h"
37
38 #include <QtCore/QTextCodec>
39
40 using namespace ProjectExplorer;
41 using namespace ProjectExplorer::Internal;
42
43 QString EditorSettingsPanelFactory::id() const
44 {
45     return QLatin1String(EDITORSETTINGS_PANEL_ID);
46 }
47
48 QString EditorSettingsPanelFactory::displayName() const
49 {
50     return QCoreApplication::translate("EditorSettingsPanelFactory", "Editor Settings");
51 }
52
53 bool EditorSettingsPanelFactory::supports(Project *project)
54 {
55     Q_UNUSED(project);
56     return true;
57 }
58
59 IPropertiesPanel *EditorSettingsPanelFactory::createPanel(Project *project)
60 {
61     return new EditorSettingsPanel(project);
62 }
63
64 EditorSettingsPanel::EditorSettingsPanel(Project *project) :
65     m_widget(new EditorSettingsWidget(project)),
66     m_icon(":/projectexplorer/images/EditorSettings.png")
67 {
68 }
69
70 EditorSettingsPanel::~EditorSettingsPanel()
71 {
72     delete m_widget;
73 }
74
75 QString EditorSettingsPanel::displayName() const
76 {
77     return QCoreApplication::translate("EditorSettingsPanel", "Editor Settings");
78 }
79
80 QWidget *EditorSettingsPanel::widget() const
81 {
82     return m_widget;
83 }
84
85 QIcon EditorSettingsPanel::icon() const
86 {
87     return m_icon;
88 }
89
90 EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_project(project)
91 {
92     m_ui.setupUi(this);
93
94     const EditorConfiguration *config = m_project->editorConfiguration();
95     settingsToUi(config);
96
97     setGlobalSettingsEnabled(config->useGlobalSettings());
98
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*)));
138 }
139
140 void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
141 {
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());
148 }
149
150 void EditorSettingsWidget::setGlobalSettingsEnabled(bool enabled)
151 {
152     m_ui.behaviorSettingsWidget->setActive(!enabled);
153     m_ui.restoreButton->setEnabled(!enabled);
154 }
155
156 void EditorSettingsWidget::restoreDefaultValues()
157 {
158     EditorConfiguration *config = m_project->editorConfiguration();
159     config->cloneGlobalSettings();
160     settingsToUi(config);
161 }