Add hotspots to the selection rectangle
This commit is contained in:
parent
c6864de782
commit
6120138523
@ -1,4 +1,5 @@
|
|||||||
#include "cropscene.hpp"
|
#include "cropscene.hpp"
|
||||||
|
#include "selectionrectangle.hpp"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -193,7 +194,7 @@ void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> dr
|
|||||||
drawingName = name;
|
drawingName = name;
|
||||||
display->setText(drawingName);
|
display->setText(drawingName);
|
||||||
if (drawingSelection)
|
if (drawingSelection)
|
||||||
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
|
if (!drawingSelection->init(this)) setDrawingSelection(tr("None"), [] { return nullptr; });
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsItem *CropScene::whichItem(QPointF scenePos) {
|
QGraphicsItem *CropScene::whichItem(QPointF scenePos) {
|
||||||
@ -245,6 +246,40 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
cursorItem->setPos(cursorPos);
|
cursorItem->setPos(cursorPos);
|
||||||
updateMag();
|
updateMag();
|
||||||
|
|
||||||
|
if (rect) {
|
||||||
|
// qAbs(e->scenePos().<axis>() - rect->rect().<edge>()) < 10
|
||||||
|
bool close = false;
|
||||||
|
QRectF newRect = rect->rect();
|
||||||
|
if (qAbs(e->scenePos().x() - rect->rect().right()) < 10) {
|
||||||
|
if (qAbs(e->scenePos().y() - rect->rect().bottom()) < 10) {
|
||||||
|
close = true;
|
||||||
|
views()[0]->setCursor(Qt::SizeFDiagCursor);
|
||||||
|
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setBottomLeft(cursorPos);
|
||||||
|
} else if (qAbs(e->scenePos().y() - rect->rect().top()) < 10) {
|
||||||
|
close = true;
|
||||||
|
views()[0]->setCursor(Qt::SizeBDiagCursor);
|
||||||
|
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setTopRight(cursorPos);
|
||||||
|
}
|
||||||
|
} else if (qAbs(e->scenePos().x() - rect->rect().left()) < 10) {
|
||||||
|
if (qAbs(e->scenePos().y() - rect->rect().top()) < 10) {
|
||||||
|
close = true;
|
||||||
|
views()[0]->setCursor(Qt::SizeFDiagCursor);
|
||||||
|
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setTopLeft(cursorPos);
|
||||||
|
} else if (qAbs(e->scenePos().y() - rect->rect().bottom()) < 10) {
|
||||||
|
close = true;
|
||||||
|
views()[0]->setCursor(Qt::SizeBDiagCursor);
|
||||||
|
if (e->buttons() & Qt::LeftButton && prevButtons != e->buttons()) newRect.setBottomLeft(cursorPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!close)
|
||||||
|
views()[0]->setCursor(Qt::BlankCursor);
|
||||||
|
else {
|
||||||
|
rect->setRect(newRect);
|
||||||
|
prevButtons = e->buttons();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto buttons = e->buttons();
|
auto buttons = e->buttons();
|
||||||
if (e->modifiers() & Qt::ControlModifier && buttons == Qt::LeftButton) {
|
if (e->modifiers() & Qt::ControlModifier && buttons == Qt::LeftButton) {
|
||||||
auto item = whichItem(cursorPos);
|
auto item = whichItem(cursorPos);
|
||||||
@ -257,7 +292,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
} else {
|
} else {
|
||||||
QPointF p = cursorPos;
|
QPointF p = cursorPos;
|
||||||
if (rect == nullptr) {
|
if (rect == nullptr) {
|
||||||
rect = new QGraphicsRectItem(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);
|
||||||
pen.setColor(_highlight);
|
pen.setColor(_highlight);
|
||||||
@ -303,7 +338,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
delete drawingSelection;
|
delete drawingSelection;
|
||||||
drawingSelection = drawingSelectionMaker();
|
drawingSelection = drawingSelectionMaker();
|
||||||
if (drawingSelection)
|
if (drawingSelection)
|
||||||
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
|
if (!drawingSelection->init(this)) setDrawingSelection(tr("None"), [] { return nullptr; });
|
||||||
} else if (settings::settings().value("quickMode", false).toBool())
|
} else if (settings::settings().value("quickMode", false).toBool())
|
||||||
done(true);
|
done(true);
|
||||||
prevButtons = Qt::NoButton;
|
prevButtons = Qt::NoButton;
|
||||||
@ -414,15 +449,16 @@ void CropScene::initMagnifierGrid() {
|
|||||||
|
|
||||||
void CropScene::done(bool notEsc) {
|
void CropScene::done(bool notEsc) {
|
||||||
if (notEsc && rect) {
|
if (notEsc && rect) {
|
||||||
|
QRectF rect2 = rect->rect();
|
||||||
hint->setVisible(false);
|
hint->setVisible(false);
|
||||||
rect->setPen(QPen(Qt::NoPen));
|
rect->setRect(QRect(-100, -100, 0, 0));
|
||||||
magnifier->setVisible(false);
|
magnifier->setVisible(false);
|
||||||
proxyMenu->setVisible(false);
|
proxyMenu->setVisible(false);
|
||||||
cursorItem->setVisible(false);
|
cursorItem->setVisible(false);
|
||||||
magnifierBox->setVisible(false);
|
magnifierBox->setVisible(false);
|
||||||
magnifierHint->setVisible(false);
|
magnifierHint->setVisible(false);
|
||||||
magnifierHintBox->setVisible(false);
|
magnifierHintBox->setVisible(false);
|
||||||
emit closedWithRect(rect->rect().toRect());
|
emit closedWithRect(rect2.toRect());
|
||||||
} else
|
} else
|
||||||
emit closedWithRect(QRect());
|
emit closedWithRect(QRect());
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
#define CROPSCENE_HPP
|
#define CROPSCENE_HPP
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QGraphicsRectItem>
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneContextMenuEvent>
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
#include <cropeditor/selectionrectangle.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <screenoverlayview.hpp>
|
#include <screenoverlayview.hpp>
|
||||||
#include <screenshotutil.hpp>
|
#include <screenshotutil.hpp>
|
||||||
@ -84,7 +84,7 @@ private:
|
|||||||
std::function<DrawItem *()> drawingSelectionMaker;
|
std::function<DrawItem *()> drawingSelectionMaker;
|
||||||
QFlags<Qt::MouseButton> prevButtons;
|
QFlags<Qt::MouseButton> prevButtons;
|
||||||
QPixmap _pixmap;
|
QPixmap _pixmap;
|
||||||
QGraphicsRectItem *rect = nullptr;
|
SelectionRectangle *rect = nullptr;
|
||||||
QGraphicsPixmapItem *magnifier = nullptr;
|
QGraphicsPixmapItem *magnifier = nullptr;
|
||||||
QGraphicsRectItem *magnifierBox = nullptr;
|
QGraphicsRectItem *magnifierBox = nullptr;
|
||||||
QGraphicsTextItem *magnifierHint = nullptr;
|
QGraphicsTextItem *magnifierHint = nullptr;
|
||||||
|
@ -11,6 +11,7 @@ public:
|
|||||||
return "Blur";
|
return "Blur";
|
||||||
}
|
}
|
||||||
~BlurItem() {
|
~BlurItem() {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init(CropScene *) override;
|
bool init(CropScene *) override;
|
||||||
|
39
src/cropeditor/selectionrectangle.cpp
Normal file
39
src/cropeditor/selectionrectangle.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "selectionrectangle.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
SelectionRectangle::SelectionRectangle() {
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectionRectangle::SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent)
|
||||||
|
: QGraphicsRectItem(x, y, w, h, parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectionRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) {
|
||||||
|
QRect rect = this->rect().toRect();
|
||||||
|
if (rect.height() > 30 && rect.width() > 30) {
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(pen().color());
|
||||||
|
|
||||||
|
// Before you panick, the <angle> * 16 things are needed because here angles are 1/16th of their value
|
||||||
|
// The <x/y> - 10 is accounting for sizes.
|
||||||
|
// Trail and error ftw
|
||||||
|
|
||||||
|
// Bottom left
|
||||||
|
painter->drawPie(rect.left() - 10, rect.bottom() - 10, 20, 20, 0, 90 * 16);
|
||||||
|
// Top right
|
||||||
|
painter->drawPie(rect.right() - 10, rect.bottom() - 10, 20, 20, 90 * 16, 90 * 16);
|
||||||
|
|
||||||
|
|
||||||
|
// Top left
|
||||||
|
painter->drawPie(rect.left() - 10, rect.top() - 10, 20, 20, 270 * 16, 90 * 16);
|
||||||
|
// Top right
|
||||||
|
painter->drawPie(rect.right() - 10, rect.top() - 10, 20, 20, 180 * 16, 90 * 16);
|
||||||
|
}
|
||||||
|
painter->setBrush(brush());
|
||||||
|
painter->setPen(pen());
|
||||||
|
QGraphicsRectItem::paint(painter, options, widget);
|
||||||
|
}
|
16
src/cropeditor/selectionrectangle.hpp
Normal file
16
src/cropeditor/selectionrectangle.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef SELECTIONRECTANGLE_HPP
|
||||||
|
#define SELECTIONRECTANGLE_HPP
|
||||||
|
|
||||||
|
#include <QGraphicsRectItem>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
class SelectionRectangle : public QGraphicsRectItem {
|
||||||
|
public:
|
||||||
|
SelectionRectangle();
|
||||||
|
explicit SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SELECTIONRECTANGLE_HPP
|
@ -67,7 +67,8 @@ SOURCES += main.cpp\
|
|||||||
logs/requestlogging.cpp \
|
logs/requestlogging.cpp \
|
||||||
logs/historydialog.cpp \
|
logs/historydialog.cpp \
|
||||||
monospacetextdialog.cpp \
|
monospacetextdialog.cpp \
|
||||||
screenoverlayview.cpp
|
screenoverlayview.cpp \
|
||||||
|
cropeditor/selectionrectangle.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -116,7 +117,8 @@ HEADERS += mainwindow.hpp \
|
|||||||
logs/historydialog.hpp \
|
logs/historydialog.hpp \
|
||||||
screenoverlayview.hpp \
|
screenoverlayview.hpp \
|
||||||
screenoverlayview.hpp \
|
screenoverlayview.hpp \
|
||||||
monospacetextdialog.hpp
|
monospacetextdialog.hpp \
|
||||||
|
cropeditor/selectionrectangle.hpp
|
||||||
|
|
||||||
nopkg {
|
nopkg {
|
||||||
# win32 {
|
# win32 {
|
||||||
|
Loading…
Reference in New Issue
Block a user