void FotoAreaEditorFotos::mousePressEvent(QMouseEvent *event)
{
if (event -> button() != Qt::LeftButton) return;
iniSeleccioX = event -> globalX();
iniSeleccioY = event -> globalY();
areaSeleccio = new QRubberBand(QRubberBand::Rectangle);
areaSeleccio -> setGeometry(iniSeleccioX, iniSeleccioY, 1, 1);
areaSeleccio -> show();
}
void FotoAreaEditorFotos::mouseMoveEvent(QMouseEvent *event)
{
int x, y, w, h;
QScrollBar *scrollBar;
if (event ->buttons() == Qt::LeftButton)
{
int auxX = event -> globalX();
int auxY = event -> globalY();
QPoint posMax = mapToGlobal(QPoint(viewport() -> width() - 1,
viewport() -> height() - 1));
QPoint posMin = mapToGlobal(QPoint(0 , 0));
if (auxX < iniSeleccioX)
{
if (auxX <= posMin.x())
{
scrollBar = horizontalScrollBar();
scrollBar -> setValue(scrollBar -> value() - scrollBar -> singleStep());
x = posMin.x();
}
else
x = auxX;
w = iniSeleccioX - x + 1;
}
else
{
if (auxX >= posMax.x())
{
scrollBar = horizontalScrollBar();
scrollBar -> setValue(scrollBar -> value() + scrollBar -> singleStep());
w = posMax.x() - iniSeleccioX + 1;
}
else
w = auxX - iniSeleccioX + 1;
x = iniSeleccioX;
}
if (auxY < iniSeleccioY)
{
if (auxY < posMin.y())
{
scrollBar = verticalScrollBar();
scrollBar -> setValue(scrollBar -> value() - scrollBar -> singleStep());
y = posMin.y();
}
else
y = auxY;
h = iniSeleccioY - y + 1;
}
else
{
if (auxY > posMax.y())
{
scrollBar = verticalScrollBar();
scrollBar -> setValue(scrollBar -> value() + scrollBar -> singleStep());
h = posMax.y() - iniSeleccioY + 1;
}
else
h = auxY - iniSeleccioY + 1;
y = iniSeleccioY;
}
areaSeleccio -> setGeometry(x, y, w, h);
}
}
void FotoAreaEditorFotos::mouseReleaseEvent(QMouseEvent *event)
{
if (event -> button() == Qt::LeftButton)
delete areaSeleccio;
}
Bookmarks