1/*
2 * Copyright (C) 2007 Luca Gugelmann <lucag@student.ethz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
12 *
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef REGIONGRABBER_H
20#define REGIONGRABBER_H
21
22#include <QWidget>
23#include <QRegion>
24#include <QPoint>
25#include <QVector>
26#include <QRect>
27
28class QPaintEvent;
29class QResizeEvent;
30class QMouseEvent;
31
32class RegionGrabber : public QWidget
33{
34 Q_OBJECT
35
36 enum MaskType { StrokeMask, FillMask };
37
38public:
39 RegionGrabber( const QRect &startSelection );
40 ~RegionGrabber();
41
42protected slots:
43 void init();
44
45signals:
46 void regionGrabbed( const QPixmap & );
47 void regionUpdated( const QRect & );
48
49protected:
50 void paintEvent( QPaintEvent* e );
51 void resizeEvent( QResizeEvent* e );
52 void mousePressEvent( QMouseEvent* e );
53 void mouseMoveEvent( QMouseEvent* e );
54 void mouseReleaseEvent( QMouseEvent* e );
55 void mouseDoubleClickEvent( QMouseEvent* );
56 void keyPressEvent( QKeyEvent* e );
57 void updateHandles();
58 QRegion handleMask( MaskType type ) const;
59 QPoint limitPointToRect( const QPoint &p, const QRect &r ) const;
60 QRect normalizeSelection( const QRect &s ) const;
61 void grabRect();
62
63 QRect selection;
64 bool mouseDown;
65 bool newSelection;
66 const int handleSize;
67 QRect* mouseOverHandle;
68 QPoint dragStartPoint;
69 QRect selectionBeforeDrag;
70 bool showHelp;
71 bool grabbing;
72
73 // naming convention for handles
74 // T top, B bottom, R Right, L left
75 // 2 letters: a corner
76 // 1 letter: the handle on the middle of the corresponding side
77 QRect TLHandle, TRHandle, BLHandle, BRHandle;
78 QRect LHandle, THandle, RHandle, BHandle;
79 QRect helpTextRect;
80
81 QVector<QRect*> handles;
82 QPixmap pixmap;
83};
84
85#endif
86