Drawing + some hotkey fixes

This commit is contained in:
ArsenArsen 2017-04-29 23:00:32 +02:00
parent dc5ce7649a
commit 99f9171951
11 changed files with 272 additions and 23 deletions

View File

@ -39,7 +39,9 @@ SOURCES += main.cpp\
uploaders/customuploader.cpp \ uploaders/customuploader.cpp \
notifications.cpp \ notifications.cpp \
hotkeying.cpp \ hotkeying.cpp \
cropeditor/drawing/dotitem.cpp cropeditor/drawing/dotitem.cpp \
cropeditor/drawing/lineitem.cpp \
cropeditor/settings/brushpenselection.cpp
HEADERS += mainwindow.hpp \ HEADERS += mainwindow.hpp \
cropeditor/cropeditor.hpp \ cropeditor/cropeditor.hpp \
@ -58,9 +60,12 @@ HEADERS += mainwindow.hpp \
notifications.hpp \ notifications.hpp \
hotkeying.hpp \ hotkeying.hpp \
cropeditor/drawing/drawitem.hpp \ cropeditor/drawing/drawitem.hpp \
cropeditor/drawing/dotitem.hpp cropeditor/drawing/dotitem.hpp \
cropeditor/drawing/lineitem.hpp \
cropeditor/settings/brushpenselection.hpp
FORMS += mainwindow.ui FORMS += mainwindow.ui \
cropeditor/settings/brushpenselection.ui
DISTFILES += \ DISTFILES += \
README.md \ README.md \

View File

@ -7,6 +7,8 @@
#include <QMenu> #include <QMenu>
#include <QTimer> #include <QTimer>
#include <cropeditor/drawing/dotitem.hpp> #include <cropeditor/drawing/dotitem.hpp>
#include <cropeditor/drawing/lineitem.hpp>
#include <cropeditor/settings/brushpenselection.hpp>
CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::NoButton) CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::NoButton)
{ {
@ -23,12 +25,12 @@ CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::
}); });
} }
QPen CropScene::pen() QPen &CropScene::pen()
{ {
return _pen; return _pen;
} }
QBrush CropScene::brush() QBrush &CropScene::brush()
{ {
return _brush; return _brush;
} }
@ -99,6 +101,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
if (drawingSelection != nullptr) if (drawingSelection != nullptr)
{ {
drawingSelection->mouseDragEndEvent(e, this); drawingSelection->mouseDragEndEvent(e, this);
delete drawingSelection;
drawingSelection = nullptr; drawingSelection = nullptr;
} }
prevButtons = Qt::NoButton; prevButtons = Qt::NoButton;
@ -113,27 +116,24 @@ void CropScene::addDrawingAction(QMenu &menu, DrawItem *item)
{ {
QAction *action = new QAction; QAction *action = new QAction;
action->setText(item->name()); action->setText(item->name());
QObject::connect(action, &QAction::triggered, QObject::connect(action, &QAction::triggered, [this, item](bool) { setDrawingSelection(item); });
[&](bool) { QTimer::singleShot(0, [&] { setDrawingSelection(item); }); });
menu.addAction(action); menu.addAction(action);
} }
void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
{ {
// QMenu menu(e->widget()); QMenu menu(e->widget());
// addDrawingAction(menu, new DotItem); addDrawingAction(menu, new DotItem);
addDrawingAction(menu, new LineItem);
// menu.addSeparator(); menu.addSeparator();
// QAction *bColorAction = new QAction; QAction *settings = new QAction;
// bColorAction->setText("Select brush color"); settings->setText("Settings");
// connect(bColorAction, &QAction::triggered, [&] { _brush.setColor(QColorDialog::getColor(_brush.color())); }); connect(settings, &QAction::triggered, [&] { BrushPenSelection(this).exec(); });
// QAction *pColorAction = new QAction; menu.addAction(settings);
// pColorAction->setText("Select pen color");
// connect(pColorAction, &QAction::triggered, [&] { _pen.setColor(QColorDialog::getColor(_pen.color())); });
// menu.addActions({ pColorAction, bColorAction });
// menu.exec(e->screenPos()); menu.exec(e->screenPos());
e->accept(); e->accept();
} }

View File

@ -16,8 +16,8 @@ class CropScene : public QGraphicsScene
Q_OBJECT Q_OBJECT
public: public:
CropScene(QObject *parent); CropScene(QObject *parent);
QPen pen(); QPen &pen();
QBrush brush(); QBrush &brush();
void setDrawingSelection(DrawItem *drawAction); void setDrawingSelection(DrawItem *drawAction);
signals: signals:

View File

