File indexing completed on 2025-04-27 03:58:25

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-08-22
0007  * Description : a generic widget to display a panel to choose
0008  *               a rectangular image area.
0009  *
0010  * SPDX-FileCopyrightText: 1997      by Tim D. Gilman <tdgilman at best dot org>
0011  * SPDX-FileCopyrightText: 1998-2001 by Mirko Boehm <mirko at kde dot org>
0012  * SPDX-FileCopyrightText: 2007      by John Layt <john at layt dot net>
0013  * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0014  *
0015  * SPDX-License-Identifier: GPL-2.0-or-later
0016  *
0017  * ============================================================ */
0018 
0019 #ifndef DIGIKAM_PAN_ICON_WIDGET_H
0020 #define DIGIKAM_PAN_ICON_WIDGET_H
0021 
0022 // Qt includes
0023 
0024 #include <QWidget>
0025 #include <QRect>
0026 #include <QImage>
0027 #include <QPixmap>
0028 #include <QHideEvent>
0029 #include <QMouseEvent>
0030 #include <QTimerEvent>
0031 #include <QPaintEvent>
0032 #include <QFrame>
0033 
0034 // Local includes
0035 
0036 #include "digikam_export.h"
0037 #include "dimg.h"
0038 
0039 class QToolButton;
0040 
0041 namespace Digikam
0042 {
0043 
0044 /**
0045  * Frame with popup menu behavior to host PanIconWidget.
0046  */
0047 class DIGIKAM_EXPORT PanIconFrame : public QFrame
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052 
0053     explicit PanIconFrame(QWidget* const parent = nullptr);
0054     ~PanIconFrame() override;
0055 
0056     /**
0057      * Set the main widget. You cannot set the main widget from the constructor,
0058      * since it must be a child of the frame itselfes.
0059      * Be careful: the size is set to the main widgets size. It is up to you to
0060      * set the main widgets correct size before setting it as the main
0061      * widget.
0062      */
0063     void setMainWidget(QWidget* const main);
0064 
0065     /**
0066      * Open the popup window at position pos.
0067      */
0068     void popup(const QPoint& pos);
0069 
0070     /**
0071      * Execute the popup window.
0072      */
0073     int exec(const QPoint& pos);
0074 
0075     /**
0076      * Execute the popup window.
0077      */
0078     int exec(int x, int y);
0079 
0080     /**
0081      * The resize event. Simply resizes the main widget to the whole
0082      * widgets client size.
0083      */
0084     void resizeEvent(QResizeEvent* resize)  override;
0085 
0086 Q_SIGNALS:
0087 
0088     void leaveModality();
0089 
0090 protected:
0091 
0092     /**
0093      * Catch key press events.
0094      */
0095     void keyPressEvent(QKeyEvent* e)        override;
0096 
0097 public Q_SLOTS:
0098 
0099     /**
0100      * Close the popup window. This is called from the main widget, usually.
0101      * @p r is the result returned from exec().
0102      */
0103     void close(int r);
0104 
0105 private:
0106 
0107     class Private;
0108     friend class Private;
0109     Private* const d;
0110 
0111     Q_DISABLE_COPY(PanIconFrame)
0112 };
0113 
0114 // ---------------------------------------------------------------------------------
0115 
0116 class DIGIKAM_EXPORT PanIconWidget : public QWidget
0117 {
0118     Q_OBJECT
0119 
0120 public:
0121 
0122     explicit PanIconWidget(QWidget* const parent = nullptr);
0123     ~PanIconWidget()                        override;
0124 
0125     static QToolButton* button();
0126 
0127     void setImage(int previewWidth, int previewHeight, const QImage& fullOriginalImage);
0128     void setImage(int previewWidth, int previewHeight, const DImg& fullOriginalImage);
0129     void setImage(const QImage& scaledPreviewImage, const QSize& fullImageSize);
0130 
0131     void  setRegionSelection(const QRect& regionSelection);
0132     QRect getRegionSelection() const;
0133     void  setCenterSelection();
0134 
0135     void  setCursorToLocalRegionSelectionCenter();
0136     void  setMouseFocus();
0137 
0138 Q_SIGNALS:
0139 
0140     /**
0141      * Emitted when selection have been moved with mouse.
0142      * 'targetDone' boolean value is used for indicate if the mouse have been released.
0143      */
0144     void signalSelectionMoved(const QRect& rect, bool targetDone);
0145 
0146     void signalSelectionTakeFocus();
0147 
0148     void signalHidden();
0149 
0150 public Q_SLOTS:
0151 
0152     void slotZoomFactorChanged(double);
0153 
0154 protected:
0155 
0156     void showEvent(QShowEvent*)             override;
0157     void hideEvent(QHideEvent*)             override;
0158     void paintEvent(QPaintEvent*)           override;
0159     void mousePressEvent(QMouseEvent*)      override;
0160     void mouseReleaseEvent(QMouseEvent*)    override;
0161     void mouseMoveEvent(QMouseEvent*)       override;
0162 
0163     /**
0164      * Recalculate the target selection position and emit 'signalSelectionMoved'.
0165      */
0166     void regionSelectionMoved(bool targetDone);
0167 
0168 protected Q_SLOTS:
0169 
0170     void slotFlickerTimer();
0171 
0172 private:
0173 
0174     class Private;
0175     Private* const d;
0176 };
0177 
0178 } // namespace Digikam
0179 
0180 #endif // DIGIKAM_PAN_ICON_WIDGET_H