File indexing completed on 2022-09-27 16:29:25

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2007 Luca Gugelmann <lucag@student.ethz.ch>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-only
0005  */
0006 
0007 #ifndef REGIONGRABBER_H
0008 #define REGIONGRABBER_H
0009 
0010 #include <QWidget>
0011 #include <QtCore/QTimer>
0012 #include <QtCore/QVector>
0013 
0014 class QPoint;
0015 class QRect;
0016 class QRegion;
0017 class QPaintEvent;
0018 class QResizeEvent;
0019 class QMouseEvent;
0020 
0021 class RegionGrabber : public QWidget
0022 {
0023     Q_OBJECT
0024 public:
0025     RegionGrabber();
0026     ~RegionGrabber() override;
0027 
0028 protected Q_SLOTS:
0029     void init();
0030     void displayHelp();
0031 
0032 Q_SIGNALS:
0033     void regionGrabbed(const QPixmap &);
0034 
0035 protected:
0036     void paintEvent(QPaintEvent *e) override;
0037     void resizeEvent(QResizeEvent *e) override;
0038     void mousePressEvent(QMouseEvent *e) override;
0039     void mouseMoveEvent(QMouseEvent *e) override;
0040     void mouseReleaseEvent(QMouseEvent *e) override;
0041     void mouseDoubleClickEvent(QMouseEvent *) override;
0042     void keyPressEvent(QKeyEvent *e) override;
0043     void updateHandles();
0044     QRegion handleMask() const;
0045     QPoint limitPointToRect(const QPoint &p, const QRect &r) const;
0046     void grabRect();
0047 
0048     QRect selection;
0049     bool mouseDown;
0050     bool newSelection;
0051     const int handleSize;
0052     QRect *mouseOverHandle;
0053     QPoint dragStartPoint;
0054     QRect selectionBeforeDrag;
0055     QTimer idleTimer;
0056     bool showHelp;
0057     bool grabbing;
0058 
0059     // naming convention for handles
0060     // T top, B bottom, R Right, L left
0061     // 2 letters: a corner
0062     // 1 letter: the handle on the middle of the corresponding side
0063     QRect TLHandle, TRHandle, BLHandle, BRHandle;
0064     QRect LHandle, THandle, RHandle, BHandle;
0065 
0066     QVector<QRect *> handles;
0067     QPixmap pixmap;
0068 };
0069 
0070 #endif