[libcalamaresui] Load panel-side settings

- Introduce an enum for panel-side
- Expose this to QML -- I can imagine that QML panels need to know
  which side of the Calamares window they're on.
- Refactor loading the setting into a method that handles both
  flavor and side
This commit is contained in:
Adriaan de Groot 2020-04-03 11:04:46 +02:00
parent b48e0ebb37
commit e15e7d1dc5
2 changed files with 91 additions and 19 deletions

View File

@ -405,6 +405,79 @@ getString( const YAML::Node& doc, const char* key )
return QString();
}
static inline void
flavorAndSide( const YAML::Node& doc, const char* key, Branding::PanelFlavor& flavor, Branding::PanelSide& side )
{
using PanelFlavor = Branding::PanelFlavor;
using PanelSide = Branding::PanelSide;
// *INDENT-OFF*
// clang-format off
static const NamedEnumTable< PanelFlavor > sidebarFlavorNames {
{ QStringLiteral( "widget" ), PanelFlavor::Widget },
{ QStringLiteral( "none" ), PanelFlavor::None },
{ QStringLiteral( "hidden" ), PanelFlavor::None },
{ QStringLiteral( "qml" ), PanelFlavor::Qml }
};
static const NamedEnumTable< PanelSide > panelSideNames {
{ QStringLiteral( "left" ), PanelSide::Left },
{ QStringLiteral( "right" ), PanelSide::Right },
{ QStringLiteral( "top" ), PanelSide::Top },
{ QStringLiteral( "bottom" ), PanelSide::Bottom }
};
// clang-format on
// *INDENT-ON*
bool ok = false;
QString configValue = getString( doc, key );
if ( configValue.isEmpty() )
{
// Complain with the original values
cWarning() << "Branding setting for" << key << "is missing, using" << sidebarFlavorNames.find( flavor, ok )
<< panelSideNames.find( side, ok );
return;
}
QStringList parts = configValue.split( ',' );
if ( parts.length() == 1 )
{
PanelFlavor f = sidebarFlavorNames.find( configValue, ok );
if ( ok )
{
flavor = f;
}
else
{
// Complain with the original value
cWarning() << "Branding setting for" << key << "interpreted as" << sidebarFlavorNames.find( flavor, ok )
<< panelSideNames.find( side, ok );
}
return;
}
for ( const QString& spart : parts )
{
bool isFlavor = false;
bool isSide = false;
PanelFlavor f = sidebarFlavorNames.find( spart, isFlavor );
PanelSide s = panelSideNames.find( spart, isSide );
if ( isFlavor )
{
flavor = f;
}
else if ( isSide )
{
side = s;
}
else
{
cWarning() << "Branding setting for" << key << "contains unknown" << spart << "interpreted as"
<< sidebarFlavorNames.find( flavor, ok ) << panelSideNames.find( side, ok );
return;
}
}
}
void
Branding::initSimpleSettings( const YAML::Node& doc )
{
@ -419,12 +492,6 @@ Branding::initSimpleSettings( const YAML::Node& doc )
{ QStringLiteral( "free" ), WindowPlacement::Free },
{ QStringLiteral( "center" ), WindowPlacement::Center }
};
static const NamedEnumTable< PanelFlavor > sidebarFlavorNames {
{ QStringLiteral( "widget" ), PanelFlavor::Widget },
{ QStringLiteral( "none" ), PanelFlavor::None },
{ QStringLiteral( "hidden" ), PanelFlavor::None },
{ QStringLiteral( "qml" ), PanelFlavor::Qml }
};
// clang-format on
// *INDENT-ON*
bool ok = false;
@ -443,18 +510,8 @@ Branding::initSimpleSettings( const YAML::Node& doc )
cWarning() << "Branding module-setting *windowPlacement* interpreted as"
<< placementNames.find( m_windowPlacement, ok );
}
m_sidebarFlavor = sidebarFlavorNames.find( getString( doc, "sidebar" ), ok );
if ( !ok )
{
cWarning() << "Branding module-setting *sidebar* interpreted as"
<< sidebarFlavorNames.find( m_sidebarFlavor, ok );
}
m_navigationFlavor = sidebarFlavorNames.find( getString( doc, "navigation" ), ok);
if ( !ok )
{
cWarning() << "Branding module-setting *navigation* interpreted as"
<< sidebarFlavorNames.find( m_navigationFlavor, ok );
}
flavorAndSide( doc, "sidebar", m_sidebarFlavor, m_sidebarSide );
flavorAndSide( doc, "navigation", m_navigationFlavor, m_navigationSide );
QString windowSize = getString( doc, "windowSize" );
if ( !windowSize.isEmpty() )

View File

@ -123,7 +123,7 @@ public:
Free
};
Q_ENUM( WindowPlacement )
///@brief What kind of sidebar to use in the main window
///@brief What kind of panel (sidebar, navigation) to use in the main window
enum class PanelFlavor
{
None,
@ -131,6 +131,16 @@ public:
Qml
};
Q_ENUM( PanelFlavor )
///@brief Where to place a panel (sidebar, navigation)
enum class PanelSide
{
None,
Left,
Right,
Top,
Bottom
};
Q_ENUM( PanelSide )
static Branding* instance();
@ -201,6 +211,9 @@ public slots:
QString styleString( StyleEntry styleEntry ) const;
QString imagePath( ImageEntry imageEntry ) const;
PanelSide sidebarSide() const { return m_sidebarSide; }
PanelSide navigationSide() const { return m_navigationSide; }
private:
static Branding* s_instance;
@ -231,6 +244,8 @@ private:
PanelFlavor m_sidebarFlavor = PanelFlavor::Widget;
PanelFlavor m_navigationFlavor = PanelFlavor::Widget;
PanelSide m_sidebarSide = PanelSide::Left;
PanelSide m_navigationSide = PanelSide::Bottom;
};
template < typename U >