File indexing completed on 2025-01-19 03:59:21
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-08-21 0007 * Description : Overlays for the import interface 0008 * 0009 * SPDX-FileCopyrightText: 2012 by Islam Wazery <wazery at ubuntu dot com> 0010 * SPDX-FileCopyrightText: 2012-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 #ifndef DIGIKAM_IMPORT_OVERLAYS_H 0017 #define DIGIKAM_IMPORT_OVERLAYS_H 0018 0019 // Qt includes 0020 0021 #include <QAbstractButton> 0022 #include <QAbstractItemView> 0023 0024 // Local includes 0025 0026 #include "itemviewhoverbutton.h" 0027 #include "itemdelegateoverlay.h" 0028 #include "itemviewimportdelegate.h" 0029 #include "ratingwidget.h" 0030 0031 namespace Digikam 0032 { 0033 0034 class ImportOverlayWidget : public QAbstractButton 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 0040 explicit ImportOverlayWidget(QWidget* const parent = nullptr); 0041 0042 protected: 0043 0044 void paintEvent(QPaintEvent*) override; 0045 }; 0046 0047 // -------------------------------------------------------------------- 0048 0049 class ImportCoordinatesOverlay : public AbstractWidgetDelegateOverlay 0050 { 0051 Q_OBJECT 0052 REQUIRE_DELEGATE(ItemViewImportDelegate) 0053 0054 public: 0055 0056 explicit ImportCoordinatesOverlay(QObject* const parent); 0057 ImportOverlayWidget* buttonWidget() const; 0058 0059 protected: 0060 0061 void updatePosition(); 0062 0063 QWidget* createWidget() override; 0064 void setActive(bool active) override; 0065 void visualChange() override; 0066 bool checkIndex(const QModelIndex& index) const override; 0067 void slotEntered(const QModelIndex& index) override; 0068 0069 protected: 0070 0071 QPersistentModelIndex m_index; 0072 }; 0073 0074 // -------------------------------------------------------------------- 0075 0076 class ImportLockOverlay : public AbstractWidgetDelegateOverlay 0077 { 0078 Q_OBJECT 0079 REQUIRE_DELEGATE(ItemViewImportDelegate) 0080 0081 public: 0082 0083 explicit ImportLockOverlay(QObject* const parent); 0084 ImportOverlayWidget* buttonWidget() const; 0085 0086 protected: 0087 0088 void updatePosition(); 0089 0090 QWidget* createWidget() override; 0091 void setActive(bool active) override; 0092 void visualChange() override; 0093 bool checkIndex(const QModelIndex& index) const override; 0094 void slotEntered(const QModelIndex& index) override; 0095 0096 protected: 0097 0098 QPersistentModelIndex m_index; 0099 }; 0100 0101 // -------------------------------------------------------------------- 0102 0103 class ImportDownloadOverlay : public AbstractWidgetDelegateOverlay 0104 { 0105 Q_OBJECT 0106 REQUIRE_DELEGATE(ItemViewImportDelegate) 0107 0108 public: 0109 0110 explicit ImportDownloadOverlay(QObject* const parent); 0111 ImportOverlayWidget* buttonWidget() const; 0112 0113 protected: 0114 0115 void updatePosition(); 0116 0117 QWidget* createWidget() override; 0118 void setActive(bool active) override; 0119 void visualChange() override; 0120 bool checkIndex(const QModelIndex& index) const override; 0121 void slotEntered(const QModelIndex& index) override; 0122 0123 protected: 0124 0125 QPersistentModelIndex m_index; 0126 }; 0127 0128 // ------------------------------------------------------------------------------------------------ 0129 0130 class ImportRatingOverlay : public AbstractWidgetDelegateOverlay 0131 { 0132 Q_OBJECT 0133 REQUIRE_DELEGATE(ItemViewImportDelegate) 0134 0135 public: 0136 0137 explicit ImportRatingOverlay(QObject* const parent); 0138 RatingWidget* ratingWidget() const; 0139 0140 Q_SIGNALS: 0141 0142 void ratingEdited(const QList<QModelIndex>& indexes, int rating); 0143 0144 protected Q_SLOTS: 0145 0146 void slotRatingChanged(int); 0147 void slotDataChanged(const QModelIndex&, const QModelIndex&); 0148 0149 protected: 0150 0151 QWidget* createWidget() override; 0152 void setActive(bool) override; 0153 void visualChange() override; 0154 void hide() override; 0155 void slotEntered(const QModelIndex& index) override; 0156 void widgetEnterEvent() override; 0157 void widgetLeaveEvent() override; 0158 0159 void updatePosition(); 0160 void updateRating(); 0161 0162 protected: 0163 0164 QPersistentModelIndex m_index; 0165 }; 0166 0167 // ------------------------------------------------------------------------------------------------ 0168 0169 enum ImportRotateOverlayDirection 0170 { 0171 ImportRotateOverlayLeft, 0172 ImportRotateOverlayRight 0173 }; 0174 0175 class ImportRotateOverlayButton : public ItemViewHoverButton 0176 { 0177 Q_OBJECT 0178 0179 public: 0180 0181 explicit ImportRotateOverlayButton(ImportRotateOverlayDirection dir, QAbstractItemView* const parentView); 0182 QSize sizeHint() const override; 0183 0184 protected: 0185 0186 QIcon icon() override; 0187 void updateToolTip() override; 0188 0189 protected: 0190 0191 ImportRotateOverlayDirection const m_direction; 0192 }; 0193 0194 // -------------------------------------------------------------------- 0195 0196 class ImportRotateOverlay : public HoverButtonDelegateOverlay 0197 { 0198 Q_OBJECT 0199 0200 public: 0201 0202 explicit ImportRotateOverlay(ImportRotateOverlayDirection dir, QObject* const parent); 0203 void setActive(bool active) override; 0204 0205 ImportRotateOverlayDirection direction() const { return m_direction; } 0206 bool isLeft() const { return m_direction == ImportRotateOverlayLeft; } 0207 bool isRight() const { return m_direction == ImportRotateOverlayRight; } 0208 0209 static ImportRotateOverlay* left (QObject* const parent) { return new ImportRotateOverlay(ImportRotateOverlayLeft, parent); } 0210 static ImportRotateOverlay* right(QObject* const parent) { return new ImportRotateOverlay(ImportRotateOverlayRight, parent); } 0211 0212 Q_SIGNALS: 0213 0214 void signalRotate(const QList<QModelIndex>& indexes); 0215 0216 protected: 0217 0218 ItemViewHoverButton* createButton() override; 0219 void updateButton(const QModelIndex& index) override; 0220 bool checkIndex(const QModelIndex& index) const override; 0221 void widgetEnterEvent() override; 0222 void widgetLeaveEvent() override; 0223 0224 private Q_SLOTS: 0225 0226 void slotClicked(); 0227 0228 private: 0229 0230 ImportRotateOverlayDirection const m_direction; 0231 }; 0232 0233 } // namespace Digikam 0234 0235 #endif // DIGIKAM_IMPORT_OVERLAYS_H