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