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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-04-30
0007  * Description : Graphics View for DImg preview
0008  *
0009  * SPDX-FileCopyrightText: 2010-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2011-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_GRAPHICS_DIMG_VIEW_H
0017 #define DIGIKAM_GRAPHICS_DIMG_VIEW_H
0018 
0019 // Qt includes
0020 
0021 #include <QGraphicsView>
0022 
0023 // Local includes
0024 
0025 #include "digikam_export.h"
0026 
0027 namespace Digikam
0028 {
0029 
0030 class GraphicsDImgItem;
0031 class DImgPreviewItem;
0032 class SinglePhotoPreviewLayout;
0033 
0034 class DIGIKAM_EXPORT GraphicsDImgView : public QGraphicsView
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     explicit GraphicsDImgView(QWidget* const parent = nullptr);
0041     ~GraphicsDImgView() override;
0042 
0043     /**
0044      * Store internal instance of item as GraphicsDImgItem. You can store DImgPreviewItem object also by this method.
0045      * Use item() or previewItem() to get right version.
0046      * Note: if you store a GraphicsDImgItem object, previewItem() will return 0.
0047      */
0048     void setItem(GraphicsDImgItem* const item);
0049 
0050     /**
0051      * Return the instance of item set by setItem().
0052      */
0053     GraphicsDImgItem*         item()        const;
0054 
0055     /**
0056      * Return a cast of item instance of item set by setItem() as DImgPreviewItem
0057      * Note: if you store a GraphicsDImgItem object using setItem(), this method will return 0.
0058      */
0059     DImgPreviewItem*          previewItem() const;
0060 
0061     SinglePhotoPreviewLayout* layout()      const;
0062 
0063     /**
0064      * Scrolls the view such that scenePos (in scene coordinates
0065      * is displayed on the viewport at viewportPos (in viewport coordinates).
0066      * E.g., calling scrollPointOnPoint(scenePos, viewport()->rect().center()) is
0067      * equivalent to calling centerOn(scenePos).
0068      */
0069     void scrollPointOnPoint(const QPointF& scenePos, const QPoint& viewportPos);
0070 
0071     // Change from protected to public to be used by ImageRegionWidget and ImageRegionItem
0072     void drawText(QPainter* p, const QRectF& rect, const QString& text);
0073 
0074     int   contentsX()                       const;
0075     int   contentsY()                       const;
0076     QRect visibleArea()                     const;
0077     void  setContentsPos(int x, int y);
0078     void  fitToWindow();
0079     void  toggleFullScreen(bool set);
0080 
0081 Q_SIGNALS:
0082 
0083     void contentsMoving(int, int);
0084     void rightButtonClicked();
0085     void leftButtonClicked();
0086     void leftButtonDoubleClicked();
0087     void activated();
0088     void toNextImage();
0089     void toPreviousImage();
0090     void contentsMoved(bool panningFinished);
0091     void resized();
0092 /*
0093     void contentTakeFocus();
0094 */
0095     void viewportRectChanged(const QRectF& viewportRect);
0096 
0097 protected:
0098 
0099     void drawForeground(QPainter* painter, const QRectF& rect)  override;
0100 
0101     void installPanIcon();
0102 
0103     void mouseDoubleClickEvent(QMouseEvent*)                    override;
0104     void mousePressEvent(QMouseEvent*)                          override;
0105     void mouseMoveEvent(QMouseEvent*)                           override;
0106     void mouseReleaseEvent(QMouseEvent*)                        override;
0107     void wheelEvent(QWheelEvent*)                               override;
0108     void resizeEvent(QResizeEvent*)                             override;
0109 
0110     void startPanning(const QPoint& pos);
0111     void continuePanning(const QPoint& pos);
0112     void finishPanning();
0113 
0114     void setShowText(bool value);
0115     void setScaleFitToWindow(bool value);
0116 
0117     virtual bool acceptsMouseClick(QMouseEvent* e);
0118     void scrollContentsBy(int dx, int dy)               override;
0119 
0120 protected Q_SLOTS:
0121 
0122     void         slotContentsMoved();
0123     void         slotCornerButtonPressed();
0124     void         slotPanIconHidden();
0125 
0126     virtual void slotPanIconSelectionMoved(const QRect&, bool);
0127 
0128 private:
0129 
0130     class Private;
0131     Private* const d;
0132 };
0133 
0134 } // namespace Digikam
0135 
0136 #endif // DIGIKAM_GRAPHICS_DIMG_VIEW_H