Add clang-format; Make text and blur less annoying

I didn't read the clang-format documentation properly
tags/v5.0.0
ArsenArsen 5 years ago
parent 7737b77671
commit 37ce6f1eda
  1. 47
      .clang-format
  2. 38
      cropeditor/cropeditor.cpp
  3. 22
      cropeditor/cropeditor.hpp
  4. 250
      cropeditor/cropscene.cpp
  5. 82
      cropeditor/cropscene.hpp
  6. 26
      cropeditor/cropview.cpp
  7. 8
      cropeditor/cropview.hpp
  8. 37
      cropeditor/drawing/bluritem.cpp
  9. 25
      cropeditor/drawing/bluritem.hpp
  10. 14
      cropeditor/drawing/dotitem.cpp
  11. 14
      cropeditor/drawing/dotitem.hpp
  12. 18
      cropeditor/drawing/drawitem.hpp
  13. 18
      cropeditor/drawing/lineitem.cpp
  14. 18
      cropeditor/drawing/lineitem.hpp
  15. 24
      cropeditor/drawing/pathitem.cpp
  16. 20
      cropeditor/drawing/pathitem.hpp
  17. 34
      cropeditor/drawing/textitem.cpp
  18. 16
      cropeditor/drawing/textitem.hpp
  19. 54
      cropeditor/settings/blurdialog.cpp
  20. 20
      cropeditor/settings/blurdialog.hpp
  21. 51
      cropeditor/settings/brushpenselection.cpp
  22. 30
      cropeditor/settings/brushpenselection.hpp
  23. 19
      formatter.cpp
  24. 44
      hotkeying.cpp
  25. 94
      io/ioutils.cpp
  26. 14
      io/ioutils.hpp
  27. 77
      main.cpp
  28. 222
      mainwindow.cpp
  29. 50
      mainwindow.hpp
  30. 7
      notifications.cpp
  31. 3
      notifications.hpp
  32. 14
      screenshotter.cpp
  33. 16
      screenshotutil.cpp
  34. 17
      settings.cpp
  35. 512
      uploaders/customuploader.cpp
  36. 34
      uploaders/customuploader.hpp
  37. 4
      uploaders/default/clipboarduploader.cpp
  38. 12
      uploaders/default/clipboarduploader.hpp
  39. 31
      uploaders/default/imguruploader.cpp
  40. 12
      uploaders/default/imguruploader.hpp
  41. 8
      uploaders/uploader.hpp
  42. 94
      uploaders/uploadersingleton.cpp
  43. 38
      uploaders/uploadersingleton.hpp

@ -0,0 +1,47 @@
AccessModifierOffset: 0
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BreakBeforeBinaryOperators: true
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 0
Cpp11BracedListStyle: false
DerivePointerBinding: false
IndentCaseLabels: false
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 100
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 20
PointerBindsToType: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
Standard: Auto
TabWidth: 4
UseTab: Never

@ -9,28 +9,30 @@
#include <settings.hpp>
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
scene = new CropScene(parent, image);
view = new CropView(scene);
QPixmap *scaled = new QPixmap();
image->scaled(view->width(), view->height()).swap(*scaled);
pixmapItem = new QGraphicsPixmapItem(*image);
pixmapItem->setZValue(-1);
scene->addItem(pixmapItem);
scene->setSceneRect(image->rect());
view->setGeometry(0, 0, image->width(), image->height());
view->showFullScreen();
scene = new CropScene(parent, image);
view = new CropView(scene);
QPixmap *scaled = new QPixmap();
image->scaled(view->width(), view->height()).swap(*scaled);
pixmapItem = new QGraphicsPixmapItem(*image);
pixmapItem->setZValue(-1);
scene->addItem(pixmapItem);
scene->setSceneRect(image->rect());
view->setGeometry(0, 0, image->width(), image->height());
view->showFullScreen();
QTimer::singleShot(0, [&] { view->showFullScreen(); });
QTimer::singleShot(0, [&] { view->showFullScreen(); });
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop);
}
CropEditor::~CropEditor() { delete scene; }
CropEditor::~CropEditor() {
delete scene;
}
void CropEditor::crop(QRect rect) {
QPixmap map = view->grab(rect);
QPixmap *cropp = new QPixmap;
map.swap(*cropp);
delete view;
emit cropped(cropp);
QPixmap map = view->grab(rect);
QPixmap *cropp = new QPixmap;
map.swap(*cropp);
delete view;
emit cropped(cropp);
}

@ -9,18 +9,18 @@
#include <QPixmap>
class CropEditor : public QObject {
Q_OBJECT
public:
CropEditor(QPixmap *image, QObject *parent = 0);
~CropEditor();
signals:
QPixmap *cropped(QPixmap *pixmap);
Q_OBJECT
public:
CropEditor(QPixmap *image, QObject *parent = 0);
~CropEditor();
signals:
QPixmap *cropped(QPixmap *pixmap);
private:
void crop(QRect rect);
CropScene *scene = nullptr;
CropView *view = nullptr;
QGraphicsPixmapItem *pixmapItem = nullptr;
private:
void crop(QRect rect);
CropScene *scene = nullptr;
CropView *view = nullptr;
QGraphicsPixmapItem *pixmapItem = nullptr;
};
#endif // CROPEDITOR_HPP

@ -17,162 +17,154 @@
#include <settings.hpp>
CropScene::CropScene(QObject *parent, QPixmap *pixmap)
: QGraphicsScene(parent), prevButtons(Qt::NoButton),
drawingSelectionMaker([] { return nullptr; }),
_font(settings::settings().value("font", QFont()).value<QFont>()) {
pen().setColor(
settings::settings().value("penColor", pen().color()).value<QColor>());
pen().setCosmetic(
settings::settings().value("penCosmetic", pen().isCosmetic()).toBool());
pen().setWidthF(
settings::settings().value("penWidth", pen().widthF()).toFloat());
brush().setColor(settings::settings()
.value("brushColor", brush().color())
.value<QColor>());
addDrawingAction(menu, "Dot", [] { return new DotItem; });
addDrawingAction(menu, "Path", [] { return new PathItem; });
addDrawingAction(menu, "Blur", [] { return new BlurItem; });
addDrawingAction(menu, "Straight line", [] { return new LineItem; });
addDrawingAction(menu, "Text", [] { return new TextItem; });
QAction *reset = menu.addAction("Reset");
connect(reset, &QAction::triggered,
[&] { setDrawingSelection("None", [] { return nullptr; }); });
menu.addSeparator();
QAction *settings = new QAction;
settings->setText("Settings");
menu.addSeparator();
display = menu.addAction(drawingName);
display->setDisabled(true);
connect(settings, &QAction::triggered,
[&] { BrushPenSelection(this).exec(); });
menu.addAction(settings);
connect(menu.addAction("Set Font"), &QAction::triggered, this,
&CropScene::fontAsk);
_pixmap = pixmap;
QTimer::singleShot(0, [&] {
QPolygonF poly;
poly.append(sceneRect().topLeft());
poly.append(sceneRect().topRight());
poly.append(sceneRect().bottomRight());
poly.append(sceneRect().bottomLeft());
polyItem = new QGraphicsPolygonItem(poly);
polyItem->setBrush(QBrush(QColor(0, 0, 0, 191)));
polyItem->setPen(QPen(Qt::NoPen));
addItem(polyItem);
});
: QGraphicsScene(parent), drawingSelectionMaker([] { return nullptr; }), prevButtons(Qt::NoButton),
_font(settings::settings().value("font", QFont()).value<QFont>()) {
pen().setColor(settings::settings().value("penColor", pen().color()).value<QColor>());
pen().setCosmetic(settings::settings().value("penCosmetic", pen().isCosmetic()).toBool());
pen().setWidthF(settings::settings().value("penWidth", pen().widthF()).toFloat());
brush().setColor(settings::settings().value("brushColor", brush().color()).value<QColor>());
addDrawingAction(menu, "Dot", [] { return new DotItem; });
addDrawingAction(menu, "Path", [] { return new PathItem; });
addDrawingAction(menu, "Blur", [] { return new BlurItem; });
addDrawingAction(menu, "Straight line", [] { return new LineItem; });
addDrawingAction(menu, "Text", [] { return new TextItem; });
QAction *reset = menu.addAction("Reset");
connect(reset, &QAction::triggered, [&] { setDrawingSelection("None", [] { return nullptr; }); });
menu.addSeparator();
QAction *settings = new QAction;
settings->setText("Settings");
menu.addSeparator();
display = menu.addAction(drawingName);
display->setDisabled(true);
connect(settings, &QAction::triggered, [&] { BrushPenSelection(this).exec(); });
menu.addAction(settings);
connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk);
_pixmap = pixmap;
QTimer::singleShot(0, [&] {
QPolygonF poly;
poly.append(sceneRect().topLeft());
poly.append(sceneRect().topRight());
poly.append(sceneRect().bottomRight());
poly.append(sceneRect().bottomLeft());
polyItem = new QGraphicsPolygonItem(poly);
polyItem->setBrush(QBrush(QColor(0, 0, 0, 191)));
polyItem->setPen(QPen(Qt::NoPen));
addItem(polyItem);
});
}
CropScene::~CropScene() { delete drawingSelection; }
CropScene::~CropScene() {
delete drawingSelection;
}
QPen &CropScene::pen() { return _pen; }
QPen &CropScene::pen() {
return _pen;
}
QBrush &CropScene::brush() { return _brush; }
QBrush &CropScene::brush() {
return _brush;
}
QFont &CropScene::font() { return _font; }
QFont &CropScene::font() {
return _font;
}
void CropScene::setDrawingSelection(QString name,
std::function<DrawItem *()> drawAction) {
drawingSelectionMaker = drawAction;
drawingSelection = drawAction();
drawingName = name;
if (drawingSelection)
drawingSelection->init(this);
void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> drawAction) {
drawingSelectionMaker = drawAction;
drawingSelection = drawAction();
drawingName = name;
if (drawingSelection)
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
}
void CropScene::fontAsk() {
bool ok = false;
QFont font = QFontDialog::getFont(&ok, this->font(), nullptr, "Font to use");
if (ok)
_font = font;
bool ok = false;
QFont font = QFontDialog::getFont(&ok, this->font(), nullptr, "Font to use");
if (ok) _font = font;
}
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
auto buttons = e->buttons();
if (buttons == Qt::LeftButton || prevButtons == Qt::NoButton) {
if (drawingSelection) {
drawingSelection->mouseDragEvent(e, this);
} else {
QPointF p = e->scenePos();
if (rect == nullptr) {
rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1);
initPos = p;
QPen pen(Qt::NoBrush, 1);
pen.setColor(Qt::cyan);
rect->setPen(pen);
addItem(rect);
} else {
if (prevButtons == Qt::NoButton) {
initPos = p;
rect->setRect(p.x(), p.y(), 1, 1);
auto buttons = e->buttons();
if (buttons == Qt::LeftButton || prevButtons == Qt::NoButton) {
if (drawingSelection) {
drawingSelection->mouseDragEvent(e, this);
} else {
rect->setRect(
QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()),
qAbs(initPos.x() - p.x()), qAbs(initPos.y() - p.y())));
QPointF p = e->scenePos();
if (rect == nullptr) {
rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1);
initPos = p;
QPen pen(Qt::NoBrush, 1);
pen.setColor(Qt::cyan);
rect->setPen(pen);
addItem(rect);
} else {
if (prevButtons == Qt::NoButton) {
initPos = p;
rect->setRect(p.x(), p.y(), 1, 1);
} else {
rect->setRect(QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()),
qAbs(initPos.y() - p.y())));
}
}
QPolygonF poly;
QPointF theMagicWikipediaPoint(rect->rect().right(), sceneRect().bottom());
poly << sceneRect().topLeft();
poly << sceneRect().topRight();
poly << sceneRect().bottomRight();
poly << theMagicWikipediaPoint;
poly << rect->rect().bottomRight();
poly << rect->rect().topRight();
poly << rect->rect().topLeft();
poly << rect->rect().bottomLeft();
poly << rect->rect().bottomRight();
poly << theMagicWikipediaPoint;
poly << sceneRect().bottomLeft();
poly << sceneRect().topLeft();
this->polyItem->setPolygon(poly);
e->accept();
}
}
QPolygonF poly;
QPointF theMagicWikipediaPoint(rect->rect().right(),
sceneRect().bottom());
poly << sceneRect().topLeft();
poly << sceneRect().topRight();
poly << sceneRect().bottomRight();
poly << theMagicWikipediaPoint;
poly << rect->rect().bottomRight();
poly << rect->rect().topRight();
poly << rect->rect().topLeft();
poly << rect->rect().bottomLeft();
poly << rect->rect().bottomRight();
poly << theMagicWikipediaPoint;
poly << sceneRect().bottomLeft();
poly << sceneRect().topLeft();
this->polyItem->setPolygon(poly);
e->accept();
}
}
prevButtons = buttons;
prevButtons = buttons;
}
void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
qDebug() << "release";
if (drawingSelection) {
drawingSelection->mouseDragEndEvent(e, this);
delete drawingSelection;
drawingSelection = drawingSelectionMaker();
if (drawingSelection)
drawingSelection->init(this);
}
prevButtons = Qt::NoButton;
qDebug() << "release";
if (drawingSelection) {
drawingSelection->mouseDragEndEvent(e, this);
delete drawingSelection;
drawingSelection = drawingSelectionMaker();
if (drawingSelection)
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
}
prevButtons = Qt::NoButton;
}
void CropScene::addDrawingAction(QMenu &menu, QString name,
std::function<DrawItem *()> item) {
QAction *action = new QAction;
action->setText(name);
connect(action, &QAction::triggered,
[this, item, name](bool) { setDrawingSelection(name, item); });
menu.addAction(action);
void CropScene::addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item) {
QAction *action = new QAction;
action->setText(name);
connect(action, &QAction::triggered, [this, item, name](bool) { setDrawingSelection(name, item); });
menu.addAction(action);
}
void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
display->setText(drawingName);
menu.exec(e->screenPos());
e->accept();
display->setText(drawingName);
menu.exec(e->screenPos());
e->accept();
}
void CropScene::keyReleaseEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
done(); // Segfault
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) done(); // Segfault
}
void CropScene::done() {
if (rect) {
rect->setPen(QPen(Qt::NoPen));
emit closedWithRect(rect->rect().toRect());
}
if (rect) {
rect->setPen(QPen(Qt::NoPen));
emit closedWithRect(rect->rect().toRect());
}
}

