File indexing completed on 2025-01-05 03:51:11
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-05-31 0007 * Description : rotate icon view item at mouse hover 0008 * 0009 * SPDX-FileCopyrightText: 2009-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 "itemrotationoverlay.h" 0016 0017 // KDE includes 0018 0019 #include <klocalizedstring.h> 0020 0021 // Local includes 0022 0023 #include "itemcategorizedview.h" 0024 #include "iteminfo.h" 0025 #include "itemmodel.h" 0026 0027 namespace Digikam 0028 { 0029 0030 ItemRotateOverlayButton::ItemRotateOverlayButton(ItemRotateOverlayDirection dir, QAbstractItemView* const parentView) 0031 : ItemViewHoverButton(parentView), 0032 m_direction (dir) 0033 { 0034 setup(); 0035 } 0036 0037 QSize ItemRotateOverlayButton::sizeHint() const 0038 { 0039 return QSize(32, 32); 0040 } 0041 0042 QIcon ItemRotateOverlayButton::icon() 0043 { 0044 if (m_direction == ItemRotateOverlayLeft) 0045 { 0046 return QIcon::fromTheme(QLatin1String("object-rotate-left")); 0047 } 0048 else 0049 { 0050 return QIcon::fromTheme(QLatin1String("object-rotate-right")); 0051 } 0052 } 0053 0054 void ItemRotateOverlayButton::updateToolTip() 0055 { 0056 if (m_direction == ItemRotateOverlayLeft) 0057 { 0058 setToolTip(i18nc("@info:tooltip", "Rotate Left")); 0059 } 0060 else 0061 { 0062 setToolTip(i18nc("@info:tooltip", "Rotate Right")); 0063 } 0064 } 0065 0066 // -------------------------------------------------------------------- 0067 0068 ItemRotateOverlay::ItemRotateOverlay(ItemRotateOverlayDirection dir, QObject* const parent) 0069 : HoverButtonDelegateOverlay(parent), 0070 m_direction (dir) 0071 { 0072 } 0073 0074 void ItemRotateOverlay::setActive(bool active) 0075 { 0076 HoverButtonDelegateOverlay::setActive(active); 0077 0078 if (active) 0079 { 0080 connect(button(), SIGNAL(clicked(bool)), 0081 this, SLOT(slotClicked())); 0082 } 0083 0084 // if !active, button() is deleted 0085 } 0086 0087 ItemViewHoverButton* ItemRotateOverlay::createButton() 0088 { 0089 return new ItemRotateOverlayButton(m_direction, view()); 0090 } 0091 0092 void ItemRotateOverlay::updateButton(const QModelIndex& index) 0093 { 0094 const QRect rect = m_view->visualRect(index); 0095 const int size = qBound(16, rect.width() / 8 - 2, 48); 0096 const int gap = 5; 0097 const int x = rect.right() - 2*gap - (isLeft() ? size*3 + 2 : size*2 + 2); 0098 const int y = rect.top() + gap; 0099 button()->resize(size, size); 0100 button()->move(QPoint(x, y)); 0101 } 0102 0103 void ItemRotateOverlay::slotClicked() 0104 { 0105 QModelIndex index = button()->index(); 0106 0107 if (index.isValid()) 0108 { 0109 /* 0110 QItemSelectionModel* selModel = m_view->selectionModel(); 0111 selModel->reset(); 0112 selModel->select(index, QItemSelectionModel::Select); 0113 selModel->setCurrentIndex(index, QItemSelectionModel::Current); 0114 */ 0115 Q_EMIT signalRotate(affectedIndexes(index)); 0116 } 0117 } 0118 0119 bool ItemRotateOverlay::checkIndex(const QModelIndex& index) const 0120 { 0121 ItemInfo info = ItemModel::retrieveItemInfo(index); 0122 0123 return ((info.category() == DatabaseItem::Image) || 0124 (info.category() == DatabaseItem::Video)); 0125 } 0126 0127 void ItemRotateOverlay::widgetEnterEvent() 0128 { 0129 widgetEnterNotifyMultiple(button()->index()); 0130 } 0131 0132 void ItemRotateOverlay::widgetLeaveEvent() 0133 { 0134 widgetLeaveNotifyMultiple(); 0135 } 0136 0137 } // namespace Digikam 0138 0139 #include "moc_itemrotationoverlay.cpp"