[libcalamaresui] Record branding window-size
This commit is contained in:
parent
99a19c7c6b
commit
32ab377e43
@ -21,6 +21,7 @@
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "utils/CalamaresUtils.h"
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/ImageRegistry.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/NamedEnum.h"
|
||||
@ -77,6 +78,17 @@ const QStringList Branding::s_styleEntryStrings =
|
||||
"sidebarTextHighlight"
|
||||
};
|
||||
|
||||
static const NamedEnumTable<Branding::WindowDimensionUnit>&
|
||||
windowDimensions()
|
||||
{
|
||||
using Unit = Branding::WindowDimensionUnit;
|
||||
static const NamedEnumTable<Unit> names{
|
||||
{"px", Unit::Pixies},
|
||||
{"em", Unit::Fonties}
|
||||
};
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
Branding::Branding( const QString& brandingFilePath,
|
||||
QObject* parent )
|
||||
@ -287,23 +299,47 @@ Branding::setGlobals( GlobalStorage* globalStorage ) const
|
||||
globalStorage->insert( "branding", brandingMap );
|
||||
}
|
||||
|
||||
bool
|
||||
Branding::WindowDimension::isValid() const
|
||||
{
|
||||
return ( unit() != none ) && ( value() > 0 );
|
||||
}
|
||||
|
||||
void
|
||||
Branding::initSimpleSettings( const YAML::Node& doc )
|
||||
{
|
||||
static const NamedEnumTable< WindowExpansion > weNames{
|
||||
static const NamedEnumTable< WindowExpansion > expansionNames{
|
||||
{ QStringLiteral( "normal" ), WindowExpansion::Normal },
|
||||
{ QStringLiteral( "fullscreen" ), WindowExpansion::Fullscreen },
|
||||
{ QStringLiteral( "noexpand" ), WindowExpansion::Fixed }
|
||||
};
|
||||
static const NamedEnumTable< WindowDimensionUnit > dimensionNames{
|
||||
{ QStringLiteral( "px" ), WindowDimensionUnit::Pixies },
|
||||
{ QStringLiteral( "em" ), WindowDimensionUnit::Fonties }
|
||||
};
|
||||
|
||||
bool ok = false;
|
||||
|
||||
m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false );
|
||||
m_welcomeExpandingLogo = doc[ "welcomeExpandingLogo" ].as< bool >( true );
|
||||
m_windowExpansion = weNames.find( QString::fromStdString( doc[ "windowExpanding" ].as< std::string >() ), ok );
|
||||
m_windowExpansion = expansionNames.find( QString::fromStdString( doc[ "windowExpanding" ].as< std::string >() ), ok );
|
||||
if ( !ok )
|
||||
cWarning() << "Branding module-setting *windowExpanding* interpreted as" << weNames.find( m_windowExpansion, ok );
|
||||
cWarning() << "Branding module-setting *windowExpanding* interpreted as" << expansionNames.find( m_windowExpansion, ok );
|
||||
|
||||
QString windowSize = QString::fromStdString( doc[ "windowSize" ].as< std::string >() );
|
||||
if ( !windowSize.isEmpty() )
|
||||
{
|
||||
auto l = windowSize.split( ',' );
|
||||
if ( l.count() == 2 )
|
||||
{
|
||||
m_windowWidth = WindowDimension( dimensionNames, l[0] );
|
||||
m_windowHeight = WindowDimension( dimensionNames, l[1] );
|
||||
}
|
||||
}
|
||||
if ( !m_windowWidth.isValid() || m_windowWidth.value() < CalamaresUtils::windowMinimumWidth )
|
||||
m_windowWidth = WindowDimension( CalamaresUtils::windowPreferredWidth, WindowDimensionUnit::Pixies );
|
||||
if ( !m_windowHeight.isValid() || m_windowHeight.value() < CalamaresUtils::windowMinimumHeight )
|
||||
m_windowHeight = WindowDimension( CalamaresUtils::windowPreferredHeight, WindowDimensionUnit::Pixies );
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "UiDllMacro.h"
|
||||
#include "Typedefs.h"
|
||||
|
||||
#include "utils/NamedSuffix.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
@ -78,6 +80,18 @@ public:
|
||||
|
||||
/** @brief Setting for how much the main window may expand. */
|
||||
enum class WindowExpansion { Normal, Fullscreen, Fixed } ;
|
||||
/** @brief Setting for the main window size.
|
||||
*
|
||||
* The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which
|
||||
* we suffix as "em", e.g. "600px" or "32em".
|
||||
*/
|
||||
enum class WindowDimensionUnit { None, Pixies, Fonties };
|
||||
class WindowDimension : public NamedSuffix<WindowDimensionUnit, WindowDimensionUnit::None>
|
||||
{
|
||||
public:
|
||||
using NamedSuffix::NamedSuffix;
|
||||
bool isValid() const;
|
||||
} ;
|
||||
|
||||
static Branding* instance();
|
||||
|
||||
@ -97,6 +111,10 @@ public:
|
||||
|
||||
bool welcomeStyleCalamares() const { return m_welcomeStyleCalamares; }
|
||||
bool welcomeExpandingLogo() const { return m_welcomeExpandingLogo; }
|
||||
QPair< WindowDimension, WindowDimension > windowSize() const
|
||||
{
|
||||
return QPair< WindowDimension, WindowDimension >( m_windowWidth, m_windowHeight );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a map called "branding" in the global storage, and inserts an
|
||||
@ -128,6 +146,9 @@ private:
|
||||
bool m_welcomeStyleCalamares;
|
||||
bool m_welcomeExpandingLogo;
|
||||
WindowExpansion m_windowExpansion;
|
||||
|
||||
WindowDimension m_windowHeight, m_windowWidth;
|
||||
|
||||
};
|
||||
|
||||
template<typename U> inline QString operator*(U e) { return Branding::instance()->string( e ); }
|
||||
|
Loading…
Reference in New Issue
Block a user