Browse Source

Add ScreenOverlaySettings for later use

gotta leave for class now
tags/v5.0.0^2
ArsenArsen 5 years ago
parent
commit
edc462ab6f
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
  1. 20
      src/colorpicker/colorpickerscene.cpp
  2. 8
      src/colorpicker/colorpickerscene.hpp
  3. 6
      src/cropeditor/cropeditor.cpp
  4. 27
      src/cropeditor/cropscene.cpp
  5. 6
      src/cropeditor/cropscene.hpp
  6. 12
      src/cropeditor/cropview.cpp
  7. 6
      src/cropeditor/cropview.hpp
  8. 10
      src/cropeditor/settings/brushpenselection.cpp
  9. 4
      src/cropeditor/settings/brushpenselection.hpp
  10. 303
      src/cropeditor/settings/brushpenselection.ui
  11. 80
      src/screenoverlay/screenoverlay.cpp
  12. 35
      src/screenoverlay/screenoverlay.hpp
  13. 29
      src/screenoverlay/screenoverlaysettings.cpp
  14. 29
      src/screenoverlay/screenoverlaysettings.hpp
  15. 104
      src/screenoverlay/screenoverlaysettings.ui
  16. 0
      src/screenoverlay/screenoverlayview.cpp
  17. 0
      src/screenoverlay/screenoverlayview.hpp
  18. 14
      src/src.pro
  19. 1
      src/utils.hpp

20
src/colorpicker/colorpickerscene.cpp

