parent
97db7ddc0c
commit
15ca46f3d0
@ -21,7 +21,7 @@
|
|||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
|
|
||||||
CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
||||||
: QGraphicsScene(parent), drawingSelectionMaker([] { return nullptr; }), prevButtons(Qt::NoButton),
|
: QGraphicsScene(parent), cursorPos(0, 0), drawingSelectionMaker([] { return nullptr; }), prevButtons(Qt::NoButton),
|
||||||
_brush(Qt::SolidPattern), _font(settings::settings().value("font", QFont()).value<QFont>()) {
|
_brush(Qt::SolidPattern), _font(settings::settings().value("font", QFont()).value<QFont>()) {
|
||||||
_pixmap = pixmap;
|
_pixmap = pixmap;
|
||||||
pen().setColor(settings::settings().value("penColor", pen().color()).value<QColor>());
|
pen().setColor(settings::settings().value("penColor", pen().color()).value<QColor>());
|
||||||
@ -64,13 +64,23 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
|||||||
show();
|
show();
|
||||||
});
|
});
|
||||||
menu.addAction(settings);
|
menu.addAction(settings);
|
||||||
|
QPolygonF cursorPoly;
|
||||||
|
cursorPoly << QPoint(-10, 0) //
|
||||||
|
<< QPoint(10, 0) //
|
||||||
|
<< QPoint(0, 0) //
|
||||||
|
<< QPoint(0, 10) //
|
||||||
|
<< QPoint(0, -10) //
|
||||||
|
<< QPoint(0, 0);
|
||||||
|
|
||||||
magnifier = addPixmap(pixmap.copy(0, 0, 11, 11).scaled(110, 110));
|
cursorItem = addPolygon(cursorPoly, QPen(Qt::white));
|
||||||
|
cursorItem->setZValue(3);
|
||||||
|
|
||||||
|
magnifier = addPixmap(QPixmap(110, 110));
|
||||||
magnifierBox = addRect(magnifier->boundingRect(), QPen(Qt::cyan));
|
magnifierBox = addRect(magnifier->boundingRect(), QPen(Qt::cyan));
|
||||||
magnifier->setZValue(1);
|
magnifier->setZValue(3);
|
||||||
magnifierBox->setZValue(1.1);
|
magnifierBox->setZValue(1.1);
|
||||||
magnifierBox->setParentItem(magnifier);
|
magnifierBox->setParentItem(magnifier);
|
||||||
magnifierHint = addText("ptr: (0, 0)\nsel: (0, 0, 0, 0)");
|
magnifierHint = addText("ptr: (0, 0)\nsel: (-1, -1, 0, 0)");
|
||||||
magnifierHint->setParentItem(magnifier);
|
magnifierHint->setParentItem(magnifier);
|
||||||
magnifierHint->setY(magnifier->boundingRect().height());
|
magnifierHint->setY(magnifier->boundingRect().height());
|
||||||
QColor c(Qt::cyan);
|
QColor c(Qt::cyan);
|
||||||
@ -80,20 +90,25 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
|||||||
magnifierHintBox->setZValue(1);
|
magnifierHintBox->setZValue(1);
|
||||||
magnifierHint->setZValue(1.1);
|
magnifierHint->setZValue(1.1);
|
||||||
initMagnifierGrid();
|
initMagnifierGrid();
|
||||||
updateMag(QPointF(0, 0));
|
updateMag();
|
||||||
|
|
||||||
connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk);
|
connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk);
|
||||||
|
|
||||||
QTimer::singleShot(0, [&] {
|
|
||||||
QPolygonF poly;
|
QPolygonF poly;
|
||||||
poly.append(sceneRect().topLeft());
|
QRect prect = pixmap.rect();
|
||||||
poly.append(sceneRect().topRight());
|
poly.append(prect.topLeft());
|
||||||
poly.append(sceneRect().bottomRight());
|
poly.append(prect.topRight());
|
||||||
poly.append(sceneRect().bottomLeft());
|
poly.append(prect.bottomRight());
|
||||||
|
poly.append(prect.bottomLeft());
|
||||||
polyItem = new QGraphicsPolygonItem(poly);
|
polyItem = new QGraphicsPolygonItem(poly);
|
||||||
polyItem->setBrush(QBrush(QColor(0, 0, 0, 191)));
|
polyItem->setBrush(QBrush(QColor(0, 0, 0, 191)));
|
||||||
polyItem->setPen(QPen(Qt::NoPen));
|
polyItem->setPen(QPen(Qt::NoPen));
|
||||||
addItem(polyItem);
|
addItem(polyItem);
|
||||||
|
QTimer::singleShot(0, [&] {
|
||||||
|
auto pf = views()[0]->mapFromGlobal(QCursor::pos());
|
||||||
|
cursorPos = QPoint(pf.x(), pf.y());
|
||||||
|
cursorItem->setPos(cursorPos);
|
||||||
|
updateMag();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,14 +162,20 @@ void CropScene::fontAsk() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
updateMag(e->scenePos());
|
QPointF delta = e->scenePos() - cursorPos;
|
||||||
|
if (e->modifiers() & Qt::ShiftModifier) {
|
||||||
|
cursorPos += delta / 2;
|
||||||
|
QCursor::setPos(views()[0]->mapToGlobal(cursorPos.toPoint()));
|
||||||
|
} else
|
||||||
|
cursorPos = e->scenePos();
|
||||||
|
cursorItem->setPos(cursorPos);
|
||||||
|
updateMag();
|
||||||
|
|
||||||
auto buttons = e->buttons();
|
auto buttons = e->buttons();
|
||||||
if (e->modifiers() & Qt::ControlModifier && buttons == Qt::LeftButton) {
|
if (e->modifiers() & Qt::ControlModifier && buttons == Qt::LeftButton) {
|
||||||
QTransform stupidThing = views()[0]->transform();
|
QTransform stupidThing = views()[0]->transform();
|
||||||
auto item = itemAt(e->scenePos(), stupidThing);
|
auto item = itemAt(cursorPos, stupidThing);
|
||||||
if (item && item != polyItem && item != rect && item->zValue() != -1) {
|
if (item && item != polyItem && item != rect && item->zValue() != -1) {
|
||||||
QPointF delta = e->scenePos() - e->lastScenePos();
|
|
||||||
item->moveBy(delta.x(), delta.y());
|
item->moveBy(delta.x(), delta.y());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -163,14 +184,14 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
if (drawingSelection) {
|
if (drawingSelection) {
|
||||||
drawingSelection->mouseDragEvent(e, this);
|
drawingSelection->mouseDragEvent(e, this);
|
||||||
} else {
|
} else {
|
||||||
QPointF p = e->scenePos();
|
QPointF p = cursorPos;
|
||||||
if (rect == nullptr) {
|
if (rect == nullptr) {
|
||||||
rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1);
|
rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1);
|
||||||
initPos = p;
|
initPos = p;
|
||||||
QPen pen(Qt::NoBrush, 1);
|
QPen pen(Qt::NoBrush, 1);
|
||||||
pen.setColor(Qt::cyan);
|
pen.setColor(Qt::cyan);
|
||||||
rect->setPen(pen);
|
rect->setPen(pen);
|
||||||
rect->setZValue(-0.1);
|
rect->setZValue(1);
|
||||||
addItem(rect);
|
addItem(rect);
|
||||||
} else {
|
} else {
|
||||||
if (prevButtons == Qt::NoButton) {
|
if (prevButtons == Qt::NoButton) {
|
||||||
@ -218,7 +239,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
if (e->modifiers() & Qt::AltModifier) {
|
if (e->modifiers() & Qt::AltModifier) {
|
||||||
QTransform stupidThing = views()[0]->transform();
|
QTransform stupidThing = views()[0]->transform();
|
||||||
auto item = itemAt(e->scenePos(), stupidThing);
|
auto item = itemAt(cursorPos, stupidThing);
|
||||||
if (item && item != polyItem && item != rect && item->zValue() != -1) {
|
if (item && item != polyItem && item != rect && item->zValue() != -1) {
|
||||||
removeItem(item);
|
removeItem(item);
|
||||||
}
|
}
|
||||||
@ -240,7 +261,7 @@ void CropScene::wheelEvent(QGraphicsSceneWheelEvent *event) {
|
|||||||
gridRectsY.clear();
|
gridRectsY.clear();
|
||||||
|
|
||||||
initMagnifierGrid();
|
initMagnifierGrid();
|
||||||
updateMag(event->scenePos());
|
updateMag();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item) {
|
void CropScene::addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item) {
|
||||||
@ -250,30 +271,32 @@ void CropScene::addDrawingAction(QMenu &menu, QString name, std::function<DrawIt
|
|||||||
menu.addAction(action);
|
menu.addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPoint contextOffset(5, 5);
|
||||||
|
|
||||||
void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
|
void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
|
||||||
display->setText(drawingName);
|
display->setText(drawingName);
|
||||||
menu.exec(e->screenPos());
|
menu.exec((cursorPos + contextOffset).toPoint());
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::keyReleaseEvent(QKeyEvent *event) {
|
void CropScene::keyReleaseEvent(QKeyEvent *event) {
|
||||||
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter || event->key() == Qt::Key_Escape)
|
if (((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !drawingSelection) || event->key() == Qt::Key_Escape)
|
||||||
done(event->key() != Qt::Key_Escape);
|
done(event->key() != Qt::Key_Escape);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::updateMag(QPointF scenePos) {
|
void CropScene::updateMag() {
|
||||||
QString rectStr("(0, 0, 0, 0)");
|
QString rectStr("(-1, -1, 0, 0)");
|
||||||
if (rect) {
|
if (rect) {
|
||||||
rectStr = "(%0, %1, %2, %3)";
|
rectStr = "(%0, %1, %2, %3)";
|
||||||
rectStr = rectStr.arg(rect->rect().x()).arg(rect->rect().y()).arg(rect->rect().width()).arg(rect->rect().height());
|
rectStr = rectStr.arg(rect->rect().x()).arg(rect->rect().y()).arg(rect->rect().width()).arg(rect->rect().height());
|
||||||
}
|
}
|
||||||
magnifierHint->setPlainText(QString("ptr: (%0, %1)\nsel: %2").arg(scenePos.x()).arg(scenePos.y()).arg(rectStr));
|
magnifierHint->setPlainText(QString("ptr: (%0, %1)\nsel: %2").arg(qRound(cursorPos.x())).arg(qRound(cursorPos.y())).arg(rectStr));
|
||||||
magnifierHintBox->setRect(magnifierHint->boundingRect());
|
magnifierHintBox->setRect(magnifierHint->boundingRect());
|
||||||
|
|
||||||
int pixCnt = settings::settings().value("magnifierPixelCount", 11).toInt();
|
int pixCnt = settings::settings().value("magnifierPixelCount", 11).toInt();
|
||||||
if (pixCnt % 2 == 0) pixCnt++;
|
if (pixCnt % 2 == 0) pixCnt++;
|
||||||
QPointF magnifierTopLeft = scenePos - QPointF(pixCnt / 2., pixCnt / 2.);
|
QPointF magnifierTopLeft = cursorPos - QPointF(pixCnt / 2., pixCnt / 2.);
|
||||||
QPointF magnifierPos = scenePos + QPointF(5, 5);
|
QPointF magnifierPos = cursorPos + QPointF(5, 5);
|
||||||
|
|
||||||
magnifier->setPos(magnifierPos);
|
magnifier->setPos(magnifierPos);
|
||||||
magnifier->setPixmap(_pixmap.copy(magnifierTopLeft.x(), magnifierTopLeft.y(), pixCnt, pixCnt).scaled(110, 110));
|
magnifier->setPixmap(_pixmap.copy(magnifierTopLeft.x(), magnifierTopLeft.y(), pixCnt, pixCnt).scaled(110, 110));
|
||||||
@ -316,6 +339,7 @@ void CropScene::done(bool notEsc) {
|
|||||||
if (notEsc && rect) {
|
if (notEsc && rect) {
|
||||||
rect->setPen(QPen(Qt::NoPen));
|
rect->setPen(QPen(Qt::NoPen));
|
||||||
magnifier->setVisible(false);
|
magnifier->setVisible(false);
|
||||||
|
cursorItem->setVisible(false);
|
||||||
magnifierBox->setVisible(false);
|
magnifierBox->setVisible(false);
|
||||||
magnifierHint->setVisible(false);
|
magnifierHint->setVisible(false);
|
||||||
magnifierHintBox->setVisible(false);
|
magnifierHintBox->setVisible(false);
|
||||||
|
@ -34,6 +34,9 @@ public:
|
|||||||
void hide();
|
void hide();
|
||||||
void show();
|
void show();
|
||||||
void setVisible(bool visible);
|
void setVisible(bool visible);
|
||||||
|
QPointF cursorPosition() {
|
||||||
|
return cursorPos;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void fontAsk();
|
void fontAsk();
|
||||||
@ -47,15 +50,15 @@ protected:
|
|||||||
void mousePressEvent(QGraphicsSceneMouseEvent *e) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *e) override;
|
||||||
void wheelEvent(QGraphicsSceneWheelEvent *event) override; // WHEEEEEEL
|
void wheelEvent(QGraphicsSceneWheelEvent *event) override; // WHEEEEEEL
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
|
||||||
|
|
||||||
void keyReleaseEvent(QKeyEvent *e) override;
|
void keyReleaseEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateMag(QPointF scenePos);
|
void updateMag();
|
||||||
void initMagnifierGrid();
|
void initMagnifierGrid();
|
||||||
void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item);
|
void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item);
|
||||||
void done(bool notEsc);
|
void done(bool notEsc);
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
|
QPointF cursorPos;
|
||||||
std::function<DrawItem *()> drawingSelectionMaker;
|
std::function<DrawItem *()> drawingSelectionMaker;
|
||||||
QFlags<Qt::MouseButton> prevButtons;
|
QFlags<Qt::MouseButton> prevButtons;
|
||||||
QPixmap _pixmap;
|
QPixmap _pixmap;
|
||||||
@ -75,6 +78,7 @@ private:
|
|||||||
QAction *display;
|
QAction *display;
|
||||||
QList<QGraphicsRectItem *> gridRectsX;
|
QList<QGraphicsRectItem *> gridRectsX;
|
||||||
QList<QGraphicsRectItem *> gridRectsY;
|
QList<QGraphicsRectItem *> gridRectsY;
|
||||||
|
QGraphicsPolygonItem *cursorItem = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CROPSCENE_HPP
|
#endif // CROPSCENE_HPP
|
||||||
|
@ -9,4 +9,5 @@ CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene) {
|
|||||||
setCursor(QCursor(Qt::CrossCursor));
|
setCursor(QCursor(Qt::CrossCursor));
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
||||||
|
setCursor(Qt::BlankCursor);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
|
|
||||||
void ArrowItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void ArrowItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (init.isNull()) {
|
if (init.isNull()) {
|
||||||
init = e->scenePos();
|
init = scene->cursorPosition();
|
||||||
line = scene->addLine(QLineF(init, init), scene->pen());
|
line = scene->addLine(QLineF(init, init), scene->pen());
|
||||||
QPainterPath poly;
|
QPainterPath poly;
|
||||||
qreal w = settings::settings().value("arrow/width", 20).toDouble() / 2;
|
qreal w = settings::settings().value("arrow/width", 20).toDouble() / 2;
|
||||||
@ -14,8 +14,9 @@ void ArrowItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
|||||||
poly.lineTo(QPoint(w, h));
|
poly.lineTo(QPoint(w, h));
|
||||||
head = scene->addPath(poly, scene->pen(), scene->brush());
|
head = scene->addPath(poly, scene->pen(), scene->brush());
|
||||||
} else {
|
} else {
|
||||||
line->setLine(QLineF(init, e->scenePos()));
|
line->setLine(QLineF(init, scene->cursorPosition()));
|
||||||
head->setRotation(270 + qRadiansToDegrees(qAtan2((init.y() - e->scenePos().y()), (init.x() - e->scenePos().x()))));
|
head->setRotation(
|
||||||
|
270 + qRadiansToDegrees(qAtan2((init.y() - scene->cursorPosition().y()), (init.x() - scene->cursorPosition().x()))));
|
||||||
}
|
}
|
||||||
head->setPos(e->scenePos());
|
head->setPos(scene->cursorPosition());
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
QString name() override {
|
QString name() override {
|
||||||
return "Arrow";
|
return "Arrow";
|
||||||
}
|
}
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override {
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,16 +13,16 @@ bool BlurItem::init(CropScene *) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (pos.isNull()) {
|
if (pos.isNull()) {
|
||||||
pos = e->scenePos();
|
pos = scene->cursorPosition();
|
||||||
rect = scene->addRect(QRect(e->scenePos().toPoint(), QSize(1, 1)), QPen(Qt::cyan), Qt::NoBrush);
|
rect = scene->addRect(QRect(scene->cursorPosition().toPoint(), QSize(1, 1)), QPen(Qt::cyan), Qt::NoBrush);
|
||||||
pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect()));
|
pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect()));
|
||||||
pixmap->setPos(e->scenePos());
|
pixmap->setPos(scene->cursorPosition());
|
||||||
pixmap->setZValue(rect->zValue() - 0.1);
|
pixmap->setZValue(rect->zValue() - 0.1);
|
||||||
pixmap->setGraphicsEffect(effect);
|
pixmap->setGraphicsEffect(effect);
|
||||||
} else {
|
} else {
|
||||||
QPointF p = e->scenePos();
|
QPointF p = scene->cursorPosition();
|
||||||
rect->setRect(QRect(qMin(pos.x(), p.x()), qMin(pos.y(), p.y()), qAbs(pos.x() - p.x()), qAbs(pos.y() - p.y())));
|
rect->setRect(QRect(qMin(pos.x(), p.x()), qMin(pos.y(), p.y()), qAbs(pos.x() - p.x()), qAbs(pos.y() - p.y())));
|
||||||
pixmap->setPixmap(scene->pixmap().copy(rect->rect().toRect()));
|
pixmap->setPixmap(scene->pixmap().copy(rect->rect().toRect()));
|
||||||
pixmap->setPos(rect->rect().topLeft());
|
pixmap->setPos(rect->rect().topLeft());
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool init(CropScene *) override;
|
bool init(CropScene *) override;
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -7,7 +7,7 @@ DotItem::~DotItem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DotItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void DotItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
||||||
scene->addEllipse(e->pos().x() - 1.5, e->pos().y() - 1.5, 3, 3, scene->pen(), scene->brush())->setPos(e->scenePos());
|
scene->addEllipse(e->pos().x() - 1.5, e->pos().y() - 1.5, 3, 3, scene->pen(), scene->brush())->setPos(scene->cursorPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
|
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include "ellipseitem.hpp"
|
#include "ellipseitem.hpp"
|
||||||
|
|
||||||
void EllipseItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void EllipseItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (!ellie) {
|
if (!ellie) {
|
||||||
ellie = scene->addEllipse(e->scenePos().x(), e->scenePos().y(), 0, 0, scene->pen(), scene->brush());
|
ellie = scene->addEllipse(scene->cursorPosition().x(), scene->cursorPosition().y(), 0, 0, scene->pen(), scene->brush());
|
||||||
initPos = e->scenePos();
|
initPos = scene->cursorPosition();
|
||||||
} else {
|
} else {
|
||||||
auto p = e->scenePos();
|
auto p = scene->cursorPosition();
|
||||||
ellie->setRect(QRectF(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()),
|
ellie->setRect(QRectF(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()),
|
||||||
qAbs(initPos.y() - p.y())));
|
qAbs(initPos.y() - p.y())));
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public:
|
|||||||
}
|
}
|
||||||
~EllipseItem() {
|
~EllipseItem() {
|
||||||
}
|
}
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override {
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@ EraserItem::EraserItem() {
|
|||||||
EraserItem::~EraserItem() {
|
EraserItem::~EraserItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EraserItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void EraserItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
for (auto i : scene->items()) {
|
for (auto i : scene->items()) {
|
||||||
if (i->contains(e->scenePos()) && i->zValue() != -1 && i != scene->polyItm() && i != scene->selRect()) {
|
if (i->contains(scene->cursorPosition()) && i->zValue() != -1 && i != scene->polyItm() && i != scene->selRect()) {
|
||||||
scene->removeItem(i);
|
scene->removeItem(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
QString name() override {
|
QString name() override {
|
||||||
return "Eraser";
|
return "Eraser";
|
||||||
}
|
}
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override {
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
LineItem::LineItem() {
|
LineItem::LineItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (init.isNull()) {
|
if (init.isNull()) {
|
||||||
init = e->scenePos();
|
init = scene->cursorPosition();
|
||||||
line = scene->addLine(QLineF(init, init), scene->pen());
|
line = scene->addLine(QLineF(init, init), scene->pen());
|
||||||
} else {
|
} else {
|
||||||
line->setLine(QLineF(init, e->scenePos()));
|
line->setLine(QLineF(init, scene->cursorPosition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ public:
|
|||||||
QString name() override {
|
QString name() override {
|
||||||
return "Straight line";
|
return "Straight line";
|
||||||
}
|
}
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -9,13 +9,13 @@ PathItem::~PathItem() {
|
|||||||
delete path;
|
delete path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (path == nullptr) {
|
if (path == nullptr) {
|
||||||
path = new QPainterPath(e->scenePos());
|
path = new QPainterPath(scene->cursorPosition());
|
||||||
pathItem = scene->addPath(*path, scene->pen(),
|
pathItem = scene->addPath(*path, scene->pen(),
|
||||||
settings::settings().value("brushPath", false).toBool() ? scene->brush() : QBrush());
|
settings::settings().value("brushPath", false).toBool() ? scene->brush() : QBrush());
|
||||||
} else {
|
} else {
|
||||||
path->quadTo(path->currentPosition(), e->scenePos());
|
path->quadTo(path->currentPosition(), scene->cursorPosition());
|
||||||
pathItem->setPath(*path);
|
pathItem->setPath(*path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
QString name() {
|
QString name() {
|
||||||
return "Path";
|
return "Path";
|
||||||
}
|
}
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene);
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -6,14 +6,14 @@ RectItem::RectItem() {
|
|||||||
RectItem::~RectItem() {
|
RectItem::~RectItem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void RectItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (!rect) {
|
if (!rect) {
|
||||||
rect = scene->addRect(e->scenePos().x(), e->scenePos().y(), 0, 0);
|
rect = scene->addRect(scene->cursorPosition().x(), scene->cursorPosition().y(), 0, 0);
|
||||||
rect->setBrush(scene->brush());
|
rect->setBrush(scene->brush());
|
||||||
rect->setPen(scene->pen());
|
rect->setPen(scene->pen());
|
||||||
initPos = e->scenePos();
|
initPos = scene->cursorPosition();
|
||||||
} else {
|
} else {
|
||||||
auto p = e->scenePos();
|
auto p = scene->cursorPosition();
|
||||||
rect->setRect(
|
rect->setRect(
|
||||||
QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()), qAbs(initPos.y() - p.y())));
|
QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()), qAbs(initPos.y() - p.y())));
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
QString name() override {
|
QString name() override {
|
||||||
return "Rectangle";
|
return "Rectangle";
|
||||||
}
|
}
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -10,15 +10,15 @@ bool TextItem::init(CropScene *s) {
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
||||||
if (!textItem) {
|
if (!textItem) {
|
||||||
textItem = scene->addSimpleText(text, scene->font());
|
textItem = scene->addSimpleText(text, scene->font());
|
||||||
textItem->setPos(e->scenePos());
|
textItem->setPos(scene->cursorPosition());
|
||||||
textItem->setPen(scene->pen().color());
|
textItem->setPen(scene->pen().color());
|
||||||
textItem->setBrush(scene->pen().color());
|
textItem->setBrush(scene->pen().color());
|
||||||
} else {
|
} else {
|
||||||
auto ee
|
auto ee = 180 + qRadiansToDegrees(qAtan2((textItem->pos().y() - scene->cursorPosition().y()),
|
||||||
= 180 + qRadiansToDegrees(qAtan2((textItem->pos().y() - e->scenePos().y()), (textItem->pos().x() - e->scenePos().x())));
|
(textItem->pos().x() - scene->cursorPosition().x())));
|
||||||
textItem->setRotation(ee);
|
textItem->setRotation(ee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class TextItem : public DrawItem {
|
|||||||
public:
|
public:
|
||||||
QString name() override;
|
QString name() override;
|
||||||
bool init(CropScene *s) override;
|
bool init(CropScene *s) override;
|
||||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
void mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) override;
|
||||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
1
main.cpp
1
main.cpp
@ -32,6 +32,7 @@ bool stillAlive = true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
||||||
|
if (!verbose && msg.startsWith("QPixmap::fromWinHBITMAP")) return;
|
||||||
std::string stdMsg = msg.toStdString();
|
std::string stdMsg = msg.toStdString();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
|
Loading…
Reference in New Issue
Block a user