Add clang-format; Make text and blur less annoying
I didn't read the clang-format documentation properly
This commit is contained in:
parent
7737b77671
commit
37ce6f1eda
47
.clang-format
Normal file
47
.clang-format
Normal 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
|
@ -25,7 +25,9 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
|
||||
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);
|
||||
|
@ -17,18 +17,12 @@
|
||||
#include <settings.hpp>
|
||||
|
||||
CropScene::CropScene(QObject *parent, QPixmap *pixmap)
|
||||
: QGraphicsScene(parent), prevButtons(Qt::NoButton),
|
||||
drawingSelectionMaker([] { return nullptr; }),
|
||||
: 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>());
|
||||
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; });
|
||||
@ -37,8 +31,7 @@ CropScene::CropScene(QObject *parent, QPixmap *pixmap)
|
||||
addDrawingAction(menu, "Text", [] { return new TextItem; });
|
||||
|
||||
QAction *reset = menu.addAction("Reset");
|
||||
connect(reset, &QAction::triggered,
|
||||
[&] { setDrawingSelection("None", [] { return nullptr; }); });
|
||||
connect(reset, &QAction::triggered, [&] { setDrawingSelection("None", [] { return nullptr; }); });
|
||||
|
||||
menu.addSeparator();
|
||||
QAction *settings = new QAction;
|
||||
@ -46,12 +39,10 @@ CropScene::CropScene(QObject *parent, QPixmap *pixmap)
|
||||
menu.addSeparator();
|
||||
display = menu.addAction(drawingName);
|
||||
display->setDisabled(true);
|
||||
connect(settings, &QAction::triggered,
|
||||
[&] { BrushPenSelection(this).exec(); });
|
||||
connect(settings, &QAction::triggered, [&] { BrushPenSelection(this).exec(); });
|
||||
menu.addAction(settings);
|
||||
|
||||
connect(menu.addAction("Set Font"), &QAction::triggered, this,
|
||||
&CropScene::fontAsk);
|
||||
connect(menu.addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk);
|
||||
|
||||
_pixmap = pixmap;
|
||||
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,
|
||||
std::function<DrawItem *()> drawAction) {
|
||||
void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> drawAction) {
|
||||
drawingSelectionMaker = drawAction;
|
||||
drawingSelection = drawAction();
|
||||
drawingName = name;
|
||||
if (drawingSelection)
|
||||
drawingSelection->init(this);
|
||||
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;
|
||||
if (ok) _font = font;
|
||||
}
|
||||
|
||||
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
@ -110,14 +107,12 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||
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())));
|
||||
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());
|
||||
QPointF theMagicWikipediaPoint(rect->rect().right(), sceneRect().bottom());
|
||||
poly << sceneRect().topLeft();
|
||||
poly << sceneRect().topRight();
|
||||
poly << sceneRect().bottomRight();
|
||||
@ -145,17 +140,15 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||
delete drawingSelection;
|
||||
drawingSelection = drawingSelectionMaker();
|
||||
if (drawingSelection)
|
||||
drawingSelection->init(this);
|
||||
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
|
||||
}
|
||||
prevButtons = Qt::NoButton;
|
||||
}
|
||||
|
||||
void CropScene::addDrawingAction(QMenu &menu, QString name,
|
||||
std::function<DrawItem *()> item) {
|
||||
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); });
|
||||
connect(action, &QAction::triggered, [this, item, name](bool) { setDrawingSelection(name, item); });
|
||||
menu.addAction(action);
|
||||
}
|
||||
|
||||
@ -166,8 +159,7 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -21,9 +21,10 @@ public:
|
||||
QPen &pen();
|
||||
QBrush &brush();
|
||||
QFont &font();
|
||||
void setDrawingSelection(QString name,
|
||||
std::function<DrawItem *()> drawAction);
|
||||
QPixmap *pixmap() { return _pixmap; }
|
||||
void setDrawingSelection(QString name, std::function<DrawItem *()> drawAction);
|
||||
QPixmap *pixmap() {
|
||||
return _pixmap;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void fontAsk();
|
||||
@ -39,8 +40,7 @@ protected:
|
||||
void keyReleaseEvent(QKeyEvent *e) override;
|
||||
|
||||
private:
|
||||
void addDrawingAction(QMenu &menu, QString name,
|
||||
std::function<DrawItem *()> item);
|
||||
void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item);
|
||||
void done();
|
||||
std::function<DrawItem *()> drawingSelectionMaker;
|
||||
QFlags<Qt::MouseButton> prevButtons;
|
||||
|
@ -1,13 +1,11 @@
|
||||
#include "cropview.hpp"
|
||||
|
||||
CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene) {
|
||||
setFrameShape(
|
||||
QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
|
||||
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);
|
||||
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
||||
setCursor(QCursor(Qt::CrossCursor));
|
||||
}
|
||||
|
||||
|
@ -3,30 +3,27 @@
|
||||
#include <QDebug>
|
||||
#include <cropeditor/settings/blurdialog.hpp>
|
||||
|
||||
void BlurItem::init(CropScene *) {
|
||||
bool BlurItem::init(CropScene *) {
|
||||
effect = new QGraphicsBlurEffect;
|
||||
BlurDialog(effect).exec();
|
||||
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);
|
||||
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())));
|
||||
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);
|
||||
}
|
||||
|
@ -7,10 +7,13 @@
|
||||
|
||||
class BlurItem : public DrawItem {
|
||||
public:
|
||||
QString name() { return "Blur"; }
|
||||
~BlurItem() {}
|
||||
QString name() {
|
||||
return "Blur";
|
||||
}
|
||||
~BlurItem() {
|
||||
}
|
||||
|
||||
void init(CropScene *) override;
|
||||
bool init(CropScene *) override;
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include "dotitem.hpp"
|
||||
|
||||
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());
|
||||
DotItem::DotItem() {
|
||||
}
|
||||
|
||||
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 *) {
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ class DotItem : public DrawItem {
|
||||
public:
|
||||
DotItem();
|
||||
~DotItem();
|
||||
QString name() { return "Dots (drag to add)"; }
|
||||
QString name() {
|
||||
return "Dots (drag to add)";
|
||||
}
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
};
|
||||
|
@ -8,13 +8,15 @@ class DrawItem;
|
||||
|
||||
class DrawItem {
|
||||
public:
|
||||
virtual ~DrawItem() {}
|
||||
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;
|
||||
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,6 +1,7 @@
|
||||
#include "lineitem.hpp"
|
||||
|
||||
LineItem::LineItem() {}
|
||||
LineItem::LineItem() {
|
||||
}
|
||||
|
||||
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
||||
if (init.isNull()) {
|
||||
@ -11,4 +12,5 @@ void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
||||
}
|
||||
}
|
||||
|
||||
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
|
||||
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
|
||||
}
|
||||
|
@ -6,7 +6,9 @@
|
||||
class LineItem : public DrawItem {
|
||||
public:
|
||||
LineItem();
|
||||
QString name() override { return "Straight line"; }
|
||||
QString name() override {
|
||||
return "Straight line";
|
||||
}
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#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) {
|
||||
@ -14,4 +17,5 @@ void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
||||
}
|
||||
}
|
||||
|
||||
void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
|
||||
void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ class PathItem : public DrawItem {
|
||||
public:
|
||||
PathItem();
|
||||
~PathItem();
|
||||
QString name() { return "Path"; }
|
||||
QString name() {
|
||||
return "Path";
|
||||
}
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
#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) {
|
||||
@ -13,13 +15,15 @@ void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
||||
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())));
|
||||
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";
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
class TextItem : public DrawItem {
|
||||
public:
|
||||
QString name() override;
|
||||
void init(CropScene *) override;
|
||||
bool init(CropScene *) override;
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||
|
||||
|
@ -6,33 +6,33 @@
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QSlider>
|
||||
|
||||
BlurDialog::BlurDialog(QGraphicsBlurEffect *e, QWidget *parent)
|
||||
: QDialog(parent), ui(new Ui::BlurDialog) {
|
||||
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->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::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();
|
||||
});
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, [&] { close(); });
|
||||
}
|
||||
|
||||
BlurDialog::~BlurDialog() { delete ui; }
|
||||
BlurDialog::~BlurDialog() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void BlurDialog::on_radSpinner_valueChanged(double arg1) {
|
||||
ui->radSlider->setValue(arg1 * 100);
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <cropeditor/cropview.hpp>
|
||||
#include <settings.hpp>
|
||||
|
||||
BrushPenSelection::BrushPenSelection(CropScene *scene)
|
||||
: QDialog(), ui(new Ui::BrushPenSelection) {
|
||||
BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::BrushPenSelection) {
|
||||
ui->setupUi(this);
|
||||
ui->cosmetic->setChecked(scene->pen().isCosmetic());
|
||||
ui->widthSlider->setValue(scene->pen().width());
|
||||
@ -20,7 +19,9 @@ BrushPenSelection::BrushPenSelection(CropScene *scene)
|
||||
this->scene = scene;
|
||||
}
|
||||
|
||||
BrushPenSelection::~BrushPenSelection() { delete ui; }
|
||||
BrushPenSelection::~BrushPenSelection() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void BrushPenSelection::on_penColor_clicked(bool) {
|
||||
pen = QColorDialog::getColor(pen, this, "Pen Color");
|
||||
@ -42,7 +43,9 @@ void BrushPenSelection::on_buttonBox_accepted() {
|
||||
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.);
|
||||
|
@ -10,8 +10,7 @@ QString formatter::format(QString toFormat) {
|
||||
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)));
|
||||
formatted = formatted.replace(capturedTexts.at(i), date.toString(capturedTexts.at(i + 1)));
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
@ -8,8 +8,7 @@
|
||||
QMap<QString, QHotkey *> hotkeys;
|
||||
|
||||
// func gets bound only on first set, or load
|
||||
void hotkeying::hotkey(QString seqName, QKeySequence seq,
|
||||
std::function<void()> func) {
|
||||
void hotkeying::hotkey(QString seqName, QKeySequence seq, std::function<void()> func) {
|
||||
if (hotkeys.contains(seqName))
|
||||
hotkeys.value(seqName)->setShortcut(seq, true);
|
||||
else {
|
||||
@ -26,8 +25,7 @@ void hotkeying::load(QString seqName, std::function<void()> func) {
|
||||
QString name = seqName;
|
||||
name.prepend("hotkey_");
|
||||
if (settings::settings().contains(name))
|
||||
h = new QHotkey(QKeySequence(settings::settings().value(name).toString()),
|
||||
true);
|
||||
h = new QHotkey(QKeySequence(settings::settings().value(name).toString()), true);
|
||||
else
|
||||
h = new QHotkey;
|
||||
QObject::connect(h, &QHotkey::activated, func);
|
||||
@ -39,7 +37,5 @@ bool hotkeying::valid(QString seq) {
|
||||
}
|
||||
|
||||
QString hotkeying::sequence(QString seqName) {
|
||||
return hotkeys.contains(seqName)
|
||||
? hotkeys.value(seqName)->shortcut().toString()
|
||||
: "";
|
||||
return hotkeys.contains(seqName) ? hotkeys.value(seqName)->shortcut().toString() : "";
|
||||
}
|
||||
|
@ -8,9 +8,7 @@ namespace ioutils {
|
||||
QNetworkAccessManager networkManager;
|
||||
}
|
||||
|
||||
void ioutils::getJson(
|
||||
QUrl target, QList<QPair<QString, QString>> headers,
|
||||
std::function<void(QJsonDocument, QNetworkReply *)> callback) {
|
||||
void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback) {
|
||||
QNetworkRequest req(target);
|
||||
for (auto header : headers) {
|
||||
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
||||
@ -22,8 +20,9 @@ void ioutils::getJson(
|
||||
});
|
||||
}
|
||||
|
||||
void ioutils::postJson(
|
||||
QUrl target, QList<QPair<QString, QString>> headers, QByteArray body,
|
||||
void ioutils::postJson(QUrl target,
|
||||
QList<QPair<QString, QString>> headers,
|
||||
QByteArray body,
|
||||
std::function<void(QJsonDocument, QNetworkReply *)> callback) {
|
||||
QNetworkRequest req(target);
|
||||
for (auto header : headers) {
|
||||
@ -36,9 +35,7 @@ void ioutils::postJson(
|
||||
});
|
||||
}
|
||||
|
||||
void ioutils::getData(
|
||||
QUrl target, QList<QPair<QString, QString>> headers,
|
||||
std::function<void(QByteArray, QNetworkReply *)> callback) {
|
||||
void ioutils::getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback) {
|
||||
QNetworkRequest req(target);
|
||||
for (auto header : headers) {
|
||||
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
||||
@ -50,8 +47,9 @@ void ioutils::getData(
|
||||
});
|
||||
}
|
||||
|
||||
void ioutils::postData(
|
||||
QUrl target, QList<QPair<QString, QString>> headers, QByteArray body,
|
||||
void ioutils::postData(QUrl target,
|
||||
QList<QPair<QString, QString>> headers,
|
||||
QByteArray body,
|
||||
std::function<void(QByteArray, QNetworkReply *)> callback) {
|
||||
QNetworkRequest req(target);
|
||||
for (auto header : headers) {
|
||||
|
@ -9,16 +9,10 @@
|
||||
|
||||
namespace ioutils {
|
||||
extern QNetworkAccessManager networkManager;
|
||||
void getJson(QUrl target, QList<QPair<QString, QString>> headers,
|
||||
std::function<void(QJsonDocument, QNetworkReply *)> callback);
|
||||
void postJson(QUrl target, QList<QPair<QString, QString>> headers,
|
||||
QByteArray body,
|
||||
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);
|
||||
void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback);
|
||||
void postJson(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, 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
|
||||
|
9
main.cpp
9
main.cpp
@ -11,8 +11,7 @@ void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
||||
QByteArray localMsg = msg.toLocal8Bit();
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
if (verbose)
|
||||
fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
|
||||
if (verbose) fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
fprintf(stderr, "INFO: %s\n", localMsg.constData());
|
||||
@ -39,8 +38,7 @@ int main(int argc, char *argv[]) {
|
||||
QCommandLineParser parser;
|
||||
parser.addHelpOption();
|
||||
|
||||
QCommandLineOption h({"b", "background"},
|
||||
"Does not show the main window, starts in tray.");
|
||||
QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray.");
|
||||
QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs");
|
||||
parser.addOption(h);
|
||||
parser.addOption(v);
|
||||
@ -50,8 +48,7 @@ int main(int argc, char *argv[]) {
|
||||
MainWindow w;
|
||||
w.show();
|
||||
QTimer::singleShot(0, [&] {
|
||||
if (parser.isSet(h))
|
||||
w.hide();
|
||||
if (parser.isSet(h)) w.hide();
|
||||
});
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -20,15 +20,13 @@
|
||||
MainWindow *MainWindow::instance;
|
||||
|
||||
void addHotkeyItem(QString text, QString name, std::function<void()> *func) {
|
||||
QListWidgetItem *item =
|
||||
new QListWidgetItem(text, MainWindow::inst()->ui->hotkeys);
|
||||
QListWidgetItem *item = new QListWidgetItem(text, MainWindow::inst()->ui->hotkeys);
|
||||
item->setData(Qt::UserRole + 1, name);
|
||||
MainWindow::inst()->fncs.insert(name, func);
|
||||
hotkeying::load(name, *func);
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
instance = this;
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(QIcon(":/icons/icon.png"));
|
||||
@ -45,27 +43,20 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
menu->addActions({ fullscreen, area });
|
||||
connect(quit, &QAction::triggered, this, &MainWindow::quit);
|
||||
connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible);
|
||||
connect(tray, &QSystemTrayIcon::messageClicked, this,
|
||||
&MainWindow::toggleVisible);
|
||||
connect(tray, &QSystemTrayIcon::activated, this,
|
||||
[this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::DoubleClick)
|
||||
toggleVisible();
|
||||
connect(tray, &QSystemTrayIcon::messageClicked, this, &MainWindow::toggleVisible);
|
||||
connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::DoubleClick) toggleVisible();
|
||||
});
|
||||
connect(fullscreen, &QAction::triggered, this,
|
||||
[] { screenshotter::fullscreenDelayed(); });
|
||||
connect(area, &QAction::triggered, this,
|
||||
[] { screenshotter::areaDelayed(); });
|
||||
connect(fullscreen, &QAction::triggered, this, [] { screenshotter::fullscreenDelayed(); });
|
||||
connect(area, &QAction::triggered, this, [] { screenshotter::areaDelayed(); });
|
||||
tray->setContextMenu(menu);
|
||||
|
||||
ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
// Add items to uploader selection
|
||||
for (Uploader *u : UploaderSingleton::inst().uploaderList())
|
||||
newUploader(u);
|
||||
connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this,
|
||||
&MainWindow::newUploader);
|
||||
for (Uploader *u : UploaderSingleton::inst().uploaderList()) newUploader(u);
|
||||
connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this, &MainWindow::newUploader);
|
||||
|
||||
// Set filename scheme
|
||||
if ((settings::settings().contains("fileFormat")))
|
||||
@ -77,9 +68,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
if (errors.length() == 1)
|
||||
statusBar()->showMessage(errors.at(0).what());
|
||||
else
|
||||
statusBar()->showMessage(
|
||||
QString("Errors visible in console (if present). Count: " +
|
||||
QString::number(errors.size())));
|
||||
statusBar()->showMessage(QString("Errors visible in console (if present). Count: " + QString::number(errors.size())));
|
||||
|
||||
// Set delay
|
||||
if ((settings::settings().contains("delay")))
|
||||
@ -89,26 +78,34 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
ui->hotkeys->setSelectionMode(QListWidget::SingleSelection);
|
||||
|
||||
addHotkeyItem("Fullscreen image", "fullscreen",
|
||||
new std::function<void()>([] { screenshotter::fullscreen(); }));
|
||||
addHotkeyItem("Area image", "area",
|
||||
new std::function<void()>([] { screenshotter::area(); }));
|
||||
addHotkeyItem("Fullscreen image", "fullscreen", new std::function<void()>([] { screenshotter::fullscreen(); }));
|
||||
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) {
|
||||
event->ignore();
|
||||
QTimer::singleShot(0, this, &MainWindow::hide);
|
||||
}
|
||||
|
||||
void MainWindow::quit() { QCoreApplication::quit(); }
|
||||
void MainWindow::quit() {
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
void MainWindow::toggleVisible() {
|
||||
this->setVisible(!this->isVisible());
|
||||
@ -121,17 +118,20 @@ void MainWindow::newUploader(Uploader *u) {
|
||||
QListWidgetItem *item = new QListWidgetItem(u->name());
|
||||
item->setToolTip(u->description());
|
||||
ui->uploaderList->addItem(item);
|
||||
if (u->name() == UploaderSingleton::inst().selectedUploader())
|
||||
item->setSelected(true);
|
||||
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionQuit_triggered() { quit(); }
|
||||
void MainWindow::on_actionQuit_triggered() {
|
||||
quit();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionFullscreen_triggered() {
|
||||
screenshotter::fullscreenDelayed();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionArea_triggered() { screenshotter::areaDelayed(); }
|
||||
void MainWindow::on_actionArea_triggered() {
|
||||
screenshotter::areaDelayed();
|
||||
}
|
||||
|
||||
void MainWindow::on_uploaderList_clicked(const QModelIndex &) {
|
||||
QList<QListWidgetItem *> index = ui->uploaderList->selectedItems();
|
||||
@ -152,10 +152,8 @@ void MainWindow::on_hotkeys_doubleClicked(const QModelIndex &) {
|
||||
if (ui->hotkeys->selectedItems().length() == 1) {
|
||||
QListWidgetItem *i = ui->hotkeys->selectedItems().at(0);
|
||||
QString str = i->data(Qt::UserRole + 1).toString();
|
||||
QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input",
|
||||
"Insert hotkey:", QLineEdit::Normal,
|
||||
QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", "Insert hotkey:", QLineEdit::Normal,
|
||||
hotkeying::sequence(str));
|
||||
if (hotkeying::valid(seq))
|
||||
hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str));
|
||||
if (hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str));
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include "mainwindow.hpp"
|
||||
#include <QStatusBar>
|
||||
|
||||
void notifications::notify(QString title, QString body,
|
||||
QSystemTrayIcon::MessageIcon icon) {
|
||||
void notifications::notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon) {
|
||||
MainWindow::inst()->tray->showMessage(title, body, icon, 5000);
|
||||
MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
|
||||
}
|
||||
|
@ -5,8 +5,7 @@
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
namespace notifications {
|
||||
void notify(QString title, QString body,
|
||||
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
||||
void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
||||
}
|
||||
|
||||
#endif // NOTIFICATIONS_HPP
|
||||
|
@ -8,9 +8,7 @@
|
||||
|
||||
void screenshotter::area() {
|
||||
CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
|
||||
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap *pixmap) {
|
||||
UploaderSingleton::inst().upload(pixmap);
|
||||
});
|
||||
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap *pixmap) { UploaderSingleton::inst().upload(pixmap); });
|
||||
}
|
||||
|
||||
void screenshotter::fullscreen() {
|
||||
@ -18,11 +16,9 @@ void screenshotter::fullscreen() {
|
||||
}
|
||||
|
||||
void screenshotter::areaDelayed() {
|
||||
QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000,
|
||||
&screenshotter::area);
|
||||
QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, &screenshotter::area);
|
||||
}
|
||||
|
||||
void screenshotter::fullscreenDelayed() {
|
||||
QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000,
|
||||
&screenshotter::fullscreen);
|
||||
QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, &screenshotter::fullscreen);
|
||||
}
|
||||
|
@ -5,7 +5,9 @@
|
||||
#include <QPixmap>
|
||||
#include <QScreen>
|
||||
|
||||
QPixmap *screenshotutil::fullscreen() { return window(0); }
|
||||
QPixmap *screenshotutil::fullscreen() {
|
||||
return window(0);
|
||||
}
|
||||
|
||||
QPixmap *screenshotutil::window(long wid) {
|
||||
QScreen *w = QApplication::primaryScreen();
|
||||
|
@ -3,14 +3,11 @@
|
||||
#include <QStandardPaths>
|
||||
|
||||
QSettings &settings::settings() {
|
||||
static QDir configDir(
|
||||
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
|
||||
if (configDir.path() ==
|
||||
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) {
|
||||
static QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
|
||||
if (configDir.path() == QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) {
|
||||
configDir.mkdir("KShare");
|
||||
configDir.cd("KShare");
|
||||
}
|
||||
static QSettings settings(configDir.absoluteFilePath("settings.ini"),
|
||||
QSettings::IniFormat);
|
||||
static QSettings settings(configDir.absoluteFilePath("settings.ini"), QSettings::IniFormat);
|
||||
return settings;
|
||||
}
|
||||
|
@ -13,9 +13,7 @@
|
||||
using std::runtime_error;
|
||||
|
||||
void error(QString absFilePath, QString err) {
|
||||
throw runtime_error(
|
||||
(QString("Invalid file: ").append(absFilePath) + ": " + err)
|
||||
.toStdString());
|
||||
throw runtime_error((QString("Invalid file: ").append(absFilePath) + ": " + err).toStdString());
|
||||
}
|
||||
|
||||
CustomUploader::CustomUploader(QString absFilePath) {
|
||||
@ -27,8 +25,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
||||
types.insert("MP4", "video/mp4");
|
||||
// Let's go
|
||||
QFile file(absFilePath);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
error(absFilePath, file.errorString());
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) error(absFilePath, file.errorString());
|
||||
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
|
||||
if (!doc.isObject()) {
|
||||
error(absFilePath, "Root not an object");
|
||||
@ -47,8 +44,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
||||
desc = absFilePath;
|
||||
QJsonValue m = obj["method"];
|
||||
if (!m.isUndefined() && !m.isNull()) {
|
||||
if (!m.isString())
|
||||
error(absFilePath, "method not a string");
|
||||
if (!m.isString()) error(absFilePath, "method not a string");
|
||||
QString toCheck = m.toString().toLower();
|
||||
if (toCheck == "post")
|
||||
method = HttpMethod::POST;
|
||||
@ -60,8 +56,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
||||
error(absFilePath, "target missing");
|
||||
}
|
||||
QUrl target(url.toString());
|
||||
if (!target.isValid())
|
||||
error(absFilePath, "target not URL");
|
||||
if (!target.isValid()) error(absFilePath, "target not URL");
|
||||
this->target = target;
|
||||
QJsonValue formatValue = obj["format"];
|
||||
if (!formatValue.isUndefined() && !formatValue.isNull()) {
|
||||
@ -83,16 +78,14 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
||||
error(absFilePath, "imageformat not string");
|
||||
}
|
||||
QString imageFormat = imageValue.toString();
|
||||
if (imageFormat == "base64" ||
|
||||
QRegExp("base64\\([^+]+\\+[^+]+)").exactMatch(imageFormat) ||
|
||||
QRegExp("[^+]+\\+[^+]+").exactMatch(imageFormat)) {
|
||||
if (imageFormat == "base64" || QRegExp("base64\\([^+]+\\+[^+]+)").exactMatch(imageFormat)
|
||||
|| QRegExp("[^+]+\\+[^+]+").exactMatch(imageFormat)) {
|
||||
this->iFormat = imageFormat;
|
||||
} else
|
||||
error(absFilePath, "imageformat invalid");
|
||||
QJsonValue bodyValue = obj["body"];
|
||||
if (format != RequestFormat::PLAIN) {
|
||||
if (bodyValue.isUndefined())
|
||||
error(absFilePath, "body not set");
|
||||
if (bodyValue.isUndefined()) error(absFilePath, "body not set");
|
||||
if (bodyValue.isObject())
|
||||
body = bodyValue;
|
||||
else
|
||||
@ -105,8 +98,7 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
||||
}
|
||||
QJsonValue headerVal = obj["headers"];
|
||||
if (!(headerVal.isUndefined() || headerVal.isNull())) {
|
||||
if (!headerVal.isObject())
|
||||
error(absFilePath, "headers must be object");
|
||||
if (!headerVal.isObject()) error(absFilePath, "headers must be object");
|
||||
headers = headerVal.toObject();
|
||||
} else
|
||||
headers = QJsonObject();
|
||||
@ -117,9 +109,13 @@ CustomUploader::CustomUploader(QString absFilePath) {
|
||||
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) {
|
||||
switch (format) {
|
||||
@ -133,22 +129,17 @@ QString getCType(RequestFormat format, QString plainType) {
|
||||
return plainType;
|
||||
}
|
||||
|
||||
QList<QPair<QString, QString>> getHeaders(QJsonObject h, QString imageFormat,
|
||||
QMap<QString, QString> types,
|
||||
RequestFormat format) {
|
||||
QList<QPair<QString, QString>> getHeaders(QJsonObject h, QString imageFormat, QMap<QString, QString> types, RequestFormat format) {
|
||||
QList<QPair<QString, QString>> headers;
|
||||
for (QString s : h.keys()) {
|
||||
if (s.toLower() == "content-type")
|
||||
continue;
|
||||
if (s.toLower() == "content-type") continue;
|
||||
QJsonValue v = h[s];
|
||||
if (!v.isString())
|
||||
headers << QPair<QString, QString>(
|
||||
s, QJsonDocument::fromVariant(v.toVariant()).toJson());
|
||||
headers << QPair<QString, QString>(s, QJsonDocument::fromVariant(v.toVariant()).toJson());
|
||||
else
|
||||
headers << QPair<QString, QString>(s, v.toString());
|
||||
}
|
||||
headers << QPair<QString, QString>(
|
||||
"Content-Type", getCType(format, types.value(imageFormat)));
|
||||
headers << QPair<QString, QString>("Content-Type", getCType(format, types.value(imageFormat)));
|
||||
return headers;
|
||||
}
|
||||
|
||||
@ -170,8 +161,7 @@ QString CustomUploader::getFormatString(bool animated) {
|
||||
return "";
|
||||
}
|
||||
|
||||
QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data,
|
||||
QString contentType) {
|
||||
QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data, QString contentType) {
|
||||
QJsonObject o;
|
||||
for (QString s : body.keys()) {
|
||||
QJsonValue v = body[s];
|
||||
@ -181,9 +171,7 @@ QJsonObject recurseAndReplace(QJsonObject &body, QByteArray &data,
|
||||
} else if (v.isString()) {
|
||||
QString str = v.toString();
|
||||
if (str.startsWith("/") && str.endsWith("/")) {
|
||||
o.insert(
|
||||
s,
|
||||
str.replace("%image", data).replace("%contenttype", contentType));
|
||||
o.insert(s, str.replace("%image", data).replace("%contenttype", contentType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -195,10 +183,8 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
|
||||
// Does not point to anything
|
||||
return "";
|
||||
} else {
|
||||
if (!response.isObject())
|
||||
return "";
|
||||
QStringList fields = pathspec.right(pathspec.length() - 1)
|
||||
.split('.', QString::SkipEmptyParts);
|
||||
if (!response.isObject()) return "";
|
||||
QStringList fields = pathspec.right(pathspec.length() - 1).split('.', QString::SkipEmptyParts);
|
||||
QJsonObject o = response.object();
|
||||
if (pathspec == ".") {
|
||||
return QString::fromUtf8(response.toJson());
|
||||
@ -209,16 +195,14 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
|
||||
else if (val.isString())
|
||||
return val.toString();
|
||||
else if (!val.isObject())
|
||||
return QString::fromUtf8(
|
||||
QJsonDocument::fromVariant(val.toVariant()).toJson());
|
||||
return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
|
||||
for (int i = 1; i < fields.size(); i++) {
|
||||
if (val.isUndefined() || val.isNull())
|
||||
return "";
|
||||
else if (val.isString())
|
||||
return val.toString();
|
||||
else if (!val.isObject())
|
||||
return QString::fromUtf8(
|
||||
QJsonDocument::fromVariant(val.toVariant()).toJson());
|
||||
return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
|
||||
else
|
||||
val = val.toObject()[fields.at(i)];
|
||||
}
|
||||
@ -227,8 +211,7 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
|
||||
else if (val.isString())
|
||||
return val.toString();
|
||||
else if (!val.isObject())
|
||||
return QString::fromUtf8(
|
||||
QJsonDocument::fromVariant(val.toVariant()).toJson());
|
||||
return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@ -239,14 +222,11 @@ void parseResult(QJsonDocument result, QString returnPathspec, QString name) {
|
||||
QString url = parsePathspec(result, returnPathspec);
|
||||
if (!url.isEmpty()) {
|
||||
QApplication::clipboard()->setText(url);
|
||||
notifications::notify("KShare Custom Uploader " + name,
|
||||
"Copied upload link to clipboard!");
|
||||
notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!");
|
||||
} else
|
||||
notifications::notify("KShare Custom Uploader " + name,
|
||||
"Upload done, but result empty!");
|
||||
notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!");
|
||||
} else
|
||||
notifications::notify("KShare Custom Uploader " + name,
|
||||
"Upload done, but result is not JSON Object!");
|
||||
notifications::notify("KShare Custom Uploader " + name, "Upload done, but result is not JSON Object!");
|
||||
}
|
||||
|
||||
void CustomUploader::doUpload(QPixmap *pixmap) {
|
||||
@ -254,29 +234,21 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
|
||||
QString format = getFormatString(false); // Soon:tm:
|
||||
QByteArray data;
|
||||
QByteArray imgData = imageBytes(pixmap, format);
|
||||
if (iFormat == "base64" ||
|
||||
QRegExp("base64\\([^+]\\+[^+]\\)").exactMatch(iFormat))
|
||||
imgData = imgData.toBase64();
|
||||
if (iFormat == "base64" || QRegExp("base64\\([^+]\\+[^+]\\)").exactMatch(iFormat)) imgData = imgData.toBase64();
|
||||
switch (this->format) {
|
||||
case RequestFormat::PLAIN: {
|
||||
data = imgData;
|
||||
} break;
|
||||
case RequestFormat::JSON: {
|
||||
if (body.isString()) {
|
||||
QStringList split = body.toString()
|
||||
.replace("%contenttype", types.value(format))
|
||||
.split("%imagedata");
|
||||
QStringList split = body.toString().replace("%contenttype", types.value(format)).split("%imagedata");
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
data.append(split[i]);
|
||||
if (i < split.size() - 1)
|
||||
data.append(imgData);
|
||||
if (i < split.size() - 1) data.append(imgData);
|
||||
}
|
||||
} else {
|
||||
QJsonObject vo = body.toObject();
|
||||
data = QJsonDocument::fromVariant(
|
||||
recurseAndReplace(vo, imgData, types.value(format))
|
||||
.toVariantMap())
|
||||
.toJson();
|
||||
data = QJsonDocument::fromVariant(recurseAndReplace(vo, imgData, types.value(format)).toVariantMap()).toJson();
|
||||
}
|
||||
} break;
|
||||
case RequestFormat::X_WWW_FORM_URLENCODED: {
|
||||
@ -288,22 +260,18 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
|
||||
QByteArray strB;
|
||||
if (str.startsWith("/") && str.endsWith("/")) {
|
||||
str = str.mid(1, str.length() - 2);
|
||||
QStringList split = str.replace("%contenttype", types.value(format))
|
||||
.split("%imagedata");
|
||||
QStringList split = str.replace("%contenttype", types.value(format)).split("%imagedata");
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
strB.append(split[i]);
|
||||
if (i < split.size() - 1)
|
||||
strB.append(imgData);
|
||||
if (i < split.size() - 1) strB.append(imgData);
|
||||
}
|
||||
}
|
||||
data.append(QUrl::toPercentEncoding(key)).append('=').append(strB);
|
||||
} else {
|
||||
if (!data.isEmpty())
|
||||
data.append('&');
|
||||
if (!data.isEmpty()) data.append('&');
|
||||
data.append(QUrl::toPercentEncoding(key))
|
||||
.append('=')
|
||||
.append(QUrl::toPercentEncoding(
|
||||
QJsonDocument::fromVariant(body[key].toVariant()).toJson()));
|
||||
.append(QUrl::toPercentEncoding(QJsonDocument::fromVariant(body[key].toVariant()).toJson()));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
@ -311,17 +279,13 @@ void CustomUploader::doUpload(QPixmap *pixmap) {
|
||||
switch (method) {
|
||||
case HttpMethod::POST:
|
||||
if (returnPathspec == "|") {
|
||||
ioutils::postData(
|
||||
target, h, data, [&](QByteArray result, QNetworkReply *) {
|
||||
ioutils::postData(target, h, data, [&](QByteArray result, QNetworkReply *) {
|
||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||
notifications::notify("KShare Custom Uploader " + name(),
|
||||
"Copied upload result to clipboard!");
|
||||
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
||||
});
|
||||
} else {
|
||||
ioutils::postJson(target, h, data,
|
||||
[&](QJsonDocument result, QNetworkReply *) {
|
||||
parseResult(result, returnPathspec, name());
|
||||
});
|
||||
[&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -6,8 +6,12 @@
|
||||
|
||||
class ClipboardUploader : public Uploader {
|
||||
public:
|
||||
QString name() { return "clipboard"; }
|
||||
QString description() { return "Copies the image to clipboard"; }
|
||||
QString name() {
|
||||
return "clipboard";
|
||||
}
|
||||
QString description() {
|
||||
return "Copies the image to clipboard";
|
||||
}
|
||||
void doUpload(QPixmap *pixmap);
|
||||
};
|
||||
|
||||
|
@ -11,19 +11,14 @@ void ImgurUploader::doUpload(QPixmap *pixmap) {
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
pixmap->save(&buffer, "PNG");
|
||||
ioutils::postJson(
|
||||
QUrl("https://api.imgur.com/3/image"),
|
||||
ioutils::postJson(QUrl("https://api.imgur.com/3/image"),
|
||||
QList<QPair<QString, QString>>()
|
||||
<< QPair<QString, QString>("Content-Type",
|
||||
"application/x-www-form-urlencoded")
|
||||
<< QPair<QString, QString>("Authorization",
|
||||
"Client-ID 8a98f183fc895da"),
|
||||
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
|
||||
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
|
||||
byteArray, [](QJsonDocument res, QNetworkReply *) {
|
||||
QString result = res.object()["data"].toObject()["link"].toString();
|
||||
screenshotutil::toClipboard(result);
|
||||
notifications::notify("KShare imgur Uploader ",
|
||||
result.isEmpty()
|
||||
? "Failed upload!"
|
||||
: "Upload done, but result empty!");
|
||||
result.isEmpty() ? "Failed upload!" : "Upload done, but result empty!");
|
||||
});
|
||||
}
|
||||
|
@ -5,8 +5,12 @@
|
||||
|
||||
class ImgurUploader : public Uploader {
|
||||
public:
|
||||
QString name() { return "imgur"; }
|
||||
QString description() { return "imgur.com uploader"; }
|
||||
QString name() {
|
||||
return "imgur";
|
||||
}
|
||||
QString description() {
|
||||
return "imgur.com uploader";
|
||||
}
|
||||
void doUpload(QPixmap *pixmap);
|
||||
};
|
||||
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <settings.hpp>
|
||||
|
||||
UploaderSingleton::UploaderSingleton() : QObject() {
|
||||
QDir configDir(
|
||||
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
|
||||
QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
|
||||
configDir.mkpath("KShare/uploaders");
|
||||
configDir.cd("KShare/uploaders");
|
||||
configDir.setNameFilters({ "*.uploader" });
|
||||
@ -40,8 +39,7 @@ UploaderSingleton::UploaderSingleton() : QObject() {
|
||||
|
||||
void UploaderSingleton::registerUploader(Uploader *uploader) {
|
||||
if (uploaders.contains(uploader->name())) {
|
||||
throw std::runtime_error(
|
||||
("Ambigious uploader " + uploader->name()).toStdString());
|
||||
throw std::runtime_error(("Ambigious uploader " + uploader->name()).toStdString());
|
||||
}
|
||||
uploaders.insert(uploader->name(), uploader);
|
||||
emit newUploader(uploader);
|
||||
@ -51,9 +49,7 @@ void UploaderSingleton::upload(QPixmap *pixmap) {
|
||||
if (settings::settings().contains("fileFormat")) {
|
||||
QString format = settings::settings().value("fileFormat").toString();
|
||||
if (!format.isEmpty()) {
|
||||
pixmap->save(QDir(QStandardPaths::writableLocation(
|
||||
QStandardPaths::PicturesLocation))
|
||||
.absoluteFilePath(formatter::format(format) + ".png"),
|
||||
pixmap->save(QDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)).absoluteFilePath(formatter::format(format) + ".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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user