-/***************************************************************************
- * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "kstandarditemlistwidget.h"
maximumRequiredWidth = fontMetrics.horizontalAdvance(itemText(index, view));
} else {
const QHash<QByteArray, QVariant>& values = view->model()->data(index);
- foreach (const QByteArray& role, visibleRoles) {
+ for (const QByteArray& role : visibleRoles) {
const QString& text = roleText(role, values);
const qreal requiredWidth = fontMetrics.horizontalAdvance(text);
maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth);
}
const KItemListStyleOption& itemListStyleOption = styleOption();
- if (isHovered()) {
+ if (isHovered() && !m_pixmap.isNull()) {
if (hoverOpacity() < 1.0) {
/*
* Linear interpolation between m_pixmap and m_hoverPixmap.
} else {
drawPixmap(painter, m_hoverPixmap);
}
- } else {
+ } else if (!m_pixmap.isNull()) {
drawPixmap(painter, m_pixmap);
}
QSet<QByteArray> dirtyRoles;
if (roles.isEmpty()) {
- dirtyRoles = visibleRoles().toSet();
+ const auto visibleRoles = this->visibleRoles();
+ dirtyRoles = QSet<QByteArray>(visibleRoles.constBegin(), visibleRoles.constEnd());
} else {
dirtyRoles = roles;
}
QGraphicsView* parent = scene()->views()[0];
if (current.isEmpty() || !parent || current != "text") {
if (m_roleEditor) {
- emit roleEditingCanceled(index(), current, data().value(current));
+ Q_EMIT roleEditingCanceled(index(), current, data().value(current));
disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled,
this, &KStandardItemListWidget::slotRoleEditingCanceled);
const QVariant& value)
{
closeRoleEditor();
- emit roleEditingCanceled(index(), role, value);
+ Q_EMIT roleEditingCanceled(index(), role, value);
setEditedRole(QByteArray());
}
const QVariant& value)
{
closeRoleEditor();
- emit roleEditingFinished(index(), role, value);
+ Q_EMIT roleEditingFinished(index(), role, value);
setEditedRole(QByteArray());
}
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight) * qApp->devicePixelRatio());
}
+ if (m_pixmap.isNull()) {
+ m_hoverPixmap = QPixmap();
+ return;
+ }
+
if (m_isCut) {
KIconEffect* effect = KIconLoader::global()->iconEffect();
m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState);
if (m_layout == IconsLayout && isSelected()) {
const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
QImage image = m_pixmap.toImage();
+ if (image.isNull()) {
+ m_hoverPixmap = QPixmap();
+ return;
+ }
KIconEffect::colorize(image, color, 0.8f);
m_pixmap = QPixmap::fromImage(image);
}
// Calculate the position for each additional information
qreal y = nameTextInfo->pos.y() + nameHeight;
- foreach (const QByteArray& role, m_sortedVisibleRoles) {
+ for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) {
if (role == "text") {
continue;
}
const qreal x = option.padding * 3 + scaledIconSize;
qreal y = qRound((widgetHeight - textLinesHeight) / 2);
const qreal maxWidth = size().width() - x - option.padding;
- foreach (const QByteArray& role, m_sortedVisibleRoles) {
+ for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) {
const QString text = roleText(role, values);
TextInfo* textInfo = m_textInfo.value(role);
textInfo->staticText.setText(text);
qreal x = firstColumnInc;
const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2);
- foreach (const QByteArray& role, m_sortedVisibleRoles) {
+ for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) {
QString text = roleText(role, values);
// Elide the text in case it does not fit into the available column-width
QPixmap pixmap;
if (!QPixmapCache::find(key, &pixmap)) {
- const QIcon icon = QIcon::fromTheme(name, fallbackIcon);
+ QIcon icon = QIcon::fromTheme(name);
+ if (icon.isNull()) {
+ icon = QIcon(name);
+ }
+ if (icon.isNull()) {
+ icon = fallbackIcon;
+ }
pixmap = icon.pixmap(size / qApp->devicePixelRatio(), size / qApp->devicePixelRatio(), mode);
if (pixmap.width() != size || pixmap.height() != size) {
// It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional
// setup time.
- foreach (const QString& overlay, overlays) {
+ for (const QString& overlay : overlays) {
if (!overlay.isEmpty()) {
int state = KIconLoader::DefaultState;