Skip to content
Snippets Groups Projects
Commit 3322a7d3 authored by nima's avatar nima
Browse files

Correct classes edit, crop , brush

parent 18e14b07
No related branches found
No related tags found
No related merge requests found
......@@ -5,79 +5,69 @@
#include <QPainter>
#include <QPushButton>
#include "crop.h"
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
#include <QDebug>
namespace tool {
Crop::Crop(const QString & name, const QIcon & icon, bool free)
: Tool(name, icon), _free(free), scene(nullptr){}
bool cropModeEnabled = false;
QGraphicsRectItem* cropRectItem = nullptr;
void Crop::toggleCropMode() {
scene = new QGraphicsScene();
cropModeEnabled = !cropModeEnabled;
if (cropModeEnabled) {
cropRectItem = new QGraphicsRectItem();
cropRectItem->setPen(QPen(Qt::red, 2, Qt::DashLine));
scene->addItem(cropRectItem);
} else {
if (scene && cropRectItem) {
scene->removeItem(cropRectItem);
delete cropRectItem;
cropRectItem = nullptr;
delete scene;
scene = nullptr;
}
} else {
scene = new QGraphicsScene();
cropRectItem = new QGraphicsRectItem();
cropRectItem->setPen(QPen(Qt::red, 2, Qt::DashLine));
scene->addItem(cropRectItem);
}
cropModeEnabled = !cropModeEnabled;
}
void Selectionable::onMousePressed(ui::ImageArea & imageArea, ui::Selection & select, const QPoint & point, const QImage & image, const QMouseEvent & e) {
void Crop::onMousePressed(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& point, const QImage& image, const QMouseEvent& e) {
if (cropModeEnabled && cropRectItem) {
// Capture the starting point of the crop area
QPointF startPoint = point;
cropRectItem->setRect(startPoint.x(), startPoint.y(), 0, 0);
} else {
cropRectItem->setRect(point.x(), point.y(), 0, 0);
}
}
void Crop::onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint & click, const QImage &, const QMouseEvent &, bool) {
void Crop::onMouseMoved(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QMouseEvent& e, bool hold) {
if (cropModeEnabled && cropRectItem) {
QPointF currentPoint = click;
qreal width = currentPoint.x() - cropRectItem->rect().left();
qreal height = currentPoint.y() - cropRectItem->rect().top();
qreal width = click.x() - cropRectItem->rect().left();
qreal height = click.y() - cropRectItem->rect().top();
cropRectItem->setRect(cropRectItem->rect().left(), cropRectItem->rect().top(), width, height);
} else {
}
}
void Crop::onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &) {
void Crop::onMouseReleased(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QMouseEvent& e) {
if (cropModeEnabled && cropRectItem) {
QRectF cropRect = cropRectItem->rect();
qDebug() << "Crop Area Dimensions: Width = " << cropRect.width() << ", Height = " << cropRect.height();
QImage croppedImage = image.copy(cropRect.toRect());
} else {
imageArea.setImage(croppedImage);
toggleCropMode();
}
}
void Crop::onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &) {}
void Crop::onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &) {}
void Crop::onKeyPress(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QKeyEvent& e) {
// Handle key press events if needed
}
void Crop::onKeyReleased(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QKeyEvent& e) {
// Handle key release events if needed
}
void Crop::pressed(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QMouseEvent& e) {
if (image.rect().contains(click) || this->_free) {
......@@ -104,4 +94,6 @@ Crop::Crop(const QString & name, const QIcon & icon, bool free)
void Crop::keyReleased(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QKeyEvent& e) {
this->onKeyReleased(area, selection, click, image, e);
}
}
......@@ -21,35 +21,25 @@ class Crop : public Tool
private:
bool _free;
bool cropModeEnabled;
QGraphicsScene* scene;
QGraphicsRectItem* cropRectItem;
public:
Crop(const QString& name, const QIcon& icon, bool free);
Crop(const QString & = "NaN", const QIcon & = QIcon(":/image/oxygen/icons/16x16/ressource/image/oxygen/icons/16x16/transform-crop.png"),bool = false);
virtual void onMousePressed(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &) = 0;
virtual void onMouseReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &) = 0;
virtual void onMouseMoved(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QMouseEvent &, bool) = 0;
virtual void onKeyPress(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
virtual void onKeyReleased(ui::ImageArea &, ui::Selection &, const QPoint &, const QImage &, const QKeyEvent &);
public slots:
virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final;
virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) final;
virtual void moved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool) final;
virtual void keyPressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final;
virtual void keyReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QKeyEvent &) final;
void toggleCropMode();
private:
tool::Selectionable *selectionable;
QPushButton *CropButton;
QGraphicsScene *scene;
QGraphicsRectItem *cropRectItem;
bool cropModeEnabled;
void onMousePressed(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& point, const QImage& image, const QMouseEvent& e) ;
void onMouseMoved(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QMouseEvent& e, bool hold);
void onMouseReleased(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QMouseEvent& e);
void onKeyPress(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QKeyEvent& e) ;
void onKeyReleased(ui::ImageArea& imageArea, ui::Selection& select, const QPoint& click, const QImage& image, const QKeyEvent& e) ;
void pressed(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QMouseEvent& e) override;
void released(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QMouseEvent& e) override;
void moved(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QMouseEvent& e, bool hold) override;
void keyPressed(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QKeyEvent& e) override;
void keyReleased(ui::ImageArea& area, QImage& image, QPoint& click, ui::Selection& selection, QKeyEvent& e) override;
signals:
};
......
......@@ -15,6 +15,7 @@
#include <tools/hand.h>
#include <tools/tool.h>
MainWindow::MainWindow(QWidget * parent)
: QMainWindow(parent), _toolRegister(), _fileselectorManager(nullptr), _viewManager(nullptr) {
......@@ -32,7 +33,7 @@ MainWindow::MainWindow(QWidget * parent)
ColorWindow = findChild<QPushButton*>("ColorWindow");
//crop = QSharedPointer<tool::Crop>(new tool::Crop("Crop Tool", QIcon(":/icons/crop.png"), true));
crop = new tool::Crop("Crop Tool", QIcon(":/icons/crop.png"), true);
CropButton = findChild<QPushButton*>("CropButton");
......@@ -106,7 +107,7 @@ void MainWindow::openColorPicker()
}
void MainWindow::handleCtrlCKey()
{
// Trigger the ColorWindow button when Ctrl+C is pressed
openColorPicker();
}
MainWindow::~MainWindow() {
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment