File indexing completed on 2025-01-05 03:51:10

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-04-19
0007  * Description : Qt model-view for face item - the delegate
0008  *
0009  * SPDX-FileCopyrightText: 2002-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2002-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2009-2010 by Andi Clemens <andi dot clemens at gmail dot com>
0012  * SPDX-FileCopyrightText: 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #include "itemfacedelegate.h"
0019 #include "itemdelegate_p.h"
0020 
0021 // Local includes
0022 
0023 #include "digikam_debug.h"
0024 #include "applicationsettings.h"
0025 #include "facetagsiface.h"
0026 #include "itemmodel.h"
0027 #include "tagregion.h"
0028 #include "digikamitemdelegate_p.h"
0029 #include "faceutils.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 ItemFaceDelegate::ItemFaceDelegate(ItemCategorizedView* const parent)
0035     : DigikamItemDelegate(*new ItemFaceDelegatePrivate, parent)
0036 {
0037 }
0038 
0039 ItemFaceDelegate::~ItemFaceDelegate()
0040 {
0041 }
0042 
0043 QPixmap ItemFaceDelegate::thumbnailPixmap(const QModelIndex& index) const
0044 {
0045     QRect rect = largerFaceRect(index);
0046 
0047     if (rect.isNull())
0048     {
0049         return DigikamItemDelegate::thumbnailPixmap(index);
0050     }
0051 
0052     // set requested thumbnail detail
0053 
0054     if (rect.isValid())
0055     {
0056         const_cast<QAbstractItemModel*>(index.model())->setData(index, rect, ItemModel::ThumbnailRole);
0057     }
0058 
0059     // parent implementation already resets the thumb size and rect set on model
0060 
0061     QPixmap pix = DigikamItemDelegate::thumbnailPixmap(index);
0062 
0063     if (!pix.isNull() && face(index).isUnconfirmedName())
0064     {
0065         QPainter greenBorder(&pix);
0066         greenBorder.setPen(QPen(Qt::green, 4));
0067         greenBorder.drawRect(2, 2, pix.width() - 4, pix.height() - 4);
0068         greenBorder.end();
0069     }
0070 
0071     return pix;
0072 }
0073 
0074 QRect ItemFaceDelegate::faceRect(const QModelIndex& index) const
0075 {
0076     return face(index).region().toRect();
0077 }
0078 
0079 QRect ItemFaceDelegate::largerFaceRect(const QModelIndex& index) const
0080 {
0081     QRect rect = faceRect(index);
0082 
0083     if (rect.isNull())
0084     {
0085         return rect;
0086     }
0087 
0088     return FaceUtils::faceRectToDisplayRect(rect);
0089 }
0090 
0091 FaceTagsIface ItemFaceDelegate::face(const QModelIndex& index)
0092 {
0093     QVariant extraData = index.data(ItemModel::ExtraDataRole);
0094 
0095     if (extraData.isNull())
0096     {
0097         return FaceTagsIface();
0098     }
0099 
0100     return FaceTagsIface::fromVariant(extraData);
0101 }
0102 
0103 void ItemFaceDelegate::updateRects()
0104 {
0105     Q_D(ItemFaceDelegate);
0106     DigikamItemDelegate::updateRects();
0107     d->groupRect = QRect();
0108 }
0109 
0110 void ItemFaceDelegate::clearModelDataCaches()
0111 {
0112     DigikamItemDelegate::clearModelDataCaches();
0113 }
0114 
0115 } // namespace Digikam
0116 
0117 #include "moc_itemfacedelegate.cpp"