@ -14,47 +14,47 @@ class CropScene;
#include <cropeditor/drawing/drawitem.hpp>
class CropScene : public QGraphicsScene {
Q_OBJECT
public:
CropScene(QObject *parent, QPixmap *pixmap);
~CropScene();
QPen &pen();
QBrush &brush();
QFont &font();
void setDrawingSelection(QString name,
std::function<DrawItem *()> drawAction);
QPixmap *pixmap() { return _pixmap; }
public slots:
void fontAsk();
signals:
void closedWithRect(QRect rect);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
void keyReleaseEvent(QKeyEvent *e) override;
private:
void addDrawingAction(QMenu &menu, QString name,
std::function<DrawItem *()> item);
void done();
std::function<DrawItem *()> drawingSelectionMaker;
QFlags<Qt::MouseButton> prevButtons;
QPixmap *_pixmap;
QGraphicsRectItem *rect = nullptr;
QPointF initPos;
QPen _pen;
QBrush _brush;
QFont _font;
QGraphicsPolygonItem *polyItem = nullptr;
DrawItem *drawingSelection = nullptr;
QMenu menu;
QString drawingName = "None";
QAction *display;
Q_OBJECT
public:
CropScene(QObject *parent, QPixmap *pixmap);
~CropScene();
QPen &pen();
QBrush &brush();
QFont &font();
void setDrawingSelection(QString name, std::function<DrawItem *()> drawAction);
QPixmap *pixmap() {
return _pixmap;
}
public slots:
void fontAsk();
signals:
void closedWithRect(QRect rect);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
void keyReleaseEvent(QKeyEvent *e) override;
private:
void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item);
void done();
std::function<DrawItem *()> drawingSelectionMaker;
QFlags<Qt::MouseButton> prevButtons;
QPixmap *_pixmap;
QGraphicsRectItem *rect = nullptr;
QPointF initPos;
QPen _pen;
QBrush _brush;
QFont _font;
QGraphicsPolygonItem *polyItem = nullptr;
DrawItem *drawingSelection = nullptr;
QMenu menu;
QString drawingName = "None";
QAction *display;
};
#endif // CROPSCENE_HPP

