File indexing completed on 2025-04-27 03:58:29
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-04-30 0007 * Description : Qt item view mouse hover button 0008 * 0009 * SPDX-FileCopyrightText: 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_ITEM_VIEW_HOVER_BUTTON_H 0016 #define DIGIKAM_ITEM_VIEW_HOVER_BUTTON_H 0017 0018 // Qt includes 0019 0020 #include <QAbstractButton> 0021 #include <QAbstractItemView> 0022 0023 // Local includes 0024 0025 #include "digikam_export.h" 0026 0027 class QTimeLine; 0028 0029 namespace Digikam 0030 { 0031 0032 class DIGIKAM_EXPORT ItemViewHoverButton : public QAbstractButton 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 0038 explicit ItemViewHoverButton(QAbstractItemView* const parentView); 0039 0040 void initIcon(); 0041 void reset(); 0042 void setIndex(const QModelIndex& index); 0043 QModelIndex index() const; 0044 void setVisible(bool visible) override; 0045 0046 /** 0047 * Reimplement to match the size of your icon 0048 */ 0049 QSize sizeHint() const override = 0; 0050 0051 protected: 0052 0053 /** 0054 * to call in children class constructors to init signal/slot connections. 0055 */ 0056 void setup(); 0057 0058 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0059 0060 void enterEvent(QEnterEvent* event); 0061 0062 #else 0063 0064 void enterEvent(QEvent* event); 0065 0066 #endif 0067 0068 void leaveEvent(QEvent* event); 0069 void paintEvent(QPaintEvent* event); 0070 0071 /** 0072 * Return your icon here. Will be queried again on toggle. 0073 */ 0074 virtual QIcon icon() = 0; 0075 0076 /** 0077 * Optionally update tooltip here. Will be called again on state change. 0078 */ 0079 virtual void updateToolTip(); 0080 0081 protected Q_SLOTS: 0082 0083 void setFadingValue(int value); 0084 void refreshIcon(); 0085 void startFading(); 0086 void stopFading(); 0087 0088 protected: 0089 0090 QPersistentModelIndex m_index; 0091 bool m_isHovered; 0092 int m_fadingValue; 0093 QIcon m_icon; 0094 QTimeLine* m_fadingTimeLine; 0095 }; 0096 0097 } // namespace Digikam 0098 0099 #endif // DIGIKAM_ITEM_VIEW_HOVER_BUTTON_H