File indexing completed on 2024-04-21 16:29:35

0001 /***************************************************************************
0002  *   Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org>    *
0003  *   dantti12@gmail.com                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
0019  ***************************************************************************/
0020 
0021 #include "CategorizedView.h"
0022 
0023 #include "CategoryDrawer.h"
0024 
0025 #include <KFileItemDelegate>
0026 #include <QLoggingCategory>
0027 
0028 CategorizedView::CategorizedView(QWidget *parent)
0029     : KCategorizedView(parent)
0030 {
0031     setWordWrap(true);
0032     auto drawer = new CategoryDrawer(this);
0033     setCategoryDrawer(drawer);
0034 }
0035 
0036 void CategorizedView::setModel(QAbstractItemModel *model)
0037 {
0038     KCategorizedView::setModel(model);
0039 // Don't set a fixed grid as this breaks the layout. Let Qt figure out the size itself
0040 #if 0
0041     //     KFileItemDelegate *delegate = qobject_cast<KFileItemDelegate*>(itemDelegate());
0042 //     kDebug() << delegate->maximumSize();
0043 //     if (delegate) {
0044         int maxWidth = -1;
0045         int maxHeight = -1;
0046         for (int i = 0; i < model->rowCount(); ++i) {
0047             const QModelIndex index = model->index(i, modelColumn(), rootIndex());
0048             const QSize size = sizeHintForIndex(index);
0049             maxWidth = qMax(maxWidth, size.width());
0050             maxHeight = qMax(maxHeight, size.height());
0051 //             kDebug() << size << index.data(Qt::DisplayRole);
0052         }
0053 //          kDebug() << maxWidth << maxHeight;
0054         setGridSize(QSize(maxWidth, maxHeight ));
0055 //         delegate->setMaximumSize(QSize(maxWidth, maxHeight));
0056 // //     }
0057 #endif
0058 }
0059 
0060 #include "moc_CategorizedView.cpp"