@ -1,21 +1,19 @@
#include "cropview.hpp"
CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene) {
setFrameShape(
QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform |
QPainter::HighQualityAntialiasing);
setCursor(QCursor(Qt::CrossCursor));
setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
setCursor(QCursor(Qt::CrossCursor));
}
void CropView::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
close();
e->accept();
return;
}
QGraphicsView::keyPressEvent(e);
if (e->key() == Qt::Key_Escape) {
close();
e->accept();
return;
}
QGraphicsView::keyPressEvent(e);
}

@ -5,11 +5,11 @@
#include <QKeyEvent>
class CropView : public QGraphicsView {
public:
CropView(QGraphicsScene *scene);
public:
CropView(QGraphicsScene *scene);
protected:
void keyPressEvent(QKeyEvent *e) override;
protected:
void keyPressEvent(QKeyEvent *e) override;
};
#endif // CROPVIEW_HPP

@ -3,30 +3,27 @@
#include <QDebug>
#include <cropeditor/settings/blurdialog.hpp>
void BlurItem::init(CropScene *) {
effect = new QGraphicsBlurEffect;
BlurDialog(effect).exec();
bool BlurItem::init(CropScene *) {
effect = new QGraphicsBlurEffect;
return BlurDialog(effect).exec();
}
void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (pos.isNull()) {
pos = e->scenePos();
rect = scene->addRect(QRect(e->scenePos().toPoint(), QSize(1, 1)),
QPen(Qt::cyan), Qt::NoBrush);
pixmap = scene->addPixmap(scene->pixmap()->copy(rect->rect().toRect()));
pixmap->setPos(e->scenePos());
pixmap->setZValue(rect->zValue() - 0.1);
pixmap->setGraphicsEffect(effect);
} else {
QPointF p = e->scenePos();
rect->setRect(QRect(qMin(pos.x(), p.x()), qMin(pos.y(), p.y()),
qAbs(pos.x() - p.x()), qAbs(pos.y() - p.y())));
pixmap->setPixmap(scene->pixmap()->copy(rect->rect().toRect()));
pixmap->setPos(rect->rect().topLeft());
}
if (pos.isNull()) {
pos = e->scenePos();
rect = scene->addRect(QRect(e->scenePos().toPoint(), QSize(1, 1)), QPen(Qt::cyan), Qt::NoBrush);
pixmap = scene->addPixmap(scene->pixmap()->copy(rect->rect().toRect()));
pixmap->setPos(e->scenePos());
pixmap->setZValue(rect->zValue() - 0.1);
pixmap->setGraphicsEffect(effect);
} else {
QPointF p = e->scenePos();
rect->setRect(QRect(qMin(pos.x(), p.x()), qMin(pos.y(), p.y()), qAbs(pos.x() - p.x()), qAbs(pos.y() - p.y())));
pixmap->setPixmap(scene->pixmap()->copy(rect->rect().toRect()));
pixmap->setPos(rect->rect().topLeft());
}
}
void BlurItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
if (rect != nullptr)
rect->setPen(Qt::NoPen);
if (rect != nullptr) rect->setPen(Qt::NoPen);
}

