Add clang-format; Make text and blur less annoying

I didn't read the clang-format documentation properly
This commit is contained in:
ArsenArsen 2017-05-09 17:26:00 +02:00
parent 7737b77671
commit 37ce6f1eda
43 changed files with 1079 additions and 1077 deletions

47
.clang-format Normal file
View File

@ -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

View File

@ -25,7 +25,9 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
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) { void CropEditor::crop(QRect rect) {
QPixmap map = view->grab(rect); QPixmap map = view->grab(rect);

View File

@ -10,13 +10,13 @@
class CropEditor : public QObject { class CropEditor : public QObject {
Q_OBJECT Q_OBJECT
public: public:
CropEditor(QPixmap *image, QObject *parent = 0); CropEditor(QPixmap *image, QObject *parent = 0);
~CropEditor(); ~CropEditor();
signals: signals:
QPixmap *cropped(QPixmap *pixmap); QPixmap *cropped(QPixmap *pixmap);
private: private:
void crop(QRect rect); void crop(QRect rect);
CropScene *scene = nullptr; CropScene *scene = nullptr;
CropView *view = nullptr; CropView *view = nullptr;

View File

@ -17,18 +17,12 @@
#include <settings.hpp> #include <settings.hpp>
CropScene::CropScene(QObject *parent, QPixmap *pixmap) CropScene::CropScene(QObject *parent, QPixmap *pixmap)
: QGraphicsScene(parent), prevButtons(Qt::NoButton), : QGraphicsScene(parent), drawingSelectionMaker([] { return nullptr; }), prevButtons(Qt::NoButton),
drawingSelectionMaker([] { return nullptr; }),
_font(settings::settings().value("font", QFont()).value<QFont>()) { _font(settings::settings().value("font", QFont()).value<QFont>()) {
pen().setColor( pen().setColor(settings::settings().value("penColor", pen().color()).value<QColor>());
settings::settings().value("penColor", pen().color()).value<QColor>()); pen().setCosmetic(settings::settings().value("penCosmetic", pen().isCosmetic()).toBool());
pen().setCosmetic( pen().setWidthF(settings::settings().value("penWidth", pen().widthF()).toFloat());
settings::settings().value("penCosmetic", pen().isCosmetic()).toBool()); brush().setColor(settings::settings().value("brushColor", brush().color()).value<QColor>());
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, "Dot", [] { return new DotItem; });
addDrawingAction(menu, "Path", [] { return new PathItem; }); addDrawingAction(menu, "Path", [] { return new PathItem; });
@ -37,8 +31,7 @@ CropScene::CropScene(QObject *parent, QPixmap *pixmap)
addDrawingAction(menu, "Text", [] { return new TextItem; }); addDrawingAction(menu, "Text", [] { return new TextItem; });
QAction *reset = menu.addAction("Reset"); QAction *reset = menu.addAction("Reset");
connect(reset, &QAction::triggered, connect(reset, &QAction::triggered, [&] { setDrawingSelection("None", [] { return nullptr; }); });
[&] { setDrawingSelection("None", [] { return nullptr; }); });
menu.addSeparator(); menu.addSeparator();
QAction *settings = new QAction; QAction *settings = new QAction;
@ -46,12 +39,10 @@ CropScene::CropScene(QObject *parent, QPixmap *pixmap)
menu.addSeparator(); menu.addSeparator();
display = menu.addAction(drawingName); display = menu.addAction(drawingName);
display->setDisabled(true); display->setDisabled(true);
connect(settings, &QAction::triggered, connect(settings, &QAction::triggered, [&] { BrushPenSelection(this).exec(); });
[&] { BrushPenSelection(this).exec(); });
menu.addAction(settings); menu.addAction(settings);
connect(menu.addAction("Set Font"), &QAction::triggered, this, connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk);
&CropScene::fontAsk);
_pixmap = pixmap; _pixmap = pixmap;
QTimer::singleShot(0, [&] { QTimer::singleShot(0, [&] {
@ -67,28 +58,34 @@ CropScene::CropScene(QObject *parent, QPixmap *pixmap)
}); });
} }
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, void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> drawAction) {
std::function<DrawItem *()> drawAction) {
drawingSelectionMaker = drawAction; drawingSelectionMaker = drawAction;
drawingSelection = drawAction(); drawingSelection = drawAction();
drawingName = name; drawingName = name;
if (drawingSelection) if (drawingSelection)
drawingSelection->init(this); if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
} }
void CropScene::fontAsk() { void CropScene::fontAsk() {
bool ok = false; bool ok = false;
QFont font = QFontDialog::getFont(&ok, this->font(), nullptr, "Font to use"); QFont font = QFontDialog::getFont(&ok, this->font(), nullptr, "Font to use");
if (ok) if (ok) _font = font;
_font = font;
} }
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
@ -110,14 +107,12 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
initPos = p; initPos = p;
rect->setRect(p.x(), p.y(), 1, 1); rect->setRect(p.x(), p.y(), 1, 1);
} else { } else {
rect->setRect( rect->setRect(QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()),
QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.y() - p.y())));
qAbs(initPos.x() - p.x()), qAbs(initPos.y() - p.y())));
} }
} }
QPolygonF poly; QPolygonF poly;
QPointF theMagicWikipediaPoint(rect->rect().right(), QPointF theMagicWikipediaPoint(rect->rect().right(), sceneRect().bottom());
sceneRect().bottom());
poly << sceneRect().topLeft(); poly << sceneRect().topLeft();
poly << sceneRect().topRight(); poly << sceneRect().topRight();
poly << sceneRect().bottomRight(); poly << sceneRect().bottomRight();
@ -145,17 +140,15 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
delete drawingSelection; delete drawingSelection;
drawingSelection = drawingSelectionMaker(); drawingSelection = drawingSelectionMaker();
if (drawingSelection) if (drawingSelection)
drawingSelection->init(this); if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
} }
prevButtons = Qt::NoButton; prevButtons = Qt::NoButton;
} }
void CropScene::addDrawingAction(QMenu &menu, QString name, void CropScene::addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item) {
std::function<DrawItem *()> item) {
QAction *action = new QAction; QAction *action = new QAction;
action->setText(name); action->setText(name);
connect(action, &QAction::triggered, connect(action, &QAction::triggered, [this, item, name](bool) { setDrawingSelection(name, item); });
[this, item, name](bool) { setDrawingSelection(name, item); });
menu.addAction(action); menu.addAction(action);
} }
@ -166,8 +159,7 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
} }
void CropScene::keyReleaseEvent(QKeyEvent *event) { void CropScene::keyReleaseEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) done(); // Segfault
done(); // Segfault
} }
void CropScene::done() { void CropScene::done() {

View File

@ -15,32 +15,32 @@ class CropScene;
class CropScene : public QGraphicsScene { class CropScene : public QGraphicsScene {
Q_OBJECT Q_OBJECT
public: public:
CropScene(QObject *parent, QPixmap *pixmap); CropScene(QObject *parent, QPixmap *pixmap);
~CropScene(); ~CropScene();
QPen &pen(); QPen &pen();
QBrush &brush(); QBrush &brush();
QFont &font(); QFont &font();
void setDrawingSelection(QString name, void setDrawingSelection(QString name, std::function<DrawItem *()> drawAction);
std::function<DrawItem *()> drawAction); QPixmap *pixmap() {
QPixmap *pixmap() { return _pixmap; } return _pixmap;
}
public slots: public slots:
void fontAsk(); void fontAsk();
signals: signals:
void closedWithRect(QRect rect); void closedWithRect(QRect rect);
protected: protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override;
void keyReleaseEvent(QKeyEvent *e) override; void keyReleaseEvent(QKeyEvent *e) override;
private: private:
void addDrawingAction(QMenu &menu, QString name, void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item);
std::function<DrawItem *()> item);
void done(); void done();
std::function<DrawItem *()> drawingSelectionMaker; std::function<DrawItem *()> drawingSelectionMaker;
QFlags<Qt::MouseButton> prevButtons; QFlags<Qt::MouseButton> prevButtons;

View File

@ -1,13 +1,11 @@
#include "cropview.hpp" #include "cropview.hpp"
CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene) { CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene) {
setFrameShape( setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
QPainter::HighQualityAntialiasing);
setCursor(QCursor(Qt::CrossCursor)); setCursor(QCursor(Qt::CrossCursor));
} }

View File

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

View File

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

View File

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

View File

@ -1,14 +1,14 @@
#include "dotitem.hpp" #include "dotitem.hpp"
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());
} }
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {} 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());
}
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}

