BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ApplicationSettings Class Reference

Description

Application wide settings.

Contains settings which the user can change. Also contains settings which may be user editable in the future.

Definition at line 27 of file ApplicationSettings.h.

Collaboration diagram for ApplicationSettings:
[legend]

Classes

struct  Palette
 

Public Types

enum class  Style { native , light , dark }
 

Public Member Functions

 ApplicationSettings ()
 
bool createNewProjectOnStartup () const
 
ApplicationSettings::Style currentStyle ()
 
QVariant defaultFunctionalities (const QVariant &absenceValue) const
 
bool defaultIsSingleInstrumentMode () const
 
bool defaultIsSingleSampleMode () const
 
bool defaultUnitIsAngstrom () const
 
void loadStyle (ApplicationSettings::Style style)
 
void loadWindowSizeAndPos (QWidget *w)
 
void saveWindowSizeAndPos (const QWidget *w)
 
void setCreateNewProjectOnStartup (bool b)
 
void setDefaultFunctionalities (const QVariant &functionalities)
 
void setDefaultIsSingleInstrumentMode (bool b)
 
void setDefaultIsSingleSampleMode (bool b)
 
void setDefaultUnitIsAngstrom (bool b) const
 
void setStyleToUse (Style style)
 
const PalettestyleSheetPalette () const
 
Style styleToUse () const
 
bool useNativeFileDialog () const
 

Private Attributes

ApplicationSettings::Style m_currentStyle
 
Palette m_styleSheetPalette
 

Member Enumeration Documentation

◆ Style

Enumerator
native 
light 
dark 

Definition at line 29 of file ApplicationSettings.h.

29 { native, light, dark };

Constructor & Destructor Documentation

◆ ApplicationSettings()

ApplicationSettings::ApplicationSettings ( )

Definition at line 38 of file ApplicationSettings.cpp.

40 {
41  appSettings = this;
42 }
ApplicationSettings * appSettings
global pointer to the instance
ApplicationSettings::Style m_currentStyle

References appSettings.

Member Function Documentation

◆ createNewProjectOnStartup()

bool ApplicationSettings::createNewProjectOnStartup ( ) const

Definition at line 53 of file ApplicationSettings.cpp.

54 {
55  return QSettings().value(S_CREATE_NEW_PROJECT_ON_STARTUP, true).toBool();
56 }

Referenced by MainWindow::MainWindow(), and ActionManager::onAboutToShowSettingsMenu().

◆ currentStyle()

ApplicationSettings::Style ApplicationSettings::currentStyle ( )

Definition at line 185 of file ApplicationSettings.cpp.

186 {
187  return m_currentStyle;
188 }

References m_currentStyle.

Referenced by GroupBoxCollapser::GroupBoxCollapser(), and ActionManager::onAboutToShowSettingsMenu().

◆ defaultFunctionalities()

QVariant ApplicationSettings::defaultFunctionalities ( const QVariant &  absenceValue) const

Definition at line 73 of file ApplicationSettings.cpp.

74 {
75  return QSettings().value(S_DEFAULT_FUNCTIONALITIES, absenceValue);
76 }

Referenced by ProjectManager::createNewProject().

◆ defaultIsSingleInstrumentMode()

bool ApplicationSettings::defaultIsSingleInstrumentMode ( ) const

Definition at line 83 of file ApplicationSettings.cpp.

84 {
85  return QSettings().value(S_SINGLE_INSTRUMENT_MODE, false).toBool();
86 }

Referenced by ProjectManager::createNewProject().

◆ defaultIsSingleSampleMode()

bool ApplicationSettings::defaultIsSingleSampleMode ( ) const

Definition at line 93 of file ApplicationSettings.cpp.

94 {
95  return QSettings().value(S_SINGLE_SAMPLE_MODE, false).toBool();
96 }

Referenced by ProjectManager::createNewProject().

◆ defaultUnitIsAngstrom()

bool ApplicationSettings::defaultUnitIsAngstrom ( ) const

Definition at line 103 of file ApplicationSettings.cpp.

104 {
105  return QSettings().value(S_DEFAULT_UNIT_IS_ANGSTROM, false).toBool();
106 }

Referenced by LayerOrientedSampleEditor::LayerOrientedSampleEditor(), and ActionManager::onAboutToShowSettingsMenu().

◆ loadStyle()

void ApplicationSettings::loadStyle ( ApplicationSettings::Style  style)

Definition at line 133 of file ApplicationSettings.cpp.

134 {
135  QString stylesheet;
136 
137  switch (style) {
139  QFile base(":/styles/Base.stylesheet");
140  base.open(QFile::ReadOnly);
141  QFile light(":/styles/Light.stylesheet");
142  light.open(QFile::ReadOnly);
143  stylesheet = base.readAll() + light.readAll();
144  break;
145  }
147  QFile base(":/styles/Base.stylesheet");
148  base.open(QFile::ReadOnly);
149  QFile dark(":/styles/Dark.stylesheet");
150  dark.open(QFile::ReadOnly);
151  stylesheet = base.readAll() + dark.readAll();
152  break;
153  }
154  default: {
155  QFile native(":/styles/Native.stylesheet");
156  native.open(QFile::ReadOnly);
157  stylesheet = native.readAll();
158  break;
159  }
160  }
161 
162  qApp->setStyleSheet(stylesheet);
163  m_currentStyle = style;
164 
165  // -- init palette for later usage; could be improved by parsing the stylesheet
166  switch (m_currentStyle) {
168  m_styleSheetPalette.headlineText = QColor(48, 113, 145);
169  m_styleSheetPalette.headlineBackground = QColor(222, 232, 237);
170  break;
171  }
173  m_styleSheetPalette.headlineText = QColor(213, 220, 223);
174  m_styleSheetPalette.headlineBackground = QColor(29, 39, 44);
175  break;
176  }
177  default: {
178  m_styleSheetPalette.headlineText = Qt::black;
179  m_styleSheetPalette.headlineBackground = QColor(250, 250, 250);
180  break;
181  }
182  }
183 }

