Merge branch 'dev' into 'dev-rework'

# Conflicts:
#   cppcheck_errors.txt
#   src/GUI/IntelliPhotoGui.h
This commit is contained in:
Conrad
2020-01-15 13:57:27 +00:00
8 changed files with 216 additions and 118 deletions

View File

@@ -18,24 +18,13 @@
#include "Tool/IntelliToolFloodFill.h"
#include "Tool/IntelliToolPolygon.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){
this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight);
this->addLayer(200,200,0,0,IntelliImage::ImageType::SHAPEDIMAGE);
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
std::vector<QPoint> polygon;
polygon.push_back(QPoint(100,000));
polygon.push_back(QPoint(200,100));
polygon.push_back(QPoint(100,200));
polygon.push_back(QPoint(000,100));
layerBundle[0].image->setPolygon(polygon);
this->addLayer(200,200,150,150,IntelliImage::ImageType::RASTERIMAGE);
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
layerBundle[1].alpha=200;
activeLayer=0;
activeLayer=-1;
}
PaintingArea::~PaintingArea(){
@@ -64,6 +53,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){
LayerObject newLayer;
updateTools();
newLayer.width = width;
newLayer.height = height;
newLayer.widthOffset = widthOffset;
@@ -80,7 +70,10 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
}
void PaintingArea::deleteLayer(int idx){
void PaintingArea::deleteLayer(int idx, bool isTool){
if(!isTool) {
updateTools();
}
if(idx<static_cast<int>(layerBundle.size())) {
this->layerBundle.erase(layerBundle.begin()+idx);
if(activeLayer>=idx) {
@@ -100,6 +93,7 @@ void PaintingArea::slotDeleteActiveLayer(){
}
void PaintingArea::setLayerActive(int idx){
updateTools();
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
this->activeLayer=idx;
}
@@ -110,6 +104,15 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
layerBundle[static_cast<size_t>(idx)].alpha=alpha;
}
}
void PaintingArea::setPolygon(int idx){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE) {
delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true;
}
}
}
// Used to load the image and place it in the widget
bool PaintingArea::open(const QString &filePath){
@@ -147,36 +150,14 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){
}
}
// Color the image area with white
void PaintingArea::floodFill(int r, int g, int b, int a){
if(this->activeLayer==-1) {
return;
}
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
active->drawPlain(QColor(r, g, b, a));
update();
}
void PaintingArea::movePositionActive(int x, int y){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
}
void PaintingArea::moveActiveLayer(int idx){
if(Tool != nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
if(idx==1) {
this->selectLayerUp();
}else if(idx==-1) {
@@ -185,13 +166,7 @@ void PaintingArea::moveActiveLayer(int idx){
}
void PaintingArea::slotActivateLayer(int a){
if(Tool != nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
this->setLayerActive(a);
}
@@ -335,7 +310,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){
update();
}
// Resize the image to slightly larger then the main window
//TODOJ Resize the image to slightly larger then the main window
// to cut down on the need to resize the image
void PaintingArea::resizeEvent(QResizeEvent*event){
//TODO wait till tool works
@@ -347,6 +322,7 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
}
void PaintingArea::selectLayerUp(){
updateTools();
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]);
activeLayer++;
@@ -354,6 +330,7 @@ void PaintingArea::selectLayerUp(){
}
void PaintingArea::selectLayerDown(){
updateTools();
if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
activeLayer--;
@@ -431,5 +408,35 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){
if(activeLayer<0) {
return nullptr;
}
return layerBundle[activeLayer].image;
return layerBundle[static_cast<size_t>(activeLayer)].image;
}
QImage PaintingArea::getImageDataOfActiveLayer(){
QImage returnImage;
if(activeLayer<0) {
returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
returnImage.fill(QColor(255,255,255,255));
}
else{
returnImage = layerBundle[static_cast<size_t>(activeLayer)].image->getImageData();
if(renderSettings.isFastRenderering()) {
returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
}
}
return returnImage;
}
void PaintingArea::updateTools(){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
if(isSettingPolygon) {
delete this->Tool;
this->Tool = nullptr;
isSettingPolygon = false;
}
}
}

View File

@@ -99,8 +99,9 @@ int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffs
/*!
* \brief The deleteLayer method removes a layer at a given idx
* \param idx - The index of the layer to be removed
* \param isTool - Is the flag for when a tool uses this function.
*/
void deleteLayer(int idx);
void deleteLayer(int idx, bool isTool = false);
/*!
* \brief The setLayerToActive method marks a specific layer as active
* \param idx - The index of the layer to be active
@@ -113,13 +114,10 @@ void setLayerActive(int idx);
*/
void setLayerAlpha(int idx, int alpha);
/*!
* \brief The floodFill method fills a the active layer with a given color
* \param r - Red value of the color the layer should be filled with
* \param g - Green value of the color the layer should be filled with
* \param b - Blue value of the color the layer should be filled with
* \param a - Alpha value of the color the layer should be filled with
* \brief setPolygon is used for setting polygondata, it only works on RASTER images
* \param idx - represents the number of the layer with should be transformed
*/
void floodFill(int r, int g, int b, int a);
void setPolygon(int idx);
/*!
* \brief The movePositionActive method moves the active layer to certain position
* \param x - The x value the new center of the layer should be at
@@ -174,6 +172,12 @@ int getNumberOfActiveLayer();
IntelliImage* getImageOfActiveLayer();
/*!
* \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture)
* \return return the image as an rgba32bit qImage
*/
QImage getImageDataOfActiveLayer();
IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker;
@@ -209,6 +213,8 @@ QImage* Canvas;
int maxWidth;
int maxHeight;
bool isSettingPolygon = false;
IntelliRenderSettings renderSettings;
IntelliTool* Tool;
IntelliPhotoGui* DummyGui;
@@ -221,6 +227,9 @@ void drawLayers(bool forSaving=false);
void resizeLayer(QImage*image_res, const QSize &newSize);
bool createTempTopLayer(int idx);
//this function is needed to avoid errors in inputhandeling if a layer has changed
void updateTools();
};
#endif