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-30 0007 * Description : selection icon view item at mouse hover 0008 * 0009 * SPDX-FileCopyrightText: 2008 by Peter Penz <peter dot penz at gmx dot at> 0010 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "facerejectionoverlay.h" 0017 0018 // KDE includes 0019 0020 #include <klocalizedstring.h> 0021 0022 // Local includes 0023 0024 #include "itemcategorizedview.h" 0025 #include "itemfacedelegate.h" 0026 #include "itemmodel.h" 0027 0028 namespace Digikam 0029 { 0030 0031 FaceRejectionOverlayButton::FaceRejectionOverlayButton(QAbstractItemView* const parentView) 0032 : ItemViewHoverButton(parentView) 0033 { 0034 setup(); 0035 } 0036 0037 QSize FaceRejectionOverlayButton::sizeHint() const 0038 { 0039 return QSize(32, 32); 0040 } 0041 0042 QIcon FaceRejectionOverlayButton::icon() 0043 { 0044 return QIcon::fromTheme(QLatin1String("window-close")); 0045 } 0046 0047 void FaceRejectionOverlayButton::updateToolTip() 0048 { 0049 setToolTip(i18nc("@info:tooltip", "If this is not a face, click to delete it.")); 0050 } 0051 0052 // -------------------------------------------------------------------- 0053 0054 FaceRejectionOverlay::FaceRejectionOverlay(QObject* const parent) 0055 : HoverButtonDelegateOverlay(parent) 0056 { 0057 } 0058 0059 void FaceRejectionOverlay::setActive(bool active) 0060 { 0061 HoverButtonDelegateOverlay::setActive(active); 0062 0063 if (active) 0064 { 0065 connect(button(), SIGNAL(clicked(bool)), 0066 this, SLOT(slotClicked())); 0067 } 0068 else 0069 { 0070 // button is deleted 0071 } 0072 } 0073 0074 ItemViewHoverButton* FaceRejectionOverlay::createButton() 0075 { 0076 return new FaceRejectionOverlayButton(view()); 0077 } 0078 0079 void FaceRejectionOverlay::updateButton(const QModelIndex& index) 0080 { 0081 const QRect rect = m_view->visualRect(index); 0082 const int size = qBound(16, rect.width() / 8 - 2, 48); 0083 const int gap = 5; 0084 const int x = rect.right() - gap - size; 0085 const int y = rect.top() + gap; 0086 button()->resize(size, size); 0087 button()->move(QPoint(x, y)); 0088 } 0089 0090 void FaceRejectionOverlay::slotClicked() 0091 { 0092 QModelIndex index = button()->index(); 0093 0094 if (index.isValid()) 0095 { 0096 Q_EMIT rejectFaces(affectedIndexes(index)); 0097 } 0098 } 0099 0100 bool FaceRejectionOverlay::checkIndex(const QModelIndex& index) const 0101 { 0102 return !index.data(ItemModel::ExtraDataRole).isNull(); 0103 } 0104 0105 void FaceRejectionOverlay::widgetEnterEvent() 0106 { 0107 widgetEnterNotifyMultiple(button()->index()); 0108 } 0109 0110 void FaceRejectionOverlay::widgetLeaveEvent() 0111 { 0112 widgetLeaveNotifyMultiple(); 0113 } 0114 0115 } // namespace Digikam 0116 0117 #include "moc_facerejectionoverlay.cpp"