@ -6,19 +6,22 @@
#include <QGraphicsEffect>
class BlurItem : public DrawItem {
public:
QString name() { return "Blur"; }
~BlurItem() {}
public:
QString name() {
return "Blur";
}
~BlurItem() {
}
void init(CropScene *) override;
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
bool init(CropScene *) override;
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
private:
QGraphicsBlurEffect *effect;
QPointF pos;
QGraphicsRectItem *rect;
QGraphicsPixmapItem *pixmap;
private:
QGraphicsBlurEffect *effect;
QPointF pos;
QGraphicsRectItem *rect;
QGraphicsPixmapItem *pixmap;
};
#endif // BLURITEM_HPP

@ -1,14 +1,14 @@
#include "dotitem.hpp"
DotItem::DotItem() {}
DotItem::DotItem() {
}
DotItem::~DotItem() {}
DotItem::~DotItem() {
}
void DotItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
scene
->addEllipse(e->pos().x() - 1.5, e->pos().y() - 1.5, 3, 3, scene->pen(),
scene->brush())
->setPos(e->scenePos());
scene->addEllipse(e->pos().x() - 1.5, e->pos().y() - 1.5, 3, 3, scene->pen(), scene->brush())->setPos(e->scenePos());
}
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}

@ -5,12 +5,14 @@
#include "drawitem.hpp"
class DotItem : public DrawItem {
public:
DotItem();
~DotItem();
QString name() { return "Dots (drag to add)"; }
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
public:
DotItem();
~DotItem();
QString name() {
return "Dots (drag to add)";
}
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
};
#endif // DOTITEM_HPP

@ -7,14 +7,16 @@ class DrawItem;
#include <cropeditor/cropscene.hpp>
class DrawItem {
public:
virtual ~DrawItem() {}
virtual QString name() = 0;
virtual void init(CropScene *scene) { Q_UNUSED(scene) }
virtual void mouseDragEvent(QGraphicsSceneMouseEvent *e,
CropScene *scene) = 0;
virtual void mouseDragEndEvent(QGraphicsSceneMouseEvent *e,
CropScene *scene) = 0;
public:
virtual ~DrawItem() {
}
virtual QString name() = 0;
virtual bool init(CropScene *scene) {
Q_UNUSED(scene)
return true;
}
virtual void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
virtual void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
};
#endif // DRAWITEM_HPP

@ -1,14 +1,16 @@
#include "lineitem.hpp"
LineItem::LineItem() {}
LineItem::LineItem() {
}
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (init.isNull()) {
init = e->scenePos();
line = scene->addLine(QLineF(init, init), scene->pen());
} else {
line->setLine(QLineF(init, e->scenePos()));
}
if (init.isNull()) {
init = e->scenePos();
line = scene->addLine(QLineF(init, init), scene->pen());
} else {
line->setLine(QLineF(init, e->scenePos()));
}
}
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}

@ -4,15 +4,17 @@
#include "drawitem.hpp"
class LineItem : public DrawItem {
public:
LineItem();
QString name() override { return "Straight line"; }
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
public:
LineItem();
QString name() override {
return "Straight line";
}
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
private:
QPointF init;
QGraphicsLineItem *line;
private:
QPointF init;
QGraphicsLineItem *line;
};
#endif // LINEITEM_HPP

