Fix some stuff that I can't remember..

... Because I've litelary been debugging this for months.
This commit is contained in:
ArsenArsen 2017-10-17 20:09:38 +02:00
parent 6d92fe11ed
commit 821d11efe0
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
3 changed files with 15 additions and 8 deletions

View File

@ -188,6 +188,10 @@ void CropScene::setHighlight(QColor highlight) {
} }
void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> drawAction) { void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> drawAction) {
if (drawingSelection) {
delete drawingSelection;
drawingSelection = 0;
}
this->setFocus(); this->setFocus();
drawingSelectionMaker = drawAction; drawingSelectionMaker = drawAction;
drawingSelection = drawAction(); drawingSelection = drawAction();
@ -195,6 +199,11 @@ void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> dr
display->setText(drawingName); display->setText(drawingName);
if (drawingSelection) if (drawingSelection)
if (!drawingSelection->init(this)) setDrawingSelection(tr("None"), [] { return nullptr; }); if (!drawingSelection->init(this)) setDrawingSelection(tr("None"), [] { return nullptr; });
menu->adjustSize();
auto screen = QApplication::primaryScreen();
int w = screen->geometry().width();
proxyMenu->setPos(views()[0]->mapToScene(
QPoint(screen->geometry().x() + (w - proxyMenu->boundingRect().width()) / 2, screen->geometry().y() + 100)));
} }
QGraphicsItem *CropScene::whichItem(QPointF scenePos) { QGraphicsItem *CropScene::whichItem(QPointF scenePos) {
@ -287,7 +296,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
if (item) item->moveBy(delta.x(), delta.y()); if (item) item->moveBy(delta.x(), delta.y());
return; return;
} }
if (buttons == Qt::LeftButton || (prevButtons == Qt::NoButton && prevButtons != buttons)) { if (buttons == Qt::LeftButton) {
if (drawingSelection) { if (drawingSelection) {
drawingSelection->mouseDragEvent(e, this); drawingSelection->mouseDragEvent(e, this);
} else { } else {
@ -323,10 +332,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
drawingRect = false; drawingRect = false;
if (drawingSelection) { if (drawingSelection) {
drawingSelection->mouseDragEndEvent(e, this); drawingSelection->mouseDragEndEvent(e, this);
delete drawingSelection; setDrawingSelection(drawingName, drawingSelectionMaker);
drawingSelection = drawingSelectionMaker();
if (drawingSelection)
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;

View File

@ -24,6 +24,8 @@ void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
} else { } else {
QPointF p = scene->cursorPosition(); 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())));
auto area = rect->rect();
if (area.width() > 1 && area.height() > 1 && area.top() > 1 && area.left() > 1)
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());
} }

View File

@ -11,7 +11,6 @@ public:
return "Blur"; return "Blur";
} }
~BlurItem() { ~BlurItem() {
return;
} }
bool init(CropScene *) override; bool init(CropScene *) override;
@ -21,7 +20,7 @@ public:
private: private:
QGraphicsBlurEffect *effect; QGraphicsBlurEffect *effect;
QPointF pos; QPointF pos;
QGraphicsRectItem *rect; QGraphicsRectItem *rect = 0;
QGraphicsPixmapItem *pixmap; QGraphicsPixmapItem *pixmap;
}; };