add space to toggle keyboard selection
This commit is contained in:
parent
0acf727347
commit
6220082042
@ -216,7 +216,7 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
|
|||||||
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);
|
||||||
if (item) item->moveBy(delta.x(), delta.y());
|
if (item) item->moveBy(cursorPos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (buttons == Qt::LeftButton) {
|
if (buttons == Qt::LeftButton) {
|
||||||
@ -225,7 +225,11 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
|
|||||||
drawingSelection->mouseDragEvent(e, this);
|
drawingSelection->mouseDragEvent(e, this);
|
||||||
} else {
|
} else {
|
||||||
QPointF p = cursorPos;
|
QPointF p = cursorPos;
|
||||||
if (rect == nullptr) {
|
if (!drawingRect || rect == nullptr) {
|
||||||
|
if (rect) {
|
||||||
|
delete rect;
|
||||||
|
rect = nullptr;
|
||||||
|
}
|
||||||
drawingRect = true;
|
drawingRect = true;
|
||||||
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
|
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
|
||||||
initPos = p;
|
initPos = p;
|
||||||
@ -235,7 +239,7 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
|
|||||||
rect->setZValue(1);
|
rect->setZValue(1);
|
||||||
addItem(rect);
|
addItem(rect);
|
||||||
} else {
|
} else {
|
||||||
if (prevButtons == Qt::NoButton) {
|
if (prevButtons == Qt::NoButton && !keyboardActiveSelection()) {
|
||||||
initPos = p;
|
initPos = p;
|
||||||
rect->setRect(p.x(), p.y(), 1, 1);
|
rect->setRect(p.x(), p.y(), 1, 1);
|
||||||
} else {
|
} else {
|
||||||
@ -257,14 +261,12 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
if (drawingSelection) {
|
if (drawingSelection) {
|
||||||
drawingSelection->mouseDragEndEvent(e, this);
|
drawingSelection->mouseDragEndEvent(e, this);
|
||||||
setDrawingSelection(drawingName, drawingSelectionMaker);
|
setDrawingSelection(drawingName, drawingSelectionMaker);
|
||||||
} else if (settings::settings().value("quickMode", false).toBool() && !proxyMenu->sceneBoundingRect().contains(e->scenePos()))
|
} else if (!proxyMenu->sceneBoundingRect().contains(e->scenePos()) && settings::settings().value("quickMode", false).toBool()) {
|
||||||
done(true);
|
done(true);
|
||||||
|
}
|
||||||
prevButtons = Qt::NoButton;
|
prevButtons = Qt::NoButton;
|
||||||
|
|
||||||
if (e->modifiers() & Qt::ControlModifier)
|
if (e->modifiers() & Qt::ControlModifier) e->accept();
|
||||||
e->accept();
|
|
||||||
else
|
|
||||||
QGraphicsScene::mouseReleaseEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
@ -273,10 +275,7 @@ void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
if (item && item != proxyMenu) removeItem(item);
|
if (item && item != proxyMenu) removeItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->modifiers() & Qt::ControlModifier)
|
if (e->modifiers() & Qt::ControlModifier) e->accept();
|
||||||
e->accept();
|
|
||||||
else
|
|
||||||
QGraphicsScene::mousePressEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function<DrawItem *()> item) {
|
void CropScene::addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function<DrawItem *()> item) {
|
||||||
|
@ -73,16 +73,17 @@ void ScreenOverlay::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
mouseMoved(e, cursorPos(), delta);
|
mouseMoved(e, cursorPos(), delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenOverlay::moveMouse(QPoint newPos) {
|
void ScreenOverlay::moveMouse(QPoint newPos, bool spaceHeld) {
|
||||||
QMouseEvent eve(QEvent::MouseMove, newPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
QMouseEvent eve(QEvent::MouseMove, newPos, spaceHeld ? Qt::LeftButton : Qt::NoButton,
|
||||||
|
spaceHeld ? Qt::LeftButton : Qt::NoButton, Qt::NoModifier);
|
||||||
for (auto &v : views()) {
|
for (auto &v : views()) {
|
||||||
QCursor::setPos(v->mapToGlobal(newPos));
|
QCursor::setPos(v->mapToGlobal(newPos));
|
||||||
QApplication::sendEvent(v->viewport(), &eve);
|
QApplication::sendEvent(v->viewport(), &eve);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenOverlay::moveMouseBy(QPoint delta) {
|
void ScreenOverlay::moveMouseBy(QPoint delta, bool spaceHeld) {
|
||||||
moveMouse(cursorPos().toPoint() + delta);
|
moveMouse(cursorPos().toPoint() + delta, spaceHeld);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenOverlay::hideMag() {
|
void ScreenOverlay::hideMag() {
|
||||||
@ -176,38 +177,48 @@ void ScreenOverlay::setHighlight(QColor highlight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScreenOverlay::keyPressEvent(QKeyEvent *e) {
|
void ScreenOverlay::keyPressEvent(QKeyEvent *e) {
|
||||||
|
if (e->key() == Qt::Key_Space) {
|
||||||
|
selectActive = !selectActive;
|
||||||
|
if (!selectActive) {
|
||||||
|
for (auto *v : views()) {
|
||||||
|
QMouseEvent eve(QEvent::MouseButtonRelease, cursorPos(), Qt::LeftButton, Qt::LeftButton, e->modifiers());
|
||||||
|
QApplication::sendEvent(v->viewport(), &eve);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (movementPattern()) {
|
switch (movementPattern()) {
|
||||||
case MP_JKL:
|
case MP_JKL:
|
||||||
if (e->key() == Qt::Key_J)
|
if (e->key() == Qt::Key_J)
|
||||||
moveMouseBy(QPoint(-1, 0));
|
moveMouseBy(QPoint(-1, 0), selectActive);
|
||||||
else if (e->key() == Qt::Key_K)
|
else if (e->key() == Qt::Key_K)
|
||||||
moveMouseBy(QPoint(0, 1));
|
moveMouseBy(QPoint(0, 1), selectActive);
|
||||||
else if (e->key() == Qt::Key_L)
|
else if (e->key() == Qt::Key_L)
|
||||||
moveMouseBy(QPoint(0, -1));
|
moveMouseBy(QPoint(0, -1), selectActive);
|
||||||
else if (e->key() == Qt::Key_Semicolon)
|
else if (e->key() == Qt::Key_Semicolon)
|
||||||
moveMouseBy(QPoint(1, 0));
|
moveMouseBy(QPoint(1, 0), selectActive);
|
||||||
break;
|
break;
|
||||||
case MP_HJKL:
|
case MP_HJKL:
|
||||||
if (e->key() == Qt::Key_H)
|
if (e->key() == Qt::Key_H)
|
||||||
moveMouseBy(QPoint(-1, 0));
|
moveMouseBy(QPoint(-1, 0), selectActive);
|
||||||
else if (e->key() == Qt::Key_J)
|
else if (e->key() == Qt::Key_J)
|
||||||
moveMouseBy(QPoint(0, 1));
|
moveMouseBy(QPoint(0, 1), selectActive);
|
||||||
else if (e->key() == Qt::Key_K)
|
else if (e->key() == Qt::Key_K)
|
||||||
moveMouseBy(QPoint(0, -1));
|
moveMouseBy(QPoint(0, -1), selectActive);
|
||||||
else if (e->key() == Qt::Key_L)
|
else if (e->key() == Qt::Key_L)
|
||||||
moveMouseBy(QPoint(1, 0));
|
moveMouseBy(QPoint(1, 0), selectActive);
|
||||||
break;
|
break;
|
||||||
case MP_ARROWS:
|
case MP_ARROWS:
|
||||||
if (e->key() == Qt::Key_Left)
|
if (e->key() == Qt::Key_Left)
|
||||||
moveMouseBy(QPoint(-1, 0));
|
moveMouseBy(QPoint(-1, 0), selectActive);
|
||||||
else if (e->key() == Qt::Key_Down)
|
else if (e->key() == Qt::Key_Down)
|
||||||
moveMouseBy(QPoint(0, 1));
|
moveMouseBy(QPoint(0, 1), selectActive);
|
||||||
else if (e->key() == Qt::Key_Up)
|
else if (e->key() == Qt::Key_Up)
|
||||||
moveMouseBy(QPoint(0, -1));
|
moveMouseBy(QPoint(0, -1), selectActive);
|
||||||
else if (e->key() == Qt::Key_Right)
|
else if (e->key() == Qt::Key_Right)
|
||||||
moveMouseBy(QPoint(1, 0));
|
moveMouseBy(QPoint(1, 0), selectActive);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
e->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenOverlay::hide() {
|
void ScreenOverlay::hide() {
|
||||||
@ -284,3 +295,7 @@ void ScreenOverlay::setMovementPattern(MovementPattern nmp) {
|
|||||||
ScreenOverlay::MovementPattern ScreenOverlay::movementPattern() {
|
ScreenOverlay::MovementPattern ScreenOverlay::movementPattern() {
|
||||||
return _movementPattern;
|
return _movementPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScreenOverlay::keyboardActiveSelection() {
|
||||||
|
return selectActive;
|
||||||
|
}
|
||||||
|
@ -35,10 +35,11 @@ public slots:
|
|||||||
void hideMag();
|
void hideMag();
|
||||||
void showMag();
|
void showMag();
|
||||||
void setMagVisibility(bool visible);
|
void setMagVisibility(bool visible);
|
||||||
void moveMouse(QPoint newPoint);
|
void moveMouse(QPoint newPoint, bool spaceHeld = false);
|
||||||
void moveMouseBy(QPoint delta);
|
void moveMouseBy(QPoint delta, bool spaceHeld = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool keyboardActiveSelection();
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
|
||||||
void wheelEvent(QGraphicsSceneWheelEvent *e) override;
|
void wheelEvent(QGraphicsSceneWheelEvent *e) override;
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
@ -65,6 +66,7 @@ private:
|
|||||||
QList<QGraphicsRectItem *> gridRectsY;
|
QList<QGraphicsRectItem *> gridRectsY;
|
||||||
QColor _highlight = Qt::cyan;
|
QColor _highlight = Qt::cyan;
|
||||||
bool _grid = true;
|
bool _grid = true;
|
||||||
|
bool selectActive = false;
|
||||||
QPixmap _pixmap;
|
QPixmap _pixmap;
|
||||||
MovementPattern _movementPattern = MP_ARROWS;
|
MovementPattern _movementPattern = MP_ARROWS;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user