File indexing completed on 2024-05-12 04:39:20
0001 /* 0002 SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "checklistitemproxystyle.h" 0008 0009 // plugin 0010 #include "checklistmodel.h" 0011 // Qt 0012 #include <QPainter> 0013 #include <QIcon> 0014 #include <QStyleOptionViewItem> 0015 0016 namespace ClangTidy 0017 { 0018 0019 void CheckListItemProxyStyle::drawPrimitive(QStyle::PrimitiveElement element, 0020 const QStyleOption* option, QPainter* painter, 0021 const QWidget* widget) const 0022 { 0023 Q_UNUSED(widget); 0024 if (element == QStyle::PE_IndicatorItemViewItemCheck) { 0025 auto* optionViewItem = static_cast<const QStyleOptionViewItem*>(option); 0026 drawCheckBox(painter, optionViewItem); 0027 return; 0028 } 0029 0030 QProxyStyle::drawPrimitive(element, option, painter); 0031 } 0032 0033 void CheckListItemProxyStyle::drawCheckBox(QPainter* painter, const QStyleOptionViewItem* option) const 0034 { 0035 QString iconName; 0036 const auto checkState = option->checkState; 0037 if (checkState == Qt::PartiallyChecked) { 0038 const int effectiveEnabledState = option->index.data(CheckListModel::EffectiveEnabledStateRole).toInt(); 0039 if (effectiveEnabledState != CheckGroup::Enabled) { 0040 return; 0041 } 0042 iconName = QStringLiteral("dialog-ok"); 0043 } else { 0044 iconName = (checkState == Qt::Unchecked) ? QStringLiteral("emblem-remove") : QStringLiteral("emblem-added"); 0045 } 0046 0047 const auto icon = QIcon::fromTheme(iconName); 0048 0049 const QIcon::Mode iconMode = (option->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled; 0050 0051 icon.paint(painter, option->rect, option->decorationAlignment, iconMode, QIcon::On); 0052 } 0053 0054 } 0055 0056 #include "moc_checklistitemproxystyle.cpp"