1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "projectsettingswidget.h"
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <QCheckBox>
#include <QLabel>
namespace ProjectExplorer {
const int CONTENTS_MARGIN = 5;
ProjectSettingsWidget::ProjectSettingsWidget(QWidget *parent)
: QWidget(parent)
{}
void ProjectSettingsWidget::setUseGlobalSettings(bool useGlobalSettings)
{
if (m_useGlobalSettings == useGlobalSettings)
return;
m_useGlobalSettings = useGlobalSettings;
emit useGlobalSettingsChanged(useGlobalSettings);
}
bool ProjectSettingsWidget::useGlobalSettings() const
{
return m_useGlobalSettings;
}
void ProjectSettingsWidget::setUseGlobalSettingsCheckBoxEnabled(bool enabled)
{
if (m_useGlobalSettingsCheckBoxEnabled == enabled)
return;
m_useGlobalSettingsCheckBoxEnabled = enabled;
emit useGlobalSettingsCheckBoxEnabledChanged(enabled);
}
void ProjectSettingsWidget::setUseGlobalSettingsCheckBoxVisible(bool visible)
{
m_useGlobalSettingsCheckBoxVisibleVisible = visible;
}
void ProjectSettingsWidget::setUseGlobalSettingsLabelVisible(bool visible)
{
m_useGlobalSettingsLabelVisibleVisible = visible;
}
void ProjectSettingsWidget::setGlobalSettingsId(Utils::Id globalId)
{
m_globalSettingsId = globalId;
}
void ProjectSettingsWidget::setExpanding(bool expanding)
{
m_expanding = expanding;
}
void ProjectSettingsWidget::addGlobalOrProjectSelectorToLayout(QBoxLayout *layout)
{
if (!m_useGlobalSettingsCheckBoxVisibleVisible && !m_useGlobalSettingsLabelVisibleVisible)
return;
const auto useGlobalSettingsCheckBox = new QCheckBox;
useGlobalSettingsCheckBox->setChecked(useGlobalSettings());
useGlobalSettingsCheckBox->setEnabled(m_useGlobalSettingsCheckBoxEnabled);
const QString labelText = m_useGlobalSettingsCheckBoxVisibleVisible
? QStringLiteral("Use <a href=\"dummy\">global settings</a>")
: QStringLiteral("<a href=\"dummy\">Global settings</a>");
const auto settingsLabel = new QLabel(labelText);
settingsLabel->setEnabled(m_useGlobalSettingsCheckBoxEnabled);
const auto horizontalLayout = new QHBoxLayout;
horizontalLayout->setContentsMargins(0, CONTENTS_MARGIN, 0, CONTENTS_MARGIN);
horizontalLayout->setSpacing(CONTENTS_MARGIN);
if (m_useGlobalSettingsCheckBoxVisibleVisible) {
horizontalLayout->addWidget(useGlobalSettingsCheckBox);
connect(this, &ProjectSettingsWidget::useGlobalSettingsCheckBoxEnabledChanged,
this, [useGlobalSettingsCheckBox, settingsLabel](bool enabled) {
useGlobalSettingsCheckBox->setEnabled(enabled);
settingsLabel->setEnabled(enabled);
});
connect(useGlobalSettingsCheckBox, &QCheckBox::stateChanged,
this, &ProjectSettingsWidget::setUseGlobalSettings);
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged,
useGlobalSettingsCheckBox, &QCheckBox::setChecked);
}
if (m_useGlobalSettingsLabelVisibleVisible) {
horizontalLayout->addWidget(settingsLabel);
connect(settingsLabel, &QLabel::linkActivated, this, [this] {
Core::ICore::showOptionsDialog(m_globalSettingsId);
});
}
horizontalLayout->addStretch(1);
layout->addLayout(horizontalLayout);
layout->addWidget(Layouting::createHr());
}
} // ProjectExplorer
|