Clean up overuse of literals for GUI constants.

Add CalamaresStyle for colors and other style constants and helpers.
Add static functions for font size.
main
Teo Mrnjavac 11 years ago
parent f10f2026ad
commit 52028d95f9

@ -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() );
}

@ -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 <QBoxLayout>
#include <QLabel>
@ -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 );
}

@ -23,10 +23,16 @@
#include "ViewStepItem.h"
#include "ProgressTreeModel.h"
#include "ViewManager.h"
#include "utils/CalamaresStyle.h"
#include "utils/CalamaresUtilsGui.h"
#include <QAbstractItemView>
#include <QPainter>
#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() );
}

@ -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 );
}

@ -0,0 +1,34 @@
/* === 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";
} // namespace CalamaresStyle
#endif // CALAMARESSTYLE_H

@ -18,11 +18,17 @@
#include "CalamaresUtilsGui.h"
#include <QFont>
#include <QFontMetrics>
#include <QLayout>
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 );
}
}

@ -22,6 +22,8 @@
#include "utils/CalamaresUtils.h"
#include "UiDllMacro.h"
#include <QSize>
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

Loading…
Cancel
Save