File indexing completed on 2024-04-14 15:42:35
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Rafael Fernández López <ereslibre@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "CategorizedView.h" 0007 0008 #include <KFileItemDelegate> 0009 0010 #include <QScrollBar> 0011 0012 CategorizedView::CategorizedView(QWidget *parent) 0013 : KCategorizedView(parent) 0014 { 0015 setStyle(new ActivateItemOnSingleClickStyle(style())); 0016 setWordWrap(true); 0017 } 0018 0019 void CategorizedView::setModel(QAbstractItemModel *model) 0020 { 0021 KCategorizedView::setModel(model); 0022 int maxWidth = -1; 0023 int maxHeight = -1; 0024 for (int i = 0; i < model->rowCount(); ++i) { 0025 const QModelIndex index = model->index(i, modelColumn(), rootIndex()); 0026 const QSize size = sizeHintForIndex(index); 0027 maxWidth = qMax(maxWidth, size.width()); 0028 maxHeight = qMax(maxHeight, size.height()); 0029 } 0030 setGridSize(QSize(maxWidth, maxHeight)); 0031 static_cast<KFileItemDelegate *>(itemDelegate())->setMaximumSize(QSize(maxWidth, maxHeight)); 0032 } 0033 0034 void CategorizedView::wheelEvent(QWheelEvent *event) 0035 { 0036 // this is a workaround because scrolling by mouse wheel is broken in Qt list views for big items 0037 // https://bugreports.qt-project.org/browse/QTBUG-7232 0038 verticalScrollBar()->setSingleStep(10); 0039 KCategorizedView::wheelEvent(event); 0040 }