View File

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

View File

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

View File

@ -1,6 +1,7 @@
#include "lineitem.hpp" #include "lineitem.hpp"
LineItem::LineItem() {} LineItem::LineItem() {
}
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) { void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (init.isNull()) { if (init.isNull()) {
@ -11,4 +12,5 @@ void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
} }
} }
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {} void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}

View File

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

View File

@ -1,8 +1,11 @@
#include "pathitem.hpp" #include "pathitem.hpp"
PathItem::PathItem() {} PathItem::PathItem() {
}
PathItem::~PathItem() { delete path; } PathItem::~PathItem() {
delete path;
}
void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) { void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (path == nullptr) { if (path == nullptr) {
@ -14,4 +17,5 @@ void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
} }
} }
void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {} void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,7 @@
#include <cropeditor/cropview.hpp> #include <cropeditor/cropview.hpp>
#include <settings.hpp> #include <settings.hpp>
BrushPenSelection::BrushPenSelection(CropScene *scene) BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::BrushPenSelection) {
: QDialog(), ui(new Ui::BrushPenSelection) {
ui->setupUi(this); ui->setupUi(this);
ui->cosmetic->setChecked(scene->pen().isCosmetic()); ui->cosmetic->setChecked(scene->pen().isCosmetic());
ui->widthSlider->setValue(scene->pen().width()); ui->widthSlider->setValue(scene->pen().width());
@ -20,7 +19,9 @@ BrushPenSelection::BrushPenSelection(CropScene *scene)
this->scene = scene; this->scene = scene;
} }
BrushPenSelection::~BrushPenSelection() { delete ui; } BrushPenSelection::~BrushPenSelection() {
delete ui;
}
void BrushPenSelection::on_penColor_clicked(bool) { void BrushPenSelection::on_penColor_clicked(bool) {
pen = QColorDialog::getColor(pen, this, "Pen Color"); pen = QColorDialog::getColor(pen, this, "Pen Color");
@ -42,7 +43,9 @@ void BrushPenSelection::on_buttonBox_accepted() {
close(); close();
} }
void BrushPenSelection::on_buttonBox_rejected() { close(); } void BrushPenSelection::on_buttonBox_rejected() {
close();
}
void BrushPenSelection::on_widthSlider_sliderMoved(int position) { void BrushPenSelection::on_widthSlider_sliderMoved(int position) {
ui->widthSpinner->setValue(position / 100.); ui->widthSpinner->setValue(position / 100.);

View File

@ -11,11 +11,11 @@ class BrushPenSelection;
class BrushPenSelection : public QDialog { class BrushPenSelection : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit BrushPenSelection(CropScene *scene); explicit BrushPenSelection(CropScene *scene);
~BrushPenSelection(); ~BrushPenSelection();
private slots: private slots:
void on_penColor_clicked(bool); void on_penColor_clicked(bool);
void on_brushColor_clicked(bool); void on_brushColor_clicked(bool);
@ -25,7 +25,7 @@ private slots:
void on_widthSlider_sliderMoved(int position); void on_widthSlider_sliderMoved(int position);
void on_widthSpinner_valueChanged(double arg1); void on_widthSpinner_valueChanged(double arg1);
private: private:
Ui::BrushPenSelection *ui; Ui::BrushPenSelection *ui;
CropScene *scene; CropScene *scene;
QColor brush, pen; QColor brush, pen;

View File

@ -10,8 +10,7 @@ QString formatter::format(QString toFormat) {
QString formatted(toFormat); QString formatted(toFormat);
QDateTime date = QDateTime::currentDateTime(); QDateTime date = QDateTime::currentDateTime();
for (int i = 0; i < capturedTexts.length(); i += 2) { for (int i = 0; i < capturedTexts.length(); i += 2) {
formatted = formatted.replace(capturedTexts.at(i), formatted = formatted.replace(capturedTexts.at(i), date.toString(capturedTexts.at(i + 1)));
date.toString(capturedTexts.at(i + 1)));
} }
return formatted; return formatted;
} }

View File

@ -8,8 +8,7 @@
QMap<QString, QHotkey *> hotkeys; QMap<QString, QHotkey *> hotkeys;
// func gets bound only on first set, or load // func gets bound only on first set, or load
void hotkeying::hotkey(QString seqName, QKeySequence seq, void hotkeying::hotkey(QString seqName, QKeySequence seq, std::function<void()> func) {
std::function<void()> func) {
if (hotkeys.contains(seqName)) if (hotkeys.contains(seqName))
hotkeys.value(seqName)->setShortcut(seq, true); hotkeys.value(seqName)->setShortcut(seq, true);
else { else {
@ -26,8 +25,7 @@ void hotkeying::load(QString seqName, std::function<void()> func) {
QString name = seqName; QString name = seqName;
name.prepend("hotkey_"); name.prepend("hotkey_");
if (settings::settings().contains(name)) if (settings::settings().contains(name))
h = new QHotkey(QKeySequence(settings::settings().value(name).toString()), h = new QHotkey(QKeySequence(settings::settings().value(name).toString()), true);
true);
else else
h = new QHotkey; h = new QHotkey;
QObject::connect(h, &QHotkey::activated, func); QObject::connect(h, &QHotkey::activated, func);
@ -39,7 +37,5 @@ bool hotkeying::valid(QString seq) {
} }
QString hotkeying::sequence(QString seqName) { QString hotkeying::sequence(QString seqName) {
return hotkeys.contains(seqName) return hotkeys.contains(seqName) ? hotkeys.value(seqName)->shortcut().toString() : "";
? hotkeys.value(seqName)->shortcut().toString()
: "";
} }

View File

@ -8,9 +8,7 @@ namespace ioutils {
QNetworkAccessManager networkManager; QNetworkAccessManager networkManager;
} }
void ioutils::getJson( void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback) {
QUrl target, QList<QPair<QString, QString>> headers,
std::function<void(QJsonDocument, QNetworkReply *)> callback) {
QNetworkRequest req(target); QNetworkRequest req(target);
for (auto header : headers) { for (auto header : headers) {
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8()); req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
@ -22,8 +20,9 @@ void ioutils::getJson(
}); });
} }
void ioutils::postJson( void ioutils::postJson(QUrl target,
QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, QList<QPair<QString, QString>> headers,
QByteArray body,
std::function<void(QJsonDocument, QNetworkReply *)> callback) { std::function<void(QJsonDocument, QNetworkReply *)> callback) {
QNetworkRequest req(target); QNetworkRequest req(target);
for (auto header : headers) { for (auto header : headers) {
@ -36,9 +35,7 @@ void ioutils::postJson(
}); });
} }
void ioutils::getData( void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback) {
QUrl target, QList<QPair<QString, QString>> headers,
std::function<void(QByteArray, QNetworkReply *)> callback) {
QNetworkRequest req(target); QNetworkRequest req(target);
for (auto header : headers) { for (auto header : headers) {
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8()); req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
@ -50,8 +47,9 @@ void ioutils::getData(
}); });
} }
void ioutils::postData( void ioutils::postData(QUrl target,
QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, QList<QPair<QString, QString>> headers,
QByteArray body,
std::function<void(QByteArray, QNetworkReply *)> callback) { std::function<void(QByteArray, QNetworkReply *)> callback) {
QNetworkRequest req(target); QNetworkRequest req(target);
for (auto header : headers) { for (auto header : headers) {

View File

@ -9,16 +9,10 @@
namespace ioutils { namespace ioutils {
extern QNetworkAccessManager networkManager; extern QNetworkAccessManager networkManager;
void getJson(QUrl target, QList<QPair<QString, QString>> headers, void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback);
std::function<void(QJsonDocument, QNetworkReply *)> callback); void postJson(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QJsonDocument, QNetworkReply *)> callback);
void postJson(QUrl target, QList<QPair<QString, QString>> headers, void getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback);
QByteArray body, void postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QByteArray, QNetworkReply *)> callback);
std::function<void(QJsonDocument, QNetworkReply *)> callback);
void getData(QUrl target, QList<QPair<QString, QString>> headers,
std::function<void(QByteArray, QNetworkReply *)> callback);
void postData(QUrl target, QList<QPair<QString, QString>> headers,
QByteArray body,
std::function<void(QByteArray, QNetworkReply *)> callback);
} }
#endif // IOUTILS_HPP #endif // IOUTILS_HPP

View File

@ -11,8 +11,7 @@ void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
QByteArray localMsg = msg.toLocal8Bit(); QByteArray localMsg = msg.toLocal8Bit();
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
if (verbose) if (verbose) fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
break; break;
case QtInfoMsg: case QtInfoMsg:
fprintf(stderr, "INFO: %s\n", localMsg.constData()); fprintf(stderr, "INFO: %s\n", localMsg.constData());
@ -39,9 +38,8 @@ int main(int argc, char *argv[]) {
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();
QCommandLineOption h({"b", "background"}, QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray.");
"Does not show the main window, starts in tray."); QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs");
QCommandLineOption v({"v", "verbose"}, "Enables QtDebugMsg outputs");
parser.addOption(h); parser.addOption(h);
parser.addOption(v); parser.addOption(v);
parser.process(a); parser.process(a);
@ -50,8 +48,7 @@ int main(int argc, char *argv[]) {
MainWindow w; MainWindow w;
w.show(); w.show();
QTimer::singleShot(0, [&] { QTimer::singleShot(0, [&] {
if (parser.isSet(h)) if (parser.isSet(h)) w.hide();
w.hide();
}); });
return a.exec(); return a.exec();
} }

View File

@ -20,15 +20,13 @@
MainWindow *MainWindow::instance; MainWindow *MainWindow::instance;
void addHotkeyItem(QString text, QString name, std::function<void()> *func) { void addHotkeyItem(QString text, QString name, std::function<void()> *func) {
QListWidgetItem *item = QListWidgetItem *item = new QListWidgetItem(text, MainWindow::inst()->ui->hotkeys);
new QListWidgetItem(text, MainWindow::inst()->ui->hotkeys);
item->setData(Qt::UserRole + 1, name); item->setData(Qt::UserRole + 1, name);
MainWindow::inst()->fncs.insert(name, func); MainWindow::inst()->fncs.insert(name, func);
hotkeying::load(name, *func); hotkeying::load(name, *func);
} }
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
: QMainWindow(parent), ui(new Ui::MainWindow) {
instance = this; instance = this;
ui->setupUi(this); ui->setupUi(this);
setWindowIcon(QIcon(":/icons/icon.png")); setWindowIcon(QIcon(":/icons/icon.png"));
@ -40,32 +38,25 @@ MainWindow::MainWindow(QWidget *parent)
QAction *shtoggle = new QAction("Show/Hide", this); QAction *shtoggle = new QAction("Show/Hide", this);
QAction *fullscreen = new QAction("Take fullscreen shot", this); QAction *fullscreen = new QAction("Take fullscreen shot", this);
QAction *area = new QAction("Take area shot", this); QAction *area = new QAction("Take area shot", this);
menu->addActions({quit, shtoggle}); menu->addActions({ quit, shtoggle });
menu->addSeparator(); menu->addSeparator();
menu->addActions({fullscreen, area}); menu->addActions({ fullscreen, area });
connect(quit, &QAction::triggered, this, &MainWindow::quit); connect(quit, &QAction::triggered, this, &MainWindow::quit);
connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible); connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible);
connect(tray, &QSystemTrayIcon::messageClicked, this, connect(tray, &QSystemTrayIcon::messageClicked, this, &MainWindow::toggleVisible);
&MainWindow::toggleVisible); connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
connect(tray, &QSystemTrayIcon::activated, this, if (reason == QSystemTrayIcon::DoubleClick) toggleVisible();
[this](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::DoubleClick)
toggleVisible();
}); });
connect(fullscreen, &QAction::triggered, this, connect(fullscreen, &QAction::triggered, this, [] { screenshotter::fullscreenDelayed(); });
[] { screenshotter::fullscreenDelayed(); }); connect(area, &QAction::triggered, this, [] { screenshotter::areaDelayed(); });
connect(area, &QAction::triggered, this,
[] { screenshotter::areaDelayed(); });
tray->setContextMenu(menu); tray->setContextMenu(menu);
ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows); ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection); ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection);
// Add items to uploader selection // Add items to uploader selection
for (Uploader *u : UploaderSingleton::inst().uploaderList()) for (Uploader *u : UploaderSingleton::inst().uploaderList()) newUploader(u);
newUploader(u); connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this, &MainWindow::newUploader);
connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this,
&MainWindow::newUploader);
// Set filename scheme // Set filename scheme
if ((settings::settings().contains("fileFormat"))) if ((settings::settings().contains("fileFormat")))
@ -77,9 +68,7 @@ MainWindow::MainWindow(QWidget *parent)
if (errors.length() == 1) if (errors.length() == 1)
statusBar()->showMessage(errors.at(0).what()); statusBar()->showMessage(errors.at(0).what());
else else
statusBar()->showMessage( statusBar()->showMessage(QString("Errors visible in console (if present). Count: " + QString::number(errors.size())));
QString("Errors visible in console (if present). Count: " +
QString::number(errors.size())));
// Set delay // Set delay
if ((settings::settings().contains("delay"))) if ((settings::settings().contains("delay")))
@ -89,26 +78,34 @@ MainWindow::MainWindow(QWidget *parent)
ui->hotkeys->setSelectionMode(QListWidget::SingleSelection); ui->hotkeys->setSelectionMode(QListWidget::SingleSelection);
addHotkeyItem("Fullscreen image", "fullscreen", addHotkeyItem("Fullscreen image", "fullscreen", new std::function<void()>([] { screenshotter::fullscreen(); }));
new std::function<void()>([] { screenshotter::fullscreen(); })); addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); }));
addHotkeyItem("Area image", "area",
new std::function<void()>([] { screenshotter::area(); }));
} }
MainWindow::~MainWindow() { delete ui; } MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::setScheme(QString scheme) { ui->nameScheme->setText(scheme); } void MainWindow::setScheme(QString scheme) {
ui->nameScheme->setText(scheme);
}
QDoubleSpinBox *MainWindow::delay() { return ui->delay; } QDoubleSpinBox *MainWindow::delay() {
return ui->delay;
}
MainWindow *MainWindow::inst() { return instance; } MainWindow *MainWindow::inst() {
return instance;
}
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
event->ignore(); event->ignore();
QTimer::singleShot(0, this, &MainWindow::hide); QTimer::singleShot(0, this, &MainWindow::hide);
} }
void MainWindow::quit() { QCoreApplication::quit(); } void MainWindow::quit() {
QCoreApplication::quit();
}
void MainWindow::toggleVisible() { void MainWindow::toggleVisible() {
this->setVisible(!this->isVisible()); this->setVisible(!this->isVisible());
@ -121,17 +118,20 @@ void MainWindow::newUploader(Uploader *u) {
QListWidgetItem *item = new QListWidgetItem(u->name()); QListWidgetItem *item = new QListWidgetItem(u->name());
item->setToolTip(u->description()); item->setToolTip(u->description());
ui->uploaderList->addItem(item); ui->uploaderList->addItem(item);
if (u->name() == UploaderSingleton::inst().selectedUploader()) if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
item->setSelected(true);
} }
void MainWindow::on_actionQuit_triggered() { quit(); } void MainWindow::on_actionQuit_triggered() {
quit();
}
void MainWindow::on_actionFullscreen_triggered() { void MainWindow::on_actionFullscreen_triggered() {
screenshotter::fullscreenDelayed(); screenshotter::fullscreenDelayed();
} }
void MainWindow::on_actionArea_triggered() { screenshotter::areaDelayed(); } void MainWindow::on_actionArea_triggered() {
screenshotter::areaDelayed();
}
void MainWindow::on_uploaderList_clicked(const QModelIndex &) { void MainWindow::on_uploaderList_clicked(const QModelIndex &) {
QList<QListWidgetItem *> index = ui->uploaderList->selectedItems(); QList<QListWidgetItem *> index = ui->uploaderList->selectedItems();
@ -152,10 +152,8 @@ void MainWindow::on_hotkeys_doubleClicked(const QModelIndex &) {
if (ui->hotkeys->selectedItems().length() == 1) { if (ui->hotkeys->selectedItems().length() == 1) {
QListWidgetItem *i = ui->hotkeys->selectedItems().at(0); QListWidgetItem *i = ui->hotkeys->selectedItems().at(0);
QString str = i->data(Qt::UserRole + 1).toString(); QString str = i->data(Qt::UserRole + 1).toString();
QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", "Insert hotkey:", QLineEdit::Normal,
"Insert hotkey:", QLineEdit::Normal,
hotkeying::sequence(str)); hotkeying::sequence(str));
if (hotkeying::valid(seq)) if (hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str));
hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str));
} }
} }

