This commit contains fixes and a broken attempt to make drawing.
Segfaults are real on this one. Basically, when I call this virtual method on a field which containts a pointer to a derived class from a pure virtual one the program segfaults. Please help.
This commit is contained in:
parent
3c92607727
commit
a2b973d34e
@ -38,7 +38,8 @@ SOURCES += main.cpp\
|
||||
formatter.cpp \
|
||||
uploaders/customuploader.cpp \
|
||||
notifications.cpp \
|
||||
hotkeying.cpp
|
||||
hotkeying.cpp \
|
||||
cropeditor/drawing/dotitem.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -56,7 +57,8 @@ HEADERS += mainwindow.hpp \
|
||||
uploaders/customuploader.hpp \
|
||||
notifications.hpp \
|
||||
hotkeying.hpp \
|
||||
cropeditor/drawing/drawitem.hpp
|
||||
cropeditor/drawing/drawitem.hpp \
|
||||
cropeditor/drawing/dotitem.hpp
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "cropeditor.hpp"
|
||||
|
||||
#include "cropscene.hpp"
|
||||
#include "cropview.hpp"
|
||||
#include <QDebug>
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
@ -1,10 +1,12 @@
|
||||
#include "cropscene.hpp"
|
||||
#include <QColorDialog>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsPolygonItem>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
#include <cropeditor/drawing/dotitem.hpp>
|
||||
|
||||
CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::NoButton)
|
||||
{
|
||||
@ -21,10 +23,31 @@ CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::
|
||||
});
|
||||
}
|
||||
|
||||
QPen CropScene::pen()
|
||||
{
|
||||
return _pen;
|
||||
}
|
||||
|
||||
QBrush CropScene::brush()
|
||||
{
|
||||
return _brush;
|
||||
}
|
||||
|
||||
void CropScene::setDrawingSelection(DrawItem *drawAction)
|
||||
{
|
||||
drawingSelection = drawAction;
|
||||
}
|
||||
|
||||
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
auto buttons = e->buttons();
|
||||
if (buttons == Qt::LeftButton || prevButtons == Qt::NoButton)
|
||||
{
|
||||
if (drawingSelection != nullptr)
|
||||
{
|
||||
drawingSelection->mouseDragEvent(e, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
QPointF p = e->scenePos();
|
||||
if (rect == nullptr)
|
||||
@ -67,6 +90,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
this->polyItem->setPolygon(poly);
|
||||
e->accept();
|
||||
}
|
||||
}
|
||||
else
|
||||
QGraphicsScene::mouseMoveEvent(e);
|
||||
prevButtons = buttons;
|
||||
@ -74,6 +98,11 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
|
||||
void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
if (drawingSelection != nullptr)
|
||||
{
|
||||
drawingSelection->mouseDragEndEvent(e, this);
|
||||
drawingSelection = nullptr;
|
||||
}
|
||||
prevButtons = Qt::NoButton;
|
||||
QGraphicsScene::mouseReleaseEvent(e);
|
||||
}
|
||||
@ -83,11 +112,31 @@ void CropScene::keyReleaseEvent(QKeyEvent *event)
|
||||
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) done();
|
||||
}
|
||||
|
||||
void CropScene::addDrawingAction(QMenu &menu, DrawItem *item)
|
||||
{
|
||||
QAction *action = new QAction;
|
||||
action->setText(item->name());
|
||||
QObject::connect(action, &QAction::triggered,
|
||||
[&](bool) { QTimer::singleShot(0, [&] { setDrawingSelection(item); }); });
|
||||
menu.addAction(action);
|
||||
}
|
||||
|
||||
void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
|
||||
{
|
||||
QMenu menu(e->widget());
|
||||
// QMenu menu(e->widget());
|
||||
|
||||
menu.exec(e->screenPos());
|
||||
// addDrawingAction(menu, new DotItem);
|
||||
|
||||
// menu.addSeparator();
|
||||
// QAction *bColorAction = new QAction;
|
||||
// bColorAction->setText("Select brush color");
|
||||
// connect(bColorAction, &QAction::triggered, [&] { _brush.setColor(QColorDialog::getColor(_brush.color())); });
|
||||
// QAction *pColorAction = new QAction;
|
||||
// pColorAction->setText("Select pen color");
|
||||
// connect(pColorAction, &QAction::triggered, [&] { _pen.setColor(QColorDialog::getColor(_pen.color())); });
|
||||
// menu.addActions({ pColorAction, bColorAction });
|
||||
|
||||
// menu.exec(e->screenPos());
|
||||
e->accept();
|
||||
}
|
||||
|
||||
@ -99,5 +148,9 @@ void CropScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e)
|
||||
|
||||
void CropScene::done()
|
||||
{
|
||||
if (rect) emit closedWithRect(rect->rect().toRect());
|
||||
if (rect)
|
||||
{
|
||||
rect->setPen(QPen(Qt::NoPen));
|
||||
emit closedWithRect(rect->rect().toRect());
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,19 @@
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
class CropScene;
|
||||
|
||||
#include <cropeditor/drawing/drawitem.hpp>
|
||||
|
||||
class CropScene : public QGraphicsScene
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CropScene(QObject *parent);
|
||||
QPen pen();
|
||||
QBrush brush();
|
||||
void setDrawingSelection(DrawItem *drawAction);
|
||||
|
||||
signals:
|
||||
void closedWithRect(QRect rect);
|
||||
|
||||
@ -24,11 +32,15 @@ class CropScene : public QGraphicsScene
|
||||
void keyReleaseEvent(QKeyEvent *e) override;
|
||||
|
||||
private:
|
||||
void addDrawingAction(QMenu &menu, DrawItem *item);
|
||||
void done();
|
||||
QFlags<Qt::MouseButton> prevButtons;
|
||||
QGraphicsRectItem *rect = nullptr;
|
||||
QPointF initPos;
|
||||
QPen _pen;
|
||||
QBrush _brush;
|
||||
QGraphicsPolygonItem *polyItem = nullptr;
|
||||
DrawItem *drawingSelection = nullptr;
|
||||
};
|
||||
|
||||
#endif // CROPSCENE_HPP
|
||||
|
@ -5,7 +5,7 @@ CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene)
|
||||
setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
|
||||
// setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
|
||||
}
|
||||
|
||||
void CropView::keyPressEvent(QKeyEvent *e)
|
||||
|
18
cropeditor/drawing/dotitem.cpp
Normal file
18
cropeditor/drawing/dotitem.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#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());
|
||||
}
|
||||
|
||||
void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *)
|
||||
{
|
||||
}
|
20
cropeditor/drawing/dotitem.hpp
Normal file
20
cropeditor/drawing/dotitem.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#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
|
@ -7,10 +7,12 @@
|
||||
class DrawItem
|
||||
{
|
||||
public:
|
||||
virtual ~DrawItem()
|
||||
{
|
||||
}
|
||||
virtual QString name() = 0;
|
||||
virtual void render(QPixmap *pixmap) = 0;
|
||||
virtual void makeItem(CropScene *scene) = 0;
|
||||
virtual void mouseDragEvent(QGraphicsSceneMoveEvent *e, CropScene *scene) = 0;
|
||||
virtual void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
|
||||
virtual void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
|
||||
};
|
||||
|
||||
#endif // DRAWITEM_HPP
|
||||
|
@ -50,8 +50,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::DoubleClick) toggleVisible();
|
||||
});
|
||||
connect(fullscreen, &QAction::triggered, this, [] { screenshotter::area(); });
|
||||
connect(area, &QAction::triggered, this, [] { screenshotter::area(); });
|
||||
connect(fullscreen, &QAction::triggered, this, [] { screenshotter::fullscreenDelayed(); });
|
||||
connect(area, &QAction::triggered, this, [] { screenshotter::areaDelayed(); });
|
||||
tray->setContextMenu(menu);
|
||||
|
||||
ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
Loading…
Reference in New Issue
Block a user