File indexing completed on 2025-01-19 03:50:50
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2013-03-02 0007 * Description : Table view: Tree view subelement 0008 * 0009 * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2013 by Michael G. Hansen <mike at mghansen dot de> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "tableview_treeview_delegate.h" 0017 0018 // Qt includes 0019 0020 0021 // Local includes 0022 0023 #include "digikam_debug.h" 0024 #include "contextmenuhelper.h" 0025 #include "coredbfields.h" 0026 #include "coredbwatch.h" 0027 #include "fileactionmngr.h" 0028 #include "iteminfo.h" 0029 #include "itemmodel.h" 0030 #include "itemposition.h" 0031 #include "importfiltermodel.h" 0032 #include "importimagemodel.h" 0033 #include "importui.h" 0034 #include "tableview_column_configuration_dialog.h" 0035 #include "tableview_model.h" 0036 #include "tableview_selection_model_syncer.h" 0037 0038 namespace Digikam 0039 { 0040 0041 TableViewItemDelegate::TableViewItemDelegate(TableViewShared* const tableViewShared, QObject* const parent) 0042 : QItemDelegate(parent), 0043 s (tableViewShared) 0044 { 0045 } 0046 0047 TableViewItemDelegate::~TableViewItemDelegate() 0048 { 0049 } 0050 0051 void TableViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& tableViewModelIndex) const 0052 { 0053 const int columnIndex = tableViewModelIndex.column(); 0054 const int columnCount = s->tableViewModel->columnCount(QModelIndex()); 0055 0056 if ((columnIndex < 0) || (columnIndex >= columnCount)) 0057 { 0058 QItemDelegate::paint(painter, option, tableViewModelIndex); 0059 return; 0060 } 0061 0062 TableViewColumn* const columnObject = s->tableViewModel->getColumnObject(columnIndex); 0063 bool useDefaultPainter = !columnObject->getColumnFlags().testFlag(TableViewColumn::ColumnCustomPainting); 0064 0065 if (!useDefaultPainter) 0066 { 0067 TableViewModel::Item* const item = s->tableViewModel->itemFromIndex(tableViewModelIndex); 0068 useDefaultPainter = !columnObject->paint(painter, option, item); 0069 } 0070 0071 if (useDefaultPainter) 0072 { 0073 QItemDelegate::paint(painter, option, tableViewModelIndex); 0074 } 0075 } 0076 0077 QSize TableViewItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& tableViewModelIndex) const 0078 { 0079 const int columnIndex = tableViewModelIndex.column(); 0080 0081 /// we have to take the maximum of all columns for the height 0082 /// @todo somehow cache this calculation 0083 /// @todo check column flags 0084 0085 const int columnCount = s->tableViewModel->columnCount(QModelIndex()); 0086 TableViewModel::Item* const item = s->tableViewModel->itemFromIndex(tableViewModelIndex); 0087 int maxHeight = 0; 0088 0089 if ((columnIndex < 0) || (columnIndex >= columnCount)) 0090 { 0091 return QItemDelegate::sizeHint(option, tableViewModelIndex); 0092 } 0093 0094 for (int i = 0 ; i < columnCount ; ++i) 0095 { 0096 TableViewColumn* const iColumnObject = s->tableViewModel->getColumnObject(i); 0097 0098 if (iColumnObject && item) 0099 { 0100 const QSize iColumnSize = iColumnObject->sizeHint(option, item); 0101 0102 if (iColumnSize.isValid()) 0103 { 0104 maxHeight = qMax(maxHeight, iColumnSize.height()); 0105 } 0106 } 0107 } 0108 0109 QSize columnSize; 0110 TableViewColumn* const columnObject = s->tableViewModel->getColumnObject(columnIndex); 0111 0112 if (columnObject && item) 0113 { 0114 columnSize = columnObject->sizeHint(option, item); 0115 } 0116 0117 if (!columnSize.isValid()) 0118 { 0119 columnSize = QItemDelegate::sizeHint(option, tableViewModelIndex); 0120 0121 /// @todo we have to incorporate the height given by QItemDelegate for the other columns, too 0122 0123 maxHeight = qMax(maxHeight, columnSize.height()); 0124 } 0125 0126 return QSize(columnSize.width(), maxHeight); 0127 } 0128 0129 } // namespace Digikam 0130 0131 #include "moc_tableview_treeview_delegate.cpp"