From fdc2cff65afbb11e106fe44954e833d0c5815ce5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 May 2019 13:36:27 +0200 Subject: [PATCH 1/4] [calamares] Keep text on a single line - In the sidepane, don't wrap long texts --- src/calamares/progresstree/ProgressTreeDelegate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 9c6a400f6..5c83b70fd 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -113,5 +113,5 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, } painter->fillRect( option.rect, painter->brush().color() ); - painter->drawText( textRect, index.data().toString() ); + painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString() ); } From 0f30acc13f7f33363d47989ca6c5ab0dbfa28bdc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 May 2019 13:45:08 +0200 Subject: [PATCH 2/4] [calamares] Fix off-center text in sidepane - The text rectangle was **moved**, not shrunk-in-place. Add the missing - sign for the right and bottom margin. - While here, move from #define to constexpr. --- .../progresstree/ProgressTreeDelegate.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 5c83b70fd..9e21255d0 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -31,8 +31,8 @@ #include #include -#define ITEM_MARGIN 12 -#define VS_FONTSIZE CalamaresUtils::defaultFontSize() + 4 +static constexpr int const item_margin = 8; +static inline int item_fontsize() { return CalamaresUtils::defaultFontSize() + 4; } ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent ) : QStyledItemDelegate( parent ) @@ -50,11 +50,11 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, QFont font = qApp->font(); - font.setPointSize( VS_FONTSIZE ); + font.setPointSize( item_fontsize() ); QFontMetrics fm( font ); int height = fm.height(); - height += 2*ITEM_MARGIN; //margin + height += 2 * item_margin; return QSize( option.rect.width(), height ); } @@ -88,12 +88,9 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { - QRect textRect = option.rect.adjusted( ITEM_MARGIN, - ITEM_MARGIN, - ITEM_MARGIN, - ITEM_MARGIN ); + QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin ); QFont font = qApp->font(); - font.setPointSize( VS_FONTSIZE ); + font.setPointSize( item_fontsize() ); font.setBold( false ); painter->setFont( font ); From dc8cfd2fcef87198b06c5ff2462fd746d7a38c66 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 May 2019 14:14:20 +0200 Subject: [PATCH 3/4] [calamares] Fit text into sidepane - Shrink the font in an attempt to fit into the box, but only up to 4pt smaller; after that just clip on one line. --- .../progresstree/ProgressTreeDelegate.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 9e21255d0..331c8c481 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -109,6 +109,32 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, painter->setBrush( QColor( textHighlight ) ); } - painter->fillRect( option.rect, painter->brush().color() ); - painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, 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 ); } From f7494864becca1e16068457f81615b9c9fd7beca Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 6 May 2019 14:21:02 +0200 Subject: [PATCH 4/4] [calamares] Tidying after fixing fit-text-in-sidepane - Simplify delegate: unused m_parent, tidy up inheritance, then drop unnecessary custom constructor and extra Q_OBJECT macro. - Drop some unnecessary included headers - Drop single-use #define. APP was used in only one place; remove it (that would be stylistically correct, anyway). - Update copyright headers - Document new label-handling --- CHANGES | 3 +++ src/calamares/CalamaresApplication.h | 4 +--- .../progresstree/ProgressTreeDelegate.cpp | 16 +++------------- .../progresstree/ProgressTreeDelegate.h | 7 ++----- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index beb545688..03d630654 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,9 @@ This release contains contributions from (alphabetically by first name): ## 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 PythonQt was found. This led to the odd situation where the non-GUI Calamares library depends on a bunch of GUI libraries. diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index f9c919aa6..71778813e 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018-2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,8 +24,6 @@ #include -#define APP CalamaresApplication::instance() - class CalamaresWindow; namespace Calamares diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 331c8c481..67dfeebda 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,29 +18,19 @@ */ #include "ProgressTreeDelegate.h" +#include "ProgressTreeModel.h" #include "Branding.h" #include "CalamaresApplication.h" #include "CalamaresWindow.h" -#include "ProgressTreeModel.h" -#include "ViewManager.h" -#include "ViewStepItem.h" #include "utils/CalamaresUtilsGui.h" -#include #include static constexpr int const item_margin = 8; static inline int item_fontsize() { return CalamaresUtils::defaultFontSize() + 4; } -ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent ) - : QStyledItemDelegate( parent ) - , m_parent( parent ) -{ -} - - QSize ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const @@ -104,7 +94,7 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, QString textHighlight = Calamares::Branding::instance()-> styleString( Calamares::Branding::SidebarTextHighlight ); if ( textHighlight.isEmpty() ) - painter->setBrush( APP->mainWindow()->palette().background() ); + painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().background() ); else painter->setBrush( QColor( textHighlight ) ); } diff --git a/src/calamares/progresstree/ProgressTreeDelegate.h b/src/calamares/progresstree/ProgressTreeDelegate.h index 371f5193f..83b281696 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.h +++ b/src/calamares/progresstree/ProgressTreeDelegate.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2019, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +22,6 @@ #include - /** * @brief The ProgressTreeDelegate class customizes the look and feel of the * ProgressTreeView elements. @@ -29,9 +29,8 @@ */ class ProgressTreeDelegate : public QStyledItemDelegate { - Q_OBJECT public: - explicit ProgressTreeDelegate( QAbstractItemView* parent = nullptr ); + using QStyledItemDelegate::QStyledItemDelegate; protected: QSize sizeHint( const QStyleOptionViewItem& option, @@ -44,8 +43,6 @@ private: void paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - - QAbstractItemView* m_parent; }; #endif // PROGRESSTREEDELEGATE_H