diff --git a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro index 0eb64a88267b3c61cb493dcd70ceef5cf38bb039..1f60245329692f203c5b4b26e73d6847a480c0e1 100644 --- a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro +++ b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro @@ -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 \ diff --git a/IHM_Retouche_Photo/dialog/sizedialog.ui b/IHM_Retouche_Photo/dialog/sizedialog.ui index 3d2cab25ba798f8f94f82f4ede9466a3857b425f..6ae5cc7c04902364d579ad71c835e9983ee03921 100644 --- a/IHM_Retouche_Photo/dialog/sizedialog.ui +++ b/IHM_Retouche_Photo/dialog/sizedialog.ui @@ -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"> diff --git a/IHM_Retouche_Photo/mainwindow.cpp b/IHM_Retouche_Photo/mainwindow.cpp index 74fb6cf0647fa2ab2bfc61f66cc3cac40db333f0..2f7e7f2b8fcdb98420d4b0df6e2ffb2b7b236d65 100644 --- a/IHM_Retouche_Photo/mainwindow.cpp +++ b/IHM_Retouche_Photo/mainwindow.cpp @@ -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); diff --git a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp index 8dea2baf71362472f917754a88243b3b27470ccf..3fb1ecdeb2beda4ffaa124a28893d227c71808fe 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp @@ -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()); } diff --git a/IHM_Retouche_Photo/tools/selectionable/color.cpp b/IHM_Retouche_Photo/tools/selectionable/color.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1057d8dbac837c1802d9edda1e3a35df732974fa --- /dev/null +++ b/IHM_Retouche_Photo/tools/selectionable/color.cpp @@ -0,0 +1,56 @@ +#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; + } + } +} diff --git a/IHM_Retouche_Photo/tools/selectionable/color.h b/IHM_Retouche_Photo/tools/selectionable/color.h new file mode 100644 index 0000000000000000000000000000000000000000..99a11ea725621ec94bba2eac9311091017a8cbd3 --- /dev/null +++ b/IHM_Retouche_Photo/tools/selectionable/color.h @@ -0,0 +1,24 @@ +#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 &); + }; +}