View File

@ -15,7 +15,7 @@ class MainWindow;
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
private slots: private slots:
void quit(); void quit();
void toggleVisible(); void toggleVisible();
void newUploader(Uploader *u); void newUploader(Uploader *u);
@ -30,7 +30,7 @@ private slots:
void on_hotkeys_doubleClicked(const QModelIndex &index); void on_hotkeys_doubleClicked(const QModelIndex &index);
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
Ui::MainWindow *ui; Ui::MainWindow *ui;
@ -42,10 +42,10 @@ public:
static MainWindow *inst(); static MainWindow *inst();
QMap<QString, std::function<void()> *> fncs; QMap<QString, std::function<void()> *> fncs;
private: private:
static MainWindow *instance; static MainWindow *instance;
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
}; };

View File

@ -3,8 +3,7 @@
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include <QStatusBar> #include <QStatusBar>
void notifications::notify(QString title, QString body, void notifications::notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon) {
QSystemTrayIcon::MessageIcon icon) {
MainWindow::inst()->tray->showMessage(title, body, icon, 5000); MainWindow::inst()->tray->showMessage(title, body, icon, 5000);
MainWindow::inst()->statusBar()->showMessage(title + ": " + body); MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
} }

View File

@ -5,8 +5,7 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
namespace notifications { namespace notifications {
void notify(QString title, QString body, void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
} }
#endif // NOTIFICATIONS_HPP #endif // NOTIFICATIONS_HPP

View File

@ -8,9 +8,7 @@
void screenshotter::area() { void screenshotter::area() {
CropEditor *editor = new CropEditor(screenshotutil::fullscreen()); CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap *pixmap) { QObject::connect(editor, &CropEditor::cropped, [&](QPixmap *pixmap) { UploaderSingleton::inst().upload(pixmap); });
UploaderSingleton::inst().upload(pixmap);
});
} }
void screenshotter::fullscreen() { void screenshotter::fullscreen() {
@ -18,11 +16,9 @@ void screenshotter::fullscreen() {
} }
void screenshotter::areaDelayed() { void screenshotter::areaDelayed() {
QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, &screenshotter::area);
&screenshotter::area);
} }
void screenshotter::fullscreenDelayed() { void screenshotter::fullscreenDelayed() {
QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, &screenshotter::fullscreen);
&screenshotter::fullscreen);
} }

View File

@ -5,7 +5,9 @@
#include <QPixmap> #include <QPixmap>
#include <QScreen> #include <QScreen>
QPixmap *screenshotutil::fullscreen() { return window(0); } QPixmap *screenshotutil::fullscreen() {
return window(0);
}
QPixmap *screenshotutil::window(long wid) { QPixmap *screenshotutil::window(long wid) {
QScreen *w = QApplication::primaryScreen(); QScreen *w = QApplication::primaryScreen();

View File

@ -3,14 +3,11 @@
#include <QStandardPaths> #include <QStandardPaths>
QSettings &settings::settings() { QSettings &settings::settings() {
static QDir configDir( static QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)); if (configDir.path() == QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) {
if (configDir.path() ==
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) {
configDir.mkdir("KShare"); configDir.mkdir("KShare");
configDir.cd("KShare"); configDir.cd("KShare");
} }
static QSettings settings(configDir.absoluteFilePath("settings.ini"), static QSettings settings(configDir.absoluteFilePath("settings.ini"), QSettings::IniFormat);
QSettings::IniFormat);
return settings; return settings;
} }

View File

@ -13,9 +13,7 @@
using std::runtime_error; using std::runtime_error;
void error(QString absFilePath, QString err) { void error(QString absFilePath, QString err) {
throw runtime_error( throw runtime_error((QString("Invalid file: ").append(absFilePath) + ": " + err).toStdString());
(QString("Invalid file: ").append(absFilePath) + ": " + err)
.toStdString());
} }
CustomUploader::CustomUploader(QString absFilePath) { CustomUploader::CustomUploader(QString absFilePath) {
@ -27,8 +25,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
types.insert("MP4", "video/mp4"); types.insert("MP4", "video/mp4");
// Let's go // Let's go
QFile file(absFilePath); QFile file(absFilePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) error(absFilePath, file.errorString());
error(absFilePath, file.errorString());
QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
if (!doc.isObject()) { if (!doc.isObject()) {
error(absFilePath, "Root not an object"); error(absFilePath, "Root not an object");
@ -47,8 +44,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
desc = absFilePath; desc = absFilePath;
QJsonValue m = obj["method"]; QJsonValue m = obj["method"];
if (!m.isUndefined() && !m.isNull()) { if (!m.isUndefined() && !m.isNull()) {
if (!m.isString()) if (!m.isString()) error(absFilePath, "method not a string");
error(absFilePath, "method not a string");
QString toCheck = m.toString().toLower(); QString toCheck = m.toString().toLower();
if (toCheck == "post") if (toCheck == "post")
method = HttpMethod::POST; method = HttpMethod::POST;
@ -60,8 +56,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
error(absFilePath, "target missing"); error(absFilePath, "target missing");
} }
QUrl target(url.toString()); QUrl target(url.toString());
if (!target.isValid()) if (!target.isValid()) error(absFilePath, "target not URL");
error(absFilePath, "target not URL");
this->target = target; this->target = target;
QJsonValue formatValue = obj["format"]; QJsonValue formatValue = obj["format"];
if (!formatValue.isUndefined() && !formatValue.isNull()) { if (!formatValue.isUndefined() && !formatValue.isNull()) {
@ -83,16 +78,14 @@ CustomUploader::CustomUploader(QString absFilePath) {
error(absFilePath, "imageformat not string"); error(absFilePath, "imageformat not string");
} }
QString imageFormat = imageValue.toString(); QString imageFormat = imageValue.toString();
if (imageFormat == "base64" || if (imageFormat == "base64" || QRegExp("base64\\([^+]+\\+[^+]+)").exactMatch(imageFormat)
QRegExp("base64\\([^+]+\\+[^+]+)").exactMatch(imageFormat) || || QRegExp("[^+]+\\+[^+]+").exactMatch(imageFormat)) {
QRegExp("[^+]+\\+[^+]+").exactMatch(imageFormat)) {
this->iFormat = imageFormat; this->iFormat = imageFormat;
} else } else
error(absFilePath, "imageformat invalid"); error(absFilePath, "imageformat invalid");
QJsonValue bodyValue = obj["body"]; QJsonValue bodyValue = obj["body"];
if (format != RequestFormat::PLAIN) { if (format != RequestFormat::PLAIN) {
if (bodyValue.isUndefined()) if (bodyValue.isUndefined()) error(absFilePath, "body not set");
error(absFilePath, "body not set");
if (bodyValue.isObject()) if (bodyValue.isObject())
body = bodyValue; body = bodyValue;
else else
@ -105,8 +98,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
} }
QJsonValue headerVal = obj["headers"]; QJsonValue headerVal = obj["headers"];
if (!(headerVal.isUndefined() || headerVal.isNull())) { if (!(headerVal.isUndefined() || headerVal.isNull())) {
if (!headerVal.isObject()) if (!headerVal.isObject()) error(absFilePath, "headers must be object");
error(absFilePath, "headers must be object");
headers = headerVal.toObject(); headers = headerVal.toObject();
} else } else
headers = QJsonObject(); headers = QJsonObject();
@ -117,9 +109,13 @@ CustomUploader::CustomUploader(QString absFilePath) {
error(absFilePath, "return invalid"); error(absFilePath, "return invalid");
} }
QString CustomUploader::name() { return uName; } QString CustomUploader::name() {
return uName;
}
QString CustomUploader::description() { return desc; } QString CustomUploader::description() {
return desc;
}
QString getCType(RequestFormat format, QString plainType) { QString getCType(RequestFormat format, QString plainType) {
switch (format) { switch (format) {
@ -133,22 +129,17 @@ QString getCType(RequestFormat format, QString plainType) {
return plainType; return plainType;
} }
QList<QPair<QString, QString>> getHeaders(QJsonObject h, QString imageFormat, QList<QPair<QString, QString>> getHeaders(QJsonObject h, QString imageFormat, QMap<QString, QString> types, RequestFormat format) {
QMap<QString, QString> types,
RequestFormat format) {
QList<QPair<QString, QString>> headers; QList<QPair<QString, QString>> headers;
for (QString s : h.keys()) { for (QString s : h.keys()) {
if (s.toLower() == "content-type") if (s.toLower() == "content-type") continue;
continue;
QJsonValue v = h[s]; QJsonValue v = h[s];
if (!v.isString()) if (!v.isString())
headers << QPair<QString, QString>( headers << QPair<QString, QString>(s, QJsonDocument::fromVariant(v.toVariant()).toJson());
s, QJsonDocument::fromVariant(v.toVariant()).toJson());
else else
headers << QPair<QString, QString>(s, v.toString()); headers << QPair<QString, QString>(s, v.toString());
} }
headers << QPair<QString, QString>( headers << QPair<QString, QString>("Content-Type", getCType(format, types.value(imageFormat)));
"Content-Type", getCType(format, types.value(imageFormat)));
return headers; return headers;
} }
@ -170,8 +161,7 @@ QString CustomUploader::getFormatString(bool animated) {
return ""; return "";
} }
QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data, QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data, QString contentType) {
QString contentType) {
QJsonObject o; QJsonObject o;
for (QString s : body.keys()) { for (QString s : body.keys()) {
QJsonValue v = body[s]; QJsonValue v = body[s];
@ -181,9 +171,7 @@ QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data,
} else if (v.isString()) { } else if (v.isString()) {
QString str = v.toString(); QString str = v.toString();
if (str.startsWith("/") && str.endsWith("/")) { if (str.startsWith("/") && str.endsWith("/")) {
o.insert( o.insert(s, str.replace("%image", data).replace("%contenttype", contentType));
s,
str.replace("%image", data).replace("%contenttype", contentType));
} }
} }
} }
@ -195,10 +183,8 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
// Does not point to anything // Does not point to anything
return ""; return "";
} else { } else {
if (!response.isObject()) if (!response.isObject()) return "";
return ""; QStringList fields = pathspec.right(pathspec.length() - 1).split('.', QString::SkipEmptyParts);
QStringList fields = pathspec.right(pathspec.length() - 1)
.split('.', QString::SkipEmptyParts);
QJsonObject o = response.object(); QJsonObject o = response.object();
if (pathspec == ".") { if (pathspec == ".") {
return QString::fromUtf8(response.toJson()); return QString::fromUtf8(response.toJson());
@ -209,16 +195,14 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
else if (val.isString()) else if (val.isString())
return val.toString(); return val.toString();
else if (!val.isObject()) else if (!val.isObject())
return QString::fromUtf8( return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
QJsonDocument::fromVariant(val.toVariant()).toJson());
for (int i = 1; i < fields.size(); i++) { for (int i = 1; i < fields.size(); i++) {
if (val.isUndefined() || val.isNull()) if (val.isUndefined() || val.isNull())
return ""; return "";
else if (val.isString()) else if (val.isString())
return val.toString(); return val.toString();
else if (!val.isObject()) else if (!val.isObject())
return QString::fromUtf8( return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
QJsonDocument::fromVariant(val.toVariant()).toJson());
else else
val = val.toObject()[fields.at(i)]; val = val.toObject()[fields.at(i)];
} }
@ -227,8 +211,7 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
else if (val.isString()) else if (val.isString())
return val.toString(); return val.toString();
else if (!val.isObject()) else if (!val.isObject())
return QString::fromUtf8( return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
QJsonDocument::fromVariant(val.toVariant()).toJson());
} }
return ""; return "";
} }
@ -239,14 +222,11 @@ void parseResult(QJsonDocument result, QString returnPathspec, QString name) {
QString url = parsePathspec(result, returnPathspec); QString url = parsePathspec(result, returnPathspec);
if (!url.isEmpty()) { if (!url.isEmpty()) {
QApplication::clipboard()->setText(url); QApplication::clipboard()->setText(url);
notifications::notify("KShare Custom Uploader " + name, notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!");
"Copied upload link to clipboard!");
} else } else
notifications::notify("KShare Custom Uploader " + name, notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!");
"Upload done, but result empty!");
} else } else
notifications::notify("KShare Custom Uploader " + name, notifications::notify("KShare Custom Uploader " + name, "Upload done, but result is not JSON Object!");
"Upload done, but result is not JSON Object!");
} }
void CustomUploader::doUpload(QPixmap *pixmap) { void CustomUploader::doUpload(QPixmap *pixmap) {
@ -254,29 +234,21 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
QString format = getFormatString(false); // Soon:tm: QString format = getFormatString(false); // Soon:tm:
QByteArray data; QByteArray data;
QByteArray imgData = imageBytes(pixmap, format); QByteArray imgData = imageBytes(pixmap, format);
if (iFormat == "base64" || if (iFormat == "base64" || QRegExp("base64\\([^+]\\+[^+]\\)").exactMatch(iFormat)) imgData = imgData.toBase64();
QRegExp("base64\\([^+]\\+[^+]\\)").exactMatch(iFormat))
imgData = imgData.toBase64();
switch (this->format) { switch (this->format) {
case RequestFormat::PLAIN: { case RequestFormat::PLAIN: {
data = imgData; data = imgData;
} break; } break;
case RequestFormat::JSON: { case RequestFormat::JSON: {
if (body.isString()) { if (body.isString()) {
QStringList split = body.toString() QStringList split = body.toString().replace("%contenttype", types.value(format)).split("%imagedata");
.replace("%contenttype", types.value(format))
.split("%imagedata");
for (int i = 0; i < split.size(); i++) { for (int i = 0; i < split.size(); i++) {
data.append(split[i]); data.append(split[i]);
if (i < split.size() - 1) if (i < split.size() - 1) data.append(imgData);
data.append(imgData);
} }
} else { } else {
QJsonObject vo = body.toObject(); QJsonObject vo = body.toObject();
data = QJsonDocument::fromVariant( data = QJsonDocument::fromVariant(recurseAndReplace(vo, imgData, types.value(format)).toVariantMap()).toJson();
recurseAndReplace(vo, imgData, types.value(format))
.toVariantMap())
.toJson();
} }
} break; } break;
case RequestFormat::X_WWW_FORM_URLENCODED: { case RequestFormat::X_WWW_FORM_URLENCODED: {
@ -288,22 +260,18 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
QByteArray strB; QByteArray strB;
if (str.startsWith("/") && str.endsWith("/")) { if (str.startsWith("/") && str.endsWith("/")) {
str = str.mid(1, str.length() - 2); str = str.mid(1, str.length() - 2);
QStringList split = str.replace("%contenttype", types.value(format)) QStringList split = str.replace("%contenttype", types.value(format)).split("%imagedata");
.split("%imagedata");
for (int i = 0; i < split.size(); i++) { for (int i = 0; i < split.size(); i++) {
strB.append(split[i]); strB.append(split[i]);
if (i < split.size() - 1) if (i < split.size() - 1) strB.append(imgData);
strB.append(imgData);
} }
} }
data.append(QUrl::toPercentEncoding(key)).append('=').append(strB); data.append(QUrl::toPercentEncoding(key)).append('=').append(strB);
} else { } else {
if (!data.isEmpty()) if (!data.isEmpty()) data.append('&');
data.append('&');
data.append(QUrl::toPercentEncoding(key)) data.append(QUrl::toPercentEncoding(key))
.append('=') .append('=')
.append(QUrl::toPercentEncoding( .append(QUrl::toPercentEncoding(QJsonDocument::fromVariant(body[key].toVariant()).toJson()));
QJsonDocument::fromVariant(body[key].toVariant()).toJson()));
} }
} }
} break; } break;
@ -311,17 +279,13 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
switch (method) { switch (method) {
case HttpMethod::POST: case HttpMethod::POST:
if (returnPathspec == "|") { if (returnPathspec == "|") {
ioutils::postData( ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
target, h, data, [&](QByteArray result, QNetworkReply *) {
QApplication::clipboard()->setText(QString::fromUtf8(result)); QApplication::clipboard()->setText(QString::fromUtf8(result));
notifications::notify("KShare Custom Uploader " + name(), notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
"Copied upload result to clipboard!");
}); });
} else { } else {
ioutils::postJson(target, h, data, ioutils::postJson(target, h, data,
[&](QJsonDocument result, QNetworkReply *) { [&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); });
parseResult(result, returnPathspec, name());
});
} }
break; break;
} }

