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 <QGraphicsSceneMouseEvent>
#include <QGraphicsView> #include <QGraphicsView>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu>
#include <settings.hpp> #include <settings.hpp>
#include <utils.hpp> #include <utils.hpp>
@ -222,3 +223,51 @@ void ScreenOverlay::loadSettings() {
setMovementPattern(settings::settings().value("movementPattern", MP_HJKL).value<MovementPattern>()); setMovementPattern(settings::settings().value("movementPattern", MP_HJKL).value<MovementPattern>());
setGrid(settings::settings().value("gridEnabled", true).toBool()); 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 <QGraphicsRectItem>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
#include <QMetaType>
class ScreenOverlay : public QGraphicsScene { class ScreenOverlay : public QGraphicsScene {
Q_OBJECT Q_OBJECT
public: public:
enum MovementPattern { MP_JKL, MP_HJKL, MP_ARROWS }; enum MovementPattern { MP_JKL, MP_HJKL, MP_ARROWS };
explicit ScreenOverlay(QPixmap pixmap, QObject *parent = 0); explicit ScreenOverlay(QPixmap pixmap, QObject *parent = 0);
void moveMouse(QPoint newPoint); MovementPattern movementPattern();
void moveMouseBy(QPoint delta); void setMovementPattern(MovementPattern nmp);
MovementPattern movementPattern() {
return _movementPattern;
}
void setMovementPattern(MovementPattern nmp) {
_movementPattern = nmp;
}
QPixmap &pixmap() { QPixmap &pixmap();
return _pixmap;
}
void updateMag();
virtual QString generateMagHint() {
return QString();
};
void hideMag();
void updateMagnifierGrid(); void updateMagnifierGrid();
QColor highlight() { QColor highlight();
return _highlight;
}
void setHighlight(QColor highlight); void setHighlight(QColor highlight);
bool grid() { bool grid();
return _grid; void setGrid(bool grid);
} QPointF cursorPos();
void setGrid(bool grid) { void setCursorPos(QPointF cursorPos);
_grid = grid;
if (grid) { public slots:
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;
}
void showSettings(); void showSettings();
void hide(); void hide();
void show(); void show();
void loadSettings(); void loadSettings();
void updateMag();
void hideMag();
void moveMouse(QPoint newPoint);
void moveMouseBy(QPoint delta);
protected: protected:
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;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
virtual void mouseMoved(QGraphicsSceneMouseEvent *, QPointF, QPointF) { virtual void mouseMoved(QGraphicsSceneMouseEvent *, QPointF, QPointF) {
} }
@ -72,6 +49,8 @@ protected:
virtual QString generateHint() { virtual QString generateHint() {
return QString(); return QString();
} }
virtual void customizeContextMenu(QGraphicsSceneContextMenuEvent *, QMenu *) {
}
private: private:
QPointF _cursorPos = QPoint(0, 0); QPointF _cursorPos = QPoint(0, 0);
@ -88,4 +67,6 @@ private:
MovementPattern _movementPattern = MP_ARROWS; MovementPattern _movementPattern = MP_ARROWS;
}; };
Q_DECLARE_METATYPE(ScreenOverlay::MovementPattern)
#endif /* SCREENOVERLAY_HPP */ #endif /* SCREENOVERLAY_HPP */