From 09bc6d888c0fba4fa38c009a2e7d21a7fa2fef9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9au?= <theau.baton@etu.univ-amu.fr> Date: Thu, 1 Feb 2024 23:41:59 +0100 Subject: [PATCH] Modification Pixelpainter en Brush, Pixeleraiser en Eraiser --- IHM_Retouche_Photo/IHM_Retouche_Photo.pro | 5 + IHM_Retouche_Photo/colorpickerwidget.cpp | 10 +- IHM_Retouche_Photo/colorpickerwidget.h | 5 +- IHM_Retouche_Photo/dialog/sizedialog.cpp | 26 ++++ IHM_Retouche_Photo/dialog/sizedialog.h | 26 ++++ IHM_Retouche_Photo/dialog/sizedialog.ui | 125 ++++++++++++++++++ IHM_Retouche_Photo/mainwindow.cpp | 37 ++++-- IHM_Retouche_Photo/mainwindow.ui | 79 +++++++---- IHM_Retouche_Photo/ressource.qrc | 1 + .../oxygen/icons/16x16/draw-unselect.png | Bin 0 -> 492 bytes IHM_Retouche_Photo/tools/editable.cpp | 2 +- IHM_Retouche_Photo/tools/editable/brush.cpp | 77 +++++++++++ .../tools/editable/pixelEraiser.cpp | 95 ++++++++++--- .../tools/editable/pixelEraiser.h | 3 + .../tools/editable/pixelpainter.cpp | 61 +++++++-- .../tools/editable/pixelpainter.h | 3 + IHM_Retouche_Photo/tools/tool.cpp | 8 +- IHM_Retouche_Photo/tools/tool.h | 10 +- IHM_Retouche_Photo/ui/menu/filemenulambda.cpp | 2 + .../ui/menu/selectionmenulambda.cpp | 20 +++ .../ui/menu/selectionmenulambda.h | 28 ++++ .../ui/toolbox/toolRegister.cpp | 45 +++++-- IHM_Retouche_Photo/ui/toolbox/toolRegister.h | 21 ++- IHM_Retouche_Photo/ui/view/imagearea.cpp | 8 +- IHM_Retouche_Photo/ui/view/imagearea.h | 2 + IHM_Retouche_Photo/ui/view/selection.h | 4 +- IHM_Retouche_Photo/ui/view/viewmanager.cpp | 18 +++ 27 files changed, 624 insertions(+), 97 deletions(-) create mode 100644 IHM_Retouche_Photo/dialog/sizedialog.cpp create mode 100644 IHM_Retouche_Photo/dialog/sizedialog.h create mode 100644 IHM_Retouche_Photo/dialog/sizedialog.ui create mode 100644 IHM_Retouche_Photo/ressource/image/oxygen/icons/16x16/draw-unselect.png create mode 100644 IHM_Retouche_Photo/tools/editable/brush.cpp create mode 100644 IHM_Retouche_Photo/ui/menu/selectionmenulambda.cpp create mode 100644 IHM_Retouche_Photo/ui/menu/selectionmenulambda.h diff --git a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro index 347621d..0eb64a8 100644 --- a/IHM_Retouche_Photo/IHM_Retouche_Photo.pro +++ b/IHM_Retouche_Photo/IHM_Retouche_Photo.pro @@ -12,6 +12,7 @@ SOURCES += \ colorpickerwidget.cpp \ dialog/rescaledialog.cpp \ dialog/resizedialog.cpp \ + dialog/sizedialog.cpp \ main.cpp \ mainwindow.cpp \ tools/editable.cpp \ @@ -35,6 +36,7 @@ SOURCES += \ ui/menu/filemenulambda.cpp \ ui/menu/imagemenulambda.cpp \ ui/menu/menubarmanager.cpp \ + ui/menu/selectionmenulambda.cpp \ ui/toolbox/toolRegister.cpp \ ui/view/imagearea.cpp \ ui/view/multyimagemodifier.cpp \ @@ -48,6 +50,7 @@ HEADERS += \ colorpickerwidget.h \ dialog/rescaledialog.h \ dialog/resizedialog.h \ + dialog/sizedialog.h \ mainwindow.h \ tools/editable.h \ tools/editable/bucket.h \ @@ -71,6 +74,7 @@ HEADERS += \ ui/menu/filemenulambda.h \ ui/menu/imagemenulambda.h \ ui/menu/menubarmanager.h \ + ui/menu/selectionmenulambda.h \ ui/toolbox/toolRegister.h \ ui/view/imagearea.h \ ui/view/multyimagemodifier.h \ @@ -84,6 +88,7 @@ HEADERS += \ FORMS += \ dialog/rescaledialog.ui \ dialog/resizedialog.ui \ + dialog/sizedialog.ui \ mainwindow.ui # Default rules for deployment. diff --git a/IHM_Retouche_Photo/colorpickerwidget.cpp b/IHM_Retouche_Photo/colorpickerwidget.cpp index 1853201..6911f48 100644 --- a/IHM_Retouche_Photo/colorpickerwidget.cpp +++ b/IHM_Retouche_Photo/colorpickerwidget.cpp @@ -15,7 +15,7 @@ ColorPickerWidget::ColorPickerWidget(QWidget *parent) this->_colorListWidget = new QListWidget(this); this->_mainLayout->addWidget(this->_colorListWidget); - this->_currentColorLayout = new QHBoxLayout(this); + this->_currentColorLayout = new QHBoxLayout(); this->_currentColorLabel = new QLabel("Couleur courrante :", this); this->_currentColorLayout->addWidget(this->_currentColorLabel); @@ -58,7 +58,6 @@ ColorPickerWidget::ColorPickerWidget(QWidget *parent) } ColorPickerWidget::~ColorPickerWidget() { - delete this->_mainLayout; delete this->_colorListWidget; delete this->_currentColorLayout; delete this->_currentColorLabel; @@ -67,6 +66,7 @@ ColorPickerWidget::~ColorPickerWidget() { delete this->_modifyColorButton; delete this->_chooseColorButton; delete this->_duplicateColorButton; + delete this->_mainLayout; } void ColorPickerWidget::setCurrentColor(const QColor & color) { @@ -124,11 +124,12 @@ void ColorPickerWidget::modifyColor() { void ColorPickerWidget::modifyColor(QListWidgetItem* item) { QListWidgetItem * selectedItem = item; if(selectedItem) { - QColor color = QColorDialog::getColor(selectedItem->background().color(), this, "Modification de l'iamge"); + QColor color = QColorDialog::getColor(selectedItem->background().color(), this, "Modification de l'image"); if (color.isValid()) { selectedItem->setBackground(QBrush(color)); this->_currentColor = color; this->setFrameColor(color); + emit this->currentColorChange(this->_currentColor); } } } @@ -136,12 +137,15 @@ void ColorPickerWidget::modifyColor(QListWidgetItem* item) { void ColorPickerWidget::chooseColor() { this->_currentColor = this->_colorListWidget->currentItem()->background().color(); this->setFrameColor(this->_currentColor); + emit this->currentColorChange(this->_currentColor); this->close(); } void ColorPickerWidget::chooseColor(QListWidgetItem * item) { this->_currentColor = item->background().color(); this->setFrameColor(this->_currentColor); + emit this->currentColorChange(this->_currentColor); + qDebug() << "Color Selected !" << this->_currentColor; } void ColorPickerWidget::duplicateCurrent() { diff --git a/IHM_Retouche_Photo/colorpickerwidget.h b/IHM_Retouche_Photo/colorpickerwidget.h index faec6fa..4d122bd 100644 --- a/IHM_Retouche_Photo/colorpickerwidget.h +++ b/IHM_Retouche_Photo/colorpickerwidget.h @@ -33,7 +33,7 @@ class ColorPickerWidget : public QWidget { ColorPickerWidget(QWidget *parent = nullptr); ~ColorPickerWidget(); - inline const QColor & currentColor() const {return this->_currentColor;} + inline QColor currentColor() const {return this->_currentColor;} void setCurrentColor(const QColor &); @@ -49,4 +49,7 @@ class ColorPickerWidget : public QWidget { void chooseColor(QListWidgetItem*); void duplicateCurrent(); + + signals: + void currentColorChange(const QColor &); }; diff --git a/IHM_Retouche_Photo/dialog/sizedialog.cpp b/IHM_Retouche_Photo/dialog/sizedialog.cpp new file mode 100644 index 0000000..83049c9 --- /dev/null +++ b/IHM_Retouche_Photo/dialog/sizedialog.cpp @@ -0,0 +1,26 @@ +#include "sizedialog.h" + +namespace dialog { + SizeDialog::SizeDialog(QString title, QString titleLabel , int min, int max, int def, QWidget *parent) + : QDialog(parent) { + this->setupUi(this); + this->_titleLabel->setText(titleLabel); + this->_sizeLabel->setText(QString::number(def)); + this->_sizeSlidder->setMinimum(min); + this->_sizeSlidder->setMaximum(max); + this->_sizeSlidder->setValue(def); + this->setWindowTitle(title); + + QObject::connect(this->_sizeSlidder, SIGNAL(valueChanged(int)), this, SLOT(updateSizeLabel(int))); + } + + void SizeDialog::setValue(int value) { + this->_sizeSlidder->setValue(value); + this->_sizeLabel->setText(QString::number(value)); + } + + void SizeDialog::updateSizeLabel(int value) { + this->_sizeLabel->setText(QString::number(value)); + } +} + diff --git a/IHM_Retouche_Photo/dialog/sizedialog.h b/IHM_Retouche_Photo/dialog/sizedialog.h new file mode 100644 index 0000000..74ba841 --- /dev/null +++ b/IHM_Retouche_Photo/dialog/sizedialog.h @@ -0,0 +1,26 @@ +#pragma once + +#include <QDialog> +#include <ui_sizedialog.h> +namespace dialog { + class SizeDialog : public QDialog, public Ui::SizeDialog { + Q_OBJECT + public: + explicit SizeDialog(QString title, QString titleLabel, int min, int max, int def = 0, QWidget *parent = nullptr); + + inline int min() const {return this->_sizeSlidder->minimum();} + inline int max() const {return this->_sizeSlidder->maximum();} + inline int value() const {return this->_sizeSlidder->value();} + + inline void setTitleLabelText(const QString & text) {this->_titleLabel->setText(text);} + inline void setSlitderLabelText(const QString & text) {this->_sizeLabel->setText(text);} + + inline void setMax(int max) {this->_sizeSlidder->setMaximum(max);} + inline void setMin(int min) {this->_sizeSlidder->setMaximum(min);} + + void setValue(int); + + protected slots: + void updateSizeLabel(int); + }; +} diff --git a/IHM_Retouche_Photo/dialog/sizedialog.ui b/IHM_Retouche_Photo/dialog/sizedialog.ui new file mode 100644 index 0000000..3d2cab2 --- /dev/null +++ b/IHM_Retouche_Photo/dialog/sizedialog.ui @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SizeDialog</class> + <widget class="QDialog" name="SizeDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>427</width> + <height>98</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <property name="windowIcon"> + <iconset resource="../ressource.qrc"> + <normaloff>:/icon/ressource/image/icon/icon.png</normaloff>:/icon/ressource/image/icon/icon.png</iconset> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="_titleLabel"> + <property name="text"> + <string>Current Size :</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="_sizeArea"> + <item> + <spacer name="_sizeLeftSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Minimum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QSlider" name="_sizeSlidder"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="_sizeLabel"> + <property name="text"> + <string>1</string> + </property> + </widget> + </item> + <item> + <spacer name="_sizeRightSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Minimum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="_exitArea"> + <item> + <spacer name="_exitSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="_exitButton"> + <property name="text"> + <string>Fermer</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources> + <include location="../ressource.qrc"/> + </resources> + <connections> + <connection> + <sender>_exitButton</sender> + <signal>released()</signal> + <receiver>SizeDialog</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel"> + <x>357</x> + <y>83</y> + </hint> + <hint type="destinationlabel"> + <x>300</x> + <y>90</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/IHM_Retouche_Photo/mainwindow.cpp b/IHM_Retouche_Photo/mainwindow.cpp index 42ca3e3..74fb6cf 100644 --- a/IHM_Retouche_Photo/mainwindow.cpp +++ b/IHM_Retouche_Photo/mainwindow.cpp @@ -12,6 +12,7 @@ #include <ui/menu/filemenulambda.h> #include <ui/menu/displaymenulambda.h> #include <ui/menu/imagemenulambda.h> +#include <ui/menu/selectionmenulambda.h> #include <ui/files/treefileselector.h> @@ -78,21 +79,27 @@ MainWindow::MainWindow(QWidget * parent) QObject::connect(this->_resizeButton, SIGNAL(released()), this->_resizeDialog, SLOT(use())); qDebug() << "Mark_6"; + + this->_toolRegister = new ui::ToolboxRegister(this->_selectionToolbox, this->_editToolbox, this->_viewManager, this->_toolConfigButton); - this->_toolRegister = new ui::ToolboxRegister(this->_toolConfigButton, this->_toolbox, this->_viewManager); + this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Hand(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); + this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Picker(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::EDIT); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Hand(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Picker(this->colorPickerWidget))); + this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Rectangle(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); + this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::RectangleTriangle(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::SELECTION); + 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->push_back(QSharedPointer<tool::Tool>(new tool::Rectangle(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::RectangleTriangle(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Triangle(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Ellipse(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Polygone(this->colorPickerWidget))); + 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); + this->_toolRegister->add(QSharedPointer<tool::Tool>(new tool::Bucket(this->colorPickerWidget)), ui::ToolboxRegister::ToolType::EDIT); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Pixelpainter(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Pixeleraiser(this->colorPickerWidget))); - this->_toolRegister->push_back(QSharedPointer<tool::Tool>(new tool::Bucket(this->colorPickerWidget))); + qDebug() << "Mark_6.1"; + + + + qDebug() << "Mark_6.2"; this->_toolRegister->update(); @@ -101,10 +108,11 @@ MainWindow::MainWindow(QWidget * parent) this->_menubarManager.insert(this->_menuFile, QSharedPointer<ui::MenuLambda>(new ui::FilemenuLambda(this->_fileselectorManager, this->_viewManager))); this->_menubarManager.insert(this->_menuAffichage, QSharedPointer<ui::MenuLambda>(new ui::DisplayMenuLambda(this->_viewManager))); this->_menubarManager.insert(this->_menuImage, QSharedPointer<ui::MenuLambda>(new ui::imagemenulambda(this->_rescaleDialog, this->_resizeDialog, this->_viewManager))); + this->_menubarManager.insert(this->_menuSelection, QSharedPointer<ui::MenuLambda>(new ui::SelectionMenuLambda(this->_viewManager))); this->_menubarManager.update(); - qDebug() << "Mark_7"; + qDebug() << "Mark_8"; _actionNoirEtBlanc = new QAction(QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/color-picker-black.png"), "Convertir en Noir et Blanc", this); toolBarLeft->addAction(_actionNoirEtBlanc); @@ -115,6 +123,7 @@ MainWindow::MainWindow(QWidget * parent) toolBarLeft->addAction(_actionAdjustBrightnessContrast); connect(_actionAdjustBrightnessContrast, &QAction::triggered, this, &MainWindow::adjustBrightnessContrastActionTriggered); + qDebug() << "Mark_9"; _actionAdjustBrightness = new QAction("Augmenter la luminosité", this); toolBarLeft->addAction(_actionAdjustBrightness); @@ -126,6 +135,8 @@ MainWindow::MainWindow(QWidget * parent) _actionDecreaseBrightness->setVisible(false); connect(_actionDecreaseBrightness, &QAction::triggered, this, &MainWindow::decreaseBrightnessActionTriggered); + qDebug() << "Mark_10"; + _actionIncreaseContrast = new QAction("Augmenter le contraste", this); toolBarLeft->addAction(_actionIncreaseContrast); _actionIncreaseContrast->setVisible(false); @@ -136,7 +147,7 @@ MainWindow::MainWindow(QWidget * parent) _actionDecreaseContrast->setVisible(false); connect(_actionDecreaseContrast, &QAction::triggered, this, &MainWindow::decreaseContrastActionTriggered); - qDebug() << "Mark_8"; + qDebug() << "Mark_11"; } void MainWindow::dragEnterEvent(QDragEnterEvent *e) { diff --git a/IHM_Retouche_Photo/mainwindow.ui b/IHM_Retouche_Photo/mainwindow.ui index 895df07..20d9189 100644 --- a/IHM_Retouche_Photo/mainwindow.ui +++ b/IHM_Retouche_Photo/mainwindow.ui @@ -6,12 +6,12 @@ <rect> <x>0</x> <y>0</y> - <width>998</width> - <height>698</height> + <width>983</width> + <height>882</height> </rect> </property> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> + <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -137,7 +137,7 @@ <item> <widget class="QLabel" name="_cuurentFilesLabel"> <property name="text"> - <string>Fichiers Courrant :</string> + <string>Fichiers Courant :</string> </property> </widget> </item> @@ -470,14 +470,14 @@ <number>6</number> </property> <item> - <widget class="QLabel" name="_toolLabel"> + <widget class="QLabel" name="_selectionToolLabel"> <property name="text"> - <string>Outils :</string> + <string>Outils de selection :</string> </property> </widget> </item> <item> - <widget class="QListWidget" name="_toolbox"> + <widget class="QListWidget" name="_selectionToolbox"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> <horstretch>0</horstretch> @@ -513,6 +513,32 @@ </property> </widget> </item> + <item> + <widget class="QLabel" name="_editLabel"> + <property name="text"> + <string>Outils d'édition :</string> + </property> + </widget> + </item> + <item> + <widget class="QListWidget" name="_editToolbox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="tabKeyNavigation"> + <bool>true</bool> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + </widget> + </item> <item> <widget class="QPushButton" name="_toolConfigButton"> <property name="statusTip"> @@ -622,7 +648,7 @@ <rect> <x>0</x> <y>0</y> - <width>998</width> + <width>983</width> <height>21</height> </rect> </property> @@ -695,6 +721,7 @@ <string>Selection</string> </property> <addaction name="_action_del"/> + <addaction name="_action_unselect"/> </widget> <addaction name="_menuFile"/> <addaction name="_menuSelection"/> @@ -731,17 +758,6 @@ <addaction name="_action_turn_verticaly"/> <addaction name="_action_turn_horizonaly"/> </widget> - <widget class="QToolBar" name="toolBarRight"> - <property name="windowTitle"> - <string>toolBar_2</string> - </property> - <attribute name="toolBarArea"> - <enum>RightToolBarArea</enum> - </attribute> - <attribute name="toolBarBreak"> - <bool>false</bool> - </attribute> - </widget> <action name="_action_new"> <property name="icon"> <iconset resource="ressource.qrc"> @@ -1049,7 +1065,7 @@ <string>Redimensionne l'image.</string> </property> <property name="shortcut"> - <string>Ctrl+R</string> + <string>Ctrl+Shift+R</string> </property> </action> <action name="_action_rezise_draw_area"> @@ -1102,9 +1118,6 @@ <property name="statusTip"> <string>Effectue une rotation, vers la gauche, de l'image à 90 degrées.</string> </property> - <property name="shortcut"> - <string>Ctrl+G</string> - </property> </action> <action name="_action_rotate_right_90"> <property name="icon"> @@ -1117,9 +1130,6 @@ <property name="statusTip"> <string>Effectue une rotation, vers la droite, de l'image à 90 degrées.</string> </property> - <property name="shortcut"> - <string>Ctrl+H</string> - </property> </action> <action name="_action_rotate_180"> <property name="icon"> @@ -1148,6 +1158,21 @@ <string>Ctrl+Shift+O</string> </property> </action> + <action name="_action_unselect"> + <property name="icon"> + <iconset resource="ressource.qrc"> + <normaloff>:/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-unselect.png</normaloff>:/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-unselect.png</iconset> + </property> + <property name="text"> + <string>Déselectionner</string> + </property> + <property name="statusTip"> + <string>Déselectionne la selection courrante</string> + </property> + <property name="shortcut"> + <string>Ctrl+D</string> + </property> + </action> </widget> <tabstops> <tabstop>_filesSelector</tabstop> @@ -1157,7 +1182,7 @@ <tabstop>_colorPicker</tabstop> <tabstop>_rescaleButton</tabstop> <tabstop>_resizeButton</tabstop> - <tabstop>_toolbox</tabstop> + <tabstop>_selectionToolbox</tabstop> <tabstop>_toolConfigButton</tabstop> <tabstop>_emitDrawCheckbox</tabstop> <tabstop>_receiveDrawCheckbox</tabstop> diff --git a/IHM_Retouche_Photo/ressource.qrc b/IHM_Retouche_Photo/ressource.qrc index c596b96..e3b8300 100644 --- a/IHM_Retouche_Photo/ressource.qrc +++ b/IHM_Retouche_Photo/ressource.qrc @@ -416,6 +416,7 @@ <file>ressource/image/oxygen/icons/16x16/zoom-select.png</file> <file>ressource/image/oxygen/icons/16x16/align-none.png</file> <file>ressource/image/oxygen/icons/16x16/actions-fill-color-icon.png</file> + <file>ressource/image/oxygen/icons/16x16/draw-unselect.png</file> </qresource> <qresource prefix="/stylesheet"/> <qresource prefix="/oxygen/64x64"> diff --git a/IHM_Retouche_Photo/ressource/image/oxygen/icons/16x16/draw-unselect.png b/IHM_Retouche_Photo/ressource/image/oxygen/icons/16x16/draw-unselect.png new file mode 100644 index 0000000000000000000000000000000000000000..232986a5499658e0f98e84bedbd20d74ffbbe622 GIT binary patch literal 492 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=<CS9u(6-}Pa-P=0|RG)M`SSr1LH0bW_+=lk&S_YvC-4TF~q`uZO~aSrbLmw_x}iZ zCNyz0&c3xJ<RE*&;*0mxKNv>+unJnpzu*S<5(UoO=&P$-)0|8`pDj6G`p$&!+A8Mb zulE+8oB6wz=Wpwb6(?nk`zKFis5Q!0Tm09<#qjeyO~n<S{XZjG_A9Ep*`EDsJ^L-I zi{$0-py161&)57D5aDW{_fYTI@kl8-xji<QZ$4$6Y0zSmFmLl0&R!Os>HURUs}3b8 zWh)!HUEH?owW;Xt*iT~IUAF$tX=lt%-<K&-<hQMRVWD?<;`T+qX8UIGWtm3B++QWR z-Tt7V%7G|tHdF2XDqF+$uU32c*tV<;QOGwoeWJ#DfNkCGyAD5Zz7M{Tb@6wB$Fh(~ zz8lS=1&k8oJQ>bq_b4+;HSy*wc9dT%s2?>&vV_5DhU_yRrU>mT3<3QcS+lnNZ)8!3 z%{FskT>N;(+?h^uez`G}Km1+iwRd*S3ME@7ftI3~J2d__n1tAC-8JD3^jTiMEk@6} ul37o;>&yP7SF=RRta9UB{xdJiza_Nq`<h)s=NT9n7(8A5T-G@yGywqZZ^jw` literal 0 HcmV?d00001 diff --git a/IHM_Retouche_Photo/tools/editable.cpp b/IHM_Retouche_Photo/tools/editable.cpp index 1f12669..37aab19 100644 --- a/IHM_Retouche_Photo/tools/editable.cpp +++ b/IHM_Retouche_Photo/tools/editable.cpp @@ -1,7 +1,7 @@ #include "editable.h" namespace tool { - Editable::Editable(const ColorPickerWidget & cp, const QString & name, const QIcon & icon,bool free) + Editable::Editable(const ColorPickerWidget & cp, const QString & name, const QIcon & icon, bool free) : Tool(name, icon), _colorPicker(&cp), _free(free) {} void Editable::onKeyPress(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QKeyEvent &, const ColorPickerWidget &) {} diff --git a/IHM_Retouche_Photo/tools/editable/brush.cpp b/IHM_Retouche_Photo/tools/editable/brush.cpp new file mode 100644 index 0000000..5d68ed5 --- /dev/null +++ b/IHM_Retouche_Photo/tools/editable/brush.cpp @@ -0,0 +1,77 @@ +#include "Brush.h" + +#include "../../dialog/sizedialog.h" + +namespace tool { + Brush::Brush(const ColorPickerWidget & cp) + : Editable(cp, "Brosse", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/document-sign.png")), + _config(new dialog::SizeDialog("Paramètre de la Brosse", "Taille de la brosse", 1, 255, 4)) { + this->setCongigurationDialog(this->_config.get()); + QObject::connect(&cp, SIGNAL(currentColorChange(QColor)), this, SLOT(changeColor(QColor))); + } + + void Brush::onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e, const ColorPickerWidget & cp) { + if(e.button() == Qt::LeftButton) { + this->_leftButton = true; + } + } + + void Brush::onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e, const ColorPickerWidget &) { + if(e.button() == Qt::LeftButton) { + this->_leftButton = false; + } + } + + void Brush::onMouseMoved(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget & cp, bool hold) { + if(this->_leftButton && hold) { + int cx = c.x(); + int cy = c.y(); + + int size = this->_config->value(); + + QColor color = cp.currentColor(); + + if(color.isValid()) { + for(int i = 0; i < size; i++) { + int dx = i - size / 2; + int x = cx + dx; + + int h = qRound(size * qSqrt(size * size / 4.0 - dx * dx) /size); + for(int dy = 1; dy < h; dy++) { + QPoint p(x, cy + dy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + area.setColor(p, color); + } + else { + area.setColor(p, color); + } + } + + p = QPoint(x, cy - dy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + area.setColor(p, color); + } + else { + area.setColor(p, color); + } + } + } + + if(h >= 0) { + QPoint p(x, cy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + area.setColor(p, color); + } + else { + area.setColor(p, color); + } + } + } + } + } + } + } +} diff --git a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp index 2b487a2..8dea2ba 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelEraiser.cpp @@ -2,7 +2,10 @@ namespace tool { Pixeleraiser::Pixeleraiser(const ColorPickerWidget & cp) - : Editable(cp, "Gomme Pixel", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-eraser.png")), _leftButton(false), _rightButton(false) {} + : 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) { + this->setCongigurationDialog(this->_config.get()); + } void Pixeleraiser::onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e, const ColorPickerWidget &) { if(e.button() == Qt::LeftButton) { @@ -24,21 +27,81 @@ namespace tool { } } - void Pixeleraiser::onMouseMoved(ui::ImageArea & a, QImage &, const QPoint & p, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget &, bool hold) { - if(hold && this->_leftButton) { - if(s.empty()) { - a.setColor(p, QColor(0, 0, 0, 0)); - } - else if(s.contain(p)) { - a.setColor(p, QColor(0, 0, 0, 0)); - } - } - else if(hold && this->_rightButton) { - if(s.empty()) { - a.setColor(p, QColorConstants::White); - } - else if(s.contain(p)) { - a.setColor(p, QColorConstants::White); + void Pixeleraiser::onMouseMoved(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget & cp, bool hold) { + if(hold) { + int cx = c.x(); + int cy = c.y(); + + int size = this->_config->value(); + + for(int i = 0; i < size; i++) { + int dx = i - size / 2; + int x = cx + dx; + + int h = qRound(size * qSqrt(size * size / 4.0 - dx * dx) /size); + for(int dy = 1; dy < h; dy++) { + QPoint p(x, cy + dy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + if(this->_leftButton) { + area.setColor(p, QColor(0, 0, 0, 0)); + } + else if(this->_rightButton) { + area.setColor(p ,QColorConstants::White); + } + } + else { + if(this->_leftButton) { + area.setColor(p, QColor(0, 0, 0, 0)); + } + else if(this->_rightButton) { + area.setColor(p ,QColorConstants::White); + } + } + } + + p = QPoint(x, cy - dy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + if(this->_leftButton) { + area.setColor(p, QColor(0, 0, 0, 0)); + } + else if(this->_rightButton) { + area.setColor(p ,QColorConstants::White); + } + } + else { + if(this->_leftButton) { + area.setColor(p, QColor(0, 0, 0, 0)); + } + else if(this->_rightButton) { + area.setColor(p ,QColorConstants::White); + } + } + } + } + + if(h >= 0) { + QPoint p(x, cy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + if(this->_leftButton) { + area.setColor(p, QColor(0, 0, 0, 0)); + } + else if(this->_rightButton) { + area.setColor(p ,QColorConstants::White); + } + } + else { + if(this->_leftButton) { + area.setColor(p, QColor(0, 0, 0, 0)); + } + else if(this->_rightButton) { + area.setColor(p ,QColorConstants::White); + } + } + } + } } } } diff --git a/IHM_Retouche_Photo/tools/editable/pixelEraiser.h b/IHM_Retouche_Photo/tools/editable/pixelEraiser.h index 2ece08c..84be3b9 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelEraiser.h +++ b/IHM_Retouche_Photo/tools/editable/pixelEraiser.h @@ -2,9 +2,12 @@ #include "../editable.h" +#include <dialog/sizedialog.h> + namespace tool { class Pixeleraiser : public Editable { private: + QSharedPointer<dialog::SizeDialog> _config; bool _leftButton; bool _rightButton; diff --git a/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp b/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp index 4d96ffb..1dfcff5 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp +++ b/IHM_Retouche_Photo/tools/editable/pixelpainter.cpp @@ -2,7 +2,10 @@ namespace tool { Pixelpainter::Pixelpainter(const ColorPickerWidget & cp) - : Editable(cp, "Crayon Pixel", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-freehand.png")), _leftButton(false) {} + : Editable(cp, "Crayon", QIcon(":/oxygen/16x16/ressource/image/oxygen/icons/16x16/draw-freehand.png")), + _config(new dialog::SizeDialog("Paramètre du crayon", "Taille du crayon", 1, 255, 4)), _leftButton(false) { + this->setCongigurationDialog(this->_config.get()); + } void Pixelpainter::onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e, const ColorPickerWidget &) { if(e.button() == Qt::LeftButton) { @@ -16,13 +19,55 @@ namespace tool { } } - void Pixelpainter::onMouseMoved(ui::ImageArea & a, QImage &, const QPoint & p, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget & cp, bool hold) { - if(hold && this->_leftButton) { - if(s.empty()) { - a.setColor(p, cp.currentColor()); - } - else if(s.contain(p)) { - a.setColor(p, cp.currentColor()); + void Pixelpainter::onMouseMoved(ui::ImageArea & area, QImage & img, const QPoint & c, const ui::Selection & s, const QMouseEvent &, const ColorPickerWidget & cp, bool hold) { + if(this->_leftButton && hold) { + int cx = c.x(); + int cy = c.y(); + + int size = this->_config->value(); + + QColor color = cp.currentColor(); + + if(color.isValid()) { + for(int i = 0; i < size; i++) { + int dx = i - size / 2; + int x = cx + dx; + + int h = qRound(size * qSqrt(size * size / 4.0 - dx * dx) /size); + for(int dy = 1; dy < h; dy++) { + QPoint p(x, cy + dy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + area.setColor(p, color); + } + else { + area.setColor(p, color); + } + } + + p = QPoint(x, cy - dy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + area.setColor(p, color); + } + else { + area.setColor(p, color); + } + } + } + + if(h >= 0) { + QPoint p(x, cy); + if(img.rect().contains(p)) { + if(!s.empty() && s.contain(p)) { + area.setColor(p, color); + } + else { + area.setColor(p, color); + } + } + } + } } } } diff --git a/IHM_Retouche_Photo/tools/editable/pixelpainter.h b/IHM_Retouche_Photo/tools/editable/pixelpainter.h index 0ecdbc8..33a1572 100644 --- a/IHM_Retouche_Photo/tools/editable/pixelpainter.h +++ b/IHM_Retouche_Photo/tools/editable/pixelpainter.h @@ -2,9 +2,12 @@ #include "../editable.h" +#include <dialog/sizedialog.h> + namespace tool { class Pixelpainter : public Editable { private: + QSharedPointer<dialog::SizeDialog> _config; bool _leftButton; public: diff --git a/IHM_Retouche_Photo/tools/tool.cpp b/IHM_Retouche_Photo/tools/tool.cpp index 7156835..f1d8d87 100644 --- a/IHM_Retouche_Photo/tools/tool.cpp +++ b/IHM_Retouche_Photo/tools/tool.cpp @@ -1,15 +1,15 @@ #include "tool.h" namespace tool { - Tool::Tool(const QString & name, const QIcon & icon, QSharedPointer<QDialog> configDialog) - : QListWidgetItem(), _configurationDialog(configDialog) { + Tool::Tool(const QString & name, const QIcon & icon) + : QListWidgetItem(), _configurationDialog(nullptr) { this->setText(name); this->setIcon(icon); } void Tool::showConfiguration() { - if(!this->_configurationDialog.isNull()) { - this->_configurationDialog.get()->exec(); + if(this->_configurationDialog != nullptr) { + this->_configurationDialog->exec(); } } } diff --git a/IHM_Retouche_Photo/tools/tool.h b/IHM_Retouche_Photo/tools/tool.h index 37c5172..8917e0f 100644 --- a/IHM_Retouche_Photo/tools/tool.h +++ b/IHM_Retouche_Photo/tools/tool.h @@ -11,15 +11,17 @@ namespace tool { class Tool : public QObject, public QListWidgetItem { Q_OBJECT private: - QSharedPointer<QDialog> _configurationDialog; + QDialog * _configurationDialog; public: - Tool(const QString &, const QIcon &, QSharedPointer<QDialog> = nullptr); + Tool(const QString &, const QIcon &); virtual inline Qt::CursorShape shape() const {return Qt::CursorShape::ArrowCursor;} - inline bool HaveConfigurationDialog() const {return !this->_configurationDialog.isNull();} - inline QDialog * configurationDialog() const {return this->_configurationDialog.get();} + inline bool HaveConfigurationDialog() const {return this->_configurationDialog != nullptr;} + inline QDialog * configurationDialog() const {return this->_configurationDialog;} + + inline void setCongigurationDialog(QDialog * dial) {this->_configurationDialog = dial;} public slots: virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0; diff --git a/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp b/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp index 6bd0f14..3ace62a 100644 --- a/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp +++ b/IHM_Retouche_Photo/ui/menu/filemenulambda.cpp @@ -17,5 +17,7 @@ namespace ui { QObject::connect(menu->actions().at(Actions::SAVE), SIGNAL(triggered()), this->_viewManager, SLOT(saveCurrentView())); QObject::connect(menu->actions().at(Actions::SAVE_AS), SIGNAL(triggered()), this->_viewManager, SLOT(saveAsCurrentView())); QObject::connect(menu->actions().at(Actions::NEW), SIGNAL(triggered()), this->_viewManager, SLOT(newView())); + + QObject::connect(menu->actions().at(Actions::CLOSE), SIGNAL(triggered()), this->_viewManager, SLOT(deleteCurrentView())); } } diff --git a/IHM_Retouche_Photo/ui/menu/selectionmenulambda.cpp b/IHM_Retouche_Photo/ui/menu/selectionmenulambda.cpp new file mode 100644 index 0000000..e8df4b6 --- /dev/null +++ b/IHM_Retouche_Photo/ui/menu/selectionmenulambda.cpp @@ -0,0 +1,20 @@ +#include "selectionmenulambda.h" + +namespace ui { + SelectionMenuLambda::SelectionMenuLambda(ViewManager * manager) + : _menu(nullptr), _manager(manager) { + + } + + void SelectionMenuLambda::initializeMenu(const QMenu * menu) { + this->_menu = menu; + QObject::connect(this->_manager, SIGNAL(changedView(ImageArea*)), this, SLOT(viewChanged(ImageArea*))); + } + + void SelectionMenuLambda::viewChanged(ImageArea * area) { + if(area != nullptr && this->_menu != nullptr) { + QObject::connect(this->_menu->actions().at(Actions::SUPPR), SIGNAL(triggered()), area, SLOT(deleteCurrentSelection())); + QObject::connect(this->_menu->actions().at(Actions::UNSELECT), SIGNAL(triggered()), &area->selection(), SLOT(clear())); + } + } +} diff --git a/IHM_Retouche_Photo/ui/menu/selectionmenulambda.h b/IHM_Retouche_Photo/ui/menu/selectionmenulambda.h new file mode 100644 index 0000000..787433f --- /dev/null +++ b/IHM_Retouche_Photo/ui/menu/selectionmenulambda.h @@ -0,0 +1,28 @@ +#pragma once + +#include "menubarmanager.h" + +#include "../view/viewmanager.h" + +namespace ui { + class SelectionMenuLambda : public MenuLambda { + Q_OBJECT + private: + const QMenu * _menu; + ViewManager * _manager; + + protected: + enum Actions { + SUPPR, + UNSELECT + }; + + public: + SelectionMenuLambda(ViewManager *); + + virtual void initializeMenu(const QMenu *) final; + + public slots: + void viewChanged(ImageArea *); + }; +} diff --git a/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp b/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp index 04dfa4f..accb5cf 100644 --- a/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp +++ b/IHM_Retouche_Photo/ui/toolbox/toolRegister.cpp @@ -1,35 +1,46 @@ #include "toolRegister.h" +#include <QDebug> + namespace ui { - ToolboxRegister::ToolboxRegister(QPushButton * configButton, Toolbox * toolbox, ViewManager * manager, const QList<tool::Tool *> & tools) - : _toolbox(toolbox), _viewManager(manager),_configButton(configButton) , _currentTool(nullptr), _currentImage(nullptr) { - for(auto & tool : tools) { - this->push_back(QSharedPointer<tool::Tool>(tool)); - } +ToolboxRegister::ToolboxRegister(Toolbox * selectionToolbox, Toolbox * editTooblox, ViewManager * manager, QPushButton * configButton) + : _selectionToolbox(selectionToolbox), _editToolbox(editTooblox), _viewManager(manager), _configButton(configButton) , _currentTool(nullptr), _currentImage(nullptr) { configButton->setEnabled(false); } - void ToolboxRegister::update() { - this->_toolbox->clear(); - for(auto & tool : *this) { - this->_toolbox->addItem(tool.get()); + void ToolboxRegister::add(QSharedPointer<tool::Tool> tool, ToolType type) { + this->_tools.push_back(tool); + if(type == ToolType::EDIT) { + this->_editToolbox->addItem(tool.get()); } + else if(type == ToolType::SELECTION) { + this->_selectionToolbox->addItem(tool.get()); + } + } + + void ToolboxRegister::update() { + QObject::connect(this->_selectionToolbox, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(updateCurrentTool(QListWidgetItem*))); + QObject::connect(this->_editToolbox, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(updateCurrentTool(QListWidgetItem*))); - QObject::connect(this->_toolbox, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(updateCurrentTool(QListWidgetItem*))); QObject::connect(this->_viewManager, SIGNAL(changedView(ImageArea*)), this, SLOT(updateCurrentView(ImageArea*))); QObject::connect(this->_viewManager, SIGNAL(createdView(ImageArea*)), this, SLOT(updateCurrentView(ImageArea*))); - - this->_toolbox->setCurrentRow(0); } void ToolboxRegister::updateCurrentTool(QListWidgetItem * item) { + if(item->listWidget() == this->_editToolbox) { + this->_selectionToolbox->setCurrentRow(-1); + } + else if(item->listWidget() == this->_selectionToolbox) { + this->_editToolbox->setCurrentRow(-1); + } + if(this->_currentTool != nullptr && this->_currentImage != nullptr) { QObject::disconnect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); QObject::disconnect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&))); QObject::disconnect(this->_currentImage, SIGNAL(mouseMoved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool)), this->_currentTool, SLOT(moved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool))); QObject::disconnect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); - QObject::disconnect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + QObject::disconnect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); if(this->_currentTool->HaveConfigurationDialog()) { QObject::disconnect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); @@ -61,6 +72,10 @@ namespace ui { QObject::disconnect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); QObject::disconnect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + + if(this->_currentTool->HaveConfigurationDialog()) { + QObject::disconnect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); + } } this->_currentImage = dynamic_cast<ImageArea *>(image); @@ -73,6 +88,10 @@ namespace ui { QObject::connect(this->_currentImage, SIGNAL(keyboardPress(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyPressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); QObject::connect(this->_currentImage, SIGNAL(keyboardRelease(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&)), this->_currentTool, SLOT(keyReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QKeyEvent&))); + + QObject::connect(this->_configButton, SIGNAL(released()), this->_currentTool, SLOT(showConfiguration())); + this->_configButton->setEnabled(this->_currentTool->HaveConfigurationDialog()); + } } } diff --git a/IHM_Retouche_Photo/ui/toolbox/toolRegister.h b/IHM_Retouche_Photo/ui/toolbox/toolRegister.h index 36afd3c..3a16109 100644 --- a/IHM_Retouche_Photo/ui/toolbox/toolRegister.h +++ b/IHM_Retouche_Photo/ui/toolbox/toolRegister.h @@ -11,25 +11,36 @@ namespace ui { using Toolbox = QListWidget; - class ToolboxRegister : public QObject, public QVector<QSharedPointer<tool::Tool>> { + class ToolboxRegister : public QObject { Q_OBJECT public: - Toolbox * _toolbox; + Toolbox * _selectionToolbox; + Toolbox * _editToolbox; ViewManager * _viewManager; QPushButton * _configButton; + QVector<QSharedPointer<tool::Tool>> _tools; + tool::Tool * _currentTool; ImageArea * _currentImage; public: - ToolboxRegister(QPushButton * = nullptr, Toolbox * = nullptr, ViewManager * = nullptr, const QList<tool::Tool *> & = {}); + ToolboxRegister(Toolbox * selectionToolbox = nullptr, Toolbox * editTooblox = nullptr, ViewManager * = nullptr, QPushButton * = nullptr); + + enum ToolType { + SELECTION, + EDIT + }; - inline void setToolbox(Toolbox * toolbox) {this->_toolbox = toolbox;} + inline void setSelectionToolbox(Toolbox * toolbox) {this->_selectionToolbox = toolbox;} + inline void setEditToolbox(Toolbox * toolbox) {this->_editToolbox = toolbox;} inline void setViewManager(ViewManager * viewManager) {this->_viewManager = viewManager;} inline void setConfigurationButton(QPushButton * button) {this->_configButton = button;} - inline const Toolbox * toolbox() const {return this->_toolbox;} + inline const Toolbox * selectionToolbox() const {return this->_selectionToolbox;} + inline const Toolbox * editToolbox() const {return this->_editToolbox;} + void add(QSharedPointer<tool::Tool>, ToolType); void update(); public slots: diff --git a/IHM_Retouche_Photo/ui/view/imagearea.cpp b/IHM_Retouche_Photo/ui/view/imagearea.cpp index 0cad5c1..71c1292 100644 --- a/IHM_Retouche_Photo/ui/view/imagearea.cpp +++ b/IHM_Retouche_Photo/ui/view/imagearea.cpp @@ -16,7 +16,7 @@ namespace ui { ImageArea::ImageArea() : _selection(), _fileinfo(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/New"), - _image(800, 600, QImage::Format_RGB32), + _image(800, 600, QImage::Format_RGBA64), _checkboard(ImageArea::Generate_Checkboard(4, 4, 16)), _transformation(), _position(0, 0), @@ -311,4 +311,10 @@ namespace ui { effect::BlackAndWhite bw; this->effect(bw); } + + void ImageArea::deleteCurrentSelection() { + for(auto & pixel : this->_selection.selection()) { + this->setColor(pixel, QColor(0, 0, 0, 0)); + } + } } diff --git a/IHM_Retouche_Photo/ui/view/imagearea.h b/IHM_Retouche_Photo/ui/view/imagearea.h index 5d302a2..8d37a58 100644 --- a/IHM_Retouche_Photo/ui/view/imagearea.h +++ b/IHM_Retouche_Photo/ui/view/imagearea.h @@ -50,6 +50,7 @@ namespace ui { inline const QImage & image() const {return this->_image;} inline const Repercution * repercution() const {return this->_repercution;} inline const QTransform & transformation() const {return this->_transformation;} + inline const Selection & selection() const {return this->_selection;} inline double zoom() const {return this->_zoom;} @@ -112,6 +113,7 @@ namespace ui { void decreaseContrast(); void blackAndWhite(); + void deleteCurrentSelection(); signals: void zoomChanged(double); diff --git a/IHM_Retouche_Photo/ui/view/selection.h b/IHM_Retouche_Photo/ui/view/selection.h index dcb9e85..9535ed0 100644 --- a/IHM_Retouche_Photo/ui/view/selection.h +++ b/IHM_Retouche_Photo/ui/view/selection.h @@ -33,11 +33,13 @@ namespace ui { void invert(const QImage &); void invert(unsigned int, unsigned int); - void clear(); + inline bool contain(const QPoint & point) const {return this->_pixels.contains(point);}; inline bool empty() const {return this->_pixels.empty();} + public slots: + void clear(); signals: void selected(const QPoint &); diff --git a/IHM_Retouche_Photo/ui/view/viewmanager.cpp b/IHM_Retouche_Photo/ui/view/viewmanager.cpp index 4b8dfed..4c80e38 100644 --- a/IHM_Retouche_Photo/ui/view/viewmanager.cpp +++ b/IHM_Retouche_Photo/ui/view/viewmanager.cpp @@ -42,6 +42,24 @@ namespace ui { } void ViewManager::deleteCurrentView() { + if(this->currentView() == nullptr) { + return; + } + + if(this->currentView()->isModified()) { + QMessageBox saveDialog; + saveDialog.setText("Voulez vous sauvegarder les modification ?"); + saveDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + saveDialog.setDefaultButton(QMessageBox::Cancel); + saveDialog.setIcon(QMessageBox::Icon::Warning); + int result = saveDialog.exec(); + + if(result == QMessageBox::Yes) { + this->saveAsCurrentView(); + this->currentView()->setModified(false); + } + } + this->deleteView(this->_tabs->currentIndex()); } -- GitLab