File indexing completed on 2024-06-02 04:17:02

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 "showfotocoordinatesoverlay.h"
0016 
0017 // KDE includes
0018 
0019 #include <klocalizedstring.h>
0020 
0021 // Local includes
0022 
0023 #include "digikam_debug.h"
0024 #include "showfotodelegate.h"
0025 #include "showfotoitemmodel.h"
0026 #include "showfotocategorizedview.h"
0027 
0028 namespace ShowFoto
0029 {
0030 
0031 ShowfotoCoordinatesOverlayWidget::ShowfotoCoordinatesOverlayWidget(QWidget* const parent)
0032     : QAbstractButton(parent)
0033 {
0034 }
0035 
0036 void ShowfotoCoordinatesOverlayWidget::paintEvent(QPaintEvent*)
0037 {
0038 }
0039 
0040 // -----------------------------------------------------------------------------------------
0041 
0042 ShowfotoCoordinatesOverlay::ShowfotoCoordinatesOverlay(QObject* const parent)
0043     : AbstractWidgetDelegateOverlay(parent)
0044 {
0045 }
0046 
0047 ShowfotoCoordinatesOverlayWidget* ShowfotoCoordinatesOverlay::buttonWidget() const
0048 {
0049     return static_cast<ShowfotoCoordinatesOverlayWidget*>(m_widget);
0050 }
0051 
0052 QWidget* ShowfotoCoordinatesOverlay::createWidget()
0053 {
0054     QAbstractButton* const button = new ShowfotoCoordinatesOverlayWidget(parentWidget());
0055 /*
0056     button->setCursor(Qt::PointingHandCursor);
0057 */
0058     return button;
0059 }
0060 
0061 void ShowfotoCoordinatesOverlay::setActive(bool active)
0062 {
0063     AbstractWidgetDelegateOverlay::setActive(active);
0064 }
0065 
0066 void ShowfotoCoordinatesOverlay::visualChange()
0067 {
0068     if (m_widget && m_widget->isVisible())
0069     {
0070         updatePosition();
0071     }
0072 }
0073 
0074 void ShowfotoCoordinatesOverlay::updatePosition()
0075 {
0076     if (!m_index.isValid())
0077     {
0078         return;
0079     }
0080 
0081     QRect rect       = static_cast<ShowfotoDelegate*>(delegate())->coordinatesIndicatorRect();
0082     QRect visualRect = m_view->visualRect(m_index);
0083     rect.translate(visualRect.topLeft());
0084 
0085     m_widget->setFixedSize(rect.width() + 1, rect.height() + 1);
0086     m_widget->move(rect.topLeft());
0087 }
0088 
0089 bool ShowfotoCoordinatesOverlay::checkIndex(const QModelIndex& index) const
0090 {
0091     ShowfotoItemInfo info = ShowfotoItemModel::retrieveShowfotoItemInfo(index);
0092     QRect rect            = static_cast<ShowfotoDelegate*>(delegate())->coordinatesIndicatorRect();
0093 
0094     if (!rect.isNull() && info.photoInfo.hasCoordinates)
0095     {
0096         m_widget->setToolTip(i18nc("@info:tooltip", "This item has geolocation information."));
0097 
0098         return true;
0099     }
0100 
0101     // If info.hasCoordinates() = false, no need to show a tooltip, because there is no icon over thumbnail.
0102 
0103     return false;
0104 }
0105 
0106 void ShowfotoCoordinatesOverlay::slotEntered(const QModelIndex& index)
0107 {
0108     AbstractWidgetDelegateOverlay::slotEntered(index);
0109     m_index = index;
0110     updatePosition();
0111 }
0112 
0113 } // namespace ShowFoto
0114 
0115 #include "moc_showfotocoordinatesoverlay.cpp"