Kstars

thumbimage.h
1 /*
2  SPDX-FileCopyrightText: 2005 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QLabel>
10 #include <QPixmap>
11 
12 #include <memory>
13 
14 class ThumbImage : public QLabel
15 {
16  Q_OBJECT
17  public:
18  explicit ThumbImage(QWidget *parent, const char *name = nullptr);
19  virtual ~ThumbImage() override = default;
20 
21  void setImage(QPixmap *pm)
22  {
23  *Image = *pm;
24  setFixedSize(Image->width(), Image->height());
25  }
26  QPixmap *image() { return Image.get(); }
27  QPixmap croppedImage();
28 
29  void setCropRect(int x, int y, int w, int h) { CropRect->setRect(x, y, w, h); }
30  QRect *cropRect() const { return CropRect.get(); }
31 
32  signals:
33  void cropRegionModified();
34 
35  protected:
36  // void resizeEvent( QResizeEvent *e);
37  void paintEvent(QPaintEvent *) override;
38  void mousePressEvent(QMouseEvent *e) override;
39  void mouseReleaseEvent(QMouseEvent *e) override;
40  void mouseMoveEvent(QMouseEvent *e) override;
41 
42  private:
43  std::unique_ptr<QRect> CropRect;
44  std::unique_ptr<QPoint> Anchor;
45  std::unique_ptr<QPixmap> Image;
46 
47  bool bMouseButtonDown { false };
48  bool bTopLeftGrab { false };
49  bool bBottomLeftGrab { false };
50  bool bTopRightGrab { false };
51  bool bBottomRightGrab { false };
52  int HandleSize { 10 };
53 };
Q_OBJECTQ_OBJECT
virtual void mouseMoveEvent(QMouseEvent *ev) override
virtual void mousePressEvent(QMouseEvent *ev) override
virtual void paintEvent(QPaintEvent *) override
void setFixedSize(const QSize &s)
virtual void mouseReleaseEvent(QMouseEvent *ev) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.