[welcome] Very basic model delegate for results / requirements
This commit is contained in:
parent
e757639669
commit
7686b89cd6
@ -21,6 +21,7 @@ calamares_add_plugin(welcome
|
||||
SOURCES
|
||||
checker/CheckerContainer.cpp
|
||||
checker/GeneralRequirements.cpp
|
||||
checker/ResultDelegate.cpp
|
||||
checker/ResultWidget.cpp
|
||||
checker/ResultsListWidget.cpp
|
||||
${PARTMAN_SRC}
|
||||
|
88
src/modules/welcome/checker/ResultDelegate.cpp
Normal file
88
src/modules/welcome/checker/ResultDelegate.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2022 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ResultDelegate.h"
|
||||
|
||||
#include "modulesystem/RequirementsModel.h"
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
static constexpr int const item_margin = 8;
|
||||
static inline int
|
||||
item_fontsize()
|
||||
{
|
||||
return CalamaresUtils::defaultFontSize() + 4;
|
||||
}
|
||||
|
||||
static void
|
||||
paintRequirement( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index )
|
||||
{
|
||||
QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
|
||||
QFont font = qApp->font();
|
||||
font.setPointSize( item_fontsize() );
|
||||
font.setBold( false );
|
||||
painter->setFont( font );
|
||||
|
||||
if ( index.data( Calamares::RequirementsModel::Satisfied ).toBool() )
|
||||
{
|
||||
painter->setBrush( QColorConstants::Green );
|
||||
painter->setPen( QColorConstants::Black );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( index.data( Calamares::RequirementsModel::Mandatory ).toBool() )
|
||||
{
|
||||
painter->setPen( QColorConstants::Red );
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setPen( QColorConstants::Blue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
painter->drawText( textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString() );
|
||||
}
|
||||
|
||||
QSize
|
||||
ResultDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
{
|
||||
return option.rect.size();
|
||||
}
|
||||
|
||||
QFont font = qApp->font();
|
||||
|
||||
font.setPointSize( item_fontsize() );
|
||||
QFontMetrics fm( font );
|
||||
int height = fm.height();
|
||||
|
||||
height += 2 * item_margin;
|
||||
|
||||
return QSize( option.rect.width(), height );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ResultDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
QStyleOptionViewItem opt = option;
|
||||
|
||||
painter->save();
|
||||
|
||||
initStyleOption( &opt, index );
|
||||
opt.text.clear();
|
||||
|
||||
paintRequirement( painter, opt, index );
|
||||
|
||||
painter->restore();
|
||||
}
|
28
src/modules/welcome/checker/ResultDelegate.h
Normal file
28
src/modules/welcome/checker/ResultDelegate.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2022 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WELCOME_CHECKER_RESULTDELEGATE_HH
|
||||
#define WELCOME_CHECKER_RESULTDELEGATE_HH
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
/**
|
||||
* @brief Class for drawing (un)satisfied requirements
|
||||
*/
|
||||
class ResultDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
using QStyledItemDelegate::QStyledItemDelegate;
|
||||
|
||||
protected:
|
||||
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
||||
};
|
||||
|
||||
#endif // PROGRESSTREEDELEGATE_H
|
Loading…
Reference in New Issue
Block a user