50 #include "ImageDialog.hh" 54 ImageDialog::ImageDialog(QImage _image, QWidget *parent) :
56 imageWidth_(_image.width() ),
57 imageHeight_(_image.height() ),
62 pixmap_ = QPixmap::fromImage(_image).scaled(QSize(400,400),Qt::KeepAspectRatio,Qt::SmoothTransformation);
64 image->setPixmap(pixmap_);
67 minX->setMaximum(imageWidth_);
68 maxX->setMaximum(imageWidth_);
69 maxX->setValue(imageWidth_);
70 minY->setMaximum(imageHeight_);
71 maxY->setMaximum(imageHeight_);
72 maxY->setValue(imageHeight_);
75 connect(minX,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
76 connect(maxX,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
77 connect(minY,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
78 connect(maxY,SIGNAL(valueChanged(
int )),
this,SLOT(slidersChanged()));
80 connect(image,SIGNAL(mouseButtonMoveEvent ( QPoint )) ,
this,SLOT(mouseButtonMoveEvent ( QPoint )));
81 connect(image,SIGNAL(mouseButtonPressEvent ( QPoint )) ,
this,SLOT(mouseButtonPressEvent ( QPoint )));
82 connect(image,SIGNAL(mouseButtonReleaseEvent ( QPoint )),
this,SLOT(mouseButtonReleaseEvent ( QPoint )));
84 setMouseTracking (
true);
89 void ImageDialog::slidersChanged() {
94 QPainter painter( &buffer_);
99 painter.setPen( pen );
101 painter.setBrush(QBrush(Qt::red,Qt::NoBrush));
103 const int minXVal = minX->value();
104 const int maxXVal = maxX->value();
105 const int minYVal = minY->value();
106 const int maxYVal = maxY->value();
109 const double scale = (double)pixmap_.width() / (double)imageWidth_;
112 painter.drawRect( minXVal * scale , minYVal * scale , (maxXVal-minXVal) * scale, (maxYVal-minYVal) * scale);
116 image->setPixmap(buffer_);
119 void ImageDialog::mouseButtonMoveEvent ( QPoint _p) {
131 int xoffset = (400 - image->pixmap()->width() ) / 2;
132 int yoffset = (400 - image->pixmap()->height()) / 2;
135 const double scale = (double)imageWidth_ / (
double)image->pixmap()->width();
137 int newXMin = (std::min(dragStartPoint_.x(),_p.x()) - xoffset ) * scale;
138 int newXMax = (std::max(dragStartPoint_.x(),_p.x()) - xoffset ) * scale;
140 int newYMin = (std::min(dragStartPoint_.y(),_p.y()) - yoffset ) * scale;
141 int newYMax = (std::max(dragStartPoint_.y(),_p.y()) - yoffset ) * scale;
143 minX->blockSignals(
true);
144 maxX->blockSignals(
true);
145 minY->blockSignals(
true);
146 maxY->blockSignals(
true);
148 minX->setValue(newXMin);
149 maxX->setValue(newXMax);
150 minY->setValue(newYMin);
151 maxY->setValue(newYMax);
153 minX->blockSignals(
false);
154 maxX->blockSignals(
false);
155 minY->blockSignals(
false);
156 maxY->blockSignals(
false);
162 void ImageDialog::mouseButtonPressEvent ( QPoint _p ) {
163 dragStartPoint_ = _p;
167 void ImageDialog::mouseButtonReleaseEvent ( QPoint _p ) {