View File

@ -11,7 +11,7 @@ enum class HttpMethod { POST };
enum class RequestFormat { X_WWW_FORM_URLENCODED, JSON, PLAIN }; enum class RequestFormat { X_WWW_FORM_URLENCODED, JSON, PLAIN };
class CustomUploader : public Uploader { class CustomUploader : public Uploader {
public: public:
CustomUploader(QString absFilePath); CustomUploader(QString absFilePath);
QString name(); QString name();
QString description(); QString description();
@ -19,7 +19,7 @@ public:
QString getFormatString(bool animated); QString getFormatString(bool animated);
QMap<QString, QString> types; QMap<QString, QString> types;
private: private:
QString desc; QString desc;
QString uName; QString uName;
RequestFormat format = RequestFormat::JSON; RequestFormat format = RequestFormat::JSON;

View File

@ -5,9 +5,13 @@
#include <uploaders/uploader.hpp> #include <uploaders/uploader.hpp>
class ClipboardUploader : public Uploader { class ClipboardUploader : public Uploader {
public: public:
QString name() { return "clipboard"; } QString name() {
QString description() { return "Copies the image to clipboard"; } return "clipboard";
}
QString description() {
return "Copies the image to clipboard";
}
void doUpload(QPixmap *pixmap); void doUpload(QPixmap *pixmap);
}; };

View File

@ -11,19 +11,14 @@ void ImgurUploader::doUpload(QPixmap *pixmap) {
QByteArray byteArray; QByteArray byteArray;
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);
pixmap->save(&buffer, "PNG"); pixmap->save(&buffer, "PNG");
ioutils::postJson( ioutils::postJson(QUrl("https://api.imgur.com/3/image"),
QUrl("https://api.imgur.com/3/image"),
QList<QPair<QString, QString>>() QList<QPair<QString, QString>>()
<< QPair<QString, QString>("Content-Type", << QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
"application/x-www-form-urlencoded") << QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
<< QPair<QString, QString>("Authorization",
"Client-ID 8a98f183fc895da"),
byteArray, [](QJsonDocument res, QNetworkReply *) { byteArray, [](QJsonDocument res, QNetworkReply *) {
QString result = res.object()["data"].toObject()["link"].toString(); QString result = res.object()["data"].toObject()["link"].toString();
screenshotutil::toClipboard(result); screenshotutil::toClipboard(result);
notifications::notify("KShare imgur Uploader ", notifications::notify("KShare imgur Uploader ",
result.isEmpty() result.isEmpty() ? "Failed upload!" : "Upload done, but result empty!");
? "Failed upload!"
: "Upload done, but result empty!");
}); });
} }