References dark, ApplicationSettings::Palette::headlineBackground, ApplicationSettings::Palette::headlineText, light, m_currentStyle, and m_styleSheetPalette.

Referenced by main(), and ActionManager::onAboutToShowSettingsMenu().

◆ loadWindowSizeAndPos()

void ApplicationSettings::loadWindowSizeAndPos ( QWidget *  w)

Definition at line 121 of file ApplicationSettings.cpp.

122 {
123  ASSERT(!w->objectName().isEmpty());
124 
125  QSettings settings;
126  const QSize size = settings.value(S_SIZE + "/" + w->objectName(), QSize()).toSize();
127  if (size.isValid())
128  w->resize(size);
129  if (settings.contains(S_POS + "/" + w->objectName()))
130  w->move(settings.value(S_POS + "/" + w->objectName()).toPoint());
131 }

Referenced by InstrumentLibraryEditor::InstrumentLibraryEditor(), MaterialEditorDialog::MaterialEditorDialog(), and PythonScriptWidget::PythonScriptWidget().

◆ saveWindowSizeAndPos()

void ApplicationSettings::saveWindowSizeAndPos ( const QWidget *  w)

Definition at line 113 of file ApplicationSettings.cpp.

114 {
115  ASSERT(!w->objectName().isEmpty());
116  QSettings settings;
117  settings.setValue(S_SIZE + "/" + w->objectName(), w->size());
118  settings.setValue(S_POS + "/" + w->objectName(), w->pos());
119 }

Referenced by InstrumentLibraryEditor::~InstrumentLibraryEditor(), MaterialEditorDialog::~MaterialEditorDialog(), and PythonScriptWidget::~PythonScriptWidget().

◆ setCreateNewProjectOnStartup()

void ApplicationSettings::setCreateNewProjectOnStartup ( bool  b)

Definition at line 58 of file ApplicationSettings.cpp.

59 {
60  QSettings().setValue(S_CREATE_NEW_PROJECT_ON_STARTUP, b);
61 }

Referenced by ActionManager::onAboutToShowSettingsMenu().

◆ setDefaultFunctionalities()

void ApplicationSettings::setDefaultFunctionalities ( const QVariant &  functionalities)

Definition at line 78 of file ApplicationSettings.cpp.

79 {
80  QSettings().setValue(S_DEFAULT_FUNCTIONALITIES, functionalities);
81 }

Referenced by ProjectSettingsView::storeAsDefaults().

◆ setDefaultIsSingleInstrumentMode()

void ApplicationSettings::setDefaultIsSingleInstrumentMode ( bool  b)

Definition at line 88 of file ApplicationSettings.cpp.

89 {
90  QSettings().setValue(S_SINGLE_INSTRUMENT_MODE, b);
91 }

Referenced by ProjectSettingsView::storeAsDefaults().

◆ setDefaultIsSingleSampleMode()

void ApplicationSettings::setDefaultIsSingleSampleMode ( bool  b)

Definition at line 98 of file ApplicationSettings.cpp.

99 {
100  QSettings().setValue(S_SINGLE_SAMPLE_MODE, b);
101 }

Referenced by ProjectSettingsView::storeAsDefaults().

◆ setDefaultUnitIsAngstrom()

void ApplicationSettings::setDefaultUnitIsAngstrom ( bool  b) const

Definition at line 108 of file ApplicationSettings.cpp.

109 {
110  QSettings().setValue(S_DEFAULT_UNIT_IS_ANGSTROM, b);
111 }

Referenced by ActionManager::onAboutToShowSettingsMenu().

◆ setStyleToUse()

void ApplicationSettings::setStyleToUse ( Style  style)

Definition at line 68 of file ApplicationSettings.cpp.

69 {
70  QSettings().setValue(S_STYLE, static_cast<int>(style));
71 }

Referenced by ActionManager::onAboutToShowSettingsMenu().

◆ styleSheetPalette()

const ApplicationSettings::Palette & ApplicationSettings::styleSheetPalette ( ) const

Definition at line 190 of file ApplicationSettings.cpp.

191 {
192  return m_styleSheetPalette;
193 }

References m_styleSheetPalette.

Referenced by RealDataTreeModel::data(), and InstrumentsTreeModel::data().

◆ styleToUse()

ApplicationSettings::Style ApplicationSettings::styleToUse ( ) const

Definition at line 63 of file ApplicationSettings.cpp.

64 {
65  return static_cast<Style>(QSettings().value(S_STYLE, static_cast<int>(Style::light)).toInt());
66 }

References light.

Referenced by main().

◆ useNativeFileDialog()

bool ApplicationSettings::useNativeFileDialog ( ) const

Member Data Documentation

◆ m_currentStyle

ApplicationSettings::Style ApplicationSettings::m_currentStyle
private

Definition at line 65 of file ApplicationSettings.h.

Referenced by currentStyle(), and loadStyle().

◆ m_styleSheetPalette

Palette ApplicationSettings::m_styleSheetPalette
private

Definition at line 66 of file ApplicationSettings.h.

Referenced by loadStyle(), and styleSheetPalette().


The documentation for this class was generated from the following files: