42 #include "ImageDialog.hh" 48 ImageDialog::ImageDialog(QImage _image, QWidget *parent) :
50 imageWidth_(_image.width() ),
51 imageHeight_(_image.height() ),
56 pixmap_ = QPixmap::fromImage(_image).scaled(QSize(400,400),Qt::KeepAspectRatio,Qt::SmoothTransformation);
58 image->setPixmap(pixmap_);
61 minX->setMaximum(imageWidth_);
62 maxX->setMaximum(imageWidth_);
63 maxX->setValue(imageWidth_);
64 minY->setMaximum(imageHeight_);
65 maxY->setMaximum(imageHeight_);
66 maxY->setValue(imageHeight_);
69 connect(minX,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
70 connect(maxX,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
71 connect(minY,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
72 connect(maxY,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
74 connect(image,SIGNAL(mouseButtonMoveEvent ( QPoint )) ,
this,SLOT(mouseButtonMoveEvent ( QPoint )));
75 connect(image,SIGNAL(mouseButtonPressEvent ( QPoint )) ,
this,SLOT(mouseButtonPressEvent ( QPoint )));
76 connect(image,SIGNAL(mouseButtonReleaseEvent ( QPoint )),
this,SLOT(mouseButtonReleaseEvent ( QPoint )));
78 setMouseTracking (
true);
83 void ImageDialog::slidersChanged() {
88 QPainter painter( &buffer_);
93 painter.setPen( pen );
95 painter.setBrush(QBrush(Qt::red,Qt::NoBrush));
97 const int minXVal = minX->value();
98 const int maxXVal = maxX->value();
99 const int minYVal = minY->value();
100 const int maxYVal = maxY->value();
103 const double scale = (double)pixmap_.width() / (double)imageWidth_;
106 painter.drawRect( minXVal * scale , minYVal * scale , (maxXVal-minXVal) * scale, (maxYVal-minYVal) * scale);
110 image->setPixmap(buffer_);
113 void ImageDialog::mouseButtonMoveEvent ( QPoint _p) {
125 int xoffset = (400 - image->pixmap()->width() ) / 2;
126 int yoffset = (400 - image->pixmap()->height()) / 2;
129 const double scale = (double)imageWidth_ / (
double)image->pixmap()->width();
131 int newXMin = (std::min(dragStartPoint_.x(),_p.x()) - xoffset ) * scale;
132 int newXMax = (std::max(dragStartPoint_.x(),_p.x()) - xoffset ) * scale;
134 int newYMin = (std::min(dragStartPoint_.y(),_p.y()) - yoffset ) * scale;
135 int newYMax = (std::max(dragStartPoint_.y(),_p.y()) - yoffset ) * scale;
137 minX->blockSignals(
true);
138 maxX->blockSignals(
true);
139 minY->blockSignals(
true);
140 maxY->blockSignals(
true);
142 minX->setValue(newXMin);
143 maxX->setValue(newXMax);
144 minY->setValue(newYMin);
145 maxY->setValue(newYMax);
147 minX->blockSignals(
false);
148 maxX->blockSignals(
false);
149 minY->blockSignals(
false);
150 maxY->blockSignals(
false);
156 void ImageDialog::mouseButtonPressEvent ( QPoint _p ) {
157 dragStartPoint_ = _p;
161 void ImageDialog::mouseButtonReleaseEvent ( QPoint _p ) {