Finish up work for #46

This commit is contained in:
ArsenArsen 2017-12-06 20:00:17 +01:00
parent edc462ab6f
commit 276b645e2c
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
2 changed files with 70 additions and 40 deletions

View File

@ -6,6 +6,7 @@
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QKeyEvent>
#include <QMenu>
#include <settings.hpp>
#include <utils.hpp>
@ -222,3 +223,51 @@ void ScreenOverlay::loadSettings() {
setMovementPattern(settings::settings().value("movementPattern", MP_HJKL).value<MovementPattern>());
setGrid(settings::settings().value("gridEnabled", true).toBool());
}
void ScreenOverlay::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
QMenu menu(e->widget());
connect(menu.addAction("Screen overlay settings"), &QAction::triggered, this, &ScreenOverlay::showSettings);
customizeContextMenu(e, &menu);
menu.exec(e->screenPos());
}
void ScreenOverlay::setCursorPos(QPointF cursorPos) {
if (!pixmap().rect().contains(cursorPos.toPoint())) return;
_cursorPos = cursorPos;
}
QPointF ScreenOverlay::cursorPos() {
return _cursorPos;
}
void ScreenOverlay::setGrid(bool grid) {
_grid = grid;
if (grid) {
updateMagnifierGrid();
} else {
for (auto r : gridRectsX) delete r;
gridRectsX.clear();
for (auto r : gridRectsY) delete r;
gridRectsY.clear();
}
}
bool ScreenOverlay::grid() {
return _grid;
}
QColor ScreenOverlay::highlight() {
return _highlight;
}
QPixmap &ScreenOverlay::pixmap() {
return _pixmap;
}
void ScreenOverlay::setMovementPattern(MovementPattern nmp) {
_movementPattern = nmp;
}
ScreenOverlay::MovementPattern ScreenOverlay::movementPattern() {
return _movementPattern;
}

View File

@ -5,65 +5,42 @@
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QMetaType>
class ScreenOverlay : public QGraphicsScene {
Q_OBJECT
public:
enum MovementPattern { MP_JKL, MP_HJKL, MP_ARROWS };
explicit ScreenOverlay(QPixmap pixmap, QObject *parent = 0);
void moveMouse(QPoint newPoint);
void moveMouseBy(QPoint delta);
MovementPattern movementPattern() {
return _movementPattern;
}
void setMovementPattern(MovementPattern nmp) {
_movementPattern = nmp;
}
MovementPattern movementPattern();
void setMovementPattern(MovementPattern nmp);
QPixmap &pixmap() {
return _pixmap;
}
void updateMag();
virtual QString generateMagHint() {
return QString();
};
void hideMag();
QPixmap &pixmap();
void updateMagnifierGrid();
QColor highlight() {
return _highlight;
}
QColor highlight();
void setHighlight(QColor highlight);
bool grid() {
return _grid;
}
void setGrid(bool grid) {
_grid = grid;
if (grid) {
updateMagnifierGrid();
} else {
for (auto r : gridRectsX) delete r;
gridRectsX.clear();
for (auto r : gridRectsY) delete r;
gridRectsY.clear();
}
}
QPointF cursorPos() {
return _cursorPos;
}
void setCursorPos(QPointF cursorPos) {
if (!pixmap().rect().contains(cursorPos.toPoint())) return;
_cursorPos = cursorPos;
}
bool grid();
void setGrid(bool grid);
QPointF cursorPos();
void setCursorPos(QPointF cursorPos);
public slots:
void showSettings();
void hide();
void show();
void loadSettings();
void updateMag();
void hideMag();
void moveMouse(QPoint newPoint);
void moveMouseBy(QPoint delta);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
void wheelEvent(QGraphicsSceneWheelEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
virtual void mouseMoved(QGraphicsSceneMouseEvent *, QPointF, QPointF) {
}
@ -72,6 +49,8 @@ protected:
virtual QString generateHint() {
return QString();
}
virtual void customizeContextMenu(QGraphicsSceneContextMenuEvent *, QMenu *) {
}
private:
QPointF _cursorPos = QPoint(0, 0);
@ -88,4 +67,6 @@ private:
MovementPattern _movementPattern = MP_ARROWS;
};
Q_DECLARE_METATYPE(ScreenOverlay::MovementPattern)
#endif /* SCREENOVERLAY_HPP */