diff --git a/KShare.pro b/KShare.pro index 7cec496..ab036c9 100644 --- a/KShare.pro +++ b/KShare.pro @@ -4,12 +4,12 @@ # #------------------------------------------------- -QT += core gui network widgets +QT += core gui network widgets svg TARGET = KShare TEMPLATE = app -CONFIG += c++11 +CONFIG += c++11 thread # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as deprecated (the exact warnings @@ -39,7 +39,6 @@ SOURCES += main.cpp\ uploaders/customuploader.cpp \ notifications.cpp \ hotkeying.cpp \ - cropeditor/drawing/dotitem.cpp \ cropeditor/settings/brushpenselection.cpp \ cropeditor/drawing/bluritem.cpp \ cropeditor/drawing/pathitem.cpp \ @@ -84,7 +83,6 @@ HEADERS += mainwindow.hpp \ notifications.hpp \ hotkeying.hpp \ cropeditor/drawing/drawitem.hpp \ - cropeditor/drawing/dotitem.hpp \ cropeditor/settings/brushpenselection.hpp \ cropeditor/drawing/bluritem.hpp \ cropeditor/drawing/pathitem.hpp \ diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index 8dc2c93..bd71c72 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -34,18 +33,19 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) static_cast(settings::settings().value("brushStyle", static_cast(Qt::SolidPattern)).toInt())); menu = new QMenuBar; - addDrawingAction(menu, "Dot", [] { return new DotItem; }); - addDrawingAction(menu, "Path", [] { return new PathItem; }); - addDrawingAction(menu, "Blur", [] { return new BlurItem; }); - addDrawingAction(menu, "Straight line", [] { return new LineItem; }); - addDrawingAction(menu, "Text", [] { return new TextItem; }); - addDrawingAction(menu, "Rectangle", [] { return new RectItem; }); - addDrawingAction(menu, "Ellipse", [] { return new EllipseItem; }); - addDrawingAction(menu, "Arrow", [] { return new ArrowItem; }); + addDrawingAction(menu, "Free draw", ":/icons/pencil.svg", [] { return new PathItem; }); + addDrawingAction(menu, "Blur", ":/icons/blur.png", [] { return new BlurItem; }); + addDrawingAction(menu, "Straight line", ":/icons/line.svg", [] { return new LineItem; }); + addDrawingAction(menu, "Text", ":/icons/text.svg", [] { return new TextItem; }); + addDrawingAction(menu, "Rectangle", ":/icons/rectangle.svg", [] { return new RectItem; }); + addDrawingAction(menu, "Ellipse", ":/icons/circle.svg", [] { return new EllipseItem; }); + addDrawingAction(menu, "Arrow", ":/icons/arrow.svg", [] { return new ArrowItem; }); menu->addSeparator(); - addDrawingAction(menu, "Eraser", [] { return new EraserItem; }); - QAction *clear = menu->addAction("Clear all drawing"); + addDrawingAction(menu, "Eraser", ":/icons/erase.svg", [] { return new EraserItem; }); + QAction *clear = menu->addAction(""); + clear->setToolTip("Clear all drawing"); + clear->setIcon(QIcon(":/icons/delete.svg")); connect(clear, &QAction::triggered, [&] { auto its = items(); for (auto i : its) { @@ -66,7 +66,8 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) menu->addSeparator(); QAction *settings = new QAction; - settings->setText("Settings"); + settings->setToolTip("Settings"); + settings->setIcon(QIcon(":/icons/settings.svg")); menu->addSeparator(); display = menu->addAction(drawingName); display->setDisabled(true); @@ -75,7 +76,25 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) BrushPenSelection(this).exec(); show(); }); + + QAction *font = menu->addAction(""); + font->setIcon(QIcon(":/icons/fontsettings.svg")); + connect(font, &QAction::triggered, this, &CropScene::fontAsk); + menu->addAction(settings); + menu->addSeparator(); + QAction *confirm = menu->addAction(""); + confirm->setToolTip("Confirm"); + confirm->setIcon(QIcon(":/icons/accept.svg")); + connect(confirm, &QAction::triggered, [this] { done(true); }); + menu->addAction(confirm); + + QAction *cancel = menu->addAction(""); + cancel->setToolTip("Cancel"); + cancel->setIcon(QIcon(":/icons/cancel.svg")); + connect(cancel, &QAction::triggered, [this] { done(false); }); + menu->addAction(cancel); + QPolygonF cursorPoly; cursorPoly << QPoint(-10, 0) // << QPoint(10, 0) // @@ -108,7 +127,6 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) hint->setPos(5, 5); hint->setZValue(2); hint->setVisible(settings::settings().value("crophint", true).toBool()); - connect(menu->addAction("Set Font"), &QAction::triggered, this, &CropScene::fontAsk); QPolygonF poly; QRect prect = pixmap.rect(); @@ -156,6 +174,7 @@ void CropScene::setDrawingSelection(QString name, std::function dr drawingSelectionMaker = drawAction; drawingSelection = drawAction(); drawingName = name; + display->setText(drawingName); if (drawingSelection) if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; }); } @@ -163,8 +182,7 @@ void CropScene::setDrawingSelection(QString name, std::function dr QGraphicsItem *CropScene::whichItem(QPointF scenePos) { for (auto item : items()) { if (item->sceneBoundingRect().contains(scenePos)) - if (item != polyItem && item != rect && item != cursorItem && item->zValue() != -1 && item != proxyMenu) - return item; + if (item != polyItem && item != rect && item != cursorItem && item->zValue() != -1) return item; } return nullptr; } @@ -281,7 +299,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { if (e->modifiers() & Qt::AltModifier) { auto item = whichItem(cursorItem->scenePos()); - if (item) removeItem(item); + if (item && item != proxyMenu) removeItem(item); } QGraphicsScene::mousePressEvent(e); @@ -307,13 +325,13 @@ void CropScene::wheelEvent(QGraphicsSceneWheelEvent *event) { QGraphicsScene::wheelEvent(event); } -void CropScene::addDrawingAction(QMenuBar *menu, QString name, std::function item) { - QAction *action = menu->addAction(name); - connect(action, &QAction::triggered, [this, &menu, action, item, name](bool) { setDrawingSelection(name, item); }); +void CropScene::addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function item) { + QAction *action = menu->addAction(""); + action->setToolTip(name); + action->setIcon(QIcon(icon)); + connect(action, &QAction::triggered, [this, menu, action, item, name](bool) { setDrawingSelection(name, item); }); } -static QPoint contextOffset(5, 5); - void CropScene::keyReleaseEvent(QKeyEvent *event) { if (((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !drawingSelection) || event->key() == Qt::Key_Escape) done(event->key() != Qt::Key_Escape); diff --git a/cropeditor/cropscene.hpp b/cropeditor/cropscene.hpp index 5fe8d49..07b79f8 100644 --- a/cropeditor/cropscene.hpp +++ b/cropeditor/cropscene.hpp @@ -54,11 +54,13 @@ protected: void wheelEvent(QGraphicsSceneWheelEvent *event) override; // WHEEEEEEL void keyReleaseEvent(QKeyEvent *e) override; +private slots: + void done(bool notEsc = true); + private: void updateMag(); void initMagnifierGrid(); - void addDrawingAction(QMenuBar *menu, QString name, std::function item); - void done(bool notEsc); + void addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function item); bool fullscreen; QPointF cursorPos; std::function drawingSelectionMaker; diff --git a/cropeditor/drawing/dotitem.cpp b/cropeditor/drawing/dotitem.cpp deleted file mode 100644 index 8eaea94..0000000 --- a/cropeditor/drawing/dotitem.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#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(scene->cursorPosition()); -} - -void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) { -} diff --git a/cropeditor/drawing/dotitem.hpp b/cropeditor/drawing/dotitem.hpp deleted file mode 100644 index 232f284..0000000 --- a/cropeditor/drawing/dotitem.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef DOTITEM_HPP -#define DOTITEM_HPP - -#include "../cropscene.hpp" -#include "drawitem.hpp" - -class DotItem : public DrawItem { -public: - DotItem(); - ~DotItem(); - QString name() { - return "Dots (drag to add)"; - } - void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene); - void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene); -}; - -#endif // DOTITEM_HPP diff --git a/icon.qrc b/icon.qrc index 4feaf3f..ee9e8d0 100644 --- a/icon.qrc +++ b/icon.qrc @@ -3,5 +3,18 @@ icons/icon.png icons/icon.svg icons/icon.ico + icons/pencil.svg + icons/rectangle.svg + icons/line.svg + icons/text.svg + icons/delete.svg + icons/arrow.svg + icons/circle.svg + icons/settings.svg + icons/fontsettings.svg + icons/erase.svg + icons/blur.png + icons/accept.svg + icons/cancel.svg diff --git a/icons/NOTICE.md b/icons/NOTICE.md new file mode 100644 index 0000000..5556507 --- /dev/null +++ b/icons/NOTICE.md @@ -0,0 +1,11 @@ +The following icons are from [iconmonstr](https://iconmonstr.com/): + +* [pencil.svg](https://iconmonstr.com/pencil-9/) +* [rectangle.svg](https://iconmonstr.com/square-4/) +* [circle.svg](https://iconmonstr.com/circle-2/) +* [arrow.svg](https://iconmonstr.com/arrow-19/) +* [delete.svg](https://iconmonstr.com/x-mark-12/) +* [settings.svg](https://iconmonstr.com/gear-1/) +* [erase.svg](https://iconmonstr.com/x-mark-4/) +* [accept.svg](https://iconmonstr.com/checkbox-21/) +* [cancel.svg](https://iconmonstr.com/x-mark-8/) diff --git a/icons/accept.svg b/icons/accept.svg new file mode 100644 index 0000000..b209b7b --- /dev/null +++ b/icons/accept.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/arrow.svg b/icons/arrow.svg new file mode 100644 index 0000000..3c73d35 --- /dev/null +++ b/icons/arrow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/blur.png b/icons/blur.png new file mode 100644 index 0000000..d0daf57 Binary files /dev/null and b/icons/blur.png differ diff --git a/icons/blur.svg b/icons/blur.svg new file mode 100644 index 0000000..80e2423 --- /dev/null +++ b/icons/blur.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/icons/cancel.svg b/icons/cancel.svg new file mode 100644 index 0000000..8a69429 --- /dev/null +++ b/icons/cancel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/circle.svg b/icons/circle.svg new file mode 100644 index 0000000..8868ede --- /dev/null +++ b/icons/circle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/delete.svg b/icons/delete.svg new file mode 100644 index 0000000..dd335ca --- /dev/null +++ b/icons/delete.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/erase.svg b/icons/erase.svg new file mode 100644 index 0000000..8cc0a22 --- /dev/null +++ b/icons/erase.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/fontsettings.svg b/icons/fontsettings.svg new file mode 100644 index 0000000..bb9e5e4 --- /dev/null +++ b/icons/fontsettings.svg @@ -0,0 +1,70 @@ + + + + + + + + + + image/svg+xml + + + + + + + F + + diff --git a/icons/line.svg b/icons/line.svg new file mode 100644 index 0000000..f40ea3b --- /dev/null +++ b/icons/line.svg @@ -0,0 +1,63 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/icons/pencil.svg b/icons/pencil.svg new file mode 100644 index 0000000..e9c292c --- /dev/null +++ b/icons/pencil.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/rectangle.svg b/icons/rectangle.svg new file mode 100644 index 0000000..2e739ff --- /dev/null +++ b/icons/rectangle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/settings.svg b/icons/settings.svg new file mode 100644 index 0000000..9a64fbd --- /dev/null +++ b/icons/settings.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/text.svg b/icons/text.svg new file mode 100644 index 0000000..91db3b5 --- /dev/null +++ b/icons/text.svg @@ -0,0 +1,70 @@ + + + + + + + + + + image/svg+xml + + + + + + + A + +