1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "simplecodestylepreferenceswidget.h"
27 #include "icodestylepreferences.h"
28 #include "tabsettings.h"
29 #include "tabsettingswidget.h"
30
31 #include <QVBoxLayout>
32
33 namespace TextEditor {
34
SimpleCodeStylePreferencesWidget(QWidget * parent)35 SimpleCodeStylePreferencesWidget::SimpleCodeStylePreferencesWidget(QWidget *parent) :
36 QWidget(parent)
37 {
38 m_tabSettingsWidget = new TabSettingsWidget(this);
39 auto layout = new QVBoxLayout(this);
40 layout->addWidget(m_tabSettingsWidget);
41 layout->setContentsMargins(QMargins());
42 m_tabSettingsWidget->setEnabled(false);
43 }
44
setPreferences(ICodeStylePreferences * preferences)45 void SimpleCodeStylePreferencesWidget::setPreferences(ICodeStylePreferences *preferences)
46 {
47 if (m_preferences == preferences)
48 return; // nothing changes
49
50 // cleanup old
51 if (m_preferences) {
52 disconnect(m_preferences, &ICodeStylePreferences::currentTabSettingsChanged,
53 m_tabSettingsWidget, &TabSettingsWidget::setTabSettings);
54 disconnect(m_preferences, &ICodeStylePreferences::currentPreferencesChanged,
55 this, &SimpleCodeStylePreferencesWidget::slotCurrentPreferencesChanged);
56 disconnect(m_tabSettingsWidget, &TabSettingsWidget::settingsChanged,
57 this, &SimpleCodeStylePreferencesWidget::slotTabSettingsChanged);
58 }
59 m_preferences = preferences;
60 // fillup new
61 if (m_preferences) {
62 slotCurrentPreferencesChanged(m_preferences->currentPreferences());
63 m_tabSettingsWidget->setTabSettings(m_preferences->currentTabSettings());
64
65 connect(m_preferences, &ICodeStylePreferences::currentTabSettingsChanged,
66 m_tabSettingsWidget, &TabSettingsWidget::setTabSettings);
67 connect(m_preferences, &ICodeStylePreferences::currentPreferencesChanged,
68 this, &SimpleCodeStylePreferencesWidget::slotCurrentPreferencesChanged);
69 connect(m_tabSettingsWidget, &TabSettingsWidget::settingsChanged,
70 this, &SimpleCodeStylePreferencesWidget::slotTabSettingsChanged);
71 }
72 m_tabSettingsWidget->setEnabled(m_preferences);
73 }
74
slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences * preferences)75 void SimpleCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *preferences)
76 {
77 m_tabSettingsWidget->setEnabled(!preferences->isReadOnly() && !m_preferences->currentDelegate());
78 }
79
slotTabSettingsChanged(const TextEditor::TabSettings & settings)80 void SimpleCodeStylePreferencesWidget::slotTabSettingsChanged(const TextEditor::TabSettings &settings)
81 {
82 if (!m_preferences)
83 return;
84
85 ICodeStylePreferences *current = m_preferences->currentPreferences();
86 if (!current)
87 return;
88
89 current->setTabSettings(settings);
90 }
91
tabSettingsWidget() const92 TabSettingsWidget *SimpleCodeStylePreferencesWidget::tabSettingsWidget() const
93 {
94 return m_tabSettingsWidget;
95 }
96
97 } // namespace TextEditor
98