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 \
notifications.cpp \
hotkeying.cpp \
cropeditor/drawing/dotitem.cpp
cropeditor/drawing/dotitem.cpp \
cropeditor/drawing/lineitem.cpp \
cropeditor/settings/brushpenselection.cpp
HEADERS += mainwindow.hpp \
cropeditor/cropeditor.hpp \
@ -58,9 +60,12 @@ HEADERS += mainwindow.hpp \
notifications.hpp \
hotkeying.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 += \
README.md \

View File

@ -7,6 +7,8 @@
#include <QMenu>
#include <QTimer>
#include <cropeditor/drawing/dotitem.hpp>
#include <cropeditor/drawing/lineitem.hpp>
#include <cropeditor/settings/brushpenselection.hpp>
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;
}
QBrush CropScene::brush()
QBrush &CropScene::brush()
{
return _brush;
}
@ -99,6 +101,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
if (drawingSelection != nullptr)
{
drawingSelection->mouseDragEndEvent(e, this);
delete drawingSelection;
drawingSelection = nullptr;
}
prevButtons = Qt::NoButton;
@ -113,27 +116,24 @@ 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); }); });
QObject::connect(action, &QAction::triggered, [this, item](bool) { setDrawingSelection(item); });
menu.addAction(action);
}
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();
// 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.addSeparator();
QAction *settings = new QAction;
settings->setText("Settings");
connect(settings, &QAction::triggered, [&] { BrushPenSelection(this).exec(); });
menu.addAction(settings);
// menu.exec(e->screenPos());
menu.exec(e->screenPos());
e->accept();
}

View File

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

View File

@ -10,7 +10,7 @@ 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());
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 *)

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)
{
return !QKeySequence(seq).toString().isEmpty();
return seq.isEmpty() || !QKeySequence(seq).toString().isEmpty();
}
QString hotkeying::sequence(QString seqName)

View File

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