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 : 2015-08-30 0007 * Description : fullscreen overlay 0008 * 0009 * SPDX-FileCopyrightText: 2015 by Luca Carlon <carlon dot luca at gmail dot com> 0010 * SPDX-FileCopyrightText: 2015-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "itemfullscreenoverlay.h" 0017 0018 // KDE includes 0019 0020 #include <klocalizedstring.h> 0021 0022 // Local includes 0023 0024 #include "itemcategorizedview.h" 0025 #include "iteminfo.h" 0026 #include "itemmodel.h" 0027 0028 namespace Digikam 0029 { 0030 0031 ItemFullScreenOverlayButton::ItemFullScreenOverlayButton(QAbstractItemView* const parentView) 0032 : ItemViewHoverButton(parentView) 0033 { 0034 setup(); 0035 } 0036 0037 QSize ItemFullScreenOverlayButton::sizeHint() const 0038 { 0039 return QSize(32, 32); 0040 } 0041 0042 QIcon ItemFullScreenOverlayButton::icon() 0043 { 0044 return QIcon::fromTheme(QLatin1String("media-playback-start")); 0045 } 0046 0047 void ItemFullScreenOverlayButton::updateToolTip() 0048 { 0049 setToolTip(i18nc("@info:tooltip", "Show Fullscreen")); 0050 } 0051 0052 // -------------------------------------------------------------------- 0053 0054 ItemFullScreenOverlay::ItemFullScreenOverlay(QObject* const parent) 0055 : HoverButtonDelegateOverlay(parent) 0056 { 0057 } 0058 0059 ItemFullScreenOverlay* ItemFullScreenOverlay::instance(QObject* const parent) 0060 { 0061 return new ItemFullScreenOverlay(parent); 0062 } 0063 0064 void ItemFullScreenOverlay::setActive(bool active) 0065 { 0066 HoverButtonDelegateOverlay::setActive(active); 0067 0068 if (active) 0069 { 0070 connect(button(), SIGNAL(clicked(bool)), 0071 this, SLOT(slotClicked())); 0072 } 0073 0074 // if !active, button() is deleted 0075 } 0076 0077 ItemViewHoverButton* ItemFullScreenOverlay::createButton() 0078 { 0079 return new ItemFullScreenOverlayButton(view()); 0080 } 0081 0082 void ItemFullScreenOverlay::updateButton(const QModelIndex& index) 0083 { 0084 const QRect rect = m_view->visualRect(index); 0085 const int size = qBound(16, rect.width() / 8 - 2, 48); 0086 const int gap = 5; 0087 const int x = rect.right() - 3*gap - size*4 + 2; 0088 const int y = rect.top() + gap; 0089 button()->resize(size, size); 0090 button()->move(QPoint(x, y)); 0091 } 0092 0093 void ItemFullScreenOverlay::slotClicked() 0094 { 0095 QModelIndex index = button()->index(); 0096 0097 if (index.isValid()) 0098 { 0099 Q_EMIT signalFullscreen(affectedIndexes(index)); 0100 } 0101 } 0102 0103 bool ItemFullScreenOverlay::checkIndex(const QModelIndex& index) const 0104 { 0105 ItemInfo info = ItemModel::retrieveItemInfo(index); 0106 0107 return ((info.category() == DatabaseItem::Image) || 0108 (info.category() == DatabaseItem::Video)); 0109 } 0110 0111 void ItemFullScreenOverlay::widgetEnterEvent() 0112 { 0113 widgetEnterNotifyMultiple(button()->index()); 0114 } 0115 0116 void ItemFullScreenOverlay::widgetLeaveEvent() 0117 { 0118 widgetLeaveNotifyMultiple(); 0119 } 0120 0121 } // namespace Digikam 0122 0123 #include "moc_itemfullscreenoverlay.cpp"