Merge branch 'dev-variable-refractor' into dev

This commit is contained in:
2019-12-20 10:13:59 +01:00
23 changed files with 154 additions and 153 deletions

View File

@@ -21,7 +21,7 @@
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){
this->Tool = nullptr;
this->setUp(maxWidth, maxHeight);
this->setLayerDimensions(maxWidth, maxHeight);
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
std::vector<QPoint> polygon;
@@ -42,7 +42,7 @@ PaintingArea::~PaintingArea(){
delete Tool;
}
void PaintingArea::setUp(int maxWidth, int maxHeight){
void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
//set standart parameter
this->maxWidth = maxWidth;
this->maxHeight = maxHeight;
@@ -99,35 +99,35 @@ void PaintingArea::setAlphaOfLayer(int index, int alpha){
}
// Used to load the image and place it in the widget
bool PaintingArea::open(const QString &fileName){
bool PaintingArea::open(const QString &filePath){
if(this->activeLayer==-1) {
return false;
}
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
bool open = active->loadImage(fileName);
bool open = active->loadImage(filePath);
active->calculateVisiblity();
update();
return open;
}
// Save the current image
bool PaintingArea::save(const QString &fileName, const char*fileFormat){
bool PaintingArea::save(const QString &filePath, const char*fileFormat){
if(layerBundle.size()==0) {
return false;
}
this->assembleLayers(true);
this->drawLayers(true);
if(!strcmp(fileFormat,"PNG")) {
QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
fileFormat = "png";
if (visibleImage.save(fileName, fileFormat)) {
if (visibleImage.save(filePath, fileFormat)) {
return true;
} else {
return false;
}
}
if (Canvas->save(fileName, fileFormat)) {
if (Canvas->save(filePath, fileFormat)) {
return true;
} else {
return false;
@@ -151,9 +151,9 @@ void PaintingArea::movePositionActive(int x, int y){
void PaintingArea::moveActiveLayer(int idx){
if(idx==1) {
this->activateUpperLayer();
this->selectLayerUp();
}else if(idx==-1) {
this->activateLowerLayer();
this->selectLayerDown();
}
}
@@ -173,8 +173,8 @@ void PaintingArea::colorPickerSetSecondColor(){
this->colorPicker.setSecondColor(clr);
}
void PaintingArea::colorPickerSwitchColor(){
this->colorPicker.switchColors();
void PaintingArea::colorPickerSwapColors(){
this->colorPicker.swapColors();
}
void PaintingArea::createPenTool(){
@@ -273,7 +273,7 @@ void PaintingArea::wheelEvent(QWheelEvent*event){
// The QPaintEvent is sent to widgets that need to
// update themselves
void PaintingArea::paintEvent(QPaintEvent*event){
this->assembleLayers();
this->drawLayers();
QPainter painter(this);
QRect dirtyRec = event->rect();
@@ -288,25 +288,25 @@ void PaintingArea::resizeEvent(QResizeEvent*event){
update();
}
void PaintingArea::resizeImage(QImage*image_res, const QSize &newSize){
void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
//TODO implement
}
void PaintingArea::activateUpperLayer(){
void PaintingArea::selectLayerUp(){
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++;
}
}
void PaintingArea::activateLowerLayer(){
void PaintingArea::selectLayerDown(){
if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
activeLayer--;
}
}
void PaintingArea::assembleLayers(bool forSaving){
void PaintingArea::drawLayers(bool forSaving){
if(forSaving) {
Canvas->fill(Qt::GlobalColor::transparent);
}else{
@@ -341,7 +341,7 @@ void PaintingArea::assembleLayers(bool forSaving){
}
}
void PaintingArea::createTempLayerAfter(int idx){
void PaintingArea::createTempTopLayer(int idx){
if(idx>=0) {
LayerObject newLayer;
newLayer.alpha = 255;

View File

@@ -61,14 +61,14 @@ public:
* \param fileName - Path and filename which are used to determine where the to-be-opened file is stored
* \return Returns a boolean variable whether the file was successfully opened or not
*/
bool open(const QString &fileName);
bool open(const QString &filePath);
/*!
* \brief The save method is used for exporting the current project as one picture
* \param fileName
* \param fileFormat
* \return Returns a boolean variable, true if the file was saved successfully, false if not
*/
bool save(const QString &fileName, const char *fileFormat);
bool save(const QString &filePath, const char *fileFormat);
/*!
* \brief The addLayer adds a layer to the current project/ painting area
@@ -139,7 +139,7 @@ public:
/*!
* \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color
*/
void colorPickerSwitchColor();
void colorPickerSwapColors();
// Create tools
void createPenTool();
@@ -187,9 +187,9 @@ protected:
void resizeEvent(QResizeEvent *event) override;
private:
void setUp(int maxWidth, int maxHeight);
void activateUpperLayer();
void activateLowerLayer();
void setLayerDimensions(int maxWidth, int maxHeight);
void selectLayerUp();
void selectLayerDown();
QImage* Canvas;
int maxWidth;
@@ -201,12 +201,13 @@ private:
std::vector<LayerObject> layerBundle;
int activeLayer=-1;
void assembleLayers(bool forSaving=false);
void drawLayers(bool forSaving=false);
void resizeImage(QImage *image_res, const QSize &newSize);
void resizeLayer(QImage *image_res, const QSize &newSize);
// Helper for Tool
void createTempLayerAfter(int idx);
// TODO: Always create this layer on top and return the id here!
void createTempTopLayer(int idx);
};
#endif