File indexing completed on 2024-04-14 03:43:28

0001 /*
0002     SPDX-FileCopyrightText: 2005 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QLabel>
0010 #include <QPixmap>
0011 
0012 #include <memory>
0013 
0014 class ThumbImage : public QLabel
0015 {
0016     Q_OBJECT
0017   public:
0018     explicit ThumbImage(QWidget *parent, const char *name = nullptr);
0019     virtual ~ThumbImage() override = default;
0020 
0021     void setImage(QPixmap *pm)
0022     {
0023         *Image = *pm;
0024         setFixedSize(Image->width(), Image->height());
0025     }
0026     QPixmap *image() { return Image.get(); }
0027     QPixmap croppedImage();
0028 
0029     void setCropRect(int x, int y, int w, int h) { CropRect->setRect(x, y, w, h); }
0030     QRect *cropRect() const { return CropRect.get(); }
0031 
0032   signals:
0033     void cropRegionModified();
0034 
0035   protected:
0036     //  void resizeEvent( QResizeEvent *e);
0037     void paintEvent(QPaintEvent *) override;
0038     void mousePressEvent(QMouseEvent *e) override;
0039     void mouseReleaseEvent(QMouseEvent *e) override;
0040     void mouseMoveEvent(QMouseEvent *e) override;
0041 
0042   private:
0043     std::unique_ptr<QRect> CropRect;
0044     std::unique_ptr<QPoint> Anchor;
0045     std::unique_ptr<QPixmap> Image;
0046 
0047     bool bMouseButtonDown { false };
0048     bool bTopLeftGrab { false };
0049     bool bBottomLeftGrab { false };
0050     bool bTopRightGrab { false };
0051     bool bBottomRightGrab { false };
0052     int HandleSize { 10 };
0053 };