32 #include <QtCore/QSettings>
34 #include "ui_workspacesettings.h"
37 using namespace Core::Internal;
39 const int WorkspaceSettings::MAX_WORKSPACES = 10;
54 return QLatin1String(
"Workspaces");
59 return tr(
"Workspaces");
64 return QLatin1String(
"GCS");
74 m_page =
new Ui::WorkspaceSettings();
75 QWidget *w =
new QWidget(parent);
78 m_page->numberOfWorkspacesSpinBox->setMaximum(MAX_WORKSPACES);
79 m_page->numberOfWorkspacesSpinBox->setValue(m_numberOfWorkspaces);
80 for (
int i = 0;
i < m_numberOfWorkspaces; ++
i) {
81 m_page->workspaceComboBox->addItem(QIcon(m_iconNames.at(
i)), m_names.at(
i));
84 m_page->iconPathChooser->setExpectedKind(Utils::PathChooser::File);
85 m_page->iconPathChooser->setPromptDialogFilter(tr(
"Images (*.png *.jpg *.bmp *.xpm)"));
86 m_page->iconPathChooser->setPromptDialogTitle(tr(
"Choose icon"));
88 connect(m_page->workspaceComboBox, SIGNAL(currentIndexChanged(
int)),
this,
90 connect(m_page->numberOfWorkspacesSpinBox, SIGNAL(valueChanged(
int)),
this,
93 connect(m_page->iconPathChooser, SIGNAL(browsingFinished()),
this, SLOT(
iconChanged()));
98 if (0 <= m_tabBarPlacementIndex
99 && m_tabBarPlacementIndex < m_page->comboBoxTabBarPlacement->count())
100 m_page->comboBoxTabBarPlacement->setCurrentIndex(m_tabBarPlacementIndex);
101 m_page->checkBoxAllowTabMovement->setChecked(m_allowTabBarMovement);
112 qs->beginGroup(QLatin1String(
"Workspace"));
113 m_numberOfWorkspaces = qs->value(QLatin1String(
"NumberOfWorkspaces"), 2).toInt();
114 m_previousNumberOfWorkspaces = m_numberOfWorkspaces;
115 for (
int i = 1;
i <= MAX_WORKSPACES; ++
i) {
116 QString numberString = QString::number(
i);
117 QString defaultName =
"Workspace" + numberString;
118 QString defaultIconName =
"Icon" + numberString;
119 QString
name = qs->value(defaultName, defaultName).toString();
120 QString
iconName = qs->value(defaultIconName,
":/core/gcs_logo_64").toString();
121 m_names.append(name);
122 m_iconNames.append(iconName);
123 m_modeNames.append(QString(
"Mode") + QString::number(
i));
125 m_tabBarPlacementIndex =
126 qs->value(QLatin1String(
"TabBarPlacementIndex"), 1).toInt();
127 m_allowTabBarMovement = qs->value(QLatin1String(
"AllowTabBarMovement"),
false).toBool();
129 QTabWidget::TabPosition pos =
130 m_tabBarPlacementIndex == 0 ? QTabWidget::North : QTabWidget::South;
136 qs->beginGroup(QLatin1String(
"Workspace"));
137 qs->setValue(QLatin1String(
"NumberOfWorkspaces"), m_numberOfWorkspaces);
138 for (
int i = 0;
i < MAX_WORKSPACES; ++
i) {
139 QString mode = QString(
"Mode") + QString::number(
i + 1);
140 int j = m_modeNames.indexOf(mode);
141 QString numberString = QString::number(
i + 1);
142 QString defaultName =
"Workspace" + numberString;
143 QString defaultIconName =
"Icon" + numberString;
144 qs->setValue(defaultName, m_names.at(j));
145 qs->setValue(defaultIconName, m_iconNames.at(j));
147 qs->setValue(QLatin1String(
"TabBarPlacementIndex"), m_tabBarPlacementIndex);
148 qs->setValue(QLatin1String(
"AllowTabBarMovement"), m_allowTabBarMovement);
158 if (m_numberOfWorkspaces != m_previousNumberOfWorkspaces) {
160 m_previousNumberOfWorkspaces = m_numberOfWorkspaces;
164 for (
int i = 0;
i < MAX_WORKSPACES; ++
i) {
171 m_tabBarPlacementIndex = m_page->comboBoxTabBarPlacement->currentIndex();
172 m_allowTabBarMovement = m_page->checkBoxAllowTabMovement->isChecked();
173 QTabWidget::TabPosition pos =
174 m_tabBarPlacementIndex == 0 ? QTabWidget::North : QTabWidget::South;
186 m_page->workspaceComboBox->setItemText(m_currentIndex, m_page->nameEdit->text());
191 QString
iconName = m_page->iconPathChooser->path();
192 m_page->workspaceComboBox->setItemIcon(m_currentIndex, QIcon(iconName));
197 m_numberOfWorkspaces = value;
198 int count = m_page->workspaceComboBox->count();
200 for (
int i = count;
i < value; ++
i) {
201 m_page->workspaceComboBox->addItem(QIcon(m_iconNames.at(
i)), m_names.at(
i));
203 }
else if (value < count) {
204 for (
int i = count - 1;
i >= value; --
i) {
205 m_page->workspaceComboBox->removeItem(
i);
212 if (store || (index != m_currentIndex)) {
214 m_iconNames.replace(m_currentIndex, m_page->iconPathChooser->path());
215 m_names.replace(m_currentIndex, m_page->nameEdit->text());
216 m_page->workspaceComboBox->setItemIcon(m_currentIndex,
217 QIcon(m_iconNames.at(m_currentIndex)));
218 m_page->workspaceComboBox->setItemText(m_currentIndex, m_names.at(m_currentIndex));
222 QString
iconName = m_iconNames.at(index);
223 m_page->iconPathChooser->setPath(iconName);
224 m_page->nameEdit->setText(m_names.at(index));
225 m_currentIndex = index;
231 QStringList modeNames;
232 for (
int i = 0;
i < modes.count(); ++
i) {
235 priorities.append(mode->
priority());
240 bool swapped =
false;
243 for (
int i = 0;
i < m_names.count() - 1; ++
i) {
245 int p = modeNames.indexOf(m_modeNames.at(
i));
246 int q = modeNames.indexOf(m_modeNames.at(j));
247 bool nonShowingMode = (p == -1 && q >= 0);
248 bool pqBothFound = (p >= 0 && q >= 0);
249 if (nonShowingMode || (pqBothFound && (priorities.at(q) > priorities.at(p)))) {
251 m_iconNames.swap(
i, j);
252 m_modeNames.swap(
i, j);
void selectWorkspace(int index, bool store=false)
void tabBarSettingsApplied(QTabWidget::TabPosition pos, bool movable)
QString modeName(int i) const
virtual void readMainSettings(QSettings *qs, bool workspaceDiffOnly=false)=0
void textEdited(QString string)
QString trCategory() const
QWidget * createPage(QWidget *parent)
IMode * mode(const QString &id) const
void numberOfWorkspacesChanged(int value)
QString name(int i) const
void saveSettings(QSettings *qs)
void newModeOrder(QVector< IMode * > modes)
static ICore * instance()
void updateModeNameIcon(IMode *mode, const QIcon &icon, const QString &label)
const char * uniqueModeName() const
QString iconName(int i) const
WorkspaceSettings(QObject *parent=nullptr)
void readSettings(QSettings *qs)
virtual ModeManager * modeManager() const =0
Returns the application's mode manager.
The IOptionsPage is an interface for providing options pages.