swift
navigatorsettings.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "navigatorsettings.h"
5 
6 #include <QStringList>
7 
8 #include "gui/guiutility.h"
9 #include "misc/stringutils.h"
10 
11 using namespace swift::misc;
12 using namespace swift::gui;
13 
14 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::gui::settings, CNavigatorSettings)
15 
16 namespace swift::gui::settings
17 {
18  CNavigatorSettings::CNavigatorSettings() {}
19 
20  void CNavigatorSettings::reset() {}
21 
22  void CNavigatorSettings::setMargins(const QMargins &margins)
23  {
24  this->m_margins = CGuiUtility::marginsToString(margins);
25  }
26 
27  QMargins CNavigatorSettings::getMargins() const { return CGuiUtility::stringToMargins(this->m_margins); }
28 
29  QByteArray CNavigatorSettings::getGeometry() const { return QByteArray::fromHex(this->m_geometry.toLatin1()); }
30 
31  void CNavigatorSettings::setGeometry(const QByteArray &ba) { this->m_geometry = ba.toHex(); }
32 
33  QString CNavigatorSettings::convertToQString(bool i18n) const { return convertToQString(", ", i18n); }
34 
35  QString CNavigatorSettings::convertToQString(const QString &separator, bool i18n) const
36  {
37  Q_UNUSED(i18n);
38  QString s("margins: ");
39  s.append(this->m_margins);
40  s.append(separator);
41  s.append("frameless: ");
42  s.append(boolToTrueFalse(this->m_frameless));
43  s.append(separator);
44  s.append("columns: ");
45  s.append(QString::number(this->m_columns));
46  return s;
47  }
48 
49  QVariant CNavigatorSettings::propertyByIndex(CPropertyIndexRef index) const
50  {
51  if (index.isMyself()) { return QVariant::fromValue(*this); }
52  ColumnIndex i = index.frontCasted<ColumnIndex>();
53  switch (i)
54  {
55  case IndexMargins: return QVariant::fromValue(this->m_margins);
56  case IndexFrameless: return QVariant::fromValue(this->isFramless());
57  case IndexColumns: return QVariant::fromValue(this->m_columns);
58  default: return CValueObject::propertyByIndex(index);
59  }
60  }
61 
62  void CNavigatorSettings::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
63  {
64  if (index.isMyself())
65  {
66  (*this) = variant.value<CNavigatorSettings>();
67  return;
68  }
69 
70  ColumnIndex i = index.frontCasted<ColumnIndex>();
71  switch (i)
72  {
73  case IndexMargins: this->m_margins = variant.toString(); break;
74  case IndexColumns: this->m_columns = variant.toInt(); break;
75  case IndexFrameless: this->m_frameless = variant.toBool(); break;
76  default: CValueObject::setPropertyByIndex(index, variant); break;
77  }
78  }
79 } // namespace swift::gui::settings
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
GUI related classes.
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToTrueFalse(bool v)
Bool to true/false.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67