@ -1,17 +1,21 @@
#include "pathitem.hpp"
PathItem::PathItem() {}
PathItem::PathItem() {
}
PathItem::~PathItem() { delete path; }
PathItem::~PathItem() {
delete path;
}
void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (path == nullptr) {
path = new QPainterPath(e->scenePos());
pathItem = scene->addPath(*path, scene->pen(), scene->brush());
} else {
path->quadTo(path->currentPosition(), e->scenePos());
pathItem->setPath(*path);
}
if (path == nullptr) {
path = new QPainterPath(e->scenePos());
pathItem = scene->addPath(*path, scene->pen(), scene->brush());
} else {
path->quadTo(path->currentPosition(), e->scenePos());
pathItem->setPath(*path);
}
}
void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}

@ -5,16 +5,18 @@
#include "drawitem.hpp"
class PathItem : public DrawItem {
public:
PathItem();
~PathItem();
QString name() { return "Path"; }
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
public:
PathItem();
~PathItem();
QString name() {
return "Path";
}
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
private:
QPainterPath *path = nullptr;
QGraphicsPathItem *pathItem = nullptr;
private:
QPainterPath *path = nullptr;
QGraphicsPathItem *pathItem = nullptr;
};
#endif // PATHITEM_HPP

@ -2,24 +2,28 @@
#include <QInputDialog>
#include <QtMath>
void TextItem::init(CropScene *) {
text = QInputDialog::getText(nullptr, "Text to add", "Input");
bool TextItem::init(CropScene *) {
bool ok;
text = QInputDialog::getText(nullptr, "Text to add", "Input", QLineEdit::Normal, QString(), &ok);
return ok;
}
void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (!textItem) {
textItem = scene->addSimpleText(text, scene->font());
textItem->setPos(e->scenePos());
textItem->setPen(scene->pen());
textItem->setBrush(scene->brush());
} else {
auto ee = 180 + qRadiansToDegrees(
qAtan2((textItem->pos().y() - e->scenePos().y()),
(textItem->pos().x() - e->scenePos().x())));
textItem->setRotation(ee);
}
if (!textItem) {
textItem = scene->addSimpleText(text, scene->font());
textItem->setPos(e->scenePos());
textItem->setPen(scene->pen());
textItem->setBrush(scene->brush());
} else {
auto ee
= 180 + qRadiansToDegrees(qAtan2((textItem->pos().y() - e->scenePos().y()), (textItem->pos().x() - e->scenePos().x())));
textItem->setRotation(ee);
}
}
void TextItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
void TextItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}
QString TextItem::name() { return "Text"; }
QString TextItem::name() {
return "Text";
}

@ -5,15 +5,15 @@
#include <QGraphicsSimpleTextItem>
class TextItem : public DrawItem {
public:
QString name() override;
void init(CropScene *) override;
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
public:
QString name() override;
bool init(CropScene *) override;
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
private:
QGraphicsSimpleTextItem *textItem = nullptr;
QString text;
private:
QGraphicsSimpleTextItem *textItem = nullptr;
QString text;
};
#endif // TEXTITEM_HPP

