Skip to content
Snippets Groups Projects
Commit 22549ca9 authored by BATON Theau's avatar BATON Theau
Browse files

Ajout de la selection par couleur

parent 09bc6d88
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ SOURCES += \
tools/editable/pixelpainter.cpp \
tools/hand.cpp \
tools/picker.cpp \
tools/selectionable/color.cpp \
tools/selectionable/ellipse.cpp \
tools/selectionable/polygone.cpp \
tools/selectionable/rectangle.cpp \
......@@ -58,6 +59,7 @@ HEADERS += \
tools/editable/pixelpainter.h \
tools/hand.h \
tools/picker.h \
tools/selectionable/color.h \
tools/selectionable/ellipse.h \
tools/selectionable/polygone.h \
tools/selectionable/rectangle.h \
......
......@@ -17,6 +17,9 @@
<iconset resource="../ressource.qrc">
<normaloff>:/icon/ressource/image/icon/icon.png</normaloff>:/icon/ressource/image/icon/icon.png</iconset>
</property>
<property name="modal">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="_titleLabel">
......
......@@ -24,6 +24,7 @@
#include <tools/selectionable/triangle.h>
#include <tools/selectionable/ellipse.h>
#include <tools/selectionable/polygone.h>
#include <tools/selectionable/color.h>
#include <tools/editable/pixelpainter.h>
#include <tools/editable/pixelEraiser.h>
......@@ -90,6 +91,7 @@ MainWindow::MainWindow(QWidget * parent)
this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Triangle(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION);
this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Ellipse(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION);
this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Polygone(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION);
this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Color(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION);
this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Pixelpainter(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::EDIT);
this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Pixeleraiser(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::EDIT);
......
......@@ -3,7 +3,7 @@
namespace tool {
Pixeleraiser::Pixeleraiser(const ColorPickerWidget & cp)
: Editable(cp, "Gomme", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-eraser.png")),
_config(new dialog::SizeDialog("Paramètre du crayon", "Taille du crayon", 1, 255, 4)), _leftButton(false), _rightButton(false) {
_config(new dialog::SizeDialog("Paramètre de la gomme", "Taille de la gomme", 1, 255, 4)), _leftButton(false), _rightButton(false) {
this->setCongigurationDialog(this->_config.get());
}
......
#include "color.h"
namespace tool {
Color::Color(const ColorPickerWidget & cp)
: Selectionable(cp, "Couleur", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/preferences-activities.png"), true),
_config(new dialog::SizeDialog("Paramètre de la séléction par couleur", "Proximité de la couleur", 0, 255, 0)),_lastClicked(-1,-1), _ctrl(false) {
this->setCongigurationDialog(this->_config.get());
}
void Color::onMousePressed(ui::ImageArea &, ui::Selection & s, const QPoint & c, const QImage & img, const QMouseEvent & e, const ColorPickerWidget &) {
if(!this->_ctrl || e.button() == Qt::RightButton) {
s.clear();
}
if(e.button() == Qt::LeftButton) {
this->_lastClicked = c;
QColor color = img.pixelColor(c);
int prox = this->_config->value();
for(int x = 0; x < img.width(); x++) {
for(int y = 0; y < img.height(); y++) {
QPoint p = QPoint(x, y);
if(img.rect().contains(p)) {
QColor iColor = img.pixelColor(p);
if(iColor.red() < (color.red() + prox) && iColor.red() >= (color.red() - prox)
&& iColor.green() < (color.green() + prox) && iColor.green() >= (color.green() - prox)
&& iColor.blue() < (color.blue() + prox) && iColor.blue() >= (color.blue() - prox)) {
s.select(p);
}
}
}
}
}
}
void Color::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &) {
}
void Color::onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &, bool) {
}
void Color::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e, const ColorPickerWidget &) {
if(e.key() == Qt::Key_Control) {
this->_ctrl = true;
}
}
void Color::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent & e, const ColorPickerWidget &) {
if(e.key() == Qt::Key_Control) {
this->_ctrl = false;
}
}
}
#pragma once
#include "../selectionnable.h"
#include <dialog/sizedialog.h>
namespace tool {
class Color : public Selectionable{
private:
QSharedPointer<dialog::SizeDialog> _config;
QPoint _lastClicked;
bool _ctrl;
public:
Color(const ColorPickerWidget &);
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &);
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &);
virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, const ColorPickerWidget &, bool);
virtual void onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &, const ColorPickerWidget &);
virtual void onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &, const ColorPickerWidget &);
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment