13QPixmap ThumbImage::croppedImage()
15 return Image->
copy(*CropRect);
18ThumbImage::ThumbImage(
QWidget *parent,
const char *name) :
QLabel(parent)
25 CropRect.reset(
new QRect());
26 Anchor.reset(
new QPoint());
41 p.
drawRect(
QRect(CropRect->left(), CropRect->top(), HandleSize, HandleSize));
42 p.
drawRect(
QRect(CropRect->right() - HandleSize, CropRect->top(), HandleSize, HandleSize));
43 p.
drawRect(
QRect(CropRect->left(), CropRect->bottom() - HandleSize, HandleSize, HandleSize));
44 p.
drawRect(
QRect(CropRect->right() - HandleSize, CropRect->bottom() - HandleSize, HandleSize, HandleSize));
46 if (CropRect->x() > 0)
48 if (CropRect->right() <
width())
51 if (CropRect->y() > 0)
53 if (CropRect->bottom() <
height())
64 bMouseButtonDown =
true;
67 Anchor->setX(e->
x() - CropRect->left());
68 Anchor->setY(e->
y() - CropRect->top());
70 if (e->
x() <= CropRect->left() + HandleSize && e->
y() <= CropRect->top() + HandleSize)
74 if (e->
x() <= CropRect->left() + HandleSize && e->
y() >= CropRect->bottom() - HandleSize)
76 bBottomLeftGrab =
true;
77 Anchor->setY(e->
y() - CropRect->bottom());
79 if (e->
x() >= CropRect->right() - HandleSize && e->
y() <= CropRect->top() + HandleSize)
82 Anchor->setX(e->
x() - CropRect->right());
84 if (e->
x() >= CropRect->right() - HandleSize && e->
y() >= CropRect->bottom() - HandleSize)
86 bBottomRightGrab =
true;
87 Anchor->setX(e->
x() - CropRect->right());
88 Anchor->setY(e->
y() - CropRect->bottom());
96 bMouseButtonDown =
false;
100 bTopRightGrab =
false;
102 bBottomLeftGrab =
false;
103 if (bBottomRightGrab)
104 bBottomRightGrab =
false;
109 if (bMouseButtonDown)
114 if (e->
x() >= 0 && e->
x() <=
width())
115 CropRect->setLeft(e->
x() - Anchor->x());
116 if (e->
y() >= 0 && e->
y() <=
height())
117 CropRect->setTop(e->
y() - Anchor->y());
118 if (CropRect->left() < 0)
119 CropRect->setLeft(0);
120 if (CropRect->top() < 0)
122 if (CropRect->width() < 200)
123 CropRect->setLeft(CropRect->left() - 200 + CropRect->width());
124 if (CropRect->height() < 200)
125 CropRect->setTop(CropRect->top() - 200 + CropRect->height());
127 else if (bTopRightGrab)
129 if (e->
x() >= 0 && e->
x() <=
width())
130 CropRect->setRight(e->
x() - Anchor->x());
131 if (e->
y() >= 0 && e->
y() <=
height())
132 CropRect->setTop(e->
y() - Anchor->y());
133 if (CropRect->right() >
width())
134 CropRect->setRight(
width());
135 if (CropRect->top() < 0)
137 if (CropRect->width() < 200)
138 CropRect->setRight(CropRect->right() + 200 - CropRect->width());
139 if (CropRect->height() < 200)
140 CropRect->setTop(CropRect->top() - 200 + CropRect->height());
142 else if (bBottomLeftGrab)
144 if (e->
x() >= 0 && e->
x() <=
width())
145 CropRect->setLeft(e->
x() - Anchor->x());
146 if (e->
y() >= 0 && e->
y() <=
height())
147 CropRect->setBottom(e->
y() - Anchor->y());
148 if (CropRect->left() < 0)
149 CropRect->setLeft(0);
150 if (CropRect->bottom() >
height())
151 CropRect->setBottom(
height());
152 if (CropRect->width() < 200)
153 CropRect->setLeft(CropRect->left() - 200 + CropRect->width());
154 if (CropRect->height() < 200)
155 CropRect->setBottom(CropRect->bottom() + 200 - CropRect->height());
157 else if (bBottomRightGrab)
159 if (e->
x() >= 0 && e->
x() <=
width())
160 CropRect->setRight(e->
x() - Anchor->x());
161 if (e->
y() >= 0 && e->
y() <=
height())
162 CropRect->setBottom(e->
y() - Anchor->y());
163 if (CropRect->right() >
width())
164 CropRect->setRight(
width());
165 if (CropRect->bottom() >
height())
166 CropRect->setBottom(
height());
167 if (CropRect->width() < 200)
168 CropRect->setRight(CropRect->right() + 200 - CropRect->width());
169 if (CropRect->height() < 200)
170 CropRect->setBottom(CropRect->bottom() + 200 - CropRect->height());
174 CropRect->moveTopLeft(
QPoint(e->
x() - Anchor->x(), e->
y() - Anchor->y()));
175 if (CropRect->left() < 0)
176 CropRect->moveLeft(0);
177 if (CropRect->right() >
width())
178 CropRect->moveRight(
width());
179 if (CropRect->top() < 0)
180 CropRect->moveTop(0);
181 if (CropRect->bottom() >
height())
182 CropRect->moveBottom(
height());
185 emit cropRegionModified();
bool begin(QPaintDevice *device)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void drawRect(const QRect &rectangle)
void fillRect(const QRect &rectangle, QGradient::Preset preset)
void setPen(Qt::PenStyle style)
QPixmap copy(const QRect &rectangle) const const