diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 89eb3f8a9..a6feaecd5 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -24,7 +24,7 @@ #include "progresstree/ProgressTreeModel.h" #include "modulesystem/ModuleManager.h" -#include "utils/CalamaresUtils.h" +#include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "Settings.h" #include "ViewManager.h" @@ -40,6 +40,18 @@ CalamaresApplication::CalamaresApplication( int& argc, char *argv[] ) setApplicationVersion( QLatin1String( CALAMARES_VERSION ) ); CalamaresUtils::installTranslator( this ); + + QFont f = font(); + + cDebug() << "Default font =====" + << "\nPixel size: " << f.pixelSize() + << "\nPoint size: " << f.pointSize() + << "\nPoint sizeF: " << f.pointSizeF() + << "\nFont family: " << f.family() + << "\nMetric height:" << QFontMetrics( f ).height(); + // The following line blocks for 15s on Qt 5.1.0 + cDebug() << "Font height:" << QFontMetrics( f ).height(); + CalamaresUtils::setDefaultFontSize( f.pointSize() ); } diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 405fa8abe..e9847f109 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -18,9 +18,10 @@ #include "CalamaresWindow.h" +#include "ViewManager.h" #include "progresstree/ProgressTreeView.h" #include "utils/CalamaresUtilsGui.h" -#include "ViewManager.h" +#include "utils/CalamaresStyle.h" #include #include @@ -51,8 +52,8 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) { QPalette plt = sideBox->palette(); sideBox->setAutoFillBackground( true ); - plt.setColor( sideBox->backgroundRole(), QColor( "#292F34" ) ); - plt.setColor( sideBox->foregroundRole(), Qt::white ); + plt.setColor( sideBox->backgroundRole(), CalamaresStyle::SIDEBAR_BACKGROUND ); + plt.setColor( sideBox->foregroundRole(), CalamaresStyle::SIDEBAR_TEXT ); sideBox->setPalette( plt ); logoLabel->setPalette( plt ); } diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 82417935f..5c9d472d1 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -23,10 +23,16 @@ #include "ViewStepItem.h" #include "ProgressTreeModel.h" #include "ViewManager.h" +#include "utils/CalamaresStyle.h" +#include "utils/CalamaresUtilsGui.h" #include #include +#define ITEM_MARGIN 12 +#define VS_FONTSIZE CalamaresUtils::defaultFontSize() + 2 +#define CAT_FONTSIZE CalamaresUtils::defaultFontSize() + 5 + ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent ) : QStyledItemDelegate( parent ) , m_parent( parent ) @@ -48,16 +54,16 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, if ( type == ProgressTreeModel::Category ) { - font.setPointSize( font.pointSize() + 5 ); + font.setPointSize( CAT_FONTSIZE ); } else if ( type == ProgressTreeModel::ViewStep ) { - font.setPointSize( font.pointSize() + 2 ); + font.setPointSize( VS_FONTSIZE ); } QFontMetrics fm( font ); int height = fm.height(); - height += 2*12; //margin + height += 2*ITEM_MARGIN; //margin return QSize( option.rect.width(), height ); } @@ -81,8 +87,8 @@ ProgressTreeDelegate::paint( QPainter* painter, initStyleOption( &opt, index ); opt.text.clear(); - painter->setBrush( QColor( "#292F34" ) ); - painter->setPen( QColor( "#FFFFFF" ) ); + painter->setBrush( CalamaresStyle::SIDEBAR_BACKGROUND ); + painter->setPen( CalamaresStyle::SIDEBAR_TEXT ); if ( type == ProgressTreeModel::Category ) paintCategory( painter, opt, index ); @@ -98,10 +104,13 @@ ProgressTreeDelegate::paintCategory( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { - QRect textRect = option.rect.adjusted( 12, 12, 12, 12 ); + QRect textRect = option.rect.adjusted( ITEM_MARGIN, + ITEM_MARGIN, + ITEM_MARGIN, + ITEM_MARGIN ); QFont font = qApp->font(); - font.setPointSize( font.pointSize() + 5 ); + font.setPointSize( CAT_FONTSIZE ); font.setBold( false ); painter->setFont( font ); @@ -114,9 +123,12 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { - QRect textRect = option.rect.adjusted( 12 + 32 /*indentation*/, 12, 12, 12 ); + QRect textRect = option.rect.adjusted( ITEM_MARGIN + 32 /*indentation*/, + ITEM_MARGIN, + ITEM_MARGIN, + ITEM_MARGIN ); QFont font = qApp->font(); - font.setPointSize( font.pointSize() + 2 ); + font.setPointSize( VS_FONTSIZE ); font.setBold( false ); painter->setFont( font ); @@ -125,7 +137,7 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, if ( isCurrent ) { - painter->setPen( QColor( "#292F34" ) ); + painter->setPen( CalamaresStyle::SIDEBAR_BACKGROUND ); painter->setBrush( APP->mainWindow()->palette().background() ); } diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp index 88ec5f9bb..37b47cf0e 100644 --- a/src/calamares/progresstree/ProgressTreeView.cpp +++ b/src/calamares/progresstree/ProgressTreeView.cpp @@ -20,6 +20,7 @@ #include "ProgressTreeDelegate.h" #include "ViewManager.h" +#include "utils/CalamaresStyle.h" ProgressTreeView* ProgressTreeView::s_instance = nullptr; @@ -53,7 +54,7 @@ ProgressTreeView::ProgressTreeView( QWidget* parent ) setItemDelegate( m_delegate ); QPalette plt = palette(); - plt.setColor( QPalette::Base, QColor( "#292F34" ) ); + plt.setColor( QPalette::Base, CalamaresStyle::SIDEBAR_BACKGROUND ); setPalette( plt ); } diff --git a/src/libcalamaresui/utils/CalamaresStyle.h b/src/libcalamaresui/utils/CalamaresStyle.h new file mode 100644 index 000000000..0520a2b56 --- /dev/null +++ b/src/libcalamaresui/utils/CalamaresStyle.h @@ -0,0 +1,34 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 . + */ + +#ifndef CALAMARESSTYLE_H +#define CALAMARESSTYLE_H + +#include "../UiDllMacro.h" + +#include + + +namespace CalamaresStyle { + +static const QColor SIDEBAR_BACKGROUND = "#292F34"; +static const QColor SIDEBAR_TEXT = "#FFFFFF"; + +} // namespace CalamaresStyle + +#endif // CALAMARESSTYLE_H diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 003d9d4e0..e43dc966c 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -18,11 +18,17 @@ #include "CalamaresUtilsGui.h" +#include +#include #include namespace CalamaresUtils { +static int s_defaultFontSize = 0; +static int s_defaultFontHeight = 0; + + void unmarginLayout( QLayout* layout ) { @@ -38,4 +44,41 @@ unmarginLayout( QLayout* layout ) } } + +int +defaultFontSize() +{ + return s_defaultFontSize; +} + + +int +defaultFontHeight() +{ + if ( s_defaultFontHeight <= 0 ) + { + QFont f; + f.setPointSize( defaultFontSize() ); + s_defaultFontHeight = QFontMetrics( f ).height(); + } + + return s_defaultFontHeight; +} + + +void +setDefaultFontSize( int points ) +{ + s_defaultFontSize = points; +} + + +QSize +defaultIconSize() +{ + const int w = defaultFontHeight() * 1.6; + return QSize( w, w ); +} + + } diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 5ae94374f..c835ddbf7 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -22,6 +22,8 @@ #include "utils/CalamaresUtils.h" #include "UiDllMacro.h" +#include + class QLayout; namespace CalamaresUtils @@ -29,6 +31,11 @@ namespace CalamaresUtils UIDLLEXPORT void unmarginLayout( QLayout* layout ); +DLLEXPORT void setDefaultFontSize( int points ); +DLLEXPORT int defaultFontSize(); +DLLEXPORT int defaultFontHeight(); +DLLEXPORT QSize defaultIconSize(); + } #endif // CALAMARESUTILSGUI_H