Merge branch 'dev' into UnitTesting

This commit is contained in:
2020-01-16 11:24:44 +01:00
38 changed files with 1179 additions and 383 deletions

View File

@@ -24,7 +24,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight);
activeLayer=-1;
activeLayer = -1;
}
PaintingArea::~PaintingArea(){
@@ -32,7 +32,7 @@ PaintingArea::~PaintingArea(){
}
void PaintingArea::setRenderSettings(bool isFastRenderingOn){
if(isFastRenderingOn != renderSettings.isFastRenderering()) {
if(isFastRenderingOn != renderSettings.isFastRenderering() && !Tool->getIsDrawing()) {
renderSettings.setFastRendering(isFastRenderingOn);
for(auto& layer : layerBundle) {
layer.image->updateRendererSetting(isFastRenderingOn);
@@ -65,7 +65,7 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
}
newLayer.alpha = 255;
this->layerBundle.push_back(newLayer);
activeLayer = static_cast<int>(layerBundle.size())-1;
activeLayer = static_cast<int>(layerBundle.size()) - 1;
return activeLayer;
}
@@ -75,19 +75,19 @@ void PaintingArea::deleteLayer(int idx, bool isTool){
updateTools();
}
if(idx<static_cast<int>(layerBundle.size())&&idx>=0) {
this->layerBundle.erase(layerBundle.begin()+idx);
this->layerBundle.erase(layerBundle.begin() + idx);
if(activeLayer>=idx) {
activeLayer--;
}
if(activeLayer < 0 && layerBundle.size()) {
activeLayer=0;
activeLayer = 0;
}
}
}
void PaintingArea::slotDeleteActiveLayer(){
if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())) {
this->layerBundle.erase(layerBundle.begin()+activeLayer);
this->layerBundle.erase(layerBundle.begin() + activeLayer);
activeLayer--;
}
}
@@ -95,14 +95,14 @@ void PaintingArea::slotDeleteActiveLayer(){
void PaintingArea::setLayerActive(int idx){
updateTools();
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
this->activeLayer=idx;
this->activeLayer = idx;
}
}
void PaintingArea::setLayerAlpha(int idx, int alpha){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
if(alpha>=0 && alpha<=255) {
layerBundle[static_cast<size_t>(idx)].alpha=alpha;
layerBundle[static_cast<size_t>(idx)].alpha = alpha;
}
}
}
@@ -112,6 +112,7 @@ void PaintingArea::setPolygon(int idx){
delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true;
this->DummyGui->setToolWidth(5);
}
}
}
@@ -165,6 +166,7 @@ void PaintingArea::moveActiveLayer(int idx){
}else if(idx==-1) {
this->selectLayerDown();
}
DummyGui->UpdateGui();
}
void PaintingArea::slotActivateLayer(int a){
@@ -230,6 +232,14 @@ int PaintingArea::getHeightOfActive(){
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].height;
}
int PaintingArea::getMaxWidth(){
return this->maxWidth;
}
int PaintingArea::getMaxHeight(){
return this->maxHeight;
}
IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
}
@@ -247,8 +257,8 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){
}
if(Tool == nullptr)
return;
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
int x = event->x() - layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y() - layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
if(event->button() == Qt::LeftButton) {
Tool->onMouseLeftPressed(x, y);
}else if(event->button() == Qt::RightButton) {
@@ -266,8 +276,8 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){
}
if(Tool == nullptr)
return;
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
int x = event->x() - layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y() - layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
Tool->onMouseMoved(x, y);
update();
}
@@ -278,8 +288,8 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
return;
if(Tool == nullptr)
return;
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
int x = event->x() - layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y() - layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
if(event->button() == Qt::LeftButton) {
Tool->onMouseLeftReleased(x, y);
}else if(event->button() == Qt::RightButton) {
@@ -295,7 +305,7 @@ void PaintingArea::wheelEvent(QWheelEvent*event){
QPoint numDegrees = event->angleDelta() / 8;
if(!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
Tool->onWheelScrolled(numSteps.y()* -1);
Tool->onWheelScrolled(numSteps.y() * -1);
}
}
}
@@ -325,8 +335,8 @@ 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)]);
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++;
}
}
@@ -334,7 +344,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)]);
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer - 1)]);
activeLayer--;
}
}
@@ -345,30 +355,30 @@ void PaintingArea::drawLayers(bool forSaving){
}else{
Canvas->fill(Qt::GlobalColor::black);
}
for(size_t i=0; i<layerBundle.size(); i++) {
for(size_t i = 0; i<layerBundle.size(); i++) {
LayerObject layer = layerBundle[i];
QImage cpy = layer.image->getDisplayable(layer.alpha);
QColor clr_0;
QColor clr_1;
for(int y=0; y<layer.height; y++) {
if(layer.heightOffset+y<0) continue;
if(layer.heightOffset+y>=maxHeight) break;
for(int x=0; x<layer.width; x++) {
if(layer.widthOffset+x<0) continue;
if(layer.widthOffset+x>=maxWidth) break;
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
clr_1=cpy.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f;
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
for(int y = 0; y<layer.height; y++) {
if(layer.heightOffset + y<0) continue;
if(layer.heightOffset + y>=maxHeight) break;
for(int x = 0; x<layer.width; x++) {
if(layer.widthOffset + x<0) continue;
if(layer.widthOffset + x>=maxWidth) break;
clr_0 = Canvas->pixelColor(layer.widthOffset + x, layer.heightOffset + y);
clr_1 = cpy.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha()) / 255.f;
int r = static_cast<int>(static_cast<float>(clr_1.red()) * (t) + static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
int g = static_cast<int>(static_cast<float>(clr_1.green()) * (t) + static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
int b = static_cast<int>(static_cast<float>(clr_1.blue()) * (t) + static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
clr_0.setRed(r);
clr_0.setGreen(g);
clr_0.setBlue(b);
clr_0.setAlpha(a);
Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0);
Canvas->setPixelColor(layer.widthOffset + x, layer.heightOffset + y, clr_0);
}
}
}
@@ -383,7 +393,7 @@ bool PaintingArea::createTempTopLayer(int idx){
newLayer.heightOffset = layerBundle[static_cast<unsigned long long>(idx)].heightOffset;
newLayer.widthOffset = layerBundle[static_cast<unsigned long long>(idx)].widthOffset;
newLayer.image = layerBundle[static_cast<unsigned long long>(idx)].image->getDeepCopy();
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
layerBundle.insert(layerBundle.begin() + idx + 1,newLayer);
return true;
}
return false;

View File

@@ -31,7 +31,7 @@ struct LayerObject {
int height;
int widthOffset;
int heightOffset;
int alpha=255;
int alpha = 255;
};
/*!
@@ -53,15 +53,13 @@ public:
* \param maxHeight - The maximum amount of pixles that are inside painting area from top to bottom (default=600px)
* \param parent - The parent window of the main window (default=nullptr)
*/
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget*parent = nullptr);
PaintingArea(int maxWidth = 600, int maxHeight = 600, QWidget*parent = nullptr);
/*!
* \brief This deconstructor is used to clear up the memory and remove the currently active window
*/
~PaintingArea() override;
// Handles all events
/*!
* \brief setRenderSettings updates all Images to the new Rendersetting.
* \param isFastRenderingOn is the new given flag for the FastRenderer.
@@ -91,7 +89,7 @@ bool save(const QString &filePath, const char*fileFormat);
* \param type - Defining the ImageType of the new layer
* \return Returns the number of layers in the project
*/
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
int addLayer(int width, int height, int widthOffset = 0, int heightOffset = 0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
/*!
* \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack
* \param idx - Index of the position the new layer should be added
@@ -102,7 +100,7 @@ int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, Intel
* \param type - Defining the ImageType of the new layer
* \return Returns the id of the layer position
*/
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
int addLayerAt(int idx, int width, int height, int widthOffset = 0, int heightOffset = 0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
/*!
* \brief The deleteLayer method removes a layer at a given idx
* \param idx - The index of the layer to be removed
@@ -137,7 +135,6 @@ void movePositionActive(int x, int y);
*/
void moveActiveLayer(int idx);
//change properties of colorPicker
/*!
* \brief The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color
*/
@@ -151,7 +148,6 @@ void colorPickerSetSecondColor();
*/
void colorPickerSwapColors();
// Create tools
void createPenTool();
void createPlainTool();
void createLineTool();
@@ -171,6 +167,10 @@ int getWidthOfActive();
*/
int getHeightOfActive();
int getMaxWidth();
int getMaxHeight();
IntelliImage::ImageType getTypeOfImageRealLayer();
std::vector<QPoint> getPolygonDataOfRealLayer();
@@ -189,7 +189,6 @@ IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker;
public slots:
// Events to handle
/*!
* \brief The slotActivateLayer method handles the event of selecting one layer as active
* \param a - idx of the layer to be active
@@ -206,11 +205,9 @@ void mouseMoveEvent(QMouseEvent*event) override;
void mouseReleaseEvent(QMouseEvent*event) override;
void wheelEvent(QWheelEvent*event) override;
// Updates the painting area where we are painting
void paintEvent(QPaintEvent*event) override;
// Makes sure the area we are drawing on remains
// as large as the widget
void resizeEvent(QResizeEvent*event) override;
private:
@@ -230,16 +227,14 @@ IntelliTool* Tool;
IntelliPhotoGui* DummyGui;
std::vector<LayerObject> layerBundle;
int activeLayer=-1;
int activeLayer = -1;
void drawLayers(bool forSaving=false);
void drawLayers(bool forSaving = false);
void resizeLayer(QImage*image_res, const QSize &newSize);
// Helper for Tool
bool createTempTopLayer(int idx);
//this function is needed to avoid errors in inputhandeling if a layer has changed
void updateTools();
};