Improve drawing experiance

This commit is contained in:
ArsenArsen 2017-04-29 23:20:08 +02:00
parent 99f9171951
commit 49d556569f
3 changed files with 13 additions and 5 deletions

View File

@ -9,15 +9,20 @@ LineItem::~LineItem()
delete path; delete path;
} }
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *) void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene)
{ {
if (path == nullptr) if (path == nullptr)
{
path = new QPainterPath(e->scenePos()); path = new QPainterPath(e->scenePos());
pathItem = scene->addPath(*path, scene->pen(), scene->brush());
}
else else
{
path->lineTo(e->scenePos()); path->lineTo(e->scenePos());
pathItem->setPath(*path);
}
} }
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *scene) void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *)
{ {
scene->addPath(*path, scene->pen(), scene->brush());
} }

View File

@ -18,6 +18,7 @@ class LineItem : public DrawItem
private: private:
QPainterPath *path = nullptr; QPainterPath *path = nullptr;
QGraphicsPathItem *pathItem = nullptr;
}; };
#endif // LINEITEM_HPP #endif // LINEITEM_HPP

View File

@ -1,7 +1,7 @@
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QDebug> #include <QTimer>
#include <QtGlobal> #include <QtGlobal>
#include <stdio.h> #include <stdio.h>
@ -51,6 +51,8 @@ int main(int argc, char *argv[])
MainWindow w; MainWindow w;
w.show(); w.show();
if (parser.isSet(h)) w.hide(); QTimer::singleShot(0, [&] {
if (parser.isSet(h)) w.hide();
});
return a.exec(); return a.exec();
} }