File indexing completed on 2024-12-22 04:52:47
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "selectprogramlistwidget.h" 0008 0009 #include <KLocalizedString> 0010 #include <QPainter> 0011 0012 SelectProgramListWidget::SelectProgramListWidget(QWidget *parent) 0013 : QListWidget(parent) 0014 { 0015 } 0016 0017 SelectProgramListWidget::~SelectProgramListWidget() = default; 0018 0019 void SelectProgramListWidget::setNoProgramFound(bool noProgramFound) 0020 { 0021 mNoProgramFound = noProgramFound; 0022 } 0023 0024 void SelectProgramListWidget::generalPaletteChanged() 0025 { 0026 const QPalette palette = viewport()->palette(); 0027 QColor color = palette.text().color(); 0028 color.setAlpha(128); 0029 mTextColor = color; 0030 } 0031 0032 void SelectProgramListWidget::paintEvent(QPaintEvent *event) 0033 { 0034 if (mNoProgramFound && (!model() || model()->rowCount() == 0)) { 0035 QPainter p(viewport()); 0036 0037 QFont font = p.font(); 0038 font.setItalic(true); 0039 p.setFont(font); 0040 0041 if (!mTextColor.isValid()) { 0042 generalPaletteChanged(); 0043 } 0044 p.setPen(mTextColor); 0045 0046 p.drawText(QRect(0, 0, width(), height()), Qt::AlignCenter, i18n("No program found.")); 0047 } else { 0048 QListWidget::paintEvent(event); 0049 } 0050 } 0051 0052 #include "moc_selectprogramlistwidget.cpp"