Merge branch 'issue-1137'

FIXES #1137
This commit is contained in:
Adriaan de Groot 2019-05-06 14:32:39 +02:00
commit c933eda610
4 changed files with 43 additions and 32 deletions

View File

@ -14,6 +14,9 @@ This release contains contributions from (alphabetically by first name):
## Core ## ## Core ##
- The side-pane, which shows the list of steps that will be executed,
now tries to fit the text (name of each module) into the available space
by shrinking the font as needed. #1137
- *libcalamares* (accidentally) linked with Qt's GUI libraries when - *libcalamares* (accidentally) linked with Qt's GUI libraries when
PythonQt was found. This led to the odd situation where the non-GUI PythonQt was found. This led to the odd situation where the non-GUI
Calamares library depends on a bunch of GUI libraries. Calamares library depends on a bunch of GUI libraries.

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2018, Adriaan de Groot <groot@kde.org> * Copyright 2018-2019, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -24,8 +24,6 @@
#include <QApplication> #include <QApplication>
#define APP CalamaresApplication::instance()
class CalamaresWindow; class CalamaresWindow;
namespace Calamares namespace Calamares

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org> * Copyright 2017, 2019, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,28 +18,18 @@
*/ */
#include "ProgressTreeDelegate.h" #include "ProgressTreeDelegate.h"
#include "ProgressTreeModel.h"
#include "Branding.h" #include "Branding.h"
#include "CalamaresApplication.h" #include "CalamaresApplication.h"
#include "CalamaresWindow.h" #include "CalamaresWindow.h"
#include "ProgressTreeModel.h"
#include "ViewManager.h"
#include "ViewStepItem.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include <QAbstractItemView>
#include <QPainter> #include <QPainter>
#define ITEM_MARGIN 12 static constexpr int const item_margin = 8;
#define VS_FONTSIZE CalamaresUtils::defaultFontSize() + 4 static inline int item_fontsize() { return CalamaresUtils::defaultFontSize() + 4; }
ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent )
: QStyledItemDelegate( parent )
, m_parent( parent )
{
}
QSize QSize
ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option,
@ -50,11 +40,11 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option,
QFont font = qApp->font(); QFont font = qApp->font();
font.setPointSize( VS_FONTSIZE ); font.setPointSize( item_fontsize() );
QFontMetrics fm( font ); QFontMetrics fm( font );
int height = fm.height(); int height = fm.height();
height += 2*ITEM_MARGIN; //margin height += 2 * item_margin;
return QSize( option.rect.width(), height ); return QSize( option.rect.width(), height );
} }
@ -88,12 +78,9 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
const QStyleOptionViewItem& option, const QStyleOptionViewItem& option,
const QModelIndex& index ) const const QModelIndex& index ) const
{ {
QRect textRect = option.rect.adjusted( ITEM_MARGIN, QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
ITEM_MARGIN,
ITEM_MARGIN,
ITEM_MARGIN );
QFont font = qApp->font(); QFont font = qApp->font();
font.setPointSize( VS_FONTSIZE ); font.setPointSize( item_fontsize() );
font.setBold( false ); font.setBold( false );
painter->setFont( font ); painter->setFont( font );
@ -107,11 +94,37 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
QString textHighlight = Calamares::Branding::instance()-> QString textHighlight = Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarTextHighlight ); styleString( Calamares::Branding::SidebarTextHighlight );
if ( textHighlight.isEmpty() ) if ( textHighlight.isEmpty() )
painter->setBrush( APP->mainWindow()->palette().background() ); painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().background() );
else else
painter->setBrush( QColor( textHighlight ) ); painter->setBrush( QColor( textHighlight ) );
} }
painter->fillRect( option.rect, painter->brush().color() );
painter->drawText( textRect, index.data().toString() ); // Draw the text at least once. If it doesn't fit, then shrink the font
// being used by 1 pt on each iteration, up to a maximum of maximumShrink
// times. On each loop, we'll have to blank out the rectangle again, so this
// is an expensive (in terms of drawing operations) thing to do.
//
// (The loop uses <= because the counter is incremented at the start).
static constexpr int const maximumShrink = 4;
int shrinkSteps = 0;
do
{
painter->fillRect( option.rect, painter->brush().color() );
shrinkSteps++;
QRectF boundingBox;
painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox );
// The extra check here is to avoid the changing-font-size if we're not going to use
// it in the next iteration of the loop anyway.
if ( ( shrinkSteps <= maximumShrink ) && (boundingBox.width() > textRect.width() ) )
{
font.setPointSize( item_fontsize() - shrinkSteps );
painter->setFont( font );
}
else
break; // It fits
}
while ( shrinkSteps <= maximumShrink );
} }

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2019, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,7 +22,6 @@
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
/** /**
* @brief The ProgressTreeDelegate class customizes the look and feel of the * @brief The ProgressTreeDelegate class customizes the look and feel of the
* ProgressTreeView elements. * ProgressTreeView elements.
@ -29,9 +29,8 @@
*/ */
class ProgressTreeDelegate : public QStyledItemDelegate class ProgressTreeDelegate : public QStyledItemDelegate
{ {
Q_OBJECT
public: public:
explicit ProgressTreeDelegate( QAbstractItemView* parent = nullptr ); using QStyledItemDelegate::QStyledItemDelegate;
protected: protected:
QSize sizeHint( const QStyleOptionViewItem& option, QSize sizeHint( const QStyleOptionViewItem& option,
@ -44,8 +43,6 @@ private:
void paintViewStep( QPainter* painter, void paintViewStep( QPainter* painter,
const QStyleOptionViewItem& option, const QStyleOptionViewItem& option,
const QModelIndex& index ) const; const QModelIndex& index ) const;
QAbstractItemView* m_parent;
}; };
#endif // PROGRESSTREEDELEGATE_H #endif // PROGRESSTREEDELEGATE_H