20 #include <QMouseEvent>
25 return Image->copy( *CropRect );
33 setObjectName( name );
34 bMouseButtonDown =
false;
36 bTopRightGrab =
false;
37 bBottomLeftGrab =
false;
38 bBottomRightGrab =
false;
41 CropRect =
new QRect();
42 Anchor =
new QPoint();
43 Image =
new QPixmap();
53 p.drawPixmap( 0, 0, *Image );
55 p.setPen( QPen( QColor(
"Grey" ), 2 ) );
56 p.drawRect( *CropRect );
58 p.setPen( QPen( QColor(
"Grey" ), 0 ) );
59 p.drawRect( QRect( CropRect->left(), CropRect->top(),
60 HandleSize, HandleSize ) );
61 p.drawRect( QRect( CropRect->right() - HandleSize, CropRect->top(),
62 HandleSize, HandleSize ) );
63 p.drawRect( QRect( CropRect->left(), CropRect->bottom() - HandleSize,
64 HandleSize, HandleSize ) );
65 p.drawRect( QRect( CropRect->right() - HandleSize, CropRect->bottom() - HandleSize,
66 HandleSize, HandleSize ) );
68 if ( CropRect->x() > 0 )
69 p.fillRect( 0, 0, CropRect->x(), height(),
70 QBrush( QColor(
"white"), Qt::Dense3Pattern ) );
71 if ( CropRect->right() < width() )
72 p.fillRect( CropRect->right(), 0, (width() - CropRect->right()), height(),
73 QBrush( QColor(
"white"), Qt::Dense3Pattern ) );
74 if ( CropRect->y() > 0 )
75 p.fillRect( 0, 0, width(), CropRect->y(),
76 QBrush( QColor(
"white"), Qt::Dense3Pattern ) );
77 if ( CropRect->bottom() < height() )
78 p.fillRect( 0, CropRect->bottom(), width(), (height() - CropRect->bottom()),
79 QBrush( QColor(
"white"), Qt::Dense3Pattern ) );
85 if ( e->button() == Qt::LeftButton && CropRect->contains( e->pos() ) ) {
86 bMouseButtonDown =
true;
89 Anchor->setX( e->x() - CropRect->left() );
90 Anchor->setY( e->y() - CropRect->top() );
92 if ( e->x() <= CropRect->left() + HandleSize && e->y() <= CropRect->top() + HandleSize ) {
95 if ( e->x() <= CropRect->left() + HandleSize && e->y() >= CropRect->bottom() - HandleSize ) {
96 bBottomLeftGrab =
true;
97 Anchor->setY( e->y() - CropRect->bottom() );
99 if ( e->x() >= CropRect->right() - HandleSize && e->y() <= CropRect->top() + HandleSize ) {
100 bTopRightGrab =
true;
101 Anchor->setX( e->x() - CropRect->right() );
103 if ( e->x() >= CropRect->right() - HandleSize && e->y() >= CropRect->bottom() - HandleSize ) {
104 bBottomRightGrab =
true;
105 Anchor->setX( e->x() - CropRect->right() );
106 Anchor->setY( e->y() - CropRect->bottom() );
112 if ( bMouseButtonDown ) bMouseButtonDown =
false;
113 if ( bTopLeftGrab ) bTopLeftGrab =
false;
114 if ( bTopRightGrab ) bTopRightGrab =
false;
115 if ( bBottomLeftGrab ) bBottomLeftGrab =
false;
116 if ( bBottomRightGrab ) bBottomRightGrab =
false;
120 if ( bMouseButtonDown ) {
123 if ( bTopLeftGrab ) {
124 if ( e->x() >= 0 && e->x() <= width() ) CropRect->setLeft( e->x() - Anchor->x() );
125 if ( e->y() >= 0 && e->y() <= height() ) CropRect->setTop( e->y() - Anchor->y() );
126 if ( CropRect->left() < 0 ) CropRect->setLeft( 0 );
127 if ( CropRect->top() < 0 ) CropRect->setTop( 0 );
128 if ( CropRect->width() < 200 ) CropRect->setLeft( CropRect->left() - 200 + CropRect->width() );
129 if ( CropRect->height() < 200 ) CropRect->setTop( CropRect->top() - 200 + CropRect->height() );
130 }
else if ( bTopRightGrab ) {
131 if ( e->x() >= 0 && e->x() <= width() ) CropRect->setRight( e->x() - Anchor->x() );
132 if ( e->y() >= 0 && e->y() <= height() ) CropRect->setTop( e->y() - Anchor->y() );
133 if ( CropRect->right() > width() ) CropRect->setRight( width() );
134 if ( CropRect->top() < 0 ) CropRect->setTop( 0 );
135 if ( CropRect->width() < 200 ) CropRect->setRight( CropRect->right() + 200 - CropRect->width() );
136 if ( CropRect->height() < 200 ) CropRect->setTop( CropRect->top() - 200 + CropRect->height() );
137 }
else if ( bBottomLeftGrab ) {
138 if ( e->x() >= 0 && e->x() <= width() ) CropRect->setLeft( e->x() - Anchor->x() );
139 if ( e->y() >= 0 && e->y() <= height() ) CropRect->setBottom( e->y() - Anchor->y() );
140 if ( CropRect->left() < 0 ) CropRect->setLeft( 0 );
141 if ( CropRect->bottom() > height() ) CropRect->setBottom( height() );
142 if ( CropRect->width() < 200 ) CropRect->setLeft( CropRect->left() - 200 + CropRect->width() );
143 if ( CropRect->height() < 200 ) CropRect->setBottom( CropRect->bottom() + 200 - CropRect->height() );
144 }
else if ( bBottomRightGrab ) {
145 if ( e->x() >= 0 && e->x() <= width() ) CropRect->setRight( e->x() - Anchor->x() );
146 if ( e->y() >= 0 && e->y() <= height() ) CropRect->setBottom( e->y() - Anchor->y() );
147 if ( CropRect->right() > width() ) CropRect->setRight( width() );
148 if ( CropRect->bottom() > height() ) CropRect->setBottom( height() );
149 if ( CropRect->width() < 200 ) CropRect->setRight( CropRect->right() + 200 - CropRect->width() );
150 if ( CropRect->height() < 200 ) CropRect->setBottom( CropRect->bottom() + 200 - CropRect->height() );
152 CropRect->moveTopLeft( QPoint( e->x() - Anchor->x(), e->y() - Anchor->y() ) );
153 if ( CropRect->left() < 0 ) CropRect->moveLeft( 0 );
154 if ( CropRect->right() > width() ) CropRect->moveRight( width() );
155 if ( CropRect->top() < 0 ) CropRect->moveTop( 0 );
156 if ( CropRect->bottom() > height() ) CropRect->moveBottom( height() );
164 #include "thumbimage.moc"
void mouseReleaseEvent(QMouseEvent *e)
void cropRegionModified()
ThumbImage(QWidget *parent, const char *name=0)
void mousePressEvent(QMouseEvent *e)
void paintEvent(QPaintEvent *)
void mouseMoveEvent(QMouseEvent *e)