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

Refonte du styème d'outil + Ajout de l'outil "Main"

parent ca38c231
Branches
No related tags found
1 merge request!1Dev
Showing
with 368 additions and 63 deletions
......@@ -11,6 +11,9 @@ CONFIG += c++17
SOURCES += \
main.cpp \
mainwindow.cpp \
tools/editable.cpp \
tools/hand.cpp \
tools/selectionnable.cpp \
tools/tool.cpp \
ui/files/treefileselector.cpp \
ui/menu/displaymenulambda.cpp \
......@@ -23,6 +26,9 @@ SOURCES += \
HEADERS += \
mainwindow.h \
tools/editable.h \
tools/hand.h \
tools/selectionnable.h \
tools/tool.h \
ui/files/fileselector.h \
ui/files/treefileselector.h \
......
......@@ -13,7 +13,7 @@ QString getStyleSheet(const QString & path) {
int main(int argc, char *argv[]) {
QApplication application(argc, argv);
//application.setStyleSheet(getStyleSheet(":/stylesheet/ressource/stylesheet/QTDark.stylesheet"));
application.setStyleSheet(getStyleSheet(":/stylesheet/ressource/stylesheet/QTDark.css"));
MainWindow window;
window.show();
......
......@@ -8,6 +8,8 @@
#include <ui/files/treefileselector.h>
#include <tools/hand.h>
MainWindow::MainWindow(QWidget * parent)
: QMainWindow(parent), _toolRegister(), _fileselectorManager(nullptr), _viewManager(nullptr) {
this->setupUi(this);
......@@ -16,20 +18,24 @@ MainWindow::MainWindow(QWidget * parent)
qDebug() << "Mark_1";
this->_toolRegister.setToolbox(this->_toolbox);
this->_toolRegister.update();
qDebug() << "Mark_2";
this->_fileselectorManager = new ui::TreeFileSelector(this->_filesSelector, this->_filesSelected, this);
QObject::connect(this->_remove_selectable_element, SIGNAL(released()), this->_fileselectorManager, SLOT(removeSelectedItem()));
QObject::connect(this->_add_selectable_element, SIGNAL(released()), this->_fileselectorManager, SLOT(pushItem()));
qDebug() << "Mark_3";
qDebug() << "Mark_2";
this->_viewManager = new ui::ViewManager(this->_fileselectorManager, this->_imageTabs);
qDebug() << "Mark_3";
this->_toolRegister.setToolbox(this->_toolbox);
this->_toolRegister.setViewManager(this->_viewManager);
this->_toolRegister.push_back(QSharedPointer<tool::Tool>(new tool::Hand()));
this->_toolRegister.update();
qDebug() << "Mark_4";
this->_menubarManager.insert(this->_menuFile, QSharedPointer<ui::MenuLambda>(new ui::FilemenuLambda(this->_fileselectorManager, this->_viewManager)));
......
#include "editable.h"
namespace tool {
Editable::Editable(const QString & name, const QIcon & icon,bool free)
: Tool(name, icon), _free(free) {}
void Editable::pressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) {
if(image.rect().contains(click) || this->_free) {
this->onMousePressed(area, image, click, selection, e);
}
}
void Editable::released(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) {
if(image.rect().contains(click) || this->_free) {
this->onMouseReleased(area, image, click, selection, e);
}
}
void Editable::moved(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e, bool hold) {
if(image.rect().contains(click) || this->_free) {
this->onMouseMoved(area, image, click, selection, e, hold);
}
}
}
#pragma once
#include "tool.h"
namespace tool {
class Editable : public Tool {
private:
bool _free;
public:
Editable(const QString & = "NaN", const QIcon & = QIcon(":/image/oxygen/icons/16x16/ressource/image/oxygen/icons/16x16/draw-freehand.png"), bool = false);
virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &) = 0;
virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &) = 0;
virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, bool) = 0;
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;
};
}
#include "hand.h"
namespace tool {
Hand::Hand()
: Editable("Main", QIcon(":/image/oxygen/icons/16x16/ressource/image/oxygen/icons/16x16/transform-move.png"), true), _leftButton(false) {}
void Hand::onMousePressed(ui::ImageArea & area, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e) {
if(e.button() == Qt::LeftButton) {
area.setCursor(QCursor(Qt::CursorShape::ClosedHandCursor));
this->_leftButton = true;
}
}
void Hand::onMouseReleased(ui::ImageArea & area, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e) {
if(e.button() == Qt::LeftButton) {
area.setCursor(QCursor(Qt::CursorShape::OpenHandCursor));
area.setLast_Positon(e.pos());
this->_leftButton = false;
}
}
void Hand::onMouseMoved(ui::ImageArea & area, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent & e, bool hold) {
if(hold && this->_leftButton) {
QPoint move = e.pos() - area.last_position();
area.setPosition(QPoint(area.position().x() + move.x(),area.position().y() + move.y()));
area.setLast_Positon(e.pos());
}
}
}
#pragma once
#include "editable.h"
namespace tool {
class Hand : public Editable {
private:
bool _leftButton;
public:
Hand();
inline virtual Qt::CursorShape shape() const {return Qt::CursorShape::OpenHandCursor;}
virtual void onMousePressed(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &);
virtual void onMouseReleased(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &);
virtual void onMouseMoved(ui::ImageArea &, QImage &, const QPoint &, const ui::Selection &, const QMouseEvent &, bool);
};
}
#pragma once
#include "tool.h"
namespace tool {
class Select : public Tool {
public:
Select(const QString &, const QIcon &);
virtual void setup() const = 0;
public slots:
virtual void use() const final;
};
}
#include "selectionnable.h"
namespace tool {
Selectionable::Selectionable(const QString & name, const QIcon & icon, bool free)
: Tool(name, icon), _free(free) {}
void Selectionable::pressed(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) {
if(image.rect().contains(click) || this->_free) {
this->onMousePressed(area, selection, click, image, e);
}
}
void Selectionable::released(ui::ImageArea & area, QImage & image, QPoint & click, ui::Selection & selection, QMouseEvent & e) {
if(image.rect().contains(click) || this->_free) {
this->onMouseReleased(area, selection, click, image, e);
}
}
void Selectionable::moved(ui::ImageArea & area, QImage & image, QPoint & click ,ui::Selection & selection, QMouseEvent & e, bool hold) {
if(image.rect().contains(click) || this->_free) {
this->onMouseMoved(area, selection, click, image, e, hold);
}
}
}
#pragma once
#include "tool.h"
namespace tool {
class Selectionable : public Tool {
private:
bool _free;
public:
Selectionable(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;
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;
};
}
#pragma once
#include <QListWidgetItem>
#include <QObject>
#include <QCursor>
#include "../ui/view/imagearea.h"
namespace tool {
class Tool : public QListWidgetItem {
class Tool : public QObject, public QListWidgetItem {
Q_OBJECT
public:
Tool(const QString &, const QIcon &);
virtual void setup() const = 0;
virtual inline Qt::CursorShape shape() const {return Qt::CursorShape::ArrowCursor;}
public slots:
virtual void use() const = 0;
virtual void pressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0;
virtual void released(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &) = 0;
virtual void moved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool) = 0;
};
}
......@@ -3,8 +3,8 @@
namespace ui {
DisplayMenuLambda::DisplayMenuLambda(ViewManager * manager)
: _manager(manager), _area(manager->currentView()) {
this->viewChange(*this->_manager->currentView());
QObject::connect(this->_manager, SIGNAL(changedView(ImageArea)), this, SLOT(viewChange(ImageArea)));
this->viewChange(this->_manager->currentView());
QObject::connect(this->_manager, SIGNAL(changedView(ImageArea*)), this, SLOT(viewChange(ImageArea*)));
}
void DisplayMenuLambda::initializeMenu(const QMenu * menu) {
......@@ -12,7 +12,7 @@ namespace ui {
}
void DisplayMenuLambda::viewChange(const ImageArea &) {
void DisplayMenuLambda::viewChange(ImageArea *) {
if(this->_menu != nullptr) {
if(this->_area != nullptr) {
QObject::disconnect(this->_menu->actions().at(Actions::ZOOM_IN), SIGNAL(triggered()), this->_area, SLOT(increaseZoom()));
......
......@@ -25,7 +25,7 @@ namespace ui {
virtual void initializeMenu(const QMenu *) final;
public slots:
void viewChange(const ImageArea &);
void viewChange(ImageArea *);
};
}
#include "toolRegister.h"
namespace ui {
ToolboxRegister::ToolboxRegister(const QList<tool::Tool *> & tools, Toolbox * toolbox)
: _toolbox(toolbox) {
ToolboxRegister::ToolboxRegister(Toolbox * toolbox, ViewManager * manager, const QList<tool::Tool *> & tools)
: _toolbox(toolbox), _viewManager(manager), _currentTool(nullptr), _currentImage(nullptr) {
for(auto & tool : tools) {
this->push_back(QSharedPointer<tool::Tool>(tool));
}
......@@ -13,5 +13,47 @@ namespace ui {
for(auto & tool : *this) {
this->_toolbox->addItem(tool.get());
}
QObject::connect(this->_toolbox, SIGNAL(itemActivated(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*)));
}
void ToolboxRegister::updateCurrentTool(QListWidgetItem * item) {
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)));
}
this->_currentTool = dynamic_cast<tool::Tool*>(item);
if(this->_currentTool != nullptr && this->_currentImage != nullptr) {
this->_currentImage->setCursor(QCursor(this->_currentTool->shape()));
QObject::connect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)));
QObject::connect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)));
QObject::connect(this->_currentImage, SIGNAL(mouseMoved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool)), this->_currentTool, SLOT(moved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool)));
}
qDebug() << "tool choose";
}
void ToolboxRegister::updateCurrentView(ImageArea * image) {
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)));
}
this->_currentImage = dynamic_cast<ImageArea *>(image);
if(this->_currentTool != nullptr && this->_currentImage != nullptr) {
this->_currentImage->setCursor(QCursor(this->_currentTool->shape()));
QObject::connect(this->_currentImage, SIGNAL(mousePressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(pressed(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)));
QObject::connect(this->_currentImage, SIGNAL(mouseReleased(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)), this->_currentTool, SLOT(released(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&)));
QObject::connect(this->_currentImage, SIGNAL(mouseMoved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool)), this->_currentTool, SLOT(moved(ui::ImageArea&,QImage&,QPoint&,ui::Selection&,QMouseEvent&,bool)));
}
qDebug() << "view changed";
}
}
......@@ -6,20 +6,30 @@
#include <tools/tool.h>
#include "../view/viewmanager.h"
namespace ui {
using Toolbox = QListWidget;
class ToolboxRegister : public QVector<QSharedPointer<tool::Tool>> {
class ToolboxRegister : public QObject, public QVector<QSharedPointer<tool::Tool>> {
Q_OBJECT
public:
Toolbox * _toolbox;
ViewManager * _viewManager;
tool::Tool * _currentTool;
ImageArea * _currentImage;
public:
ToolboxRegister(const QList<tool::Tool *> & = {}, Toolbox * toolbox = nullptr);
ToolboxRegister(Toolbox * = nullptr, ViewManager * = nullptr, const QList<tool::Tool *> & = {});
inline void setToolbox(Toolbox * toolbox) {this->_toolbox = toolbox;}
inline void setViewManager(ViewManager * viewManager) {this->_viewManager = viewManager;}
inline const Toolbox * toolbox() const {return this->_toolbox;}
void update();
public slots:
void updateCurrentTool(QListWidgetItem *);
void updateCurrentView(ImageArea *);
};
}
......@@ -12,9 +12,9 @@ namespace ui {
_fileinfo(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/New"),
_image(800, 600, QImage::Format_RGB32),
_checkboard(ImageArea::Generate_Checkboard(4, 4, 16)),
_position(this->width()/2, this->height()/2),
_lastPos(this->width()/2, this->height()/2),
_zoom(2.f),
_position(0, 0),
_lastPos(0, 0),
_zoom(1.f),
_mouseClickHold(false),
_status(NEW) {
this->setMouseTracking(true);
......@@ -26,9 +26,9 @@ namespace ui {
_fileinfo(info),
_image(info.absoluteFilePath()),
_checkboard(ImageArea::Generate_Checkboard(4, 4, 16)) ,
_position(this->width()/2, this->height()/2),
_lastPos(this->width()/2, this->height()/2),
_zoom(2.f),
_position(0, 0),
_lastPos(0, 0),
_zoom(1.f),
_mouseClickHold(false),
_status(ORIGINAL) {
this->setMouseTracking(true);
......@@ -39,46 +39,56 @@ namespace ui {
QPainter painter(this);
QRect drawZone(
-this->_image.width() /2, -this->_image.height()/2,
this->_image.width() , this->_image.height()
this->_position.x(),
this->_position.y(),
this->_image.width() * this->_zoom,
this->_image.height() * this->_zoom
);
painter.translate(this->_position);
painter.drawRect(drawZone);
painter.scale(this->_zoom, this->_zoom);
painter.drawImage(drawZone, this->_checkboard);
painter.drawImage(drawZone, this->_image);
this->_selection.paint(painter, QPoint(drawZone.x(), drawZone.y()));
this->_selection.paint(painter, QPoint(drawZone.x(), drawZone.y()), this->_zoom);
}
void ImageArea::mouseMoveEvent(QMouseEvent * e) {
if(this->_mouseClickHold) {
QPoint move = e->pos() - this->_lastPos;
this->_position.setX(this->_position.x() + move.x());
this->_position.setY(this->_position.y() + move.y());
this->repaint();
QPoint pixelPosition = this->_position - this->_lastPos;
if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) {
pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom);
pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom);
}
emit this->mouseMoved(*this, this->_image, pixelPosition, this->_selection, *e, this->_mouseClickHold);
this->_lastPos = e->pos();
}
this->repaint();
}
void ImageArea::mousePressEvent(QMouseEvent * e) {
if(e->button() == Qt::LeftButton) {
this->_lastPos = e->pos();
this->_mouseClickHold = true;
this->setCursor(QCursor(Qt::CursorShape::ClosedHandCursor));
QPoint pixelPosition = this->_position - this->_lastPos;
if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) {
pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom);
pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom);
}
emit this->mousePressed(*this, this->_image, pixelPosition, this->_selection, *e);
this->repaint();
}
void ImageArea::mouseReleaseEvent(QMouseEvent * e) {
if(e->button() == Qt::LeftButton) {
this->_mouseClickHold = false;
this->setCursor(QCursor(Qt::CursorShape::OpenHandCursor));
QPoint pixelPosition = this->_position - this->_lastPos;
if(pixelPosition.x() <= 0 && pixelPosition.y() <= 0) {
pixelPosition.setX(abs(pixelPosition.x()) / this->_zoom);
pixelPosition.setY(abs(pixelPosition.y()) / this->_zoom);
}
this->repaint();
emit this->mouseReleased(*this, this->_image, pixelPosition, this->_selection, *e);
}
void ImageArea::wheelEvent(QWheelEvent *event) {
......@@ -97,16 +107,18 @@ namespace ui {
}
void ImageArea::increaseZoom() {
++this->_zoom;
this->_zoom += 1;
emit this->zoomChange(this->_zoom);
this->repaint();
}
void ImageArea::decreaseZoom() {
--this->_zoom;
if(this->_zoom > 1) {
this->_zoom -= 1;
emit this->zoomChange(this->_zoom);
this->repaint();
}
}
void ImageArea::setImage(const QImage & image) {
this->_image = image;
......
......@@ -44,11 +44,18 @@ namespace ui {
inline bool isOriginal() const {return (this->_status & ORIGINAL) != 0;}
inline bool isModified() const {return (this->_status & MODIFIED) != 0;}
inline bool isNew() const {return (this->_status & NEW) != 0;}
inline bool isMouseHolded() const {return this->_mouseClickHold;}
inline const QPoint & position() const {return this->_position;}
inline const QPoint & last_position() const {return this->_lastPos;}
inline void setOriginal(bool original) {this->_status = original ? this->_status | ORIGINAL : this->_status & ~ORIGINAL;}
inline void setModified(bool modified) {this->_status = modified ? this->_status | MODIFIED : this->_status & ~MODIFIED;}
inline void setNew(bool news) {this->_status = news ? this->_status | NEW : this->_status & ~NEW;}
inline void setZoom(float zoom) {this->_zoom = zoom;}
inline void setMouseHold(bool hold) {this->_mouseClickHold = hold;}
inline void setPosition(const QPoint & position) {this->_position = position;}
inline void setLast_Positon(const QPoint & lastPosition) {this->_lastPos = lastPosition;}
virtual void paintEvent(QPaintEvent * e);
......@@ -77,9 +84,12 @@ namespace ui {
void imageChanged(const QImage &);
void pixelChange(const QPoint &);
void saved(const QImage &, const QFileInfo &);
void pressed(QImage &, Selection &, QPoint &, Qt::MouseButton);
void mousePressed(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &);
void mouseReleased(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &);
void mouseMoved(ui::ImageArea &, QImage &, QPoint &, ui::Selection &, QMouseEvent &, bool);
};
}
......@@ -2,13 +2,11 @@
namespace ui {
Selection::Selection(const QSet<QPoint> & preselection,const QColor & color)
: _pixels(preselection), _color(color) {
this->_pixels.insert(QPoint(0, 0));
}
: _pixels(preselection), _color(color) {}
void Selection::paint(QPainter & painter, const QPoint & position) {
void Selection::paint(QPainter & painter, const QPoint & position, float zoom) {
for(auto & pixel : this->_pixels) {
painter.fillRect(position.x() + pixel.x(),position.y() + pixel.y(), 1, 1, this->_color);
painter.fillRect(position.x() + pixel.x() * zoom, position.y() + pixel.y() * zoom, zoom, zoom, this->_color);
}
}
......@@ -37,6 +35,16 @@ namespace ui {
}
}
void Selection::select(const QImage & image, const QColor & color) {
for(int x = 0; x < image.width(); x++) {
for(int y = 0; y < image.width(); y++) {
if(image.pixel(x, y) == color.rgba()) {
this->selected(QPoint(x, y));
}
}
}
}
void Selection::unselect(const QPoint & point) {
this->_pixels.erase(this->_pixels.find(point));
emit this->unselected(point);
......@@ -61,4 +69,37 @@ namespace ui {
}
}
}
void Selection::unselect(const QImage & image, const QColor & color) {
for(auto & point : this->_pixels) {
if(image.pixel(point) == color.rgb()) {
this->unselect(point);
}
}
}
void Selection::invert(const QImage & image) {
this->invert(image.width(), image.height());
}
void Selection::invert(unsigned int w, unsigned int h) {
QSet<QPoint> current = this->_pixels;
this->clear();
for(unsigned int x = 0; x < w; x++) {
for(unsigned int y = 0; y < h; y++) {
QPoint point = QPoint(x, y);
if(!current.contains(point)) {
this->select(point);
}
}
}
}
void Selection::clear() {
this->_pixels.clear();
}
bool Selection::contain(const QPoint & point) {
return this->_pixels.contains(point);
}
}
......@@ -15,17 +15,27 @@ namespace ui {
public:
Selection(const QSet<QPoint> & = {}, const QColor & = QColor(0, 148, 255, 96));
void paint(QPainter &, const QPoint &);
inline const QSet<QPoint> selection() const {return this->_pixels;}
void paint(QPainter &, const QPoint &, float);
void select(const QPoint &);
void select(const QSet<QPoint> &);
void select(const QVector<QPoint> &);
void select(const QRect &);
void select(const QImage &, const QColor &);
void unselect(const QPoint &);
void unselect(const QSet<QPoint> &);
void unselect(const QVector<QPoint> &);
void unselect(const QRect &);
void unselect(const QImage &, const QColor &);
void invert(const QImage &);
void invert(unsigned int, unsigned int);
void clear();
bool contain(const QPoint &);
signals:
void selected(const QPoint &);
......
......@@ -16,9 +16,9 @@ namespace ui {
}
void ViewManager::deleteView(int index) {
emit this->deletedView(*this->currentView());
emit this->deletedView(this->currentView());
if(this->_tabs->count() != 0) {
emit this->changedView(*this->currentView());
emit this->changedView(this->currentView());
}
this->_tabs->removeTab(index);
}
......@@ -28,7 +28,7 @@ namespace ui {
}
void ViewManager::changeView(int) {
emit this->changedView(*this->currentView());
emit this->changedView(this->currentView());
}
void ViewManager::viewModified(const QFileInfo &) {
......@@ -41,20 +41,24 @@ namespace ui {
}
void ViewManager::newView() {
int tabs = this->_tabs->count();
this->_tabs->addTab(new ImageArea(), "New");
emit this->createdView(*this->currentView());
emit this->createdView(this->currentView());
if(tabs == 0) {
emit this->changedView(this->currentView());
}
}
void ViewManager::newView(const QFileInfo & info) {
this->_tabs->addTab(QPointer<ImageArea>(new ImageArea(info)), info.fileName());
emit this->createdView(*this->currentView());
emit this->createdView(this->currentView());
}
void ViewManager::deleteView(const QFileInfo & info) {
for(int i = 0; i < this->_tabs->count(); i++) {
ImageArea * widget = dynamic_cast<ImageArea *>(this->_tabs->widget(i));
if(widget->file().absoluteFilePath() == info.absoluteFilePath()) {
emit this->deletedView(*widget);
emit this->deletedView(widget);
this->_tabs->removeTab(i);
--i;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment