Refractoring Update 1

- Refractored switchColor to slotSwapColor
- Corrected spelling mistake in variable name (weight-->width)
- Unified variable names
This commit is contained in:
2019-12-20 09:50:30 +01:00
parent ab8590c4fe
commit 52292ebfe7
10 changed files with 109 additions and 44 deletions

View File

@@ -206,8 +206,8 @@ void IntelliPhotoGui::slotSetSecondColor(){
paintingArea->colorPickerSetSecondColor();
}
void IntelliPhotoGui::slotSwitchColor(){
paintingArea->colorPickerSwitchColor();
void IntelliPhotoGui::slotSwapColor(){
paintingArea->colorPickerSwapColors();
}
void IntelliPhotoGui::slotCreatePenTool(){
@@ -328,9 +328,9 @@ void IntelliPhotoGui::createActions(){
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
actionColorSwitch = new QAction(tr("&Switch"), this);
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
connect(actionColorSwitch, SIGNAL(triggered()), this, SLOT(slotSwitchColor()));
actionColorSwap = new QAction(tr("&Switch"), this);
actionColorSwap->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
connect(actionColorSwap, SIGNAL(triggered()), this, SLOT(slotSwapColor()));
//Create Tool actions down here
actionCreatePlainTool = new QAction(tr("&Plain"), this);
@@ -398,7 +398,7 @@ void IntelliPhotoGui::createMenus(){
colorMenu = new QMenu(tr("&Color"), this);
colorMenu->addAction(actionColorPickerFirstColor);
colorMenu->addAction(actionColorPickerSecondColor);
colorMenu->addAction(actionColorSwitch);
colorMenu->addAction(actionColorSwap);
//Attach all Tool Options
toolMenu = new QMenu(tr("&Tools"), this);

View File

@@ -55,7 +55,7 @@ void slotMoveLayerDown();
// color Picker slots here
void slotSetFirstColor();
void slotSetSecondColor();
void slotSwitchColor();
void slotSwapColor();
// tool slots here
void slotCreatePenTool();
@@ -103,7 +103,7 @@ QAction*actionExit;
// color Picker actions
QAction*actionColorPickerFirstColor;
QAction*actionColorPickerSecondColor;
QAction*actionColorSwitch;
QAction*actionColorSwap;
// tool actions
QAction*actionCreatePenTool;

View File

@@ -33,10 +33,10 @@ QImage imageData;
public:
/*!
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
* \param weight - The weight of the Image.
* \param width - The width of the Image.
* \param height - The height of the Image.
*/
IntelliImage(int weight, int height);
IntelliImage(int width, int height);
/*!
* \brief An Abstract Destructor.
@@ -91,7 +91,7 @@ virtual QImage getDisplayable(int alpha=255) = 0;
/*!
* \brief A function that copys all that returns a [allocated] Image
* \return A [allocated] Image with all the properties of the instance.
* \return An [allocated] image with all the properties of the instance.
*/
virtual IntelliImage* getDeepCopy() = 0;

View File

@@ -16,10 +16,10 @@ virtual void calculateVisiblity() override;
public:
/*!
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
* \param weight - The weight of the Image.
* \param width - The width of the Image.
* \param height - The height of the Image.
*/
IntelliRasterImage(int weight, int height);
IntelliRasterImage(int width, int height);
/*!
* \brief An Destructor.

View File

@@ -29,10 +29,10 @@ std::vector<QPoint> polygonData;
public:
/*!
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
* \param weight - The weight of the Image.
* \param width - The width of the Image.
* \param height - The height of the Image.
*/
IntelliShapedImage(int weight, int height);
IntelliShapedImage(int width, int height);
/*!
* \brief An Destructor.

View File

@@ -9,7 +9,7 @@ IntelliColorPicker::~IntelliColorPicker(){
}
void IntelliColorPicker::switchColors(){
void IntelliColorPicker::swapColors(){
std::swap(firstColor, secondColor);
}

View File

@@ -0,0 +1,64 @@
#ifndef INTELLITOOLSETCOLORTOOL_H
#define INTELLITOOLSETCOLORTOOL_H
#include "QColor"
#include "QPoint"
#include "QColorDialog"
/*!
* \brief The IntelliColorPicker manages the selected colors for one whole project.
*/
class IntelliColorPicker {
public:
/*!
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
*/
IntelliColorPicker();
/*!
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
*/
virtual ~IntelliColorPicker();
/*!
* \brief A function switching primary and secondary color.
*/
void swapColors();
/*!
* \brief A function to read the primary selected color.
* \return Returns the primary color.
*/
QColor getFirstColor();
/*!
* \brief A function to read the secondary selected color.
* \return Returns the secondary color.
*/
QColor getSecondColor();
/*!
* \brief A function to set the primary color.
* \param Color - The color to be set as primary.
*/
void setFirstColor(QColor Color);
/*!
* \brief A function to set the secondary color.
* \param Color - The color to be set as secondary.
*/
void setSecondColor(QColor Color);
private:
/*!
* \brief The primary color.
*/
QColor firstColor;
/*!
* \brief The secondary color.
*/
QColor secondColor;
};
#endif // INTELLITOOLSETCOLORTOOL_H

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 && activeLayer<layerBundle.size()-1) {
std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
activeLayer++;
}
}
void PaintingArea::activateLowerLayer(){
void PaintingArea::selectLayerDown(){
if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
activeLayer--;
}
}
void PaintingArea::assembleLayers(bool forSaving){
void PaintingArea::drawLayers(bool forSaving){
if(forSaving) {
Canvas->fill(Qt::GlobalColor::transparent);
}else{

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
@@ -90,7 +90,7 @@ public:
* \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, ImageType type = ImageType::Raster_Image);
int addLayerAt(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image, int idx);
/*!
* \brief The deleteLayer method removes a layer at a given index
* \param index - The index of the layer to be removed
@@ -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

View File

@@ -48,7 +48,7 @@ void IntelliTool::onWheelScrolled(int value){
}
void IntelliTool::createToolLayer(){
Area->createTempLayerAfter(Area->activeLayer);
Area->createTempTopLayer(Area->activeLayer);
this->Active=&Area->layerBundle[Area->activeLayer];
this->Canvas=&Area->layerBundle[Area->activeLayer+1];
}