@ -10,7 +10,7 @@ DotItem::~DotItem()
void DotItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) 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()); 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 *) void DotItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *)

View File

@ -0,0 +1,23 @@
#include "lineitem.hpp"
LineItem::LineItem()
{
}
LineItem::~LineItem()
{
delete path;
}
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *)
{
if (path == nullptr)
path = new QPainterPath(e->scenePos());
else
path->lineTo(e->scenePos());
}
void LineItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *scene)
{
scene->addPath(*path, scene->pen(), scene->brush());
}

View File

@ -0,0 +1,23 @@
#ifndef LINEITEM_HPP
#define LINEITEM_HPP
#include "../cropscene.hpp"
#include "drawitem.hpp"
class LineItem : public DrawItem
{
public:
LineItem();
~LineItem();
QString name()
{
return "Line";
}
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
private:
QPainterPath *path = nullptr;
};
#endif // LINEITEM_HPP

View File

@ -0,0 +1,59 @@
#include "brushpenselection.hpp"
#include "ui_brushpenselection.h"
#include <QCheckBox>
#include <QColorDialog>
#include <QDoubleSpinBox>
#include <QInputDialog>
#include <QSlider>
#include <cropeditor/cropview.hpp>
BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::BrushPenSelection)
{
ui->setupUi(this);
ui->cosmetic->setChecked(scene->pen().isCosmetic());
ui->widthSlider->setValue(scene->pen().width());
ui->widthSpinner->setValue(scene->pen().widthF());
pen = scene->pen().color();
brush = scene->brush().color();
this->scene = scene;
}
BrushPenSelection::~BrushPenSelection()
{
delete ui;
}
void BrushPenSelection::on_penColor_clicked(bool)
{
pen = QColorDialog::getColor(pen, this, "Pen Color");
}
void BrushPenSelection::on_brushColor_clicked(bool)
{
brush = QColorDialog::getColor(brush, this, "Brush Color");
}
void BrushPenSelection::on_buttonBox_accepted()
{
scene->pen().setColor(pen);
scene->pen().setCosmetic(ui->cosmetic->isChecked());
scene->pen().setWidthF(ui->widthSpinner->value());
scene->brush().setColor(brush);
close();
}
void BrushPenSelection::on_buttonBox_rejected()
{
close();
}
void BrushPenSelection::on_widthSlider_sliderMoved(int position)
{
ui->widthSpinner->setValue(position / 100.);
}
void BrushPenSelection::on_widthSpinner_valueChanged(double arg)
{
ui->widthSlider->setValue(arg * 100);
}

View File

@ -0,0 +1,36 @@
#ifndef BRUSHPENSELECTION_HPP
#define BRUSHPENSELECTION_HPP
#include <QDialog>
#include <cropeditor/cropscene.hpp>
namespace Ui
{
class BrushPenSelection;
}
class BrushPenSelection : public QDialog
{
Q_OBJECT
public:
explicit BrushPenSelection(CropScene *scene);
~BrushPenSelection();
private slots:
void on_penColor_clicked(bool);
void on_brushColor_clicked(bool);
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_widthSlider_sliderMoved(int position);
void on_widthSpinner_valueChanged(double arg1);
private:
Ui::BrushPenSelection *ui;
CropScene *scene;
QColor brush, pen;
};
#endif // BRUSHPENSELECTION_HPP

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BrushPenSelection</class>
<widget class="QDialog" name="BrushPenSelection">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>262</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="6" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QPushButton" name="penColor">
<property name="text">
<string>Choose pen color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSlider" name="widthSlider">
<property name="maximum">
<number>2500</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="9" column="0" colspan="3">
<widget class="QPushButton" name="brushColor">
<property name="text">
<string>Choose brush color</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Brush settings</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="cosmetic">
<property name="text">
<string>Cosmetic</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Pen settings</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QDoubleSpinBox" name="widthSpinner"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -37,7 +37,7 @@ void hotkeying::load(QString seqName, std::function<void()> func)
bool hotkeying::valid(QString seq) bool hotkeying::valid(QString seq)
{ {
return !QKeySequence(seq).toString().isEmpty(); return seq.isEmpty() || !QKeySequence(seq).toString().isEmpty();
} }
QString hotkeying::sequence(QString seqName) QString hotkeying::sequence(QString seqName)

View File

@ -50,6 +50,7 @@ int main(int argc, char *argv[])
verbose = parser.isSet(v); verbose = parser.isSet(v);
MainWindow w; MainWindow w;
if (!parser.isSet(h)) w.show(); w.show();
if (parser.isSet(h)) w.hide();
return a.exec(); return a.exec();
} }