refs #830, settings for global GUI properties

(such as widget style, selection mode)
This commit is contained in:
Klaus Basan
2016-12-10 05:31:42 +01:00
parent 1d773f2264
commit f3037f083a
5 changed files with 154 additions and 10 deletions

View File

@@ -11,6 +11,7 @@
#include "blackgui/settings/dockwidgetsettings.h"
#include "blackgui/settings/navigatorsettings.h"
#include "blackgui/settings/viewupdatesettings.h"
#include "blackgui/settings/guisettings.h"
#include "blackgui/components/registermetadatacomponents.h"
namespace BlackGui
@@ -20,6 +21,7 @@ namespace BlackGui
BlackGui::Settings::CDockWidgetSettings::registerMetadata();
BlackGui::Settings::CNavigatorSettings::registerMetadata();
BlackGui::Settings::CViewUpdateSettings::registerMetadata();
BlackGui::Settings::CGeneralGuiSettings::registerMetadata();
BlackGui::Components::registerMetadata();
}
}

View File

@@ -0,0 +1,88 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "guisettings.h"
#include <QStyleFactory>
using namespace BlackMisc;
namespace BlackGui
{
namespace Settings
{
CGeneralGuiSettings::CGeneralGuiSettings()
{ }
void CGeneralGuiSettings::setWidgetStyle(const QString &widgetStyle)
{
if (this->m_widgetStyle == widgetStyle) { return; }
const auto availableStyles = QStyleFactory::keys();
if (availableStyles.contains(widgetStyle))
{
m_widgetStyle = widgetStyle;
}
}
bool CGeneralGuiSettings::isDifferentValidWidgetStyle(const QString &style) const
{
if (!QStyleFactory::keys().contains(style)) { return false; }
return style != this->m_widgetStyle;
}
QAbstractItemView::SelectionMode CGeneralGuiSettings::getPreferredSelection() const
{
return static_cast<QAbstractItemView::SelectionMode>(m_preferredSelection);
}
void CGeneralGuiSettings::setPreferredSelection(QAbstractItemView::SelectionMode selection)
{
this->m_preferredSelection = static_cast<int>(selection);
}
QString CGeneralGuiSettings::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
static const QString s("Widget style: %1");
return s.arg(this->m_widgetStyle);
}
BlackMisc::CVariant CGeneralGuiSettings::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexWidgetStyle:
return CVariant::fromValue(this->m_widgetStyle);
case IndexPreferredSelection:
return CVariant::fromValue(this->m_preferredSelection);
default:
return CValueObject::propertyByIndex(index);
}
}
void CGeneralGuiSettings::setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CGeneralGuiSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexWidgetStyle:
this->setWidgetStyle(variant.toQString());
break;
case IndexPreferredSelection:
this->m_preferredSelection = variant.toInt();
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
} // ns
} // ns

View File

@@ -17,28 +17,80 @@
#include "blackmisc/simulation/aircraftmodel.h"
#include <QString>
#include <QAbstractItemView>
namespace BlackGui
{
namespace Settings
{
//! General GUI settings
class BLACKGUI_EXPORT CGeneralGuiSettings :
public BlackMisc::CValueObject<CGeneralGuiSettings>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexWidgetStyle = BlackMisc::CPropertyIndex::GlobalIndexCGeneralGuiSettings,
IndexPreferredSelection
};
//! Default constructor
CGeneralGuiSettings();
//! Widget style
const QString &getWidgetStyle() const { return m_widgetStyle; }
//! Widget style
void setWidgetStyle(const QString &widgetStyle);
//! Has changed widget style
bool isDifferentValidWidgetStyle(const QString &style) const;
//! Preferred selection
QAbstractItemView::SelectionMode getPreferredSelection() const;
//! Preferred selection
void setPreferredSelection(QAbstractItemView::SelectionMode selection);
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
private:
QString m_widgetStyle { "Fusion" };
int m_preferredSelection = static_cast<int>(QAbstractItemView::ExtendedSelection);
BLACK_METACLASS(
CGeneralGuiSettings,
BLACK_METAMEMBER(widgetStyle),
BLACK_METAMEMBER(preferredSelection)
);
};
//! General GUI settings
struct TGeneralGui : public BlackMisc::TSettingTrait<CGeneralGuiSettings>
{
//! \copydoc BlackCore::TSettingTrait::key
static const char *key() { return "guigeneral"; }
};
//! Settings for last manual entries of own aircraft mode
struct TOwnAircraftModel : public BlackMisc::TSettingTrait<BlackMisc::Simulation::CAircraftModel>
{
//! Key in data cache
static const char *key() { return "guinownaircraftmodel"; }
};
//! Widget Style
struct TWidgetStyle : public BlackMisc::TSettingTrait<QString>
{
//! \copydoc BlackCore::TSettingTrait::key
static const char *key() { return "application/widgetstyle"; }
//! \copydoc BlackCore::TSettingTrait::defaultValue
static QString defaultValue() { return QStringLiteral("Fusion"); }
};
} // ns
} // ns
Q_DECLARE_METATYPE(BlackGui::Settings::CGeneralGuiSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CGeneralGuiSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CGeneralGuiSettings>)
#endif // guard

View File

@@ -141,6 +141,7 @@ namespace BlackMisc
GlobalIndexCNavigatorSettings = 14300,
GlobalIndexCSettingsReaders = 14400,
GlobalIndexCViewUpdateSettings = 14500,
GlobalIndexCGeneralGuiSettings = 14600,
GloablIndexInterpolatorSetup = 15000,
GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers
};

View File

@@ -43,6 +43,7 @@ namespace BlackMisc
CVPilotModelRule::registerMetadata();
CVPilotModelRuleSet::registerMetadata();
CSimulatorSettings::registerMetadata();
CModelSettings::registerMetadata();
CSimulatorMessagesSettings::registerMetadata();
}
} // ns