File indexing completed on 2025-01-05 04:00:09
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-11-15 0007 * Description : widget item delegate for setup collection view 0008 * 0009 * SPDX-FileCopyrightText: 2015-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2007-2008 by Rafael Fernández López <ereslibre at kde dot org> 0011 * SPDX-FileCopyrightText: 2008 by Kevin Ottens <ervin at kde dot org> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "dwitemdelegate_p.h" 0018 0019 // Qt includes 0020 0021 #include <QSize> 0022 #include <QTimer> 0023 #include <QTreeView> 0024 #include <QApplication> 0025 #include <QAbstractItemView> 0026 0027 // Local includes 0028 0029 #include "dwitemdelegatepool.h" 0030 0031 namespace Digikam 0032 { 0033 0034 DWItemDelegate::DWItemDelegate(QAbstractItemView* const itemView, QObject* const parent) 0035 : QAbstractItemDelegate(parent), 0036 d (new DWItemDelegatePrivate(this)) 0037 { 0038 Q_ASSERT(itemView); 0039 0040 itemView->setMouseTracking(true); 0041 itemView->viewport()->setAttribute(Qt::WA_Hover); 0042 0043 d->itemView = itemView; 0044 0045 itemView->viewport()->installEventFilter(d); // mouse events 0046 itemView->installEventFilter(d); // keyboard events 0047 0048 if (qobject_cast<QTreeView*>(itemView)) 0049 { 0050 connect(itemView, SIGNAL(collapsed(QModelIndex)), 0051 d, SLOT(initializeModel())); 0052 0053 connect(itemView, SIGNAL(expanded(QModelIndex)), 0054 d, SLOT(initializeModel())); 0055 } 0056 } 0057 0058 DWItemDelegate::~DWItemDelegate() 0059 { 0060 delete d; 0061 } 0062 0063 QAbstractItemView* DWItemDelegate::itemView() const 0064 { 0065 return d->itemView; 0066 } 0067 0068 QPersistentModelIndex DWItemDelegate::focusedIndex() const 0069 { 0070 const QPersistentModelIndex idx = d->widgetPool->d->widgetInIndex.value(QApplication::focusWidget()); 0071 0072 if (idx.isValid()) 0073 { 0074 return idx; 0075 } 0076 0077 // Use the mouse position, if the widget refused to take keyboard focus. 0078 0079 const QPoint pos = d->itemView->viewport()->mapFromGlobal(QCursor::pos()); 0080 0081 return d->itemView->indexAt(pos); 0082 } 0083 0084 void DWItemDelegate::setBlockedEventTypes(QWidget* const widget, const QList<QEvent::Type>& types) const 0085 { 0086 widget->setProperty("DigiKam:blockedEventTypes", QVariant::fromValue(types)); 0087 } 0088 0089 QList<QEvent::Type> DWItemDelegate::blockedEventTypes(QWidget* const widget) const 0090 { 0091 return widget->property("Digikam:blockedEventTypes").value<QList<QEvent::Type> >(); 0092 } 0093 0094 } // namespace Digikam 0095 0096 #include "moc_dwitemdelegate.cpp"