@ -6,38 +6,38 @@
#include <QDoubleSpinBox>
#include <QSlider>
BlurDialog::BlurDialog(QGraphicsBlurEffect *e, QWidget *parent)
: QDialog(parent), ui(new Ui::BlurDialog) {
effect = e;
ui->setupUi(this);
ui->animated->setChecked(
effect->blurHints().testFlag(QGraphicsBlurEffect::AnimationHint));
ui->performance->setChecked(
effect->blurHints().testFlag(QGraphicsBlurEffect::PerformanceHint));
ui->quality->setChecked(
effect->blurHints().testFlag(QGraphicsBlurEffect::QualityHint));
ui->radSlider->setValue(effect->blurRadius() * 100);
ui->radSpinner->setValue(effect->blurRadius());
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] {
QFlags<QGraphicsBlurEffect::BlurHint> hints;
hints.setFlag(QGraphicsBlurEffect::AnimationHint,
ui->animated->isChecked());
hints.setFlag(QGraphicsBlurEffect::PerformanceHint,
ui->performance->isChecked());
hints.setFlag(QGraphicsBlurEffect::QualityHint, ui->quality->isChecked());
effect->setBlurHints(hints);
effect->setBlurRadius(ui->radSpinner->value());
close();
});
connect(ui->buttonBox, &QDialogButtonBox::rejected, [&] { close(); });
BlurDialog::BlurDialog(QGraphicsBlurEffect *e, QWidget *parent) : QDialog(parent), ui(new Ui::BlurDialog) {
effect = e;
ui->setupUi(this);
ui->animated->setChecked(effect->blurHints().testFlag(QGraphicsBlurEffect::AnimationHint));
ui->performance->setChecked(effect->blurHints().testFlag(QGraphicsBlurEffect::PerformanceHint));
ui->quality->setChecked(effect->blurHints().testFlag(QGraphicsBlurEffect::QualityHint));
ui->radSlider->setValue(effect->blurRadius() * 100);
ui->radSpinner->setValue(effect->blurRadius());
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] {
QFlags<QGraphicsBlurEffect::BlurHint> hints;
hints.setFlag(QGraphicsBlurEffect::AnimationHint, ui->animated->isChecked());
hints.setFlag(QGraphicsBlurEffect::PerformanceHint, ui->performance->isChecked());
hints.setFlag(QGraphicsBlurEffect::QualityHint, ui->quality->isChecked());
effect->setBlurHints(hints);
effect->setBlurRadius(ui->radSpinner->value());
setResult(QDialog::Accepted);
close();
});
connect(ui->buttonBox, &QDialogButtonBox::rejected, [&] {
setResult(QDialog::Rejected);
close();
});
}
BlurDialog::~BlurDialog() { delete ui; }
BlurDialog::~BlurDialog() {
delete ui;
}
void BlurDialog::on_radSpinner_valueChanged(double arg1) {
ui->radSlider->setValue(arg1 * 100);
ui->radSlider->setValue(arg1 * 100);
}
void BlurDialog::on_radSlider_sliderMoved(int position) {
ui->radSpinner->setValue(position / 100.);
ui->radSpinner->setValue(position / 100.);
}

@ -9,19 +9,19 @@ class BlurDialog;
}
class BlurDialog : public QDialog {
Q_OBJECT
Q_OBJECT
public:
explicit BlurDialog(QGraphicsBlurEffect *effect, QWidget *parent = 0);
~BlurDialog();
public:
explicit BlurDialog(QGraphicsBlurEffect *effect, QWidget *parent = 0);
~BlurDialog();
private slots:
void on_radSpinner_valueChanged(double arg1);
void on_radSlider_sliderMoved(int position);
private slots:
void on_radSpinner_valueChanged(double arg1);
void on_radSlider_sliderMoved(int position);
private:
Ui::BlurDialog *ui;
QGraphicsBlurEffect *effect;
private:
Ui::BlurDialog *ui;
QGraphicsBlurEffect *effect;
};
#endif // BLURDIALOG_HPP

@ -9,45 +9,48 @@
#include <cropeditor/cropview.hpp>
#include <settings.hpp>
BrushPenSelection::BrushPenSelection(CropScene *scene)
: QDialog(), ui(new Ui::BrushPenSelection) {
ui->setupUi(this);
ui->cosmetic->setChecked(scene->pen().isCosmetic());
ui->widthSlider->setValue(scene->pen().width());
ui->widthSpinner->setValue(scene->pen().widthF());
pen = scene->pen().color();
brush = scene->brush().color();
this->scene = scene;
BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::BrushPenSelection) {
ui->setupUi(this);
ui->cosmetic->setChecked(scene->pen().isCosmetic());
ui->widthSlider->setValue(scene->pen().width());
ui->widthSpinner->setValue(scene->pen().widthF());
pen = scene->pen().color();
brush = scene->brush().color();
this->scene = scene;
}
BrushPenSelection::~BrushPenSelection() { delete ui; }
BrushPenSelection::~BrushPenSelection() {
delete ui;
}
void BrushPenSelection::on_penColor_clicked(bool) {
pen = QColorDialog::getColor(pen, this, "Pen Color");
pen = QColorDialog::getColor(pen, this, "Pen Color");
}
void BrushPenSelection::on_brushColor_clicked(bool) {
brush = QColorDialog::getColor(brush, this, "Brush Color");
brush = QColorDialog::getColor(brush, this, "Brush Color");
}
void BrushPenSelection::on_buttonBox_accepted() {
scene->pen().setColor(pen);
scene->pen().setCosmetic(ui->cosmetic->isChecked());
scene->pen().setWidthF(ui->widthSpinner->value());
scene->brush().setColor(brush);
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());
close();
scene->pen().setColor(pen);
scene->pen().setCosmetic(ui->cosmetic->isChecked());
scene->pen().setWidthF(ui->widthSpinner->value());
scene->brush().setColor(brush);
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());
close();
}
void BrushPenSelection::on_buttonBox_rejected() { close(); }
void BrushPenSelection::on_buttonBox_rejected() {
close();
}
void BrushPenSelection::on_widthSlider_sliderMoved(int position) {
ui->widthSpinner->setValue(position / 100.);
ui->widthSpinner->setValue(position / 100.);
}
void BrushPenSelection::on_widthSpinner_valueChanged(double arg) {
ui->widthSlider->setValue(arg * 100);
ui->widthSlider->setValue(arg * 100);
}