@ -6,7 +6,7 @@
#include <QGraphicsPixmapItem>
#include <QGraphicsTextItem>
#include <QTimer>
#include <screenoverlayview.hpp>
#include <screenoverlay/screenoverlayview.hpp>
#include <settings.hpp>
ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
@ -17,23 +17,11 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
activateWindow();
setGeometry(pixmap.rect());
QPoint p = utils::smallestScreenCoordinate()
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
move(p.x(), p.y());
if (QApplication::screens().size() == 1)
showFullScreen();
else
show();
ScreenOverlay::show();
}
void ColorPickerScene::mouseMoved(QGraphicsSceneMouseEvent *event, QPointF cursor, QPointF delta) {
color = image.pixelColor(cursorPos().toPoint());
qreal bottom = rect().bottom(); // max y
qreal right = rect().right(); // max x
QPointF origPoint = cursorPos() + QPoint(25, 0);
QPointF scopePoint = cursorPos();
QPointF resPoint = origPoint;
void ColorPickerScene::mouseMoved(QGraphicsSceneMouseEvent *, QPointF cursorPos, QPointF) {
color = image.pixelColor(cursorPos.toPoint());
}
void ColorPickerScene::keyPressEvent(QKeyEvent *event) {

8
src/colorpicker/colorpickerscene.hpp

@ -7,15 +7,14 @@
#include <QGraphicsTextItem>
#include <QKeyEvent>
#include <QTimer>
#include <screenoverlayview.hpp>
#include <screenoverlay.hpp>
#include <screenoverlay/screenoverlay.hpp>
#include <screenoverlay/screenoverlayview.hpp>
#include <utils.hpp>
class ColorPickerScene : public ScreenOverlay, public ScreenOverlayView {
Q_DECLARE_TR_FUNCTIONS(ColorPickerScene)
public:
ColorPickerScene(QPixmap pixmap, QWidget *parent = nullptr);
void mouseMoved(QGraphicsSceneMouseEvent *event, QPointF cursorPos, QPointF delta) override;
void keyPressEvent(QKeyEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
QString generateHint() override;
@ -23,6 +22,9 @@ public:
new ColorPickerScene(utils::fullscreen());
}
protected:
void mouseMoved(QGraphicsSceneMouseEvent *, QPointF cursorPos, QPointF) override;
private:
QImage image;
QColor color;

6
src/cropeditor/cropeditor.cpp

@ -13,10 +13,6 @@
CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
scene = new CropScene(parent, image);
view = new CropView(scene);
if (QApplication::screens().size() > 1)
view->show();
else
view->showFullScreen();
view->raise();
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(image);
pixmapItem->setZValue(-1);
@ -29,7 +25,7 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
view->move(p.x(), p.y());
view->setWindowTitle(tr("KShare Crop Editor"));
view->activateWindow();
scene->show();
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
}

27
src/cropeditor/cropscene.cpp

@ -167,28 +167,6 @@ QGraphicsItem *CropScene::whichItem(QPointF scenePos) {
return nullptr;
}
void CropScene::hide() {
setVisible(false);
}
void CropScene::show() {
setVisible(true);
}
void CropScene::setVisible(bool visible) {
for (auto view : views()) {
view->setVisible(visible);
if (visible) {
if (QApplication::screens().size() == 1) view->showFullScreen();
QPoint p = utils::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(),
settings::settings().value("cropy", 0).toInt());
view->move(p.x(), p.y());
view->setWindowTitle(tr("KShare Crop Editor"));
view->activateWindow();
}
}
}
void CropScene::fontAsk() {
hide();
bool ok = false;
@ -348,7 +326,10 @@ QString CropScene::generateHint() {
QString rectStr("(-1, -1, 0, 0)");
if (rect) {
rectStr = "(%0, %1, %2, %3)";
rectStr = rectStr.arg(rect->rect().x()).arg(rect->rect().y()).arg(rect->rect().width()).arg(rect->rect().height());
rectStr = rectStr.arg(qRound(rect->rect().x()))
.arg(qRound(rect->rect().y()))
.arg(qRound(rect->rect().width()))
.arg(qRound(rect->rect().height()));
}
return QString("ptr: (%0, %1)\nsel: %2").arg(qRound(cursorPos().x())).arg(qRound(cursorPos().y())).arg(rectStr);
}

6
src/cropeditor/cropscene.hpp

@ -1,7 +1,6 @@
#ifndef CROPSCENE_HPP
#define CROPSCENE_HPP
#include "../screenoverlay.hpp"
#include <QFont>
#include <QGraphicsScene>
#include <QGraphicsSceneContextMenuEvent>
@ -11,7 +10,8 @@
#include <QMenuBar>
#include <cropeditor/selectionrectangle.hpp>
#include <functional>
#include <screenoverlayview.hpp>
#include <screenoverlay/screenoverlay.hpp>
#include <screenoverlay/screenoverlayview.hpp>
#include <utils.hpp>
class CropScene;
@ -33,8 +33,6 @@ public:
return rect;
}
QGraphicsItem *whichItem(QPointF scenePos);
void hide();
void show();
void setVisible(bool visible);
public slots:

12
src/cropeditor/cropview.cpp

@ -1,8 +1,20 @@
#include "cropview.hpp"
#include <settings.hpp>
#include <utils.hpp>
CropView::CropView(QGraphicsScene *scene) : ScreenOverlayView(scene) {
setCursor(Qt::BlankCursor);
}
CropView::~CropView() {
}
void CropView::showEvent(QShowEvent *) {
QPoint p = utils::smallestScreenCoordinate()
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
if (QApplication::screens().size() == 1) showFullScreen();
move(p);
setWindowTitle(tr("KShare Crop Editor"));
activateWindow();
}

6
src/cropeditor/cropview.hpp

@ -2,12 +2,16 @@
#define CROPVIEW_HPP
#include <QKeyEvent>
#include <screenoverlayview.hpp>
#include <QCoreApplication>
#include <screenoverlay/screenoverlayview.hpp>
class CropView : public ScreenOverlayView {
Q_DECLARE_TR_FUNCTIONS(CropScene)
public:
CropView(QGraphicsScene *scene);
~CropView();
protected:
void showEvent(QShowEvent *e) override;
};
#endif // CROPVIEW_HPP

10
src/cropeditor/settings/brushpenselection.cpp

@ -21,8 +21,6 @@ BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::B
ui->radSlider->setValue(settings::settings().value("blur/radius", 5.).toDouble() * 100);
ui->radSpinner->setValue(settings::settings().value("blur/radius", 5.).toDouble());
ui->gridBox->setChecked(scene->grid());
ui->cosmetic->setChecked(scene->pen().isCosmetic());
ui->widthSlider->setValue(scene->pen().width());
ui->widthSpinner->setValue(scene->pen().widthF());
@ -39,7 +37,6 @@ BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::B
brush = scene->brush().color();
ui->alphaSlider->setValue(brush.alpha());
ui->alphaSpin->setValue(brush.alpha());
highlight = scene->highlight();
setWindowTitle(tr("Crop editor settings"));
this->scene = scene;
@ -64,15 +61,12 @@ void BrushPenSelection::on_buttonBox_accepted() {
scene->pen().setCosmetic(ui->cosmetic->isChecked());
scene->pen().setWidthF(ui->widthSpinner->value());
scene->brush().setColor(brush);
scene->setHighlight(highlight);
scene->setGrid(ui->gridBox->isChecked());
scene->brush().setStyle((Qt::BrushStyle)ui->brushStyle->currentIndex());
settings::settings().setValue("penColor", scene->pen().color());
settings::settings().setValue("penCosmetic", scene->pen().isCosmetic());
settings::settings().setValue("penWidth", scene->pen().widthF());
settings::settings().setValue("brushColor", scene->brush().color());
settings::settings().setValue("highlightColor", scene->highlight());
settings::settings().setValue("gridEnabled", scene->grid());
settings::settings().setValue("brushStyle", (int)scene->brush().style());
settings::settings().setValue("brushPath", ui->pathItemHasBrush->isChecked());
@ -112,7 +106,3 @@ void BrushPenSelection::on_alphaSpin_valueChanged(int arg1) {
void BrushPenSelection::on_penAlphaSpin_valueChanged(int arg1) {
pen.setAlpha(arg1);
}
void BrushPenSelection::on_highlightColor_clicked() {
highlight = QColorDialog::getColor(highlight, this, tr("Highlight color"));
}

4
src/cropeditor/settings/brushpenselection.hpp

@ -27,12 +27,10 @@ private slots:
void on_widthSpinner_valueChanged(double arg1);
void on_penAlphaSpin_valueChanged(int arg1);
void on_highlightColor_clicked();
private:
Ui::BrushPenSelection *ui;
CropScene *scene;
QColor brush, pen, highlight;
QColor brush, pen;
};
#endif // BRUSHPENSELECTION_HPP

303
src/cropeditor/settings/brushpenselection.ui

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>442</width>
<height>550</height>
<height>493</height>
</rect>
</property>
<property name="focusPolicy">
@ -17,157 +17,7 @@
<string notr="true">Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Pen settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QSlider" name="widthSlider">
<property name="maximum">
<number>2500</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="penColor">
<property name="text">
<string>Choose pen color</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="cosmetic">
<property name="text">
<string>Cosmetic</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Pen alpha</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="widthSpinner"/>
</item>
<item row="6" column="0">
<widget class="QSlider" name="penAlphaSlider">
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="penAlphaSpin">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="3">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Blur settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0" colspan="2">
<widget class="QSlider" name="radSlider">
<property name="maximum">
<number>3000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="performance">
<property name="text">
<string>Performance Hint</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="animated">
<property name="text">
<string>Animated Hint</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="quality">
<property name="text">
<string>Quality Hint</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="whatsThis">
<string notr="true">http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum</string>
</property>
<property name="text">
<string>&lt;a href=&quot;http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum&quot;&gt;Blur Hints</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Blur Radius</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="radSpinner">
<property name="suffix">
<string notr="true">px</string>
</property>
<property name="maximum">
<double>30.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" rowspan="5">
<item row="1" column="0" rowspan="4">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Brush settings</string>
@ -293,7 +143,84 @@
</layout>
</widget>
</item>
<item row="4" column="1" rowspan="2">
<item row="5" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Pen settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QSlider" name="widthSlider">
<property name="maximum">
<number>2500</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="penColor">
<property name="text">
<string>Choose pen color</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="cosmetic">
<property name="text">
<string>Cosmetic</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Pen alpha</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="widthSpinner"/>
</item>
<item row="6" column="0">
<widget class="QSlider" name="penAlphaSlider">
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="penAlphaSpin">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="1" rowspan="2">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Arrow settings</string>
@ -329,23 +256,73 @@
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox_5">
<item row="0" column="1" rowspan="3">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Other editor settings</string>
<string>Blur settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QCheckBox" name="gridBox">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0" colspan="2">
<widget class="QSlider" name="radSlider">
<property name="maximum">
<number>3000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="performance">
<property name="text">
<string>Enable grid</string>
<string>Performance Hint</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="highlightColor">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="animated">
<property name="text">
<string>Highligh color</string>
<string>Animated Hint</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="quality">
<property name="text">
<string>Quality Hint</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="whatsThis">
<string notr="true">http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum</string>
</property>
<property name="text">
<string>&lt;a href=&quot;http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum&quot;&gt;Blur Hints</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Blur Radius</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="radSpinner">
<property name="suffix">
<string notr="true">px</string>
</property>
<property name="maximum">
<double>30.000000000000000</double>
</property>
</widget>
</item>

80
src/screenoverlay.cpp → src/screenoverlay/screenoverlay.cpp

@ -1,8 +1,11 @@
#include "screenoverlay.hpp"
#include "screenoverlaysettings.hpp"
#include <QApplication>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QKeyEvent>
#include <settings.hpp>
#include <utils.hpp>
@ -34,6 +37,7 @@ ScreenOverlay::ScreenOverlay(QPixmap pixmap, QObject *parent) : QGraphicsScene(p
magnifierHintBox->setZValue(199);
magnifierHint->setZValue(199);
updateMag();
loadSettings();
}
void ScreenOverlay::wheelEvent(QGraphicsSceneWheelEvent *e) {
@ -59,7 +63,7 @@ void ScreenOverlay::wheelEvent(QGraphicsSceneWheelEvent *e) {
void ScreenOverlay::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
QPointF delta = e->scenePos() - cursorPos();
if (e->modifiers() & Qt::ShiftModifier) {
_cursorPos += delta / 2;
setCursorPos(cursorPos() + (delta / 2));
QCursor::setPos(views()[0]->mapToGlobal(cursorPos().toPoint()));
} else
setCursorPos(e->scenePos());
@ -68,6 +72,18 @@ 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);
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::hideMag() {
magnifier->setVisible(false);
cursorItem->setVisible(false);
@ -144,3 +160,65 @@ void ScreenOverlay::setHighlight(QColor highlight) {
gridRectsY[i]->setBrush(c);
highlightChanged(highlight);
}
void ScreenOverlay::keyPressEvent(QKeyEvent *e) {
switch (movementPattern()) {
case MP_JKL:
if (e->key() == Qt::Key_J)
moveMouseBy(QPoint(-1, 0));
else if (e->key() == Qt::Key_K)
moveMouseBy(QPoint(0, 1));
else if (e->key() == Qt::Key_L)
moveMouseBy(QPoint(0, -1));
else if (e->key() == Qt::Key_Semicolon)
moveMouseBy(QPoint(1, 0));
break;
case MP_HJKL:
if (e->key() == Qt::Key_H)
moveMouseBy(QPoint(-1, 0));
else if (e->key() == Qt::Key_J)
moveMouseBy(QPoint(0, 1));
else if (e->key() == Qt::Key_K)
moveMouseBy(QPoint(0, -1));
else if (e->key() == Qt::Key_L)
moveMouseBy(QPoint(1, 0));
break;
case MP_ARROWS:
if (e->key() == Qt::Key_Left)
moveMouseBy(QPoint(-1, 0));
else if (e->key() == Qt::Key_Down)
moveMouseBy(QPoint(0, 1));
else if (e->key() == Qt::Key_Up)
moveMouseBy(QPoint(0, -1));
else if (e->key() == Qt::Key_Right)
moveMouseBy(QPoint(1, 0));
break;
}
}
void ScreenOverlay::hide() {
for (auto &v : views()) {
v->hide();
}
}
void ScreenOverlay::show() {
for (auto &v : views()) {
if (QApplication::screens().size() > 1)
v->show();
else
v->showFullScreen();
}
}
void ScreenOverlay::showSettings() {
hide();
ScreenOverlaySettings(this).exec();
show();
}
void ScreenOverlay::loadSettings() {
setHighlight(settings::settings().value("highlightColor", QColor(Qt::cyan)).value<QColor>());
setMovementPattern(settings::settings().value("movementPattern", MP_HJKL).value<MovementPattern>());
setGrid(settings::settings().value("gridEnabled", true).toBool());
}

35
src/screenoverlay.hpp → src/screenoverlay/screenoverlay.hpp

@ -4,21 +4,21 @@
#include <QGraphicsPixmapItem>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsView>
class ScreenOverlay : public QGraphicsScene {
Q_OBJECT
public:
enum MovementPattern { MP_JKL, MP_HJKL, MP_ARROWS };
explicit ScreenOverlay(QPixmap pixmap, QObject *parent = 0);
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
void wheelEvent(QGraphicsSceneWheelEvent *e) override;
virtual void mouseMoved(QGraphicsSceneMouseEvent *, QPointF, QPointF) {
}
virtual void highlightChanged(QColor) {
void moveMouse(QPoint newPoint);
void moveMouseBy(QPoint delta);
MovementPattern movementPattern() {
return _movementPattern;
}
virtual QString generateHint() {
return QString();
void setMovementPattern(MovementPattern nmp) {
_movementPattern = nmp;
}
QPixmap &pixmap() {
@ -52,8 +52,26 @@ public:
return _cursorPos;
}
void setCursorPos(QPointF cursorPos) {
if (!pixmap().rect().contains(cursorPos.toPoint())) return;
_cursorPos = cursorPos;
}
void showSettings();
void hide();
void show();
void loadSettings();
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
void wheelEvent(QGraphicsSceneWheelEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
virtual void mouseMoved(QGraphicsSceneMouseEvent *, QPointF, QPointF) {
}
virtual void highlightChanged(QColor) {
}
virtual QString generateHint() {
return QString();
}
private:
QPointF _cursorPos = QPoint(0, 0);
@ -67,6 +85,7 @@ private:
QColor _highlight = Qt::cyan;
bool _grid = true;
QPixmap _pixmap;
MovementPattern _movementPattern = MP_ARROWS;
};
#endif /* SCREENOVERLAY_HPP */

29
src/screenoverlay/screenoverlaysettings.cpp

@ -0,0 +1,29 @@
#include "screenoverlaysettings.hpp"
#include "ui_screenoverlaysettings.h"
#include <settings.hpp>
#include <QColorDialog>
ScreenOverlaySettings::ScreenOverlaySettings(ScreenOverlay *overlay, QWidget *parent)
: overlay(overlay), QDialog(parent), ui(new Ui::ScreenOverlaySettings) {
ui->setupUi(this);
ui->gridBox->setChecked(overlay->grid());
ui->movementPattern->setCurrentIndex(overlay->movementPattern());
highlight = overlay->highlight();
}
void ScreenOverlaySettings::on_buttonBox_accepted() {
settings::settings().setValue("gridEnabled", ui->gridBox->isChecked());
settings::settings().setValue("highlightColor", highlight);
settings::settings().setValue("movementPattern", ui->movementPattern->currentIndex());
overlay->loadSettings();
}
void ScreenOverlaySettings::on_setHighlight_pressed() {
highlight = QColorDialog::getColor(highlight, this, tr("Highlight color"));
}
ScreenOverlaySettings::~ScreenOverlaySettings() {
delete ui;
}

29
src/screenoverlay/screenoverlaysettings.hpp

@ -0,0 +1,29 @@
#ifndef SCREENOVERLAYSETTINGS_H
#define SCREENOVERLAYSETTINGS_H
#include <QDialog>
#include "screenoverlay.hpp"
namespace Ui {
class ScreenOverlaySettings;
}
class ScreenOverlaySettings : public QDialog
{
Q_OBJECT
public:
explicit ScreenOverlaySettings(ScreenOverlay *overlay, QWidget *parent = 0);
~ScreenOverlaySettings();
private slots:
void on_buttonBox_accepted();
void on_setHighlight_pressed();
private:
Ui::ScreenOverlaySettings *ui;
QColor highlight;
ScreenOverlay *overlay;
};
#endif // SCREENOVERLAYSETTINGS_H

104
src/screenoverlay/screenoverlaysettings.ui

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScreenOverlaySettings</class>
<widget class="QDialog" name="ScreenOverlaySettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>208</width>
<height>179</height>
</rect>
</property>
<property name="windowTitle">
<string>Screen overlay settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Keyboard movement pattern</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="movementPattern">
<item>
<property name="text">
<string>JKL; movement (Home-row)</string>
</property>
</item>
<item>
<property name="text">
<string>HJKL movement (Vim-like)</string>
</property>
</item>
<item>
<property name="text">
<string>Arrow movement</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="gridBox">
<property name="text">
<string>Enable grid</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setHighlight">
<property name="text">
<string>Set highlight color</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ScreenOverlaySettings</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ScreenOverlaySettings</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0
src/screenoverlayview.cpp → src/screenoverlay/screenoverlayview.cpp

0
src/screenoverlayview.hpp → src/screenoverlay/screenoverlayview.hpp

14
src/src.pro

@ -67,9 +67,10 @@ SOURCES += main.cpp\
logs/requestlogging.cpp \
logs/historydialog.cpp \
monospacetextdialog.cpp \
screenoverlayview.cpp \
cropeditor/selectionrectangle.cpp \
screenoverlay.cpp
screenoverlay/screenoverlayview.cpp \
screenoverlay/screenoverlay.cpp \
screenoverlay/screenoverlaysettings.cpp
HEADERS += mainwindow.hpp \
cropeditor/cropeditor.hpp \
@ -116,11 +117,11 @@ HEADERS += mainwindow.hpp \
filenamevalidator.hpp \
logs/requestlogging.hpp \
logs/historydialog.hpp \
screenoverlayview.hpp \
screenoverlayview.hpp \
monospacetextdialog.hpp \
cropeditor/selectionrectangle.hpp \
screenoverlay.hpp
screenoverlay/screenoverlayview.hpp \
screenoverlay/screenoverlay.hpp \
screenoverlay/screenoverlaysettings.hpp
nopkg {
# win32 {
@ -181,7 +182,8 @@ FORMS += mainwindow.ui \
hotkeyinputdialog.ui \
uploaders/default/imgursettingsdialog.ui \
logs/historydialog.ui \
monospacetextdialog.ui
monospacetextdialog.ui \
screenoverlay/screenoverlaysettings.ui
RESOURCES += \
icon.qrc \

1
src/utils.hpp

@ -4,6 +4,7 @@
#include <QApplication>
#include <QPixmap>
#include <QWidget>
#include <QScreen>
namespace utils {
QColor invertColor(QColor color);

Loading…
Cancel
Save