File indexing completed on 2025-03-09 03:49:58
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2014-05-28 0007 * Description : overlay for GPS location indicator 0008 * 0009 * SPDX-FileCopyrightText: 2014-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "itemcoordinatesoverlay.h" 0016 0017 // KDE includes 0018 0019 #include <klocalizedstring.h> 0020 0021 // Local includes 0022 0023 #include "itemdelegate.h" 0024 #include "itemmodel.h" 0025 #include "itemcategorizedview.h" 0026 0027 namespace Digikam 0028 { 0029 0030 CoordinatesOverlayWidget::CoordinatesOverlayWidget(QWidget* const parent) 0031 : QAbstractButton(parent) 0032 { 0033 } 0034 0035 void CoordinatesOverlayWidget::paintEvent(QPaintEvent*) 0036 { 0037 } 0038 0039 // ----------------------------------------------------------------------------------------- 0040 0041 ItemCoordinatesOverlay::ItemCoordinatesOverlay(QObject* const parent) 0042 : AbstractWidgetDelegateOverlay(parent) 0043 { 0044 } 0045 0046 CoordinatesOverlayWidget* ItemCoordinatesOverlay::buttonWidget() const 0047 { 0048 return static_cast<CoordinatesOverlayWidget*>(m_widget); 0049 } 0050 0051 QWidget* ItemCoordinatesOverlay::createWidget() 0052 { 0053 QAbstractButton* const button = new CoordinatesOverlayWidget(parentWidget()); 0054 //button->setCursor(Qt::PointingHandCursor); 0055 return button; 0056 } 0057 0058 void ItemCoordinatesOverlay::setActive(bool active) 0059 { 0060 AbstractWidgetDelegateOverlay::setActive(active); 0061 } 0062 0063 void ItemCoordinatesOverlay::visualChange() 0064 { 0065 if (m_widget && m_widget->isVisible()) 0066 { 0067 updatePosition(); 0068 } 0069 } 0070 0071 void ItemCoordinatesOverlay::updatePosition() 0072 { 0073 if (!m_index.isValid()) 0074 { 0075 return; 0076 } 0077 0078 QRect rect = static_cast<ItemDelegate*>(delegate())->coordinatesIndicatorRect(); 0079 QRect visualRect = m_view->visualRect(m_index); 0080 rect.translate(visualRect.topLeft()); 0081 0082 m_widget->setFixedSize(rect.width() + 1, rect.height() + 1); 0083 m_widget->move(rect.topLeft()); 0084 } 0085 0086 bool ItemCoordinatesOverlay::checkIndex(const QModelIndex& index) const 0087 { 0088 ItemInfo info = ItemModel::retrieveItemInfo(index); 0089 QRect rect = static_cast<ItemDelegate*>(delegate())->coordinatesIndicatorRect(); 0090 0091 if (!rect.isNull() && info.hasCoordinates()) 0092 { 0093 m_widget->setToolTip(i18nc("@info:tooltip", "This item has geolocation information.")); 0094 return true; 0095 } 0096 0097 // If info.hasCoordinates() = false, no need to show a tooltip, because there is no icon over thumbnail. 0098 0099 return false; 0100 } 0101 0102 void ItemCoordinatesOverlay::slotEntered(const QModelIndex& index) 0103 { 0104 AbstractWidgetDelegateOverlay::slotEntered(index); 0105 m_index = index; 0106 updatePosition(); 0107 } 0108 0109 } // namespace Digikam 0110 0111 #include "moc_itemcoordinatesoverlay.cpp"