source: calamares/trunk/fuentes/src/calamares/progresstree/ProgressTreeDelegate.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 3.6 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "ProgressTreeDelegate.h"
21
22#include "../CalamaresApplication.h"
23#include "../CalamaresWindow.h"
24#include "ViewStepItem.h"
25#include "ProgressTreeModel.h"
26#include "ViewManager.h"
27#include "Branding.h"
28#include "utils/CalamaresUtilsGui.h"
29
30#include <QAbstractItemView>
31#include <QPainter>
32
33#define ITEM_MARGIN 12
34#define VS_FONTSIZE CalamaresUtils::defaultFontSize() + 4
35
36ProgressTreeDelegate::ProgressTreeDelegate( QAbstractItemView* parent )
37    : QStyledItemDelegate( parent )
38    , m_parent( parent )
39{
40}
41
42
43QSize
44ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option,
45                                const QModelIndex& index ) const
46{
47    if ( !index.isValid() )
48        return option.rect.size();
49
50    QFont font = qApp->font();
51
52    font.setPointSize( VS_FONTSIZE );
53    QFontMetrics fm( font );
54    int height = fm.height();
55
56    height += 2*ITEM_MARGIN; //margin
57
58    return QSize( option.rect.width(), height );
59}
60
61
62void
63ProgressTreeDelegate::paint( QPainter* painter,
64                             const QStyleOptionViewItem& option,
65                             const QModelIndex& index) const
66{
67    QStyleOptionViewItem opt = option;
68
69    painter->save();
70
71    initStyleOption( &opt, index );
72    opt.text.clear();
73
74    painter->setBrush( QColor( Calamares::Branding::instance()->
75        styleString( Calamares::Branding::SidebarBackground ) ) );
76    painter->setPen( QColor( Calamares::Branding::instance()->
77        styleString( Calamares::Branding::SidebarText ) ) );
78
79    paintViewStep( painter, opt, index );
80
81    painter->restore();
82}
83
84
85void
86ProgressTreeDelegate::paintViewStep( QPainter* painter,
87                                     const QStyleOptionViewItem& option,
88                                     const QModelIndex& index ) const
89{
90    QRect textRect = option.rect.adjusted( ITEM_MARGIN,
91                                           ITEM_MARGIN,
92                                           ITEM_MARGIN,
93                                           ITEM_MARGIN );
94    QFont font = qApp->font();
95    font.setPointSize( VS_FONTSIZE );
96    font.setBold( false );
97    painter->setFont( font );
98
99    bool isCurrent = false;
100    isCurrent = index.data( ProgressTreeModel::ProgressTreeItemCurrentRole ).toBool();
101
102    if ( isCurrent )
103    {
104        painter->setPen( Calamares::Branding::instance()->
105                         styleString( Calamares::Branding::SidebarTextSelect ) );
106        QString textHighlight = Calamares::Branding::instance()->
107                           styleString( Calamares::Branding::SidebarTextHighlight );
108        if ( textHighlight.isEmpty() )
109            painter->setBrush( APP->mainWindow()->palette().background() );
110        else
111            painter->setBrush( QColor( textHighlight ) );
112    }
113
114    painter->fillRect( option.rect, painter->brush().color() );
115    painter->drawText( textRect, index.data().toString() );
116}
Note: See TracBrowser for help on using the repository browser.