Merge pull request #211 from calamares/branding-style

Eliminate CalamaresStyle and get style constants from Branding instead.
This commit is contained in:
Teo Mrnjavac 2015-03-20 16:37:36 +01:00
commit 19715c2ab1
7 changed files with 52 additions and 44 deletions

View File

@ -15,3 +15,8 @@ images:
productIcon: "squid.png" productIcon: "squid.png"
slideshow: "show.qml" slideshow: "show.qml"
style:
sidebarBackground: "#292F34"
sidebarText: "#FFFFFF"
sidebarTextSelect: "#292F34"

View File

@ -21,7 +21,6 @@
#include "ViewManager.h" #include "ViewManager.h"
#include "progresstree/ProgressTreeView.h" #include "progresstree/ProgressTreeView.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/CalamaresStyle.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/DebugWindow.h" #include "utils/DebugWindow.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
@ -71,8 +70,10 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
{ {
QPalette plt = sideBox->palette(); QPalette plt = sideBox->palette();
sideBox->setAutoFillBackground( true ); sideBox->setAutoFillBackground( true );
plt.setColor( sideBox->backgroundRole(), CalamaresStyle::SIDEBAR_BACKGROUND ); plt.setColor( sideBox->backgroundRole(), Calamares::Branding::instance()->
plt.setColor( sideBox->foregroundRole(), CalamaresStyle::SIDEBAR_TEXT ); styleString( Calamares::Branding::SidebarBackground ) );
plt.setColor( sideBox->foregroundRole(), Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarText ) );
sideBox->setPalette( plt ); sideBox->setPalette( plt );
logoLabel->setPalette( plt ); logoLabel->setPalette( plt );
} }

View File

@ -23,7 +23,7 @@
#include "ViewStepItem.h" #include "ViewStepItem.h"
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "utils/CalamaresStyle.h" #include "Branding.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include <QAbstractItemView> #include <QAbstractItemView>
@ -82,8 +82,10 @@ ProgressTreeDelegate::paint( QPainter* painter,
initStyleOption( &opt, index ); initStyleOption( &opt, index );
opt.text.clear(); opt.text.clear();
painter->setBrush( CalamaresStyle::SIDEBAR_BACKGROUND ); painter->setBrush( QColor( Calamares::Branding::instance()->
painter->setPen( CalamaresStyle::SIDEBAR_TEXT ); styleString( Calamares::Branding::SidebarBackground ) ) );
painter->setPen( QColor( Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarText ) ) );
if ( isFirstLevel ) if ( isFirstLevel )
paintCategory( painter, opt, index ); paintCategory( painter, opt, index );
@ -135,7 +137,8 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
if ( isCurrent ) if ( isCurrent )
{ {
painter->setPen( CalamaresStyle::SIDEBAR_TEXT_SELECT ); painter->setPen( Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarTextSelect ) );
painter->setBrush( APP->mainWindow()->palette().background() ); painter->setBrush( APP->mainWindow()->palette().background() );
} }

View File

@ -20,7 +20,7 @@
#include "ProgressTreeDelegate.h" #include "ProgressTreeDelegate.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "utils/CalamaresStyle.h" #include "Branding.h"
ProgressTreeView* ProgressTreeView::s_instance = nullptr; ProgressTreeView* ProgressTreeView::s_instance = nullptr;
@ -54,7 +54,8 @@ ProgressTreeView::ProgressTreeView( QWidget* parent )
setItemDelegate( m_delegate ); setItemDelegate( m_delegate );
QPalette plt = palette(); QPalette plt = palette();
plt.setColor( QPalette::Base, CalamaresStyle::SIDEBAR_BACKGROUND ); plt.setColor( QPalette::Base, Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarBackground ) );
setPalette( plt ); setPalette( plt );
} }

View File

@ -62,6 +62,13 @@ QStringList Branding::s_imageEntryStrings =
"productIcon" "productIcon"
}; };
QStringList Branding::s_styleEntryStrings =
{
"sidebarBackground",
"sidebarText",
"sidebarTextSelect"
};
Branding::Branding( const QString& brandingFilePath, Branding::Branding( const QString& brandingFilePath,
QObject* parent ) QObject* parent )
@ -146,6 +153,15 @@ Branding::Branding( const QString& brandingFilePath,
} }
else else
bail( "Syntax error in slideshow sequence." ); bail( "Syntax error in slideshow sequence." );
if ( !doc[ "style" ].IsMap() )
bail( "Syntax error in style map." );
QVariantMap style =
CalamaresUtils::yamlMapToVariant( doc[ "style" ] ).toMap();
m_style.clear();
for ( auto it = style.constBegin(); it != style.constEnd(); ++it )
m_style.insert( it.key(), it.value().toString() );
} }
catch ( YAML::Exception& e ) catch ( YAML::Exception& e )
@ -192,6 +208,13 @@ Branding::string( Branding::StringEntry stringEntry ) const
} }
QString
Branding::styleString( Branding::StyleEntry styleEntry ) const
{
return m_style.value( s_styleEntryStrings.value( styleEntry ) );
}
QString QString
Branding::imagePath( Branding::ImageEntry imageEntry ) const Branding::imagePath( Branding::ImageEntry imageEntry ) const
{ {

View File

@ -52,6 +52,13 @@ public:
ProductLogo, ProductLogo,
ProductIcon ProductIcon
}; };
enum StyleEntry : short
{
SidebarBackground,
SidebarText,
SidebarTextSelect
};
static Branding* instance(); static Branding* instance();
@ -63,6 +70,7 @@ public:
QString componentDirectory() const; QString componentDirectory() const;
QString string( Branding::StringEntry stringEntry ) const; QString string( Branding::StringEntry stringEntry ) const;
QString styleString( Branding::StyleEntry styleEntry ) const;
QString imagePath( Branding::ImageEntry imageEntry ) const; QString imagePath( Branding::ImageEntry imageEntry ) const;
QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const; QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const;
QString slideshowPath() const; QString slideshowPath() const;
@ -79,6 +87,7 @@ private:
static QStringList s_stringEntryStrings; static QStringList s_stringEntryStrings;
static QStringList s_imageEntryStrings; static QStringList s_imageEntryStrings;
static QStringList s_styleEntryStrings;
void bail( const QString& message ); void bail( const QString& message );
@ -86,6 +95,7 @@ private:
QString m_componentName; QString m_componentName;
QMap< QString, QString > m_strings; QMap< QString, QString > m_strings;
QMap< QString, QString > m_images; QMap< QString, QString > m_images;
QMap< QString, QString > m_style;
QString m_slideshowPath; QString m_slideshowPath;
}; };

View File

@ -1,35 +0,0 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CALAMARESSTYLE_H
#define CALAMARESSTYLE_H
#include "../UiDllMacro.h"
#include <QColor>
namespace CalamaresStyle {
static const QColor SIDEBAR_BACKGROUND = "#292F34";
static const QColor SIDEBAR_TEXT = "#FFFFFF";
static const QColor SIDEBAR_TEXT_SELECT = "#292F34";
} // namespace CalamaresStyle
#endif // CALAMARESSTYLE_H