Fix the hotspots
This commit is contained in:
parent
7ec7b47249
commit
423383dca9
@ -246,7 +246,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
cursorItem->setPos(cursorPos);
|
cursorItem->setPos(cursorPos);
|
||||||
updateMag();
|
updateMag();
|
||||||
|
|
||||||
if (rect) {
|
if (rect && !drawingRect) {
|
||||||
// qAbs(e->scenePos().<axis>() - rect->rect().<edge>()) < 10
|
// qAbs(e->scenePos().<axis>() - rect->rect().<edge>()) < 10
|
||||||
bool close = false;
|
bool close = false;
|
||||||
QRectF newRect = rect->rect();
|
QRectF newRect = rect->rect();
|
||||||
@ -254,21 +254,21 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
if (qAbs(e->scenePos().y() - rect->rect().bottom()) < 10) {
|
if (qAbs(e->scenePos().y() - rect->rect().bottom()) < 10) {
|
||||||
close = true;
|
close = true;
|
||||||
views()[0]->setCursor(Qt::SizeFDiagCursor);
|
views()[0]->setCursor(Qt::SizeFDiagCursor);
|
||||||
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setBottomRight(cursorPos);
|
if (e->buttons() & Qt::LeftButton) newRect.setBottomRight(cursorPos);
|
||||||
} else if (qAbs(e->scenePos().y() - rect->rect().top()) < 10) {
|
} else if (qAbs(e->scenePos().y() - rect->rect().top()) < 10) {
|
||||||
close = true;
|
close = true;
|
||||||
views()[0]->setCursor(Qt::SizeBDiagCursor);
|
views()[0]->setCursor(Qt::SizeBDiagCursor);
|
||||||
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setTopRight(cursorPos);
|
if (e->buttons() & Qt::LeftButton) newRect.setTopRight(cursorPos);
|
||||||
}
|
}
|
||||||
} else if (qAbs(e->scenePos().x() - rect->rect().left()) < 10) {
|
} else if (qAbs(e->scenePos().x() - rect->rect().left()) < 10) {
|
||||||
if (qAbs(e->scenePos().y() - rect->rect().top()) < 10) {
|
if (qAbs(e->scenePos().y() - rect->rect().top()) < 10) {
|
||||||
close = true;
|
close = true;
|
||||||
views()[0]->setCursor(Qt::SizeFDiagCursor);
|
views()[0]->setCursor(Qt::SizeFDiagCursor);
|
||||||
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setTopLeft(cursorPos);
|
if (e->buttons() & Qt::LeftButton) newRect.setTopLeft(cursorPos);
|
||||||
} else if (qAbs(e->scenePos().y() - rect->rect().bottom()) < 10) {
|
} else if (qAbs(e->scenePos().y() - rect->rect().bottom()) < 10) {
|
||||||
close = true;
|
close = true;
|
||||||
views()[0]->setCursor(Qt::SizeBDiagCursor);
|
views()[0]->setCursor(Qt::SizeBDiagCursor);
|
||||||
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setBottomLeft(cursorPos);
|
if (e->buttons() & Qt::LeftButton) newRect.setBottomLeft(cursorPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!close)
|
if (!close)
|
||||||
@ -276,6 +276,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
else {
|
else {
|
||||||
rect->setRect(newRect);
|
rect->setRect(newRect);
|
||||||
prevButtons = e->buttons();
|
prevButtons = e->buttons();
|
||||||
|
updatePoly();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,6 +293,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
} else {
|
} else {
|
||||||
QPointF p = cursorPos;
|
QPointF p = cursorPos;
|
||||||
if (rect == nullptr) {
|
if (rect == nullptr) {
|
||||||
|
drawingRect = true;
|
||||||
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
|
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
|
||||||
initPos = p;
|
initPos = p;
|
||||||
QPen pen(Qt::NoBrush, 1);
|
QPen pen(Qt::NoBrush, 1);
|
||||||
@ -308,22 +310,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
qAbs(initPos.y() - p.y())));
|
qAbs(initPos.y() - p.y())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPolygonF poly;
|
updatePoly();
|
||||||
QPointF theMagicWikipediaPoint(rect->rect().right(), sceneRect().bottom());
|
|
||||||
poly << sceneRect().topLeft();
|
|
||||||
poly << sceneRect().topRight();
|
|
||||||
poly << sceneRect().bottomRight();
|
|
||||||
poly << theMagicWikipediaPoint;
|
|
||||||
poly << rect->rect().bottomRight();
|
|
||||||
poly << rect->rect().topRight();
|
|
||||||
poly << rect->rect().topLeft();
|
|
||||||
poly << rect->rect().bottomLeft();
|
|
||||||
poly << rect->rect().bottomRight();
|
|
||||||
poly << theMagicWikipediaPoint;
|
|
||||||
poly << sceneRect().bottomLeft();
|
|
||||||
poly << sceneRect().topLeft();
|
|
||||||
|
|
||||||
this->polyItem->setPolygon(poly);
|
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,6 +320,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
|
drawingRect = false;
|
||||||
if (drawingSelection) {
|
if (drawingSelection) {
|
||||||
drawingSelection->mouseDragEndEvent(e, this);
|
drawingSelection->mouseDragEndEvent(e, this);
|
||||||
delete drawingSelection;
|
delete drawingSelection;
|
||||||
@ -424,6 +412,25 @@ void CropScene::updateMag() {
|
|||||||
magnifier->setPos(magnifierPos);
|
magnifier->setPos(magnifierPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CropScene::updatePoly() {
|
||||||
|
QPolygonF poly;
|
||||||
|
QPointF theMagicWikipediaPoint(rect->rect().right(), sceneRect().bottom());
|
||||||
|
poly << sceneRect().topLeft();
|
||||||
|
poly << sceneRect().topRight();
|
||||||
|
poly << sceneRect().bottomRight();
|
||||||
|
poly << theMagicWikipediaPoint;
|
||||||
|
poly << rect->rect().bottomRight();
|
||||||
|
poly << rect->rect().topRight();
|
||||||
|
poly << rect->rect().topLeft();
|
||||||
|
poly << rect->rect().bottomLeft();
|
||||||
|
poly << rect->rect().bottomRight();
|
||||||
|
poly << theMagicWikipediaPoint;
|
||||||
|
poly << sceneRect().bottomLeft();
|
||||||
|
poly << sceneRect().topLeft();
|
||||||
|
|
||||||
|
this->polyItem->setPolygon(poly);
|
||||||
|
}
|
||||||
|
|
||||||
void CropScene::initMagnifierGrid() {
|
void CropScene::initMagnifierGrid() {
|
||||||
if (!gridRectsX.isEmpty() || !gridRectsY.isEmpty()) return;
|
if (!gridRectsX.isEmpty() || !gridRectsY.isEmpty()) return;
|
||||||
|
|
||||||
|
@ -78,13 +78,15 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateMag();
|
void updateMag();
|
||||||
|
void updatePoly();
|
||||||
void initMagnifierGrid();
|
void initMagnifierGrid();
|
||||||
void addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function<DrawItem *()> item);
|
void addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function<DrawItem *()> item);
|
||||||
QPointF cursorPos;
|
QPointF cursorPos;
|
||||||
std::function<DrawItem *()> drawingSelectionMaker;
|
std::function<DrawItem *()> drawingSelectionMaker;
|
||||||
QFlags<Qt::MouseButton> prevButtons;
|
QFlags<Qt::MouseButton> prevButtons;
|
||||||
QPixmap _pixmap;
|
QPixmap _pixmap;
|
||||||
SelectionRectangle *rect = nullptr;
|
QGraphicsRectItem *rect = nullptr;
|
||||||
|
bool drawingRect = true;
|
||||||
QGraphicsPixmapItem *magnifier = nullptr;
|
QGraphicsPixmapItem *magnifier = nullptr;
|
||||||
QGraphicsRectItem *magnifierBox = nullptr;
|
QGraphicsRectItem *magnifierBox = nullptr;
|
||||||
QGraphicsTextItem *magnifierHint = nullptr;
|
QGraphicsTextItem *magnifierHint = nullptr;
|
||||||
|
@ -12,6 +12,10 @@ SelectionRectangle::SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGrap
|
|||||||
: QGraphicsRectItem(x, y, w, h, parent) {
|
: QGraphicsRectItem(x, y, w, h, parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectionRectangle::SelectionRectangle(QRectF rect, QGraphicsItem *parent)
|
||||||
|
: SelectionRectangle(rect.left(), rect.top(), rect.width(), rect.height()) {
|
||||||
|
}
|
||||||
|
|
||||||
void SelectionRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) {
|
void SelectionRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) {
|
||||||
QRect rect = this->rect().toRect();
|
QRect rect = this->rect().toRect();
|
||||||
if (rect.height() > 30 && rect.width() > 30) {
|
if (rect.height() > 30 && rect.width() > 30) {
|
||||||
|
@ -8,6 +8,7 @@ class SelectionRectangle : public QGraphicsRectItem {
|
|||||||
public:
|
public:
|
||||||
SelectionRectangle();
|
SelectionRectangle();
|
||||||
explicit SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = nullptr);
|
explicit SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = nullptr);
|
||||||
|
explicit SelectionRectangle(QRectF rect, QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) override;
|
||||||
|
@ -108,5 +108,6 @@ int main(int argc, char *argv[]) {
|
|||||||
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
|
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
|
||||||
|
|
||||||
if (!parser.isSet(h)) w.show();
|
if (!parser.isSet(h)) w.show();
|
||||||
|
qDebug() << "lol";
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user