@ -9,26 +9,26 @@ class BrushPenSelection;
}
class BrushPenSelection : public QDialog {
Q_OBJECT
Q_OBJECT
public:
explicit BrushPenSelection(CropScene *scene);
~BrushPenSelection();
public:
explicit BrushPenSelection(CropScene *scene);
~BrushPenSelection();
private slots:
void on_penColor_clicked(bool);
void on_brushColor_clicked(bool);
private slots:
void on_penColor_clicked(bool);
void on_brushColor_clicked(bool);
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_widthSlider_sliderMoved(int position);
void on_widthSpinner_valueChanged(double arg1);
void on_widthSlider_sliderMoved(int position);
void on_widthSpinner_valueChanged(double arg1);
private:
Ui::BrushPenSelection *ui;
CropScene *scene;
QColor brush, pen;
private:
Ui::BrushPenSelection *ui;
CropScene *scene;
QColor brush, pen;
};
#endif // BRUSHPENSELECTION_HPP

@ -4,14 +4,13 @@
#include <QStringList>
QString formatter::format(QString toFormat) {
QRegExp dateRegex("%\\((.+)\\)date");
dateRegex.indexIn(toFormat);
QStringList capturedTexts(dateRegex.capturedTexts());
QString formatted(toFormat);
QDateTime date = QDateTime::currentDateTime();
for (int i = 0; i < capturedTexts.length(); i += 2) {
formatted = formatted.replace(capturedTexts.at(i),
date.toString(capturedTexts.at(i + 1)));
}
return formatted;
QRegExp dateRegex("%\\((.+)\\)date");
dateRegex.indexIn(toFormat);
QStringList capturedTexts(dateRegex.capturedTexts());
QString formatted(toFormat);
QDateTime date = QDateTime::currentDateTime();
for (int i = 0; i < capturedTexts.length(); i += 2) {
formatted = formatted.replace(capturedTexts.at(i), date.toString(capturedTexts.at(i + 1)));
}
return formatted;
}

@ -8,38 +8,34 @@
QMap<QString, QHotkey *> hotkeys;
// func gets bound only on first set, or load
void hotkeying::hotkey(QString seqName, QKeySequence seq,
std::function<void()> func) {
if (hotkeys.contains(seqName))
hotkeys.value(seqName)->setShortcut(seq, true);
else {
QHotkey *hotkey = new QHotkey(seq, true);
QObject::connect(hotkey, &QHotkey::activated, func);
hotkeys.insert(seqName, hotkey);
}
settings::settings().setValue(seqName.prepend("hotkey_"), seq.toString());
void hotkeying::hotkey(QString seqName, QKeySequence seq, std::function<void()> func) {
if (hotkeys.contains(seqName))
hotkeys.value(seqName)->setShortcut(seq, true);
else {
QHotkey *hotkey = new QHotkey(seq, true);
QObject::connect(hotkey, &QHotkey::activated, func);
hotkeys.insert(seqName, hotkey);
}
settings::settings().setValue(seqName.prepend("hotkey_"), seq.toString());
}
// forces the hotkey from settings
void hotkeying::load(QString seqName, std::function<void()> func) {
QHotkey *h;
QString name = seqName;
name.prepend("hotkey_");
if (settings::settings().contains(name))
h = new QHotkey(QKeySequence(settings::settings().value(name).toString()),
true);
else
h = new QHotkey;
QObject::connect(h, &QHotkey::activated, func);
hotkeys.insert(seqName, h);
QHotkey *h;
QString name = seqName;
name.prepend("hotkey_");
if (settings::settings().contains(name))
h = new QHotkey(QKeySequence(settings::settings().value(name).toString()), true);
else
h = new QHotkey;
QObject::connect(h, &QHotkey::activated, func);
hotkeys.insert(seqName, h);
}
bool hotkeying::valid(QString seq) {
return seq.isEmpty() || !QKeySequence(seq).toString().isEmpty();
return seq.isEmpty() || !QKeySequence(seq).toString().isEmpty();
}
QString hotkeying::sequence(QString seqName) {
return hotkeys.contains(seqName)
? hotkeys.value(seqName)->shortcut().toString()
: "";
return hotkeys.contains(seqName) ? hotkeys.value(seqName)->shortcut().toString() : "";
}

@ -8,58 +8,56 @@ namespace ioutils {
QNetworkAccessManager networkManager;