View File

@ -4,9 +4,13 @@
#include "../uploader.hpp" #include "../uploader.hpp"
class ImgurUploader : public Uploader { class ImgurUploader : public Uploader {
public: public:
QString name() { return "imgur"; } QString name() {
QString description() { return "imgur.com uploader"; } return "imgur";
}
QString description() {
return "imgur.com uploader";
}
void doUpload(QPixmap *pixmap); void doUpload(QPixmap *pixmap);
}; };

View File

@ -5,7 +5,7 @@
#include <QString> #include <QString>
class Uploader { class Uploader {
public: public:
virtual void doUpload(QPixmap *pixmap) = 0; virtual void doUpload(QPixmap *pixmap) = 0;
virtual QString name() = 0; virtual QString name() = 0;
virtual QString description() = 0; virtual QString description() = 0;

View File

@ -9,11 +9,10 @@
#include <settings.hpp> #include <settings.hpp>
UploaderSingleton::UploaderSingleton() : QObject() { UploaderSingleton::UploaderSingleton() : QObject() {
QDir configDir( QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
configDir.mkpath("KShare/uploaders"); configDir.mkpath("KShare/uploaders");
configDir.cd("KShare/uploaders"); configDir.cd("KShare/uploaders");
configDir.setNameFilters({"*.uploader"}); configDir.setNameFilters({ "*.uploader" });
for (QString file : configDir.entryList()) { for (QString file : configDir.entryList()) {
try { try {
registerUploader(new CustomUploader(configDir.absoluteFilePath(file))); registerUploader(new CustomUploader(configDir.absoluteFilePath(file)));
@ -40,8 +39,7 @@ UploaderSingleton::UploaderSingleton() : QObject() {
void UploaderSingleton::registerUploader(Uploader *uploader) { void UploaderSingleton::registerUploader(Uploader *uploader) {
if (uploaders.contains(uploader->name())) { if (uploaders.contains(uploader->name())) {
throw std::runtime_error( throw std::runtime_error(("Ambigious uploader " + uploader->name()).toStdString());
("Ambigious uploader " + uploader->name()).toStdString());
} }
uploaders.insert(uploader->name(), uploader); uploaders.insert(uploader->name(), uploader);
emit newUploader(uploader); emit newUploader(uploader);
@ -51,9 +49,7 @@ void UploaderSingleton::upload(QPixmap *pixmap) {
if (settings::settings().contains("fileFormat")) { if (settings::settings().contains("fileFormat")) {
QString format = settings::settings().value("fileFormat").toString(); QString format = settings::settings().value("fileFormat").toString();
if (!format.isEmpty()) { if (!format.isEmpty()) {
pixmap->save(QDir(QStandardPaths::writableLocation( pixmap->save(QDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)).absoluteFilePath(formatter::format(format) + ".png"),
QStandardPaths::PicturesLocation))
.absoluteFilePath(formatter::format(format) + ".png"),
"PNG"); "PNG");
} }
} }
@ -72,6 +68,10 @@ void UploaderSingleton::set(QString uploader) {
} }
} }
QString UploaderSingleton::selectedUploader() { return uploader; } QString UploaderSingleton::selectedUploader() {
return uploader;
}
QList<std::runtime_error> UploaderSingleton::errors() { return errs; } QList<std::runtime_error> UploaderSingleton::errors() {
return errs;
}

View File

@ -6,7 +6,7 @@
class UploaderSingleton : public QObject { class UploaderSingleton : public QObject {
Q_OBJECT Q_OBJECT
public: public:
static UploaderSingleton &inst() { static UploaderSingleton &inst() {
static UploaderSingleton inst; static UploaderSingleton inst;
return inst; return inst;
@ -17,10 +17,10 @@ public:
void set(QString uploader); void set(QString uploader);
QString selectedUploader(); QString selectedUploader();
QList<std::runtime_error> errors(); QList<std::runtime_error> errors();
signals: signals:
void newUploader(Uploader *u); void newUploader(Uploader *u);
private: private:
UploaderSingleton(); UploaderSingleton();
QMap<QString, Uploader *> uploaders; QMap<QString, Uploader *> uploaders;
QString uploader = "imgur"; QString uploader = "imgur";